copyright changes 2010 to 2011
diff --git a/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/Say.java b/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/Say.java
index 2e8336f..a9366b8 100644
--- a/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/Say.java
+++ b/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/Say.java
@@ -1,128 +1,128 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * egwin - initial implementation, Dec 2009
- * egwin - expanded to add file output and property expansion support, Jan 2010
- * egwin - clean-up and comment
- ******************************************************************************/
-package org.eclipse.persistence.buildtools.ant.taskdefs;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.LogLevel;
-import org.apache.tools.ant.util.FileUtils;
-
-/**
- * This class expanded to do everything Ant's "Echo" class/task does, while also supporting "if=" and "unless="
- * used primarily in debugging builds and for dependency warnings.
- *
- * @author Eric Gwin
- * @since EclipseLink 2.2.0,
- */
-public class Say extends Task {
-
- private String encoding = ""; // encoding to use when writing to file, defaults to platform default
- private String ifProperty; // the name of the property to test; if exist=true, then exec=true
- private String unlessProperty; // the name of the property to test; if exist=true, then exec=false
-
- protected boolean append = false; // whether to append message to file if it exists.
- protected int level = Project.MSG_WARN; // logging level (when to output). Should be: error, warning, info, verbose, or debug.
- protected File outfile = null; // file to write to (standard out if not specified).
- protected String message = ""; // message to print if conditions met.
-
- // The "meat"
- public void execute() throws BuildException {
- if (testIf() && testUnless()) {
- if (outfile == null) {
- log(message, level);
- } else {
- Writer outbuffer = null;
- try {
- String f = outfile.getAbsolutePath();
- if (encoding.length() == 0 || encoding == null) {
- outbuffer = new FileWriter(f, append);
- } else {
- outbuffer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, append), encoding));
- }
- outbuffer.write(message, 0, message.length());
- } catch (IOException e) {
- throw new BuildException(e, getLocation());
- } finally {
- FileUtils.close(outbuffer);
- }
- }
- }
- }
-
- // Conditional printing: if "if=" doesn't exist return "true" for print status
- // otherwise return result of test: "ifProperty" isn't null
- private boolean testIf() {
- if (ifProperty == null || ifProperty.equals("")) {
- return true;
- }
- return getProject().getProperty(ifProperty) != null;
- }
-
- // Conditional printing: if "unless=" doesn't exist return "true" for print status
- // otherwise return result of test: "unlessProperty" is null
- private boolean testUnless() {
- if (unlessProperty == null || unlessProperty.equals("")) {
- return true;
- }
- return getProject().getProperty(unlessProperty) == null;
- }
-
- // allows for property substitution within 'message' string
- public void addText(String singlelinemsg) {
- message = message + getProject().replaceProperties(singlelinemsg);
- }
-
- // Setters
- public void setAppend(boolean append) {
- this.append = append;
- }
-
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- public void setFile(File outfile) {
- this.outfile = outfile;
- }
-
- public void setIf(String c) {
- ifProperty = c;
- }
-
- public void setLevel(SayLevel sayLevel) {
- level = sayLevel.getLevel();
- }
-
- public void setMessage(String singlelinemsg) {
- this.message = singlelinemsg;
- }
-
- public void setUnless(String c) {
- unlessProperty = c;
- }
-
- // innerclass
- public static class SayLevel extends LogLevel {
- }
- }
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * egwin - initial implementation, Dec 2009
+ * egwin - expanded to add file output and property expansion support, Jan 2010
+ * egwin - clean-up and comment
+ ******************************************************************************/
+package org.eclipse.persistence.buildtools.ant.taskdefs;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.LogLevel;
+import org.apache.tools.ant.util.FileUtils;
+
+/**
+ * This class expanded to do everything Ant's "Echo" class/task does, while also supporting "if=" and "unless="
+ * used primarily in debugging builds and for dependency warnings.
+ *
+ * @author Eric Gwin
+ * @since EclipseLink 2.2.0,
+ */
+public class Say extends Task {
+
+ private String encoding = ""; // encoding to use when writing to file, defaults to platform default
+ private String ifProperty; // the name of the property to test; if exist=true, then exec=true
+ private String unlessProperty; // the name of the property to test; if exist=true, then exec=false
+
+ protected boolean append = false; // whether to append message to file if it exists.
+ protected int level = Project.MSG_WARN; // logging level (when to output). Should be: error, warning, info, verbose, or debug.
+ protected File outfile = null; // file to write to (standard out if not specified).
+ protected String message = ""; // message to print if conditions met.
+
+ // The "meat"
+ public void execute() throws BuildException {
+ if (testIf() && testUnless()) {
+ if (outfile == null) {
+ log(message, level);
+ } else {
+ Writer outbuffer = null;
+ try {
+ String f = outfile.getAbsolutePath();
+ if (encoding.length() == 0 || encoding == null) {
+ outbuffer = new FileWriter(f, append);
+ } else {
+ outbuffer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, append), encoding));
+ }
+ outbuffer.write(message, 0, message.length());
+ } catch (IOException e) {
+ throw new BuildException(e, getLocation());
+ } finally {
+ FileUtils.close(outbuffer);
+ }
+ }
+ }
+ }
+
+ // Conditional printing: if "if=" doesn't exist return "true" for print status
+ // otherwise return result of test: "ifProperty" isn't null
+ private boolean testIf() {
+ if (ifProperty == null || ifProperty.equals("")) {
+ return true;
+ }
+ return getProject().getProperty(ifProperty) != null;
+ }
+
+ // Conditional printing: if "unless=" doesn't exist return "true" for print status
+ // otherwise return result of test: "unlessProperty" is null
+ private boolean testUnless() {
+ if (unlessProperty == null || unlessProperty.equals("")) {
+ return true;
+ }
+ return getProject().getProperty(unlessProperty) == null;
+ }
+
+ // allows for property substitution within 'message' string
+ public void addText(String singlelinemsg) {
+ message = message + getProject().replaceProperties(singlelinemsg);
+ }
+
+ // Setters
+ public void setAppend(boolean append) {
+ this.append = append;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public void setFile(File outfile) {
+ this.outfile = outfile;
+ }
+
+ public void setIf(String c) {
+ ifProperty = c;
+ }
+
+ public void setLevel(SayLevel sayLevel) {
+ level = sayLevel.getLevel();
+ }
+
+ public void setMessage(String singlelinemsg) {
+ this.message = singlelinemsg;
+ }
+
+ public void setUnless(String c) {
+ unlessProperty = c;
+ }
+
+ // innerclass
+ public static class SayLevel extends LogLevel {
+ }
+ }
diff --git a/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/SelectBundle.java b/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/SelectBundle.java
index 044311c..a8398f1 100644
--- a/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/SelectBundle.java
+++ b/ant_customizations/src/org/eclipse/persistence/buildtools/ant/taskdefs/SelectBundle.java
@@ -1,240 +1,240 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * SelectBundle
- * property to set
- * basename (bnd, org.eclipse.equinox) required
- * separator (-,_) default to _
- * criterion OSGi selection criteria [1.0,2.0) required
- *
- * Contributors:
- * egwin - initial conception and implementation
- */
-
-package org.eclipse.persistence.buildtools.ant.taskdefs;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.BuildException;
-import org.eclipse.persistence.buildtools.helper.Version;
-
-public class SelectBundle extends Task {
- private boolean includepath = false; // whether to include the path (directory property) in the value of property if selection is successful (default: no)
- private boolean versiononly = false; // whether to return bundle version info only, or full bundle name (default: full bundle name)
- private String criterion = ""; // the OSGi-like criteria used to 'select' the most appropriate jar. for example:(1.0,2.0]
- private String basename = ""; // basename of jar (org.eclipse.persistence.jpa, javax.xml.bind, javax.persistence)
- private String directory = ""; // directory to search for the jar
- private String property = ""; // property to set with filename of 'selected' jar
- private String separator = "_"; // the separator used to differentiate basename and jarversion
- private String suffix = "jar"; // suffix of file to find (default: jar)
-
- private boolean minInclusive = false; // local: whether the 'floor' version is inclusive or not "("=true "["=false
- private boolean maxInclusive = false; // local: whether the 'ceiling' version is inclusive or not "("=true "["=false
- private Version minVersion = null; // local: the value of the "floor" version
- private Version maxVersion = null; // local: the value of the "ceiling" version
- private String version = ""; // the 'version' component of the "bestmatch" string
-
- private void evaluateCriteria() throws BuildException {
- // ()= includes
- // []= up to, not including
- // should be at most 1 ','
- // can have 1 version, or two containing up to four version parts (major.minor.bugfix.qualifier)
- if ( !( criterion == null || criterion.length() == 0)) {
- int endIndex = criterion.length() - 1;
- boolean minSquareBracket = criterion.startsWith("[");
- boolean maxSquareBracket = criterion.endsWith("]");
- boolean minRoundBracket = criterion.startsWith("(");
- boolean maxRoundBracket = criterion.endsWith(")");
- boolean initInt = criterion.substring(0,1).contains("0123456789");
- boolean endInt = criterion.substring(endIndex-1,endIndex).contains("0123456789");
- boolean commapresent = criterion.contains(",");
- // validate beginning of string
- if ( !( minSquareBracket || minRoundBracket || initInt ) )
- throw new BuildException("The criterion attribute must begin with (,[, or a number.", getLocation());
- // validate end of string
- if ( !( maxSquareBracket || maxRoundBracket || endInt ) )
- throw new BuildException("The criterion attribute must end with ),], or a number.", getLocation());
- // validate basic syntax
- if((initInt && !endInt) || (!initInt && endInt) || (!initInt && !commapresent) || (initInt && commapresent) )
- throw new BuildException("The criterion attribute must be a valid OSGi version range string", getLocation());
- // determine "floor" version
- minInclusive = (minSquareBracket || initInt);
- maxInclusive = (maxSquareBracket || endInt);
- //singleton version
- if(initInt) {
- log("evaluateCriteria: Singleton detected", Project.MSG_VERBOSE);
- minVersion = new Version(criterion);
- // an approximation of infinity (high value for major.monor.micro and qualifier)
- maxVersion = new Version("99999.99999.99999.ÿÿÿÿÿÿ");
- }
- // version range
- if(!initInt) {
- log("evaluateCriteria: Range(min:" + criterion.substring(1,criterion.indexOf(',')) + ")", Project.MSG_VERBOSE);
- minVersion = new Version( criterion.substring(1,criterion.indexOf(',')) );
- }
- if(!endInt) {
- log("evaluateCriteria: Range(max:" + criterion.substring(criterion.indexOf(',')+1,endIndex) + ")", Project.MSG_VERBOSE);
- maxVersion = new Version( criterion.substring(criterion.indexOf(',')+1,endIndex) );
- }
- }
- else {
- // criteria not specified. Default is "any version" or "[0.0,infinity]"
- minInclusive = true;
- minVersion = new Version();
- // an approximation of infinity (high value for major.monor.micro and qualifier)
- maxVersion = new Version("99999.99999.99999.ÿÿÿÿÿÿ");
- }
-
- // Debug Logging
- if(minInclusive)
- log("evaluateCriteria: minInclusive(true)", Project.MSG_VERBOSE);
- else
- log("evaluateCriteria: minInclusive(false)", Project.MSG_VERBOSE);
- if(maxInclusive)
- log("evaluateCriteria: maxInclusive(true)", Project.MSG_VERBOSE);
- else
- log("evaluateCriteria: maxInclusive(false)", Project.MSG_VERBOSE);
- log("evaluateCriteria: minVersion(" + minVersion.getIdentifier() + ")", Project.MSG_VERBOSE);
- log("evaluateCriteria: maxVersion(" + maxVersion.getIdentifier() + ")", Project.MSG_VERBOSE);
-
- }
-
- private String matchCriteria() {
- String bestMatch = null; //filename of file selected
- String[] filelist = getListOfFiles(directory);
-
- log("matchCriteria: basename.length='" + Integer.toString(basename.length()) + "'", Project.MSG_VERBOSE);
- log("matchCriteria: separator.length='" + Integer.toString(separator.length()) + "'", Project.MSG_VERBOSE);
- int relativeVersionIndex = basename.length() + separator.length();
- log("matchCriteria: relativeVersionIndex(" + Integer.toString(relativeVersionIndex) + ")", Project.MSG_VERBOSE);
- if( filelist != null ) {
- log("matchCriteria: filelist.length='" + Integer.toString(filelist.length) + "'", Project.MSG_VERBOSE);
- for ( int i=0; i<filelist.length; i++ )
- {
- int versionEndIndex = filelist[i].indexOf("."+suffix);
- log("matchCriteria: versionEndIndex(" + Integer.toString(versionEndIndex)+")", Project.MSG_VERBOSE);
- log("matchCriteria: filelist["+ Integer.toString(i) + "](" + filelist[i] + ")", Project.MSG_VERBOSE);
- // Should add try block to test for version exception
- version = filelist[i].substring(relativeVersionIndex,versionEndIndex);
-
- log("matchCriteria: version string of found file(" + version + ")", Project.MSG_VERBOSE);
- if(version.length()>0){
- if(minInclusive && maxInclusive) {
- if(minVersion.le(version) && maxVersion.ge(version) ){
- bestMatch = filelist[i];
- }
- }
- else if (minInclusive && !maxInclusive){
- if(minVersion.le(version) && maxVersion.gt(version) ){
- bestMatch = filelist[i];
- }
- }
- else if (!minInclusive && maxInclusive){
- if(minVersion.lt(version) && maxVersion.ge(version) ){
- bestMatch = filelist[i];
- }
- }
- else if (!minInclusive && !maxInclusive ){
- if(minVersion.lt(version) && maxVersion.gt(version) ){
- bestMatch = filelist[i];
- }
- }
- log("matchCriteria: Best Match so far(" + bestMatch + ")", Project.MSG_VERBOSE);
- }
- }
- log("matchCriteria: BestMatch(" + bestMatch + ")", Project.MSG_VERBOSE);
- }
- else log("matchCriteria: filelist is null!", Project.MSG_VERBOSE);
- return bestMatch;
- }
-
- private String[] getListOfFiles(String directory) {
- class MyFilter implements FilenameFilter
- {
- public boolean accept(File directory, String filepattern)
- {
- if ( filepattern.startsWith(basename + separator) && filepattern.endsWith("." + suffix) ) return true;
- return false;
- }
- }
- return new java.io.File(directory).list( new MyFilter() );
- }
-
- // The "meat"
- public void execute() throws BuildException {
- if (getProject() == null) {
- throw new IllegalStateException("Project not set!");
- }
- if (basename == null || basename.length() == 0) {
- throw new BuildException("The basename attribute must be present.", getLocation());
- }
- if (directory == null || directory.length() == 0) {
- throw new BuildException("The directory attribute must be present.", getLocation());
- }
- if (property == null || property.length() == 0) {
- throw new BuildException("The property attribute must be present.", getLocation());
- }
- log("execute: ** Evaluate **", Project.MSG_VERBOSE);
- evaluateCriteria();
- log("execute: ** Match **", Project.MSG_VERBOSE);
- String file = matchCriteria();
-
- if( file != null ){
- if (includepath)
- getProject().setNewProperty(property, directory+"/"+file);
- else {
- if (versiononly)
- getProject().setNewProperty(property, version);
- else
- getProject().setNewProperty(property, file);
- }
- }
- log("execute: Search Finished.", Project.MSG_VERBOSE);
- }
-
- // Setters
- public void setIncludepath(boolean includepath) {
- this.includepath = includepath;
- }
-
- public void setVersionOnly(boolean versiononly) {
- this.versiononly = versiononly;
- }
-
- public void setCriterion(String criterion) {
- this.criterion = criterion;
- }
-
- public void setBasename(String basename) {
- this.basename = basename;
- }
-
- public void setDirectory(String directory) {
- this.directory = directory;
- log("setDirectory: directory='" + directory + "'", Project.MSG_VERBOSE);
- }
-
- public void setProperty(String property) {
- this.property = property;
- }
-
- public void setSeparator(String separator) {
- if ( (separator.length() > 1) || (separator.length() == 0) ) {
- throw new BuildException("The separator attribute can only be a single character.", getLocation());
- }
- this.separator = separator;
- }
-
- public void setSuffix(String suffix) {
- this.suffix = suffix;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SelectBundle
+ * property to set
+ * basename (bnd, org.eclipse.equinox) required
+ * separator (-,_) default to _
+ * criterion OSGi selection criteria [1.0,2.0) required
+ *
+ * Contributors:
+ * egwin - initial conception and implementation
+ */
+
+package org.eclipse.persistence.buildtools.ant.taskdefs;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.eclipse.persistence.buildtools.helper.Version;
+
+public class SelectBundle extends Task {
+ private boolean includepath = false; // whether to include the path (directory property) in the value of property if selection is successful (default: no)
+ private boolean versiononly = false; // whether to return bundle version info only, or full bundle name (default: full bundle name)
+ private String criterion = ""; // the OSGi-like criteria used to 'select' the most appropriate jar. for example:(1.0,2.0]
+ private String basename = ""; // basename of jar (org.eclipse.persistence.jpa, javax.xml.bind, javax.persistence)
+ private String directory = ""; // directory to search for the jar
+ private String property = ""; // property to set with filename of 'selected' jar
+ private String separator = "_"; // the separator used to differentiate basename and jarversion
+ private String suffix = "jar"; // suffix of file to find (default: jar)
+
+ private boolean minInclusive = false; // local: whether the 'floor' version is inclusive or not "("=true "["=false
+ private boolean maxInclusive = false; // local: whether the 'ceiling' version is inclusive or not "("=true "["=false
+ private Version minVersion = null; // local: the value of the "floor" version
+ private Version maxVersion = null; // local: the value of the "ceiling" version
+ private String version = ""; // the 'version' component of the "bestmatch" string
+
+ private void evaluateCriteria() throws BuildException {
+ // ()= includes
+ // []= up to, not including
+ // should be at most 1 ','
+ // can have 1 version, or two containing up to four version parts (major.minor.bugfix.qualifier)
+ if ( !( criterion == null || criterion.length() == 0)) {
+ int endIndex = criterion.length() - 1;
+ boolean minSquareBracket = criterion.startsWith("[");
+ boolean maxSquareBracket = criterion.endsWith("]");
+ boolean minRoundBracket = criterion.startsWith("(");
+ boolean maxRoundBracket = criterion.endsWith(")");
+ boolean initInt = criterion.substring(0,1).contains("0123456789");
+ boolean endInt = criterion.substring(endIndex-1,endIndex).contains("0123456789");
+ boolean commapresent = criterion.contains(",");
+ // validate beginning of string
+ if ( !( minSquareBracket || minRoundBracket || initInt ) )
+ throw new BuildException("The criterion attribute must begin with (,[, or a number.", getLocation());
+ // validate end of string
+ if ( !( maxSquareBracket || maxRoundBracket || endInt ) )
+ throw new BuildException("The criterion attribute must end with ),], or a number.", getLocation());
+ // validate basic syntax
+ if((initInt && !endInt) || (!initInt && endInt) || (!initInt && !commapresent) || (initInt && commapresent) )
+ throw new BuildException("The criterion attribute must be a valid OSGi version range string", getLocation());
+ // determine "floor" version
+ minInclusive = (minSquareBracket || initInt);
+ maxInclusive = (maxSquareBracket || endInt);
+ //singleton version
+ if(initInt) {
+ log("evaluateCriteria: Singleton detected", Project.MSG_VERBOSE);
+ minVersion = new Version(criterion);
+ // an approximation of infinity (high value for major.monor.micro and qualifier)
+ maxVersion = new Version("99999.99999.99999.ÿÿÿÿÿÿ");
+ }
+ // version range
+ if(!initInt) {
+ log("evaluateCriteria: Range(min:" + criterion.substring(1,criterion.indexOf(',')) + ")", Project.MSG_VERBOSE);
+ minVersion = new Version( criterion.substring(1,criterion.indexOf(',')) );
+ }
+ if(!endInt) {
+ log("evaluateCriteria: Range(max:" + criterion.substring(criterion.indexOf(',')+1,endIndex) + ")", Project.MSG_VERBOSE);
+ maxVersion = new Version( criterion.substring(criterion.indexOf(',')+1,endIndex) );
+ }
+ }
+ else {
+ // criteria not specified. Default is "any version" or "[0.0,infinity]"
+ minInclusive = true;
+ minVersion = new Version();
+ // an approximation of infinity (high value for major.monor.micro and qualifier)
+ maxVersion = new Version("99999.99999.99999.ÿÿÿÿÿÿ");
+ }
+
+ // Debug Logging
+ if(minInclusive)
+ log("evaluateCriteria: minInclusive(true)", Project.MSG_VERBOSE);
+ else
+ log("evaluateCriteria: minInclusive(false)", Project.MSG_VERBOSE);
+ if(maxInclusive)
+ log("evaluateCriteria: maxInclusive(true)", Project.MSG_VERBOSE);
+ else
+ log("evaluateCriteria: maxInclusive(false)", Project.MSG_VERBOSE);
+ log("evaluateCriteria: minVersion(" + minVersion.getIdentifier() + ")", Project.MSG_VERBOSE);
+ log("evaluateCriteria: maxVersion(" + maxVersion.getIdentifier() + ")", Project.MSG_VERBOSE);
+
+ }
+
+ private String matchCriteria() {
+ String bestMatch = null; //filename of file selected
+ String[] filelist = getListOfFiles(directory);
+
+ log("matchCriteria: basename.length='" + Integer.toString(basename.length()) + "'", Project.MSG_VERBOSE);
+ log("matchCriteria: separator.length='" + Integer.toString(separator.length()) + "'", Project.MSG_VERBOSE);
+ int relativeVersionIndex = basename.length() + separator.length();
+ log("matchCriteria: relativeVersionIndex(" + Integer.toString(relativeVersionIndex) + ")", Project.MSG_VERBOSE);
+ if( filelist != null ) {
+ log("matchCriteria: filelist.length='" + Integer.toString(filelist.length) + "'", Project.MSG_VERBOSE);
+ for ( int i=0; i<filelist.length; i++ )
+ {
+ int versionEndIndex = filelist[i].indexOf("."+suffix);
+ log("matchCriteria: versionEndIndex(" + Integer.toString(versionEndIndex)+")", Project.MSG_VERBOSE);
+ log("matchCriteria: filelist["+ Integer.toString(i) + "](" + filelist[i] + ")", Project.MSG_VERBOSE);
+ // Should add try block to test for version exception
+ version = filelist[i].substring(relativeVersionIndex,versionEndIndex);
+
+ log("matchCriteria: version string of found file(" + version + ")", Project.MSG_VERBOSE);
+ if(version.length()>0){
+ if(minInclusive && maxInclusive) {
+ if(minVersion.le(version) && maxVersion.ge(version) ){
+ bestMatch = filelist[i];
+ }
+ }
+ else if (minInclusive && !maxInclusive){
+ if(minVersion.le(version) && maxVersion.gt(version) ){
+ bestMatch = filelist[i];
+ }
+ }
+ else if (!minInclusive && maxInclusive){
+ if(minVersion.lt(version) && maxVersion.ge(version) ){
+ bestMatch = filelist[i];
+ }
+ }
+ else if (!minInclusive && !maxInclusive ){
+ if(minVersion.lt(version) && maxVersion.gt(version) ){
+ bestMatch = filelist[i];
+ }
+ }
+ log("matchCriteria: Best Match so far(" + bestMatch + ")", Project.MSG_VERBOSE);
+ }
+ }
+ log("matchCriteria: BestMatch(" + bestMatch + ")", Project.MSG_VERBOSE);
+ }
+ else log("matchCriteria: filelist is null!", Project.MSG_VERBOSE);
+ return bestMatch;
+ }
+
+ private String[] getListOfFiles(String directory) {
+ class MyFilter implements FilenameFilter
+ {
+ public boolean accept(File directory, String filepattern)
+ {
+ if ( filepattern.startsWith(basename + separator) && filepattern.endsWith("." + suffix) ) return true;
+ return false;
+ }
+ }
+ return new java.io.File(directory).list( new MyFilter() );
+ }
+
+ // The "meat"
+ public void execute() throws BuildException {
+ if (getProject() == null) {
+ throw new IllegalStateException("Project not set!");
+ }
+ if (basename == null || basename.length() == 0) {
+ throw new BuildException("The basename attribute must be present.", getLocation());
+ }
+ if (directory == null || directory.length() == 0) {
+ throw new BuildException("The directory attribute must be present.", getLocation());
+ }
+ if (property == null || property.length() == 0) {
+ throw new BuildException("The property attribute must be present.", getLocation());
+ }
+ log("execute: ** Evaluate **", Project.MSG_VERBOSE);
+ evaluateCriteria();
+ log("execute: ** Match **", Project.MSG_VERBOSE);
+ String file = matchCriteria();
+
+ if( file != null ){
+ if (includepath)
+ getProject().setNewProperty(property, directory+"/"+file);
+ else {
+ if (versiononly)
+ getProject().setNewProperty(property, version);
+ else
+ getProject().setNewProperty(property, file);
+ }
+ }
+ log("execute: Search Finished.", Project.MSG_VERBOSE);
+ }
+
+ // Setters
+ public void setIncludepath(boolean includepath) {
+ this.includepath = includepath;
+ }
+
+ public void setVersionOnly(boolean versiononly) {
+ this.versiononly = versiononly;
+ }
+
+ public void setCriterion(String criterion) {
+ this.criterion = criterion;
+ }
+
+ public void setBasename(String basename) {
+ this.basename = basename;
+ }
+
+ public void setDirectory(String directory) {
+ this.directory = directory;
+ log("setDirectory: directory='" + directory + "'", Project.MSG_VERBOSE);
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+ public void setSeparator(String separator) {
+ if ( (separator.length() > 1) || (separator.length() == 0) ) {
+ throw new BuildException("The separator attribute can only be a single character.", getLocation());
+ }
+ this.separator = separator;
+ }
+
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+
+}
diff --git a/ant_customizations/src/org/eclipse/persistence/buildtools/helper/Version.java b/ant_customizations/src/org/eclipse/persistence/buildtools/helper/Version.java
index fc7f4c4..800b10b 100644
--- a/ant_customizations/src/org/eclipse/persistence/buildtools/helper/Version.java
+++ b/ant_customizations/src/org/eclipse/persistence/buildtools/helper/Version.java
@@ -1,233 +1,233 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Version
- * class defines OSGi-like behavior to a version object
- * it has an identifier (Major.Minor.Micro.Qualifier) and can compare itself to others
- * it can report its identifier, and its identifier can be set
- *
- * Contributors:
- * egwin - initial conception and implementation
- */
-
-package org.eclipse.persistence.buildtools.helper;
-
-import java.lang.NumberFormatException;
-
-import org.eclipse.persistence.buildtools.helper.VersionException;;
-
-public class Version {
- private String identifier = "0.0";
- private Integer major = 0;
- private Integer minor = 0;
- private Integer micro = 0;
- private String qualifier = "";
-
- private int[] indexList = {0,0,0}; //holds the indexes of the "."s in the identifier string.
-
- // helper
- private String validateIdentifier(String identifier) throws VersionException{
- String validated=identifier;
- boolean error=false;
-
- if ( validated.startsWith(".") ) {
- throw new VersionException("Initial '.' invalids version");
- }
- else {
- if( validated.endsWith(".") ) {
- throw new VersionException("Terminating '.' invalids version");
- }
- else {
- int index = 0;
- int subindex = 0;
- int count = 0;
- int maxindex = validated.lastIndexOf(".");
- while( !error && ( (subindex = validated.substring(index).indexOf(".")) >0 || index<maxindex )) {
- if(count>2 && subindex>0)
- throw new VersionException("Maximum tokens (4) exceeded.");
- else {
- index += subindex;
- indexList[count] = index;
- index++; //increment to point to char after found '.'
- count++;
- }
- }
- }
- }
- return validated;
- }
-
- // setter
- private void setMajor(Integer major) {
- this.major = major;
- }
- private void setMinor(Integer minor) {
- this.minor = minor;
- }
- private void setMicro(Integer micro) {
- this.micro = micro;
- }
- private void setQualifier(String qualifier) {
- this.qualifier = qualifier;
- }
-
- private void setAll(String identifier) throws VersionException{
- // assumes basic validation completed
- try {
- if( identifier != "" ){
- if( indexList[0] > 0 ) {
- setMajor(Integer.valueOf( identifier.substring(0, indexList[0])));
- if( indexList[1] > 0 ) {
- setMinor(Integer.valueOf( identifier.substring(indexList[0]+1, indexList[1])));
- if( indexList[2] > 0 ) {
- setMicro(Integer.valueOf( identifier.substring(indexList[1]+1, indexList[2])));
- setQualifier(identifier.substring(indexList[2]+1));
- }
- else
- setMicro(Integer.valueOf( identifier.substring(indexList[1]+1)));
- }
- else
- setMinor(Integer.valueOf( identifier.substring(indexList[0]+1) ));
- }
- else
- setMajor(Integer.valueOf(identifier));
- }
- } catch ( NumberFormatException e){
- throw new VersionException("A numeric version token is invalid. " + e.getMessage() + " in \"" + identifier + "\".", e);
- }
- String validIdentifier = getMajorStr() + "." + getMinorStr() + "." + getMicroStr();
- if(getQualifier() != null && getQualifier() != "" ) {
- validIdentifier+= "." + getQualifier();
- }
- this.identifier = validIdentifier;
- }
-
- // Public methods
- // constructors
- public Version() {
- }
- public Version(String identifier) {
- setIdentifier(identifier);
- }
-
- // getters
- public Integer getMajorInt() {
- return this.major;
- }
- public Integer getMinorInt() {
- return this.minor;
- }
- public Integer getMicroInt() {
- return this.micro;
- }
- public String getMajorStr() {
- return this.major.toString();
- }
- public String getMinorStr() {
- return this.minor.toString();
- }
- public String getMicroStr() {
- return this.micro.toString();
- }
- public String getQualifier() {
- return this.qualifier;
- }
- public String getIdentifier() {
- return this.identifier;
- }
-
- // setters
- public void setIdentifier(String identifier) {
- setAll(validateIdentifier(identifier));
- }
-
- // Compare Versions
- public boolean gt( Version comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp.getIdentifier()) > 0) {
- result = true;
- }
- return result;
- }
- public boolean lt( Version comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp.getIdentifier()) < 0) {
- result = true;
- }
- return result;
- }
- public boolean ge( Version comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp.getIdentifier()) >= 0) {
- result = true;
- }
- return result;
- }
- public boolean le( Version comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp.getIdentifier()) <= 0) {
- result = true;
- }
- return result;
- }
- public boolean eq( Version comp ) {
- boolean result=false;
-
- if(this.identifier.equals(comp.getIdentifier())) {
- result = true;
- }
- return result;
- }
-
- // Compare version strings
- public boolean gt( String comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp) > 0) {
- result = true;
- }
- return result;
- }
- public boolean lt( String comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp) < 0) {
- result = true;
- }
- return result;
- }
- public boolean ge( String comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp) >= 0) {
- result = true;
- }
- return result;
- }
- public boolean le( String comp ) {
- boolean result=false;
-
- if(this.identifier.compareTo(comp) <= 0) {
- result = true;
- }
- return result;
- }
- public boolean eq( String comp ) {
- boolean result=false;
-
- if(this.identifier.equals(comp)) {
- result = true;
- }
- return result;
- }
-}
\ No newline at end of file
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Version
+ * class defines OSGi-like behavior to a version object
+ * it has an identifier (Major.Minor.Micro.Qualifier) and can compare itself to others
+ * it can report its identifier, and its identifier can be set
+ *
+ * Contributors:
+ * egwin - initial conception and implementation
+ */
+
+package org.eclipse.persistence.buildtools.helper;
+
+import java.lang.NumberFormatException;
+
+import org.eclipse.persistence.buildtools.helper.VersionException;;
+
+public class Version {
+ private String identifier = "0.0";
+ private Integer major = 0;
+ private Integer minor = 0;
+ private Integer micro = 0;
+ private String qualifier = "";
+
+ private int[] indexList = {0,0,0}; //holds the indexes of the "."s in the identifier string.
+
+ // helper
+ private String validateIdentifier(String identifier) throws VersionException{
+ String validated=identifier;
+ boolean error=false;
+
+ if ( validated.startsWith(".") ) {
+ throw new VersionException("Initial '.' invalids version");
+ }
+ else {
+ if( validated.endsWith(".") ) {
+ throw new VersionException("Terminating '.' invalids version");
+ }
+ else {
+ int index = 0;
+ int subindex = 0;
+ int count = 0;
+ int maxindex = validated.lastIndexOf(".");
+ while( !error && ( (subindex = validated.substring(index).indexOf(".")) >0 || index<maxindex )) {
+ if(count>2 && subindex>0)
+ throw new VersionException("Maximum tokens (4) exceeded.");
+ else {
+ index += subindex;
+ indexList[count] = index;
+ index++; //increment to point to char after found '.'
+ count++;
+ }
+ }
+ }
+ }
+ return validated;
+ }
+
+ // setter
+ private void setMajor(Integer major) {
+ this.major = major;
+ }
+ private void setMinor(Integer minor) {
+ this.minor = minor;
+ }
+ private void setMicro(Integer micro) {
+ this.micro = micro;
+ }
+ private void setQualifier(String qualifier) {
+ this.qualifier = qualifier;
+ }
+
+ private void setAll(String identifier) throws VersionException{
+ // assumes basic validation completed
+ try {
+ if( identifier != "" ){
+ if( indexList[0] > 0 ) {
+ setMajor(Integer.valueOf( identifier.substring(0, indexList[0])));
+ if( indexList[1] > 0 ) {
+ setMinor(Integer.valueOf( identifier.substring(indexList[0]+1, indexList[1])));
+ if( indexList[2] > 0 ) {
+ setMicro(Integer.valueOf( identifier.substring(indexList[1]+1, indexList[2])));
+ setQualifier(identifier.substring(indexList[2]+1));
+ }
+ else
+ setMicro(Integer.valueOf( identifier.substring(indexList[1]+1)));
+ }
+ else
+ setMinor(Integer.valueOf( identifier.substring(indexList[0]+1) ));
+ }
+ else
+ setMajor(Integer.valueOf(identifier));
+ }
+ } catch ( NumberFormatException e){
+ throw new VersionException("A numeric version token is invalid. " + e.getMessage() + " in \"" + identifier + "\".", e);
+ }
+ String validIdentifier = getMajorStr() + "." + getMinorStr() + "." + getMicroStr();
+ if(getQualifier() != null && getQualifier() != "" ) {
+ validIdentifier+= "." + getQualifier();
+ }
+ this.identifier = validIdentifier;
+ }
+
+ // Public methods
+ // constructors
+ public Version() {
+ }
+ public Version(String identifier) {
+ setIdentifier(identifier);
+ }
+
+ // getters
+ public Integer getMajorInt() {
+ return this.major;
+ }
+ public Integer getMinorInt() {
+ return this.minor;
+ }
+ public Integer getMicroInt() {
+ return this.micro;
+ }
+ public String getMajorStr() {
+ return this.major.toString();
+ }
+ public String getMinorStr() {
+ return this.minor.toString();
+ }
+ public String getMicroStr() {
+ return this.micro.toString();
+ }
+ public String getQualifier() {
+ return this.qualifier;
+ }
+ public String getIdentifier() {
+ return this.identifier;
+ }
+
+ // setters
+ public void setIdentifier(String identifier) {
+ setAll(validateIdentifier(identifier));
+ }
+
+ // Compare Versions
+ public boolean gt( Version comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp.getIdentifier()) > 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean lt( Version comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp.getIdentifier()) < 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean ge( Version comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp.getIdentifier()) >= 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean le( Version comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp.getIdentifier()) <= 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean eq( Version comp ) {
+ boolean result=false;
+
+ if(this.identifier.equals(comp.getIdentifier())) {
+ result = true;
+ }
+ return result;
+ }
+
+ // Compare version strings
+ public boolean gt( String comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp) > 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean lt( String comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp) < 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean ge( String comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp) >= 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean le( String comp ) {
+ boolean result=false;
+
+ if(this.identifier.compareTo(comp) <= 0) {
+ result = true;
+ }
+ return result;
+ }
+ public boolean eq( String comp ) {
+ boolean result=false;
+
+ if(this.identifier.equals(comp)) {
+ result = true;
+ }
+ return result;
+ }
+}