git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272164 13f79535-47bb-0310-9956-ffa450edef68master
@@ -237,10 +237,10 @@ Legal: | |||||
<javac | <javac | ||||
destdir="${build.classes}" | destdir="${build.classes}" | ||||
debug="${debug}" | debug="${debug}" | ||||
deprecation="${deprecation}" | |||||
deprecation="${deprecation}" | |||||
includeAntRuntime="false" | includeAntRuntime="false" | ||||
includeJavaRuntime="false"> | includeJavaRuntime="false"> | ||||
<classpath refid="project.class.path"/> | <classpath refid="project.class.path"/> | ||||
<src location="src/todo"/> | <src location="src/todo"/> | ||||
<src path="${java.dir}" /> | <src path="${java.dir}" /> | ||||
@@ -494,6 +494,10 @@ Legal: | |||||
<property name="antlib.name" value="core"/> | <property name="antlib.name" value="core"/> | ||||
</ant> | </ant> | ||||
<ant antfile="antlib.xml"> | |||||
<property name="antlib.name" value="extensions"/> | |||||
</ant> | |||||
<ant antfile="antlib.xml"> | <ant antfile="antlib.xml"> | ||||
<property name="antlib.name" value="file"/> | <property name="antlib.name" value="file"/> | ||||
</ant> | </ant> | ||||
@@ -546,12 +550,12 @@ Legal: | |||||
destdir="${test.classes}" | destdir="${test.classes}" | ||||
debug="${debug}" | debug="${debug}" | ||||
deprecation="${deprecation}"> | deprecation="${deprecation}"> | ||||
<classpath> | <classpath> | ||||
<pathelement location="${build.classes}"/> | <pathelement location="${build.classes}"/> | ||||
<path refid="project.class.path"/> | <path refid="project.class.path"/> | ||||
</classpath> | </classpath> | ||||
<exclude name="**/SmbFileSystemTestCase.java" unless="jcifs.present"/> | <exclude name="**/SmbFileSystemTestCase.java" unless="jcifs.present"/> | ||||
<exclude name="**/FtpFileSystemTestCase.java" unless="netcomp.present"/> | <exclude name="**/FtpFileSystemTestCase.java" unless="netcomp.present"/> | ||||
</javac> | </javac> | ||||
@@ -611,7 +615,7 @@ Legal: | |||||
tofile="${test.classes}/META-INF/ant-descriptor.xml"/> | tofile="${test.classes}/META-INF/ant-descriptor.xml"/> | ||||
<!-- Run all the tests --> | <!-- Run all the tests --> | ||||
<junit printsummary="on" | |||||
<junit printsummary="on" | |||||
fork="true" failureProperty="test.failed"> | fork="true" failureProperty="test.failed"> | ||||
<formatter type="brief" usefile="false"/> | <formatter type="brief" usefile="false"/> | ||||
<classpath> | <classpath> | ||||
@@ -637,7 +641,7 @@ Legal: | |||||
<!-- Need Ant1.5+ to run Ant1Compat tests, because of classpath | <!-- Need Ant1.5+ to run Ant1Compat tests, because of classpath | ||||
problems in Ant1.4 JUnit Task (prepends ant.jar to classpath) --> | problems in Ant1.4 JUnit Task (prepends ant.jar to classpath) --> | ||||
<exclude name="**/Ant1CompatTestCase.class" unless="ant1.5"/> | <exclude name="**/Ant1CompatTestCase.class" unless="ant1.5"/> | ||||
<!-- This test fails, as it has no test methods --> | <!-- This test fails, as it has no test methods --> | ||||
<exclude name="**/SimpleConvertersTestCase.class" unless="single.test"/> | <exclude name="**/SimpleConvertersTestCase.class" unless="single.test"/> | ||||
</fileset> | </fileset> | ||||
@@ -781,7 +785,7 @@ Legal: | |||||
<exclude name="jdepend.jar"/> | <exclude name="jdepend.jar"/> | ||||
</fileset> | </fileset> | ||||
</copy> | </copy> | ||||
<copy todir="${dist.lib}" file="../../lib/optional/junit.jar" /> | <copy todir="${dist.lib}" file="../../lib/optional/junit.jar" /> | ||||
<copy todir="${dist.bin}"> | <copy todir="${dist.bin}"> | ||||
@@ -0,0 +1,125 @@ | |||||
/* | |||||
* 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="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 ); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,164 @@ | |||||
/* | |||||
* 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:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
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 ); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,3 @@ | |||||
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. |
@@ -323,4 +323,14 @@ Legal: | |||||
</changelog> | </changelog> | ||||
</target> | </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> | </project> |