Skip to content

Commit f4bb09f

Browse files
committed
ID-32: generate 'gateway.info.json' file for server and deployment archives
1 parent 18c5f18 commit f4bb09f

File tree

9 files changed

+183
-20
lines changed

9 files changed

+183
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.settings
22
.data
33
.policystudio
4+
.studio
45
.vscode
56
.projdeps.json
67
*.class

CHANGELOG.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ Example:
1515
$ buildfed ... -F description:config/description.txt
1616

1717
This will define a new property `description` which is populated from the content of the `description.txt` file.
18+
19+
|https://github.com/Axway-API-Management-Plus/apigw-maven-plugin/issues/32[#32]
20+
|Enhancement
21+
|Build artifact information JSON.
22+
23+
For server and deployment archives the plugin will generate a `gateway.info.json` file.
24+
The file contains information about the version of the artifact and its dependencies.
25+
26+
On configuring the `.fed` package, the plugin passes the content of the `gateway.info.json` file as `_system.artifact.info` property to the `buildfed` tool.
27+
This enables the developer to use the contained JSON document to build an endpoint providing information about the currently deployed version.
1828
|===
1929

2030
== Version 0.10.0

doc/manual/_config-tool.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ The plugin and the configuration tool provides a set of predefined system proper
197197
|Complete ID of the project artifact.
198198
|Plugin
199199

200+
|_system.artifact.info
201+
|JSON describing the artifact and its dependencies (content of the `gateway.info.json` file).
202+
If the `gateway.info.json` file is not available the property contains an empty JSON document `{}`.
203+
|Plugin
204+
200205
|_system.build.datetime
201206
|Build date and time in ISO format (YYYY-MM-DD'T'HH:MM:SS.S)
202207
|Config Tool

doc/manual/_reference.adoc

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ icon:folder[] server-archive.axsar <1>
9999
icon:folder[] staticFiles <3>
100100
icon:file[] gateway.pol <4>
101101
icon:file[] gateway.env <5>
102-
icon:file[] readme-server-archive.txt <6>
102+
icon:file[] gateway.info.json <6>
103+
icon:file[] readme-server-archive.txt <7>
103104
----
104105
<1> Generated server archive.
105106
<2> Folder containing dependent JARs.
@@ -108,7 +109,30 @@ The files are copied from the `staticFiles` folders of all dependent policy arch
108109
<4> Packed `.pol` archive containing the server configuration and polices (including policies of all dependent policy archives)
109110
<5> `.env` file containing all environment specific information.
110111
The environment is not configured and should be treated as environment independent.
111-
<6> Generated readme file describing the content of the archive (e.g. version of dependent policy archives)
112+
<6> JSON document describing the content of the archive (e.g. version and dependencies)
113+
<7> Generated readme file describing the content of the archive (e.g. version of dependent policy archives)
114+
115+
*`gateway.info.json` File*
116+
117+
The artifact information file describes the content of the server archive as a JSON document.
118+
It contains information about the deployment archive itself the dependencies.
119+
120+
[source,json]
121+
----
122+
{
123+
"id" : "com.example:hello-world-gw:axway-server-archive:0.1.0-SNAPSHOT",
124+
"name" : "Hello World Server",
125+
"description" : "My first \"Hello World\" server project.",
126+
"buildTime" : "2019-12-17T17:25:40",
127+
"artifact" : {
128+
"groupID" : "com.example",
129+
"artifactID" : "hello-world-gw",
130+
"version" : "0.1.0-SNAPSHOT"
131+
},
132+
"dependencies" : [ "com.example:hello-world:axway-policy-archive:0.1.0-SNAPSHOT" ]
133+
}
134+
----
135+
112136

113137
=== Deployment Project
114138
Deployment projects are used to configure API gateways for specific environments or groups based on an environment independent server project.
@@ -138,24 +162,54 @@ icon:folder[] deploy-archive.axdar <1>
138162
icon:folder[] lib <2>
139163
icon:folder[] staticFiles <3>
140164
icon:file[] gateway.fed <4>
141-
icon:file[] gateway.pol <5>
142-
icon:file[] gateway.env <6>
143-
icon:file[] readme-deployment-archive.txt <7>
144-
icon:file[] readme-server-archive.txt <8>
165+
icon:file[] gateway.info.json <5>
166+
icon:file[] readme-deployment-archive.txt <6>
167+
icon:file[] readme-server-archive.txt <7>
145168
----
146169
<1> Generated server archive.
147170
<2> Folder containing dependent JARs.
148171
<3> Static files belonging to the gateway instance.
149172
The files are copied from the `staticFiles` folders of all dependent policy archives.
150173
<4> Configured `.fed` file.
151174
It is environment specific and contains all configured certificates and environmentalized fields.
152-
<5> Packed `.pol` archive containing the server configuration and polices (including policies of all dependent policy archives)
153-
<6> Configured `.env` file containing all environment specific information.
154-
All certificates and environmentalized fields are replace by configured values.
155-
<7> Generated readme file describing the content of the archive (e.g. version of depnednt server archive).
156-
<8> Generated readme file describing the content of the archive (e.g. version of dependent policy archives).
175+
<5> JSON document describing the content of the archive (e.g. version and dependencies)
176+
<6> Generated readme file describing the content of the archive (e.g. version of dependent server archive).
177+
<7> Generated readme file describing the content of the archive (e.g. version of dependent policy archives).
157178
Copied from server archive.
158179

