Make JPA updateable over JBoss Tools Maven JPA
Signed-off-by: Fred Bricon <fbricon@gmail.com>
diff --git a/org.eclipse.m2e.wtp.jpa.feature/p2.inf b/org.eclipse.m2e.wtp.jpa.feature/p2.inf
index f2cbe3b..428fda5 100644
--- a/org.eclipse.m2e.wtp.jpa.feature/p2.inf
+++ b/org.eclipse.m2e.wtp.jpa.feature/p2.inf
@@ -11,3 +11,4 @@
requires.0.name=org.jboss.tools.maven.jpa
requires.0.range=[$version$, $version$]
+update.matchExp=providedCapabilities.exists(pc | pc.namespace \=\= 'org.eclipse.equinox.p2.iu' && (pc.name \=\= 'org.jboss.tools.maven.jpa.feature.feature.group' || pc.name \=\= 'org.eclipse.m2e.wtp.jpa.feature.feature.group' && pc.version < '$version$'))
diff --git a/org.eclipse.m2e.wtp.jpa.feature/pom.xml b/org.eclipse.m2e.wtp.jpa.feature/pom.xml
index b46e354..c40bb52 100644
--- a/org.eclipse.m2e.wtp.jpa.feature/pom.xml
+++ b/org.eclipse.m2e.wtp.jpa.feature/pom.xml
@@ -41,7 +41,24 @@
<artifactRepositoryName>${project.name}</artifactRepositoryName>
</configuration>
</plugin>
- <plugin>
+ <plugin>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <version>1.4</version>
+ <executions>
+ <execution>
+ <id>fix-content</id>
+ <phase>package</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <source>${pom.basedir}/src/main/assembly/fixupdate.groovy</source>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>io.tesla.tycho</groupId>
<artifactId>feature-zip-plugin</artifactId>
<version>0.0.1</version>
diff --git a/org.eclipse.m2e.wtp.jpa.feature/src/main/assembly/fixupdate.groovy b/org.eclipse.m2e.wtp.jpa.feature/src/main/assembly/fixupdate.groovy
new file mode 100644
index 0000000..36b479f
--- /dev/null
+++ b/org.eclipse.m2e.wtp.jpa.feature/src/main/assembly/fixupdate.groovy
@@ -0,0 +1,41 @@
+def updateMatchDefinition(root, oldFeature, newFeature, textContent) {
+ def oldFeatureGroup = "${oldFeature}.feature.feature.group"
+ def featureGroup = "${newFeature}.feature.feature.group"
+ def feature = root.units.unit.find{ it.@id==featureGroup }
+ if (!feature) {
+ println "can't find " + featureGroup
+ return textContent
+ }
+ def version = feature.@version
+ println "Found " + feature.@id + '-' + version
+
+ //Replace update match definition
+ String originalStatement = "<update id='${featureGroup}' range='[0.0.0,$version)' severity='0'/>"
+ matchDefinition = "providedCapabilities.exists(pc | pc.namespace == \"org.eclipse.equinox.p2.iu\" && (pc.name == \"${oldFeatureGroup}\" || pc.name == \"${featureGroup}\" && pc.version < \"${version}\"))"
+ String newStatement = "<update match='$matchDefinition' severity='0'/>"
+ return textContent.replace(originalStatement, newStatement)
+
+}
+
+def basedir = project.basedir.canonicalPath
+def repositoryDir = basedir + "/target/site"
+def contentJar = repositoryDir + "/content.jar"
+def contentDir = basedir + "/target/content.jar/"
+
+def ant = new AntBuilder(); // create an antbuilder
+println 'Unzipping content.jar'
+ant.unzip( src: contentJar, dest:contentDir, overwrite:"true")
+
+println 'Modify content.xml to make m2e-wtp jpa updateable from jboss tools'
+
+File contentXml = new File(contentDir, "content.xml")
+def root = new XmlParser().parseText(contentXml.text)
+
+def newContentText = contentXml.text
+newContentText = updateMatchDefinition(root, "org.jboss.tools.maven.jpa", "org.eclipse.m2e.wtp.jpa", newContentText)
+
+println 'Overwriting content.xml'
+contentXml.text = newContentText
+
+println 'Zipping back customized content.jar'
+ant.zip( destFile: contentJar, baseDir:contentDir)
\ No newline at end of file