Apply snapshot versions to dependencies
diff --git a/src/main/groovy/m4e/PatchCmd.groovy b/src/main/groovy/m4e/PatchCmd.groovy index a554afd..57a998e 100644 --- a/src/main/groovy/m4e/PatchCmd.groovy +++ b/src/main/groovy/m4e/PatchCmd.groovy
@@ -13,6 +13,7 @@ import java.util.regex.Pattern; import groovy.transform.ToString; import m4e.maven.ImportExportDB; +import m4e.p2.Version import m4e.patch.ArtifactRenamer import m4e.patch.DeleteClasses import m4e.patch.DeleteEmptyDirectories @@ -21,6 +22,7 @@ import m4e.patch.OrbitPatch import m4e.patch.PatchLoader import m4e.patch.PatchSet +import m4e.patch.QualifierPatch import m4e.patch.RemoveNonOptional import m4e.patch.StripQualifiers import org.codehaus.groovy.control.CompilerConfiguration; @@ -173,9 +175,35 @@ GlobalPatches globalPatches = new GlobalPatches() void init() { + assert target != null + globalPatches.orbitExclusions << 'org.eclipse.*' set = new PatchSet() + + convertSnapshotVersionsToPatches() + } + + void convertSnapshotVersionsToPatches() { + File snapshotVersionMapping = new File( target, "${MT4E_FOLDER}/${SNAPSHOT_VERSION_MAPPING_FILE}" ) + if( !snapshotVersionMapping.exists() ) { + return + } + + loadSnapshotVersionsFromFile( snapshotVersionMapping ) + } + + void loadSnapshotVersionsFromFile( File snapshotVersionMapping ) { + snapshotVersionMapping.eachLine( UTF_8 ) { + def (shortKey, eclipseVersion, mavenVersion) = it.split( ' ' ) + + String pattern = "${shortKey}:${eclipseVersion}" + globalPatches.qualifierPatches << new QualifierPatch( pattern, mavenVersion ) + + def version = new Version( eclipseVersion ) + pattern = "${shortKey}:[${version.shortVersion()},)" + globalPatches.qualifierPatches << new QualifierPatch( pattern, mavenVersion ) + } } PatchSet deleteClasses = new PatchSet()
diff --git a/src/test/groovy/m4e/PatchCmdTest.groovy b/src/test/groovy/m4e/PatchCmdTest.groovy index 066d077..63c978b 100644 --- a/src/test/groovy/m4e/PatchCmdTest.groovy +++ b/src/test/groovy/m4e/PatchCmdTest.groovy
@@ -21,6 +21,7 @@ public void testGoogleInject() throws Exception { def tool = new PatchCmd() + tool.target = CommonTestCode.newFile( 'testGoogleInject' ) tool.init() tool.loadPatches( 'data/input/googleInject.patch' )
diff --git a/src/test/groovy/m4e/patch/OrbitPatchTest.groovy b/src/test/groovy/m4e/patch/OrbitPatchTest.groovy index f6b646b..4260780 100644 --- a/src/test/groovy/m4e/patch/OrbitPatchTest.groovy +++ b/src/test/groovy/m4e/patch/OrbitPatchTest.groovy
@@ -151,6 +151,7 @@ public void testProfilePatching() throws Exception { def tool = new PatchCmd() + tool.target = CommonTestCode.newFile( 'testProfilePatching' ) tool.init() tool.globalPatches.defaultProfile = 'm4e.orbit'
diff --git a/src/test/groovy/m4e/patch/PatchLoaderTest.groovy b/src/test/groovy/m4e/patch/PatchLoaderTest.groovy index 4e51140..3e211fe 100644 --- a/src/test/groovy/m4e/patch/PatchLoaderTest.groovy +++ b/src/test/groovy/m4e/patch/PatchLoaderTest.groovy
@@ -72,8 +72,12 @@ void loadAndPatch( String fileName ) throws Exception { MopSetup.setup() + + def dir = CommonTestCode.newFile( 'patchLoaderTest' ) + dir.makedirs() PatchCmd cmd = new PatchCmd() + cmd.target = dir cmd.init() cmd.loadPatches( 'patches/eclipse-3.6.2.patches' ) @@ -81,9 +85,6 @@ def file = new File( 'data/input', fileName ) def expectedFile = new File( 'data/expected', fileName ) - def dir = CommonTestCode.newFile( 'patchLoaderTest' ) - dir.makedirs() - def copy = new File( dir, fileName ) file.copy( copy )
diff --git a/src/test/groovy/m4e/patch/StripQualifiersTest.groovy b/src/test/groovy/m4e/patch/StripQualifiersTest.groovy index 8d2f775..c9de3fc 100644 --- a/src/test/groovy/m4e/patch/StripQualifiersTest.groovy +++ b/src/test/groovy/m4e/patch/StripQualifiersTest.groovy
@@ -12,13 +12,14 @@ import static org.junit.Assert.*; import java.io.File; +import m4e.CommonConstants; import m4e.CommonTestCode; import m4e.MopSetup; import m4e.PatchCmd import m4e.Pom; import org.junit.Test; -class StripQualifiersTest { +class StripQualifiersTest extends CommonTestCode implements CommonConstants { @Test public void testNoVersion1() throws Exception { @@ -88,7 +89,7 @@ @Test public void testStripQualifierFromPomVersion() throws Exception { - File target = CommonTestCode.prepareRepo( new File( 'data/input/stripQualifier' ), 'testStripQualifierFromPomVersion/m2repo' ) + File target = prepareRepo( new File( 'data/input/stripQualifier' ), 'testStripQualifierFromPomVersion/m2repo' ) def tool = new PatchCmd( target: target ) tool.init() @@ -113,7 +114,7 @@ org/eclipse/swt/org.eclipse.swt.gtk.linux.x86/3.7.1/org.eclipse.swt.gtk.linux.x86-3.7.1.pom.bak org/eclipse/swt/org.eclipse.swt.gtk.linux.x86/3.7.1/org.eclipse.swt.gtk.linux.x86-3.7.1.sha1 org/eclipse/swt/org.eclipse.swt.gtk.linux.x86/3.7.1/org.eclipse.swt.gtk.linux.x86-3.7.1xxx''' - , CommonTestCode.listFiles( target ) ) + , listFiles( target ) ) File dir = new File( target, 'org/eclipse/swt/org.eclipse.swt.gtk.linux.x86' ) def pom = Pom.load( new File( dir, '3.7.1/org.eclipse.swt.gtk.linux.x86-3.7.1.pom' ) ) @@ -123,7 +124,7 @@ File newDir = new File( dir, pom.version() ) assert newDir.exists() - CommonTestCode.fileEquals( '''\ + fileEquals( '''\ <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> @@ -157,7 +158,7 @@ newDir = new File( dir, pom.version() ) assert newDir.exists() - CommonTestCode.fileEquals( '''\ + fileEquals( '''\ <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> @@ -185,7 +186,7 @@ newDir = new File( dir, pom.version() ) assert newDir.exists() - CommonTestCode.fileEquals( '''\ + fileEquals( '''\ <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> @@ -219,4 +220,42 @@ </project>''', new File( newDir, 'org.apache.batik.dom-1.6.0.pom' ) ) } + + @Test + public void testSnapshotDependencies() throws Exception { + + File target = newFile( 'testSnapshotDependencies' ) + + def file = new File( target, "${MT4E_FOLDER}/${SNAPSHOT_VERSION_MAPPING_FILE}" ) + file.parentFile?.makedirs() + file << "de.itemis.xtext:de.itemis.xtext.typesystem 2.0.5.201205161310 2.0.5-SNAPSHOT\n" + + def tool = new PatchCmd( target: target ) + tool.init() + + tool.loadPatches() + + def input = '''\ +<?xml version="1.0" encoding="UTF-8"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <groupId>com.avanon.eclipse</groupId> + <artifactId>com.avanon.eclipse.pm-dsl</artifactId> + <version>2.2.0-SNAPSHOT</version> + <name>DSL for Parameter Model</name> + <dependencies> + <dependency> + <groupId>de.itemis.xtext</groupId> + <artifactId>de.itemis.xtext.typesystem</artifactId> + <version>[2.0.5,)</version> + </dependency> + </dependencies> +</project>''' + + def pom = Pom.load( input ) + tool.patchPom( pom ) + + assertEquals( input.replace( '<version>[2.0.5,)</version>' ,'<version>2.0.5-SNAPSHOT</version>' ), pom.toString() ) + } }