git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269632 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -8,6 +8,8 @@ | |||
| package org.apache.myrmidon.components.aspect; | |||
| import java.util.HashMap; | |||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
| import org.apache.avalon.excalibur.i18n.Resources; | |||
| import org.apache.avalon.framework.activity.Initializable; | |||
| import org.apache.avalon.framework.configuration.Configuration; | |||
| import org.apache.avalon.framework.parameters.Parameters; | |||
| @@ -25,6 +27,9 @@ import org.apache.myrmidon.aspects.NoopAspectHandler; | |||
| public class DefaultAspectManager | |||
| implements AspectManager, Initializable | |||
| { | |||
| private static final Resources REZ = | |||
| ResourceManager.getPackageResources( DefaultAspectManager.class ); | |||
| private HashMap m_aspectMap = new HashMap(); | |||
| private AspectHandler[] m_aspects = new AspectHandler[ 0 ]; | |||
| private String[] m_names = new String[ 0 ]; | |||
| @@ -50,7 +55,8 @@ public class DefaultAspectManager | |||
| final AspectHandler entry = (AspectHandler)m_aspectMap.remove( name ); | |||
| if( null == entry ) | |||
| { | |||
| throw new TaskException( "No such aspect with name '" + name + "'" ); | |||
| final String message = REZ.getString( "no.aspect", name ); | |||
| throw new TaskException( message ); | |||
| } | |||
| rebuildArrays(); | |||
| @@ -75,7 +81,8 @@ public class DefaultAspectManager | |||
| final AspectHandler handler = (AspectHandler)m_aspectMap.get( name ); | |||
| if( null == handler ) | |||
| { | |||
| throw new TaskException( "No such aspect with name '" + name + "'" ); | |||
| final String message = REZ.getString( "no.aspect", name ); | |||
| throw new TaskException( message ); | |||
| } | |||
| handler.aspectSettings( parameters, elements ); | |||
| @@ -98,7 +105,8 @@ public class DefaultAspectManager | |||
| public void aspectSettings( final Parameters parameters, final Configuration[] elements ) | |||
| throws TaskException | |||
| { | |||
| throw new UnsupportedOperationException( "Can not provide Settings to AspectManager" ); | |||
| final String message = REZ.getString( "no.settings" ); | |||
| throw new UnsupportedOperationException( message ); | |||
| } | |||
| public void postCreate( final Task task ) | |||
| @@ -0,0 +1,2 @@ | |||
| no.aspect=No such aspect with name {0}. | |||
| no.settings=Can not provide Settings to AspectManager. | |||
| @@ -7,25 +7,27 @@ | |||
| */ | |||
| package org.apache.myrmidon.components.builder; | |||
| import java.net.URL; | |||
| import java.io.InputStream; | |||
| import java.net.URL; | |||
| import java.util.Properties; | |||
| import javax.xml.parsers.SAXParser; | |||
| import javax.xml.parsers.SAXParserFactory; | |||
| import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | |||
| import org.apache.avalon.framework.parameters.Parameterizable; | |||
| import org.apache.avalon.framework.parameters.Parameters; | |||
| import org.xml.sax.SAXException; | |||
| import org.xml.sax.XMLReader; | |||
| import javax.xml.transform.TransformerFactory; | |||
| import javax.xml.transform.Transformer; | |||
| import javax.xml.transform.TransformerConfigurationException; | |||
| import javax.xml.transform.TransformerFactory; | |||
| import javax.xml.transform.sax.SAXResult; | |||
| import javax.xml.transform.sax.SAXSource; | |||
| import javax.xml.transform.sax.SAXTransformerFactory; | |||
| import javax.xml.transform.sax.TransformerHandler; | |||
| import javax.xml.transform.stream.StreamSource; | |||
| import javax.xml.transform.stream.StreamResult; | |||
| import javax.xml.transform.stream.StreamSource; | |||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
| import org.apache.avalon.excalibur.i18n.Resources; | |||
| import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | |||
| import org.apache.avalon.framework.parameters.Parameterizable; | |||
| import org.apache.avalon.framework.parameters.Parameters; | |||
| import org.xml.sax.SAXException; | |||
| import org.xml.sax.XMLReader; | |||
| /** | |||
| * Default implementation to construct project from a build file. | |||
| @@ -36,14 +38,8 @@ public class ATIProjectBuilder | |||
| extends DefaultProjectBuilder | |||
| implements Parameterizable | |||
| { | |||
| private final static String PARAM_EXCEPTION = | |||
| "Malformed PI: expected <?xsl-param name=\"foo\" value=\"bar\"?>"; | |||
| private final static String PARAMS_EXCEPTION = | |||
| "Malformed PI: expected <?xsl-params location=\"myparams.properties\"?>"; | |||
| private final static String STYLE_EXCEPTION = | |||
| "Malformed PI: expected <?xsl-params href=\"mystylesheet.xsl\"?>"; | |||
| private static final Resources REZ = | |||
| ResourceManager.getPackageResources( ATIProjectBuilder.class ); | |||
| private Parameters m_parameters; | |||
| private URL m_systemID; | |||
| @@ -82,12 +78,12 @@ public class ATIProjectBuilder | |||
| if( target.equals( "xsl-param" ) ) handleParameter( data ); | |||
| else if( target.equals( "xsl-params" ) ) handleParameters( data, sourceID ); | |||
| else if( target.equals( "xsl-stylesheet" ) ) | |||
| else if( target.equals( "xsl-stylesheet" ) ) | |||
| { | |||
| if( null != transformer ) | |||
| { | |||
| throw new SAXException( "Build file can not contain " + | |||
| "two xsl-stylesheet PIs" ); | |||
| final String message = REZ.getString( "ati.two.stylesheet.pis" ); | |||
| throw new SAXException( message ); | |||
| } | |||
| final TransformerFactory factory = TransformerFactory.newInstance(); | |||
| @@ -113,9 +109,9 @@ public class ATIProjectBuilder | |||
| final SAXResult result = new SAXResult( handler ); | |||
| transformer.transform( new StreamSource( sourceID.toString() ), result ); | |||
| //transformer.transform( new StreamSource( sourceID.toString() ), | |||
| //transformer.transform( new StreamSource( sourceID.toString() ), | |||
| //new StreamResult( System.out ) ); | |||
| } | |||
| } | |||
| } | |||
| private void handleParameter( final String data ) | |||
| @@ -124,22 +120,25 @@ public class ATIProjectBuilder | |||
| int index = data.indexOf( '\"' ); | |||
| if( -1 == index ) | |||
| { | |||
| throw new SAXException( PARAM_EXCEPTION ); | |||
| final String message = REZ.getString( "ati.param.error" ); | |||
| throw new SAXException( message ); | |||
| } | |||
| index = data.indexOf( '\"', index + 1 ); | |||
| if( -1 == index ) | |||
| { | |||
| throw new SAXException( PARAM_EXCEPTION ); | |||
| final String message = REZ.getString( "ati.param.error" ); | |||
| throw new SAXException( message ); | |||
| } | |||
| //split between two "attributes" occurs on index | |||
| final String[] name = parseAttribute( data.substring( 0, index + 1 ) ); | |||
| final String[] value = parseAttribute( data.substring( index + 1 ).trim() ); | |||
| if( !name[ 0 ].equals( "name" ) || !value[ 0 ].equals( "value" ) ) | |||
| { | |||
| throw new SAXException( PARAM_EXCEPTION ); | |||
| final String message = REZ.getString( "ati.param.error" ); | |||
| throw new SAXException( message ); | |||
| } | |||
| m_parameters.setParameter( name[ 1 ], value[ 1 ] ); | |||
| @@ -151,7 +150,8 @@ public class ATIProjectBuilder | |||
| final String[] params = parseAttribute( data ); | |||
| if( !params[ 0 ].equals( "location" ) ) | |||
| { | |||
| throw new SAXException( PARAMS_EXCEPTION ); | |||
| final String message = REZ.getString( "ati.params.error" ); | |||
| throw new SAXException( message ); | |||
| } | |||
| try | |||
| @@ -165,7 +165,8 @@ public class ATIProjectBuilder | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new SAXException( "Error loading parameters: " + e ); | |||
| final String message = REZ.getString( "ati.loading-params.error", params[ 1 ], e ); | |||
| throw new SAXException( message ); | |||
| } | |||
| } | |||
| @@ -175,14 +176,16 @@ public class ATIProjectBuilder | |||
| final String[] stylesheet = parseAttribute( data ); | |||
| if( !stylesheet[ 0 ].equals( "href" ) ) | |||
| { | |||
| throw new SAXException( STYLE_EXCEPTION ); | |||
| final String message = REZ.getString( "ati.style.error" ); | |||
| throw new SAXException( message ); | |||
| } | |||
| try { return new URL( baseSource, stylesheet[ 1 ] ).toString(); } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new SAXException( "Error locating stylesheet '" + stylesheet[ 1 ] + | |||
| "' due to " + e ); | |||
| final String message = | |||
| REZ.getString( "ati.loading-style.error", stylesheet[ 1 ], e ); | |||
| throw new SAXException( message ); | |||
| } | |||
| } | |||
| @@ -193,20 +196,20 @@ public class ATIProjectBuilder | |||
| int index = data.indexOf( '=' ); | |||
| if( -1 == index ) | |||
| { | |||
| throw new SAXException( "Expecting an attribute but received '" + | |||
| data + "'" ); | |||
| final String message = REZ.getString( "ati.attribue-expected.error", data ); | |||
| throw new SAXException( message ); | |||
| } | |||
| final int size = data.length(); | |||
| if( '\"' != data.charAt( index + 1 ) || | |||
| if( '\"' != data.charAt( index + 1 ) || | |||
| '\"' != data.charAt( size - 1 ) || | |||
| size - 1 == index ) | |||
| { | |||
| throw new SAXException( "Expecting the value of attribute " + | |||
| data.substring( 0, index ) + | |||
| " to be enclosed in quotes" ); | |||
| final String message = | |||
| REZ.getString( "ati.attribue-unquoted.error", data.substring( 0, index ) ); | |||
| throw new SAXException( message ); | |||
| } | |||
| final String[] result = new String[ 2 ]; | |||
| result[ 0 ] = data.substring( 0, index ); | |||
| result[ 1 ] = data.substring( index + 2, size - 1 ); | |||
| @@ -29,6 +29,8 @@ import org.apache.myrmidon.components.model.Project; | |||
| import org.apache.myrmidon.components.model.Target; | |||
| import org.xml.sax.SAXException; | |||
| import org.xml.sax.XMLReader; | |||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
| import org.apache.avalon.excalibur.i18n.Resources; | |||
| /** | |||
| * Default implementation to construct project from a build file. | |||
| @@ -39,6 +41,9 @@ public class DefaultProjectBuilder | |||
| extends AbstractLoggable | |||
| implements ProjectBuilder | |||
| { | |||
| private static final Resources REZ = | |||
| ResourceManager.getPackageResources( DefaultProjectBuilder.class ); | |||
| private final static int PROJECT_REFERENCES = 0; | |||
| private final static int LIBRARY_IMPORTS = 1; | |||
| private final static int IMPLICIT_TASKS = 2; | |||
| @@ -117,7 +122,8 @@ public class DefaultProjectBuilder | |||
| { | |||
| if( !configuration.getName().equals( "project" ) ) | |||
| { | |||
| throw new Exception( "Project file must be enclosed in project element" ); | |||
| final String message = REZ.getString( "ant.no-project-element.error" ); | |||
| throw new Exception( message ); | |||
| } | |||
| //get project-level attributes | |||
| @@ -129,7 +135,11 @@ public class DefaultProjectBuilder | |||
| final File baseDirectory = | |||
| (new File( file.getParentFile(), baseDirectoryName )).getAbsoluteFile(); | |||
| getLogger().debug( "Project " + file + " base directory: " + baseDirectory ); | |||
| if( getLogger().isDebugEnabled() ) | |||
| { | |||
| final String message = REZ.getString( "ant.project-banner.notice", file, baseDirectory ); | |||
| getLogger().debug( message ); | |||
| } | |||
| //create project and ... | |||
| final DefaultProject project = new DefaultProject(); | |||
| @@ -205,9 +215,9 @@ public class DefaultProjectBuilder | |||
| if( name.equals( "target" ) ) buildTarget( project, element ); | |||
| else | |||
| { | |||
| throw new Exception( "Unknown top-level element " + name + | |||
| " at " + element.getLocation() + | |||
| ". Expecting target" ); | |||
| final String message = | |||
| REZ.getString( "ant.unknown-toplevel-element.error", name, element.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| } | |||
| @@ -228,20 +238,23 @@ public class DefaultProjectBuilder | |||
| if( null == name ) | |||
| { | |||
| throw new Exception( "Malformed projectref without a name attribute at " + | |||
| element.getLocation() ); | |||
| final String message = | |||
| REZ.getString( "ant.projectref-no-name.error", element.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| if( !validName( name ) ) | |||
| { | |||
| throw new Exception( "Projectref with an invalid name attribute at " + | |||
| element.getLocation() ); | |||
| final String message = | |||
| REZ.getString( "ant.projectref-bad-name.error", element.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| if( null == location ) | |||
| { | |||
| throw new Exception( "Malformed projectref without a location attribute at " + | |||
| element.getLocation() ); | |||
| final String message = | |||
| REZ.getString( "ant.projectref-no-location.error", element.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| final File baseDirectory = project.getBaseDirectory(); | |||
| @@ -270,17 +283,18 @@ public class DefaultProjectBuilder | |||
| if( null == library ) | |||
| { | |||
| throw new Exception( "Malformed import without a library attribute at " + | |||
| element.getLocation() ); | |||
| final String message = | |||
| REZ.getString( "ant.import-no-library.error", element.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| if( null == name || null == type ) | |||
| { | |||
| if( null != name || null != type ) | |||
| { | |||
| throw new Exception( "Malformed import at " + element.getLocation() + | |||
| ". If name or type attribute is specified, both " + | |||
| "attributes must be specified." ); | |||
| final String message = | |||
| REZ.getString( "ant.import-malformed.error", element.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| } | |||
| @@ -303,34 +317,49 @@ public class DefaultProjectBuilder | |||
| if( null == name ) | |||
| { | |||
| throw new Exception( "Discovered un-named target at " + | |||
| target.getLocation() ); | |||
| final String message = | |||
| REZ.getString( "ant.target-noname.error", target.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| if( !validName( name ) ) | |||
| { | |||
| throw new Exception( "Target with an invalid name at " + | |||
| target.getLocation() ); | |||
| final String message = | |||
| REZ.getString( "ant.target-bad-name.error", target.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| getLogger().debug( "Parsing target: " + name ); | |||
| if( getLogger().isDebugEnabled() ) | |||
| { | |||
| final String message = REZ.getString( "ant.target-parse.notice", name ); | |||
| getLogger().debug( message ); | |||
| } | |||
| if( null != ifCondition && null != unlessCondition ) | |||
| { | |||
| throw new Exception( "Discovered invalid target that has both a if and " + | |||
| "unless condition at " + target.getLocation() ); | |||
| final String message = | |||
| REZ.getString( "ant.target-bad-logic.error", target.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| Condition condition = null; | |||
| if( null != ifCondition ) | |||
| { | |||
| getLogger().debug( "Target if condition: " + ifCondition ); | |||
| if( getLogger().isDebugEnabled() ) | |||
| { | |||
| final String message = REZ.getString( "ant.target-if.notice", ifCondition ); | |||
| getLogger().debug( message ); | |||
| } | |||
| condition = new Condition( true, ifCondition ); | |||
| } | |||
| else if( null != unlessCondition ) | |||
| { | |||
| getLogger().debug( "Target unless condition: " + unlessCondition ); | |||
| if( getLogger().isDebugEnabled() ) | |||
| { | |||
| final String message = REZ.getString( "ant.target-unless.notice", unlessCondition ); | |||
| getLogger().debug( message ); | |||
| } | |||
| condition = new Condition( false, unlessCondition ); | |||
| } | |||
| @@ -348,11 +377,18 @@ public class DefaultProjectBuilder | |||
| if( 0 == dependency.length() ) | |||
| { | |||
| throw new Exception( "Discovered empty dependency in target " + | |||
| target.getName() + " at " + target.getLocation() ); | |||
| final String message = REZ.getString( "ant.target-bad-dependency.error", | |||
| target.getName(), | |||
| target.getLocation() ); | |||
| throw new Exception( message ); | |||
| } | |||
| getLogger().debug( "Target dependency: " + dependency ); | |||
| if( getLogger().isDebugEnabled() ) | |||
| { | |||
| final String message = REZ.getString( "ant.target-dependency.notice", dependency ); | |||
| getLogger().debug( message ); | |||
| } | |||
| dependsList.add( dependency ); | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| ati.two.stylesheet.pis=Build file can not contain two xsl-stylesheet PIs. | |||
| ati.params.error=Malformed PI: expected <?xsl-params location=\"myparams.properties\"?> | |||
| ati.param.error=Malformed PI: expected <?xsl-param name=\"foo\" value=\"bar\"?> | |||
| ati.style.error=Malformed PI: expected <?xsl-params href=\"mystylesheet.xsl\"?> | |||
| ati.loading-params.error=Error loading parameters {0}. Reason: {1}. | |||
| ati.loading-style.error=Error locating stylesheet {0}. Reason: {1}. | |||
| ati.attribue-expected.error=Expecting an attribute but received {0}. | |||
| ati.attribue-unquoted.error=Expecting the value of attribute {0} to be enclosed in quotes. | |||
| ant.project-banner.notice=Project {0} base directory: {1}. | |||
| ant.target-parse.notice=Parsing target: {0}. | |||
| ant.target-if.notice=Target if condition: {0} | |||
| ant.target- unless.notice=Target unless condition: {0} | |||
| ant.target-dependency.notice=Target dependency: {0} | |||
| ant.no-project-element.error=Project file must be enclosed in project element. | |||
| ant.unknown-toplevel-element.error=Unknown top-level element {0} at {1}. | |||
| ant.projectref-no-name.error=Malformed projectref without a name attribute at {0}. | |||
| ant.projectref-bad-name.error=Projectref with an invalid name attribute at {0}. | |||
| ant.projectref-no-location.error=Malformed projectref without a location attribute at {0}. | |||
| ant.import-no-library.error=Malformed import without a library attribute at {0}. | |||
| ant.import-malformed.error=Malformed import at {0}. If name or type attribute is specified, both attributes must be specified. | |||
| 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}. | |||