Skip to content

Commit e120c97

Browse files
committed
ID-51: customized version name
1 parent 4a86854 commit e120c97

File tree

9 files changed

+58
-38
lines changed

9 files changed

+58
-38
lines changed

CHANGELOG.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44
[cols="1,2,<10a", options="header"]
55
|===
66
|ID|Type|Description
7+
|https://github.com/Axway-API-Management-Plus/apigw-maven-plugin/issues/51[#51]
8+
|Enhancement
9+
|Customized version name for `.pol` and `.fed` packages.
10+
11+
A new property `axway.project.version` is introduced to customize the version of `.pol` and `.fed` packages. As default the value will be set to ${project.version} . The version can be overwritten by a command line property of by a defined property within the pom.xml.
12+
13+
*Example*
14+
15+
Command line
16+
17+
`$ mvn clean package -Daxway.project.version="${project.version}-BN20201031"`
18+
19+
.pom.xml
20+
[source,xml]
21+
----
22+
<properties>
23+
<axway.project.version>${project.version}-BN20201031</axway.project.version>
24+
</properties>
25+
----
26+
727
|https://github.com/Axway-API-Management-Plus/apigw-maven-plugin/pull/45[#45]
828
|Enhancement
929
|Docker capabilities.

doc/manual/_reference.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ Default: ${axway.home}/apigateway
236236

237237
Default: ${axway.home}/policystudio
238238

