Skip to content
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

Drop support for Scala 2.10/2.11, bump version to 2.0.0-SNAPSHOT #143

Merged
merged 1 commit into from
Dec 6, 2023
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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Maven generated plugin documentation:
|------------------|--------------------------------------------------------------------------------------------------|
| `1.4.11` | [Plugin Info](http://scoverage.github.io/scoverage-maven-plugin/1.4.11/plugin-info.html) |

##### Prerequisities / limitations
##### Prerequisites / limitations

Plugin is compatible with two Maven Scala compiler plugins:

Expand All @@ -61,20 +61,20 @@ This can be set as project property.
```xml
<project>
<properties>
<scoverage.plugin.version>1.4.11</scoverage.plugin.version>
<scoverage.plugin.version>2.0.0</scoverage.plugin.version>
</properties>
</project>
```


##### Scala version configuration

Plugin supports Scala 2.10.x, 2.11.x, 2.12.x and 2.13.x versions by automatically loading and configuring scalac-scoverage-plugin_2.10, scalac-scoverage-plugin_2.11, scalac-scoverage-plugin_2.12 or scalac-scoverage-plugin_2.13 Scalac SCoverage Plugin artifact. For this to work Scala version has to be set. It can be done by defining `scalaVersion` plugin configuration parameter or `scala.version` project property. Without this setting, coverage will not be calculated.
Plugin supports Scala 2.12.x and 2.13.x versions by automatically loading and configuring matching `scalac-scoverage-plugin` Scalac SCoverage Plugin artifact. For this to work Scala version has to be set. It can be done by defining `scalaVersion` plugin configuration parameter or `scala.version` project property. Without this setting, coverage will not be calculated.

```xml
<project>
<properties>
<scala.version>2.13.8</scala.version>
<scala.version>2.13.12</scala.version>
</properties>
</project>
```
Expand All @@ -90,7 +90,7 @@ or
<artifactId>scoverage-maven-plugin</artifactId>
<version>${scoverage.plugin.version}</version>
<configuration>
<scalaVersion>2.13.8</scalaVersion>
<scalaVersion>2.13.12</scalaVersion>
<!-- other parameters -->
</configuration>
</plugin>
Expand All @@ -113,6 +113,8 @@ The first method is better because once the property is defined it's value can b
</project>
```

For Scala 2.10 and 2.11 support please use Scoverage Maven plugin `1.4.11`.

##### Scalac SCoverage plugin version configuration

Maven SCoverage plugin uses by default the latest version of the [scalac-scoverage-plugin](https://github.com/scoverage/scalac-scoverage-plugin) available on its release day.
Expand All @@ -122,7 +124,7 @@ It can be configured by defining `scalacPluginVersion` plugin configuration para
```xml
<project>
<properties>
<scoverage.scalacPluginVersion>1.4.11</scoverage.scalacPluginVersion>
<scoverage.scalacPluginVersion>2.0.11</scoverage.scalacPluginVersion>
</properties>
</project>
```
Expand All @@ -138,7 +140,7 @@ or
<artifactId>scoverage-maven-plugin</artifactId>
<version>${scoverage.plugin.version}</version>
<configuration>
<scalacPluginVersion>1.4.11</scalacPluginVersion>
<scalacPluginVersion>2.0.11</scalacPluginVersion>
<!-- other parameters -->
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion 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.12-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>SCoverage Maven Plugin</name>
Expand Down
92 changes: 19 additions & 73 deletions src/main/java/org/scoverage/plugin/SCoveragePreCompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class SCoveragePreCompileMojo
*
* @since 1.0.0
*/
@Parameter( property = "scoverage.scalacPluginVersion", defaultValue = "" )
@Parameter( property = "scoverage.scalacPluginVersion", defaultValue = "2.0.11" )
private String scalacPluginVersion;

/**
Expand Down Expand Up @@ -230,15 +230,7 @@ public void execute() throws MojoExecutionException
String resolvedScalaVersion = resolveScalaVersion();
if ( resolvedScalaVersion != null )
{
if ( "2.10".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.10." ) )
{
scalaBinaryVersion = "2.10";
}
else if ( "2.11".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.11." ) )
{
scalaBinaryVersion = "2.11";
}
else if ( "2.12".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.12." ) )
if ( "2.12".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWith( "2.12." ) )
{
scalaBinaryVersion = "2.12";
}
Expand Down Expand Up @@ -426,79 +418,33 @@ private void setProperty( Properties projectProperties, String propertyName, Str
}
}

private ArtifactVersion getScalacPluginVersion() {
if ( scalacPluginVersion == null || scalacPluginVersion.isEmpty()) {
throw new IllegalStateException("scalacPluginVersion is unset.");
} else if ( scalacPluginVersion.startsWith("1.") ) {
throw new IllegalStateException( String.format( "Unsupported scalacPluginVersion \"%s\". Please use scalacPluginVersion 2.0.0+ or use older version of scoverage-maven-plugin", scalacPluginVersion ) );
} else {
return new DefaultArtifactVersion(scalacPluginVersion);
}
}

private List<Artifact> getScalaScoveragePluginArtifacts(String resolvedScalaVersion, String scalaMainVersion )
throws ArtifactNotFoundException, ArtifactResolutionException
{
String resolvedScalacPluginVersion = scalacPluginVersion;
if ( resolvedScalacPluginVersion == null || "".equals( resolvedScalacPluginVersion ) )
{
for ( Artifact artifact : pluginArtifacts )
{
if ( "org.scoverage".equals( artifact.getGroupId() )
&& artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) )
{
resolvedScalacPluginVersion = artifact.getVersion();
break;
}
}
}

// There are 3 cases depending on the version of scalac-scoverage-plugin
// * Version 2.0.0 onwards - 3 artifacts, plugin using resolvedScalaVersion
// * Version 1.4.2 - 1 artifact, plugin using resolvedScalaVersion falling back to scalaMainVersion
// * Version 1.4.1 older - 1 artifact, plugin using scalaMainVersion
//
final ArtifactVersion pluginArtifactVersion = new DefaultArtifactVersion(resolvedScalacPluginVersion);
if(pluginArtifactVersion.getMajorVersion() >= 2) {
List<Artifact> resolvedArtifacts = new ArrayList<>();
resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion, resolvedScalacPluginVersion));
resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-domain_" + scalaMainVersion, resolvedScalacPluginVersion));
resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-serializer_" + scalaMainVersion, resolvedScalacPluginVersion));
return resolvedArtifacts;
} else if (pluginArtifactVersion.getMajorVersion() == 1 && pluginArtifactVersion.getMinorVersion() == 4 && pluginArtifactVersion.getIncrementalVersion() == 2)
{
try
{
return Collections.singletonList(
getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion, resolvedScalacPluginVersion )
);
}
catch ( ArtifactNotFoundException | ArtifactResolutionException e2 )
{
getLog().warn( String.format( "Artifact \"org.scoverage:scalac-scoverage-plugin_%s:%s\" not found, " +
"falling back to \"org.scoverage:scalac-scoverage-plugin_%s:%s\"",
resolvedScalaVersion, resolvedScalacPluginVersion, scalaMainVersion, resolvedScalacPluginVersion ) );
return Collections.singletonList(
getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion, resolvedScalacPluginVersion )
);
}
} else {
return Collections.singletonList(
getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion, resolvedScalacPluginVersion )
);
}
String resolvedScalacPluginVersion = getScalacPluginVersion().toString();
List<Artifact> resolvedArtifacts = new ArrayList<>();
resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion, resolvedScalacPluginVersion));
resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-domain_" + scalaMainVersion, resolvedScalacPluginVersion));
resolvedArtifacts.add(getResolvedArtifact("org.scoverage", "scalac-scoverage-serializer_" + scalaMainVersion, resolvedScalacPluginVersion));
return resolvedArtifacts;
}

private Artifact getScalaScoverageRuntimeArtifact( String scalaMainVersion )
throws ArtifactNotFoundException, ArtifactResolutionException
{
String resolvedScalacRuntimeVersion = scalacPluginVersion;
if ( resolvedScalacRuntimeVersion == null || "".equals( resolvedScalacRuntimeVersion ) )
{
for ( Artifact artifact : pluginArtifacts )
{
if ( "org.scoverage".equals( artifact.getGroupId() )
&& artifact.getArtifactId().startsWith( "scalac-scoverage-plugin_" ) )
{
resolvedScalacRuntimeVersion = artifact.getVersion();
break;
}
}
}

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

/**
Expand Down