180+
*`gateway.info.json` File*
181+
182+
The artifact information file describes the content of the deployment archive as a JSON document.
183+
It contains information about the deployment archive itself and about the based server archive.
184+
185+
[source,json]
186+
----
187+
{
188+
"id" : "com.example:hello-world-dev:axway-deployment-archive:0.1.0-SNAPSHOT",
189+
"name" : "Hello World (DEV)",
190+
"description" : null,
191+
"buildTime" : "2019-12-17T17:25:40",
192+
"artifact" : {
193+
"groupID" : "com.example",
194+
"artifactID" : "hello-world-dev",
195+
"version" : "0.1.0-SNAPSHOT"
196+
},
197+
"dependencies" : [ "com.example:hello-world-gw:axway-server-archive:0.1.0-SNAPSHOT" ],
198+
"serverArchive" : {
199+
"id" : "com.example:hello-world-gw:axway-server-archive:0.1.0-SNAPSHOT",
200+
"name" : "Hello World Server",
201+
"description" : "My first \"Hello World\" server project.",
202+
"buildTime" : "2019-12-17T17:25:40",
203+
"artifact" : {
204+
"groupID" : "com.example",
205+
"artifactID" : "hello-world-gw",
206+
"version" : "0.1.0-SNAPSHOT"
207+
},
208+
"dependencies" : [ "com.example:hello-world:axway-policy-archive:0.1.0-SNAPSHOT" ]
209+
}
210+
}
211+
----
212+
159213
== Build Properties
160214

161215
The plugin can be configured by various properties.

src/main/java/com/axway/maven/apigw/AbstractGatewayMojo.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.axway.maven.apigw;
22

33
import java.io.File;
4+
import java.text.SimpleDateFormat;
45
import java.util.ArrayList;
6+
import java.util.Date;
57
import java.util.HashSet;
68
import java.util.List;
79
import java.util.Optional;
@@ -13,6 +15,10 @@
1315
import org.apache.maven.plugins.annotations.Parameter;
1416
import org.apache.maven.project.MavenProject;
1517

18+
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import com.fasterxml.jackson.databind.node.ArrayNode;
20+
import com.fasterxml.jackson.databind.node.ObjectNode;
21+
1622
/**
1723
*
1824
*/
@@ -254,4 +260,29 @@ protected List<File> getPropertyFiles() {
254260

255261
return propFiles;
256262
}
263+
264+
protected ObjectNode buildBasicArtifactInfo() {
265+
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
266+
ObjectMapper mapper = new ObjectMapper();
267+
268+
ObjectNode artifact = mapper.createObjectNode();
269+
artifact.put("groupID", this.project.getGroupId());
270+
artifact.put("artifactID", this.project.getArtifactId());
271+
artifact.put("version", this.project.getVersion());
272+
273+
ObjectNode root = mapper.createObjectNode();
274+
root.put("id", this.project.getId());
275+
root.put("name", this.project.getName());
276+
root.put("description", this.project.getDescription());
277+
root.put("buildTime", df.format(new Date()));
278+
root.set("artifact", artifact);
279+
280+
ArrayNode deps = mapper.createArrayNode();
281+
for (Artifact a : getDependencies(null)) {
282+
deps.add(a.getId());
283+
}
284+
root.set("dependencies", deps);
285+
286+
return root;
287+
}
257288
}

src/main/java/com/axway/maven/apigw/DeploymentArchiveMojo.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
import org.apache.maven.plugins.annotations.ResolutionScope;
1717

1818
import com.axway.maven.apigw.utils.FedBuilder;
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.fasterxml.jackson.databind.node.ObjectNode;
1921

