brett       2004/04/22 00:34:57

  Modified:    changes/src/main/org/apache/maven/changes
                        ReleaseVersion.java
               changes/xdocs changes.xml
  Added:       changes/src/test/org/apache/maven/changes
                        ReleaseVersionTest.java
               changes/src/test-data
                        test-existing-release-current-version-in-cvs.xml
                        
test-existing-release-current-version-released-and-target-version-in-cvs.xml
                        
test-existing-release-current-version-released-and-target-version-released.xml
                        test-existing-release-current-version-released.xml
                        test-existing-release-target-version-in-cvs.xml
                        test-existing-release-target-version-released.xml
                        test-no-versions.xml test-one-unrelated-release.xml
  Log:
  PR: MPCHANGES-7
  fix version handling
  
  Revision  Changes    Path
  1.3       +41 -5     
maven-plugins/changes/src/main/org/apache/maven/changes/ReleaseVersion.java
  
  Index: ReleaseVersion.java
  ===================================================================
  RCS file: 
/home/cvs/maven-plugins/changes/src/main/org/apache/maven/changes/ReleaseVersion.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReleaseVersion.java       2 Mar 2004 15:37:56 -0000       1.2
  +++ ReleaseVersion.java       22 Apr 2004 07:34:56 -0000      1.3
  @@ -39,7 +39,7 @@
           releaseVersion( changesFile, currentVersion, version, dateFormat.format( 
new Date() ) );
       }
   
  -    public static final void releaseVersion( File changesFile, String 
currentVersion, String version, String date )
  +    static final Document transformVersion( File changesFile, String 
currentVersion, String version, String date )
           throws DocumentException, FileNotFoundException, 
UnsupportedEncodingException, IOException
       {
           SAXReader r = new SAXReader();
  @@ -52,18 +52,38 @@
           
           for ( Iterator i = releases.elementIterator( "release" ); i.hasNext(); )
           {
  -            Element e = (Element) i.next();
  +            Element e = ( Element ) i.next();
               
               Attribute v = e.attribute( "version" );
               
               if ( v != null )
               {
                   String text = v.getText();
  +                Attribute d = e.attribute( "date" );
  +                boolean updateRelease = false;
                   if ( text.equals( currentVersion ) || text.equals( version ) )
                   {
  +                    updateRelease = true;
  +                }
  +                if ( updateRelease && d != null )
  +                {
  +                    DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
  +                    try
  +                    {
  +                        dateFormat.parse( d.getText() );
  +                        // date is set correctly
  +                        updateRelease = false;
  +                    }
  +                    catch ( ParseException ex )
  +                    {
  +                        // intentional
  +                    }
  +                }
  +
  +                if ( updateRelease )
  +                {
                       v.setText( version );
   
  -                    Attribute d = e.attribute( "date" );
                       if ( d == null )
                       {
                           e.addAttribute( "date", date );
  @@ -72,10 +92,25 @@
                       {
                           d.setText( date );
                       }
  +                    return doc;
                   }
               }
           }
  -        
  +
  +        // indicates no transform necessary
  +        return null;
  +    }
  +
  +    public static final void releaseVersion( File changesFile, String 
currentVersion, String version, String date )
  +        throws DocumentException, FileNotFoundException, 
UnsupportedEncodingException, IOException
  +    {
  +        Document doc = transformVersion( changesFile, currentVersion, version, date 
);
  +        if ( doc == null )
  +        {
  +            // no transform necessary
  +            return;
  +        }
  +
           // Backup the original first.
           FileUtils.copyFile( changesFile, new File( changesFile + ".backup" ) );
   
  @@ -91,3 +126,4 @@
           writer.write( doc );
       }   
   }
  +
  
  
  
  1.1                  
maven-plugins/changes/src/test/org/apache/maven/changes/ReleaseVersionTest.java
  
  Index: ReleaseVersionTest.java
  ===================================================================
  package org.apache.maven.changes;
  
  /* ====================================================================
   *   Copyright 2001-2004 The Apache Software Foundation.
   *
   *   Licensed 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 junit.framework.TestCase;
  
  import java.io.File;
  import java.util.List;
  
  import org.dom4j.Element;
  import org.dom4j.Document;
  import org.dom4j.io.SAXReader;
  
  /**
   */
  public class ReleaseVersionTest
      extends TestCase
  {
      /**
       * Constructor.
       *
       * @param name Name of the test.
       */
      public ReleaseVersionTest( String name )
      {
          super( name );
      }
  
      public void testExistingReleaseTargetVersionReleased()
          throws Exception
      {
          File changesFile = new File( System.getProperty( "basedir" ), 
"/src/test-data/test-existing-release-target-version-released.xml" );
          Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", 
"2004-04-21" );
  
          assertNull( "check transform required", doc );
  
          SAXReader r = new SAXReader();
  
          doc = r.read( changesFile );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 1 release", 1, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.2", "1.2", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2003-03-23", "2003-03-23", release.attribute( 
"date" ).getText() );
      }
  
      public void testExistingReleaseTargetVersionInCvs()
          throws Exception
      {
          File changesFile = new File( System.getProperty( "basedir" ), 
"/src/test-data/test-existing-release-target-version-in-cvs.xml" );
          Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", 
"2004-04-21" );
  
          assertNotNull( "check transform required", doc );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 1 release", 1, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.2", "1.2", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2004-04-21", "2004-04-21", release.attribute( 
