From a4d8a1d817bed0dd239f5a7d195fa5df45da4005 Mon Sep 17 00:00:00 2001 From: Stephane Bailliez Date: Tue, 8 Jan 2002 23:31:05 +0000 Subject: [PATCH] Code layout git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270639 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/optional/ANTLR.java | 35 +++--- .../tools/ant/taskdefs/optional/Cab.java | 118 ++++++++---------- 2 files changed, 67 insertions(+), 86 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java index 29dfa1d65..13234ad6a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java @@ -54,23 +54,20 @@ package org.apache.tools.ant.taskdefs.optional; -import java.io.File; import java.io.BufferedReader; +import java.io.File; import java.io.FileReader; import java.io.IOException; import java.net.URL; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.ExitException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.LogStreamHandler; -import org.apache.tools.ant.taskdefs.ExecuteJava; +import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Commandline; -import org.apache.tools.ant.types.Environment; /** * ANTLR task. @@ -165,21 +162,21 @@ public class ANTLR extends Task { if (u.startsWith("jar:file:")) { int pling = u.indexOf("!"); String jarName = u.substring(9, pling); - log("Implicitly adding "+jarName+" to classpath", - Project.MSG_DEBUG); + log("Implicitly adding " + jarName + " to classpath", + Project.MSG_DEBUG); createClasspath().setLocation(new File((new File(jarName)).getAbsolutePath())); } else if (u.startsWith("file:")) { int tail = u.indexOf(resource); String dirName = u.substring(5, tail); - log("Implicitly adding "+dirName+" to classpath", - Project.MSG_DEBUG); + log("Implicitly adding " + dirName + " to classpath", + Project.MSG_DEBUG); createClasspath().setLocation(new File((new File(dirName)).getAbsolutePath())); } else { - log("Don\'t know how to handle resource URL "+u, - Project.MSG_DEBUG); + log("Don\'t know how to handle resource URL " + u, + Project.MSG_DEBUG); } } else { - log("Couldn\'t find "+resource, Project.MSG_DEBUG); + log("Couldn\'t find " + resource, Project.MSG_DEBUG); } } @@ -194,14 +191,14 @@ public class ANTLR extends Task { log("Forking " + commandline.toString(), Project.MSG_VERBOSE); int err = run(commandline.getCommandline()); if (err == 1) { - throw new BuildException("ANTLR returned: "+err, location); + throw new BuildException("ANTLR returned: " + err, location); } } else { log("Skipped grammar file. Generated file is newer.", Project.MSG_VERBOSE); } } - private void validateAttributes() throws BuildException{ + private void validateAttributes() throws BuildException { if (target == null || !target.isFile()) { throw new BuildException("Invalid target: " + target); } @@ -223,7 +220,7 @@ public class ANTLR extends Task { String line; while ((line = in.readLine()) != null) { int extendsIndex = line.indexOf(" extends "); - if (line.startsWith("class ") && extendsIndex > -1) { + if (line.startsWith("class ") && extendsIndex > -1) { generatedFileName = line.substring(6, extendsIndex).trim(); break; } @@ -241,9 +238,9 @@ public class ANTLR extends Task { /** execute in a forked VM */ private int run(String[] command) throws BuildException { Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, - Project.MSG_WARN), null); + Project.MSG_WARN), null); exe.setAntRun(project); - if (workingdir != null){ + if (workingdir != null) { exe.setWorkingDirectory(workingdir); } exe.setCommandline(command); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java index 81e5a4633..b3ea425d5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -54,24 +54,24 @@ package org.apache.tools.ant.taskdefs.optional; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Vector; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.taskdefs.ExecTask; +import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.taskdefs.condition.Os; -import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.util.FileUtils; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.Vector; - /** * Create a CAB archive. @@ -87,21 +87,21 @@ public class Cab extends MatchingTask { private boolean doCompress = true; private boolean doVerbose = false; private String cmdOptions; - + protected String archiveType = "cab"; private FileUtils fileUtils = FileUtils.newFileUtils(); /** - * This is the name/location of where to + * This is the name/location of where to * create the .cab file. */ public void setCabfile(File cabFile) { this.cabFile = cabFile; } - + /** - * This is the base directory to look in for + * This is the base directory to look in for * things to cab. */ public void setBasedir(File baseDir) { @@ -157,9 +157,8 @@ public class Cab extends MatchingTask { * Create a new exec delegate. The delegate task is populated so that * it appears in the logs to be the same task as this one. */ - protected ExecTask createExec() throws BuildException - { - ExecTask exec = (ExecTask)project.createTask("exec"); + protected ExecTask createExec() throws BuildException { + ExecTask exec = (ExecTask) project.createTask("exec"); exec.setOwningTarget(this.getOwningTarget()); exec.setTaskName(this.getTaskName()); exec.setDescription(this.getDescription()); @@ -171,14 +170,12 @@ public class Cab extends MatchingTask { * Check to see if the target is up to date with respect to input files. * @return true if the cab file is newer than its dependents. */ - protected boolean isUpToDate(Vector files) - { + protected boolean isUpToDate(Vector files) { boolean upToDate = true; - for (int i=0; i - cabFile.lastModified()) { + if (new File(baseDir, file).lastModified() > + cabFile.lastModified()) { upToDate = false; } } @@ -188,24 +185,21 @@ public class Cab extends MatchingTask { /** * Create the cabarc command line to use. */ - protected Commandline createCommand(File listFile) - { + protected Commandline createCommand(File listFile) { Commandline command = new Commandline(); command.setExecutable("cabarc"); command.createArgument().setValue("-r"); command.createArgument().setValue("-p"); - if (!doCompress) - { + if (!doCompress) { command.createArgument().setValue("-m"); command.createArgument().setValue("none"); } - if (cmdOptions != null) - { + if (cmdOptions != null) { command.createArgument().setLine(cmdOptions); } - + command.createArgument().setValue("n"); command.createArgument().setFile(cabFile); command.createArgument().setValue("@" + listFile.getAbsolutePath()); @@ -218,14 +212,12 @@ public class Cab extends MatchingTask { * to be included in the cab, one file per line. */ protected File createListFile(Vector files) - throws IOException - { + throws IOException { File listFile = fileUtils.createTempFile("ant", "", null); - + PrintWriter writer = new PrintWriter(new FileOutputStream(listFile)); - for (int i = 0; i < files.size(); i++) - { + for (int i = 0; i < files.size(); i++) { writer.println(files.elementAt(i).toString()); } writer.close(); @@ -236,12 +228,10 @@ public class Cab extends MatchingTask { /** * Append all files found by a directory scanner to a vector. */ - protected void appendFiles(Vector files, DirectoryScanner ds) - { + protected void appendFiles(Vector files, DirectoryScanner ds) { String[] dsfiles = ds.getIncludedFiles(); - for (int i = 0; i < dsfiles.length; i++) - { + for (int i = 0; i < dsfiles.length; i++) { files.addElement(dsfiles[i]); } } @@ -251,23 +241,17 @@ public class Cab extends MatchingTask { * are gathered from filesets if any have been added, otherwise from the * traditional include parameters. */ - protected Vector getFileList() throws BuildException - { + protected Vector getFileList() throws BuildException { Vector files = new Vector(); - if (filesets.size() == 0) - { + if (filesets.size() == 0) { // get files from old methods - includes and nested include appendFiles(files, super.getDirectoryScanner(baseDir)); - } - else - { + } else { // get files from filesets - for (int i = 0; i < filesets.size(); i++) - { + for (int i = 0; i < filesets.size(); i++) { FileSet fs = (FileSet) filesets.elementAt(i); - if (fs != null) - { + if (fs != null) { appendFiles(files, fs.getDirectoryScanner(project)); } } @@ -281,26 +265,26 @@ public class Cab extends MatchingTask { checkConfiguration(); Vector files = getFileList(); - + // quick exit if the target is up to date if (isUpToDate(files)) { - return; + return; } - log("Building "+ archiveType +": "+ cabFile.getAbsolutePath()); + log("Building " + archiveType + ": " + cabFile.getAbsolutePath()); if (!Os.isFamily("windows")) { log("Using listcab/libcabinet", Project.MSG_VERBOSE); - + StringBuffer sb = new StringBuffer(); - + Enumeration fileEnum = files.elements(); - + while (fileEnum.hasMoreElements()) { sb.append(fileEnum.nextElement()).append("\n"); } sb.append("\n").append(cabFile.getAbsolutePath()).append("\n"); - + try { Process p = Runtime.getRuntime().exec("listcab"); OutputStream out = p.getOutputStream(); @@ -316,23 +300,23 @@ public class Cab extends MatchingTask { File listFile = createListFile(files); ExecTask exec = createExec(); File outFile = null; - + // die if cabarc fails exec.setFailonerror(true); exec.setDir(baseDir); - + if (!doVerbose) { outFile = fileUtils.createTempFile("ant", "", null); exec.setOutput(outFile); } - + exec.setCommand(createCommand(listFile)); exec.execute(); - + if (outFile != null) { outFile.delete(); } - + listFile.delete(); } catch (IOException ioe) { String msg = "Problem creating " + cabFile + " " + ioe.getMessage();