-
Notifications
You must be signed in to change notification settings - Fork 48
Added support for scalac-scoverage-plugin > 2.0.0 #107
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
Changes from 4 commits
213462f
ea48709
63e0174
034e40c
6ec7b6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,14 +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.11</scalac-scoverage-plugin.version> | ||
<scalac-scoverage-plugin.scala.version>2.12.15</scalac-scoverage-plugin.scala.version> | ||
<scalac-scoverage-plugin.version>2.0.7</scalac-scoverage-plugin.version> | ||
<scalac-scoverage-plugin.scala.version>2.13</scalac-scoverage-plugin.scala.version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may have to be pinned to e.g. 2.13.10, to actually work? (going by available maven coordinates) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is only being used by the reporter down below, which doesn't need to be the exact version of Scala, only the binary 2.12, 2.13, or 3. The actual compiler plugin is what needs to be the full version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. referencing that in the variable name would make it unmistakable. |
||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.scoverage</groupId> | ||
<artifactId>scalac-scoverage-plugin_${scalac-scoverage-plugin.scala.version}</artifactId> | ||
<artifactId>scalac-scoverage-reporter_${scalac-scoverage-plugin.scala.version}</artifactId> | ||
<version>${scalac-scoverage-plugin.version}</version> | ||
</dependency> | ||
|
||
|
@@ -264,12 +264,12 @@ under the License. | |
<artifactId>umlgraph</artifactId> | ||
<version>5.6.6</version> | ||
</docletArtifact> | ||
<additionalparam> | ||
<additionalOptions> | ||
-inferrel -inferdep -quiet -hide (java|javax)\..* | ||
-collpackages java\.util\..* -qualify | ||
-postfixpackage -nodefontsize 9 | ||
-nodefontpackagesize 7 | ||
</additionalparam> | ||
</additionalOptions> | ||
</configuration> | ||
</plugin> | ||
|
||
|
@@ -380,7 +380,7 @@ under the License. | |
<configuration> | ||
<signature> | ||
<groupId>org.codehaus.mojo.signature</groupId> | ||
<artifactId>java16</artifactId> | ||
<artifactId>java18</artifactId> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched to targeting Java 1.8 |
||
<version>1.0</version> | ||
</signature> | ||
</configuration> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,19 +22,19 @@ | |||||||||||||||
import java.io.FileOutputStream; | ||||||||||||||||
import java.io.IOException; | ||||||||||||||||
import java.io.OutputStreamWriter; | ||||||||||||||||
import java.util.HashMap; | ||||||||||||||||
import java.util.LinkedHashSet; | ||||||||||||||||
import java.util.List; | ||||||||||||||||
import java.util.Map; | ||||||||||||||||
import java.util.Properties; | ||||||||||||||||
import java.util.Set; | ||||||||||||||||
import java.util.*; | ||||||||||||||||
import java.util.stream.Collectors; | ||||||||||||||||
import java.util.stream.Stream; | ||||||||||||||||
|
||||||||||||||||
import edu.emory.mathcs.backport.java.util.Arrays; | ||||||||||||||||
import org.apache.maven.artifact.Artifact; | ||||||||||||||||
import org.apache.maven.artifact.factory.ArtifactFactory; | ||||||||||||||||
import org.apache.maven.artifact.repository.ArtifactRepository; | ||||||||||||||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; | ||||||||||||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException; | ||||||||||||||||
import org.apache.maven.artifact.resolver.ArtifactResolver; | ||||||||||||||||
import org.apache.maven.artifact.versioning.ArtifactVersion; | ||||||||||||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; | ||||||||||||||||
import org.apache.maven.model.Dependency; | ||||||||||||||||
import org.apache.maven.plugin.AbstractMojo; | ||||||||||||||||
import org.apache.maven.plugin.MojoExecutionException; | ||||||||||||||||
|
@@ -286,20 +286,19 @@ else if ( "2.13".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWi | |||||||||||||||
|
||||||||||||||||
try | ||||||||||||||||
{ | ||||||||||||||||
Artifact pluginArtifact = getScalaScoveragePluginArtifact( resolvedScalaVersion, scalaBinaryVersion ); | ||||||||||||||||
List<Artifact> pluginArtifacts = getScalaScoveragePluginArtifacts( resolvedScalaVersion, scalaBinaryVersion ); | ||||||||||||||||
Artifact runtimeArtifact = getScalaScoverageRuntimeArtifact( scalaBinaryVersion ); | ||||||||||||||||
|
||||||||||||||||
if ( pluginArtifact == null ) | ||||||||||||||||
{ | ||||||||||||||||
return; // scoverage plugin will not be configured | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
addScoverageDependenciesToClasspath( runtimeArtifact ); | ||||||||||||||||
|
||||||||||||||||
String arg = DATA_DIR_OPTION + dataDirectory.getAbsolutePath(); | ||||||||||||||||
String _scalacOptions = quoteArgument( arg ); | ||||||||||||||||
String addScalacArgs = arg; | ||||||||||||||||
|
||||||||||||||||
arg = SOURCE_ROOT_OPTION + project.getBasedir().getAbsolutePath(); | ||||||||||||||||
_scalacOptions = _scalacOptions + SPACE + quoteArgument( arg ); | ||||||||||||||||
addScalacArgs = addScalacArgs + PIPE + arg; | ||||||||||||||||
|
||||||||||||||||
if ( !StringUtils.isEmpty( excludedPackages ) ) | ||||||||||||||||
{ | ||||||||||||||||
arg = EXCLUDED_PACKAGES_OPTION + excludedPackages.replace( "(empty)", "<empty>" ); | ||||||||||||||||
|
@@ -320,11 +319,10 @@ else if ( "2.13".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWi | |||||||||||||||
addScalacArgs = addScalacArgs + PIPE + "-Yrangepos"; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
String _scalacPlugins = | ||||||||||||||||
String.format( "%s:%s:%s", pluginArtifact.getGroupId(), pluginArtifact.getArtifactId(), | ||||||||||||||||
pluginArtifact.getVersion() ); | ||||||||||||||||
String _scalacPlugins = pluginArtifacts.stream() | ||||||||||||||||
.map(x -> String.format("%s:%s:%s", x.getGroupId(), x.getArtifactId(),x.getVersion())).collect(Collectors.joining(" ")); | ||||||||||||||||
|
||||||||||||||||
arg = PLUGIN_OPTION + pluginArtifact.getFile().getAbsolutePath(); | ||||||||||||||||
arg = PLUGIN_OPTION + pluginArtifacts.stream().map(x -> x.getFile().getAbsolutePath()).collect(Collectors.joining(":")); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this platform independent:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samantmaharaj could you amend this change to the PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've pushed that change now. |
||||||||||||||||
addScalacArgs = addScalacArgs + PIPE + arg; | ||||||||||||||||
|
||||||||||||||||
Properties projectProperties = project.getProperties(); | ||||||||||||||||
|
@@ -371,6 +369,7 @@ else if ( "2.13".equals( resolvedScalaVersion ) || resolvedScalaVersion.startsWi | |||||||||||||||
private static final String SCALA_LIBRARY_ARTIFACT_ID = "scala-library"; | ||||||||||||||||
|
||||||||||||||||
private static final String DATA_DIR_OPTION = "-P:scoverage:dataDir:"; | ||||||||||||||||
private static final String SOURCE_ROOT_OPTION = "-P:scoverage:sourceRoot:"; | ||||||||||||||||
private static final String EXCLUDED_PACKAGES_OPTION = "-P:scoverage:excludedPackages:"; | ||||||||||||||||
private static final String EXCLUDED_FILES_OPTION = "-P:scoverage:excludedFiles:"; | ||||||||||||||||
private static final String PLUGIN_OPTION = "-Xplugin:"; | ||||||||||||||||
|
@@ -427,7 +426,7 @@ private void setProperty( Properties projectProperties, String propertyName, Str | |||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
private Artifact getScalaScoveragePluginArtifact( String resolvedScalaVersion, String scalaMainVersion ) | ||||||||||||||||
private List<Artifact> getScalaScoveragePluginArtifacts(String resolvedScalaVersion, String scalaMainVersion ) | ||||||||||||||||
throws ArtifactNotFoundException, ArtifactResolutionException | ||||||||||||||||
{ | ||||||||||||||||
String resolvedScalacPluginVersion = scalacPluginVersion; | ||||||||||||||||
|
@@ -444,22 +443,39 @@ private Artifact getScalaScoveragePluginArtifact( String resolvedScalaVersion, S | |||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
try | ||||||||||||||||
// 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) { | ||||||||||||||||
Comment on lines
+451
to
+452
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I guess something like this would make the failure more evident? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The current behaviour will be to fail to resolve the scoverage compiler plugin for Scala 3 as no plugins are currently published newer than 2.13.10 (Link to MVNRepository here) This will cause a build failure. It's not as nice as explicitly notifying the user. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The artifact version in the test you referenced is the version of the scoverage plugin. The scala version is calculated through That function will default to an explicitly configured scala version or a search for the scala standard library. If I understand correctly, the Scala 3 standard library uses different coordinates from the earlier versions If the user is depending on the scala 3 standard library There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me that sounds like acceptable behavior - @ckipp01 since an explicit scala-3-warning would need explicit scala-3 detection, I would leave that to a separate fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure that would be fine, but I'd for sure want to try to get that in before we attempt to do another release. |
||||||||||||||||
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) | ||||||||||||||||
{ | ||||||||||||||||
return getResolvedArtifact( | ||||||||||||||||
"org.scoverage", "scalac-scoverage-plugin_" + resolvedScalaVersion, | ||||||||||||||||
resolvedScalacPluginVersion ); | ||||||||||||||||
} | ||||||||||||||||
catch ( ArtifactNotFoundException | ArtifactResolutionException e ) | ||||||||||||||||
{ | ||||||||||||||||
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 ) ); | ||||||||||||||||
|
||||||||||||||||
// for scalac-scoverage-plugin versions up to 1.4.1 | ||||||||||||||||
return getResolvedArtifact( | ||||||||||||||||
"org.scoverage", "scalac-scoverage-plugin_" + scalaMainVersion, | ||||||||||||||||
resolvedScalacPluginVersion ); | ||||||||||||||||
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 ) | ||||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.