"date" ).getText() );
      }
  
      public void testExistingReleaseCurrentVersionReleasedAndTargetVersionInCvs()
          throws Exception
      {
          File changesFile = new File( System.getProperty( "basedir" ), 
"/src/test-data/test-existing-release-current-version-released-and-target-version-in-cvs.xml"
 );
          Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", 
"2004-04-21" );
  
          assertNotNull( "check transform required", doc );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 2 releases", 2, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.2", "1.2", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2004-04-21", "2004-04-21", release.attribute( 
"date" ).getText() );
  
          release = ( Element ) nodes.get( 1 );
  
          assertEquals( "Check version is 1.1", "1.1", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2003-03-23", "2003-03-23", release.attribute( 
"date" ).getText() );
      }
  
      public void testExistingReleaseCurrentVersionReleasedAndTargetVersionReleased()
          throws Exception
      {
          File changesFile = new File( System.getProperty( "basedir" ), 
"/src/test-data/test-existing-release-current-version-released-and-target-version-released.xml"
 );
          Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", 
"2004-04-21" );
  
          assertNull( "check transform required", doc );
  
          SAXReader r = new SAXReader();
          
          doc = r.read( changesFile );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 2 releases", 2, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.2", "1.2", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2003-03-23", "2003-03-23", release.attribute( 
"date" ).getText() );
  
          release = ( Element ) nodes.get( 1 );
  
          assertEquals( "Check version is 1.1", "1.1", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2002-02-22", "2002-02-22", release.attribute( 
"date" ).getText() );
      }
  
      public void testExistingReleaseCurrentVersionReleased()
          throws Exception
      {
          File changesFile = new File( System.getProperty( "basedir" ), 
"/src/test-data/test-existing-release-current-version-released.xml" );
          Document doc = ReleaseVersion.transformVersion( changesFile, "1.2", "1.2", 
"2004-04-21" );
  
          assertNull( "check transform required", doc );
  
          SAXReader r = new SAXReader();
          
          doc = r.read( changesFile );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 1 release", 1, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.2", "1.2", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2004-04-21", "2003-03-23", release.attribute( 
"date" ).getText() );
      }
  
      public void testExistingReleaseCurrentVersionInCvs()
          throws Exception
      {
          Document doc = ReleaseVersion.transformVersion(
              new File( System.getProperty( "basedir" ), 
"/src/test-data/test-existing-release-current-version-in-cvs.xml" ),
              "1.2-SNAPSHOT", "1.2", "2004-04-21" );
  
          assertNotNull( "check transform required", doc );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 1 release", 1, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.2", "1.2", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2004-04-21", "2004-04-21", release.attribute( 
"date" ).getText() );
      }
  
      public void testOneUnrelatedRelease()
          throws Exception
      {
          File changesFile = new File( System.getProperty( "basedir" ), 
"/src/test-data/test-one-unrelated-release.xml" );
          Document doc = ReleaseVersion.transformVersion( changesFile, "1.2-SNAPSHOT", 
"1.2", "2004-04-21" );
  
          assertNull( "check transform required", doc );
  
          SAXReader r = new SAXReader();
          doc = r.read( changesFile );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 1 releases", 1, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.1", "1.1", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2003-03-23", "2003-03-23", release.attribute( 
"date" ).getText() );
  
          /* assumes addition of elements
          assertNotNull( "check transform required", doc );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check exactly 2 releases", 2, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.2", "1.2", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2004-04-21", "2004-04-21", release.attribute( 
"date" ).getText() );
  
          release = ( Element ) nodes.get( 1 );
          assertEquals( "Check version is 1.1", "1.1", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2003-03-23", "2003-03-23", release.attribute( 
"date" ).getText() );
  */
      }
  
      public void testNoReleases()
          throws Exception
      {
          File changesFile = new File( System.getProperty( "basedir" ), 
"/src/test-data/test-no-versions.xml" );
          Document doc = ReleaseVersion.transformVersion( changesFile, "1.0-SNAPSHOT", 
"1.0", "2004-04-21" );
  
          assertNull( "check transform required", doc );
          SAXReader r = new SAXReader();
          doc = r.read( changesFile );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check no release", 0, nodes.size() );
  
          /* assumes addition of elements
          assertNotNull( "check transform required", doc );
  
          List nodes = doc.selectNodes( "/document/body/release" );
  
          assertEquals( "check only 1 release", 1, nodes.size() );
  
          Element release = ( Element ) nodes.get( 0 );
  
          assertEquals( "Check version is 1.0", "1.0", release.attribute( "version" 
).getText() );
          assertEquals( "Check date is 2004-04-21", "2004-04-21", release.attribute( 
"date" ).getText() );
          */
      }
  }
  
  
  
  
  1.1                  
