diff --git a/proposal/myrmidon/lib/excalibur-extension-1.0a.jar b/proposal/myrmidon/lib/excalibur-extension-1.0a.jar index fdb10a169..08e785f15 100644 Binary files a/proposal/myrmidon/lib/excalibur-extension-1.0a.jar and b/proposal/myrmidon/lib/excalibur-extension-1.0a.jar differ diff --git a/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionAdapter.java b/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionAdapter.java new file mode 100644 index 000000000..3e421f2d7 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionAdapter.java @@ -0,0 +1,171 @@ +/* + * 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.extension.DeweyDecimal; +import org.apache.avalon.excalibur.extension.Extension; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; +import org.apache.myrmidon.api.TaskException; + +/** + * Simple class that represents an Extension and conforms to Ants + * patterns. + * + * @author Peter Donald + * @version $Revision$ $Date$ + */ +public class ExtensionAdapter +{ + private static final Resources REZ = + ResourceManager.getPackageResources( ExtensionAdapter.class ); + + /** + * The name of the optional package being made available, or required. + */ + private String m_extensionName; + + /** + * The version number (dotted decimal notation) of the specification + * to which this optional package conforms. + */ + private DeweyDecimal m_specificationVersion; + + /** + * The name of the company or organization that originated the + * specification to which this optional package conforms. + */ + private String m_specificationVendor; + + /** + * The unique identifier of the company that produced the optional + * package contained in this JAR file. + */ + private String m_implementationVendorID; + + /** + * The name of the company or organization that produced this + * implementation of this optional package. + */ + private String m_implementationVendor; + + /** + * The version number (dotted decimal notation) for this implementation + * of the optional package. + */ + private DeweyDecimal m_implementationVersion; + + /** + * The URL from which the most recent version of this optional package + * can be obtained if it is not already installed. + */ + private String m_implementationURL; + + /** + * Set the name of extension. + * + * @param extensionName the name of extension + */ + public void setExtensionName( final String extensionName ) + { + m_extensionName = extensionName; + } + + /** + * Set the specificationVersion of extension. + * + * @param specificationVersion the specificationVersion of extension + */ + public void setSpecificationVersion( final String specificationVersion ) + { + m_specificationVersion = new DeweyDecimal( specificationVersion ); + } + + /** + * Set the specificationVendor of extension. + * + * @param specificationVendor the specificationVendor of extension + */ + public void setSpecificationVendor( final String specificationVendor ) + { + m_specificationVendor = specificationVendor; + } + + /** + * Set the implementationVendorID of extension. + * + * @param implementationVendorID the implementationVendorID of extension + */ + public void setImplementationVendorID( final String implementationVendorID ) + { + m_implementationVendorID = implementationVendorID; + } + + /** + * Set the implementationVendor of extension. + * + * @param implementationVendor the implementationVendor of extension + */ + public void setImplementationVendor( final String implementationVendor ) + { + m_implementationVendor = implementationVendor; + } + + /** + * Set the implementationVersion of extension. + * + * @param implementationVersion the implementationVersion of extension + */ + public void setImplementationVersion( final String implementationVersion ) + { + m_implementationVersion = new DeweyDecimal( implementationVersion ); + } + + /** + * Set the implementationURL of extension. + * + * @param implementationURL the implementationURL of extension + */ + public void setImplementationURL( final String implementationURL ) + { + m_implementationURL = implementationURL; + } + + /** + * Convert this adpater object into an extension object. + * + * @return the extension object + */ + Extension toExtension() + throws TaskException + { + if( null == m_extensionName ) + { + final String message = REZ.getString( "extension.noname.error" ); + throw new TaskException( message ); + } + + String specificationVersion = null; + if( null != m_specificationVersion ) + { + specificationVersion = m_specificationVersion.toString(); + } + String implementationVersion = null; + if( null != m_implementationVersion ) + { + implementationVersion = m_implementationVersion.toString(); + } + return new Extension( m_extensionName, + specificationVersion, + m_specificationVendor, + implementationVersion, + m_implementationVendorID, + m_implementationVendor, + m_implementationURL ); + } +} 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 2fbbaffe2..da9311369 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java @@ -12,11 +12,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; -import java.util.Vector; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import org.apache.avalon.excalibur.extension.DeweyDecimal; import org.apache.avalon.excalibur.extension.Extension; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; @@ -24,7 +22,6 @@ import org.apache.avalon.excalibur.io.IOUtil; import org.apache.myrmidon.Constants; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.FileSet; import org.apache.tools.todo.types.DirectoryScanner; import org.apache.tools.todo.types.ScannerUtil; @@ -44,7 +41,7 @@ import org.apache.tools.todo.types.ScannerUtil; * @author Peter Donald * @ant.task name="jarlib-manifest" */ -public class JarLibManifestTask +public final class JarLibManifestTask extends AbstractTask { private final static Resources REZ = @@ -61,57 +58,33 @@ public class JarLibManifestTask private File m_destfile; /** - * Filesets specifying all the librarys - * to generate dependency information about. - */ - private final Vector m_dependencies = new Vector(); - - /** - * Filesets specifying all the librarys - * to generate optional dependency information about. - */ - private final Vector m_optionals = new Vector(); - - /** - * The name of the optional package being made available, or required. - */ - private String m_extensionName; - - /** - * The version number (dotted decimal notation) of the specification - * to which this optional package conforms. - */ - private DeweyDecimal m_specificationVersion; - - /** - * The name of the company or organization that originated the - * specification to which this optional package conforms. + * The extension supported by this library (if any). */ - private String m_specificationVendor; + private Extension m_extension; /** - * The unique identifier of the company that produced the optional - * package contained in this JAR file. + * ExtensionAdapter objects representing + * dependencies required by library. */ - private String m_implementationVendorID; + private final ArrayList m_dependencies = new ArrayList(); /** - * The name of the company or organization that produced this - * implementation of this optional package. + * ExtensionAdapter objects representing optional + * dependencies required by library. */ - private String m_implementationVendor; + private final ArrayList m_optionals = new ArrayList(); /** - * The version number (dotted decimal notation) for this implementation - * of the optional package. + * Filesets specifying all the librarys + * to generate dependency information about. */ - private DeweyDecimal m_implementationVersion; + private final ArrayList m_dependsFilesets = new ArrayList(); /** - * The URL from which the most recent version of this optional package - * can be obtained if it is not already installed. + * Filesets specifying all the librarys + * to generate optional dependency information about. */ - private String m_implementationURL; + private final ArrayList m_optionalsFilesets = new ArrayList(); /** * Extra attributes the user specifies for main section @@ -120,83 +93,52 @@ public class JarLibManifestTask private final ArrayList m_extraAttributes = new ArrayList(); /** - * Set the name of extension in generated manifest. - * - * @param extensionName the name of extension in generated manifest - */ - public void setExtensionName( final String extensionName ) - { - m_extensionName = extensionName; - } - - /** - * Set the specificationVersion of extension in generated manifest. - * - * @param specificationVersion the specificationVersion of extension in generated manifest - */ - public void setSpecificationVersion( final String specificationVersion ) - { - m_specificationVersion = new DeweyDecimal( specificationVersion ); - } - - /** - * Set the specificationVendor of extension in generated manifest. - * - * @param specificationVendor the specificationVendor of extension in generated manifest - */ - public void setSpecificationVendor( final String specificationVendor ) - { - m_specificationVendor = specificationVendor; - } - - /** - * Set the implementationVendorID of extension in generated manifest. - * - * @param implementationVendorID the implementationVendorID of extension in generated manifest - */ - public void setImplementationVendorID( final String implementationVendorID ) - { - m_implementationVendorID = implementationVendorID; - } - - /** - * Set the implementationVendor of extension in generated manifest. + * The location where generated manifest is placed. * - * @param implementationVendor the implementationVendor of extension in generated manifest + * @param destfile The location where generated manifest is placed. */ - public void setImplementationVendor( final String implementationVendor ) + public void setDestfile( final File destfile ) { - m_implementationVendor = implementationVendor; + m_destfile = destfile; } /** - * Set the implementationVersion of extension in generated manifest. + * Adds an extension that this library implements. * - * @param implementationVersion the implementationVersion of extension in generated manifest + * @param extensionAdapter an extension that this library implements. */ - public void setImplementationVersion( final String implementationVersion ) + public void addExtension( final ExtensionAdapter extensionAdapter ) + throws TaskException { - m_implementationVersion = new DeweyDecimal( implementationVersion ); + if( null != m_extension ) + { + final String message = REZ.getString( "manifest.multi-extension.error" ); + throw new TaskException( message ); + } + else + { + m_extension = extensionAdapter.toExtension(); + } } /** - * Set the implementationURL of extension in generated manifest. + * Adds an extension that this library requires. * - * @param implementationURL the implementationURL of extension in generated manifest + * @param extensionAdapter an extension that this library requires. */ - public void setImplementationURL( final String implementationURL ) + public void addDepends( final ExtensionAdapter extensionAdapter ) { - m_implementationURL = implementationURL; + m_dependencies.add( extensionAdapter ); } /** - * The location where generated manifest is placed. + * Adds an extension that this library optionally requires. * - * @param destfile The location where generated manifest is placed. + * @param extensionAdapter an extension that this library optionally requires. */ - public void setDestfile( final File destfile ) + public void addOption( final ExtensionAdapter extensionAdapter ) { - m_destfile = destfile; + m_optionals.add( extensionAdapter ); } /** @@ -204,9 +146,9 @@ public class JarLibManifestTask * * @param fileSet a set of files about which library data will be displayed. */ - public void addDepends( final LibFileSet fileSet ) + public void addDependsfileset( final LibFileSet fileSet ) { - m_dependencies.add( fileSet ); + m_dependsFilesets.add( fileSet ); } /** @@ -214,9 +156,9 @@ public class JarLibManifestTask * * @param fileSet a set of files about which library data will be displayed. */ - public void addOptional( final LibFileSet fileSet ) + public void addOptionalfileset( final LibFileSet fileSet ) { - m_optionals.addElement( fileSet ); + m_optionalsFilesets.add( fileSet ); } /** @@ -242,14 +184,26 @@ public class JarLibManifestTask appendExtraAttributes( attributes ); - appendExtensionData( attributes ); - - final String extensionKey = Extension.EXTENSION_LIST.toString(); - appendLibrarys( attributes, extensionKey, m_dependencies ); - - final String optionalExtensionKey = - "Optional-" + Extension.EXTENSION_LIST.toString(); - appendLibrarys( attributes, optionalExtensionKey, m_optionals ); + Extension.addExtension( m_extension, attributes ); + + //Add all the dependency data to manifest for dependencies + final ArrayList depends = toExtensions( m_dependencies ); + extractLibraryData( depends, m_dependsFilesets ); + appendExtensionList( attributes, + Extension.EXTENSION_LIST, + "lib", + depends.size() ); + appendLibraryList( attributes, "lib", depends ); + + //Add all the dependency data to manifest for "optional" + //dependencies + final ArrayList option = toExtensions( m_optionals ); + extractLibraryData( option, m_optionalsFilesets ); + appendExtensionList( attributes, + Extension.OPTIONAL_EXTENSION_LIST, + "opt", + option.size() ); + appendLibraryList( attributes, "opt", option ); try { @@ -328,123 +282,78 @@ public class JarLibManifestTask } /** - * Append specified librarys extension data to specified attributes. - * Use the extensionKey to list the extensions, usually "Extension-List:" - * for required dependencies and "Optional-Extension-List:" for optional - * dependencies. NOTE: "Optional" dependencies are not part of the - * specification. + * Generate a list of extensions from a specified fileset. * - * @param attributes the attributes to add extensions to - * @param extensionKey the key under which to add extensions - * @param librarys the filesets containing librarys + * @param librarys the list to add extensions to + * @param fileset the filesets containing librarys * @throws TaskException if an error occurs */ - private void appendLibrarys( final Attributes attributes, - final String extensionKey, - final Vector librarys ) + private void extractLibraryData( final ArrayList librarys, + final ArrayList fileset ) throws TaskException { - if( !librarys.isEmpty() ) + if( !fileset.isEmpty() ) { - final Extension[] extensions = getExtensions( librarys ); - final String[] names = getNames( extensions ); - final StringBuffer sb = new StringBuffer(); - for( int i = 0; i < names.length; i++ ) - { - sb.append( names[ i ] ); - sb.append( ' ' ); - } - - //Extension-List: javahelp java3d - attributes.putValue( extensionKey, sb.toString() ); - - for( int i = 0; i < names.length; i++ ) + final Extension[] extensions = getExtensions( fileset ); + for( int i = 0; i < extensions.length; i++ ) { - appendDependency( attributes, - names[ i ], - extensions[ i ] ); + librarys.add( extensions[ i ] ); } } } /** - * add a extension dependency to manifest. - * Use specified name as prefix name. + * Append specified librarys extension data to specified attributes. + * Use the extensionKey to list the extensions, usually "Extension-List:" + * for required dependencies and "Optional-Extension-List:" for optional + * dependencies. NOTE: "Optional" dependencies are not part of the + * specification. * - * @param attributes the attributes of manifest - * @param name the name to prefix to extension - * @param extension the extension + * @param attributes the attributes to add extensions to + * @param librarys the filesets containing librarys * @throws TaskException if an error occurs */ - private void appendDependency( final Attributes attributes, - final String name, - final Extension extension ) + private void appendLibraryList( final Attributes attributes, + final String listPrefix, + final ArrayList librarys ) throws TaskException { - final String prefix = name + "-"; - attributes.putValue( prefix + Extension.EXTENSION_NAME, - extension.getExtensionName() ); + final int size = librarys.size(); - final String specificationVendor = extension.getSpecificationVendor(); - if( null != specificationVendor ) + for( int i = 0; i < size; i++ ) { - attributes.putValue( prefix + Extension.SPECIFICATION_VENDOR, - specificationVendor ); - } - - final DeweyDecimal specificationVersion = extension.getSpecificationVersion(); - if( null != specificationVersion ) - { - attributes.putValue( prefix + Extension.SPECIFICATION_VERSION, - specificationVersion.toString() ); - } - - final String implementationVendorID = extension.getImplementationVendorID(); - if( null != implementationVendorID ) - { - attributes.putValue( prefix + Extension.IMPLEMENTATION_VENDOR_ID, - implementationVendorID ); - } - - final String implementationVendor = extension.getImplementationVendor(); - if( null != implementationVendor ) - { - attributes.putValue( prefix + Extension.IMPLEMENTATION_VENDOR, - implementationVendor ); - } - - final DeweyDecimal implementationVersion = extension.getImplementationVersion(); - if( null != implementationVersion ) - { - attributes.putValue( prefix + Extension.IMPLEMENTATION_VERSION, - implementationVersion.toString() ); - } - - final String implementationURL = extension.getImplementationURL(); - if( null != implementationURL ) - { - attributes.putValue( prefix + Extension.IMPLEMENTATION_URL, - implementationURL ); + final Extension extension = (Extension)librarys.get( i ); + final String prefix = listPrefix + i + "-"; + Extension.addExtension( extension, prefix, attributes ); } } /** - * Create an array of names that can be used for dependencies - * list for the specified extensions. + * Append an attribute such as "Extension-List: lib0 lib1 lib2" + * using specified prefix and counting up to specified size. + * Also use specified extensionKey so that can generate list of + * optional dependencies aswell. * - * @param extensions the extensions - * @return the names to use for extensions - */ - private String[] getNames( final Extension[] extensions ) + * @param size the number of librarys to list + * @param listPrefix the prefix for all librarys + * @param attributes the attributes to add key-value to + * @param extensionKey the key to use + */ + private void appendExtensionList( final Attributes attributes, + final Attributes.Name extensionKey, + final String listPrefix, + final int size ) { - final String[] results = new String[ extensions.length ]; - for( int i = 0; i < results.length; i++ ) + final StringBuffer sb = new StringBuffer(); + for( int i = 0; i < size; i++ ) { - //Perhaps generate mangled names based on extension in future - results[ i ] = "lib" + i; + sb.append( listPrefix + i ); + sb.append( ' ' ); } - return results; + //add in something like + //"Extension-List: javahelp java3d" + attributes.put( extensionKey, sb.toString() ); } /** @@ -454,14 +363,14 @@ public class JarLibManifestTask * @return the extensions contained in librarys * @throws TaskException if failing to scan librarys */ - private Extension[] getExtensions( final Vector librarys ) + private static Extension[] getExtensions( final ArrayList librarys ) throws TaskException { final ArrayList extensions = new ArrayList(); final Iterator iterator = librarys.iterator(); while( iterator.hasNext() ) { - final FileSet fileSet = (FileSet)iterator.next(); + final LibFileSet fileSet = (LibFileSet)iterator.next(); final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet ); final File basedir = scanner.getBasedir(); final String[] files = scanner.getIncludedFiles(); @@ -481,8 +390,8 @@ public class JarLibManifestTask * @param extensions the list to add available extensions to * @throws TaskException if there is an error */ - private void loadExtensions( final File file, - final ArrayList extensions ) + private static void loadExtensions( final File file, + final ArrayList extensions ) throws TaskException { try @@ -490,9 +399,9 @@ public class JarLibManifestTask final JarFile jarFile = new JarFile( file ); final Extension[] extension = Extension.getAvailable( jarFile.getManifest() ); - for( int j = 0; j < extension.length; j++ ) + for( int i = 0; i < extension.length; i++ ) { - extensions.add( extension[ j ] ); + extensions.add( extension[ i ] ); } } catch( final Exception e ) @@ -502,42 +411,25 @@ public class JarLibManifestTask } /** - * Add extension data into specified attributes. + * Convert a list of extensionAdapter objects to extensions. * - * @param attributes the attributes to add extension data to + * @param adapters the list of ExtensionAdapterss to add to convert + * @throws TaskException if an error occurs */ - private void appendExtensionData( final Attributes attributes ) + private static ArrayList toExtensions( final ArrayList adapters ) + throws TaskException { - attributes.put( Extension.EXTENSION_NAME, m_extensionName ); - if( null != m_specificationVendor ) - { - attributes.put( Extension.SPECIFICATION_VENDOR, - m_specificationVendor ); - } - if( null != m_specificationVersion ) - { - attributes.put( Extension.SPECIFICATION_VERSION, - m_specificationVersion.toString() ); - } - if( null != m_implementationVendorID ) - { - attributes.put( Extension.IMPLEMENTATION_VENDOR_ID, - m_implementationVendorID ); - } - if( null != m_implementationVendor ) - { - attributes.put( Extension.IMPLEMENTATION_VENDOR, - m_implementationVendor ); - } - if( null != m_implementationVersion ) - { - attributes.put( Extension.IMPLEMENTATION_VERSION, - m_implementationVersion.toString() ); - } - if( null != m_implementationURL ) + final ArrayList results = new ArrayList(); + + final int size = adapters.size(); + for( int i = 0; i < size; i++ ) { - attributes.put( Extension.IMPLEMENTATION_URL, - m_implementationURL ); + final ExtensionAdapter adapter = + (ExtensionAdapter)adapters.get( i ); + final Extension extension = adapter.toExtension(); + results.add( extension ); } + + return results; } } 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 f2500e165..cef51537e 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties @@ -5,6 +5,9 @@ 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}. +manifest.multi-extension.error=Can not have multiple extensions defined in one library. param.noname.error=Missing name from parameter. param.novalue.error=Missing value from parameter "{0}". + +extension.noname.error=Extension is missing name. \ No newline at end of file diff --git a/proposal/myrmidon/src/samples/sample.ant b/proposal/myrmidon/src/samples/sample.ant index 6c0cd517f..33875f1cb 100644 --- a/proposal/myrmidon/src/samples/sample.ant +++ b/proposal/myrmidon/src/samples/sample.ant @@ -337,19 +337,21 @@ Legal: --> - + + - + + - - + + - + +