Browse Source

fmt/refac

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@556984 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
4a827ff185
2 changed files with 34 additions and 72 deletions
  1. +15
    -34
      src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java
  2. +19
    -38
      src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibResolveTask.java

+ 15
- 34
src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java View File

@@ -101,11 +101,9 @@ public final class JarLibManifestTask extends Task {
* in the library. * in the library.
*/ */
public void addConfiguredExtension(final ExtensionAdapter extensionAdapter) public void addConfiguredExtension(final ExtensionAdapter extensionAdapter)
throws BuildException {
throws BuildException {
if (null != extension) { if (null != extension) {
final String message =
"Can not have multiple extensions defined in one library.";
throw new BuildException(message);
throw new BuildException("Can not have multiple extensions defined in one library.");
} }
extension = extensionAdapter.toExtension(); extension = extensionAdapter.toExtension();
} }
@@ -149,8 +147,8 @@ public final class JarLibManifestTask extends Task {
final Attributes attributes = manifest.getMainAttributes(); final Attributes attributes = manifest.getMainAttributes();


attributes.put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION); attributes.put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION);
final String createdBy = "Apache Ant " + getProject().getProperty(MagicNames.ANT_VERSION);
attributes.putValue(CREATED_BY, createdBy);
attributes.putValue(CREATED_BY, "Apache Ant "
+ getProject().getProperty(MagicNames.ANT_VERSION));


appendExtraAttributes(attributes); appendExtraAttributes(attributes);


