Skip to content

Commit 4d1fc25

Browse files
committed
Added url and description to generated artifacts.
1 parent e14b961 commit 4d1fc25

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ It is used in combination with the [artifact-version-service](https://github.com
3131
<plugin>
3232
<groupId>de.westemeyer</groupId>
3333
<artifactId>artifact-version-maven-plugin</artifactId>
34-
<version>1.0.2</version>
34+
<version>1.1.0</version>
3535
<executions>
3636
<execution>
3737
<goals>
@@ -47,7 +47,7 @@ It is used in combination with the [artifact-version-service](https://github.com
4747
<dependency>
4848
<groupId>de.westemeyer</groupId>
4949
<artifactId>artifact-version-service</artifactId>
50-
<version>1.0.2</version>
50+
<version>1.1.0</version>
5151
</dependency>
5252
</dependencies>
5353
```
@@ -59,7 +59,7 @@ It is also possible to configure the generator to use target directories and a m
5959
<plugin>
6060
<groupId>de.westemeyer</groupId>
6161
<artifactId>artifact-version-maven-plugin</artifactId>
62-
<version>1.0.2</version>
62+
<version>1.1.0</version>
6363
<executions>
6464
<execution>
6565
<goals>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>de.westemeyer</groupId>
88
<artifactId>artifact-version-maven-plugin</artifactId>
9-
<version>1.0.2</version>
9+
<version>1.1.0</version>
1010

1111
<name>Maven source code generator for artifact version services.</name>
1212
<description>The artifact-version-maven-plugin is used to automatically generate artifact version information to be collected by ArtifactVersionCollector somewhere in the classpath.</description>

src/main/java/de/westemeyer/plugins/maven/versions/GenerateServiceMojo.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,13 @@ void writeServiceClass() throws MojoFailureException {
200200

201201
// iterate map of template values for replacement
202202
for (Map.Entry<String, String> entry : getTemplateValues().entrySet()) {
203-
// replace values in string
204-
out = out.replace("${" + entry.getKey() + "}", entry.getValue());
203+
String value = entry.getValue();
204+
if (value == null) {
205+
out = out.replace("\"${" + entry.getKey() + "}\"", "null");
206+
} else {
207+
// replace values in string
208+
out = out.replace("${" + entry.getKey() + "}", value);
209+
}
205210
}
206211

207212
// write resulting java source code to output file
@@ -225,6 +230,8 @@ Map<String, String> getTemplateValues() {
225230
valueMap.put("artifactId", project.getArtifactId());
226231
valueMap.put("version", project.getVersion());
227232
valueMap.put("name", project.getName());
233+
valueMap.put("url", project.getUrl());
234+
valueMap.put("description", project.getDescription());
228235
valueMap.put("timestamp", "" + new Date().getTime());
229236
return valueMap;
230237
}

src/main/resources/de/westemeyer/plugins/maven/versions/service-template.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import de.westemeyer.version.service.ArtifactVersionService;
99
public class ${serviceClass} implements ArtifactVersionService {
1010
@Override
1111
public Artifact getArtifact() {
12-
return new Artifact("${groupId}", "${artifactId}", "${version}", ${timestamp}L, "${name}");
12+
return new Artifact("${groupId}", "${artifactId}", "${version}", ${timestamp}L, "${name}", "${description}", "${url}");
1313
}
1414
}

src/test/java/de/westemeyer/plugins/maven/versions/GenerateServiceMojoTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.westemeyer.plugins.maven.versions;
22

33
import org.apache.maven.model.Build;
4+
import org.apache.maven.model.Model;
45
import org.apache.maven.plugin.MojoFailureException;
56
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
67
import org.junit.jupiter.api.Assertions;
@@ -99,7 +100,7 @@ void writeServiceClass() {
99100
mojo.setOutstreamBehaviour(OUTSTREAM_BEHAVIOUR.BYTE);
100101
mojo.setInstreamBehaviour(INSTREAM_BEHAVIOUR.BYTE);
101102
Assertions.assertDoesNotThrow(mojo::writeServiceClass);
102-
Assertions.assertEquals("de.westemeyer:artifact-version-test:1.0.0-SNAPSHOT:My new maven project name:de.westemeyer.service.version:MyServiceClass", mojo.getOutputString().replace("\n", ""));
103+
Assertions.assertEquals("\"de.westemeyer\":\"artifact-version-test\":\"1.0.0-SNAPSHOT\":\"My new maven project name\":\"de.westemeyer.service.version\":\"MyServiceClass\":\"https://www.myproject.com\":null", mojo.getOutputString().replace("\n", ""));
103104
}
104105

105106
@Test
@@ -146,10 +147,13 @@ private MockProject createMockProject() {
146147
build.setOutputDirectory("target/testdir");
147148
project.setBuild(build);
148149
project.readModel(testPom);
149-
project.setArtifactId(project.getModel().getArtifactId());
150-
project.setGroupId(project.getModel().getGroupId());
151-
project.setName(project.getModel().getName());
152-
project.setVersion((project.getModel().getVersion()));
150+
Model model = project.getModel();
151+
project.setArtifactId(model.getArtifactId());
152+
project.setGroupId(model.getGroupId());
153+
project.setName(model.getName());
154+
project.setVersion(model.getVersion());
155+
project.setUrl(model.getUrl());
156+
project.setDescription(model.getDescription());
153157
return project;
154158
}
155159

@@ -164,7 +168,7 @@ private static class MockGenerateServiceMojo extends GenerateServiceMojo {
164168
private OUTSTREAM_BEHAVIOUR outstreamBehaviour = OUTSTREAM_BEHAVIOUR.SUPER;
165169
private INSTREAM_BEHAVIOUR instreamBehaviour = INSTREAM_BEHAVIOUR.SUPER;
166170
private final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
167-
private static final String TEMPLATE = "${groupId}:${artifactId}:${version}:${name}:${package}:${serviceClass}";
171+
private static final String TEMPLATE = "\"${groupId}\":\"${artifactId}\":\"${version}\":\"${name}\":\"${package}\":\"${serviceClass}\":\"${url}\":\"${description}\"";
168172
private final ByteArrayInputStream inputStream = new ByteArrayInputStream(TEMPLATE.getBytes(StandardCharsets.UTF_8));
169173

170174
@Override

src/test/resources/de/westemeyer/plugins/maven/versions/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<version>1.0.0-SNAPSHOT</version>
1010

1111
<name>My new maven project name</name>
12+
<url>https://www.myproject.com</url>
1213

1314
<properties>
1415
<maven.compiler.source>8</maven.compiler.source>

0 commit comments

Comments
 (0)