Browse Source

More style

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274849 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
f3399d5643
2 changed files with 60 additions and 42 deletions
  1. +49
    -32
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  2. +11
    -10
      src/main/org/apache/tools/ant/taskdefs/Tar.java

+ 49
- 32
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -331,6 +331,7 @@ public class IntrospectionHelper implements BuildListener {


}); });
} catch (NoSuchMethodException nse) { } catch (NoSuchMethodException nse) {
// ignore
} }
} else if (name.startsWith("add") } else if (name.startsWith("add")
&& java.lang.Void.TYPE.equals(returnType) && java.lang.Void.TYPE.equals(returnType)
@@ -357,6 +358,7 @@ public class IntrospectionHelper implements BuildListener {
}); });
nestedStorers.remove(name); nestedStorers.remove(name);
} catch (NoSuchMethodException nse) { } catch (NoSuchMethodException nse) {
// ignore
} }
} }
} }
@@ -409,6 +411,7 @@ public class IntrospectionHelper implements BuildListener {
* The method will make sure the helper will be cleaned up at the end of * The method will make sure the helper will be cleaned up at the end of
* the project, and only one instance will be created for each class. * the project, and only one instance will be created for each class.
* *
* @param p the project instance
* @param c The class for which a helper is required. * @param c The class for which a helper is required.
* Must not be <code>null</code>. * Must not be <code>null</code>.
* *
@@ -454,9 +457,9 @@ public class IntrospectionHelper implements BuildListener {
dc.setDynamicAttribute(attributeName, value); dc.setDynamicAttribute(attributeName, value);
return; return;
} else { } else {
String msg = getElementName(p, element) +
" doesn't support the \"" + attributeName +
"\" attribute.";
String msg = getElementName(p, element)
+ " doesn't support the \"" + attributeName
+ "\" attribute.";
throw new BuildException(msg); throw new BuildException(msg);
} }
} }
@@ -519,10 +522,17 @@ public class IntrospectionHelper implements BuildListener {
} }
} }


/**
* Utility method to throw a NotSupported exception
*
* @param project the Project instance.
* @param parent the object which doesn't support a requested element
* @param elementName the name of the Element which is trying to be created.
*/
public void throwNotSupported(Project project, Object parent, public void throwNotSupported(Project project, Object parent,
String elementName) { String elementName) {
String msg = project.getElementName(parent) +
" doesn't support the nested \"" + elementName + "\" element.";
String msg = project.getElementName(parent)
+ " doesn't support the nested \"" + elementName + "\" element.";
throw new BuildException(msg); throw new BuildException(msg);
} }


