Skip to content

Improve Scala version resolution #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ under the License.
<modelVersion>4.0.0</modelVersion>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.4.2-SNAPSHOT</version>
<version>1.4.11-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>SCoverage Maven Plugin</name>
Expand Down Expand Up @@ -90,13 +90,14 @@ under the License.
<maven.version>2.2.1</maven.version>
<maven-plugin-plugin.version>3.6.0</maven-plugin-plugin.version>

<scalac-scoverage-plugin.version>1.4.1</scalac-scoverage-plugin.version>
<scalac-scoverage-plugin.version>1.4.11</scalac-scoverage-plugin.version>
<scalac-scoverage-plugin.scala.version>2.12.15</scalac-scoverage-plugin.scala.version>
</properties>

<dependencies>
<dependency>
<groupId>org.scoverage</groupId>
<artifactId>scalac-scoverage-plugin_2.12</artifactId>
<artifactId>scalac-scoverage-plugin_${scalac-scoverage-plugin.scala.version}</artifactId>
<version>${scalac-scoverage-plugin.version}</version>
</dependency>

Expand Down Expand Up @@ -245,7 +246,7 @@ under the License.
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<source>1.6</source>
<source>1.8</source>
<detectJavaApiLink>false</detectJavaApiLink>
<subpackages>org.scoverage.plugin</subpackages>
<links>
Expand Down Expand Up @@ -539,8 +540,8 @@ under the License.
<configuration>
<rules>
<requireJavaVersion>
<version>1.6</version>
<message>Java 1.6 or later required.</message>
<version>1.8</version>
<message>Java 1.8 or later required.</message>
</requireJavaVersion>
</rules>
</configuration>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/scoverage/plugin/SCoverageCheckMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

import scala.Tuple2;
import scala.collection.JavaConverters;

import scoverage.Coverage;
Expand Down Expand Up @@ -149,7 +150,8 @@ public void execute() throws MojoFailureException

Coverage coverage = Serializer.deserialize( coverageFile );
List<File> measurementFiles = Arrays.asList( IOUtils.findMeasurementFiles( dataDirectory ) );
scala.collection.Set<Object> measurements = IOUtils.invoked( JavaConverters.asScalaBuffer( measurementFiles ) );
scala.collection.Set<Tuple2<Object, String>> measurements =
IOUtils.invoked( JavaConverters.asScalaBuffer( measurementFiles ) );
coverage.apply( measurements );

int branchCount = coverage.branchCount();
Expand Down
53 changes: 17 additions & 36 deletions src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ public class SCoveragePreCompileMojo
private boolean skip;

