Submitted by: Kev Jackson git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277732 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2002-2004 The Apache Software Foundation | |||
* Copyright 2002-2005 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -23,6 +23,8 @@ import java.util.StringTokenizer; | |||
import java.util.jar.Attributes; | |||
import java.util.jar.Manifest; | |||
import org.apache.tools.ant.util.StringUtils; | |||
/** | |||
* <p>Utility class that represents either an available "Optional Package" | |||
* (formerly known as "Standard Extension") as described in the manifest | |||
@@ -489,54 +491,53 @@ public final class Extension { | |||
* @return string representation of object. | |||
*/ | |||
public String toString() { | |||
final String lineSeparator = System.getProperty("line.separator"); | |||
final String brace = ": "; | |||
final StringBuffer sb = new StringBuffer(EXTENSION_NAME.toString()); | |||
sb.append(brace); | |||
sb.append(extensionName); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
if (null != specificationVersion) { | |||
sb.append(SPECIFICATION_VERSION); | |||
sb.append(brace); | |||
sb.append(specificationVersion); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != specificationVendor) { | |||
sb.append(SPECIFICATION_VENDOR); | |||
sb.append(brace); | |||
sb.append(specificationVendor); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != implementationVersion) { | |||
sb.append(IMPLEMENTATION_VERSION); | |||
sb.append(brace); | |||
sb.append(implementationVersion); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != implementationVendorID) { | |||
sb.append(IMPLEMENTATION_VENDOR_ID); | |||
sb.append(brace); | |||
sb.append(implementationVendorID); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != implementationVendor) { | |||
sb.append(IMPLEMENTATION_VENDOR); | |||
sb.append(brace); | |||
sb.append(implementationVendor); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != implementationURL) { | |||
sb.append(IMPLEMENTATION_URL); | |||
sb.append(brace); | |||
sb.append(implementationURL); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
return sb.toString(); | |||
@@ -683,10 +684,6 @@ public final class Extension { | |||
* @return the trimmed string or null | |||
*/ | |||
private static String getTrimmedString(final String value) { | |||
if (null == value) { | |||
return null; | |||
} else { | |||
return value.trim(); | |||
} | |||
return null == value ? null : value.trim(); | |||
} | |||
} | |||
} |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2002,2004 The Apache Software Foundation | |||
* Copyright 2002,2004-2005 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -73,14 +73,14 @@ public class ExtensionSet | |||
/** | |||
* Extract a set of Extension objects from the ExtensionSet. | |||
* | |||
* @param project the project instance. | |||
* @param proj the project instance. | |||
* @return an array containing the Extensions from this set | |||
* @throws BuildException if an error occurs | |||
*/ | |||
public Extension[] toExtensions(final Project project) | |||
public Extension[] toExtensions(final Project proj) | |||
throws BuildException { | |||
final ArrayList extensionsList = ExtensionUtil.toExtensions(extensions); | |||
ExtensionUtil.extractExtensions(project, extensionsList, extensionsFilesets); | |||
ExtensionUtil.extractExtensions(proj, extensionsList, extensionsFilesets); | |||
return (Extension[]) extensionsList.toArray(new Extension[extensionsList.size()]); | |||
} | |||
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2002-2004 The Apache Software Foundation | |||
* Copyright 2002-2005 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -20,8 +20,10 @@ import java.io.File; | |||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.jar.JarFile; | |||
import java.util.jar.Manifest; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.DirectoryScanner; | |||
import org.apache.tools.ant.Project; | |||
@@ -37,6 +39,7 @@ public class ExtensionUtil { | |||
* Class is not meant to be instantiated. | |||
*/ | |||
private ExtensionUtil() { | |||
//all methods static | |||
} | |||
/** | |||
@@ -45,7 +48,7 @@ public class ExtensionUtil { | |||
* @param adapters the list of ExtensionAdapterss to add to convert | |||
* @throws BuildException if an error occurs | |||
*/ | |||
static ArrayList toExtensions(final ArrayList adapters) | |||
static ArrayList toExtensions(final List adapters) | |||
throws BuildException { | |||
final ArrayList results = new ArrayList(); | |||
@@ -63,35 +66,35 @@ public class ExtensionUtil { | |||
/** | |||
* Generate a list of extensions from a specified fileset. | |||
* | |||
* @param librarys the list to add extensions to | |||
* @param libraries the list to add extensions to | |||
* @param fileset the filesets containing librarys | |||
* @throws BuildException if an error occurs | |||
*/ | |||
static void extractExtensions(final Project project, | |||
final ArrayList librarys, | |||
final ArrayList fileset) | |||
final List libraries, | |||
final List fileset) | |||
throws BuildException { | |||
if (!fileset.isEmpty()) { | |||
final Extension[] extensions = getExtensions(project, | |||
fileset); | |||
for (int i = 0; i < extensions.length; i++) { | |||
librarys.add(extensions[ i ]); | |||
libraries.add(extensions[ i ]); | |||
} | |||
} | |||
} | |||
/** | |||
* Retrieve extensions from the specified librarys. | |||
* Retrieve extensions from the specified libraries. | |||
* | |||
* @param librarys the filesets for librarys | |||
* @return the extensions contained in librarys | |||
* @throws BuildException if failing to scan librarys | |||
* @param libraries the filesets for libraries | |||
* @return the extensions contained in libraries | |||
* @throws BuildException if failing to scan libraries | |||
*/ | |||
private static Extension[] getExtensions(final Project project, | |||
final ArrayList librarys) | |||
final List libraries) | |||
throws BuildException { | |||
final ArrayList extensions = new ArrayList(); | |||
final Iterator iterator = librarys.iterator(); | |||
final Iterator iterator = libraries.iterator(); | |||
while (iterator.hasNext()) { | |||
final FileSet fileSet = (FileSet) iterator.next(); | |||
@@ -123,7 +126,7 @@ public class ExtensionUtil { | |||
* @throws BuildException if there is an error | |||
*/ | |||
private static void loadExtensions(final File file, | |||
final ArrayList extensionList, | |||
final List extensionList, | |||
final boolean includeImpl, | |||
final boolean includeURL) | |||
throws BuildException { | |||
@@ -151,7 +154,7 @@ public class ExtensionUtil { | |||
* @param includeImpl false to exclude implementation details | |||
* @param includeURL false to exclude implementation URL | |||
*/ | |||
private static void addExtension(final ArrayList extensionList, | |||
private static void addExtension(final List extensionList, | |||
final Extension originalExtension, | |||
final boolean includeImpl, | |||
final boolean includeURL) { | |||
@@ -189,12 +192,12 @@ public class ExtensionUtil { | |||
} | |||
/** | |||
* retrieve manifest for specified file. | |||
* Retrieve manifest for specified file. | |||
* | |||
* @param file the file | |||
* @return the manifest | |||
* @throws BuildException if errror occurs (file not exist, | |||
* file not a jar, manifest not exist in file) | |||
* @throws BuildException if errror occurs (file doesn't exist, | |||
* file not a jar, manifest doesn't exist in file) | |||
*/ | |||
static Manifest getManifest(final File file) | |||
throws BuildException { | |||
@@ -209,4 +212,4 @@ public class ExtensionUtil { | |||
throw new BuildException(ioe.getMessage(), ioe); | |||
} | |||
} | |||
} | |||
} |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2002-2004 The Apache Software Foundation | |||
* Copyright 2002-2005 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -104,9 +104,8 @@ public final class JarLibManifestTask extends Task { | |||
final String message = | |||
"Can not have multiple extensions defined in one library."; | |||
throw new BuildException(message); | |||
} else { | |||
extension = extensionAdapter.toExtension(); | |||
} | |||
extension = extensionAdapter.toExtension(); | |||
} | |||
/** | |||
@@ -309,4 +308,4 @@ public final class JarLibManifestTask extends Task { | |||
return results; | |||
} | |||
} | |||
} |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2002-2004 The Apache Software Foundation | |||
* Copyright 2002-2005 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -98,10 +98,10 @@ public class JarLibResolveTask extends Task { | |||
* Adds location resolver to look for a library in a location | |||
* relative to project directory. | |||
* | |||
* @param location the resolver location to search. | |||
* @param loc the resolver location to search. | |||
*/ | |||
public void addConfiguredLocation(final LocationResolver location) { | |||
resolvers.add(location); | |||
public void addConfiguredLocation(final LocationResolver loc) { | |||
resolvers.add(loc); | |||
} | |||
/** | |||
@@ -155,10 +155,9 @@ public class JarLibResolveTask extends Task { | |||
final String message = "Property Already set to: " + candidate; | |||
if (failOnError) { | |||
throw new BuildException(message); | |||
} else { | |||
getProject().log(message, Project.MSG_ERR); | |||
return; | |||
} | |||
} | |||
getProject().log(message, Project.MSG_ERR); | |||
return; | |||
} | |||
final int size = resolvers.size(); | |||
@@ -201,9 +200,8 @@ public class JarLibResolveTask extends Task { | |||
"Unable to resolve extension to a file"; | |||
if (failOnError) { | |||
throw new BuildException(message); | |||
} else { | |||
getProject().log(message, Project.MSG_ERR); | |||
} | |||
getProject().log(message, Project.MSG_ERR); | |||
} | |||
/** | |||
@@ -283,4 +281,4 @@ public class JarLibResolveTask extends Task { | |||
throw new BuildException(message); | |||
} | |||
} | |||
} | |||
} |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2002,2004 The Apache Software Foundation | |||
* Copyright 2002,2004-2005 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -24,6 +24,8 @@ import java.util.Map; | |||
import java.util.jar.Attributes; | |||
import java.util.jar.Manifest; | |||
import org.apache.tools.ant.util.StringUtils; | |||
/** | |||
* <p>Utility class that represents either an available "Optional Package" | |||
* (formerly known as "Standard Extension") as described in the manifest | |||
@@ -37,6 +39,9 @@ import java.util.jar.Manifest; | |||
* @version $Revision$ $Date$ | |||
*/ | |||
public final class Specification { | |||
private static final String MISSING = "Missing "; | |||
/** | |||
* Manifest Attribute Name object for SPECIFICATION_TITLE. | |||
*/ | |||
@@ -320,11 +325,10 @@ public final class Specification { | |||
public String[] getSections() { | |||
if (null == sections) { | |||
return null; | |||
} else { | |||
final String[] newSections = new String[ sections.length ]; | |||
System.arraycopy(sections, 0, newSections, 0, sections.length); | |||
return newSections; | |||
} | |||
} | |||
final String[] newSections = new String[ sections.length ]; | |||
System.arraycopy(sections, 0, newSections, 0, sections.length); | |||
return newSections; | |||
} | |||
/** | |||
@@ -394,48 +398,47 @@ public final class Specification { | |||
* @return string representation of object. | |||
*/ | |||
public String toString() { | |||
final String lineSeparator = System.getProperty("line.separator"); | |||
final String brace = ": "; | |||
final StringBuffer sb | |||
= new StringBuffer(SPECIFICATION_TITLE.toString()); | |||
sb.append(brace); | |||
sb.append(specificationTitle); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
if (null != specificationVersion) { | |||
sb.append(SPECIFICATION_VERSION); | |||
sb.append(brace); | |||
sb.append(specificationVersion); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != specificationVendor) { | |||
sb.append(SPECIFICATION_VENDOR); | |||
sb.append(brace); | |||
sb.append(specificationVendor); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != implementationTitle) { | |||
sb.append(IMPLEMENTATION_TITLE); | |||
sb.append(brace); | |||
sb.append(implementationTitle); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != implementationVersion) { | |||
sb.append(IMPLEMENTATION_VERSION); | |||
sb.append(brace); | |||
sb.append(implementationVersion); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
if (null != implementationVendor) { | |||
sb.append(IMPLEMENTATION_VENDOR); | |||
sb.append(brace); | |||
sb.append(implementationVendor); | |||
sb.append(lineSeparator); | |||
sb.append(StringUtils.LINE_SEP); | |||
} | |||
return sb.toString(); | |||
@@ -521,20 +524,19 @@ public final class Specification { | |||
final ArrayList sectionsToAdd) { | |||
if (0 == sectionsToAdd.size()) { | |||
return specification; | |||
} else { | |||
sectionsToAdd.addAll(Arrays.asList(specification.getSections())); | |||
final String[] sections = | |||
(String[]) sectionsToAdd.toArray(new String[sectionsToAdd.size()]); | |||
return new Specification(specification.getSpecificationTitle(), | |||
specification.getSpecificationVersion().toString(), | |||
specification.getSpecificationVendor(), | |||
specification.getImplementationTitle(), | |||
specification.getImplementationVersion(), | |||
specification.getImplementationVendor(), | |||
sections); | |||
} | |||
sectionsToAdd.addAll(Arrays.asList(specification.getSections())); | |||
final String[] sections = | |||
(String[]) sectionsToAdd.toArray(new String[sectionsToAdd.size()]); | |||
return new Specification(specification.getSpecificationTitle(), | |||
specification.getSpecificationVersion().toString(), | |||
specification.getSpecificationVendor(), | |||
specification.getImplementationTitle(), | |||
specification.getImplementationVersion(), | |||
specification.getImplementationVendor(), | |||
sections); | |||
} | |||
/** | |||
@@ -544,11 +546,7 @@ public final class Specification { | |||
* @return the trimmed string or null | |||
*/ | |||
private static String getTrimmedString(final String value) { | |||
if (null == value) { | |||
return null; | |||
} else { | |||
return value.trim(); | |||
} | |||
return value == null ? null : value.trim(); | |||
} | |||
/** | |||
@@ -572,35 +570,35 @@ public final class Specification { | |||
final String specVendor | |||
= getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR)); | |||
if (null == specVendor) { | |||
throw new ParseException("Missing " + SPECIFICATION_VENDOR, 0); | |||
throw new ParseException(MISSING + SPECIFICATION_VENDOR, 0); | |||
} | |||
final String specVersion | |||
= getTrimmedString(attributes.getValue(SPECIFICATION_VERSION)); | |||
if (null == specVersion) { | |||
throw new ParseException("Missing " + SPECIFICATION_VERSION, 0); | |||
throw new ParseException(MISSING + SPECIFICATION_VERSION, 0); | |||
} | |||
final String impTitle | |||
= getTrimmedString(attributes.getValue(IMPLEMENTATION_TITLE)); | |||
if (null == impTitle) { | |||
throw new ParseException("Missing " + IMPLEMENTATION_TITLE, 0); | |||
throw new ParseException(MISSING + IMPLEMENTATION_TITLE, 0); | |||
} | |||
final String impVersion | |||
= getTrimmedString(attributes.getValue(IMPLEMENTATION_VERSION)); | |||
if (null == impVersion) { | |||
throw new ParseException("Missing " + IMPLEMENTATION_VERSION, 0); | |||
throw new ParseException(MISSING + IMPLEMENTATION_VERSION, 0); | |||
} | |||
final String impVendor | |||
= getTrimmedString(attributes.getValue(IMPLEMENTATION_VENDOR)); | |||
if (null == impVendor) { | |||
throw new ParseException("Missing " + IMPLEMENTATION_VENDOR, 0); | |||
throw new ParseException(MISSING + IMPLEMENTATION_VENDOR, 0); | |||
} | |||
return new Specification(name, specVersion, specVendor, | |||
impTitle, impVersion, impVendor, | |||
new String[]{section}); | |||
} | |||
} | |||
} |