From e3cc7de84e7518e5144dba5c23f36b4694987f48 Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Thu, 3 Jul 2003 20:47:10 +0000 Subject: [PATCH] checkstyle fixes PR: 21316 Submitted by: Gus Heck (Gus dot Heck at Olin dot edu) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274752 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/unix/Symlink.java | 222 +++++++++--------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java index b66c4b1db..7a1907c2e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java @@ -97,11 +97,11 @@ import org.apache.tools.ant.taskdefs.Execute; *

This task performs several related operations. In the most trivial, * and default usage, it creates a link specified in the link atribute to * a resource specified in the resource atribute. The second usage of this - * task is to traverses a directory structure specified by a fileset, + * task is to traverses a directory structure specified by a fileset, * and write a properties file in each included directory describing the * links found in that directory. The third usage is to traverse a * directory structure specified by a fileset, looking for properties files - * (also specified as included in the fileset) and recreate the links + * (also specified as included in the fileset) and recreate the links * that have been previously recorded for each directory. Finally, it can be * used to remove a symlink without deleting the file or directory it points * to. @@ -133,21 +133,21 @@ import org.apache.tools.ant.taskdefs.Execute; * <symlink action="delete" link="${dir.top}/foo"/> * * - *

LIMITATIONS: Because Java has no direct support for + *

