Skip to content

Commit

Permalink
Added url and description to generated artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
swesteme committed Dec 14, 2021
1 parent e14b961 commit 4d1fc25
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ It is used in combination with the [artifact-version-service](https://github.com
<plugin>
<groupId>de.westemeyer</groupId>
<artifactId>artifact-version-maven-plugin</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
<executions>
<execution>
<goals>
Expand All @@ -47,7 +47,7 @@ It is used in combination with the [artifact-version-service](https://github.com
<dependency>
<groupId>de.westemeyer</groupId>
<artifactId>artifact-version-service</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
</dependency>
</dependencies>
```
Expand All @@ -59,7 +59,7 @@ It is also possible to configure the generator to use target directories and a m
<plugin>
<groupId>de.westemeyer</groupId>
<artifactId>artifact-version-maven-plugin</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
<executions>
<execution>
<goals>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.westemeyer</groupId>
<artifactId>artifact-version-maven-plugin</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>

<name>Maven source code generator for artifact version services.</name>
<description>The artifact-version-maven-plugin is used to automatically generate artifact version information to be collected by ArtifactVersionCollector somewhere in the classpath.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,13 @@ void writeServiceClass() throws MojoFailureException {

// iterate map of template values for replacement
for (Map.Entry<String, String> entry : getTemplateValues().entrySet()) {
// replace values in string
out = out.replace("${" + entry.getKey() + "}", entry.getValue());
String value = entry.getValue();
if (value == null) {
out = out.replace("\"${" + entry.getKey() + "}\"", "null");
} else {
// replace values in string
out = out.replace("${" + entry.getKey() + "}", value);
}
}

// write resulting java source code to output file
Expand All @@ -225,6 +230,8 @@ Map<String, String> getTemplateValues() {
valueMap.put("artifactId", project.getArtifactId());
valueMap.put("version", project.getVersion());
valueMap.put("name", project.getName());
valueMap.put("url", project.getUrl());
valueMap.put("description", project.getDescription());
valueMap.put("timestamp", "" + new Date().getTime());
return valueMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import de.westemeyer.version.service.ArtifactVersionService;
public class ${serviceClass} implements ArtifactVersionService {
@Override
public Artifact getArtifact() {
return new Artifact("${groupId}", "${artifactId}", "${version}", ${timestamp}L, "${name}");
return new Artifact("${groupId}", "${artifactId}", "${version}", ${timestamp}L, "${name}", "${description}", "${url}");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.westemeyer.plugins.maven.versions;

import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -99,7 +100,7 @@ void writeServiceClass() {
mojo.setOutstreamBehaviour(OUTSTREAM_BEHAVIOUR.BYTE);
mojo.setInstreamBehaviour(INSTREAM_BEHAVIOUR.BYTE);
Assertions.assertDoesNotThrow(mojo::writeServiceClass);
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", ""));
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", ""));
}

@Test
Expand Down Expand Up @@ -146,10 +147,13 @@ private MockProject createMockProject() {
build.setOutputDirectory("target/testdir");
project.setBuild(build);
project.readModel(testPom);
project.setArtifactId(project.getModel().getArtifactId());
project.setGroupId(project.getModel().getGroupId());
project.setName(project.getModel().getName());
project.setVersion((project.getModel().getVersion()));
Model model = project.getModel();
project.setArtifactId(model.getArtifactId());
project.setGroupId(model.getGroupId());
project.setName(model.getName());
project.setVersion(model.getVersion());
project.setUrl(model.getUrl());
project.setDescription(model.getDescription());
return project;
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<version>1.0.0-SNAPSHOT</version>

<name>My new maven project name</name>
<url>https://www.myproject.com</url>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down

0 comments on commit 4d1fc25

Please sign in to comment.