|
@@ -13,7 +13,6 @@ import java.io.IOException; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Iterator; |
|
|
import java.util.Iterator; |
|
|
import java.util.jar.Attributes; |
|
|
import java.util.jar.Attributes; |
|
|
import java.util.jar.JarFile; |
|
|
|
|
|
import java.util.jar.Manifest; |
|
|
import java.util.jar.Manifest; |
|
|
import org.apache.avalon.excalibur.extension.Extension; |
|
|
import org.apache.avalon.excalibur.extension.Extension; |
|
|
import org.apache.avalon.excalibur.i18n.ResourceManager; |
|
|
import org.apache.avalon.excalibur.i18n.ResourceManager; |
|
@@ -22,8 +21,6 @@ import org.apache.avalon.excalibur.io.IOUtil; |
|
|
import org.apache.myrmidon.Constants; |
|
|
import org.apache.myrmidon.Constants; |
|
|
import org.apache.myrmidon.api.AbstractTask; |
|
|
import org.apache.myrmidon.api.AbstractTask; |
|
|
import org.apache.myrmidon.api.TaskException; |
|
|
import org.apache.myrmidon.api.TaskException; |
|
|
import org.apache.tools.todo.types.DirectoryScanner; |
|
|
|
|
|
import org.apache.tools.todo.types.ScannerUtil; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Task to generate a manifest that declares all the dependencies |
|
|
* Task to generate a manifest that declares all the dependencies |
|
@@ -79,18 +76,6 @@ public final class JarLibManifestTask |
|
|
*/ |
|
|
*/ |
|
|
private final ArrayList m_optionals = new ArrayList(); |
|
|
private final ArrayList m_optionals = new ArrayList(); |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Filesets specifying all the librarys |
|
|
|
|
|
* to generate dependency information about. |
|
|
|
|
|
*/ |
|
|
|
|
|
private final ArrayList m_dependsFilesets = new ArrayList(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Filesets specifying all the librarys |
|
|
|
|
|
* to generate optional dependency information about. |
|
|
|
|
|
*/ |
|
|
|
|
|
private final ArrayList m_optionalsFilesets = new ArrayList(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Extra attributes the user specifies for main section |
|
|
* Extra attributes the user specifies for main section |
|
|
* in manifest. |
|
|
* in manifest. |
|
@@ -127,43 +112,23 @@ public final class JarLibManifestTask |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Adds an extension that this library requires. |
|
|
|
|
|
* |
|
|
|
|
|
* @param extensionAdapter an extension that this library requires. |
|
|
|
|
|
*/ |
|
|
|
|
|
public void addDepends( final ExtensionAdapter extensionAdapter ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_dependencies.add( extensionAdapter ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Adds an extension that this library optionally requires. |
|
|
|
|
|
* |
|
|
|
|
|
* @param extensionAdapter an extension that this library optionally requires. |
|
|
|
|
|
*/ |
|
|
|
|
|
public void addOption( final ExtensionAdapter extensionAdapter ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_optionals.add( extensionAdapter ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Adds a set of files about which library data will be displayed. |
|
|
|
|
|
|
|
|
* Adds a set of extensions that this library requires. |
|
|
* |
|
|
* |
|
|
* @param fileSet a set of files about which library data will be displayed. |
|
|
|
|
|
|
|
|
* @param extensionSet a set of extensions that this library requires. |
|
|
*/ |
|
|
*/ |
|
|
public void addDependsfileset( final LibFileSet fileSet ) |
|
|
|
|
|
|
|
|
public void addDepends( final ExtensionSet extensionSet ) |
|
|
{ |
|
|
{ |
|
|
m_dependsFilesets.add( fileSet ); |
|
|
|
|
|
|
|
|
m_dependencies.add( extensionSet ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Adds a set of files about which library data will be displayed. |
|
|
|
|
|
|
|
|
* Adds a set of extensions that this library optionally requires. |
|
|
* |
|
|
* |
|
|
* @param fileSet a set of files about which library data will be displayed. |
|
|
|
|
|
|
|
|
* @param extensionSet a set of extensions that this library optionally requires. |
|
|
*/ |
|
|
*/ |
|
|
public void addOptionalfileset( final LibFileSet fileSet ) |
|
|
|
|
|
|
|
|
public void addOption( final ExtensionSet extensionSet ) |
|
|
{ |
|
|
{ |
|
|
m_optionalsFilesets.add( fileSet ); |
|
|
|
|
|
|
|
|
m_optionals.add( extensionSet ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -196,7 +161,6 @@ public final class JarLibManifestTask |
|
|
|
|
|
|
|
|
//Add all the dependency data to manifest for dependencies |
|
|
//Add all the dependency data to manifest for dependencies |
|
|
final ArrayList depends = toExtensions( m_dependencies ); |
|
|
final ArrayList depends = toExtensions( m_dependencies ); |
|
|
extractLibraryData( depends, m_dependsFilesets ); |
|
|
|
|
|
appendExtensionList( attributes, |
|
|
appendExtensionList( attributes, |
|
|
Extension.EXTENSION_LIST, |
|
|
Extension.EXTENSION_LIST, |
|
|
"lib", |
|
|
"lib", |
|
@@ -206,7 +170,6 @@ public final class JarLibManifestTask |
|
|
//Add all the dependency data to manifest for "optional" |
|
|
//Add all the dependency data to manifest for "optional" |
|
|
//dependencies |
|
|
//dependencies |
|
|
final ArrayList option = toExtensions( m_optionals ); |
|
|
final ArrayList option = toExtensions( m_optionals ); |
|
|
extractLibraryData( option, m_optionalsFilesets ); |
|
|
|
|
|
appendExtensionList( attributes, |
|
|
appendExtensionList( attributes, |
|
|
Extension.OPTIONAL_EXTENSION_LIST, |
|
|
Extension.OPTIONAL_EXTENSION_LIST, |
|
|
"opt", |
|
|
"opt", |
|
@@ -290,47 +253,25 @@ public final class JarLibManifestTask |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 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 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void extractLibraryData( 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 ] ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Append specified librarys extension data to specified attributes. |
|
|
|
|
|
|
|
|
* Append specified extensions to specified attributes. |
|
|
* Use the extensionKey to list the extensions, usually "Extension-List:" |
|
|
* Use the extensionKey to list the extensions, usually "Extension-List:" |
|
|
* for required dependencies and "Optional-Extension-List:" for optional |
|
|
* for required dependencies and "Optional-Extension-List:" for optional |
|
|
* dependencies. NOTE: "Optional" dependencies are not part of the |
|
|
* dependencies. NOTE: "Optional" dependencies are not part of the |
|
|
* specification. |
|
|
* specification. |
|
|
* |
|
|
* |
|
|
* @param attributes the attributes to add extensions to |
|
|
* @param attributes the attributes to add extensions to |
|
|
* @param librarys the filesets containing librarys |
|
|
|
|
|
|
|
|
* @param extensions the list of extensions |
|
|
* @throws TaskException if an error occurs |
|
|
* @throws TaskException if an error occurs |
|
|
*/ |
|
|
*/ |
|
|
private void appendLibraryList( final Attributes attributes, |
|
|
private void appendLibraryList( final Attributes attributes, |
|
|
final String listPrefix, |
|
|
final String listPrefix, |
|
|
final ArrayList librarys ) |
|
|
|
|
|
|
|
|
final ArrayList extensions ) |
|
|
throws TaskException |
|
|
throws TaskException |
|
|
{ |
|
|
{ |
|
|
final int size = librarys.size(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final int size = extensions.size(); |
|
|
for( int i = 0; i < size; i++ ) |
|
|
for( int i = 0; i < size; i++ ) |
|
|
{ |
|
|
{ |
|
|
final Extension extension = (Extension)librarys.get( i ); |
|
|
|
|
|
|
|
|
final Extension extension = (Extension)extensions.get( i ); |
|
|
final String prefix = listPrefix + i + "-"; |
|
|
final String prefix = listPrefix + i + "-"; |
|
|
Extension.addExtension( extension, prefix, attributes ); |
|
|
Extension.addExtension( extension, prefix, attributes ); |
|
|
} |
|
|
} |
|
@@ -365,77 +306,25 @@ public final class JarLibManifestTask |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Retrieve extensions from the specified librarys. |
|
|
|
|
|
|
|
|
* Convert a list of ExtensionSet objects to extensions. |
|
|
* |
|
|
* |
|
|
* @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 ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Convert a list of extensionAdapter objects to extensions. |
|
|
|
|
|
* |
|
|
|
|
|
* @param adapters the list of ExtensionAdapterss to add to convert |
|
|
|
|
|
|
|
|
* @param extensionSets the list of ExtensionSets to add to list |
|
|
* @throws TaskException if an error occurs |
|
|
* @throws TaskException if an error occurs |
|
|
*/ |
|
|
*/ |
|
|
private static ArrayList toExtensions( final ArrayList adapters ) |
|
|
|
|
|
|
|
|
private static ArrayList toExtensions( final ArrayList extensionSets ) |
|
|
throws TaskException |
|
|
throws TaskException |
|
|
{ |
|
|
{ |
|
|
final ArrayList results = new ArrayList(); |
|
|
final ArrayList results = new ArrayList(); |
|
|
|
|
|
|
|
|
final int size = adapters.size(); |
|
|
|
|
|
|
|
|
final int size = extensionSets.size(); |
|
|
for( int i = 0; i < size; i++ ) |
|
|
for( int i = 0; i < size; i++ ) |
|
|
{ |
|
|
{ |
|
|
final ExtensionAdapter adapter = |
|
|
|
|
|
(ExtensionAdapter)adapters.get( i ); |
|
|
|
|
|
final Extension extension = adapter.toExtension(); |
|
|
|
|
|
results.add( extension ); |
|
|
|
|
|
|
|
|
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; |
|
|
return results; |
|
|