Browse Source

Made the version attribute a required attribute of build file

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270767 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
9005ee85f3
4 changed files with 58 additions and 4 deletions
  1. +52
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java
  2. +3
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties
  3. +2
    -3
      proposal/myrmidon/src/make/primitive-tests.ant
  4. +1
    -1
      proposal/myrmidon/src/make/sample.ant

+ 52
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java View File

@@ -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.
*


+ 3
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties View File

@@ -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}.

+ 2
- 3
proposal/myrmidon/src/make/primitive-tests.ant View File

@@ -14,7 +14,7 @@ Legal:
==============================================================================
-->

<project name="MySample" default="main" basedir=".">
<project version="2.0.0">

<import library="selftest" />

@@ -58,8 +58,7 @@ Legal:
float="1.0"
float2="2.0"
double="3.0"
double2="4.0"
/>
double2="4.0" />

<sub-elements-test>
<create-beep message="A string" />


+ 1
- 1
proposal/myrmidon/src/make/sample.ant View File

@@ -14,7 +14,7 @@ Legal:
==============================================================================
-->

<project name="MySample" default="main" basedir=".">
<project version="2.0.0">

<projectref name="prim" location="primitive-tests.ant" />



Loading…
Cancel
Save