diff --git a/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtraAttribute.java b/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtraAttribute.java new file mode 100644 index 000000000..be74b5449 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtraAttribute.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.extensions; + +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; +import org.apache.myrmidon.api.TaskException; + +/** + * Simple holder for extra attributes in main section of manifest. + * + * @author Peter Donald + * @version $Revision$ $Date$ + * @todo Refactor this and all the other parameter, sysproperty, + * property etc into a single class in framework + */ +public class ExtraAttribute +{ + private static final Resources REZ = + ResourceManager.getPackageResources( ExtraAttribute.class ); + + private String m_name; + private String m_value; + + /** + * Set the name of the parameter. + * + * @param name the name of parameter + */ + public void setName( final String name ) + { + m_name = name; + } + + /** + * Set the value of the parameter. + * + * @param value the parameter value + */ + public void setValue( final String value ) + { + m_value = value; + } + + /** + * Retrieve name of parameter. + * + * @return the name of parameter. + */ + String getName() + { + return m_name; + } + + /** + * Retrieve the value of parameter. + * + * @return the value of parameter. + */ + String getValue() + { + return m_value; + } + + /** + * Make sure that neither the name or the value + * is null. + */ + public void validate() + throws TaskException + { + if( null == m_name ) + { + final String message = REZ.getString( "param.noname.error" ); + throw new TaskException( message ); + } + else if( null == m_value ) + { + final String message = + REZ.getString( "param.novalue.error", m_name ); + throw new TaskException( message ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java b/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java index ce4642e38..2fbbaffe2 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java @@ -113,6 +113,12 @@ public class JarLibManifestTask */ private String m_implementationURL; + /** + * Extra attributes the user specifies for main section + * in manifest. + */ + private final ArrayList m_extraAttributes = new ArrayList(); + /** * Set the name of extension in generated manifest. * @@ -213,6 +219,16 @@ public class JarLibManifestTask m_optionals.addElement( fileSet ); } + /** + * Adds an attribute that is to be put in main section of manifest. + * + * @param attribute an attribute that is to be put in main section of manifest. + */ + public void addAttribute( final ExtraAttribute attribute ) + { + m_extraAttributes.add( attribute ); + } + public void execute() throws TaskException { @@ -224,6 +240,8 @@ public class JarLibManifestTask attributes.put( Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION ); attributes.putValue( "Created-By", Constants.BUILD_DESCRIPTION ); + appendExtraAttributes( attributes ); + appendExtensionData( attributes ); final String extensionKey = Extension.EXTENSION_LIST.toString(); @@ -269,6 +287,24 @@ public class JarLibManifestTask } } + /** + * Add any extra attributes to the manifest. + * + * @param attributes the manifest section to write + * attributes to + */ + private void appendExtraAttributes( final Attributes attributes ) + { + final Iterator iterator = m_extraAttributes.iterator(); + while( iterator.hasNext() ) + { + final ExtraAttribute attribute = + (ExtraAttribute)iterator.next(); + attributes.putValue( attribute.getName(), + attribute.getValue() ); + } + } + /** * Write out manifest to destfile. * diff --git a/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties b/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties index 49ef6d768..f2500e165 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties @@ -4,4 +4,7 @@ extension.bad-file.error="{0}" is not a file. manifest.missing-file.error=Destfile attribute not specified. manifest.bad-file.error="{0}" is not a file. -manifest.file.notice=Generating manifest {0}. \ No newline at end of file +manifest.file.notice=Generating manifest {0}. + +param.noname.error=Missing name from parameter. +param.novalue.error=Missing value from parameter "{0}". diff --git a/proposal/myrmidon/src/samples/sample.ant b/proposal/myrmidon/src/samples/sample.ant index 2e0ee54de..6c0cd517f 100644 --- a/proposal/myrmidon/src/samples/sample.ant +++ b/proposal/myrmidon/src/samples/sample.ant @@ -341,8 +341,9 @@ Legal: destfile="../../generated-manifest.txt" extension-name="org.realityforge.dve" specification-version="1.0" - specification-vendor="Peter Donald" - > + specification-vendor="Peter Donald" > +