Author: rhillegas
Date: Thu Oct 7 19:49:38 2010
New Revision: 1005590
URL: http://svn.apache.org/viewvc?rev=1005590&view=rev
Log:
DERBY-2573: Create new ant task to generate release.properties from a passed-in release id.
Added:
db/derby/code/trunk/java/build/org/apache/derbyPreBuild/ReleaseProperties.java (with props)
Modified:
db/derby/code/trunk/build.xml
db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/ProductVersionHolder.java
db/derby/code/trunk/tools/ant/properties/release.properties
Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1005590&r1=1005589&r2=1005590&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Thu Oct 7 19:49:38 2010
@@ -322,6 +322,21 @@
+
+
+ * This ant task creates the release properties needed to define the release id + * when building the Derby distributions. For a description of the Derby release id, + * see http://db.apache.org/derby/papers/versionupgrade.html + *
+ */ + +public class ReleaseProperties extends Task +{ + ///////////////////////////////////////////////////////////////////////// + // + // CONSTANTS + // + ///////////////////////////////////////////////////////////////////////// + + private static final String APACHE_LICENSE_HEADER = + "# Licensed to the Apache Software Foundation (ASF) under one or more\n" + + "# contributor license agreements. See the NOTICE file distributed with\n" + + "# this work for additional information regarding copyright ownership.\n" + + "# The ASF licenses this file to you under the Apache License, Version 2.0\n" + + "# (the \"License\"); you may not use this file except in compliance with\n" + + "# the License. You may obtain a copy of the License at\n" + + "#\n" + + "# http://www.apache.org/licenses/LICENSE-2.0\n" + + "#\n" + + "# Unless required by applicable law or agreed to in writing, software\n" + + "# distributed under the License is distributed on an \"AS IS\" BASIS,\n" + + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + + "# See the License for the specific language governing permissions and\n" + + "# limitations under the License.\n" + + "\n"; + + public final static int MAINT_ENCODING = 1000000; + private final static int MAINT_LENGTH = 7; + + + + ///////////////////////////////////////////////////////////////////////// + // + // STATE + // + ///////////////////////////////////////////////////////////////////////// + + // set by caller. Derby release id of the form "N.N.N.N" or "N.N.N.N beta" + private String _releaseID; + + // set by caller. name of file where release properties will be written + private String _releasePropertiesFileName; + + ///////////////////////////////////////////////////////////////////////// + // + // CONSTRUCTORS + // + ///////////////////////////////////////////////////////////////////////// + + /** + *+ * Let Ant conjure us out of thin air. + *
+ */ + public ReleaseProperties() + {} + + ///////////////////////////////////////////////////////////////////////// + // + // Task BEHAVIOR + // + ///////////////////////////////////////////////////////////////////////// + + + /**Let Ant set the Derby release id, a string of the form N.N.N.N.
*/ + public void setReleaseID( String releaseID ) { _releaseID = releaseID; } + + /**Let Ant set the output file name.
*/ + public void setReleasePropertiesFileName( String fileName ) { _releasePropertiesFileName = fileName; } + + /** + *+ * Create the release properties file from the release id. + *
+ */ + public void execute() + throws BuildException + { + File target = new File( _releasePropertiesFileName ); + FileWriter propertiesFW = null; + PrintWriter propertiesPW = null; + + try { + VersionID versionID = new VersionID( _releaseID ); + int major = versionID.getMajor(); + int minor = versionID.getMinor(); + + propertiesFW = new FileWriter( target ); + propertiesPW = new PrintWriter( propertiesFW ); + + propertiesPW.println( APACHE_LICENSE_HEADER ); + + propertiesPW.println( "drdamaint=0" ); + propertiesPW.println( "maint=" + encodeFixpackAndPoint( versionID ) ); + propertiesPW.println( "major=" + major ); + propertiesPW.println( "minor=" + minor ); + propertiesPW.println( "eversion=" + major + "." + minor ); + propertiesPW.println( "beta=" + versionID.isBeta() ); + propertiesPW.println( "copyright.comment=Copyright 1997, " + getCurrentYear() + " The Apache Software Foundation or its licensors, as applicable." ); + propertiesPW.println( "vendor=The Apache Software Foundation" ) ; + } + catch (Exception e) + { + throw new BuildException( "Could not generate release properties: " + e.getMessage(), e ); + } + finally + { + try { + finishWriting( propertiesFW, propertiesPW ); + } + catch (Exception ex) + { + throw new BuildException( "Error closing file writers.", ex ); + } + } + } + + ///////////////////////////////////////////////////////////////////////// + // + // MINIONS + // + ///////////////////////////////////////////////////////////////////////// + + /** + *+ * Stuff the third and fourth numbers of a Derby release id into the + * encoded format expected by the Derby release machinery. + *
+ */ + private String encodeFixpackAndPoint( VersionID versionID ) + { + int result = ( versionID.getFixpack() * MAINT_ENCODING ) + versionID.getPoint(); + + // the convention is to represent the number as 7 digits even + // if the number is 0 + String retval = Integer.toString( result ); + int length = retval.length(); + + int count = MAINT_LENGTH - length; + for ( int i = 0; i < count; i++ ) { retval = "0" + retval; } + + return retval; + } + + /** + *+ * Get the current year as an int. + *
+ */ + private int getCurrentYear() + { + return Calendar.getInstance().get( Calendar.YEAR ); + } + + /** + *+ * Flush and close file writers. + *
+ */ + private void finishWriting( FileWriter fw, PrintWriter pw ) + throws IOException + { + if ( (fw == null) || (pw == null) ) { return; } + + pw.flush(); + fw.flush(); + + pw.close(); + fw.close(); + } + + ///////////////////////////////////////////////////////////////////////// + // + // INNER CLASSES + // + ///////////////////////////////////////////////////////////////////////// + + public static final class VersionID + { + private int _major; + private int _minor; + private int _fixpack; + private int _point; + private boolean _isBeta = false; + + public VersionID( String text ) + throws BuildException + { + StringTokenizer tokenizer = new StringTokenizer( text, ". " ); + + try { + _major = Integer.parseInt( tokenizer.nextToken() ); + _minor = Integer.parseInt( tokenizer.nextToken() ); + _fixpack = Integer.parseInt( tokenizer.nextToken() ); + _point = Integer.parseInt( tokenizer.nextToken() ); + + if ( tokenizer.hasMoreTokens() ) + { + if ( tokenizer.nextToken().trim().toLowerCase().equals( "beta" ) ) + { _isBeta = true; } + else { throw new Exception( "Illegal trailing token" ); } + } + } + catch (Exception e) { throw badID( text ); } + } + + public int getMajor() { return _major; } + public int getMinor() { return _minor; } + public int getFixpack() { return _fixpack; } + public int getPoint() { return _point; } + public boolean isBeta() { return _isBeta; } + + private BuildException badID( String text ) + { + return new BuildException( "Version id \"" + text + "\" is not a string of the form \"N.N.N.N\" or \"N.N.N.N beta\"" ); + } + } + +} + Propchange: db/derby/code/trunk/java/build/org/apache/derbyPreBuild/ReleaseProperties.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/ProductVersionHolder.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/ProductVersionHolder.java?rev=1005590&r1=1005589&r2=1005590&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/ProductVersionHolder.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/ProductVersionHolder.java Thu Oct 7 19:49:38 2010 @@ -119,7 +119,7 @@ public final class ProductVersionHolder private static final String ALPHA = "alpha"; private static final String BETA = "beta"; - public final static int MAINT_ENCODING = 1000000; + public final static int MAINT_ENCODING = org.apache.derbyPreBuild.ReleaseProperties.MAINT_ENCODING; private String productVendorName; private String productName; Modified: db/derby/code/trunk/tools/ant/properties/release.properties URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/ant/properties/release.properties?rev=1005590&r1=1005589&r2=1005590&view=diff ============================================================================== --- db/derby/code/trunk/tools/ant/properties/release.properties (original) +++ db/derby/code/trunk/tools/ant/properties/release.properties Thu Oct 7 19:49:38 2010 @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -#Mon Mar 16 16:46:00 PDT 2009 + drdamaint=0 maint=0000000 major=10