@@ -160,24 +158,17 @@ public final class JarLibManifestTask extends Task {


//Add all the dependency data to manifest for dependencies //Add all the dependency data to manifest for dependencies
final ArrayList depends = toExtensions(dependencies); final ArrayList depends = toExtensions(dependencies);
appendExtensionList(attributes,
Extension.EXTENSION_LIST,
"lib",
depends.size());
appendExtensionList(attributes, Extension.EXTENSION_LIST, "lib", depends.size());
appendLibraryList(attributes, "lib", depends); appendLibraryList(attributes, "lib", depends);


//Add all the dependency data to manifest for "optional"
// Add all the dependency data to manifest for "optional"
//dependencies //dependencies
final ArrayList option = toExtensions(optionals); final ArrayList option = toExtensions(optionals);
appendExtensionList(attributes,
Extension.OPTIONAL_EXTENSION_LIST,
"opt",
option.size());
appendExtensionList(attributes, Extension.OPTIONAL_EXTENSION_LIST, "opt", option.size());
appendLibraryList(attributes, "opt", option); appendLibraryList(attributes, "opt", option);


try { try {
final String message = "Generating manifest " + destFile.getAbsoluteFile();
log(message, Project.MSG_INFO);
log("Generating manifest " + destFile.getAbsoluteFile(), Project.MSG_INFO);
writeManifest(manifest); writeManifest(manifest);
} catch (final IOException ioe) { } catch (final IOException ioe) {
throw new BuildException(ioe.getMessage(), ioe); throw new BuildException(ioe.getMessage(), ioe);
@@ -191,12 +182,10 @@ public final class JarLibManifestTask extends Task {
*/ */
private void validate() throws BuildException { private void validate() throws BuildException {
if (null == destFile) { if (null == destFile) {
final String message = "Destfile attribute not specified.";
throw new BuildException(message);
throw new BuildException("Destfile attribute not specified.");
} }
if (destFile.exists() && !destFile.isFile()) { if (destFile.exists() && !destFile.isFile()) {
final String message = destFile + " is not a file.";
throw new BuildException(message);
throw new BuildException(destFile + " is not a file.");
} }
} }


@@ -222,8 +211,7 @@ public final class JarLibManifestTask extends Task {
* @param manifest the manifest * @param manifest the manifest
* @throws IOException if error writing file * @throws IOException if error writing file
*/ */
private void writeManifest(final Manifest manifest)
throws IOException {
private void writeManifest(final Manifest manifest) throws IOException {
FileOutputStream output = null; FileOutputStream output = null;
try { try {
output = new FileOutputStream(destFile); output = new FileOutputStream(destFile);
@@ -251,10 +239,8 @@ public final class JarLibManifestTask extends Task {
* @param extensions the list of extensions * @param extensions the list of extensions
* @throws BuildException if an error occurs * @throws BuildException if an error occurs
*/ */
private void appendLibraryList(final Attributes attributes,
final String listPrefix,
final ArrayList extensions)
throws BuildException {
private void appendLibraryList(final Attributes attributes, final String listPrefix,
final ArrayList extensions) throws BuildException {
final int size = extensions.size(); final int size = extensions.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final Extension ext = (Extension) extensions.get(i); final Extension ext = (Extension) extensions.get(i);
@@ -275,16 +261,13 @@ public final class JarLibManifestTask extends Task {
* @param extensionKey the key to use * @param extensionKey the key to use
*/ */
private void appendExtensionList(final Attributes attributes, private void appendExtensionList(final Attributes attributes,
final Attributes.Name extensionKey,
final String listPrefix,
final int size) {
final Attributes.Name extensionKey, final String listPrefix, final int size) {
final StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
sb.append(listPrefix); sb.append(listPrefix);
sb.append(i); sb.append(i);
sb.append(' '); sb.append(' ');
} }

//add in something like //add in something like
//"Extension-List: javahelp java3d" //"Extension-List: javahelp java3d"
attributes.put(extensionKey, sb.toString()); attributes.put(extensionKey, sb.toString());
@@ -296,8 +279,7 @@ public final class JarLibManifestTask extends Task {
* @param extensionSets the list of ExtensionSets to add to list * @param extensionSets the list of ExtensionSets to add to list
* @throws BuildException if an error occurs * @throws BuildException if an error occurs
*/ */
private ArrayList toExtensions(final ArrayList extensionSets)
throws BuildException {
private ArrayList toExtensions(final ArrayList extensionSets) throws BuildException {
final ArrayList results = new ArrayList(); final ArrayList results = new ArrayList();


final int size = extensionSets.size(); final int size = extensionSets.size();
@@ -308,7 +290,6 @@ public final class JarLibManifestTask extends Task {
results.add(extensions[ j ]); results.add(extensions[ j ]);
} }
} }

return results; return results;
} }
} }

+ 19
- 38
src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibResolveTask.java View File

@@ -146,11 +146,9 @@ public class JarLibResolveTask extends Task {
public void execute() throws BuildException { public void execute() throws BuildException {
validate(); validate();


getProject().log("Resolving extension: " + requiredExtension,
Project.MSG_VERBOSE);
getProject().log("Resolving extension: " + requiredExtension, Project.MSG_VERBOSE);


String candidate =
getProject().getProperty(propertyName);
String candidate = getProject().getProperty(propertyName);


if (null != candidate) { if (null != candidate) {
final String message = "Property Already set to: " + candidate; final String message = "Property Already set to: " + candidate;
@@ -167,27 +165,24 @@ public class JarLibResolveTask extends Task {
(ExtensionResolver) resolvers.get(i); (ExtensionResolver) resolvers.get(i);


getProject().log("Searching for extension using Resolver:" + resolver, getProject().log("Searching for extension using Resolver:" + resolver,
Project.MSG_VERBOSE);
Project.MSG_VERBOSE);


try { try {
final File file =
resolver.resolve(requiredExtension, getProject());
final File file = resolver.resolve(requiredExtension, getProject());
try { try {
checkExtension(file); checkExtension(file);
return; return;
} catch (final BuildException be) { } catch (final BuildException be) {
final String message = "File " + file + " returned by " final String message = "File " + file + " returned by "
+ "resolver failed to satisfy extension due to: "
+ be.getMessage();
+ "resolver failed to satisfy extension due to: " + be.getMessage();
getProject().log(message, Project.MSG_WARN); getProject().log(message, Project.MSG_WARN);
} }
} catch (final BuildException be) { } catch (final BuildException be) {
final String message = "Failed to resolve extension to file "
+ "using resolver " + resolver + " due to: " + be;
final String message = "Failed to resolve extension to file " + "using resolver "
+ resolver + " due to: " + be;
getProject().log(message, Project.MSG_WARN); getProject().log(message, Project.MSG_WARN);
} }
} }

missingExtension(); missingExtension();
} }


@@ -197,8 +192,7 @@ public class JarLibResolveTask extends Task {
* a warning. * a warning.
*/ */
private void missingExtension() { private void missingExtension() {
final String message =
"Unable to resolve extension to a file";
final String message = "Unable to resolve extension to a file";
if (failOnError) { if (failOnError) {
throw new BuildException(message); throw new BuildException(message);
} }
@@ -215,28 +209,20 @@ public class JarLibResolveTask extends Task {
*/ */
private void checkExtension(final File file) { private void checkExtension(final File file) {
if (!file.exists()) { if (!file.exists()) {
final String message =
"File " + file + " does not exist";
throw new BuildException(message);
throw new BuildException("File " + file + " does not exist");
} }
if (!file.isFile()) { if (!file.isFile()) {
final String message =
"File " + file + " is not a file";
throw new BuildException(message);
throw new BuildException("File " + file + " is not a file");
} }

if (!checkExtension) { if (!checkExtension) {
final String message = "Setting property to " + file
+ " without verifying library satisfies extension";
getProject().log(message, Project.MSG_VERBOSE);
getProject().log("Setting property to " + file
+ " without verifying library satisfies extension", Project.MSG_VERBOSE);
setLibraryProperty(file); setLibraryProperty(file);
} else { } else {
getProject().log("Checking file " + file
+ " to see if it satisfies extension", Project.MSG_VERBOSE);
final Manifest manifest =
ExtensionUtil.getManifest(file);
final Extension[] extensions =
Extension.getAvailable(manifest);
getProject().log("Checking file " + file + " to see if it satisfies extension",
Project.MSG_VERBOSE);
final Manifest manifest = ExtensionUtil.getManifest(file);
final Extension[] extensions = Extension.getAvailable(manifest);
for (int i = 0; i < extensions.length; i++) { for (int i = 0; i < extensions.length; i++) {
final Extension extension = extensions[ i ]; final Extension extension = extensions[ i ];
if (extension.isCompatibleWith(requiredExtension)) { if (extension.isCompatibleWith(requiredExtension)) {
@@ -244,12 +230,8 @@ public class JarLibResolveTask extends Task {
return; return;
} }
} }

getProject().log("File " + file + " skipped as it "
+ "does not satisfy extension", Project.MSG_VERBOSE);

final String message =
"File " + file + " does not satisfy extension";
final String message = "File " + file + " skipped as it " + "does not satisfy extension";
getProject().log(message, Project.MSG_VERBOSE);
throw new BuildException(message); throw new BuildException(message);
} }
} }
@@ -262,8 +244,7 @@ public class JarLibResolveTask extends Task {
* @param file the library * @param file the library
*/ */
private void setLibraryProperty(final File file) { private void setLibraryProperty(final File file) {
getProject().setNewProperty(propertyName,
file.getAbsolutePath());
getProject().setNewProperty(propertyName, file.getAbsolutePath());
} }


/** /**


Loading…
Cancel
Save