Skip to content

Commit

Permalink
Merge pull request #15 from SimY4/master
Browse files Browse the repository at this point in the history
Allow RC and milestone releases
  • Loading branch information
nathanalderson committed Nov 19, 2018
2 parents 8988d7d + a095aa1 commit b0c3a40
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 32 deletions.
7 changes: 4 additions & 3 deletions src/main/groovy/com/adtran/ScalaMultiVersionPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class ScalaMultiVersionPlugin implements Plugin<Project> {
}

private boolean validateScalaVersion(String scalaVersion) {
def m = scalaVersion =~ /\d+\.\d+\.\d+/
def m = scalaVersion =~ /\d+\.\d+\.\d+(-(RC|M)\d+)?/
return m.matches()
}

private String scalaVersionToSuffix(String scalaVersion) {
def m = scalaVersion =~ /(\d+\.\d+)\.\d+/
def m = scalaVersion =~ /(\d+\.\d+)\.\d+(-(RC|M)\d+)?/
m.matches()
return "_" + m.group(1)
}
Expand All @@ -67,7 +67,8 @@ class ScalaMultiVersionPlugin implements Plugin<Project> {
if (firstInvalid != null) {
throw new GradleException(
"Invalid scala version '$firstInvalid' in '$propertyName' property. " +
"Please specify full X.Y.Z scala versions.")
"Please specify full X.Y.Z scala versions " +
"(Release Candidate and Milestone versions are also supported).")
}
return versions
} catch (NullPointerException | UnknownPropertyException e) {
Expand Down
75 changes: 47 additions & 28 deletions src/test/groovy/unit/TestScalaMultiVersionPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ class TestScalaMultiVersionPlugin extends GroovyTestCase implements SimpleProjec
}

void testBaseName() {
def project = createProject("2.12.1")
assert project.jar.baseName == "test_2.12"
[ ["2.12.1", "2.12"],
["2.13.0-M5", "2.13"]
].each {
def (ver, base) = it
def project = createProject(ver)
assert project.jar.baseName == "test_$base"
}
}