@@ -564,8 +574,8 @@ public class IntrospectionHelper implements BuildListener {
DynamicConfigurator dc = (DynamicConfigurator) parent; DynamicConfigurator dc = (DynamicConfigurator) parent;
Object nestedElement = dc.createDynamicElement(elementName); Object nestedElement = dc.createDynamicElement(elementName);
if (nestedElement != null) { if (nestedElement != null) {
if ( project != null ) {
project.setProjectReference( nestedElement );
if (project != null) {
project.setProjectReference(nestedElement);
} }
return nestedElement; return nestedElement;
} }
@@ -575,8 +585,8 @@ public class IntrospectionHelper implements BuildListener {
} }
try { try {
Object nestedElement = nc.create(parent); Object nestedElement = nc.create(parent);
if ( project != null ) {
project.setProjectReference( nestedElement );
if (project != null) {
project.setProjectReference(nestedElement);
} }
return nestedElement; return nestedElement;
} catch (IllegalAccessException ie) { } catch (IllegalAccessException ie) {
@@ -603,9 +613,9 @@ public class IntrospectionHelper implements BuildListener {
* @return true if the given nested element is supported * @return true if the given nested element is supported
*/ */
public boolean supportsNestedElement(String elementName) { public boolean supportsNestedElement(String elementName) {
return nestedCreators.containsKey(elementName) ||
DynamicConfigurator.class.isAssignableFrom(bean) ||
addTypeMethods.size() != 0;
return nestedCreators.containsKey(elementName)
|| DynamicConfigurator.class.isAssignableFrom(bean)
|| addTypeMethods.size() != 0;
} }


/** /**
@@ -670,8 +680,9 @@ public class IntrospectionHelper implements BuildListener {
throws BuildException { throws BuildException {
Class nt = (Class) nestedTypes.get(elementName); Class nt = (Class) nestedTypes.get(elementName);
if (nt == null) { if (nt == null) {
String msg = "Class " + bean.getName() +
" doesn't support the nested \"" + elementName + "\" element.";
String msg = "Class " + bean.getName()
+ " doesn't support the nested \"" + elementName
+ "\" element.";
throw new BuildException(msg); throw new BuildException(msg);
} }
return nt; return nt;
@@ -839,13 +850,13 @@ public class IntrospectionHelper implements BuildListener {
}; };


// EnumeratedAttributes have their own helper class // EnumeratedAttributes have their own helper class
} else if (org.apache.tools.ant.types.EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
} else if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
return new AttributeSetter() { return new AttributeSetter() {
public void set(Project p, Object parent, String value) public void set(Project p, Object parent, String value)
throws InvocationTargetException, IllegalAccessException, BuildException { throws InvocationTargetException, IllegalAccessException, BuildException {
try { try {
org.apache.tools.ant.types.EnumeratedAttribute ea =
(org.apache.tools.ant.types.EnumeratedAttribute) reflectedArg.newInstance();
EnumeratedAttribute ea =
(EnumeratedAttribute) reflectedArg.newInstance();
ea.setValue(value); ea.setValue(value);
m.invoke(parent, new EnumeratedAttribute[] {ea}); m.invoke(parent, new EnumeratedAttribute[] {ea});
} catch (InstantiationException ie) { } catch (InstantiationException ie) {
@@ -869,8 +880,8 @@ public class IntrospectionHelper implements BuildListener {
throws InvocationTargetException, IllegalAccessException, BuildException { throws InvocationTargetException, IllegalAccessException, BuildException {
try { try {
Object attribute = c.newInstance(new String[] {value}); Object attribute = c.newInstance(new String[] {value});
if ( p != null ) {
p.setProjectReference( attribute );
if (p != null) {
p.setProjectReference(attribute);
} }
m.invoke(parent, new Object[] {attribute}); m.invoke(parent, new Object[] {attribute});
} catch (InstantiationException ie) { } catch (InstantiationException ie) {
@@ -880,6 +891,7 @@ public class IntrospectionHelper implements BuildListener {
}; };


} catch (NoSuchMethodException nme) { } catch (NoSuchMethodException nme) {
// ignore
} }
} }


@@ -969,42 +981,48 @@ public class IntrospectionHelper implements BuildListener {
* Empty implementation to satisfy the BuildListener interface. * Empty implementation to satisfy the BuildListener interface.
* @param event Ignored in this implementation. * @param event Ignored in this implementation.
*/ */
public void buildStarted(BuildEvent event) {}
public void buildStarted(BuildEvent event) {
}


/** /**
* Empty implementation to satisfy the BuildListener interface. * Empty implementation to satisfy the BuildListener interface.
* *
* @param event Ignored in this implementation. * @param event Ignored in this implementation.
*/ */
public void targetStarted(BuildEvent event) {}
public void targetStarted(BuildEvent event) {
}


/** /**
* Empty implementation to satisfy the BuildListener interface. * Empty implementation to satisfy the BuildListener interface.
* *
* @param event Ignored in this implementation. * @param event Ignored in this implementation.
*/ */
public void targetFinished(BuildEvent event) {}
public void targetFinished(BuildEvent event) {
}


/** /**
* Empty implementation to satisfy the BuildListener interface. * Empty implementation to satisfy the BuildListener interface.
* *
* @param event Ignored in this implementation. * @param event Ignored in this implementation.
*/ */
public void taskStarted(BuildEvent event) {}
public void taskStarted(BuildEvent event) {
}


/** /**
* Empty implementation to satisfy the BuildListener interface. * Empty implementation to satisfy the BuildListener interface.
* *
* @param event Ignored in this implementation. * @param event Ignored in this implementation.
*/ */
public void taskFinished(BuildEvent event) {}
public void taskFinished(BuildEvent event) {
}


/** /**
* Empty implementation to satisfy the BuildListener interface. * Empty implementation to satisfy the BuildListener interface.
* *
* @param event Ignored in this implementation. * @param event Ignored in this implementation.
*/ */
public void messageLogged(BuildEvent event) {}
public void messageLogged(BuildEvent event) {
}


/** /**
* Check if the parent accepts a typed nested element * Check if the parent accepts a typed nested element
@@ -1016,8 +1034,7 @@ public class IntrospectionHelper implements BuildListener {
*/ */


private Object createAddTypeElement( private Object createAddTypeElement(
Project project, Object parent, String elementName)
{
Project project, Object parent, String elementName) {
ComponentHelper helper = ComponentHelper.getComponentHelper(project); ComponentHelper helper = ComponentHelper.getComponentHelper(project);
Object addedObject = null; Object addedObject = null;
Method addMethod = null; Method addMethod = null;
@@ -1091,11 +1108,11 @@ public class IntrospectionHelper implements BuildListener {
matchedClass = methodClass; matchedClass = methodClass;
matchedMethod = method; matchedMethod = method;
} else { } else {
if (! methodClass.isAssignableFrom(matchedClass)) {
throw new BuildException(
"ambiguous: types " + matchedClass.getName() +
" and " + methodClass.getName() +
" match " + paramClass.getName());
if (!methodClass.isAssignableFrom(matchedClass)) {
throw new BuildException("ambiguous: types "
+ matchedClass.getName() + " and "
+ methodClass.getName() + " match "
+ paramClass.getName());
} }
} }
} }


+ 11
- 10
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -88,7 +88,6 @@ import org.apache.tools.zip.UnixStat;
* *
* @ant.task category="packaging" * @ant.task category="packaging"
*/ */

public class Tar extends MatchingTask { public class Tar extends MatchingTask {


/** /**
@@ -296,8 +295,8 @@ public class Tar extends MatchingTask {
tOut.setDebug(true); tOut.setDebug(true);
if (longFileMode.isTruncateMode()) { if (longFileMode.isTruncateMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE); tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
} else if (longFileMode.isFailMode() ||
longFileMode.isOmitMode()) {
} else if (longFileMode.isFailMode()
|| longFileMode.isOmitMode()) {
tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR); tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
} else { } else {
// warn or GNU // warn or GNU
@@ -329,7 +328,9 @@ public class Tar extends MatchingTask {
try { try {
// close up // close up
tOut.close(); tOut.close();
} catch (IOException e) {}
} catch (IOException e) {
// ignore
}
} }
} }
} finally { } finally {
@@ -381,8 +382,8 @@ public class Tar extends MatchingTask {
log("Omitting: " + vPath, Project.MSG_INFO); log("Omitting: " + vPath, Project.MSG_INFO);
return; return;
} else if (longFileMode.isWarnMode()) { } else if (longFileMode.isWarnMode()) {
log("Entry: " + vPath + " longer than " +
TarConstants.NAMELEN + " characters.",
log("Entry: " + vPath + " longer than "
+ TarConstants.NAMELEN + " characters.",
Project.MSG_WARN); Project.MSG_WARN);
if (!longWarningGiven) { if (!longWarningGiven) {
log("Resulting tar file can only be processed " log("Resulting tar file can only be processed "
@@ -391,9 +392,9 @@ public class Tar extends MatchingTask {
longWarningGiven = true; longWarningGiven = true;
} }
} else if (longFileMode.isFailMode()) { } else if (longFileMode.isFailMode()) {
throw new BuildException(
"Entry: " + vPath + " longer than " +
TarConstants.NAMELEN + "characters.", getLocation());
throw new BuildException( "Entry: " + vPath
+ " longer than " + TarConstants.NAMELEN
+ "characters.", getLocation());
} }
} }


@@ -668,7 +669,7 @@ public class Tar extends MatchingTask {
* @return valid enumeration values * @return valid enumeration values
*/ */
public String[] getValues() { public String[] getValues() {
return new String[] { NONE, GZIP, BZIP2 };
return new String[] {NONE, GZIP, BZIP2 };
} }


/** /**


Loading…
Cancel
Save