Skip to content

Commit ea45685

Browse files
author
Rob Austin
committed
added ea support to the reference version
1 parent 9af8a23 commit ea45685

3 files changed

Lines changed: 67 additions & 16 deletions

File tree

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
<scope>provided</scope>
6565
</dependency>
6666

67+
68+
<dependency>
69+
<groupId>junit</groupId>
70+
<artifactId>junit</artifactId>
71+
<version>4.11</version>
72+
<scope>test</scope>
73+
</dependency>
74+
75+
6776
</dependencies>
6877

6978
<scm>

src/main/java/software/chronicle/BinaryCompatibilityEnforcerPluginMogo.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void execute() throws MojoExecutionException {
6363
if (finalName.endsWith(".0-SNAPSHOT") || finalName.endsWith(".0")
6464
|| finalName.endsWith("ea0-SNAPSHOT") || finalName.endsWith("ea0"))
6565
return;
66-
66+
6767
try {
6868
checkJavaAPIComplianceCheckerInstalled();
6969
} catch (final MojoExecutionException e) {
@@ -107,25 +107,24 @@ private String referencePath(final String groupId,
107107
String version = project.getVersion();
108108
int i = version.indexOf(".");
109109
if (i != -1) {
110-
i = version.indexOf(".", i + 1);
111-
if (i != -1) {
112-
version = version.substring(0, i);
113-
referenceVersion = version + ".0";
114-
getLog().info("setting referenceVersion=" + referenceVersion);
115-
try {
116-
pathToJar1 = downloadArtifact(groupId,
117-
artifactId,
118-
referenceVersion,
119-
outputDirectory).getAbsolutePath();
120-
} catch (final Exception e) {
121-
throw new MojoExecutionException(String.format("Please set <referenceVersion> config, " +
122-
"can not download default version=%s of %s", referenceVersion, artifactId), e);
123-
}
124110

125-
}
126111

112+
referenceVersion = calculateDefaultRefVersion(version, i);
113+
getLog().info("setting referenceVersion=" + referenceVersion);
127114
if (pathToJar1 == null)
128115
throw new MojoExecutionException("Please set <referenceVersion> config");
116+
117+
try {
118+
pathToJar1 = downloadArtifact(groupId,
119+
artifactId,
120+
referenceVersion,
121+
outputDirectory).getAbsolutePath();
122+
123+
} catch (final Exception e) {
124+
throw new MojoExecutionException(String.format("Please set <referenceVersion> config, " +
125+
"can not download default version=%s of %s", referenceVersion, artifactId), e);
126+
}
127+
129128
} else {
130129

131130
pathToJar1 = downloadArtifact(groupId,
@@ -143,6 +142,21 @@ private String referencePath(final String groupId,
143142
}
144143

145144

145+
static String calculateDefaultRefVersion(String version, int indexOfFirstDot) throws MojoExecutionException {
146+
147+
boolean containsES = version.contains("ea");
148+
149+
int indexOfSecondDelimitor = version.indexOf(containsES ? "ea" : ".", indexOfFirstDot + 1);
150+
if (indexOfSecondDelimitor != -1) {
151+
version = version.substring(0, indexOfSecondDelimitor);
152+
return containsES ? version + "ea0" : version + ".0";
153+
}
154+
155+
throw new MojoExecutionException(String.format("Please set <referenceVersion> config, " +
156+
"can not download default version=%s", version));
157+
}
158+
159+
146160
private File downloadArtifact(final String group, final String artifactId, final String version, final String target) throws MojoExecutionException {
147161
final File tempFile = new File(target, artifactId + "-" + version + ".jar");
148162
tempFile.delete();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package software.chronicle;
2+
3+
4+
import org.apache.maven.plugin.MojoExecutionException;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
import static software.chronicle.BinaryCompatibilityEnforcerPluginMogo.calculateDefaultRefVersion;
9+
10+
public class BinaryCompatibilityEnforcerPluginMogoTest {
11+
12+
@Test
13+
public void test() throws MojoExecutionException {
14+
assertEquals("1.2.0", test("1.2.3"));
15+
assertEquals("1.2.0", test("1.2.3-SNAPSHOT"));
16+
assertEquals("1.2.0", test("1.2.99-SNAPSHOT"));
17+
assertEquals("1.2.0", test("1.2.0-SNAPSHOT"));
18+
assertEquals("1.3.0", test("1.3.0-SNAPSHOT"));
19+
20+
assertEquals("1.2ea0", test("1.2ea3"));
21+
assertEquals("1.2ea0", test("1.2ea4-SNAPSHOT"));
22+
23+
}
24+
25+
private String test(String version) throws MojoExecutionException {
26+
return calculateDefaultRefVersion(version, version.indexOf("."));
27+
}
28+
}

0 commit comments

Comments
 (0)