239+
|axway.project.version
240+
|Version name of the project.
241+
242+
The version name is used for setting the version attribute of the policy properties within `.pol` or `.fed` packages.
243+
244+
Default: ${project.version}
245+
239246
|axway.dir.source
240247
|Directory of gateway or configuration file source code used by the plugin.
241248
${basedir}/src/main/axwgw

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public abstract class AbstractGatewayMojo extends AbstractMojo {
110110

111111
@Parameter(property = "axway.config.secrets.key", required = false)
112112
protected File configSecretsKey = null;
113+
114+
@Parameter(property = "axway.project.version", required = false, defaultValue="${project.version}")
115+
protected String projectVersion;
113116

114117

115118
@Parameter(defaultValue = "${project}", readonly = true)
@@ -296,4 +299,13 @@ protected ObjectNode buildBasicArtifactInfo() {
296299

297300
return root;
298301
}
302+
303+
protected Map<String, String> buildPolicyProperties() throws MojoExecutionException {
304+
Map<String, String> polProps = new HashMap<>();
305+
polProps.put("Name", this.project.getGroupId() + ":" + this.project.getArtifactId());
306+
polProps.put("Version", this.projectVersion);
307+
polProps.put("Type", getPackageType().getType());
308+
309+
return polProps;
310+
}
299311
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ private void deployFed(File fed) throws MojoExecutionException {
253253
Source source = new Source(fed, this.passphraseFed);
254254
Target target = new Target(this.deployGroup, this.passphraseDeploy);
255255

256-
AbstractCommandExecutor deploy;
256+
DockerImage deploy;
257257

258258
// containerName is populated, so we are going to create a new container
259-
AbstractCommandExecutor dockerCommands = new DockerCommands("Docker Commands", getLog());
259+
DockerCommands dockerCommands = new DockerCommands("Docker Commands", getLog());
260260
int exitCode = dockerCommands.execute("Remove Container", this.isRemoveContainer(), this.containerName,
261261
null, null, null, null, null,
262262
null, null, null, null);

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import java.io.File;
44
import java.io.IOException;
5-
import java.util.HashMap;
65
import java.util.Map;
76

8-
import com.axway.maven.apigw.utils.*;
97
import org.apache.commons.io.FileUtils;
108
import org.apache.maven.plugin.MojoExecutionException;
119
import org.apache.maven.plugin.MojoFailureException;
@@ -14,6 +12,11 @@
1412
import org.apache.maven.plugins.annotations.Mojo;
1513
import org.apache.maven.plugins.annotations.Parameter;
1614

15+
import com.axway.maven.apigw.utils.FedBuilder;
16+
import com.axway.maven.apigw.utils.ProjectDeploy;
17+
import com.axway.maven.apigw.utils.ProjectPack;
18+
import com.axway.maven.apigw.utils.Source;
19+
import com.axway.maven.apigw.utils.Target;
1720
import com.fasterxml.jackson.databind.ObjectMapper;
1821
import com.fasterxml.jackson.databind.node.ObjectNode;
1922

@@ -77,7 +80,7 @@ private void deployPolicyProject() throws MojoExecutionException {
7780
// pack test server project
7881
ProjectPack packer = new ProjectPack(this.homeAxwayGW, getLog());
7982
packer.setPassphrasePol(this.passphrasePol);
80-
int exitCode = packer.execute(getTempDir(), PROJECT_NAME, this.testServerDirectory, null);
83+
int exitCode = packer.execute(getTempDir(), PROJECT_NAME, this.testServerDirectory, buildPolicyProperties());
8184
if (exitCode != 0) {
8285
throw new MojoExecutionException("failed to build packed project");
8386
}
@@ -154,19 +157,14 @@ private File configFed(File pol, File env, File info) throws MojoExecutionExcept
154157

155158
private void deployFed(File fed) throws MojoExecutionException {
156159
try {
157-
Map<String, String> polProps = new HashMap<>();
158-
polProps.put("Name", this.project.getGroupId() + ":" + this.project.getArtifactId());
159-
polProps.put("Version", this.project.getVersion());
160-
polProps.put("Type", "Test Deployment");
160+
Map<String, String> polProps = buildPolicyProperties();
161161

162162
Source source = new Source(fed, this.passphraseFed);
163163
Target target = new Target(this.deployGroup, this.passphraseDeploy);
164164

165-
AbstractCommandExecutor deploy;
166-
167165
// Deploying to a Classic Gateway, ok to use projdeploy
168166
this.getLog().info("Using projdeploy to deploy the fed file");
169-
deploy = new ProjectDeploy(this.homeAxwayGW, getDomain(), getLog());
167+
ProjectDeploy deploy = new ProjectDeploy(this.homeAxwayGW, getDomain(), getLog());
170168
int exitCode = deploy.execute(source, target, polProps, null);
171169
if (exitCode != 0) {
172170
throw new MojoExecutionException("Failed to deploy project: exitCode=" + exitCode);

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.text.SimpleDateFormat;
66
import java.util.ArrayList;
77
import java.util.Date;
8-
import java.util.HashMap;
98
import java.util.List;
109
import java.util.Map;
1110

@@ -46,7 +45,7 @@ protected List<ArchiveDir> prepareDirs() throws MojoExecutionException {
4645
File outDir = executeProjPack();
4746
File polFile = new File(outDir, FILE_GATEWAY_POL);
4847
File envFile = new File(outDir, FILE_GATEWAY_ENV);
49-
48+
5049
File archiveBuildDir = getArchiveBuildDir();
5150

5251
try {
@@ -84,15 +83,15 @@ private void prepareReadme(File targetDir) throws IOException, MojoExecutionExce
8483

8584
FileUtils.writeStringToFile(readme, str.toString(), "UTF-8");
8685
}
87-
86+
8887
private void prepareInfoJson(File targetDir) throws IOException, MojoExecutionException {
8988
ObjectMapper mapper = new ObjectMapper();
9089
File info = new File(targetDir, FILE_GATEWAY_INFO);
91-
90+
9291
ObjectNode root = buildBasicArtifactInfo();
93-
92+
9493
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
95-
94+
9695
FileUtils.writeStringToFile(info, json, "UTF-8");
9796
}
9897

@@ -126,20 +125,17 @@ private void prepareJars(File targetDir) throws IOException, MojoExecutionExcept
126125
private File executeProjPack() throws MojoExecutionException {
127126
try {
128127
File outDir = new File(getTargetDir(), DIR_ARCHIVE_ROOT);
129-
128+
130129
ProjectPack packer = new ProjectPack(this.homeAxwayGW, getLog());
131130
packer.setPassphrasePol(this.passphrasePol);
132-
Map<String, String> polProps = new HashMap<>();
133-
polProps.put("Name", this.project.getGroupId() + ":" + this.project.getArtifactId());
134-
polProps.put("Version", this.project.getVersion());
135-
polProps.put("Type", getType());
136-
131+
Map<String, String> polProps = buildPolicyProperties();
132+
137133
int index = 0;
138134
for (Artifact a : getDependentPolicyArchives()) {
139135
polProps.put("Dependency_" + index, a.getId());
140136
index++;
141137
}
142-
138+
143139
packer.execute(outDir, FILE_GATEWAY, getPoliciesDirectory(), polProps);
144140

145141
return outDir;

src/main/java/com/axway/maven/apigw/utils/AbstractCommandExecutor.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.io.InputStreamReader;
77
import java.util.ArrayList;
88
import java.util.List;
9-
import java.util.Map;
109
import java.util.Objects;
1110

1211
import org.apache.maven.plugin.logging.Log;
@@ -29,16 +28,6 @@ protected Log getLog() {
2928
return this.log;
3029
}
3130

32-
protected int execute () throws IOException { return 0; }
33-
34-
public int execute ( String task, boolean remove, String containerName, String imageName, String imageTag,
35-
Map<String, String> ports, Map<String, String> links,
36-
Map<String, String> environmentVariables, String adminNodeManagerHost, String metricsDbUrl,
37-
String metricsDbUsername, String metricsDbPassword )
38-
throws IOException { return 0; }
39-
40-
public int execute(Source source, Target target, Map<String, String> polProperties,
41-
Map<String, String> envProperties) throws IOException { return 0; }
4231

4332
protected int execute(List<String> parameters) throws IOException {
4433
List<String> inputParam = new ArrayList<String>();

src/main/java/com/axway/maven/apigw/utils/DockerCommands.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public DockerCommands(String name, Log log) {
1313
super(name, log);
1414
}
1515

16-
@Override
1716
public int execute ( String task, boolean remove, String containerName, String imageName, String imageTag,
1817
Map<String, String> ports, Map<String, String> links,
1918
Map<String, String> environmentVariables, String adminNodeManagerHost, String metricsDbUrl,

src/main/java/com/axway/maven/apigw/utils/DockerImage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public DockerImage(File axwayContainerScriptHome, String axwayImageName, String
3939
this.domainKeyPassFile = domainKeyPassFile;
4040
}
4141

42-
@Override
4342
public int execute(Source source, Target target, Map<String, String> polProperties, Map<String,
4443
String> envProperties) throws IOException {
4544
List<String> inputParam = new ArrayList<String>();

0 commit comments

Comments
 (0)