diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java index 7cbe0e709..e8f92a6e1 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java @@ -15,8 +15,11 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; +import org.apache.avalon.framework.CascadingException; import org.apache.avalon.framework.ExceptionUtil; +import org.apache.avalon.framework.Version; import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.SAXConfigurationHandler; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.myrmidon.components.model.DefaultProject; @@ -39,6 +42,8 @@ public class DefaultProjectBuilder private static final Resources REZ = ResourceManager.getPackageResources( DefaultProjectBuilder.class ); + private final static Version VERSION = new Version( 2, 0, 0 ); + private final static int PROJECT_REFERENCES = 0; private final static int LIBRARY_IMPORTS = 1; private final static int IMPLICIT_TASKS = 2; @@ -124,6 +129,14 @@ public class DefaultProjectBuilder //get project-level attributes final String baseDirectoryName = configuration.getAttribute( "basedir", null ); final String defaultTarget = configuration.getAttribute( "default", "main" ); + final Version version = getVersion( configuration ); + + if( !VERSION.complies( version ) ) + { + final String message = + REZ.getString( "ant.bad-version.error", VERSION, version ); + throw new Exception( message ); + } //determine base directory for project. Use the directory containing //the build file as the default. @@ -148,6 +161,45 @@ public class DefaultProjectBuilder return project; } + /** + * Retrieve the version attribute from the specified configuration element. + * Throw exceptions with meaningful errors if malformed or missing. + */ + private Version getVersion( final Configuration configuration ) + throws CascadingException + { + try + { + final String versionString = configuration.getAttribute( "version" ); + return parseVersion( versionString ); + } + catch( final ConfigurationException ce ) + { + final String message = REZ.getString( "ant.version-missing.error" ); + throw new CascadingException( message, ce ); + } + } + + /** + * Utility function to extract version + */ + private Version parseVersion( final String versionString ) + throws CascadingException + { + + try + { + return Version.getVersion( versionString ); + } + catch( final Exception e ) + { + final String message = + REZ.getString( "ant.malformed.version", versionString ); + getLogger().warn( message ); + throw new CascadingException( message, e ); + } + } + /** * Handle all top level elements in configuration. * diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties index c0ff96a6e..63e387bed 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties @@ -23,3 +23,6 @@ ant.target-noname.error=Discovered un-named target at {0}. ant.target-bad-name.error=Target with an invalid name at {0}. ant.target-bad-logic.error=Discovered invalid target that has both a if and unless condition at {0}. ant.target-bad-dependency.error=Discovered empty dependency in target {0} at {1}. +ant.malformed.version=Malformed version string "{0}" specified in version attribute of project. +ant.version-missing.error=Missing version attribute from project. +ant.bad-version.error=Incompatible build file version detected. Expected {0} but found {1}. diff --git a/proposal/myrmidon/src/make/primitive-tests.ant b/proposal/myrmidon/src/make/primitive-tests.ant index f4b3e28bf..a59df484e 100644 --- a/proposal/myrmidon/src/make/primitive-tests.ant +++ b/proposal/myrmidon/src/make/primitive-tests.ant @@ -14,7 +14,7 @@ Legal: ============================================================================== --> - + @@ -58,8 +58,7 @@ Legal: float="1.0" float2="2.0" double="3.0" - double2="4.0" - /> + double2="4.0" /> diff --git a/proposal/myrmidon/src/make/sample.ant b/proposal/myrmidon/src/make/sample.ant index bd6d645cc..ebd4e4c8d 100644 --- a/proposal/myrmidon/src/make/sample.ant +++ b/proposal/myrmidon/src/make/sample.ant @@ -14,7 +14,7 @@ Legal: ============================================================================== --> - +