aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Oehm2011-09-13 08:51:25 (EDT)
committerTobias Oberlies2011-10-07 09:12:35 (EDT)
commitcd1e4c62c445e7593ea2a5965705a6c6fd76a643 (patch)
tree2539d55de539163a2484fde269aeb8a6ee302b1c
parentd767fc5c582eaa9308fec26bd62850176181be5e (diff)
downloadorg.eclipse.tycho-cd1e4c62c445e7593ea2a5965705a6c6fd76a643.zip
org.eclipse.tycho-cd1e4c62c445e7593ea2a5965705a6c6fd76a643.tar.gz
org.eclipse.tycho-cd1e4c62c445e7593ea2a5965705a6c6fd76a643.tar.bz2
357481 tycho-version-plugin should not allow broken version
With the tycho-version-plugin it was possible to change the version to something like 1.2.3_SNAPSHOT, which left you with a broken project (it didnt allow you to change the version back to something valid, like 1.2.3-SNAPSHOT).
-rw-r--r--tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/SetMojo.java6
-rw-r--r--tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java6
-rw-r--r--tycho-release/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/engine/tests/VersionsEngineTest.java12
3 files changed, 23 insertions, 1 deletions
diff --git a/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/SetMojo.java b/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/SetMojo.java
index 7479eb6..bfdcb7e 100644
--- a/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/SetMojo.java
+++ b/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/SetMojo.java
@@ -59,7 +59,11 @@ public class SetMojo extends AbstractMojo {
if (newVersion == null || newVersion.length() == 0) {
throw new MojoExecutionException("Missing required parameter newVersion");
}
-
+ try {
+ VersionsEngine.assertIsOsgiVersion(VersionsEngine.toCanonicalVersion(newVersion));
+ } catch (RuntimeException e) {
+ throw new MojoExecutionException("Invalid version: " + newVersion, e);
+ }
try {
engine.addBasedir(session.getCurrentProject().getBasedir());
diff --git a/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java b/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java
index 1f8ed96..fd13706 100644
--- a/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java
+++ b/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/VersionsEngine.java
@@ -24,6 +24,7 @@ import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.tycho.versions.pom.MutablePomFile;
import org.eclipse.tycho.versions.pom.Profile;
+import org.osgi.framework.Version;
@Component(role = VersionsEngine.class, instantiationStrategy = "per-lookup")
public class VersionsEngine {
@@ -150,6 +151,11 @@ public class VersionsEngine {
return version;
}
+ public static void assertIsOsgiVersion(String version) throws NumberFormatException, IllegalArgumentException,
+ NullPointerException {
+ new Version(version);
+ }
+
public static String toMavenVersion(String version) {
if (version == null) {
return null;
diff --git a/tycho-release/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/engine/tests/VersionsEngineTest.java b/tycho-release/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/engine/tests/VersionsEngineTest.java
index ae8bf44..7c00f71 100644
--- a/tycho-release/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/engine/tests/VersionsEngineTest.java
+++ b/tycho-release/tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/engine/tests/VersionsEngineTest.java
@@ -239,6 +239,18 @@ public class VersionsEngineTest extends PlexusTestCase {
assertBundleManifest(new File(basedir, "bundle"));
}
+ public void testWrongSnapshotVersion() throws Exception {
+ try {
+ VersionsEngine.assertIsOsgiVersion("1.2.3_SNAPSHOT");
+ fail("invalid version accepted");
+ } catch (NumberFormatException e) {
+ }
+ }
+
+ public void testAssertOsgiVersion() {
+ VersionsEngine.assertIsOsgiVersion("1.2.3.qualifier");
+ }
+
private void assertPom(File basedir) throws IOException {
assertFileContent(new File(basedir, "pom.xml"));
}