void testResolutionStrategy() {
Expand All @@ -62,6 +67,8 @@ class TestScalaMultiVersionPlugin extends GroovyTestCase implements SimpleProjec
[ [null, "Must set 'scalaVersions' property."],
["", "Invalid scala version '' in 'scalaVersions' property."],
["2.12", "Invalid scala version '2.12' in 'scalaVersions' property."],
["2.13.0-SNAPSHOT", "Invalid scala version '2.13.0-SNAPSHOT' in 'scalaVersions' property."],
["2.13.0-rc1", "Invalid scala version '2.13.0-rc1' in 'scalaVersions' property."],
].each {
def (scalaVersions, error_msg) = it
def msg = shouldFailWithCause(GradleException) { createProject(scalaVersions) }
Expand All @@ -72,6 +79,8 @@ class TestScalaMultiVersionPlugin extends GroovyTestCase implements SimpleProjec
void testBadDefaultScalaVersions() {
[ ["", "Invalid scala version '' in 'defaultScalaVersions' property."],
["2.12", "Invalid scala version '2.12' in 'defaultScalaVersions' property."],
["2.13.0-SNAPSHOT", "Invalid scala version '2.13.0-SNAPSHOT' in 'defaultScalaVersions' property."],
["2.13.0-rc1", "Invalid scala version '2.13.0-rc1' in 'defaultScalaVersions' property."],
].each {
def (ver, error_msg) = it
def msg = shouldFailWithCause(GradleException) {
Expand All @@ -85,41 +94,46 @@ class TestScalaMultiVersionPlugin extends GroovyTestCase implements SimpleProjec
}

void testSingleVersion() {
def project = createProject("2.12.1")
assert project.ext.scalaVersions == ["2.12.1"]
assert project.ext.scalaVersion == "2.12.1"
assert project.ext.scalaSuffix == "_2.12"
[ ["2.12.1", "_2.12"],
["2.13.0-M5", "_2.13"]
].each {
def (ver, base) = it
def project = createProject(ver)
assert project.ext.scalaVersions == [ver]
assert project.ext.scalaVersion == ver
assert project.ext.scalaSuffix == base
}
}

void testMultipleVersions() {
// comma-separated lists, with or without whitespace, should be allowed
["2.12.1,2.11.8", "2.12.1, 2.11.8"].each {
["2.13.0-M5,2.12.1,2.11.8", "2.13.0-M5, 2.12.1, 2.11.8"].each {
def project = createProject(it)
assert project.ext.scalaVersions == ["2.12.1", "2.11.8"]
assert project.ext.scalaVersion == "2.12.1"
assert project.ext.scalaSuffix == "_2.12"
assert project.gradle.startParameter.taskNames == [":recurseWithScalaVersion_2.11.8"]
assert project.ext.scalaVersions == ["2.13.0-M5", "2.12.1", "2.11.8"]
assert project.ext.scalaVersion == "2.13.0-M5"
assert project.ext.scalaSuffix == "_2.13"
assert project.gradle.startParameter.taskNames == [":recurseWithScalaVersion_2.12.1", ":recurseWithScalaVersion_2.11.8"]
}
}

void testDefaultScalaVersions() {
def project = createProject("2.12.1,2.11.8") {
def project = createProject("2.13.0-M5,2.12.1,2.11.8") {
ext.defaultScalaVersions = "2.11.8"
}
assert project.ext.scalaVersion == "2.11.8"
}

void testAllScalaVersions() {
def project = createProject("2.12.1,2.11.8") {
def project = createProject("2.13.0-M5,2.12.1,2.11.8") {
ext.defaultScalaVersions = "2.11.8"
ext.allScalaVersions = true
}
assert project.ext.scalaVersion == "2.12.1"
assert project.gradle.startParameter.taskNames == [":recurseWithScalaVersion_2.11.8"]
assert project.ext.scalaVersion == "2.13.0-M5"
assert project.gradle.startParameter.taskNames == [":recurseWithScalaVersion_2.12.1", ":recurseWithScalaVersion_2.11.8"]
}

void testTasks() {
def versions = ["2.12.1", "2.11.8"]
def versions = ["2.13.0-M5, 2.12.1", "2.11.8"]
def project = createProject(versions.join(","))
project.tasks.withType(GradleBuild).each { assert it.tasks == [] }
versions.tail().each {
Expand All @@ -141,20 +155,25 @@ class TestScalaMultiVersionPlugin extends GroovyTestCase implements SimpleProjec
}

void testMavenPom() {
def project = createProject("2.12.1") {
plugins.apply("maven")
tasks.uploadArchives.repositories.mavenDeployer {
repository(url: "dummyUrl")
[ ["2.12.1", "2.12"],
["2.13.0-M5", "2.13"]
].each {
def (ver, base) = it
def project = createProject(ver) {
plugins.apply("maven")
tasks.uploadArchives.repositories.mavenDeployer {
repository(url: "dummyUrl")
}
}
def pomXml = new StringWriter()
project.tasks.uploadArchives.repositories[0].pom.writeTo(pomXml)
pomXml = pomXml.toString()
assert !pomXml.contains("_%%")
assert !pomXml.contains("%scala_version%")
def root = new XmlSlurper().parseText(pomXml)
assert root.dependencies.'*'.find { it.artifactId == "scala-library" }.version.text() == ver
assert root.dependencies.'*'.find { it.artifactId == "fake-scala-dep_$base" } != null
}
def pomXml = new StringWriter()
project.tasks.uploadArchives.repositories[0].pom.writeTo(pomXml)
pomXml = pomXml.toString()
assert !pomXml.contains("_%%")
assert !pomXml.contains("%scala_version%")
def root = new XmlSlurper().parseText(pomXml)
assert root.dependencies.'*'.find { it.artifactId == "scala-library" }.version.text() == '2.12.1'
assert root.dependencies.'*'.find { it.artifactId == "fake-scala-dep_2.12" } != null
}

}
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion testProjects/simpleProject/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scalaVersions = 2.12.1, 2.11.8
scalaVersions = 2.13.0-M5, 2.12.1, 2.11.8

0 comments on commit b0c3a40

Please sign in to comment.