Skip to content

Commit bfccef7

Browse files
committed
Improve Scala version resolution mechanism
Continuation of work done in #95
1 parent be00142 commit bfccef7

File tree

1 file changed

+17
-36
lines changed

1 file changed

+17
-36
lines changed

src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,7 @@ public class SCoveragePreCompileMojo
7777
private boolean skip;
7878

7979
/**
80-
* Scala version used for compiler plugin artifact resolution.
81-
* <ul>
82-
* <li>if specified, and equals {@code 2.10} or starts with {@code 2.10.} - <b>{@code scalac-scoverage-plugin_2.10}</b> will be used</li>
83-
* <li>if specified, and equals {@code 2.11} or starts with {@code 2.11.} - <b>{@code scalac-scoverage-plugin_2.11}</b> will be used</li>
84-
* <li>if specified, and equals {@code 2.12} or starts with {@code 2.12.} - <b>{@code scalac-scoverage-plugin_2.12}</b> will be used</li>
85-
* <li>if specified, and equals {@code 2.13} or starts with {@code 2.13.} - <b>{@code scalac-scoverage-plugin_2.13}</b> will be used</li>
86-
* <li>if specified, but does not meet any of the above conditions or if not specified - plugin execution will be skipped</li>
87-
* </ul>
80+
* Scala version used for scalac compiler plugin artifact resolution.
8881
*
8982
* @since 1.0.0
9083
*/
@@ -293,7 +286,7 @@ else if ( "2.13".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWi
293286

294287
try
295288
{
296-
Artifact pluginArtifact = getScalaScoveragePluginArtifact( scalaBinaryVersion, resolvedScalaVersion );
289+
Artifact pluginArtifact = getScalaScoveragePluginArtifact( resolvedScalaVersion, scalaBinaryVersion );
297290
Artifact runtimeArtifact = getScalaScoverageRuntimeArtifact( scalaBinaryVersion );
298291

299292
if ( pluginArtifact == null )
@@ -434,23 +427,17 @@ private void setProperty( Properties projectProperties, String propertyName, Str
434427
}
435428
}
436429

437-
private Artifact getScalaScoveragePluginArtifact( String scalaMainVersion, String resolvedScalaVersion )
430+
private Artifact getScalaScoveragePluginArtifact( String resolvedScalaVersion, String scalaMainVersion )
438431
throws ArtifactNotFoundException, ArtifactResolutionException
439432
{
440-
Artifact result = null;
441-
442433
String resolvedScalacPluginVersion = scalacPluginVersion;
443434
if ( resolvedScalacPluginVersion == null || "".equals( resolvedScalacPluginVersion ) )
444435
{
445436
for ( Artifact artifact : pluginArtifacts )
446437
{
447438
if ( "org.scoverage".equals( artifact.getGroupId() )
448-
&& "scalac-scoverage-plugin_2.12".equals( artifact.getArtifactId() ) )
439+
&& artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) )
449440
{
450-
if ( "2.12".equals( scalaMainVersion ) )
451-
{
452-
return artifact; // shortcut, use the same artifact plugin uses
453-
}
454441
resolvedScalacPluginVersion = artifact.getVersion();
455442
break;
456443
}
@@ -459,44 +446,39 @@ private Artifact getScalaScoveragePluginArtifact( String scalaMainVersion, Strin
459446

460447
try
461448
{
462-
// Look for plugin artifact matching the scala version (full form like 2.12.14)
463-
// If not found then look for artifact based on major version like 2.12
464-
result =
465-
getResolvedArtifact( "org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion,
466-
resolvedScalacPluginVersion );
467-
} catch (ArtifactNotFoundException e)
449+
return getResolvedArtifact(
450+
"org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion,
451+
resolvedScalacPluginVersion );
452+
}
453+
catch ( ArtifactNotFoundException | ArtifactResolutionException e )
468454
{
469-
result =
470-
getResolvedArtifact( "org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion,
471-
resolvedScalacPluginVersion );
455+
// for scalac-scoverage-plugin versions up to 1.4.1
456+
return getResolvedArtifact(
457+
"org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion,
458+
resolvedScalacPluginVersion );
472459
}
473-
474-
return result;
475460
}
476461

477462
private Artifact getScalaScoverageRuntimeArtifact( String scalaMainVersion )
478463
throws ArtifactNotFoundException, ArtifactResolutionException
479464
{
480-
Artifact result = null;
481-
482465
String resolvedScalacRuntimeVersion = scalacPluginVersion;
483466
if ( resolvedScalacRuntimeVersion == null || "".equals( resolvedScalacRuntimeVersion ) )
484467
{
485468
for ( Artifact artifact : pluginArtifacts )
486469
{
487470
if ( "org.scoverage".equals( artifact.getGroupId() )
488-
&& "scalac-scoverage-plugin_2.12".equals( artifact.getArtifactId() ) )
471+
&& artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) )
489472
{
490473
resolvedScalacRuntimeVersion = artifact.getVersion();
491474
break;
492475
}
493476
}
494477
}
495478

496-
result =
497-
getResolvedArtifact( "org.scoverage", "scalac-scoverage-runtime_" + scalaMainVersion,
498-
resolvedScalacRuntimeVersion );
499-
return result;
479+
return getResolvedArtifact(
480+
"org.scoverage", "scalac-scoverage-runtime_" + scalaMainVersion,
481+
resolvedScalacRuntimeVersion );
500482
}
501483

502484
/**
@@ -505,7 +487,6 @@ private Artifact getScalaScoverageRuntimeArtifact( String scalaMainVersion )
505487
* @throws MojoExecutionException
506488
*/
507489
private void addScoverageDependenciesToClasspath( Artifact scalaScoveragePluginArtifact )
508-
throws MojoExecutionException
509490
{
510491
@SuppressWarnings( "unchecked" )
511492
Set<Artifact> set = new LinkedHashSet<Artifact>( project.getDependencyArtifacts() );

0 commit comments

Comments
 (0)