2022
@Mojo(name = "axdar", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = false, requiresDependencyResolution = ResolutionScope.COMPILE, requiresDependencyCollection = ResolutionScope.COMPILE)
2123
public class DeploymentArchiveMojo extends AbstractFlattendProjectArchiveMojo {
2224

2325
public static final String FILE_FED_NAME = "gateway.fed";
26+
public static final String FILE_GATEWAY_INFO = "gateway.info.json";
2427
public static final String FILE_README = "readme-deployment-archive.txt";
2528
public static final String FILE_GATEWAY_CONFIG_JSON = "gateway.config.json";
2629

@@ -69,12 +72,13 @@ protected List<ArchiveDir> prepareDirs() throws MojoExecutionException {
6972
FileUtils.deleteDirectory(archiveBuildDir);
7073
archiveBuildDir.mkdirs();
7174

72-
buildFedArchive(archiveBuildDir, srcPolFile, srcEnvFile);
75+
File infoFile = prepareInfoJson(archiveBuildDir);
76+
buildFedArchive(archiveBuildDir, srcPolFile, srcEnvFile, infoFile);
7377

7478
prepareReadme(archiveBuildDir);
7579
FileUtils.copyFileToDirectory(
7680
new File(getSharedArtifactDir(this.serverArchive), ServerArchiveMojo.FILE_README), archiveBuildDir);
77-
81+
7882
prepareStaticFiles(new File(archiveBuildDir, DIR_STATIC_FILES));
7983
prepareJars(new File(archiveBuildDir, ServerArchiveMojo.DIR_LIBS));
8084

@@ -100,6 +104,29 @@ private void prepareReadme(File targetDir) throws IOException, MojoExecutionExce
100104
FileUtils.writeStringToFile(readme, str.toString(), "UTF-8");
101105
}
102106

107+
private File prepareInfoJson(File targetDir) throws IOException, MojoExecutionException {
108+
ObjectMapper mapper = new ObjectMapper();
109+
File info = new File(targetDir, FILE_GATEWAY_INFO);
110+
111+
ObjectNode root = buildBasicArtifactInfo();
112+
113+
ObjectNode serverJson;
114+
File serverInfo = new File(getSharedArtifactDir(this.serverArchive), ServerArchiveMojo.FILE_GATEWAY_INFO);
115+
if (serverInfo.canRead()) {
116+
serverJson = (ObjectNode) mapper.readTree(serverInfo);
117+
} else {
118+
serverJson = mapper.createObjectNode();
119+
serverJson.put("id", this.serverArchive.getId());
120+
}
121+
root.set("serverArchive", serverJson);
122+
123+
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
124+
125+
FileUtils.writeStringToFile(info, json, "UTF-8");
126+
127+
return info;
128+
}
129+
103130
private void prepareStaticFiles(File targetDir) throws IOException, MojoExecutionException {
104131
File staticFiles;
105132

@@ -124,15 +151,15 @@ private void prepareJars(File targetDir) throws IOException, MojoExecutionExcept
124151
}
125152
}
126153