/**
* Scala version used for compiler plugin artifact resolution.
* <ul>
* <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>
* <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>
* <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>
* <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>
* <li>if specified, but does not meet any of the above conditions or if not specified - plugin execution will be skipped</li>
* </ul>
* Scala version used for scalac compiler plugin artifact resolution.
*
* @since 1.0.0
*/
Expand Down Expand Up @@ -293,7 +286,7 @@ else if ( "2.13".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWi

try
{
Artifact pluginArtifact = getScalaScoveragePluginArtifact( scalaBinaryVersion, resolvedScalaVersion );
Artifact pluginArtifact = getScalaScoveragePluginArtifact( resolvedScalaVersion, scalaBinaryVersion );
Artifact runtimeArtifact = getScalaScoverageRuntimeArtifact( scalaBinaryVersion );

if ( pluginArtifact == null )
Expand Down Expand Up @@ -434,23 +427,17 @@ private void setProperty( Properties projectProperties, String propertyName, Str
}
}

private Artifact getScalaScoveragePluginArtifact( String scalaMainVersion, String resolvedScalaVersion )
private Artifact getScalaScoveragePluginArtifact( String resolvedScalaVersion, String scalaMainVersion )
throws ArtifactNotFoundException, ArtifactResolutionException
{
Artifact result = null;

String resolvedScalacPluginVersion = scalacPluginVersion;
if ( resolvedScalacPluginVersion == null || "".equals( resolvedScalacPluginVersion ) )
{
for ( Artifact artifact : pluginArtifacts )
{
if ( "org.scoverage".equals( artifact.getGroupId() )
&& "scalac-scoverage-plugin_2.12".equals( artifact.getArtifactId() ) )
&& artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) )
{
if ( "2.12".equals( scalaMainVersion ) )
{
return artifact; // shortcut, use the same artifact plugin uses
}
resolvedScalacPluginVersion = artifact.getVersion();
break;
}
Expand All @@ -459,44 +446,39 @@ private Artifact getScalaScoveragePluginArtifact( String scalaMainVersion, Strin

try
{
// Look for plugin artifact matching the scala version (full form like 2.12.14)
// If not found then look for artifact based on major version like 2.12
result =
getResolvedArtifact( "org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion,
resolvedScalacPluginVersion );
} catch (ArtifactNotFoundException e)
return getResolvedArtifact(
"org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion,
resolvedScalacPluginVersion );
}
catch ( ArtifactNotFoundException | ArtifactResolutionException e )
{
result =
getResolvedArtifact( "org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion,
resolvedScalacPluginVersion );
// for scalac-scoverage-plugin versions up to 1.4.1
return getResolvedArtifact(
"org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion,
resolvedScalacPluginVersion );
}

return result;
}

private Artifact getScalaScoverageRuntimeArtifact( String scalaMainVersion )
throws ArtifactNotFoundException, ArtifactResolutionException
{
Artifact result = null;

String resolvedScalacRuntimeVersion = scalacPluginVersion;
if ( resolvedScalacRuntimeVersion == null || "".equals( resolvedScalacRuntimeVersion ) )
{
for ( Artifact artifact : pluginArtifacts )
{
if ( "org.scoverage".equals( artifact.getGroupId() )
&& "scalac-scoverage-plugin_2.12".equals( artifact.getArtifactId() ) )
&& artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) )
{
resolvedScalacRuntimeVersion = artifact.getVersion();
break;
}
}
}

result =
getResolvedArtifact( "org.scoverage", "scalac-scoverage-runtime_" + scalaMainVersion,
resolvedScalacRuntimeVersion );
return result;
return getResolvedArtifact(
"org.scoverage", "scalac-scoverage-runtime_" + scalaMainVersion,
resolvedScalacRuntimeVersion );
}

/**
Expand All @@ -505,7 +487,6 @@ private Artifact getScalaScoverageRuntimeArtifact( String scalaMainVersion )
* @throws MojoExecutionException
*/
private void addScoverageDependenciesToClasspath( Artifact scalaScoveragePluginArtifact )
throws MojoExecutionException
{
@SuppressWarnings( "unchecked" )
Set<Artifact> set = new LinkedHashSet<Artifact>( project.getDependencyArtifacts() );
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/scoverage/plugin/SCoverageReportMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.codehaus.plexus.util.StringUtils;

import scala.Option;
import scala.Tuple2;
import scala.collection.JavaConverters;
import scala.collection.Seq;

Expand Down Expand Up @@ -422,7 +423,8 @@ private void generateReports()
getLog().info( String.format( "Reading scoverage measurements [%s*]...",
new File( dataDirectory, Constants.MeasurementsPrefix() ).getAbsolutePath() ) );
List<File> measurementFiles = Arrays.asList( IOUtils.findMeasurementFiles( dataDirectory ) );
scala.collection.Set<Object> measurements = IOUtils.invoked( JavaConverters.asScalaBuffer( measurementFiles ) );
scala.collection.Set<Tuple2<Object, String>> measurements =
IOUtils.invoked( JavaConverters.asScalaBuffer( measurementFiles ) );
coverage.apply( measurements );

getLog().info( "Generating coverage reports..." );
Expand Down