Browse Source

changed for checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274771 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 22 years ago
parent
commit
1819851c5e
1 changed files with 82 additions and 53 deletions
  1. +82
    -53
      src/main/org/apache/tools/ant/ComponentHelper.java

+ 82
- 53
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -109,29 +109,54 @@ public class ComponentHelper {
protected Project project; protected Project project;


/** /**
* find a project component for a specific project, creating
* it if it does not exist
* @param project the project
* @return the project component for a specific project
*/ */
public static ComponentHelper getComponentHelper(Project project) { public static ComponentHelper getComponentHelper(Project project) {
// Singleton for now, it may change ( per/classloader ) // Singleton for now, it may change ( per/classloader )
ComponentHelper ph=(ComponentHelper)project.getReference( "ant.ComponentHelper" );
if( ph!=null ) return ph;
ph=new ComponentHelper();
ph.setProject( project );
ComponentHelper ph = (ComponentHelper) project.getReference(
"ant.ComponentHelper");
if (ph != null) {
return ph;
}
ph = new ComponentHelper();
ph.setProject(project);


project.addReference( "ant.ComponentHelper",ph );
project.addReference("ant.ComponentHelper", ph);
return ph; return ph;
} }


/**
* Creates a new ComponentHelper instance.
*/
protected ComponentHelper() { protected ComponentHelper() {
} }


public void setNext( ComponentHelper next ) {
this.next=next;
/**
* Set the next chained component helper
*
* @param next the next chained component helper
*/
public void setNext(ComponentHelper next) {
this.next = next;
} }


/**
* Get the next chained component helper
*
* @return the next chained component helper
*/
public ComponentHelper getNext() { public ComponentHelper getNext() {
return next; return next;
} }


/**
* Sets the project for this component helper
*
* @param project the project for this helper
*/
public void setProject(Project project) { public void setProject(Project project) {
this.project = project; this.project = project;
antTypeTable = new AntTypeTable(project); antTypeTable = new AntTypeTable(project);
@@ -141,6 +166,7 @@ public class ComponentHelper {
* Used with creating child projects. Each child * Used with creating child projects. Each child
* project inherites the component definitions * project inherites the component definitions
* from its parent. * from its parent.
* @param helper the component helper of the parent project
*/ */
public void initSubProject(ComponentHelper helper) { public void initSubProject(ComponentHelper helper) {
// add the types of the parent project // add the types of the parent project
@@ -158,14 +184,13 @@ public class ComponentHelper {
* @param ue The component helper has access via ue to the entire XML tree. * @param ue The component helper has access via ue to the entire XML tree.
* @param ns Namespace. Also available as ue.getNamespace() * @param ns Namespace. Also available as ue.getNamespace()
* @param taskName The element name. Also available as ue.getTag() * @param taskName The element name. Also available as ue.getTag()
* @return
* @throws BuildException
* @return the created component
* @throws BuildException if an error occuries
*/ */
public Object createComponent( UnknownElement ue,
String ns,
String taskName )
throws BuildException
{
public Object createComponent(UnknownElement ue,
String ns,
String taskName)
throws BuildException {
Object component = createComponent(taskName); Object component = createComponent(taskName);
if (component == null) { if (component == null) {
return null; return null;
@@ -189,9 +214,7 @@ public class ComponentHelper {
* name is prefixed withe the namespace uri and ":" * name is prefixed withe the namespace uri and ":"
* @return the class if found or null if not. * @return the class if found or null if not.
*/ */
public Object createComponent(String componentName)
throws BuildException
{
public Object createComponent(String componentName) {
return antTypeTable.create(componentName); return antTypeTable.create(componentName);
} }


@@ -209,18 +232,19 @@ public class ComponentHelper {


/** /**
* Return the antTypeDefinition for a componentName * Return the antTypeDefinition for a componentName
* @param componentName the name of the component
* @return the ant definition or null if not present
*/ */
public AntTypeDefinition getDefinition(String componentName) { public AntTypeDefinition getDefinition(String componentName) {
return antTypeTable.getDefinition(componentName); return antTypeTable.getDefinition(componentName);
} }


/** Initialization code - implementing the original ant component
/**
* Initialization code - implementing the original ant component
* loading from /org/apache/tools/ant/taskdefs/default.properties * loading from /org/apache/tools/ant/taskdefs/default.properties
* and .../types/default.properties * and .../types/default.properties
*
* @throws BuildException
*/ */
public void initDefaultDefinitions() throws BuildException {
public void initDefaultDefinitions() {
initTasks(); initTasks();
initTypes(); initTypes();
} }
@@ -303,13 +327,12 @@ public class ComponentHelper {
* (String to Class). * (String to Class).
*/ */
public Hashtable getTaskDefinitions() { public Hashtable getTaskDefinitions() {
synchronized(taskClassDefinitions) {
synchronized (taskClassDefinitions) {
synchronized (antTypeTable) { synchronized (antTypeTable) {
if (rebuildTaskClassDefinitions) { if (rebuildTaskClassDefinitions) {
taskClassDefinitions.clear(); taskClassDefinitions.clear();
for (Iterator i = antTypeTable.keySet().iterator(); for (Iterator i = antTypeTable.keySet().iterator();
i.hasNext();)
{
i.hasNext();) {
String name = (String) i.next(); String name = (String) i.next();
Class clazz = Class clazz =
(Class) antTypeTable.getExposedClass(name); (Class) antTypeTable.getExposedClass(name);
@@ -337,20 +360,19 @@ public class ComponentHelper {
* (String to Class). * (String to Class).
*/ */
public Hashtable getDataTypeDefinitions() { public Hashtable getDataTypeDefinitions() {
synchronized(typeClassDefinitions) {
synchronized (typeClassDefinitions) {
synchronized (antTypeTable) { synchronized (antTypeTable) {
if (rebuildTypeClassDefinitions) { if (rebuildTypeClassDefinitions) {
typeClassDefinitions.clear(); typeClassDefinitions.clear();
for (Iterator i = antTypeTable.keySet().iterator(); for (Iterator i = antTypeTable.keySet().iterator();
i.hasNext();)
{
i.hasNext();) {
String name = (String) i.next(); String name = (String) i.next();
Class clazz = Class clazz =
(Class) antTypeTable.getExposedClass(name); (Class) antTypeTable.getExposedClass(name);
if (clazz == null) { if (clazz == null) {
continue; continue;
} }
if (! Task.class.isAssignableFrom(clazz)) {
if (!(Task.class.isAssignableFrom(clazz))) {
typeClassDefinitions.put( typeClassDefinitions.put(
name, antTypeTable.getTypeClass(name)); name, antTypeTable.getTypeClass(name));
} }
@@ -423,7 +445,7 @@ public class ComponentHelper {
* creation fails. * creation fails.
*/ */
public Task createTask(String taskType) throws BuildException { public Task createTask(String taskType) throws BuildException {
Task task=createNewTask(taskType);
Task task = createNewTask(taskType);
if (task == null && taskType.equals("property")) { if (task == null && taskType.equals("property")) {
// quick fix for Ant.java use of property before // quick fix for Ant.java use of property before
// initializeing the project // initializeing the project
@@ -457,7 +479,7 @@ public class ComponentHelper {
return null; return null;
} }


if (! Task.class.isAssignableFrom(c)) {
if (!(Task.class.isAssignableFrom(c))) {
return null; return null;
} }
Task task = (Task) antTypeTable.create(taskType); Task task = (Task) antTypeTable.create(taskType);
@@ -508,11 +530,11 @@ public class ComponentHelper {
if (v != null) { if (v != null) {
Enumeration enum = v.elements(); Enumeration enum = v.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
WeakishReference ref=
WeakishReference ref =
(WeakishReference) enum.nextElement(); (WeakishReference) enum.nextElement();
Task t = (Task) ref.get(); Task t = (Task) ref.get();
//being a weak ref, it may be null by this point //being a weak ref, it may be null by this point
if(t!=null) {
if (t != null) {
t.markInvalid(); t.markInvalid();
} }
} }
@@ -568,11 +590,11 @@ public class ComponentHelper {
/** return true if the two definitions are the same */ /** return true if the two definitions are the same */
private boolean sameDefinition( private boolean sameDefinition(
AntTypeDefinition def, AntTypeDefinition old) { AntTypeDefinition def, AntTypeDefinition old) {
if (! (old.getTypeClass(project).equals(def.getTypeClass(project)))) {
if (!(old.getTypeClass(project).equals(def.getTypeClass(project)))) {
return false; return false;
} }
if (! (old.getExposedClass(project).equals(
def.getExposedClass(project)))) {
if (!(old.getExposedClass(project).equals(
def.getExposedClass(project)))) {
return false; return false;
} }
return true; return true;
@@ -595,18 +617,18 @@ public class ComponentHelper {
Class oldClass = antTypeTable.getExposedClass(name); Class oldClass = antTypeTable.getExposedClass(name);
if (Task.class.isAssignableFrom(oldClass)) { if (Task.class.isAssignableFrom(oldClass)) {
int logLevel = Project.MSG_WARN; int logLevel = Project.MSG_WARN;
if (def.getClassName().equals(old.getClassName()) &&
def.getClassLoader() == old.getClassLoader()) {
if (def.getClassName().equals(old.getClassName())
&& def.getClassLoader() == old.getClassLoader()) {
logLevel = Project.MSG_VERBOSE; logLevel = Project.MSG_VERBOSE;
} }
project.log( project.log(
"Trying to override old definition of task " +
name, logLevel);
"Trying to override old definition of task "
+ name, logLevel);
invalidateCreatedTasks(name); invalidateCreatedTasks(name);
} else { } else {
project.log( project.log(
"Trying to override old definition of datatype " +
name, Project.MSG_WARN);
"Trying to override old definition of datatype "
+ name, Project.MSG_WARN);
} }
} }
project.log(" +Datatype " + name + " " + def.getClassName(), project.log(" +Datatype " + name + " " + def.getClassName(),
@@ -620,8 +642,8 @@ public class ComponentHelper {
*/ */
private void initTasks() { private void initTasks() {
ClassLoader classLoader = null; ClassLoader classLoader = null;
if (project.getCoreLoader() != null &&
! ("only".equals(project.getProperty("build.sysclasspath")))) {
if (project.getCoreLoader() != null
&& !("only".equals(project.getProperty("build.sysclasspath")))) {
classLoader = project.getCoreLoader(); classLoader = project.getCoreLoader();
} }
String dataDefs = "/org/apache/tools/ant/taskdefs/defaults.properties"; String dataDefs = "/org/apache/tools/ant/taskdefs/defaults.properties";
@@ -649,10 +671,13 @@ public class ComponentHelper {
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new BuildException("Can't load default type list"); throw new BuildException("Can't load default type list");
}
finally {
} finally {
if (in != null) { if (in != null) {
try {in.close();} catch (Exception ignore) {}
try {
in.close();
} catch (Exception ignore) {
// Ignore
}
} }
} }
} }
@@ -662,8 +687,8 @@ public class ComponentHelper {
*/ */
private void initTypes() { private void initTypes() {
ClassLoader classLoader = null; ClassLoader classLoader = null;
if (project.getCoreLoader() != null &&
! ("only".equals(project.getProperty("build.sysclasspath")))) {
if (project.getCoreLoader() != null
&& !("only".equals(project.getProperty("build.sysclasspath")))) {
classLoader = project.getCoreLoader(); classLoader = project.getCoreLoader();
} }
String dataDefs = "/org/apache/tools/ant/types/defaults.properties"; String dataDefs = "/org/apache/tools/ant/types/defaults.properties";
@@ -689,10 +714,13 @@ public class ComponentHelper {
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new BuildException("Can't load default type list"); throw new BuildException("Can't load default type list");
}
finally {
} finally {
if (in != null) { if (in != null) {
try {in.close();} catch (Exception ignore) {}
try {
in.close();
} catch (Exception ignore) {
// ignore
}
} }
} }
} }
@@ -701,7 +729,7 @@ public class ComponentHelper {
* map that contains the component definitions * map that contains the component definitions
*/ */
private static class AntTypeTable extends Hashtable { private static class AntTypeTable extends Hashtable {
Project project;
private Project project;


public AntTypeTable(Project project) { public AntTypeTable(Project project) {
this.project = project; this.project = project;
@@ -745,8 +773,9 @@ public class ComponentHelper {
for (Iterator i = values().iterator(); i.hasNext();) { for (Iterator i = values().iterator(); i.hasNext();) {
AntTypeDefinition def = (AntTypeDefinition) i.next(); AntTypeDefinition def = (AntTypeDefinition) i.next();
Class c = def.getExposedClass(project); Class c = def.getExposedClass(project);
if (c == clazz)
if (c == clazz) {
return true; return true;
}
} }
return false; return false;
} }


Loading…
Cancel
Save