You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2018/07/18 22:50:59 UTC
[isis] 03/05: ISIS-1810: updates script to recreate archetypes
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 003b3c5f27b9f8ca10593d41c9054b3c64f18324
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jul 18 23:16:41 2018 +0200
ISIS-1810: updates script to recreate archetypes
pass in -Drevision=...
overwrite revision and isis.version properties in the archetype-resources/pom.xml
simplify groovy
---
scripts/recreate-archetype.sh | 6 +-
scripts/updateGeneratedArchetypeSources.groovy | 160 ++++++++-----------------
2 files changed, 52 insertions(+), 114 deletions(-)
diff --git a/scripts/recreate-archetype.sh b/scripts/recreate-archetype.sh
index e58ea51..9c382b2 100755
--- a/scripts/recreate-archetype.sh
+++ b/scripts/recreate-archetype.sh
@@ -63,8 +63,8 @@ for a in .project .classpath .settings bin .idea neo4j_DB target-ide; do /bin/fi
/bin/find . -name "*.log" -exec rm {} \;
/bin/find . -name "pom.xml.*" -exec rm {} \;
-echo "mvn archetype:create-from-project ..."
-mvn org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project
+echo "mvn -Drevision=$ISISREL archetype:create-from-project ..."
+mvn -Drevision=$ISISREL org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project
echo "copy over Dockerfile since seems to be excluded for some reason ... "
mkdir -p target/generated-sources/archetype/src/main/resources/archetype-resources/webapp/src/main/resources/docker
@@ -91,4 +91,4 @@ git commit -m "$JIRA: recreating $ISISCPN archetype"
echo "building the newly created archetype ..."
cd ../../archetype/$ISISCPN
-mvn clean install
+mvn -Drevision=$ISISREL clean install
diff --git a/scripts/updateGeneratedArchetypeSources.groovy b/scripts/updateGeneratedArchetypeSources.groovy
index 275f426..357af14 100644
--- a/scripts/updateGeneratedArchetypeSources.groovy
+++ b/scripts/updateGeneratedArchetypeSources.groovy
@@ -16,15 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-import groovy.xml.XmlUtil
-
-import javax.xml.transform.OutputKeys
-import javax.xml.transform.Transformer
-import javax.xml.transform.TransformerFactory
-import javax.xml.transform.stream.StreamResult
-import javax.xml.transform.stream.StreamSource
-
-
def cli = new CliBuilder(usage: 'updateGeneratedArchetypeSources.groovy -n [name] -v [version]')
cli.with {
n(longOpt: 'name', args: 1, required: true, argName: 'name', 'Application name (eg \'simpleapp\' or \'helloworld\')')
@@ -41,26 +32,6 @@ cli.with {
def BASE="target/generated-sources/archetype/"
def ROOT=BASE + "src/main/resources/"
-def license_using_xml_comments="""<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-"""
def supplemental_models_text="""<?xml version="1.0" encoding="UTF-8"?>
<!--
@@ -104,6 +75,8 @@ if (!options) {
application_name=options.n
isis_version=options.v
+println "isis_version = ${isis_version}"
+
/////////////////////////////////////////////////////
//
// update archetype's own pom.xml's groupId
@@ -114,10 +87,8 @@ def pomFile=new File(BASE+"pom.xml")
println "updating ${pomFile.path}"
-// read file, ignoring XML pragma
-def pomFileText = stripXmlPragma(pomFile)
+def pomXml = new XmlSlurper(false,false).parseText(pomFile.text)
-def pomXml = new XmlSlurper(false,true).parseText(pomFileText)
pomXml.appendNode {
parent {
groupId("org.apache.isis.core")
@@ -128,62 +99,33 @@ pomXml.appendNode {
}
pomXml.groupId='org.apache.isis.archetype'
-def fragmentToAdd = new XmlSlurper( false, true ).parseText( '''<properties>
+def fragmentToAdd = new XmlSlurper( false, false ).parseText( '''<properties>
<archetype.test.skip>true</archetype.test.skip>
</properties>''' )
pomXml.appendNode(fragmentToAdd)
-def pomSmb = new groovy.xml.StreamingMarkupBuilder().bind {
- mkp.declareNamespace("":"http://maven.apache.org/POM/4.0.0")
- mkp.yield(pomXml)
-}
+pomFile.text = withLicense(pomXml)
-def pomTempFile = File.createTempFile("temp",".xml")
-def indentedXml = indentXml(pomSmb.toString())
-pomTempFile.text = indentedXml
-def pomXmlText = stripXmlPragma(pomTempFile)
-pomFile.text =
- license_using_xml_comments +
- pomXmlText
+/////////////////////////////////////////////////////
+//
+// update archetype's resource's pom.xml's
+// <revision> and <isis.version>
+//
+/////////////////////////////////////////////////////
+def resourcePomXmlFile=new File(BASE+"src/main/resources/archetype-resources/pom.xml")
+println "updating ${resourcePomXmlFile.path}"
-///////////////////////////////////////////////////////
-////
-//// update archetype's resource's dom/pom.xml's activeByDefault=true
-////
-///////////////////////////////////////////////////////
-//
-//def pomDomFile=new File(BASE+"src/main/resources/archetype-resources/dom/pom.xml")
-//
-//println "updating ${pomDomFile.path}"
-//
-//// read file, ignoring XML pragma
-//def pomDomFileText = stripXmlPragma(pomDomFile)
-//
-//def pomDomXml = new XmlSlurper(false,true).parseText(pomDomFileText)
-//
-//pomDomXml.profiles.profile.activation.activeByDefault='true'
-//
-//def pomDomSmb = new groovy.xml.StreamingMarkupBuilder().bind {
-// mkp.declareNamespace("":"http://maven.apache.org/POM/4.0.0")
-// mkp.yield(pomDomXml)
-//}
-//
-//
-//def pomDomTempFile = File.createTempFile("temp",".xml")
-//def indentedDomXml = indentXml(pomDomSmb.toString())
-//pomDomTempFile.text = indentedDomXml
-//def pomDomXmlText = stripXmlPragma(pomDomTempFile)
-//
-//
-//pomDomFile.text =
-// license_using_xml_comments +
-// pomDomXmlText
+def resourcePomXml = new XmlSlurper(false,false).parseText(resourcePomXmlFile.text)
+resourcePomXml.properties.revision='0.0.1-SNAPSHOT'
+resourcePomXml.properties['isis.version']=isis_version
+
+resourcePomXmlFile.text = withLicense(resourcePomXml)
/////////////////////////////////////////////////////
@@ -197,31 +139,16 @@ def metaDataFile=new File(ROOT+"META-INF/maven/archetype-metadata.xml")
println "updating ${metaDataFile.path}"
+def metaDataXml = new XmlSlurper(false,false).parseText(metaDataFile.text)
-// read file, ignoring XML pragma
-def metaDataFileText = stripXmlPragma(metaDataFile)
-
-def metaDataXml = new XmlSlurper().parseText(metaDataFileText)
metaDataXml.modules.module.fileSets.fileSet.each { fileSet ->
if(fileSet.directory=='ide/eclipse') {
fileSet.@filtered='true'
}
}
-def metaDataSmb = new groovy.xml.StreamingMarkupBuilder().bind {
- mkp.xmlDeclaration()
- mkp.declareNamespace("":"http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0")
- mkp.yield(metaDataXml)
-}
-
-def tempFile = File.createTempFile("temp",".xml")
-tempFile.text = indentXml(metaDataSmb.toString())
-def metaDataXmlText = stripXmlPragma(tempFile)
-
-metaDataFile.text =
- license_using_xml_comments +
- metaDataXmlText
+metaDataFile.text = withLicense(metaDataXml)
/////////////////////////////////////////////////////
@@ -230,13 +157,13 @@ metaDataFile.text =
//
/////////////////////////////////////////////////////
-new File(ROOT+"archetype-resources/").eachDirRecurse() { dir ->
+new File(ROOT+"archetype-resources/").eachDirRecurse() { dir ->
- dir.eachFileMatch(~/.*[.]launch/) { launchFile ->
+ dir.eachFileMatch(~/.*[.]launch/) { launchFile ->
println "updating ${launchFile.path}"
- def launchXml = new XmlSlurper().parseText(launchFile.text)
+ def launchXml = new XmlSlurper(false,false).parseText(launchFile.text)
def projectAttr = launchXml.stringAttribute.find { it.@key=="org.eclipse.jdt.launching.PROJECT_ATTR" }
String oldValue=projectAttr.@value
def newValue = oldValue.replaceAll("${application_name}[^-]*-","\\\${rootArtifactId}-")
@@ -247,7 +174,7 @@ new File(ROOT+"archetype-resources/").eachDirRecurse() { dir ->
#set( \$symbol_escape = '\\' )
"""
launchFile.append(XmlUtil.serialize(launchXml))
- }
+ }
}
@@ -270,20 +197,31 @@ supplementalModelsFile.text = supplemental_models_text
//
///////////////////////////////////////////////////
-String indentXml(xml) {
- def factory = TransformerFactory.newInstance()
- factory.setAttribute("indent-number", 4);
- Transformer transformer = factory.newTransformer()
- transformer.setOutputProperty(OutputKeys.INDENT, 'yes')
- StreamResult result = new StreamResult(new StringWriter())
- transformer.transform(new StreamSource(new ByteArrayInputStream(xml.toString().bytes)), result)
- return result.writer.toString().replaceAll("\\?><", "\\?>\n<")
-}
+String withLicense(pomXml) {
-String stripXmlPragma(File file) {
- def sw = new StringWriter()
- file.filterLine(sw) { ! (it =~ /^\<\?xml/ ) }
- return sw.toString()
-}
+ def license_using_xml_comments="""<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+"""
+ return license_using_xml_comments +
+ groovy.xml.XmlUtil.serialize(pomXml).replaceFirst("<\\?xml version=\"1.0\".*\\?>", "")
+
+}