donaldp 02/04/02 04:06:37
Modified: proposal/myrmidon build.xml
proposal/myrmidon/src/samples sample.ant
Added: proposal/myrmidon/src/java/org/apache/antlib/extensions
ExtensionDisplayTask.java LibraryDisplay.java
Resources.properties
Log:
Write a basic task that prints out extension and package specification data
for a library or set of librarys
Revision Changes Path
1.101 +11 -7 jakarta-ant/proposal/myrmidon/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -r1.100 -r1.101
--- build.xml 1 Apr 2002 09:56:25 -0000 1.100
+++ build.xml 2 Apr 2002 12:06:37 -0000 1.101
@@ -237,10 +237,10 @@
<javac
destdir="${build.classes}"
debug="${debug}"
- deprecation="${deprecation}"
+ deprecation="${deprecation}"
includeAntRuntime="false"
includeJavaRuntime="false">
-
+
<classpath refid="project.class.path"/>
<src location="src/todo"/>
<src path="${java.dir}" />
@@ -495,6 +495,10 @@
</ant>
<ant antfile="antlib.xml">
+ <property name="antlib.name" value="extensions"/>
+ </ant>
+
+ <ant antfile="antlib.xml">
<property name="antlib.name" value="file"/>
</ant>
@@ -546,12 +550,12 @@
destdir="${test.classes}"
debug="${debug}"
deprecation="${deprecation}">
-
+
<classpath>
<pathelement location="${build.classes}"/>
<path refid="project.class.path"/>
</classpath>
-
+
<exclude name="**/SmbFileSystemTestCase.java"
unless="jcifs.present"/>
<exclude name="**/FtpFileSystemTestCase.java"
unless="netcomp.present"/>
</javac>
@@ -611,7 +615,7 @@
tofile="${test.classes}/META-INF/ant-descriptor.xml"/>
<!-- Run all the tests -->
- <junit printsummary="on"
+ <junit printsummary="on"
fork="true" failureProperty="test.failed">
<formatter type="brief" usefile="false"/>
<classpath>
@@ -637,7 +641,7 @@
<!-- Need Ant1.5+ to run Ant1Compat tests, because of
classpath
problems in Ant1.4 JUnit Task (prepends ant.jar to
classpath) -->
<exclude name="**/Ant1CompatTestCase.class"
unless="ant1.5"/>
-
+
<!-- This test fails, as it has no test methods -->
<exclude name="**/SimpleConvertersTestCase.class"
unless="single.test"/>
</fileset>
@@ -781,7 +785,7 @@
<exclude name="jdepend.jar"/>
</fileset>
</copy>
-
+
<copy todir="${dist.lib}" file="../../lib/optional/junit.jar" />
<copy todir="${dist.bin}">
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtensionDisplayTask.java
Index: ExtensionDisplayTask.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 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:[EMAIL PROTECTED]">Peter Donald</a>
* @ant.task name="extension-display"
*/
public class ExtensionDisplayTask
extends AbstractTask
{
private final static Resources REZ =
ResourceManager.getPackageResources( ExtensionDisplayTask.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 LibraryDisplay displayer = new LibraryDisplay();
// 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.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/LibraryDisplay.java
Index: LibraryDisplay.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 java.io.File;
import java.io.IOException;
import java.util.jar.Manifest;
import java.util.jar.JarFile;
import java.text.ParseException;
import java.lang.StringBuffer;
import org.apache.myrmidon.api.TaskException;
import org.apache.avalon.excalibur.extension.Extension;
import org.apache.avalon.excalibur.extension.Specification;
/**
* Utility class to output the information in a jar relating
* to "Optional Packages" (formely known as "Extensions")
* and Package Specifications.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/04/02 12:06:37 $
*/
class LibraryDisplay
{
/**
* Display the extensions and specifications contained
* within specified file.
*
* @param file the file
* @throws TaskException if fail to read file
*/
public void displayLibrary( final File file )
throws TaskException
{
final Manifest manifest = getManifest( file );
final Extension[] available = Extension.getAvailable( manifest );
final Extension[] required = Extension.getRequired( manifest );
final Specification[] specifications = getSpecifications( manifest );
if( 0 == available.length &&
0 == required.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 != 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 org.apache.myrmidon.api.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.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties
Index: Resources.properties
===================================================================
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.
1.3 +10 -0 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- sample.ant 1 Apr 2002 06:29:37 -0000 1.2
+++ sample.ant 2 Apr 2002 12:06:37 -0000 1.3
@@ -323,4 +323,14 @@
</changelog>
</target>
+ <target name="extension-test">
+ <extension-display file="../../src/ant1compat/jar/ant.jar"/>
+ <extension-display>
+ <fileset dir="../../">
+ <include name="src/ant1compat/jar/*.jar"/>
+ <include name="lib/*.jar"/>
+ </fileset>
+ </extension-display>
+ </target>
+
</project>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>