LIMITATIONS: Because Java has no direct support for * handling symlinks this task divines them by comparing canoniacal and - * absolute paths. On non-unix systems this may cause false positives. - * Furthermore, any operating system on which the command - * ln -s link resource is not a valid command on the comandline - * will not be able to use action= "delete", action="single" or - * action="recreate", but action="record" should still work. Finally, the - * lack of support for symlinks in Java means that all links are recorded - * as links to the canonical resource name. Therefore - * the link: link --> subdir/dir/../foo.bar will be recorded - * as link=subdir/foo.bar and restored as + * absolute paths. On non-unix systems this may cause false positives. + * Furthermore, any operating system on which the command + * ln -s link resource is not a valid command on the comandline + * will not be able to use action= "delete", action="single" or + * action="recreate", but action="record" should still work. Finally, the + * lack of support for symlinks in Java means that all links are recorded + * as links to the canonical resource name. Therefore + * the link: link --> subdir/dir/../foo.bar will be recorded + * as link=subdir/foo.bar and restored as * link --> subdir/foo.bar * * @version $Revision$ - * @author Patrick G. Heck + * @author Patrick G. Heck */ public class Symlink extends Task { @@ -163,8 +163,7 @@ public class Symlink extends Task { /** Initialize the task. */ - public void init() throws BuildException - { + public void init() throws BuildException { super.init(); failonerror = true; // default behavior is to fail on an error overwrite = false; // devault behavior is to not overwrite @@ -187,48 +186,47 @@ public class Symlink extends Task { } catch (IOException ioe) { handleError(ioe.toString()); } - } else if (action.equals("recreate")) { + } else if (action.equals("recreate")) { Properties listOfLinks; Enumeration keys; - if (fileSets.size() == 0){ - handleError("File set identifying link file(s) " + - "required for action recreate"); + if (fileSets.size() == 0) { + handleError("File set identifying link file(s) " + + "required for action recreate"); return; } listOfLinks = loadLinks(fileSets); - + keys = listOfLinks.keys(); - - while(keys.hasMoreElements()) { + + while (keys.hasMoreElements()) { link = (String) keys.nextElement(); resource = listOfLinks.getProperty(link); doLink(resource, link); - } + } } else if (action.equals("record")) { Vector vectOfLinks; Hashtable byDir = new Hashtable(); Enumeration links, dirs; - - + if (fileSets.size() == 0) { - handleError("File set identifying links to " + - "record required"); + handleError("File set identifying links to " + + "record required"); return; } if (linkFileName == null) { - handleError("Name of file to record links in " + - "required"); + handleError("Name of file to record links in " + + "required"); return; } - + // fill our vector with file objects representing // links (canonical) vectOfLinks = findLinks(fileSets); - - // create a hashtable to group them by parent directory + + // create a hashtable to group them by parent directory links = vectOfLinks.elements(); while (links.hasMoreElements()) { File thisLink = (File) links.nextElement(); @@ -240,7 +238,7 @@ public class Symlink extends Task { ((Vector) byDir.get(parent)).addElement(thisLink); } } - + // write a Properties file in each directory dirs = byDir.keys(); while (dirs.hasMoreElements()) { @@ -249,7 +247,7 @@ public class Symlink extends Task { Properties linksToStore = new Properties(); Enumeration eachlink = linksInDir.elements(); File writeTo; - + // fill up a Properties object with link and resource // names while(eachlink.hasMoreElements()) { @@ -258,21 +256,19 @@ public class Symlink extends Task { linksToStore.put(alink.getName(), alink.getCanonicalPath()); } catch (IOException ioe) { - handleError("Couldn't get canonical "+ - "name of a parent link"); + handleError("Couldn't get canonical " + + "name of a parent link"); } } - + // Get a place to record what we are about to write - writeTo = new File(dir + File.separator + - linkFileName); + writeTo = new File(dir + File.separator + + linkFileName); writePropertyFile(linksToStore, writeTo, "Symlinks from " + writeTo.getParent()); - } - } else { handleError("Invalid action specified in symlink"); @@ -326,10 +322,10 @@ public class Symlink extends Task { public void setAction(String typ) { this.action = typ; } - + /** * The setter for the "link" attribute. Only used for action = single. - * + * * @param lnk The name for the link */ public void setLink(String lnk) { @@ -370,7 +366,7 @@ public class Symlink extends Task { /** * Deletes a symlink without deleteing the resource it points to. * - *

This is a convenience method that simply invokes + *

This is a convenience method that simply invokes * deleteSymlink(java.io.File) * * @param path A string containing the path of the symlink to delete @@ -380,8 +376,8 @@ public class Symlink extends Task { * @throws IOException If calls to File.rename * or File.delete fail. */ - - public static void deleteSymlink(String path) + + public static void deleteSymlink(String path) throws IOException, FileNotFoundException { File linkfil = new File(path); @@ -395,8 +391,8 @@ public class Symlink extends Task { * the resource that the symlink points to. If it is accidentally invoked * on a real file, the real file will not be harmed, but an exception * will be thrown when the deletion is attempted. This method works by - * getting the canonical path of the link, using the canonical path to - * rename the resource (breaking the link) and then deleting the link. + * getting the canonical path of the link, using the canonical path to + * rename the resource (breaking the link) and then deleting the link. * The resource is then returned to it's original name inside a finally * block to ensure that the resource is unharmed even in the event of * an exception. @@ -406,12 +402,12 @@ public class Symlink extends Task { * @throws FileNotFoundException When the path results in a * File that doesn't exist. * @throws IOException If calls to File.rename, - * File.delete or + * File.delete or * File.getCanonicalPath * fail. */ - public static void deleteSymlink(File linkfil) + public static void deleteSymlink(File linkfil) throws IOException, FileNotFoundException { if (!linkfil.exists()) { @@ -421,35 +417,35 @@ public class Symlink extends Task { // find the resource of the existing link String canstr = linkfil.getCanonicalPath(); File canfil = new File(canstr); - + // rename the resource, thus breaking the link String parentStr = canfil.getParent(); File parentDir = new File(parentStr); FileUtils fu = FileUtils.newFileUtils(); - File temp = fu.createTempFile("symlink",".tmp", parentDir); + File temp = fu.createTempFile("symlink", ".tmp", parentDir); try { try { fu.rename(canfil, temp); } catch (IOException e) { - throw new IOException("Couldn't rename resource when " + - "attempting to delete " + linkfil); + throw new IOException("Couldn't rename resource when " + + "attempting to delete " + linkfil); } - + // delete the (now) broken link - if(!linkfil.delete()) { - throw new IOException("Couldn't delete symlink: " + linkfil + - " (was it a real file? is this not a " + - "UNIX system?)"); + if (!linkfil.delete()) { + throw new IOException("Couldn't delete symlink: " + linkfil + + " (was it a real file? is this not a " + + "UNIX system?)"); } } finally { // return the resource to its original name. try { fu.rename(temp, canfil); } catch (IOException e) { - throw new IOException("Couldn't return resource " + temp + - " its original name: " + canstr + - "\n THE RESOURCE'S NAME ON DISK HAS " + - "BEEN CHANGED BY THIS ERROR!\n"); + throw new IOException("Couldn't return resource " + temp + + " to its original name: " + canstr + + "\n THE RESOURCE'S NAME ON DISK HAS " + + "BEEN CHANGED BY THIS ERROR!\n"); } } } @@ -462,7 +458,7 @@ public class Symlink extends Task { /** * Writes a properties file. * - * In jdk 1.2+ this method will use Properties.store + * In jdk 1.2+ this method will use Properties.store * and thus report exceptions that occur while writing the file. * In jdk 1.1 we are forced to use Properties.save * and therefore all exceptions are masked. This method was lifted @@ -476,8 +472,8 @@ public class Symlink extends Task { */ private void writePropertyFile(Properties properties, - File propertyfile, - String comment) + File propertyfile, + String comment) throws BuildException { BufferedOutputStream bos = null; @@ -506,7 +502,9 @@ public class Symlink extends Task { if (bos != null) { try { bos.close(); - } catch (IOException ioex) {} + } catch (IOException ioex) { + log("Failed to close output stream"); + } } } } @@ -514,7 +512,7 @@ public class Symlink extends Task { /** * Handles errors correctly based on the setting of failonerror. * - * @param msg The message to log, or include in the + * @param msg The message to log, or include in the * BuildException */ @@ -543,8 +541,8 @@ public class Symlink extends Task { return; } if (link == null) { - handleError("Must define the link " + - "name for symlink!"); + handleError("Must define the link " + + "name for symlink!"); return; } @@ -566,7 +564,7 @@ public class Symlink extends Task { handleError("Unable to overwrite preexisting link " + link); } - log(cmd[0]+" "+cmd[1]+" "+cmd[2]+" "+cmd[3]); + log(cmd[0] + " " + cmd[1] + " " + cmd[2] + " " + cmd[3]); Execute.runCommand(this,cmd); } @@ -588,10 +586,10 @@ public class Symlink extends Task { files = ds.getIncludedFiles(); dirs = ds.getIncludedDirectories(); - for (int i=0; i *

  • Compile a list of all matches
  • *
  • Convert matches to File objects
  • - *
  • Remove all non-symlinks using + *
  • Remove all non-symlinks using * FileUtils.isSymbolicLink
  • *
  • Convert all parent directories to the canonical form
  • - *
  • Add the remaining links from each file set to a + *
  • Add the remaining links from each file set to a * master list of links unless the link is already recorded * in the list
  • * * * @param fileSets The filesets specified by the user. - * @return A vector of File objects containing the + * @return A vector of File objects containing the * links (with canonical parent directories) */ @@ -626,7 +624,7 @@ public class Symlink extends Task { Vector result = new Vector(); // loop through the supplied file sets - FSLoop: for (int i=0; i This method is only invoked when the action atribute is set to + *

    This method is only invoked when the action atribute is set to * "multi". The filesets passed in are assumed to specify the names * of the property files with the link information and the * subdirectories in which to look for them. @@ -736,7 +736,7 @@ public class Symlink extends Task { *

  • Scan for properties files
  • *
  • load the contents of each properties file found.
  • * - * + * * @param fileSets The FileSets for this task * @return The links to be made. */ @@ -748,20 +748,20 @@ public class Symlink extends Task { String[] includedFiles; // loop through the supplied file sets - FSLoop: for (int i=0; i