127-
private void buildFedArchive(File targetDir, File srcPolFile, File srcEnvFile) throws MojoExecutionException {
154+
private void buildFedArchive(File targetDir, File srcPolFile, File srcEnvFile, File infoFile) throws MojoExecutionException {
128155
File configFile = this.configConfigFile;
129156
if (configFile == null) {
130157
configFile = new File(this.sourceDirectory, FILE_GATEWAY_CONFIG_JSON);
131158
}
132159

133160
File outFedFile = new File(targetDir, FILE_FED_NAME);
134161

135-
FedBuilder fedBuilder = new FedBuilder(this, srcPolFile, srcEnvFile, configFile);
162+
FedBuilder fedBuilder = new FedBuilder(this, srcPolFile, srcEnvFile, configFile, infoFile);
136163

137164
fedBuilder.addPropertyFiles(getPropertyFiles());
138165

src/main/java/com/axway/maven/apigw/DeploymentMojo.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashMap;
66
import java.util.Map;
77

8+
import org.apache.commons.io.FileUtils;
89
import org.apache.maven.plugin.MojoExecutionException;
910
import org.apache.maven.plugin.MojoFailureException;
1011
import org.apache.maven.plugins.annotations.Execute;
@@ -15,6 +16,8 @@
1516
import com.axway.maven.apigw.utils.FedBuilder;
1617
import com.axway.maven.apigw.utils.ProjectDeploy;
1718
import com.axway.maven.apigw.utils.ProjectPack;
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.fasterxml.jackson.databind.node.ObjectNode;
1821

1922
@Mojo(name = "deploy", defaultPhase = LifecyclePhase.NONE, requiresProject = true, threadSafe = false)
2023
@Execute(phase = LifecyclePhase.PACKAGE)
@@ -84,8 +87,14 @@ private void deployPolicyProject() throws MojoExecutionException {
8487
// configure fed
8588
File pol = new File(getTempDir(), PROJECT_NAME + ".pol");
8689
File env = new File(getTempDir(), PROJECT_NAME + ".env");
90+
File info = new File(getTempDir(), PROJECT_NAME + ".info.json");
8791

88-
File fed = configFed(pol, env);
92+
ObjectMapper mapper = new ObjectMapper();
93+
ObjectNode root = buildBasicArtifactInfo();
94+
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
95+
FileUtils.writeStringToFile(info, json, "UTF-8");
96+
97+
File fed = configFed(pol, env, info);
8998

9099
// deploy to server
91100
deployFed(fed);
@@ -100,8 +109,9 @@ private void deployServerProject() throws MojoExecutionException {
100109
// configure fed
101110
File pol = new File(archiveBuildDir, ServerArchiveMojo.FILE_GATEWAY_POL);
102111
File env = new File(archiveBuildDir, ServerArchiveMojo.FILE_GATEWAY_ENV);
112+
File info = new File(archiveBuildDir, ServerArchiveMojo.FILE_GATEWAY_INFO);
103113

104-
File fed = configFed(pol, env);
114+
File fed = configFed(pol, env, info);
105115

106116
// deploy to server
107117
deployFed(fed);
@@ -113,8 +123,8 @@ private void deployDeploymentProject() throws MojoExecutionException {
113123
deployFed(fed);
114124
}
115125

116-
private File configFed(File pol, File env) throws MojoExecutionException {
117-
FedBuilder fb = new FedBuilder(this, pol, env, this.configConfigFile);
126+
private File configFed(File pol, File env, File info) throws MojoExecutionException {
127+
FedBuilder fb = new FedBuilder(this, pol, env, this.configConfigFile, info);
118128
fb.setPassphrasePol(this.passphrasePol);
119129
fb.setPassphraseFed(this.passphraseFed);
120130

src/main/java/com/axway/maven/apigw/ServerArchiveMojo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.apache.maven.plugins.annotations.ResolutionScope;
1818

1919
import com.axway.maven.apigw.utils.ProjectPack;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import com.fasterxml.jackson.databind.node.ObjectNode;
2022

2123
@Mojo(name = "axsar", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = false, requiresDependencyResolution = ResolutionScope.COMPILE, requiresDependencyCollection = ResolutionScope.COMPILE)
2224
public class ServerArchiveMojo extends AbstractFlattendProjectArchiveMojo {
@@ -26,6 +28,7 @@ public class ServerArchiveMojo extends AbstractFlattendProjectArchiveMojo {
2628
public static final String FILE_GATEWAY = "gateway";
2729
public static final String FILE_GATEWAY_POL = FILE_GATEWAY + ".pol";
2830
public static final String FILE_GATEWAY_ENV = FILE_GATEWAY + ".env";
31+
public static final String FILE_GATEWAY_INFO = FILE_GATEWAY + ".info.json";
2932
public static final String FILE_README = "readme-server-archive.txt";
3033

3134
@Override
@@ -54,6 +57,7 @@ protected List<ArchiveDir> prepareDirs() throws MojoExecutionException {
5457
FileUtils.copyFileToDirectory(envFile, archiveBuildDir);
5558

5659
prepareReadme(archiveBuildDir);
60+
prepareInfoJson(archiveBuildDir);
5761
prepareStaticFiles(new File(archiveBuildDir, DIR_STATIC_FILES));
5862
prepareJars(new File(archiveBuildDir, DIR_LIBS));
5963

@@ -80,6 +84,17 @@ private void prepareReadme(File targetDir) throws IOException, MojoExecutionExce
8084

8185
FileUtils.writeStringToFile(readme, str.toString(), "UTF-8");
8286
}
87+
88+
private void prepareInfoJson(File targetDir) throws IOException, MojoExecutionException {
89+
ObjectMapper mapper = new ObjectMapper();
90+
File info = new File(targetDir, FILE_GATEWAY_INFO);
91+
92+
ObjectNode root = buildBasicArtifactInfo();
93+
94+
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
95+
96+
FileUtils.writeStringToFile(info, json, "UTF-8");
97+
}
8398

8499
private void prepareStaticFiles(File targetDir) throws IOException, MojoExecutionException {
85100
File staticFiles;

0 commit comments

Comments
 (0)