You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2002/04/06 06:25:49 UTC
cvs commit: jakarta-ant/proposal/myrmidon/lib excalibur-extension-1.0a.jar
donaldp 02/04/05 20:25:49
Modified: proposal/myrmidon/src/samples sample.ant
proposal/myrmidon/src/java/org/apache/antlib/extensions
Resources.properties JarLibManifestTask.java
proposal/myrmidon/lib excalibur-extension-1.0a.jar
Added: proposal/myrmidon/src/java/org/apache/antlib/extensions
ExtensionAdapter.java
Log:
Reworked task based on feedback.
Moved all attributes relating to extension into a sub-element "extension"
Renamed "depends" to "dependsfileset"
Renamed "optional" to "optionalfileset"
Added "depends" sub element that are the same as "extension" sub-element
Added "option" sub element that are the same as "extension" sub-element
Revision Changes Path
1.7 +11 -9 jakarta-ant/proposal/myrmidon/src/samples/sample.ant
Index: sample.ant
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/samples/sample.ant,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- sample.ant 4 Apr 2002 11:00:44 -0000 1.6
+++ sample.ant 6 Apr 2002 04:25:49 -0000 1.7
@@ -337,19 +337,21 @@
-->
<target name="manifest-test">
- <jarlib-manifest
- destfile="../../generated-manifest.txt"
- extension-name="org.realityforge.dve"
- specification-version="1.0"
- specification-vendor="Peter Donald" >
+ <jarlib-manifest destfile="../../generated-manifest.txt">
+ <extension
+ extension-name="org.realityforge.dve"
+ specification-version="1.0"
+ specification-vendor="Peter Donald"/>
<attribute name="Main-class"
value="org.realityforg.dve.WorldGen"/>
- <depends dir="../../">
+
+ <dependsfileset dir="../../">
<include name="src/ant1compat/jar/*.jar"/>
- </depends>
- <depends dir="../../">
+ </dependsfileset>
+ <dependsfileset dir="../../">
<include name="lib/*.jar"/>
- </depends>
+ </dependsfileset>
+
</jarlib-manifest>
</target>
1.4 +3 -0 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 4 Apr 2002 11:00:44 -0000 1.3
+++ Resources.properties 6 Apr 2002 04:25:49 -0000 1.4
@@ -5,6 +5,9 @@
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
1.3 +127 -235 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java
Index: JarLibManifestTask.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JarLibManifestTask.java 4 Apr 2002 11:00:44 -0000 1.2
+++ JarLibManifestTask.java 6 Apr 2002 04:25:49 -0000 1.3
@@ -12,11 +12,9 @@
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.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 @@
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @ant.task name="jarlib-manifest"
*/
-public class JarLibManifestTask
+public final class JarLibManifestTask
extends AbstractTask
{
private final static Resources REZ =
@@ -61,57 +58,33 @@
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.
+ * The extension supported by this library (if any).
*/
- private final Vector m_optionals = new Vector();
+ private Extension m_extension;
/**
- * The name of the optional package being made available, or required.
+ * ExtensionAdapter objects representing
+ * dependencies required by library.
*/
- private String m_extensionName;
+ private final ArrayList m_dependencies = new ArrayList();
/**
- * The version number (dotted decimal notation) of the specification
- * to which this optional package conforms.
+ * ExtensionAdapter objects representing optional
+ * dependencies required by library.
*/
- private DeweyDecimal m_specificationVersion;
+ private final ArrayList m_optionals = new ArrayList();
/**
- * 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.
+ * 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 @@
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 @@
*
* @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 @@
*
* @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 @@
appendExtraAttributes( attributes );
- appendExtensionData( attributes );
+ Extension.addExtension( m_extension, 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 );
+ //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 @@
}
/**
- * 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++ )
+ final Extension[] extensions = getExtensions( fileset );
+ for( int i = 0; i < extensions.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++ )
- {
- 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 String specificationVendor = extension.getSpecificationVendor();
- if( null != specificationVendor )
- {
- 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 int size = librarys.size();
- final String implementationURL = extension.getImplementationURL();
- if( null != implementationURL )
+ for( int i = 0; i < size; i++ )
{
- 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
+ * @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 String[] getNames( final Extension[] extensions )
+ 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 @@
* @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 @@
* @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 @@
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 @@
}
/**
- * 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;
}
}
1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionAdapter.java
Index: ExtensionAdapter.java
===================================================================
/*
* 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 <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/04/06 04:25:49 $
*/
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 );
}
}
1.2 +78 -371 jakarta-ant/proposal/myrmidon/lib/excalibur-extension-1.0a.jar
<<Binary file>>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>