Return-Path: Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 17845 invoked by uid 500); 3 Jul 2003 20:47:12 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 17829 invoked by uid 500); 3 Jul 2003 20:47:11 -0000 Received: (qmail 17823 invoked from network); 3 Jul 2003 20:47:11 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 3 Jul 2003 20:47:11 -0000 Received: (qmail 13495 invoked by uid 1652); 3 Jul 2003 20:47:10 -0000 Date: 3 Jul 2003 20:47:10 -0000 Message-ID: <20030703204710.13493.qmail@icarus.apache.org> From: antoine@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/unix Symlink.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N antoine 2003/07/03 13:47:10 Modified: src/main/org/apache/tools/ant/taskdefs/optional/unix Symlink.java Log: checkstyle fixes PR: 21316 Submitted by: Gus Heck (Gus dot Heck at Olin dot edu) Revision Changes Path 1.8 +112 -112 ant/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java Index: Symlink.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Symlink.java 25 Jun 2003 11:52:47 -0000 1.7 +++ Symlink.java 3 Jul 2003 20:47:10 -0000 1.8 @@ -97,11 +97,11 @@ *

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 @@ * <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 @@ /** 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 @@ } 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 @@ ((Vector) byDir.get(parent)).addElement(thisLink); } } - + // write a Properties file in each directory dirs = byDir.keys(); while (dirs.hasMoreElements()) { @@ -249,7 +247,7 @@ 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 @@ 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 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 @@ /** * 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 @@ * @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 @@ * 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 @@ * @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 @@ // 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 @@ /** * 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 @@ */ private void writePropertyFile(Properties properties, - File propertyfile, - String comment) + File propertyfile, + String comment) throws BuildException { BufferedOutputStream bos = null; @@ -506,7 +502,9 @@ if (bos != null) { try { bos.close(); - } catch (IOException ioex) {} + } catch (IOException ioex) { + log("Failed to close output stream"); + } } } } @@ -514,7 +512,7 @@ /** * 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ *

  • 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 @@ String[] includedFiles; // loop through the supplied file sets - FSLoop: for (int i=0; i