git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272486 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,174 +0,0 @@ | |||||
/* | |||||
* 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; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | |||||
* Simple class that represents an Extension and conforms to Ants | |||||
* patterns. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
* @ant.data-type name="extension" | |||||
*/ | |||||
public class ExtensionAdapter | |||||
implements DataType | |||||
{ | |||||
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,69 +0,0 @@ | |||||
/* | |||||
* 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 java.util.ArrayList; | |||||
import org.apache.avalon.excalibur.extension.Extension; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.framework.DataType; | |||||
/** | |||||
* The Extension set lists a set of "Optional Packages" / | |||||
* "Extensions". | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
* @ant.data-type name="extension-set" | |||||
*/ | |||||
public class ExtensionSet | |||||
implements DataType | |||||
{ | |||||
/** | |||||
* ExtensionAdapter objects representing extensions. | |||||
*/ | |||||
private final ArrayList m_extensions = new ArrayList(); | |||||
/** | |||||
* Filesets specifying all the extensions wanted. | |||||
*/ | |||||
private final ArrayList m_extensionsFilesets = new ArrayList(); | |||||
/** | |||||
* Adds an extension that this library requires. | |||||
* | |||||
* @param extensionAdapter an extension that this library requires. | |||||
*/ | |||||
public void addExtension( final ExtensionAdapter extensionAdapter ) | |||||
{ | |||||
m_extensions.add( extensionAdapter ); | |||||
} | |||||
/** | |||||
* Adds a set of files about which extensions data will be extracted. | |||||
* | |||||
* @param fileSet a set of files about which extensions data will be extracted. | |||||
*/ | |||||
public void addLibfileset( final LibFileSet fileSet ) | |||||
{ | |||||
m_extensionsFilesets.add( fileSet ); | |||||
} | |||||
/** | |||||
* Extract a set of Extension objects from the ExtensionSet. | |||||
* | |||||
* @throws TaskException if an error occurs | |||||
*/ | |||||
public Extension[] toExtensions() | |||||
throws TaskException | |||||
{ | |||||
final ArrayList extensions = ExtensionUtil.toExtensions( m_extensions ); | |||||
ExtensionUtil.extractExtensions( extensions, m_extensionsFilesets ); | |||||
return (Extension[])extensions.toArray( new Extension[ extensions.size() ] ); | |||||
} | |||||
} |
@@ -1,124 +0,0 @@ | |||||
/* | |||||
* 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 java.io.File; | |||||
import java.util.ArrayList; | |||||
import java.util.Iterator; | |||||
import java.util.jar.JarFile; | |||||
import org.apache.avalon.excalibur.extension.Extension; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.tools.todo.types.DirectoryScanner; | |||||
import org.apache.tools.todo.types.ScannerUtil; | |||||
/** | |||||
* A set of useful methods relating to extensions. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class ExtensionUtil | |||||
{ | |||||
/** | |||||
* Convert a list of extensionAdapter objects to extensions. | |||||
* | |||||
* @param adapters the list of ExtensionAdapterss to add to convert | |||||
* @throws TaskException if an error occurs | |||||
*/ | |||||
static ArrayList toExtensions( final ArrayList adapters ) | |||||
throws TaskException | |||||
{ | |||||
final ArrayList results = new ArrayList(); | |||||
final int size = adapters.size(); | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
final ExtensionAdapter adapter = | |||||
(ExtensionAdapter)adapters.get( i ); | |||||
final Extension extension = adapter.toExtension(); | |||||
results.add( extension ); | |||||
} | |||||
return results; | |||||
} | |||||
/** | |||||
* Generate a list of extensions from a specified fileset. | |||||
* | |||||
* @param librarys the list to add extensions to | |||||
* @param fileset the filesets containing librarys | |||||
* @throws TaskException if an error occurs | |||||
*/ | |||||
static void extractExtensions( final ArrayList librarys, | |||||
final ArrayList fileset ) | |||||
throws TaskException | |||||
{ | |||||
if( !fileset.isEmpty() ) | |||||
{ | |||||
final Extension[] extensions = getExtensions( fileset ); | |||||
for( int i = 0; i < extensions.length; i++ ) | |||||
{ | |||||
librarys.add( extensions[ i ] ); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Retrieve extensions from the specified librarys. | |||||
* | |||||
* @param librarys the filesets for librarys | |||||
* @return the extensions contained in librarys | |||||
* @throws TaskException if failing to scan librarys | |||||
*/ | |||||
private static Extension[] getExtensions( final ArrayList librarys ) | |||||
throws TaskException | |||||
{ | |||||
final ArrayList extensions = new ArrayList(); | |||||
final Iterator iterator = librarys.iterator(); | |||||
while( iterator.hasNext() ) | |||||
{ | |||||
final LibFileSet fileSet = (LibFileSet)iterator.next(); | |||||
final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet ); | |||||
final File basedir = scanner.getBasedir(); | |||||
final String[] files = scanner.getIncludedFiles(); | |||||
for( int i = 0; i < files.length; i++ ) | |||||
{ | |||||
final File file = new File( basedir, files[ i ] ); | |||||
loadExtensions( file, extensions ); | |||||
} | |||||
} | |||||
return (Extension[])extensions.toArray( new Extension[ extensions.size() ] ); | |||||
} | |||||
/** | |||||
* Load list of available extensions from specified file. | |||||
* | |||||
* @param file the file | |||||
* @param extensions the list to add available extensions to | |||||
* @throws TaskException if there is an error | |||||
*/ | |||||
private static void loadExtensions( final File file, | |||||
final ArrayList extensions ) | |||||
throws TaskException | |||||
{ | |||||
try | |||||
{ | |||||
final JarFile jarFile = new JarFile( file ); | |||||
final Extension[] extension = | |||||
Extension.getAvailable( jarFile.getManifest() ); | |||||
for( int i = 0; i < extension.length; i++ ) | |||||
{ | |||||
extensions.add( extension[ i ] ); | |||||
} | |||||
} | |||||
catch( final Exception e ) | |||||
{ | |||||
throw new TaskException( e.getMessage(), e ); | |||||
} | |||||
} | |||||
} |
@@ -1,89 +0,0 @@ | |||||
/* | |||||
* 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 <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @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 ); | |||||
} | |||||
} | |||||
} |
@@ -1,125 +0,0 @@ | |||||
/* | |||||
* 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 java.io.File; | |||||
import java.util.Iterator; | |||||
import java.util.Vector; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
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; | |||||
/** | |||||
* Display the "Optional Package" and "Package Specification" information | |||||
* contained within the specified jars. | |||||
* | |||||
* <p>Prior to JDK1.3, an "Optional Package" was known as an Extension. | |||||
* The specification for this mechanism is available in the JDK1.3 | |||||
* documentation in the directory | |||||
* $JDK_HOME/docs/guide/extensions/versioning.html. Alternatively it is | |||||
* available online at <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html"> | |||||
* http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html</a>.</p> | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @ant.task name="jarlib-display" | |||||
*/ | |||||
public class JarLibDisplayTask | |||||
extends AbstractTask | |||||
{ | |||||
private final static Resources REZ = | |||||
ResourceManager.getPackageResources( JarLibDisplayTask.class ); | |||||
/** | |||||
* The library to display information about. | |||||
*/ | |||||
private File m_file; | |||||
/** | |||||
* Filesets specifying all the librarys | |||||
* to display information about. | |||||
*/ | |||||
private final Vector m_filesets = new Vector(); | |||||
/** | |||||
* The jar library to display information for. | |||||
* | |||||
* @param file The jar library to display information for. | |||||
*/ | |||||
public void setFile( final File file ) | |||||
{ | |||||
m_file = file; | |||||
} | |||||
/** | |||||
* Adds a set of files about which library data will be displayed. | |||||
* | |||||
* @param fileSet a set of files about which library data will be displayed. | |||||
*/ | |||||
public void addFileset( final FileSet fileSet ) | |||||
{ | |||||
m_filesets.addElement( fileSet ); | |||||
} | |||||
public void execute() | |||||
throws TaskException | |||||
{ | |||||
validate(); | |||||
final LibraryDisplayer displayer = new LibraryDisplayer(); | |||||
// Check if list of files to check has been specified | |||||
if( !m_filesets.isEmpty() ) | |||||
{ | |||||
final Iterator iterator = m_filesets.iterator(); | |||||
while( iterator.hasNext() ) | |||||
{ | |||||
final FileSet fileSet = (FileSet)iterator.next(); | |||||
final DirectoryScanner scanner = ScannerUtil.getDirectoryScanner( fileSet ); | |||||
final File basedir = scanner.getBasedir(); | |||||
final String[] files = scanner.getIncludedFiles(); | |||||
for( int i = 0; i < files.length; i++ ) | |||||
{ | |||||
final File file = new File( basedir, files[ i ] ); | |||||
displayer.displayLibrary( file ); | |||||
} | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
displayer.displayLibrary( m_file ); | |||||
} | |||||
} | |||||
/** | |||||
* Validate the tasks parameters. | |||||
* | |||||
* @throws TaskException if invalid parameters found | |||||
*/ | |||||
private void validate() | |||||
throws TaskException | |||||
{ | |||||
if( null == m_file && m_filesets.isEmpty() ) | |||||
{ | |||||
final String message = REZ.getString( "extension.missing-file.error" ); | |||||
throw new TaskException( message ); | |||||
} | |||||
if( null != m_file && !m_file.exists() ) | |||||
{ | |||||
final String message = REZ.getString( "extension.file-noexist.error", m_file ); | |||||
throw new TaskException( message ); | |||||
} | |||||
if( null != m_file && !m_file.isFile() ) | |||||
{ | |||||
final String message = REZ.getString( "extension.bad-file.error", m_file ); | |||||
throw new TaskException( message ); | |||||
} | |||||
} | |||||
} |
@@ -1,332 +0,0 @@ | |||||
/* | |||||
* 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 java.io.File; | |||||
import java.io.FileOutputStream; | |||||
import java.io.IOException; | |||||
import java.util.ArrayList; | |||||
import java.util.Iterator; | |||||
import java.util.jar.Attributes; | |||||
import java.util.jar.Manifest; | |||||
import org.apache.avalon.excalibur.extension.Extension; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.excalibur.io.IOUtil; | |||||
import org.apache.myrmidon.Constants; | |||||
import org.apache.myrmidon.api.AbstractTask; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
/** | |||||
* Task to generate a manifest that declares all the dependencies | |||||
* in manifest. The dependencies are determined by looking in the | |||||
* specified path and searching for Extension / "Optional Package" | |||||
* specifications in the manifests of the jars. | |||||
* | |||||
* <p>Prior to JDK1.3, an "Optional Package" was known as an Extension. | |||||
* The specification for this mechanism is available in the JDK1.3 | |||||
* documentation in the directory | |||||
* $JDK_HOME/docs/guide/extensions/versioning.html. Alternatively it is | |||||
* available online at <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html"> | |||||
* http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html</a>.</p> | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @ant.task name="jarlib-manifest" | |||||
*/ | |||||
public final class JarLibManifestTask | |||||
extends AbstractTask | |||||
{ | |||||
private final static Resources REZ = | |||||
ResourceManager.getPackageResources( JarLibManifestTask.class ); | |||||
/** | |||||
* Version of manifest spec that task generates. | |||||
*/ | |||||
private static final String MANIFEST_VERSION = "1.0"; | |||||
/** | |||||
* "Created-By" string used when creating manifest. | |||||
*/ | |||||
private static final String CREATED_BY = "Created-By"; | |||||
/** | |||||
* The library to display information about. | |||||
*/ | |||||
private File m_destfile; | |||||
/** | |||||
* The extension supported by this library (if any). | |||||
*/ | |||||
private Extension m_extension; | |||||
/** | |||||
* ExtensionAdapter objects representing | |||||
* dependencies required by library. | |||||
*/ | |||||
private final ArrayList m_dependencies = new ArrayList(); | |||||
/** | |||||
* ExtensionAdapter objects representing optional | |||||
* dependencies required by library. | |||||
*/ | |||||
private final ArrayList m_optionals = new ArrayList(); | |||||
/** | |||||
* Extra attributes the user specifies for main section | |||||
* in manifest. | |||||
*/ | |||||
private final ArrayList m_extraAttributes = new ArrayList(); | |||||
/** | |||||
* The location where generated manifest is placed. | |||||
* | |||||
* @param destfile The location where generated manifest is placed. | |||||
*/ | |||||
public void setDestfile( final File destfile ) | |||||
{ | |||||
m_destfile = destfile; | |||||
} | |||||
/** | |||||
* Adds an extension that this library implements. | |||||
* | |||||
* @param extensionAdapter an extension that this library implements. | |||||
*/ | |||||
public void addExtension( final ExtensionAdapter extensionAdapter ) | |||||
throws TaskException | |||||
{ | |||||
if( null != m_extension ) | |||||
{ | |||||
final String message = REZ.getString( "manifest.multi-extension.error" ); | |||||
throw new TaskException( message ); | |||||
} | |||||
else | |||||
{ | |||||
m_extension = extensionAdapter.toExtension(); | |||||
} | |||||
} | |||||
/** | |||||
* Adds a set of extensions that this library requires. | |||||
* | |||||
* @param extensionSet a set of extensions that this library requires. | |||||
*/ | |||||
public void addDepends( final ExtensionSet extensionSet ) | |||||
{ | |||||
m_dependencies.add( extensionSet ); | |||||
} | |||||
/** | |||||
* Adds a set of extensions that this library optionally requires. | |||||
* | |||||
* @param extensionSet a set of extensions that this library optionally requires. | |||||
*/ | |||||
public void addOptions( final ExtensionSet extensionSet ) | |||||
{ | |||||
m_optionals.add( extensionSet ); | |||||
} | |||||
/** | |||||
* 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 | |||||
{ | |||||
validate(); | |||||
final Manifest manifest = new Manifest(); | |||||
final Attributes attributes = manifest.getMainAttributes(); | |||||
attributes.put( Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION ); | |||||
attributes.putValue( CREATED_BY, Constants.BUILD_DESCRIPTION ); | |||||
appendExtraAttributes( attributes ); | |||||
if( null != m_extension ) | |||||
{ | |||||
Extension.addExtension( m_extension, attributes ); | |||||
} | |||||
//Add all the dependency data to manifest for dependencies | |||||
final ArrayList depends = toExtensions( m_dependencies ); | |||||
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 ); | |||||
appendExtensionList( attributes, | |||||
Extension.OPTIONAL_EXTENSION_LIST, | |||||
"opt", | |||||
option.size() ); | |||||
appendLibraryList( attributes, "opt", option ); | |||||
try | |||||
{ | |||||
final String message = | |||||
REZ.getString( "manifest.file.notice", | |||||
m_destfile.getAbsoluteFile() ); | |||||
getContext().info( message ); | |||||
writeManifest( manifest ); | |||||
} | |||||
catch( final IOException ioe ) | |||||
{ | |||||
throw new TaskException( ioe.getMessage(), ioe ); | |||||
} | |||||
} | |||||
/** | |||||
* Validate the tasks parameters. | |||||
* | |||||
* @throws TaskException if invalid parameters found | |||||
*/ | |||||
private void validate() | |||||
throws TaskException | |||||
{ | |||||
if( null == m_destfile ) | |||||
{ | |||||
final String message = | |||||
REZ.getString( "manifest.missing-file.error" ); | |||||
throw new TaskException( message ); | |||||
} | |||||
if( m_destfile.exists() && !m_destfile.isFile() ) | |||||
{ | |||||
final String message = | |||||
REZ.getString( "manifest.bad-file.error", m_destfile ); | |||||
throw new TaskException( message ); | |||||
} | |||||
} | |||||
/** | |||||
* 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. | |||||
* | |||||
* @param manifest the manifest | |||||
* @throws IOException if error writing file | |||||
*/ | |||||
private void writeManifest( final Manifest manifest ) | |||||
throws IOException | |||||
{ | |||||
FileOutputStream output = null; | |||||
try | |||||
{ | |||||
output = new FileOutputStream( m_destfile ); | |||||
manifest.write( output ); | |||||
output.flush(); | |||||
} | |||||
finally | |||||
{ | |||||
IOUtil.shutdownStream( output ); | |||||
} | |||||
} | |||||
/** | |||||
* Append specified extensions 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 to add extensions to | |||||
* @param extensions the list of extensions | |||||
* @throws TaskException if an error occurs | |||||
*/ | |||||
private void appendLibraryList( final Attributes attributes, | |||||
final String listPrefix, | |||||
final ArrayList extensions ) | |||||
throws TaskException | |||||
{ | |||||
final int size = extensions.size(); | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
final Extension extension = (Extension)extensions.get( i ); | |||||
final String prefix = listPrefix + i + "-"; | |||||
Extension.addExtension( extension, prefix, attributes ); | |||||
} | |||||
} | |||||
/** | |||||
* 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 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 StringBuffer sb = new StringBuffer(); | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
sb.append( listPrefix + i ); | |||||
sb.append( ' ' ); | |||||
} | |||||
//add in something like | |||||
//"Extension-List: javahelp java3d" | |||||
attributes.put( extensionKey, sb.toString() ); | |||||
} | |||||
/** | |||||
* Convert a list of ExtensionSet objects to extensions. | |||||
* | |||||
* @param extensionSets the list of ExtensionSets to add to list | |||||
* @throws TaskException if an error occurs | |||||
*/ | |||||
private static ArrayList toExtensions( final ArrayList extensionSets ) | |||||
throws TaskException | |||||
{ | |||||
final ArrayList results = new ArrayList(); | |||||
final int size = extensionSets.size(); | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
final ExtensionSet set = (ExtensionSet)extensionSets.get( i ); | |||||
final Extension[] extensions = set.toExtensions(); | |||||
for( int j = 0; j < extensions.length; j++ ) | |||||
{ | |||||
results.add( extensions[ j ] ); | |||||
} | |||||
} | |||||
return results; | |||||
} | |||||
} |
@@ -1,119 +0,0 @@ | |||||
/* | |||||
* 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.myrmidon.framework.FileSet; | |||||
/** | |||||
* LibFileSet represents a fileset containing libraries. | |||||
* Asociated with the libraries is data pertaining to | |||||
* how they are to be handled when building manifests. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class LibFileSet | |||||
extends FileSet | |||||
{ | |||||
/** | |||||
* Flag indicating whether should include the | |||||
* "Implementation-URL" attribute in manifest. | |||||
* Defaults to false. | |||||
*/ | |||||
private boolean m_includeURL; | |||||
/** | |||||
* Flag indicating whether should include the | |||||
* "Implementation-*" attributes in manifest. | |||||
* Defaults to false. | |||||
*/ | |||||
private boolean m_includeImpl; | |||||
/** | |||||
* String that is the base URL for the librarys | |||||
* when constructing the "Implementation-URL" | |||||
* attribute. For instance setting the base to | |||||
* "http://jakarta.apache.org/avalon/libs/" and then | |||||
* including the library "excalibur-cli-1.0.jar" in the | |||||
* fileset will result in the "Implementation-URL" attribute | |||||
* being set to "http://jakarta.apache.org/avalon/libs/excalibur-cli-1.0.jar" | |||||
* | |||||
* Note this is only used if the library does not define | |||||
* "Implementation-URL" itself. | |||||
* | |||||
* Note that this also implies includeURL=true | |||||
*/ | |||||
private String m_urlBase; | |||||
/** | |||||
* Flag indicating whether should include the | |||||
* "Implementation-URL" attribute in manifest. | |||||
* Defaults to false. | |||||
* | |||||
* @param includeURL the flag | |||||
* @see #m_includeURL | |||||
*/ | |||||
public void setIncludeURL( boolean includeURL ) | |||||
{ | |||||
m_includeURL = includeURL; | |||||
} | |||||
/** | |||||
* Flag indicating whether should include the | |||||
* "Implementation-*" attributes in manifest. | |||||
* Defaults to false. | |||||
* | |||||
* @param includeImpl the flag | |||||
* @see #m_includeImpl | |||||
*/ | |||||
public void setIncludeImpl( boolean includeImpl ) | |||||
{ | |||||
m_includeImpl = includeImpl; | |||||
} | |||||
/** | |||||
* Set the url base for fileset. | |||||
* | |||||
* @param urlBase the base url | |||||
* @see #m_urlBase | |||||
*/ | |||||
public void setUrlBase( String urlBase ) | |||||
{ | |||||
m_urlBase = urlBase; | |||||
} | |||||
/** | |||||
* Get the includeURL flag. | |||||
* | |||||
* @return the includeURL flag. | |||||
*/ | |||||
boolean isIncludeURL() | |||||
{ | |||||
return m_includeURL; | |||||
} | |||||
/** | |||||
* Get the includeImpl flag. | |||||
* | |||||
* @return the includeImpl flag. | |||||
*/ | |||||
boolean isIncludeImpl() | |||||
{ | |||||
return m_includeImpl; | |||||
} | |||||
/** | |||||
* Get the urlbase. | |||||
* | |||||
* @return the urlbase. | |||||
*/ | |||||
String getUrlBase() | |||||
{ | |||||
return m_urlBase; | |||||
} | |||||
} |
@@ -1,190 +0,0 @@ | |||||
/* | |||||
* 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 java.io.File; | |||||
import java.io.IOException; | |||||
import java.text.ParseException; | |||||
import java.util.jar.JarFile; | |||||
import java.util.jar.Manifest; | |||||
import org.apache.avalon.excalibur.extension.Extension; | |||||
import org.apache.avalon.excalibur.extension.Specification; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
/** | |||||
* Utility class to output the information in a jar relating | |||||
* to "Optional Packages" (formely known as "Extensions") | |||||
* and Package Specifications. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
class LibraryDisplayer | |||||
{ | |||||
/** | |||||
* Display the extensions and specifications contained | |||||
* within specified file. | |||||
* | |||||
* @param file the file | |||||
* @throws TaskException if fail to read file | |||||
*/ | |||||
void displayLibrary( final File file ) | |||||
throws TaskException | |||||
{ | |||||
final Manifest manifest = getManifest( file ); | |||||
displayLibrary( file, manifest ); | |||||
} | |||||
/** | |||||
* Display the extensions and specifications contained | |||||
* within specified file. | |||||
* | |||||
* @param file the file to use while reporting | |||||
* @param manifest the manifest of file | |||||
* @throws TaskException if fail to read file | |||||
*/ | |||||
void displayLibrary( final File file, | |||||
final Manifest manifest ) | |||||
throws TaskException | |||||
{ | |||||
final Extension[] available = Extension.getAvailable( manifest ); | |||||
final Extension[] required = Extension.getRequired( manifest ); | |||||
final Extension[] options = Extension.getOptions( manifest ); | |||||
final Specification[] specifications = getSpecifications( manifest ); | |||||
if( 0 == available.length && | |||||
0 == required.length && | |||||
0 == options.length && | |||||
0 == specifications.length ) | |||||
{ | |||||
return; | |||||
} | |||||
final String message = "File: " + file; | |||||
final int size = message.length(); | |||||
printLine( size ); | |||||
System.out.println( message ); | |||||
printLine( size ); | |||||
if( 0 != available.length ) | |||||
{ | |||||
System.out.println( "Extensions Supported By Library:" ); | |||||
for( int i = 0; i < available.length; i++ ) | |||||
{ | |||||
final Extension extension = available[ i ]; | |||||
System.out.println( extension.toString() ); | |||||
} | |||||
} | |||||
if( 0 != required.length ) | |||||
{ | |||||
System.out.println( "Extensions Required By Library:" ); | |||||
for( int i = 0; i < required.length; i++ ) | |||||
{ | |||||
final Extension extension = required[ i ]; | |||||
System.out.println( extension.toString() ); | |||||
} | |||||
} | |||||
if( 0 != options.length ) | |||||
{ | |||||
System.out.println( "Extensions that will be used by Library if present:" ); | |||||
for( int i = 0; i < options.length; i++ ) | |||||
{ | |||||
final Extension extension = options[ i ]; | |||||
System.out.println( extension.toString() ); | |||||
} | |||||
} | |||||
if( 0 != specifications.length ) | |||||
{ | |||||
System.out.println( "Specifications Supported By Library:" ); | |||||
for( int i = 0; i < specifications.length; i++ ) | |||||
{ | |||||
final Specification specification = specifications[ i ]; | |||||
displaySpecification( specification ); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Print out a line of '-'s equal to specified size. | |||||
* | |||||
* @param size the number of dashes to printout | |||||
*/ | |||||
private void printLine( final int size ) | |||||
{ | |||||
for( int i = 0; i < size; i++ ) | |||||
{ | |||||
System.out.print( "-" ); | |||||
} | |||||
System.out.println(); | |||||
} | |||||
/** | |||||
* Get specifications from manifest. | |||||
* | |||||
* @param manifest the manifest | |||||
* @return the specifications or null if none | |||||
* @throws TaskException if malformed specification sections | |||||
*/ | |||||
private Specification[] getSpecifications( final Manifest manifest ) | |||||
throws TaskException | |||||
{ | |||||
try | |||||
{ | |||||
return Specification.getSpecifications( manifest ); | |||||
} | |||||
catch( final ParseException pe ) | |||||
{ | |||||
throw new TaskException( pe.getMessage(), pe ); | |||||
} | |||||
} | |||||
/** | |||||
* Print out specification details. | |||||
* | |||||
* @param specification the specification | |||||
*/ | |||||
private void displaySpecification( final Specification specification ) | |||||
{ | |||||
final String[] sections = specification.getSections(); | |||||
if( null != sections ) | |||||
{ | |||||
final StringBuffer sb = new StringBuffer( "Sections: " ); | |||||
for( int i = 0; i < sections.length; i++ ) | |||||
{ | |||||
sb.append( " " ); | |||||
sb.append( sections[ i ] ); | |||||
} | |||||
System.out.println( sb ); | |||||
} | |||||
System.out.println( specification.toString() ); | |||||
} | |||||
/** | |||||
* retrieve manifest for specified file. | |||||
* | |||||
* @param file the file | |||||
* @return the manifest | |||||
* @throws org.apache.myrmidon.api.TaskException if errror occurs (file not exist, | |||||
* file not a jar, manifest not exist in file) | |||||
*/ | |||||
private Manifest getManifest( final File file ) | |||||
throws TaskException | |||||
{ | |||||
try | |||||
{ | |||||
final JarFile jarFile = new JarFile( file ); | |||||
return jarFile.getManifest(); | |||||
} | |||||
catch( final IOException ioe ) | |||||
{ | |||||
throw new TaskException( ioe.getMessage(), ioe ); | |||||
} | |||||
} | |||||
} |
@@ -1,13 +0,0 @@ | |||||
extension.missing-file.error=File attribute not specified. | |||||
extension.file-noexist.error=File "{0}" does not exist. | |||||
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. |