maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1742695 - in /maven/release/trunk/maven-release-manager/src: main/java/org/apache/maven/shared/release/phase/ main/java/org/apache/maven/shared/release/transform/jdom/ test/java/org/apache/maven/shared/release/transform/jdom/
Date Sat, 07 May 2016 09:38:21 GMT
Author: rfscholte
Date: Sat May  7 09:38:21 2016
New Revision: 1742695

URL: http://svn.apache.org/viewvc?rev=1742695&view=rev
Log:
[MRELEASE-952] Replace JDom as XML transformer
Introduce JDomProperties

Added:
    maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomProperties.java
    maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomPropertiesTest.java
Modified:
    maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
    maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModel.java
    maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomModelTest.java

Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java?rev=1742695&r1=1742694&r2=1742695&view=diff
==============================================================================
--- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
(original)
+++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
Sat May  7 09:38:21 2016
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -316,7 +317,8 @@ public abstract class AbstractRewritePom
         Map<String, Map<String, String>> resolvedSnapshotDependencies =
             releaseDescriptor.getResolvedSnapshotDependencies();
         Model model = project.getModel();
-        Element properties = rootElement.getChild( "properties", namespace );
+        
+        Properties properties = new JDomModel( rootElement ).getProperties();
 
         String parentVersion = rewriteParent( project, new JDomModel( rootElement ), mappedVersions,
                                               resolvedSnapshotDependencies, originalVersions
);
@@ -439,8 +441,9 @@ public abstract class AbstractRewritePom
 
     private void rewriteArtifactVersions( Collection<Element> elements, Map<String,
String> mappedVersions,
                                           Map<String, Map<String, String>> resolvedSnapshotDependencies,
-                                          Map<String, String> originalVersions, Model
projectModel, Element properties,
-                                          ReleaseResult result, ReleaseDescriptor releaseDescriptor
)
+                                          Map<String, String> originalVersions, Model
projectModel,
+                                          Properties properties, ReleaseResult result,
+                                          ReleaseDescriptor releaseDescriptor )
         throws ReleaseExecutionException, ReleaseFailureException
     {
         if ( elements == null )
@@ -525,16 +528,16 @@ public abstract class AbstractRewritePom
                     else if ( properties != null )
                     {
                         // version is an expression, check for properties to update instead
-                        Element property = properties.getChild( expression, properties.getNamespace()
);
-                        if ( property != null )
+                        
+                        String propertyValue = properties.getProperty( expression );
+                        
+                        if ( propertyValue != null )
                         {
-                            String propertyValue = property.getTextTrim();
-
                             if ( propertyValue.equals( originalVersion ) )
                             {
                                 logInfo( result, "  Updating " + rawVersion + " to " + mappedVersion
);
                                 // change the property only if the property is the same as
what's in the reactor
-                                JDomUtils.rewriteValue( property, mappedVersion );
+                                properties.setProperty( expression, mappedVersion );
                             }
                             else if ( mappedVersion.equals( propertyValue ) )
                             {

Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModel.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModel.java?rev=1742695&r1=1742694&r2=1742695&view=diff
==============================================================================
--- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModel.java
(original)
+++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomModel.java
Sat May  7 09:38:21 2016
@@ -19,6 +19,8 @@ package org.apache.maven.shared.release.
  * under the License.
  */
 
+import java.util.Properties;
+
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Scm;
@@ -34,7 +36,7 @@ import org.jdom.Text;
  */
 public class JDomModel extends Model
 {
-    private Element project;
+    private final Element project;
     
     public JDomModel( Document document )
     {
@@ -67,6 +69,21 @@ public class JDomModel extends Model
     }
     
     @Override
+    public Properties getProperties()
+    {
+        Element properties = project.getChild( "properties", project.getNamespace() );
+        
+        if ( properties == null )
+        {
+            return null;
+        }
+        else
+        {
+            return new JDomProperties( properties );
+        }
+    }
+    
+    @Override
     public void setScm( Scm scm )
     {
         if ( scm == null )

Added: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomProperties.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomProperties.java?rev=1742695&view=auto
==============================================================================
--- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomProperties.java
(added)
+++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom/JDomProperties.java
Sat May  7 09:38:21 2016
@@ -0,0 +1,161 @@
+package org.apache.maven.shared.release.transform.jdom;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Enumeration;
+import java.util.InvalidPropertiesFormatException;
+import java.util.Properties;
+import java.util.Set;
+
+import org.jdom.Element;
+
+/**
+ * JDom implementation of poms PROPERTIES element
+ * 
+ * @author Robert Scholte
+ * @since 3.0
+ */
+public class JDomProperties extends Properties
+{
+    private final Element properties;
+    
+    public JDomProperties( Element properties )
+    {
+        this.properties = properties;
+    }
+
+    @Override
+    public synchronized Object setProperty( String key, String value )
+    {
+        Element property = properties.getChild( key, properties.getNamespace() );
+        
+        JDomUtils.rewriteValue( property, value );
+        
+        // todo follow specs of Hashtable.put
+        return null;
+    }
+
+    @Override
+    public synchronized void load( Reader reader )
+        throws IOException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public synchronized void load( InputStream inStream )
+        throws IOException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void save( OutputStream out, String comments )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void store( Writer writer, String comments )
+        throws IOException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void store( OutputStream out, String comments )
+        throws IOException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public synchronized void loadFromXML( InputStream in )
+        throws IOException, InvalidPropertiesFormatException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void storeToXML( OutputStream os, String comment )
+        throws IOException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void storeToXML( OutputStream os, String comment, String encoding )
+        throws IOException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String getProperty( String key )
+    {
+        Element property = properties.getChild( key, properties.getNamespace() );
+        
+        if ( property == null )
+        {
+            return null;
+        }
+        else
+        {
+            return property.getTextTrim();
+        }
+    }
+
+    @Override
+    public String getProperty( String key, String defaultValue )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Enumeration<?> propertyNames()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Set<String> stringPropertyNames()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void list( PrintStream out )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void list( PrintWriter out )
+    {
+        throw new UnsupportedOperationException();
+    }
+}

Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomModelTest.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomModelTest.java?rev=1742695&r1=1742694&r2=1742695&view=diff
==============================================================================
--- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomModelTest.java
(original)
+++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomModelTest.java
Sat May  7 09:38:21 2016
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertNul
 import java.io.StringReader;
 
 import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
 import org.apache.maven.model.Scm;
 import org.jdom.Document;
 import org.jdom.Element;

Added: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomPropertiesTest.java
URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomPropertiesTest.java?rev=1742695&view=auto
==============================================================================
--- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomPropertiesTest.java
(added)
+++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom/JDomPropertiesTest.java
Sat May  7 09:38:21 2016
@@ -0,0 +1,157 @@
+package org.apache.maven.shared.release.transform.jdom;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.junit.Test;
+
+public class JDomPropertiesTest
+{
+    private SAXBuilder builder = new SAXBuilder();
+    
+    @Test
+    public void testSetProperty() throws Exception
+    {
+        String content = "<properties></properties>";
+        Element propertiesElm = builder.build( new StringReader( content ) ).getRootElement();
+        assertNull( getProperty( propertiesElm, "KEY" ) );
+
+        // Adding not allowed, prepare properties
+        content = "<properties><KEY>OLD_VALUE</KEY></properties>";
+        propertiesElm = builder.build( new StringReader( content ) ).getRootElement();
+        assertEquals( "OLD_VALUE", getProperty( propertiesElm, "KEY" ) );
+        new JDomProperties( propertiesElm ).setProperty( "KEY", "NEW_VALUE" );
+        assertEquals( "NEW_VALUE", getProperty( propertiesElm, "KEY" ) );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testLoadReader()
+        throws Exception
+    {
+        new JDomProperties( null ).load( (Reader) null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testLoadInputStream()
+        throws Exception
+    {
+        new JDomProperties( null ).load( (InputStream) null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testSave()
+    {
+        new JDomProperties( null ).save( null, null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testStoreWriter()
+        throws Exception
+    {
+        new JDomProperties( null ).store( (Writer) null, null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testStoreOutputStream()
+        throws Exception
+    {
+        new JDomProperties( null ).store( (OutputStream) null, null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testLoadFromXML()
+        throws Exception
+    {
+        new JDomProperties( null ).loadFromXML( null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testStoreToXML()
+        throws Exception
+    {
+        new JDomProperties( null ).storeToXML( null, null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testStoreToXMLEncoded()
+        throws Exception
+    {
+        new JDomProperties( null ).storeToXML( null, null, null );
+    }
+
+    @Test
+    public void testGetProperty() throws Exception
+    {
+        String content = "<properties></properties>";
+        Element propertiesElm = builder.build( new StringReader( content ) ).getRootElement();
+        assertNull( new JDomProperties( propertiesElm ).getProperty( "KEY" ) );
+        
+        content = "<properties><KEY>VALUE</KEY></properties>";
+        propertiesElm = builder.build( new StringReader( content ) ).getRootElement();
+        assertEquals( "VALUE", new JDomProperties( propertiesElm ).getProperty( "KEY" ) );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testGetPropertyDefault()
+    {
+        new JDomProperties( null ).getProperty( null, null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testPropertyNames()
+    {
+        new JDomProperties( null ).propertyNames();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testStringPropertyNames()
+    {
+        new JDomProperties( null ).stringPropertyNames();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testListPrintStream()
+    {
+        new JDomProperties( null ).list( (PrintStream) null );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void testListPrintWriter()
+    {
+        new JDomProperties( null ).list( (PrintWriter) null );
+    }
+    
+    private String getProperty( Element propertiesElm, String key )
+    {
+        return propertiesElm.getChildText( key, propertiesElm.getNamespace() );
+    }
+}



Mime
View raw message