You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/09/06 13:07:17 UTC

svn commit: r1520537 - in /httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy: HCProject.groovy Line.groovy ReleaseTag.groovy UpgradeVersion.groovy

Author: olegk
Date: Fri Sep  6 11:07:16 2013
New Revision: 1520537

URL: http://svn.apache.org/r1520537
Log:
Added tasks to rewtite POM files for a release tag or a next development cycle

Added:
    httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/ReleaseTag.groovy
    httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/UpgradeVersion.groovy
Modified:
    httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/HCProject.groovy
    httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Line.groovy

Modified: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/HCProject.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/HCProject.groovy?rev=1520537&r1=1520536&r2=1520537&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/HCProject.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/HCProject.groovy Fri Sep  6 11:07:16 2013
@@ -2,6 +2,7 @@ import org.jdom2.Document
 import org.jdom2.Element
 import org.jdom2.Namespace
 import org.jdom2.input.SAXBuilder
+import org.jdom2.output.Format
 import org.jdom2.output.XMLOutputter
 
 /*
@@ -79,7 +80,7 @@ class HCProject {
         SAXBuilder parser = new SAXBuilder()
         Document doc = parser.build(pomFile)
 
-        Namespace ns = Namespace.getNamespace("http://maven.apache.org/POM/4.0.0");
+        Namespace ns = Namespace.getNamespace("http://maven.apache.org/POM/4.0.0")
         Element rootEl = doc.rootElement
         Element parentEl = rootEl.getChild('parent', ns)
         if (parentEl != null) {
@@ -107,7 +108,9 @@ class HCProject {
 
             parentEl.removeChild('relativePath', ns)
 
-            XMLOutputter xmlOutputter = new XMLOutputter()
+            Format format = Format.getRawFormat()
+            format.lineSeparator = Line.DELIM
+            XMLOutputter xmlOutputter = new XMLOutputter(format)
             Writer writer = pomFile.newWriter('UTF-8')
             try {
                 xmlOutputter.output(doc, writer)

Modified: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Line.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Line.groovy?rev=1520537&r1=1520536&r2=1520537&view=diff
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Line.groovy (original)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/Line.groovy Fri Sep  6 11:07:16 2013
@@ -29,6 +29,8 @@ import org.apache.tools.ant.filters.FixC
 
 class Line {
 
+    static DELIM = System.getProperty('line.separator', '\n')
+
     static Class<? extends FilterReader> filter() {
         FixCrLfFilter.class
     }

Added: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/ReleaseTag.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/ReleaseTag.groovy?rev=1520537&view=auto
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/ReleaseTag.groovy (added)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/ReleaseTag.groovy Fri Sep  6 11:07:16 2013
@@ -0,0 +1,137 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.InvalidUserDataException
+import org.gradle.api.tasks.TaskAction
+import org.jdom2.Document
+import org.jdom2.Element
+import org.jdom2.Namespace
+import org.jdom2.input.SAXBuilder
+import org.jdom2.output.Format
+import org.jdom2.output.XMLOutputter
+
+import java.util.regex.Matcher
+
+class ReleaseTag extends DefaultTask {
+
+    File location
+
+    @TaskAction
+    void generate() {
+        if (!location || !location.exists()) {
+            return
+        }
+        rewritePom(location)
+    }
+
+    private static String rewriteLocation(String location, String ver) {
+        Matcher m1 = location =~ '(.*)/trunk'
+        if (m1.find()) {
+            return m1.group(1) + '/' + 'tags/' + ver
+        }
+        Matcher m2 = location =~ '(.*)/branches/[A-Za-z0-9_\\-\\.]'
+        if (m2.find()) {
+            return m2.group(1) + '/' + 'tags/' + ver
+        }
+        location
+    }
+
+    private void rewritePom(File dir) {
+        File pomFile = new File(dir, 'pom.xml')
+        SAXBuilder parser = new SAXBuilder()
+
+        Namespace ns = Namespace.getNamespace("http://maven.apache.org/POM/4.0.0")
+
+        Document maindoc = parser.build(pomFile)
+
+        Element rootEl = maindoc.rootElement
+        Element versionEl = rootEl.getChild('version', ns)
+        if (!versionEl) {
+            throw new InvalidUserDataException("Version not specified")
+        }
+        String ver = versionEl.text
+        if (!ver.endsWith('-SNAPSHOT')) {
+            throw new InvalidUserDataException("${ver}: Snapshot version expected")
+        }
+        ver = ver - '-SNAPSHOT'
+        versionEl.text = ver
+
+        Element scmEl = rootEl.getChild('scm', ns)
+        if (scmEl) {
+            Element connectionEl = scmEl.getChild('connection', ns)
+            if (connectionEl) {
+                connectionEl.text = rewriteLocation(connectionEl.text, ver)
+            }
+            Element devConnectionEl = scmEl.getChild('developerConnection', ns)
+            if (devConnectionEl) {
+                devConnectionEl.text = rewriteLocation(devConnectionEl.text, ver)
+            }
+            Element urlEl = scmEl.getChild('url', ns)
+            if (urlEl) {
+                urlEl.text = rewriteLocation(urlEl.text, ver)
+            }
+        }
+
+        Format format = Format.getRawFormat()
+        format.lineSeparator = Line.DELIM
+
+        Element modulesEl = rootEl.getChild('modules', ns)
+        if (modulesEl) {
+            List<Element> moduleEls = modulesEl.getChildren('module', ns)
+            for (Element moduleEl: moduleEls) {
+                File moduleDir = new File(dir, moduleEl.text)
+                File modulePomFile = new File(moduleDir, 'pom.xml')
+                Document doc = parser.build(modulePomFile)
+                Element moduleParentEl = doc.rootElement.getChild('parent', ns)
+                if (moduleParentEl) {
+                    Element moduleVersionEl = moduleParentEl.getChild('version', ns)
+                    if (moduleVersionEl) {
+                        moduleVersionEl.text = ver
+                    }
+                }
+                XMLOutputter xmlOutputter = new XMLOutputter(format)
+                Writer writer = modulePomFile.newWriter('UTF-8')
+                try {
+                    xmlOutputter.output(doc, writer)
+                } finally {
+                    writer.close()
+                }
+            }
+        }
+
+        XMLOutputter xmlOutputter = new XMLOutputter(format)
+        Writer writer = pomFile.newWriter('UTF-8')
+        try {
+            xmlOutputter.output(maindoc, writer)
+        } finally {
+            writer.close()
+        }
+    }
+
+}

Added: httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/UpgradeVersion.groovy
URL: http://svn.apache.org/viewvc/httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/UpgradeVersion.groovy?rev=1520537&view=auto
==============================================================================
--- httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/UpgradeVersion.groovy (added)
+++ httpcomponents/project-release-tools/trunk/buildSrc/src/main/groovy/UpgradeVersion.groovy Fri Sep  6 11:07:16 2013
@@ -0,0 +1,153 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+import org.apache.maven.artifact.versioning.ArtifactVersion
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion
+import org.gradle.api.DefaultTask
+import org.gradle.api.InvalidUserDataException
+import org.gradle.api.tasks.TaskAction
+import org.jdom2.Document
+import org.jdom2.Element
+import org.jdom2.Namespace
+import org.jdom2.input.SAXBuilder
+import org.jdom2.output.Format
+import org.jdom2.output.XMLOutputter
+
+import java.util.regex.Matcher
+
+class UpgradeVersion extends DefaultTask {
+
+    File location
+
+    @TaskAction
+    void generate() {
+        if (!location || !location.exists()) {
+            return
+        }
+        rewritePom(location)
+    }
+
+    private void rewritePom(File dir) {
+        File pomFile = new File(dir, 'pom.xml')
+        SAXBuilder parser = new SAXBuilder()
+
+        Namespace ns = Namespace.getNamespace("http://maven.apache.org/POM/4.0.0")
+
+        Document maindoc = parser.build(pomFile)
+
+        Element rootEl = maindoc.rootElement
+        Element versionEl = rootEl.getChild('version', ns)
+        if (!versionEl) {
+            throw new InvalidUserDataException("Version not specified")
+        }
+        ArtifactVersion ver = new DefaultArtifactVersion(versionEl.text)
+        int major = ver.majorVersion
+        int minor = ver.minorVersion
+        int patch = ver.incrementalVersion
+        String qualifier = ver.qualifier
+
+        if (qualifier) {
+            if (qualifier == 'SNAPSHOT') {
+                qualifier = null
+            } else if (qualifier.endsWith('-SNAPSHOT')) {
+                qualifier = qualifier - '-SNAPSHOT'
+            }
+        }
+
+        if (qualifier) {
+            Matcher m = qualifier =~ '(alpah|beta|rc)(\\d)'
+            if (m.find()) {
+                int n = Integer.parseInt(m.group(2))
+                qualifier = m.group(1) + (++n)
+            } else {
+                patch++
+            }
+        } else {
+            patch++
+        }
+        StringBuilder buf = new StringBuilder()
+        buf.append(major).append('.').append(minor)
+        if (patch > 0) {
+            buf.append('.').append(patch)
+        }
+        if (qualifier) {
+            buf.append('-').append(qualifier)
+        }
+        buf.append('-SNAPSHOT')
+        String newVer = buf.toString()
+
+        Console console = System.console()
+        if (!console) {
+            throw new IllegalStateException("Console not available")
+        }
+
+        console.println("Enter new project version [defaults to ${newVer}]:")
+        String s = console.readLine()
+        if (s) {
+            newVer = s
+        }
+
+        versionEl.text = newVer
+
+        Format format = Format.getRawFormat()
+        format.lineSeparator = Line.DELIM
+
+        Element modulesEl = rootEl.getChild('modules', ns)
+        if (modulesEl) {
+            List<Element> moduleEls = modulesEl.getChildren('module', ns)
+            for (Element moduleEl: moduleEls) {
+                File moduleDir = new File(dir, moduleEl.text)
+                File modulePomFile = new File(moduleDir, 'pom.xml')
+                Document doc = parser.build(modulePomFile)
+                Element moduleParentEl = doc.rootElement.getChild('parent', ns)
+                if (moduleParentEl) {
+                    Element moduleVersionEl = moduleParentEl.getChild('version', ns)
+                    if (moduleVersionEl) {
+                        moduleVersionEl.text = newVer
+                    }
+                }
+                XMLOutputter xmlOutputter = new XMLOutputter(format)
+                Writer writer = modulePomFile.newWriter('UTF-8')
+                try {
+                    xmlOutputter.output(doc, writer)
+                } finally {
+                    writer.close()
+                }
+            }
+        }
+
+        XMLOutputter xmlOutputter = new XMLOutputter(format)
+        Writer writer = pomFile.newWriter('UTF-8')
+        try {
+            xmlOutputter.output(maindoc, writer)
+        } finally {
+            writer.close()
+        }
+
+    }
+
+}