Author: mbenson Date: Tue Jul 17 11:37:53 2007 New Revision: 557013 URL: http://svn.apache.org/viewvc?view=rev&rev=557013 Log: fmt/refac
Modified: ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java?view=diff&rev=557013&r1=557012&r2=557013 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java Tue Jul 17 11:37:53 2007 @@ -15,7 +15,6 @@ * limitations under the License. * */ - package org.apache.tools.ant; import java.io.ByteArrayOutputStream; @@ -139,11 +138,9 @@ */ private void findNextResource() { URL url = null; - while ((pathElementsIndex < pathComponents.size()) - && (url == null)) { + while ((pathElementsIndex < pathComponents.size()) && (url == null)) { try { - File pathComponent - = (File) pathComponents.elementAt(pathElementsIndex); + File pathComponent = (File) pathComponents.elementAt(pathElementsIndex); url = getResourceURL(pathComponent, this.resourceName); pathElementsIndex++; } catch (BuildException e) { @@ -159,6 +156,7 @@ * The size of buffers to be used in this classloader. */ private static final int BUFFER_SIZE = 8192; + /** * Number of array elements in a test array of strings */ @@ -221,6 +219,7 @@ * context loader. */ private ClassLoader savedContextLoader = null; + /** * Whether or not the context loader is currently saved. */ @@ -235,8 +234,7 @@ * belong. * @param classpath The classpath to use to load classes. */ - public AntClassLoader( - ClassLoader parent, Project project, Path classpath) { + public AntClassLoader(ClassLoader parent, Project project, Path classpath) { setParent(parent); setClassPath(classpath); setProject(project); @@ -282,8 +280,7 @@ * classloader should be consulted before trying to * load the a class through this loader. */ - public AntClassLoader(ClassLoader parent, Project project, Path classpath, - boolean parentFirst) { + public AntClassLoader(ClassLoader parent, Project project, Path classpath, boolean parentFirst) { this(project, classpath); if (parent != null) { setParent(parent); @@ -292,7 +289,6 @@ addJavaLibraries(); } - /** * Creates a classloader for the given project using the classpath given. * @@ -305,8 +301,7 @@ * classloader should be consulted before trying to * load the a class through this loader. */ - public AntClassLoader(Project project, Path classpath, - boolean parentFirst) { + public AntClassLoader(Project project, Path classpath, boolean parentFirst) { this(null, project, classpath, parentFirst); } @@ -371,11 +366,7 @@ * @param parent the parent class loader. */ public void setParent(ClassLoader parent) { - if (parent == null) { - this.parent = AntClassLoader.class.getClassLoader(); - } else { - this.parent = parent; - } + this.parent = parent == null ? AntClassLoader.class.getClassLoader() : parent; } /** @@ -390,7 +381,6 @@ this.parentFirst = parentFirst; } - /** * Logs a message through the project object if one has been provided. * @@ -403,9 +393,6 @@ if (project != null) { project.log(message, priority); } - // else { - // System.out.println(message); - // } } /** @@ -419,8 +406,7 @@ if (LoaderUtils.isContextLoaderAvailable()) { savedContextLoader = LoaderUtils.getContextClassLoader(); ClassLoader loader = this; - if (project != null - && "only".equals(project.getProperty("build.sysclasspath"))) { + if (project != null && "only".equals(project.getProperty("build.sysclasspath"))) { loader = this.getClass().getClassLoader(); } LoaderUtils.setContextClassLoader(loader); @@ -432,8 +418,7 @@ * Resets the current thread's context loader to its original value. */ public void resetThreadContextLoader() { - if (LoaderUtils.isContextLoaderAvailable() - && isContextLoaderSaved) { + if (LoaderUtils.isContextLoaderAvailable() && isContextLoaderSaved) { LoaderUtils.setContextClassLoader(savedContextLoader); savedContextLoader = null; isContextLoaderSaved = false; @@ -451,9 +436,8 @@ * against the project. */ public void addPathElement(String pathElement) throws BuildException { - File pathComponent - = project != null ? project.resolveFile(pathElement) - : new File(pathElement); + File pathComponent = project != null ? project.resolveFile(pathElement) : new File( + pathElement); try { addPathFile(pathComponent); } catch (IOException e) { @@ -491,28 +475,23 @@ return; } - String absPathPlusTimeAndLength = - pathComponent.getAbsolutePath() + pathComponent.lastModified() + "-" - + pathComponent.length(); + String absPathPlusTimeAndLength = pathComponent.getAbsolutePath() + + pathComponent.lastModified() + "-" + pathComponent.length(); String classpath = (String) pathMap.get(absPathPlusTimeAndLength); if (classpath == null) { ZipFile jarFile = null; InputStream manifestStream = null; try { jarFile = new ZipFile(pathComponent); - manifestStream - = jarFile.getInputStream(new ZipEntry("META-INF/MANIFEST.MF")); + manifestStream = jarFile.getInputStream(new ZipEntry("META-INF/MANIFEST.MF")); if (manifestStream == null) { return; } - Reader manifestReader - = new InputStreamReader(manifestStream, "UTF-8"); + Reader manifestReader = new InputStreamReader(manifestStream, "UTF-8"); org.apache.tools.ant.taskdefs.Manifest manifest - = new org.apache.tools.ant.taskdefs.Manifest(manifestReader); - classpath - = manifest.getMainSection().getAttributeValue("Class-Path"); - + = new org.apache.tools.ant.taskdefs.Manifest(manifestReader); + classpath = manifest.getMainSection().getAttributeValue("Class-Path"); } catch (org.apache.tools.ant.taskdefs.ManifestException e) { // ignore } finally { @@ -535,8 +514,8 @@ URL libraryURL = new URL(baseURL, classpathElement); if (!libraryURL.getProtocol().equals("file")) { log("Skipping jar library " + classpathElement - + " since only relative URLs are supported by this" - + " loader", Project.MSG_VERBOSE); + + " since only relative URLs are supported by this" + " loader", + Project.MSG_VERBOSE); continue; } String decodedPath = Locator.decodeUri(libraryURL.getFile()); @@ -635,8 +614,7 @@ * Should not be <code>null</code>. */ public void addSystemPackageRoot(String packageRoot) { - systemPackages.addElement(packageRoot - + (packageRoot.endsWith(".") ? "" : ".")); + systemPackages.addElement(packageRoot + (packageRoot.endsWith(".") ? "" : ".")); } /** @@ -649,8 +627,7 @@ * Should not be <code>null</code>. */ public void addLoaderPackageRoot(String packageRoot) { - loaderPackages.addElement(packageRoot - + (packageRoot.endsWith(".") ? "" : ".")); + loaderPackages.addElement(packageRoot + (packageRoot.endsWith(".") ? "" : ".")); } /** @@ -668,8 +645,7 @@ * @exception ClassNotFoundException if the requested class does not exist * on this loader's classpath. */ - public Class forceLoadClass(String classname) - throws ClassNotFoundException { + public Class forceLoadClass(String classname) throws ClassNotFoundException { log("force loading " + classname, Project.MSG_DEBUG); Class theClass = findLoadedClass(classname); @@ -677,7 +653,6 @@ if (theClass == null) { theClass = findClass(classname); } - return theClass; } @@ -697,8 +672,7 @@ * @exception ClassNotFoundException if the requested class does not exist * on this loader's classpath. */ - public Class forceLoadSystemClass(String classname) - throws ClassNotFoundException { + public Class forceLoadSystemClass(String classname) throws ClassNotFoundException { log("force system loading " + classname, Project.MSG_DEBUG); Class theClass = findLoadedClass(classname); @@ -706,7 +680,6 @@ if (theClass == null) { theClass = findBaseClass(classname); } - return theClass; } @@ -720,41 +693,32 @@ * resource cannot be found on the loader's classpath. */ public InputStream getResourceAsStream(String name) { - InputStream resourceStream = null; if (isParentFirst(name)) { resourceStream = loadBaseResource(name); if (resourceStream != null) { - log("ResourceStream for " + name - + " loaded from parent loader", Project.MSG_DEBUG); - + log("ResourceStream for " + name + " loaded from parent loader", Project.MSG_DEBUG); } else { resourceStream = loadResource(name); if (resourceStream != null) { - log("ResourceStream for " + name - + " loaded from ant loader", Project.MSG_DEBUG); + log("ResourceStream for " + name + " loaded from ant loader", Project.MSG_DEBUG); } } } else { resourceStream = loadResource(name); if (resourceStream != null) { - log("ResourceStream for " + name - + " loaded from ant loader", Project.MSG_DEBUG); - + log("ResourceStream for " + name + " loaded from ant loader", Project.MSG_DEBUG); } else { resourceStream = loadBaseResource(name); if (resourceStream != null) { - log("ResourceStream for " + name - + " loaded from parent loader", Project.MSG_DEBUG); + log("ResourceStream for " + name + " loaded from parent loader", + Project.MSG_DEBUG); } } } - if (resourceStream == null) { - log("Couldn't load ResourceStream for " + name, - Project.MSG_DEBUG); + log("Couldn't load ResourceStream for " + name, Project.MSG_DEBUG); } - return resourceStream; } @@ -791,11 +755,7 @@ * the resource cannot be found. */ private InputStream loadBaseResource(String name) { - if (parent == null) { - return getSystemResourceAsStream(name); - } else { - return parent.getResourceAsStream(name); - } + return parent == null ? getSystemResourceAsStream(name) : parent.getResourceAsStream(name); } /** @@ -815,14 +775,12 @@ ZipFile zipFile = (ZipFile) zipFiles.get(file); if (zipFile == null && file.isDirectory()) { File resource = new File(file, resourceName); - if (resource.exists()) { return new FileInputStream(resource); } } else { if (zipFile == null) { if (file.exists()) { - zipFile = new ZipFile(file); zipFiles.put(file, zipFile); } else { @@ -838,11 +796,9 @@ } } } catch (Exception e) { - log("Ignoring Exception " + e.getClass().getName() + ": " - + e.getMessage() + " reading resource " + resourceName - + " from " + file, Project.MSG_VERBOSE); + log("Ignoring Exception " + e.getClass().getName() + ": " + e.getMessage() + + " reading resource " + resourceName + " from " + file, Project.MSG_VERBOSE); } - return null; } @@ -876,7 +832,6 @@ break; } } - for (Enumeration e = loaderPackages.elements(); e.hasMoreElements();) { String packageName = (String) e.nextElement(); if (resourceName.startsWith(packageName)) { @@ -884,7 +839,6 @@ break; } } - return useParentFirst; } @@ -917,14 +871,10 @@ // we can find the class we want. URL url = null; if (isParentFirst(name)) { - url = (parent == null) ? super.getResource(name) - : parent.getResource(name); + url = parent == null ? super.getResource(name) : parent.getResource(name); } - if (url != null) { - log("Resource " + name + " loaded from parent loader", - Project.MSG_DEBUG); - + log("Resource " + name + " loaded from parent loader", Project.MSG_DEBUG); } else { // try and load from this loader if the parent either didn't find // it or wasn't consulted. @@ -933,32 +883,24 @@ File pathComponent = (File) e.nextElement(); url = getResourceURL(pathComponent, name); if (url != null) { - log("Resource " + name - + " loaded from ant loader", - Project.MSG_DEBUG); + log("Resource " + name + " loaded from ant loader", Project.MSG_DEBUG); } } } - if (url == null && !isParentFirst(name)) { // this loader was first but it didn't find it - try the parent if (ignoreBase) { - url = (getRootLoader() == null) ? null - : getRootLoader().getResource(name); + url = getRootLoader() == null ? null : getRootLoader().getResource(name); } else { - url = (parent == null) ? super.getResource(name) - : parent.getResource(name); + url = parent == null ? super.getResource(name) : parent.getResource(name); } if (url != null) { - log("Resource " + name + " loaded from parent loader", - Project.MSG_DEBUG); + log("Resource " + name + " loaded from parent loader", Project.MSG_DEBUG); } } - if (url == null) { log("Couldn't load Resource " + name, Project.MSG_DEBUG); } - return url; } @@ -986,15 +928,13 @@ if (isParentFirst(name)) { // Normal case. return CollectionUtils.append(base, mine); - } else if (ignoreBase) { - return getRootLoader() == null - ? mine - : CollectionUtils.append( - mine, getRootLoader().getResources(name)); - } else { - // Inverted. - return CollectionUtils.append(mine, base); } + if (ignoreBase) { + return getRootLoader() == null ? mine : CollectionUtils.append(mine, getRootLoader() + .getResources(name)); + } + // parent last: + return CollectionUtils.append(mine, base); } /** @@ -1034,8 +974,7 @@ ZipEntry entry = zipFile.getEntry(resourceName); if (entry != null) { try { - return new URL("jar:" + FILE_UTILS.getFileURL(file) - + "!/" + entry); + return new URL("jar:" + FILE_UTILS.getFileURL(file) + "!/" + entry); } catch (MalformedURLException ex) { return null; } @@ -1044,7 +983,6 @@ } catch (Exception e) { e.printStackTrace(); } - return null; } @@ -1069,7 +1007,7 @@ * classpath. */ protected synchronized Class loadClass(String classname, boolean resolve) - throws ClassNotFoundException { + throws ClassNotFoundException { // 'sync' is needed - otherwise 2 threads can load the same class // twice, resulting in LinkageError: duplicated class definition. // findLoadedClass avoids that, but without sync it won't work. @@ -1078,36 +1016,31 @@ if (theClass != null) { return theClass; } - if (isParentFirst(classname)) { try { theClass = findBaseClass(classname); - log("Class " + classname + " loaded from parent loader " - + "(parentFirst)", Project.MSG_DEBUG); + log("Class " + classname + " loaded from parent loader " + "(parentFirst)", + Project.MSG_DEBUG); } catch (ClassNotFoundException cnfe) { theClass = findClass(classname); - log("Class " + classname + " loaded from ant loader " - + "(parentFirst)", Project.MSG_DEBUG); + log("Class " + classname + " loaded from ant loader " + "(parentFirst)", + Project.MSG_DEBUG); } } else { try { theClass = findClass(classname); - log("Class " + classname + " loaded from ant loader", - Project.MSG_DEBUG); + log("Class " + classname + " loaded from ant loader", Project.MSG_DEBUG); } catch (ClassNotFoundException cnfe) { if (ignoreBase) { throw cnfe; } theClass = findBaseClass(classname); - log("Class " + classname + " loaded from parent loader", - Project.MSG_DEBUG); + log("Class " + classname + " loaded from parent loader", Project.MSG_DEBUG); } } - if (resolve) { resolveClass(theClass); } - return theClass; } @@ -1137,14 +1070,14 @@ * * @throws IOException if the class data cannot be read. */ - protected Class defineClassFromData(File container, byte[] classData, - String classname) throws IOException { + protected Class defineClassFromData(File container, byte[] classData, String classname) + throws IOException { definePackage(container, classname); // XXX should instead make a new ProtectionDomain with a CodeSource // corresponding to container.toURI().toURL() and the same // PermissionCollection as Project.class.protectionDomain had - return defineClass(classname, classData, 0, classData.length, - Project.class.getProtectionDomain()); + return defineClass(classname, classData, 0, classData.length, Project.class + .getProtectionDomain()); } /** @@ -1157,25 +1090,21 @@ * @exception IOException if the package information cannot be read from the * container. */ - protected void definePackage(File container, String className) - throws IOException { + protected void definePackage(File container, String className) throws IOException { int classIndex = className.lastIndexOf('.'); if (classIndex == -1) { return; } - String packageName = className.substring(0, classIndex); if (getPackage(packageName) != null) { // already defined return; } - // define the package now Manifest manifest = getJarManifest(container); if (manifest == null) { - definePackage(packageName, null, null, null, null, null, - null, null); + definePackage(packageName, null, null, null, null, null, null, null); } else { definePackage(container, packageName, manifest); } @@ -1215,8 +1144,7 @@ * @param packageName the name of the package being defined. * @param manifest the jar's manifest */ - protected void definePackage(File container, String packageName, - Manifest manifest) { + protected void definePackage(File container, String packageName, Manifest manifest) { String sectionName = packageName.replace('.', '/') + "/"; String specificationTitle = null; @@ -1230,69 +1158,49 @@ Attributes sectionAttributes = manifest.getAttributes(sectionName); if (sectionAttributes != null) { - specificationTitle - = sectionAttributes.getValue(Name.SPECIFICATION_TITLE); - specificationVendor - = sectionAttributes.getValue(Name.SPECIFICATION_VENDOR); - specificationVersion - = sectionAttributes.getValue(Name.SPECIFICATION_VERSION); - implementationTitle - = sectionAttributes.getValue(Name.IMPLEMENTATION_TITLE); - implementationVendor - = sectionAttributes.getValue(Name.IMPLEMENTATION_VENDOR); - implementationVersion - = sectionAttributes.getValue(Name.IMPLEMENTATION_VERSION); - sealedString - = sectionAttributes.getValue(Name.SEALED); + specificationTitle = sectionAttributes.getValue(Name.SPECIFICATION_TITLE); + specificationVendor = sectionAttributes.getValue(Name.SPECIFICATION_VENDOR); + specificationVersion = sectionAttributes.getValue(Name.SPECIFICATION_VERSION); + implementationTitle = sectionAttributes.getValue(Name.IMPLEMENTATION_TITLE); + implementationVendor = sectionAttributes.getValue(Name.IMPLEMENTATION_VENDOR); + implementationVersion = sectionAttributes.getValue(Name.IMPLEMENTATION_VERSION); + sealedString = sectionAttributes.getValue(Name.SEALED); } - Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes != null) { if (specificationTitle == null) { - specificationTitle - = mainAttributes.getValue(Name.SPECIFICATION_TITLE); + specificationTitle = mainAttributes.getValue(Name.SPECIFICATION_TITLE); } if (specificationVendor == null) { - specificationVendor - = mainAttributes.getValue(Name.SPECIFICATION_VENDOR); + specificationVendor = mainAttributes.getValue(Name.SPECIFICATION_VENDOR); } if (specificationVersion == null) { - specificationVersion - = mainAttributes.getValue(Name.SPECIFICATION_VERSION); + specificationVersion = mainAttributes.getValue(Name.SPECIFICATION_VERSION); } if (implementationTitle == null) { - implementationTitle - = mainAttributes.getValue(Name.IMPLEMENTATION_TITLE); + implementationTitle = mainAttributes.getValue(Name.IMPLEMENTATION_TITLE); } if (implementationVendor == null) { - implementationVendor - = mainAttributes.getValue(Name.IMPLEMENTATION_VENDOR); + implementationVendor = mainAttributes.getValue(Name.IMPLEMENTATION_VENDOR); } if (implementationVersion == null) { - implementationVersion - = mainAttributes.getValue(Name.IMPLEMENTATION_VERSION); + implementationVersion = mainAttributes.getValue(Name.IMPLEMENTATION_VERSION); } if (sealedString == null) { - sealedString - = mainAttributes.getValue(Name.SEALED); + sealedString = mainAttributes.getValue(Name.SEALED); } } - - if (sealedString != null - && sealedString.toLowerCase(Locale.ENGLISH).equals("true")) { + if (sealedString != null && sealedString.toLowerCase(Locale.ENGLISH).equals("true")) { try { sealBase = new URL(FileUtils.getFileUtils().toURI(container.getAbsolutePath())); } catch (MalformedURLException e) { // ignore } } - - definePackage(packageName, specificationTitle, specificationVersion, - specificationVendor, implementationTitle, - implementationVersion, implementationVendor, sealBase); + definePackage(packageName, specificationTitle, specificationVersion, specificationVendor, + implementationTitle, implementationVersion, implementationVendor, sealBase); } - /** * Reads a class definition from a stream. * @@ -1309,9 +1217,8 @@ * @exception SecurityException if there is a security problem while * reading the class from the stream. */ - private Class getClassFromStream(InputStream stream, String classname, - File container) - throws IOException, SecurityException { + private Class getClassFromStream(InputStream stream, String classname, File container) + throws IOException, SecurityException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int bytesRead = -1; byte[] buffer = new byte[BUFFER_SIZE]; @@ -1319,7 +1226,6 @@ while ((bytesRead = stream.read(buffer, 0, BUFFER_SIZE)) != -1) { baos.write(buffer, 0, bytesRead); } - byte[] classData = baos.toByteArray(); return defineClassFromData(container, classData, classname); } @@ -1337,7 +1243,6 @@ */ public Class findClass(String name) throws ClassNotFoundException { log("Finding class " + name, Project.MSG_DEBUG); - return findClassInComponents(name); } @@ -1358,7 +1263,6 @@ return false; } - /** * Finds a class on the given classpath. * @@ -1383,20 +1287,17 @@ try { stream = getResourceStream(pathComponent, classFilename); if (stream != null) { - log("Loaded from " + pathComponent + " " - + classFilename, Project.MSG_DEBUG); + log("Loaded from " + pathComponent + " " + classFilename, Project.MSG_DEBUG); return getClassFromStream(stream, name, pathComponent); } } catch (SecurityException se) { throw se; } catch (IOException ioe) { // ioe.printStackTrace(); - log("Exception reading component " + pathComponent - + " (reason: " + ioe.getMessage() + ")", - Project.MSG_VERBOSE); + log("Exception reading component " + pathComponent + " (reason: " + + ioe.getMessage() + ")", Project.MSG_VERBOSE); } } - throw new ClassNotFoundException(name); } finally { FileUtils.close(stream); @@ -1419,11 +1320,7 @@ * on this loader's classpath. */ private Class findBaseClass(String name) throws ClassNotFoundException { - if (parent == null) { - return findSystemClass(name); - } else { - return parent.loadClass(name); - } + return parent == null ? findSystemClass(name) : parent.loadClass(name); } /** Modified: ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java?view=diff&rev=557013&r1=557012&r2=557013 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java Tue Jul 17 11:37:53 2007 @@ -15,7 +15,6 @@ * limitations under the License. * */ - package org.apache.tools.ant; import java.lang.reflect.Modifier; @@ -62,11 +61,13 @@ /** Map of tasks generated from antTypeTable */ private Hashtable taskClassDefinitions = new Hashtable(); + /** flag to rebuild taskClassDefinitions */ private boolean rebuildTaskClassDefinitions = true; /** Map of types generated from antTypeTable */ private Hashtable typeClassDefinitions = new Hashtable(); + /** flag to rebuild typeClassDefinitions */ private boolean rebuildTypeClassDefinitions = true; @@ -78,6 +79,7 @@ * processing antlib */ private Stack antLibStack = new Stack(); + /** current antlib uri */ private String antLibCurrentUri = null; @@ -96,6 +98,7 @@ * Error string when the file taskdefs/defaults.properties cannot be found */ private static final String ERROR_NO_TASK_LIST_LOAD = "Can't load default task list"; + /** * Error string when the typedefs/defaults.properties cannot be found */ @@ -120,7 +123,6 @@ // {tasks, types} private static Properties[] defaultDefinitions = new Properties[2]; - /** * Find a project component for a specific project, creating * it if it does not exist. @@ -132,8 +134,7 @@ return null; } // Singleton for now, it may change ( per/classloader ) - ComponentHelper ph = (ComponentHelper) project.getReference( - COMPONENT_HELPER_REFERENCE); + ComponentHelper ph = (ComponentHelper) project.getReference(COMPONENT_HELPER_REFERENCE); if (ph != null) { return ph; } @@ -209,10 +210,8 @@ * @return the created component. * @throws BuildException if an error occurs. */ - public Object createComponent(UnknownElement ue, - String ns, - String componentType) - throws BuildException { + public Object createComponent(UnknownElement ue, String ns, String componentType) + throws BuildException { Object component = createComponent(componentType); if (component instanceof Task) { Task task = (Task) component; @@ -235,7 +234,7 @@ */ public Object createComponent(String componentName) { AntTypeDefinition def = getDefinition(componentName); - return (def == null) ? null : def.create(project); + return def == null ? null : def.create(project); } /** @@ -248,7 +247,7 @@ */ public Class getComponentClass(String componentName) { AntTypeDefinition def = getDefinition(componentName); - return (def == null) ? null : def.getExposedClass(project); + return def == null ? null : def.getExposedClass(project); } /** @@ -329,8 +328,7 @@ // don't have to check for public, since // getConstructor finds public constructors only. } catch (NoSuchMethodException e) { - final String message = "No public no-arg constructor in " - + taskClass; + final String message = "No public no-arg constructor in " + taskClass; project.log(message, Project.MSG_ERR); throw new BuildException(message); } @@ -351,16 +349,14 @@ synchronized (antTypeTable) { if (rebuildTaskClassDefinitions) { taskClassDefinitions.clear(); - for (Iterator i = antTypeTable.keySet().iterator(); - i.hasNext();) { + for (Iterator i = antTypeTable.keySet().iterator(); i.hasNext();) { String name = (String) i.next(); Class clazz = antTypeTable.getExposedClass(name); if (clazz == null) { continue; } if (Task.class.isAssignableFrom(clazz)) { - taskClassDefinitions.put( - name, antTypeTable.getTypeClass(name)); + taskClassDefinitions.put(name, antTypeTable.getTypeClass(name)); } } rebuildTaskClassDefinitions = false; @@ -370,7 +366,6 @@ return taskClassDefinitions; } - /** * Returns the current type definition hashtable. The returned hashtable is * "live" and so should not be modified. @@ -383,16 +378,14 @@ synchronized (antTypeTable) { if (rebuildTypeClassDefinitions) { typeClassDefinitions.clear(); - for (Iterator i = antTypeTable.keySet().iterator(); - i.hasNext();) { + for (Iterator i = antTypeTable.keySet().iterator(); i.hasNext();) { String name = (String) i.next(); Class clazz = antTypeTable.getExposedClass(name); if (clazz == null) { continue; } if (!(Task.class.isAssignableFrom(clazz))) { - typeClassDefinitions.put( - name, antTypeTable.getTypeClass(name)); + typeClassDefinitions.put(name, antTypeTable.getTypeClass(name)); } } rebuildTypeClassDefinitions = false; @@ -420,8 +413,8 @@ def.setName(typeName); def.setClass(typeClass); updateDataTypeDefinition(def); - project.log(" +User datatype: " + typeName + " " - + typeClass.getName(), Project.MSG_DEBUG); + project.log(" +User datatype: " + typeName + " " + typeClass.getName(), + Project.MSG_DEBUG); } /** @@ -463,8 +456,7 @@ if (task == null && taskType.equals(ANT_PROPERTY_TASK)) { // quick fix for Ant.java use of property before // initializing the project - addTaskDefinition(ANT_PROPERTY_TASK, - org.apache.tools.ant.taskdefs.Property.class); + addTaskDefinition(ANT_PROPERTY_TASK, org.apache.tools.ant.taskdefs.Property.class); task = createNewTask(taskType); } return task; @@ -492,10 +484,8 @@ return null; } if (!(obj instanceof Task)) { - throw new BuildException( - "Expected a Task from '" + taskType - + "' but got an instance of " + obj.getClass().getName() - + " instead"); + throw new BuildException("Expected a Task from '" + taskType + + "' but got an instance of " + obj.getClass().getName() + " instead"); } Task task = (Task) obj; task.setTaskType(taskType); @@ -582,8 +572,8 @@ if (p == null) { p = Project.getProject(o); } - return p == null ? getUnmappedElementName(o.getClass(), brief) - : getComponentHelper(p).getElementName(o, brief); + return p == null ? getUnmappedElementName(o.getClass(), brief) : getComponentHelper(p) + .getElementName(o, brief); } private static String getUnmappedElementName(Class c, boolean brief) { @@ -601,8 +591,7 @@ * @return true if exposed type of definition is present. */ private boolean validDefinition(AntTypeDefinition def) { - return !(def.getTypeClass(project) == null - || def.getExposedClass(project) == null); + return !(def.getTypeClass(project) == null || def.getExposedClass(project) == null); } /** @@ -611,8 +600,7 @@ * @param old the old definition. * @return true if the two definitions are the same. */ - private boolean sameDefinition( - AntTypeDefinition def, AntTypeDefinition old) { + private boolean sameDefinition(AntTypeDefinition def, AntTypeDefinition old) { boolean defValid = validDefinition(def); boolean sameValidity = (defValid == validDefinition(old)); //must have same validity; then if they are valid they must also be the same: @@ -635,15 +623,12 @@ return; } Class oldClass = antTypeTable.getExposedClass(name); - boolean isTask = - (oldClass != null && Task.class.isAssignableFrom(oldClass)); + boolean isTask = oldClass != null && Task.class.isAssignableFrom(oldClass); project.log("Trying to override old definition of " - + (isTask ? "task " : "datatype ") + name, - (def.similarDefinition(old, project)) - ? Project.MSG_VERBOSE : Project.MSG_WARN); + + (isTask ? "task " : "datatype ") + name, (def.similarDefinition(old, + project)) ? Project.MSG_VERBOSE : Project.MSG_WARN); } - project.log(" +Datatype " + name + " " + def.getClassName(), - Project.MSG_DEBUG); + project.log(" +Datatype " + name + " " + def.getClassName(), Project.MSG_DEBUG); antTypeTable.put(name, def); } } @@ -669,8 +654,7 @@ */ public void exitAntLib() { antLibStack.pop(); - antLibCurrentUri = (antLibStack.size() == 0) - ? null : (String) antLibStack.peek(); + antLibCurrentUri = (antLibStack.size() == 0) ? null : (String) antLibStack.peek(); } /** @@ -695,8 +679,7 @@ private ClassLoader getClassLoader(ClassLoader classLoader) { String buildSysclasspath = project.getProperty(MagicNames.BUILD_SYSCLASSPATH); - if (project.getCoreLoader() != null - && !(BUILD_SYSCLASSPATH_ONLY.equals(buildSysclasspath))) { + if (project.getCoreLoader() != null && !(BUILD_SYSCLASSPATH_ONLY.equals(buildSysclasspath))) { classLoader = project.getCoreLoader(); } return classLoader; @@ -712,19 +695,15 @@ * or parsing the definitions list */ private static synchronized Properties getDefaultDefinitions(boolean type) - throws BuildException { + throws BuildException { int idx = type ? 1 : 0; if (defaultDefinitions[idx] == null) { - String resource = type - ? MagicNames.TYPEDEFS_PROPERTIES_RESOURCE - : MagicNames.TASKDEF_PROPERTIES_RESOURCE; - String errorString = type - ? ERROR_NO_TYPE_LIST_LOAD - : ERROR_NO_TASK_LIST_LOAD; + String resource = type ? MagicNames.TYPEDEFS_PROPERTIES_RESOURCE + : MagicNames.TASKDEF_PROPERTIES_RESOURCE; + String errorString = type ? ERROR_NO_TYPE_LIST_LOAD : ERROR_NO_TASK_LIST_LOAD; InputStream in = null; try { - in = ComponentHelper.class.getResourceAsStream( - resource); + in = ComponentHelper.class.getResourceAsStream(resource); if (in == null) { throw new BuildException(errorString); } @@ -831,10 +810,8 @@ dirListingText.append(libDir); dirListingText.append('\n'); dirListingText.append(tab); - dirListingText.append( - "a directory added on the command line with the -lib argument"); + dirListingText.append("a directory added on the command line with the -lib argument"); } - String dirListing = dirListingText.toString(); //look up the name @@ -892,11 +869,11 @@ t.printStackTrace(out); } catch (NoClassDefFoundError ncdfe) { jars = true; - out.println("Cause: A class needed by class " - + classname + " cannot be found: "); + out.println("Cause: A class needed by class " + classname + + " cannot be found: "); out.println(" " + ncdfe.getMessage()); out.println("Action: Determine what extra JAR files are" - + " needed, and place them in:"); + + " needed, and place them in:"); out.println(dirListing); } } @@ -917,8 +894,8 @@ + "defect or contact the developer team."); } else { out.println("This does not appear to be a task bundled with Ant."); - out.println("Please take it up with the supplier of the third-party " - + type + "."); + out.println("Please take it up with the supplier of the third-party " + type + + "."); out.println("If you have written it yourself, you probably have a bug to fix."); } } else { @@ -934,24 +911,23 @@ /** * Print unknown definition.forking */ - private void printUnknownDefinition( - PrintWriter out, String componentName, String dirListing) { + private void printUnknownDefinition(PrintWriter out, String componentName, String dirListing) { boolean isAntlib = componentName.indexOf(MagicNames.ANTLIB_PREFIX) == 0; String uri=ProjectHelper.extractUriFromComponentName(componentName); out.println("Cause: The name is undefined."); out.println("Action: Check the spelling."); out.println("Action: Check that any custom tasks/types have been declared."); out.println("Action: Check that any <presetdef>/<macrodef>" - + " declarations have taken place."); - if(uri.length()>0) { + + " declarations have taken place."); + if (uri.length() > 0) { List matches = antTypeTable.findMatches(uri); - if(matches.size()>0) { + if (matches.size() > 0) { out.println(); - out.println("The definitions in the namespace "+uri+" are:"); - for(Iterator it=matches.iterator();it.hasNext();) { - AntTypeDefinition def=(AntTypeDefinition) it.next(); + out.println("The definitions in the namespace " + uri + " are:"); + for (Iterator it = matches.iterator(); it.hasNext();) { + AntTypeDefinition def = (AntTypeDefinition) it.next(); String local = ProjectHelper.extractNameFromComponentName(def.getName()); - out.println(" "+local); + out.println(" " + local); } } else { out.println("No types or tasks have been defined in this namespace yet"); @@ -968,9 +944,8 @@ /** * Print class not found. */ - private void printClassNotFound( - PrintWriter out, String classname, boolean optional, - String dirListing) { + private void printClassNotFound(PrintWriter out, String classname, boolean optional, + String dirListing) { out.println("Cause: the class " + classname + " was not found."); if (optional) { out.println(" This looks like one of Ant's optional components."); @@ -986,23 +961,19 @@ /** * Print could not load dependent class. */ - private void printNotLoadDependentClass( - PrintWriter out, boolean optional, NoClassDefFoundError ncdfe, - String dirListing) { + private void printNotLoadDependentClass(PrintWriter out, boolean optional, + NoClassDefFoundError ncdfe, String dirListing) { out.println("Cause: Could not load a dependent class " + ncdfe.getMessage()); if (optional) { out.println(" It is not enough to have Ant's optional JARs"); - out.println(" you need the JAR files that the" - + " optional tasks depend upon."); - out.println(" Ant's optional task dependencies are" - + " listed in the manual."); + out.println(" you need the JAR files that the" + " optional tasks depend upon."); + out.println(" Ant's optional task dependencies are" + " listed in the manual."); } else { - out.println(" This class may be in a separate JAR" - + " that is not installed."); + out.println(" This class may be in a separate JAR" + " that is not installed."); } out.println("Action: Determine what extra JAR files are" - + " needed, and place them in one of:"); + + " needed, and place them in one of:"); out.println(dirListing); } @@ -1038,15 +1009,14 @@ Class getExposedClass(String name) { AntTypeDefinition def = getDefinition(name); - return (def == null) ? null : def.getExposedClass(project); + return def == null ? null : def.getExposedClass(project); } public boolean contains(Object clazz) { boolean found = false; if (clazz instanceof Class) { for (Iterator i = values().iterator(); i.hasNext() && !found;) { - found = (((AntTypeDefinition) (i.next())).getExposedClass( - project) == clazz); + found = (((AntTypeDefinition) (i.next())).getExposedClass(project) == clazz); } } return found; @@ -1066,7 +1036,7 @@ ArrayList matches=new ArrayList(); for (Iterator i = values().iterator(); i.hasNext() ;) { AntTypeDefinition def = (AntTypeDefinition) (i.next()); - if(def.getName().startsWith(prefix)) { + if (def.getName().startsWith(prefix)) { matches.add(def); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]