@@ -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 ();
0 commit comments