maven-plugins/changes/src/test-data/test-existing-release-current-version-in-cvs.xml
  
  Index: test-existing-release-current-version-in-cvs.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
      <release version="1.2-SNAPSHOT" date="in CVS">
        <action dev="brett" type="fix" issue="MPCHANGES-7">Don't overwrite 
currentVersion if it already has a release date. Add unit tests.</action>
      </release>
    </body>
  </document>
  
  
  
  1.1                  
maven-plugins/changes/src/test-data/test-existing-release-current-version-released-and-target-version-in-cvs.xml
  
  Index: test-existing-release-current-version-released-and-target-version-in-cvs.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
      <release version="1.2" date="in CVS">
        <action dev="brett" type="fix">Fix something else</action>
      </release>
      <release version="1.1" date="2003-03-23">
        <action dev="brett" type="fix">Fix something</action>
      </release>
    </body>
  </document>
  
  
  
  1.1                  
maven-plugins/changes/src/test-data/test-existing-release-current-version-released-and-target-version-released.xml
  
  Index: test-existing-release-current-version-released-and-target-version-released.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
      <release version="1.2" date="2003-03-23">
        <action dev="brett" type="fix">Fix something else</action>
      </release>
      <release version="1.1" date="2002-02-22">
        <action dev="brett" type="fix">Fix something</action>
      </release>
    </body>
  </document>
  
  
  
  1.1                  
maven-plugins/changes/src/test-data/test-existing-release-current-version-released.xml
  
  Index: test-existing-release-current-version-released.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
      <release version="1.2" date="2003-03-23">
        <action dev="brett" type="fix">Fix something</action>
      </release>
    </body>
  </document>
  
  
  
  1.1                  
maven-plugins/changes/src/test-data/test-existing-release-target-version-in-cvs.xml
  
  Index: test-existing-release-target-version-in-cvs.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
      <release version="1.2" date="in CVS">
        <action dev="brett" type="fix">Fix something</action>
      </release>
    </body>
  </document>
  
  
  
  1.1                  
maven-plugins/changes/src/test-data/test-existing-release-target-version-released.xml
  
  Index: test-existing-release-target-version-released.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
      <release version="1.2" date="2003-03-23">
        <action dev="brett" type="fix">Fix something</action>
      </release>
    </body>
  </document>
  
  
  
  1.1                  maven-plugins/changes/src/test-data/test-no-versions.xml
  
  Index: test-no-versions.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
    </body>
  </document>
  
  
  
  1.1                  
maven-plugins/changes/src/test-data/test-one-unrelated-release.xml
  
  Index: test-one-unrelated-release.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!-- 
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed 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.
   */
   -->
  
  <document>
    <properties>
      <title>Changes plugin changes</title>
      <author email="[EMAIL PROTECTED]">Brett Porter</author>
    </properties>
    <body>
      <release version="1.1" date="2003-03-23">
        <action dev="brett" type="fix" issue="MPCHANGES-7">Don't overwrite 
currentVersion if it already has a release date. Add unit tests.</action>
      </release>
    </body>
  </document>
  
  
  
  1.18      +2 -1      maven-plugins/changes/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/maven-plugins/changes/xdocs/changes.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- changes.xml       20 Apr 2004 19:42:36 -0000      1.17
  +++ changes.xml       22 Apr 2004 07:34:57 -0000      1.18
  @@ -24,7 +24,8 @@
       <author email="[EMAIL PROTECTED]">Vincent Massol</author>
     </properties>
     <body>
  -    <release version="1.4" date="in CVS">
  +    <release version="1.4-SNAPSHOT" date="in CVS">
  +      <action dev="brett" type="fix" issue="MPCHANGES-7">Don't overwrite 
currentVersion if it already has a release date. Add unit tests.</action>
         <action dev="vmassol" type="add" issue="MPCHANGES-5">
           Added documentation for the format of <code>changes.xml</code> file.
         </action>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to