From 6154080061f869b4e425d608da3bd61fad967564 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Mon, 15 Apr 2002 12:11:52 +0000 Subject: [PATCH] More coding standard fixes git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272433 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/helper/ProjectHelperImpl.java | 20 +- .../tools/ant/taskdefs/BuildNumber.java | 169 ++-- .../org/apache/tools/ant/taskdefs/Concat.java | 20 +- .../tools/ant/taskdefs/LoadProperties.java | 2 +- .../apache/tools/ant/taskdefs/Manifest.java | 42 +- .../apache/tools/ant/taskdefs/Parallel.java | 6 +- .../org/apache/tools/ant/taskdefs/Patch.java | 6 +- .../tools/ant/taskdefs/PathConvert.java | 286 +++---- .../ant/taskdefs/cvslib/ChangeLogParser.java | 2 +- .../tools/ant/taskdefs/cvslib/CvsTagDiff.java | 10 +- .../ant/taskdefs/optional/TraXLiaison.java | 26 +- .../taskdefs/optional/XMLValidateTask.java | 66 +- .../taskdefs/optional/jlink/JlinkTask.java | 10 +- .../ant/taskdefs/optional/jlink/jlink.java | 380 ++++----- .../tools/ant/taskdefs/optional/jsp/JspC.java | 86 +-- .../ant/taskdefs/optional/jsp/WLJspc.java | 62 +- .../compilers/DefaultJspCompilerAdapter.java | 12 +- .../optional/jsp/compilers/JasperC.java | 26 +- .../jsp/compilers/JspCompilerAdapter.java | 2 +- .../compilers/JspCompilerAdapterFactory.java | 18 +- .../optional/junit/AggregateTransformer.java | 2 +- .../taskdefs/optional/junit/BatchTest.java | 12 +- .../ant/taskdefs/optional/junit/DOMUtil.java | 18 +- .../taskdefs/optional/junit/Enumerations.java | 4 +- .../optional/junit/FormatterElement.java | 5 +- .../optional/junit/JUnitResultFormatter.java | 8 +- .../taskdefs/optional/junit/JUnitTask.java | 53 +- .../taskdefs/optional/junit/JUnitTest.java | 28 +- .../optional/junit/JUnitTestRunner.java | 38 +- .../junit/PlainJUnitResultFormatter.java | 14 +- .../junit/SummaryJUnitResultFormatter.java | 14 +- .../junit/XMLJUnitResultFormatter.java | 17 +- .../optional/junit/XMLResultAggregator.java | 17 +- .../optional/junit/Xalan1Executor.java | 2 +- .../taskdefs/optional/metamata/MParse.java | 14 +- .../tools/ant/taskdefs/optional/net/FTP.java | 697 ++++++++--------- .../ant/taskdefs/optional/net/MimeMail.java | 3 +- .../ant/taskdefs/optional/net/TelnetTask.java | 26 +- .../taskdefs/optional/perforce/P4Submit.java | 4 +- .../ant/taskdefs/optional/pvcs/Pvcs.java | 141 ++-- .../optional/scm/AntStarTeamCheckOut.java | 724 ++++++++---------- .../optional/sound/AntSoundPlayer.java | 5 +- .../taskdefs/optional/sound/SoundTask.java | 14 +- .../optional/splash/SplashScreen.java | 18 +- .../taskdefs/optional/splash/SplashTask.java | 24 +- .../optional/starteam/StarTeamTask.java | 2 +- .../ant/taskdefs/optional/vss/MSVSS.java | 14 +- .../ant/taskdefs/optional/vss/MSVSSADD.java | 20 +- .../taskdefs/optional/vss/MSVSSCHECKIN.java | 28 +- .../taskdefs/optional/vss/MSVSSCHECKOUT.java | 24 +- .../ant/taskdefs/optional/vss/MSVSSCP.java | 12 +- .../taskdefs/optional/vss/MSVSSCREATE.java | 6 +- .../ant/taskdefs/optional/vss/MSVSSGET.java | 29 +- .../taskdefs/optional/vss/MSVSSHISTORY.java | 36 +- .../ant/taskdefs/optional/vss/MSVSSLABEL.java | 25 +- .../ant/taskdefs/rmic/DefaultRmicAdapter.java | 37 +- .../tools/ant/taskdefs/rmic/KaffeRmic.java | 4 +- .../tools/ant/taskdefs/rmic/RmicAdapter.java | 2 +- .../ant/taskdefs/rmic/RmicAdapterFactory.java | 24 +- .../tools/ant/taskdefs/rmic/SunRmic.java | 6 +- .../tools/ant/taskdefs/rmic/WLRmic.java | 2 +- .../tools/ant/types/AbstractFileSet.java | 12 +- .../apache/tools/ant/types/Commandline.java | 32 +- .../tools/ant/types/CommandlineJava.java | 10 +- .../org/apache/tools/ant/types/DataType.java | 18 +- .../apache/tools/ant/types/Environment.java | 4 +- .../org/apache/tools/ant/types/FileList.java | 2 +- .../org/apache/tools/ant/types/FilterSet.java | 36 +- .../tools/ant/types/FilterSetCollection.java | 4 +- .../org/apache/tools/ant/types/Mapper.java | 4 +- src/main/org/apache/tools/ant/types/Path.java | 39 +- .../apache/tools/ant/types/PatternSet.java | 22 +- .../org/apache/tools/ant/types/Reference.java | 2 +- .../tools/ant/types/RegularExpression.java | 3 +- .../apache/tools/ant/types/XMLCatalog.java | 4 +- .../apache/tools/ant/types/ZipFileSet.java | 2 +- .../types/optional/depend/ClassfileSet.java | 6 +- .../types/optional/depend/DependScanner.java | 8 +- .../tools/ant/util/DOMElementWriter.java | 19 +- .../org/apache/tools/ant/util/DateUtils.java | 2 +- .../org/apache/tools/ant/util/FileUtils.java | 40 +- .../tools/ant/util/GlobPatternMapper.java | 6 +- .../apache/tools/ant/util/LoaderUtils.java | 2 +- .../tools/ant/util/RegexpPatternMapper.java | 4 +- .../tools/ant/util/SourceFileScanner.java | 22 +- .../apache/tools/ant/util/StringUtils.java | 16 +- .../util/depend/bcel/AncestorAnalyzer.java | 16 +- .../ant/util/depend/bcel/FullAnalyzer.java | 19 +- .../ant/util/regexp/JakartaOroMatcher.java | 2 +- .../ant/util/regexp/JakartaOroRegexp.java | 2 +- .../ant/util/regexp/JakartaRegexpMatcher.java | 2 +- .../ant/util/regexp/JakartaRegexpRegexp.java | 2 +- .../ant/util/regexp/Jdk14RegexpMatcher.java | 2 +- .../ant/util/regexp/Jdk14RegexpRegexp.java | 2 +- .../apache/tools/bzip2/CBZip2InputStream.java | 122 +-- .../tools/bzip2/CBZip2OutputStream.java | 226 +++--- src/main/org/apache/tools/bzip2/CRC.java | 4 +- src/main/org/apache/tools/tar/TarEntry.java | 6 +- .../org/apache/tools/zip/AsiExtraField.java | 18 +- .../org/apache/tools/zip/ExtraFieldUtils.java | 42 +- .../tools/zip/UnrecognizedExtraField.java | 10 +- src/main/org/apache/tools/zip/ZipEntry.java | 8 +- src/main/org/apache/tools/zip/ZipLong.java | 8 +- .../org/apache/tools/zip/ZipOutputStream.java | 12 +- src/main/org/apache/tools/zip/ZipShort.java | 4 +- 105 files changed, 2112 insertions(+), 2138 deletions(-) diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java index eceed8d06..5bba57089 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java @@ -128,9 +128,9 @@ public class ProjectHelperImpl extends ProjectHelper { */ public void parse(Project project, Object source) throws BuildException { if (!(source instanceof File)) { - throw new BuildException( "Only File source supported by default plugin" ); + throw new BuildException("Only File source supported by default plugin"); } - File buildFile = (File)source; + File buildFile = (File) source; FileInputStream inputStream = null; InputSource inputSource = null; @@ -193,7 +193,7 @@ public class ProjectHelperImpl extends ProjectHelper { exc); } catch (IOException exc) { throw new BuildException("Error reading project file: " - +exc.getMessage(), exc); + + exc.getMessage(), exc); } finally { if (inputStream != null) { try { @@ -321,7 +321,7 @@ public class ProjectHelperImpl extends ProjectHelper { static class RootHandler extends HandlerBase { ProjectHelperImpl helperImpl; - public RootHandler( ProjectHelperImpl helperImpl ) { + public RootHandler(ProjectHelperImpl helperImpl) { this.helperImpl = helperImpl; } @@ -876,9 +876,11 @@ public class ProjectHelperImpl extends ProjectHelper { public void startElement(String name, AttributeList attrs) throws SAXParseException { if (task instanceof TaskContainer) { // task can contain other tasks - no other nested elements possible - new TaskHandler(helperImpl, this, (TaskContainer)task, wrapper, target).init(name, attrs); + new TaskHandler(helperImpl, this, (TaskContainer) task, + wrapper, target).init(name, attrs); } else { - new NestedElementHandler(helperImpl, this, task, wrapper, target).init(name, attrs); + new NestedElementHandler(helperImpl, this, task, + wrapper, target).init(name, attrs); } } } @@ -1027,9 +1029,11 @@ public class ProjectHelperImpl extends ProjectHelper { if (child instanceof TaskContainer) { // taskcontainer nested element can contain other tasks - no other // nested elements possible - new TaskHandler(helperImpl, this, (TaskContainer)child, childWrapper, target).init(name, attrs); + new TaskHandler(helperImpl, this, (TaskContainer) child, + childWrapper, target).init(name, attrs); } else { - new NestedElementHandler(helperImpl, this, child, childWrapper, target).init(name, attrs); + new NestedElementHandler(helperImpl, this, child, + childWrapper, target).init(name, attrs); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java b/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java index b3f6b309d..e05fc4ded 100644 --- a/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java +++ b/src/main/org/apache/tools/ant/taskdefs/BuildNumber.java @@ -63,12 +63,11 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.util.FileUtils; /** - * This is a basic task that can be used to track build numbers. - * - * It will first attempt to read a build number from a file, then - * set the property "build.number" to the value that was read in - * (or 0 if no such value). Then it will increment the build number - * by one and write it back out into the file. + * This is a basic task that can be used to track build numbers. It will first + * attempt to read a build number from a file, then set the property + * "build.number" to the value that was read in (or 0 if no such value). Then + * it will increment the build number by one and write it back out into the + * file. * * @author Peter Donald * @version $Revision$ $Date$ @@ -76,85 +75,76 @@ import org.apache.tools.ant.util.FileUtils; * @ant.task name="buildnumber" */ public class BuildNumber - extends Task -{ + extends Task { /** * The name of the property in which the build number is stored. */ private static final String DEFAULT_PROPERTY_NAME = "build.number"; - /** - * The default filename to use if no file specified. - */ + /** The default filename to use if no file specified. */ private static final String DEFAULT_FILENAME = DEFAULT_PROPERTY_NAME; - /** - * The File in which the build number is stored. - */ + /** The File in which the build number is stored. */ private File m_file; + /** - * Specify the file in which the build numberis stored. - * Defaults to "build.number" if not specified. + * Specify the file in which the build numberis stored. Defaults to + * "build.number" if not specified. * * @param file the file in which build number is stored. */ - public void setFile( final File file ) - { + public void setFile(final File file) { m_file = file; } + /** * Run task. * * @exception BuildException if an error occurs */ public void execute() - throws BuildException - { - File savedFile = m_file; // may be altered in validate + throws BuildException { + File savedFile = m_file;// may be altered in validate + validate(); final Properties properties = loadProperties(); - final int buildNumber = getBuildNumber( properties ); + final int buildNumber = getBuildNumber(properties); - properties.put( DEFAULT_PROPERTY_NAME, - String.valueOf( buildNumber + 1 ) ); + properties.put(DEFAULT_PROPERTY_NAME, + String.valueOf(buildNumber + 1)); // Write the properties file back out FileOutputStream output = null; - try - { - output = new FileOutputStream( m_file ); + + try { + output = new FileOutputStream(m_file); final String header = "Build Number for ANT. Do not edit!"; - properties.save( output, header ); - } - catch( final IOException ioe ) - { + + properties.save(output, header); + } catch (final IOException ioe) { final String message = "Error while writing " + m_file; - throw new BuildException( message, ioe ); - } - finally - { - if( null != output ) - { - try - { + + throw new BuildException(message, ioe); + } finally { + if (null != output) { + try { output.close(); - } - catch( final IOException ioe ) - { + } catch (final IOException ioe) { } } m_file = savedFile; } //Finally set the property - getProject().setNewProperty( DEFAULT_PROPERTY_NAME, - String.valueOf( buildNumber ) ); + getProject().setNewProperty(DEFAULT_PROPERTY_NAME, + String.valueOf(buildNumber)); } + /** * Utility method to retrieve build number from properties object. * @@ -162,25 +152,23 @@ public class BuildNumber * @return the build number or if no number in properties object * @throws BuildException if build.number property is not an integer */ - private int getBuildNumber( final Properties properties ) - throws BuildException - { + private int getBuildNumber(final Properties properties) + throws BuildException { final String buildNumber = - properties.getProperty( DEFAULT_PROPERTY_NAME, "0" ).trim(); + properties.getProperty(DEFAULT_PROPERTY_NAME, "0").trim(); // Try parsing the line into an integer. - try - { - return Integer.parseInt( buildNumber ); - } - catch( final NumberFormatException nfe ) - { - final String message = + try { + return Integer.parseInt(buildNumber); + } catch (final NumberFormatException nfe) { + final String message = m_file + " contains a non integer build number: " + buildNumber; - throw new BuildException( message , nfe ); + + throw new BuildException(message, nfe); } } + /** * Utility method to load properties from file. * @@ -188,72 +176,61 @@ public class BuildNumber * @throws BuildException */ private Properties loadProperties() - throws BuildException - { + throws BuildException { FileInputStream input = null; - try - { + + try { final Properties properties = new Properties(); - input = new FileInputStream( m_file ); - properties.load( input ); + + input = new FileInputStream(m_file); + properties.load(input); return properties; - } - catch( final IOException ioe ) - { - throw new BuildException( ioe ); - } - finally - { - if( null != input ) - { - try - { + } catch (final IOException ioe) { + throw new BuildException(ioe); + } finally { + if (null != input) { + try { input.close(); - } - catch( final IOException ioe ) - { + } catch (final IOException ioe) { } } } } + /** * Validate that the task parameters are valid. * * @throws BuildException if parameters are invalid */ private void validate() - throws BuildException - { - if( null == m_file ) - { - m_file = getProject().resolveFile( DEFAULT_FILENAME ); + throws BuildException { + if (null == m_file) { + m_file = getProject().resolveFile(DEFAULT_FILENAME); } - if( !m_file.exists() ) - { - try - { + if (!m_file.exists()) { + try { FileUtils.newFileUtils().createNewFile(m_file); - } - catch( final IOException ioe ) - { - final String message = + } catch (final IOException ioe) { + final String message = m_file + " doesn't exist and new file can't be created."; - throw new BuildException( message, ioe ); + + throw new BuildException(message, ioe); } } - if( !m_file.canRead() ) - { + if (!m_file.canRead()) { final String message = "Unable to read from " + m_file + "."; - throw new BuildException( message ); + + throw new BuildException(message); } - if( !m_file.canWrite() ) - { + if (!m_file.canWrite()) { final String message = "Unable to write to " + m_file + "."; - throw new BuildException( message ); + + throw new BuildException(message); } } } + diff --git a/src/main/org/apache/tools/ant/taskdefs/Concat.java b/src/main/org/apache/tools/ant/taskdefs/Concat.java index f104e2d18..77c0689f2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Concat.java +++ b/src/main/org/apache/tools/ant/taskdefs/Concat.java @@ -227,7 +227,7 @@ public class Concat extends Task { try { // Iterate the FileSet collection, concatenating each file as // it is encountered. - for (Enumeration e = fileSets.elements(); e.hasMoreElements(); ) { + for (Enumeration e = fileSets.elements(); e.hasMoreElements();) { // Root directory for files. File fileSetBase = null; @@ -392,17 +392,14 @@ public class Concat extends Task { // Log using WARN so it displays in 'quiet' mode. out = new PrintWriter( new OutputStreamWriter( - new LogOutputStream(this, Project.MSG_WARN) - ) - ); + new LogOutputStream(this, Project.MSG_WARN))); } else { out = new PrintWriter( new OutputStreamWriter( new FileOutputStream(destinationFile .getAbsolutePath(), append), - encoding) - ); + encoding)); // This flag should only be recognized for the first // file. In the context of a single 'cat', we always @@ -412,11 +409,8 @@ public class Concat extends Task { for (int i = 0; i < len; i++) { in = new BufferedReader( - new InputStreamReader( - new FileInputStream(input[i]), - encoding - ) - ); + new InputStreamReader(new FileInputStream(input[i]), + encoding)); String line; while ((line = in.readLine()) != null) { @@ -480,9 +474,7 @@ public class Concat extends Task { // Reads the text, line by line. BufferedReader reader = null; try { - reader = new BufferedReader( - new StringReader(text) - ); + reader = new BufferedReader(new StringReader(text)); String line; while ((line = reader.readLine()) != null) { diff --git a/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java b/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java index b4ec09775..08f5e55be 100644 --- a/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java +++ b/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java @@ -122,7 +122,7 @@ public final class LoadProperties extends Task { try { final long len = srcFile.length(); - final int size=(int) len; + final int size = (int) len; //open up the file fis = new FileInputStream(srcFile); diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java index 59fbc7805..394a7070b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java +++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java @@ -184,7 +184,7 @@ public class Manifest extends Task { return false; } - Attribute rhsAttribute = (Attribute)rhs; + Attribute rhsAttribute = (Attribute) rhs; return (name != null && rhsAttribute.name != null && getKey().equals(rhsAttribute.getKey()) && values != null && @@ -266,7 +266,7 @@ public class Manifest extends Task { String fullValue = ""; for (Enumeration e = getValues(); e.hasMoreElements();) { - String value = (String)e.nextElement(); + String value = (String) e.nextElement(); fullValue += value + " "; } return fullValue.trim(); @@ -301,7 +301,7 @@ public class Manifest extends Task { * @param line the continuation line. */ public void addContinuation(String line) { - String currentValue = (String)values.elementAt(currentIndex); + String currentValue = (String) values.elementAt(currentIndex); setValue(currentValue + line.substring(1)); } @@ -314,7 +314,7 @@ public class Manifest extends Task { */ public void write(PrintWriter writer) throws IOException { for (Enumeration e = getValues(); e.hasMoreElements();) { - writeValue(writer, (String)e.nextElement()); + writeValue(writer, (String) e.nextElement()); } } @@ -451,14 +451,14 @@ public class Manifest extends Task { Enumeration e = section.getAttributeKeys(); while (e.hasMoreElements()) { - String attributeName = (String)e.nextElement(); + String attributeName = (String) e.nextElement(); Attribute attribute = section.getAttribute(attributeName); if (attributeName.equals(ATTRIBUTE_CLASSPATH) && attributes.containsKey(attributeName)) { Attribute ourClassPath = getAttribute(attributeName); Enumeration cpe = attribute.getValues(); while (cpe.hasMoreElements()) { - String value = (String)cpe.nextElement(); + String value = (String) cpe.nextElement(); ourClassPath.addValue(value); } } else { @@ -488,7 +488,7 @@ public class Manifest extends Task { } Enumeration e = getAttributeKeys(); while (e.hasMoreElements()) { - String key = (String)e.nextElement(); + String key = (String) e.nextElement(); Attribute attribute = getAttribute(key); attribute.write(writer); } @@ -504,7 +504,7 @@ public class Manifest extends Task { * instances. */ public Attribute getAttribute(String attributeName) { - return (Attribute)attributes.get(attributeName.toLowerCase()); + return (Attribute) attributes.get(attributeName.toLowerCase()); } /** @@ -594,14 +594,14 @@ public class Manifest extends Task { String attributeKey = attribute.getKey(); if (attributeKey.equals(ATTRIBUTE_CLASSPATH)) { Attribute classpathAttribute = - (Attribute)attributes.get(attributeKey); + (Attribute) attributes.get(attributeKey); if (classpathAttribute == null) { storeAttribute(attribute); } else { Enumeration e = attribute.getValues(); while (e.hasMoreElements()) { - String value = (String)e.nextElement(); + String value = (String) e.nextElement(); classpathAttribute.addValue(value); } } @@ -649,13 +649,13 @@ public class Manifest extends Task { return false; } - Section rhsSection = (Section)rhs; + Section rhsSection = (Section) rhs; if (attributes.size() != rhsSection.attributes.size()) { return false; } for (Enumeration e = attributes.keys(); e.hasMoreElements();) { - String attributeName = (String)e.nextElement(); + String attributeName = (String) e.nextElement(); Object attributeValue = attributes.get(attributeName); Object rhsAttributeValue = rhsSection.attributes.get(attributeName); @@ -843,10 +843,10 @@ public class Manifest extends Task { Enumeration e = other.getSectionNames(); while (e.hasMoreElements()) { - String sectionName = (String)e.nextElement(); - Section ourSection = (Section)sections.get(sectionName); + String sectionName = (String) e.nextElement(); + Section ourSection = (Section) sections.get(sectionName); Section otherSection - = (Section)other.sections.get(sectionName); + = (Section) other.sections.get(sectionName); if (ourSection == null) { if (otherSection != null) { addConfiguredSection(otherSection); @@ -889,7 +889,7 @@ public class Manifest extends Task { Enumeration e = sectionIndex.elements(); while (e.hasMoreElements()) { - String sectionName = (String)e.nextElement(); + String sectionName = (String) e.nextElement(); Section section = getSection(sectionName); section.write(writer); } @@ -927,7 +927,7 @@ public class Manifest extends Task { // create a vector and add in the warnings for all the sections Enumeration e = sections.elements(); while (e.hasMoreElements()) { - Section section = (Section)e.nextElement(); + Section section = (Section) e.nextElement(); Enumeration e2 = section.getWarnings(); while (e2.hasMoreElements()) { warnings.addElement(e2.nextElement()); @@ -945,7 +945,7 @@ public class Manifest extends Task { return false; } - Manifest rhsManifest = (Manifest)rhs; + Manifest rhsManifest = (Manifest) rhs; if (manifestVersion == null) { if (rhsManifest.manifestVersion != null) { return false; @@ -963,9 +963,9 @@ public class Manifest extends Task { Enumeration e = sections.elements(); while (e.hasMoreElements()) { - Section section = (Section)e.nextElement(); + Section section = (Section) e.nextElement(); Section rhsSection - = (Section)rhsManifest.sections.get(section.getName()); + = (Section) rhsManifest.sections.get(section.getName()); if (!section.equals(rhsSection)) { return false; } @@ -1018,7 +1018,7 @@ public class Manifest extends Task { * does not exist in the manifest */ public Section getSection(String name) { - return (Section)sections.get(name); + return (Section) sections.get(name); } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/Parallel.java b/src/main/org/apache/tools/ant/taskdefs/Parallel.java index e7baca1f7..366f34976 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Parallel.java +++ b/src/main/org/apache/tools/ant/taskdefs/Parallel.java @@ -99,7 +99,7 @@ public class Parallel extends Task int threadNumber = 0; for (Enumeration e = nestedTasks.elements(); e.hasMoreElements(); threadNumber++) { - Task nestedTask = (Task)e.nextElement(); + Task nestedTask = (Task) e.nextElement(); threads[threadNumber] = new TaskThread(threadNumber, nestedTask); } @@ -132,7 +132,7 @@ public class Parallel extends Task } if (t instanceof BuildException && firstLocation == Location.UNKNOWN_LOCATION) { - firstLocation = ((BuildException)t).getLocation(); + firstLocation = ((BuildException) t).getLocation(); } exceptionMessage.append(StringUtils.LINE_SEP); exceptionMessage.append(t.getMessage()); @@ -141,7 +141,7 @@ public class Parallel extends Task if (numExceptions == 1) { if (firstException instanceof BuildException) { - throw (BuildException)firstException; + throw (BuildException) firstException; } else { throw new BuildException(firstException); diff --git a/src/main/org/apache/tools/ant/taskdefs/Patch.java b/src/main/org/apache/tools/ant/taskdefs/Patch.java index 02e0e1ecf..c54e8fb95 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Patch.java +++ b/src/main/org/apache/tools/ant/taskdefs/Patch.java @@ -88,7 +88,7 @@ public class Patch extends Task { */ public void setPatchfile(File file) { if (!file.exists()) { - throw new BuildException("patchfile "+file+" doesn\'t exist", + throw new BuildException("patchfile " + file + " doesn\'t exist", location); } cmd.createArgument().setValue("-i"); @@ -124,7 +124,7 @@ public class Patch extends Task { if (num < 0) { throw new BuildException("strip has to be >= 0", location); } - cmd.createArgument().setValue("-p"+num); + cmd.createArgument().setValue("-p" + num); } /** @@ -151,7 +151,7 @@ public class Patch extends Task { location); } - Commandline toExecute = (Commandline)cmd.clone(); + Commandline toExecute = (Commandline) cmd.clone(); toExecute.setExecutable("patch"); if (originalFile != null) { diff --git a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java index 86103b662..441a07173 100644 --- a/src/main/org/apache/tools/ant/taskdefs/PathConvert.java +++ b/src/main/org/apache/tools/ant/taskdefs/PathConvert.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001-2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -51,7 +51,6 @@ * information on the Apache Software Foundation, please see * . */ - package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; @@ -70,53 +69,66 @@ import java.util.Vector; import java.io.File; /** - * This task converts path and classpath information to a specific - * target OS format. The resulting formatted path is placed into a - * specified property. - * - * @author Larry Streepy streepy@healthlanguage.com + * This task converts path and classpath information to a specific target OS + * format. The resulting formatted path is placed into a specified property. * + * @author Larry Streepy + * streepy@healthlanguage.com * @since Ant 1.4 - * * @ant.task category="utility" */ public class PathConvert extends Task { + // Members + private Path path = null;// Path to be converted + private Reference refid = null;// Reference to path/fileset to + // convert + private String targetOS = null;// The target OS type + private boolean targetWindows = false;// Set when targetOS is set + private boolean onWindows = false;// Set if we're running on windows + private String property = null;// The property to receive the + //results + private Vector prefixMap = new Vector();// Path prefix map + private String pathSep = null;// User override on path sep char + private String dirSep = null;// User override on directory sep + // char + public PathConvert() { onWindows = Os.isFamily("dos"); } + /** - * Helper class, holds the nested values. Elements will - * look like this: <map from="d:" to="/foo"/> - *

- * When running on windows, the prefix comparison will be case insensitive. + * Helper class, holds the nested values. Elements will look like + * this: <map from="d:" to="/foo"/>

+ * + * When running on windows, the prefix comparison will be case + * insensitive. */ public class MapEntry { - /** - * Set the "from" attribute of the map entry - */ - public void setFrom( String from ) { + /** Set the "from" attribute of the map entry */ + public void setFrom(String from) { this.from = from; } - /** - * Set the "to" attribute of the map entry - */ - public void setTo( String to ) { + + /** Set the "to" attribute of the map entry */ + public void setTo(String to) { this.to = to; } + /** * Apply this map entry to a given path element + * * @param elem Path element to process * @return String Updated path element after mapping */ - public String apply( String elem ) { - if( from == null || to == null ) { - throw new BuildException( "Both 'from' and 'to' must be set " - + "in a map entry" ); + public String apply(String elem) { + if (from == null || to == null) { + throw new BuildException("Both 'from' and 'to' must be set " + + "in a map entry"); } // If we're on windows, then do the comparison ignoring case @@ -126,13 +138,13 @@ public class PathConvert extends Task { // If the element starts with the configured prefix, then // convert the prefix to the configured 'to' value. - if( cmpElem.startsWith( cmpFrom ) ) { + if (cmpElem.startsWith(cmpFrom)) { int len = from.length(); - if( len >= elem.length() ) { + if (len >= elem.length()) { elem = to; } else { - elem = to + elem.substring( len ); + elem = to + elem.substring(len); } } @@ -144,54 +156,58 @@ public class PathConvert extends Task { private String to = null; } + public static class TargetOs extends EnumeratedAttribute { public String[] getValues() { - return new String[] {"windows", "unix", "netware", "os/2"}; + return new String[]{"windows", "unix", "netware", "os/2"}; } } - /** - * Create a nested PATH element - */ + + /** Create a nested PATH element */ public Path createPath() { - if( isReference() ) { + if (isReference()) { throw noChildrenAllowed(); } - if( path == null ) { + if (path == null) { path = new Path(getProject()); } return path.createPath(); } - /** - * Create a nested MAP element - */ + + /** Create a nested MAP element */ public MapEntry createMap() { MapEntry entry = new MapEntry(); - prefixMap.addElement( entry ); + + prefixMap.addElement(entry); return entry; } /** * Set the value of the targetos attribute + * * @deprecated use the method taking a TargetOs argument instead * @see #setTargetos(TargetOs) */ - public void setTargetos( String target ) { + public void setTargetos(String target) { TargetOs to = new TargetOs(); + to.setValue(target); setTargetos(to); } + /** * Set the value of the targetos attribute + * * @since Ant 1.5 */ - public void setTargetos( TargetOs target ) { + public void setTargetos(TargetOs target) { targetOS = target.getValue(); @@ -205,134 +221,135 @@ public class PathConvert extends Task { targetWindows = !targetOS.equals("unix"); } + /** - * Set the value of the property attribute - this is the property - * into which our converted path will be placed. + * Set the value of the property attribute - this is the property into + * which our converted path will be placed. */ - public void setProperty( String p ) { + public void setProperty(String p) { property = p; } + /** * Adds a reference to a Path, FileSet, DirSet, or FileList defined * elsewhere. */ public void setRefid(Reference r) { - if( path != null ) { + if (path != null) { throw noChildrenAllowed(); } refid = r; } - /** - * Override the default path separator string for the target os - */ - public void setPathSep( String sep ) { + + /** Override the default path separator string for the target os */ + public void setPathSep(String sep) { pathSep = sep; } + /** * Override the default directory separator string for the target os */ - public void setDirSep( String sep ) { + public void setDirSep(String sep) { dirSep = sep; } - /** - * Has the refid attribute of this element been set? - */ + + /** Has the refid attribute of this element been set? */ public boolean isReference() { return refid != null; } - /** - * Do the execution. - */ + + /** Do the execution. */ public void execute() throws BuildException { Path savedPath = path; - String savedPathSep = pathSep; // may be altered in validateSetup - String savedDirSep = dirSep; // may be altered in validateSetup + String savedPathSep = pathSep;// may be altered in validateSetup + String savedDirSep = dirSep;// may be altered in validateSetup try { // If we are a reference, create a Path from the reference - if( isReference() ) { + if (isReference()) { path = new Path(getProject()).createPath(); - + Object obj = refid.getReferencedObject(getProject()); - - if( obj instanceof Path ) { + + if (obj instanceof Path) { path.setRefid(refid); - } else if( obj instanceof FileSet ) { - FileSet fs = (FileSet)obj; - path.addFileset( fs ); - } else if( obj instanceof DirSet ) { - DirSet ds = (DirSet)obj; - path.addDirset( ds ); - } else if( obj instanceof FileList ) { - FileList fl = (FileList)obj; - path.addFilelist( fl ); - + } else if (obj instanceof FileSet) { + FileSet fs = (FileSet) obj; + + path.addFileset(fs); + } else if (obj instanceof DirSet) { + DirSet ds = (DirSet) obj; + + path.addDirset(ds); + } else if (obj instanceof FileList) { + FileList fl = (FileList) obj; + + path.addFilelist(fl); + } else { - throw new BuildException( "'refid' does not refer to a " - + "path, fileset, dirset, or " - + "filelist." ); + throw new BuildException("'refid' does not refer to a " + + "path, fileset, dirset, or " + + "filelist."); } } - - validateSetup(); // validate our setup - + + validateSetup();// validate our setup + // Currently, we deal with only two path formats: Unix and Windows // And Unix is everything that is not Windows // (with the exception for NetWare and OS/2 below) - + // for NetWare and OS/2, piggy-back on Windows, since here and // in the apply code, the same assumptions can be made as with // windows - that \\ is an OK separator, and do comparisons // case-insensitive. String fromDirSep = onWindows ? "\\" : "/"; - - StringBuffer rslt = new StringBuffer( 100 ); - + + StringBuffer rslt = new StringBuffer(100); + // Get the list of path components in canonical form String[] elems = path.list(); - - for( int i=0; i < elems.length; i++ ) { + + for (int i = 0; i < elems.length; i++) { String elem = elems[i]; - - elem = mapElement( elem ); // Apply the path prefix map - - + + elem = mapElement(elem);// Apply the path prefix map + // Now convert the path and file separator characters from the // current os to the target os. - - if( i != 0 ) { - rslt.append( pathSep ); + + if (i != 0) { + rslt.append(pathSep); } - - StringTokenizer stDirectory = + + StringTokenizer stDirectory = new StringTokenizer(elem, fromDirSep, true); String token = null; - - while ( stDirectory.hasMoreTokens() ) { + + while (stDirectory.hasMoreTokens()) { token = stDirectory.nextToken(); - + if (fromDirSep.equals(token)) { - rslt.append( dirSep ); - } - else { - rslt.append( token ); + rslt.append(dirSep); + } else { + rslt.append(token); } } } // Place the result into the specified property String value = rslt.toString(); - - log( "Set property " + property + " = " + value, - Project.MSG_VERBOSE ); - - getProject().setNewProperty( property, value ); + + log("Set property " + property + " = " + value, + Project.MSG_VERBOSE); + + getProject().setNewProperty(property, value); } finally { path = savedPath; dirSep = savedDirSep; @@ -340,33 +357,34 @@ public class PathConvert extends Task { } } + /** - * Apply the configured map to a path element. The map is used to convert - * between Windows drive letters and Unix paths. If no map is configured, + * Apply the configured map to a path element. The map is used to convert + * between Windows drive letters and Unix paths. If no map is configured, * then the input string is returned unchanged. * * @param elem The path element to apply the map to * @return String Updated element */ - private String mapElement( String elem ) { + private String mapElement(String elem) { int size = prefixMap.size(); - if( size != 0 ) { + if (size != 0) { // Iterate over the map entries and apply each one. // Stop when one of the entries actually changes the element. - for( int i=0; i < size; i++ ) { - MapEntry entry = (MapEntry)prefixMap.elementAt(i); - String newElem = entry.apply( elem ); + for (int i = 0; i < size; i++) { + MapEntry entry = (MapEntry) prefixMap.elementAt(i); + String newElem = entry.apply(elem); // Note I'm using "!=" to see if we got a new object back from // the apply method. - if( newElem != elem ) { + if (newElem != elem) { elem = newElem; - break; // We applied one, so we're done + break;// We applied one, so we're done } } } @@ -374,25 +392,27 @@ public class PathConvert extends Task { return elem; } + /** * Validate that all our parameters have been properly initialized. + * * @throws BuildException if something is not setup properly */ private void validateSetup() throws BuildException { - if( path == null ) { - throw new BuildException( "You must specify a path to convert" ); + if (path == null) { + throw new BuildException("You must specify a path to convert"); } - if( property == null ) { - throw new BuildException( "You must specify a property" ); + if (property == null) { + throw new BuildException("You must specify a property"); } // Must either have a target OS or both a dirSep and pathSep - if( targetOS == null && pathSep == null && dirSep == null ) { - throw new BuildException( "You must specify at least one of " - + "targetOS, dirSep, or pathSep" ); + if (targetOS == null && pathSep == null && dirSep == null) { + throw new BuildException("You must specify at least one of " + + "targetOS, dirSep, or pathSep"); } // Determine the separator strings. The dirsep and pathsep attributes @@ -400,16 +420,16 @@ public class PathConvert extends Task { String dsep = File.separator; String psep = File.pathSeparator; - if( targetOS != null ) { + if (targetOS != null) { psep = targetWindows ? ";" : ":"; dsep = targetWindows ? "\\" : "/"; } - if( pathSep != null ) { // override with pathsep= + if (pathSep != null) {// override with pathsep= psep = pathSep; } - if( dirSep != null ) { // override with dirsep= + if (dirSep != null) {// override with dirsep= dsep = dirSep; } @@ -417,27 +437,15 @@ public class PathConvert extends Task { dirSep = dsep; } + /** - * Creates an exception that indicates that this XML element must - * not have child elements if the refid attribute is set. + * Creates an exception that indicates that this XML element must not have + * child elements if the refid attribute is set. */ private BuildException noChildrenAllowed() { return new BuildException("You must not specify nested " - + "elements when using the refid attribute."); + + "elements when using the refid attribute."); } - // Members - private Path path = null; // Path to be converted - private Reference refid = null; // Reference to path/fileset to - // convert - private String targetOS = null; // The target OS type - private boolean targetWindows = false; // Set when targetOS is set - private boolean onWindows = false; // Set if we're running on windows - private String property = null; // The property to receive the - //results - private Vector prefixMap = new Vector(); // Path prefix map - private String pathSep = null; // User override on path sep char - private String dirSep = null; // User override on directory sep - // char - } + diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java index adb72e802..7a7aa6911 100644 --- a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java +++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java @@ -159,7 +159,7 @@ class ChangeLogParser { saveEntry(); m_status = GET_FILE; } - else if( line.startsWith( "----------------------------" ) ) { + else if (line.startsWith("----------------------------")) { final int end = m_comment.length() - lineSeparator.length(); //was -1 m_comment = m_comment.substring(0, end); m_status = GET_PREVIOUS_REV; diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java index 566257834..dd6457f2f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java +++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java @@ -168,7 +168,7 @@ public class CvsTagDiff extends Task { * @exception BuildException if an error occurs */ public void init() throws BuildException { - m_cvs = (Cvs)getProject().createTask("cvs"); + m_cvs = (Cvs) getProject().createTask("cvs"); } /** @@ -290,10 +290,10 @@ public class CvsTagDiff extends Task { // build the rdiff command String rdiff = "rdiff -s " + - (m_startTag!=null?("-r " + m_startTag):("-D " + m_startDate)) - + " " + - (m_endTag!=null?("-r " + m_endTag):("-D " + m_endDate)) + " " + - m_package; + (m_startTag != null ? ("-r " + m_startTag) : ("-D " + m_startDate)) + + " " + + (m_endTag != null ? ("-r " + m_endTag) : ("-D " + m_endDate)) + + " " + m_package; log("Cvs command is " + rdiff, Project.MSG_VERBOSE); m_cvs.setCommand(rdiff); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java index 17cc5d7c7..18c20a866 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java @@ -148,12 +148,12 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware if (resolver != null) { if (tfactory.getFeature(SAXSource.FEATURE)) { SAXParserFactory spFactory = SAXParserFactory.newInstance(); - spFactory.setNamespaceAware( true ); + spFactory.setNamespaceAware(true); XMLReader reader = spFactory.newSAXParser().getXMLReader(); reader.setEntityResolver(resolver); src = new SAXSource(reader, new InputSource(fis)); } else { - throw new IllegalStateException("xcatalog specified, but "+ + throw new IllegalStateException("xcatalog specified, but " + "parser doesn't support SAX"); } } else { @@ -193,7 +193,7 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware // making sure it is really a /'ed path protected String getSystemId(File file){ String path = file.getAbsolutePath(); - path = path.replace('\\','/'); + path = path.replace('\\', '/'); // on Windows, use 'file:///' if (File.separatorChar == '\\') { @@ -234,27 +234,27 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware } StringBuffer msg = new StringBuffer(); - if(e.getLocator() != null) { - if(e.getLocator().getSystemId() != null) { + if (e.getLocator() != null) { + if (e.getLocator().getSystemId() != null) { String url = e.getLocator().getSystemId(); - if(url.startsWith("file:///")) { + if (url.startsWith("file:///")) { url = url.substring(8); } msg.append(url); } else { msg.append("Unknown file"); } - if(e.getLocator().getLineNumber() != -1) { - msg.append(":"+e.getLocator().getLineNumber()); - if(e.getLocator().getColumnNumber() != -1) { - msg.append(":"+e.getLocator().getColumnNumber()); + if (e.getLocator().getLineNumber() != -1) { + msg.append(":" + e.getLocator().getLineNumber()); + if (e.getLocator().getColumnNumber() != -1) { + msg.append(":" + e.getLocator().getColumnNumber()); } } } - msg.append(": "+type+"! "); + msg.append(": " + type + "! "); msg.append(e.getMessage()); - if(e.getCause() != null) { - msg.append(" Cause: "+e.getCause()); + if (e.getCause() != null) { + msg.append(" Cause: " + e.getCause()); } logger.log(msg.toString()); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java index f52b01e1e..5bc788a75 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java @@ -95,7 +95,8 @@ public class XMLValidateTask extends Task { * validation. */ // The crimson implementation is shipped with ant. - public static String DEFAULT_XML_READER_CLASSNAME= "org.apache.crimson.parser.XMLReaderImpl"; + public static String DEFAULT_XML_READER_CLASSNAME + = "org.apache.crimson.parser.XMLReaderImpl"; protected static String INIT_FAILED_MSG = "Could not start xml validation: "; @@ -234,7 +235,7 @@ public class XMLValidateTask extends Task { LocalResolver resolver = new LocalResolver(); for (Enumeration i = dtdLocations.elements(); i.hasMoreElements();) { - DTDLocation location = (DTDLocation)i.nextElement(); + DTDLocation location = (DTDLocation) i.nextElement(); resolver.registerDTD(location); } return resolver; @@ -243,7 +244,7 @@ public class XMLValidateTask extends Task { public void execute() throws BuildException { int fileProcessed = 0; - if (file == null && (filesets.size()==0) ) { + if (file == null && (filesets.size() == 0)) { throw new BuildException("Specify at least one source - a file or a fileset."); } @@ -264,13 +265,13 @@ public class XMLValidateTask extends Task { } } - for (int i=0; i. */ - /** - * jlink.java - * links together multiple .jar files - * - * Original code by Patrick Beard. Modifications to work - * with ANT by Matthew Kuperus Heun. + * jlink.java links together multiple .jar files Original code by Patrick + * Beard. Modifications to work with ANT by Matthew Kuperus Heun. * - * @author Matthew Kuperus Heun + * @author Matthew Kuperus Heun + * */ package org.apache.tools.ant.taskdefs.optional.jlink; @@ -70,8 +67,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.FileInputStream; import java.io.BufferedInputStream; -import java.util .Enumeration; -import java.util .Vector; +import java.util.Enumeration; +import java.util.Vector; import java.util.zip.ZipOutputStream; import java.util.zip.Deflater; import java.util.zip.ZipFile; @@ -79,167 +76,168 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.CRC32; -public class jlink extends Object{ +public class jlink extends Object { - /** - * The file that will be created by this instance of jlink. - */ - public void setOutfile( String outfile ) { - if ( outfile == null ) { - return ; + /** The file that will be created by this instance of jlink. */ + public void setOutfile(String outfile) { + if (outfile == null) { + return; } - this .outfile = outfile; + this.outfile = outfile; } - /** - * Adds a file to be merged into the output. - */ - public void addMergeFile( String mergefile ) { - if ( mergefile == null ) { - return ; + + /** Adds a file to be merged into the output. */ + public void addMergeFile(String mergefile) { + if (mergefile == null) { + return; } - mergefiles .addElement( mergefile ); + mergefiles.addElement(mergefile); } - /** - * Adds a file to be added into the output. - */ - public void addAddFile( String addfile ) { - if ( addfile == null ) { - return ; + + /** Adds a file to be added into the output. */ + public void addAddFile(String addfile) { + if (addfile == null) { + return; } - addfiles .addElement( addfile ); + addfiles.addElement(addfile); } - /** - * Adds several files to be merged into the output. - */ - public void addMergeFiles( String[] mergefiles ) { - if ( mergefiles == null ) { - return ; + + /** Adds several files to be merged into the output. */ + public void addMergeFiles(String[] mergefiles) { + if (mergefiles == null) { + return; } - for ( int i = 0; i < mergefiles .length; i++ ) { - addMergeFile( mergefiles[i] ); + for (int i = 0; i < mergefiles.length; i++) { + addMergeFile(mergefiles[i]); } } - /** - * Adds several file to be added into the output. - */ - public void addAddFiles( String[] addfiles ) { - if ( addfiles == null ) { - return ; + + /** Adds several file to be added into the output. */ + public void addAddFiles(String[] addfiles) { + if (addfiles == null) { + return; } - for ( int i = 0; i < addfiles .length; i++ ) { - addAddFile( addfiles[i] ); + for (int i = 0; i < addfiles.length; i++) { + addAddFile(addfiles[i]); } } - /** - * Determines whether output will be compressed. - */ - public void setCompression( boolean compress ) { - this .compression = compress; + + /** Determines whether output will be compressed. */ + public void setCompression(boolean compress) { + this.compression = compress; } + /** - * Performs the linking of files. - * Addfiles are added to the output as-is. For example, a - * jar file is added to the output as a jar file. - * However, mergefiles are first examined for their type. - * If it is a jar or zip file, the contents will be extracted - * from the mergefile and entered into the output. - * If a zip or jar file is encountered in a subdirectory - * it will be added, not merged. - * If a directory is encountered, it becomes the root - * entry of all the files below it. Thus, you can - * provide multiple, disjoint directories, as - * addfiles: they will all be added in a rational - * manner to outfile. + * Performs the linking of files. Addfiles are added to the output as-is. + * For example, a jar file is added to the output as a jar file. However, + * mergefiles are first examined for their type. If it is a jar or zip + * file, the contents will be extracted from the mergefile and entered + * into the output. If a zip or jar file is encountered in a subdirectory + * it will be added, not merged. If a directory is encountered, it becomes + * the root entry of all the files below it. Thus, you can provide + * multiple, disjoint directories, as addfiles: they will all be added in + * a rational manner to outfile. */ - public void link() throws Exception { - ZipOutputStream output = new ZipOutputStream( new FileOutputStream( outfile ) ); - if ( compression ) { - output .setMethod( ZipOutputStream .DEFLATED ); - output .setLevel( Deflater .DEFAULT_COMPRESSION ); + public void link() throws Exception { + ZipOutputStream output = new ZipOutputStream(new FileOutputStream(outfile)); + + if (compression) { + output.setMethod(ZipOutputStream.DEFLATED); + output.setLevel(Deflater.DEFAULT_COMPRESSION); } else { - output .setMethod( ZipOutputStream .STORED ); + output.setMethod(ZipOutputStream.STORED); } - Enumeration merges = mergefiles .elements(); - while ( merges .hasMoreElements() ) { - String path = (String) merges .nextElement(); - File f = new File( path ); - if ( f.getName().endsWith( ".jar" ) || f.getName().endsWith( ".zip" ) ) { - //Do the merge - mergeZipJarContents( output, f ); - } - else { - //Add this file to the addfiles Vector and add it + + Enumeration merges = mergefiles.elements(); + + while (merges.hasMoreElements()) { + String path = (String) merges.nextElement(); + File f = new File(path); + + if (f.getName().endsWith(".jar") || f.getName().endsWith(".zip")) { + //Do the merge + mergeZipJarContents(output, f); + } else { + //Add this file to the addfiles Vector and add it //later at the top level of the output file. - addAddFile( path ); + addAddFile(path); } } - Enumeration adds = addfiles .elements(); - while ( adds .hasMoreElements() ) { - String name = (String) adds .nextElement(); - File f = new File( name ); - if ( f .isDirectory() ) { + + Enumeration adds = addfiles.elements(); + + while (adds.hasMoreElements()) { + String name = (String) adds.nextElement(); + File f = new File(name); + + if (f.isDirectory()) { //System.out.println("in jlink: adding directory contents of " + f.getPath()); - addDirContents( output, f, f.getName() + '/', compression ); - } - else { - addFile( output, f, "", compression ); + addDirContents(output, f, f.getName() + '/', compression); + } else { + addFile(output, f, "", compression); } } - if ( output != null ) { - try { - output .close(); - } catch( IOException ioe ) {} + if (output != null) { + try { + output.close(); + } catch (IOException ioe) { + } } } - public static void main( String[] args ) { + + public static void main(String[] args) { // jlink output input1 ... inputN - if ( args .length < 2 ) { - System .out .println( "usage: jlink output input1 ... inputN" ); - System .exit( 1 ); + if (args.length < 2) { + System.out.println("usage: jlink output input1 ... inputN"); + System.exit(1); } jlink linker = new jlink(); - linker .setOutfile( args[0] ); + + linker.setOutfile(args[0]); //To maintain compatibility with the command-line version, we will only add files to be merged. - for ( int i = 1; i < args .length; i++ ) { - linker .addMergeFile( args[i] ); + for (int i = 1; i < args.length; i++) { + linker.addMergeFile(args[i]); } - try { - linker .link(); - } catch( Exception ex ) { - System .err .print( ex .getMessage() ); + try { + linker.link(); + } catch (Exception ex) { + System.err.print(ex.getMessage()); } } + /* * Actually performs the merging of f into the output. * f should be a zip or jar file. */ - private void mergeZipJarContents( ZipOutputStream output, File f ) throws IOException { + private void mergeZipJarContents(ZipOutputStream output, File f) throws IOException { //Check to see that the file with name "name" exists. - if ( ! f .exists() ) { - return ; + if (!f.exists()) { + return; } - ZipFile zipf = new ZipFile( f ); + ZipFile zipf = new ZipFile(f); Enumeration entries = zipf.entries(); - while (entries.hasMoreElements()){ + + while (entries.hasMoreElements()) { ZipEntry inputEntry = (ZipEntry) entries.nextElement(); //Ignore manifest entries. They're bound to cause conflicts between //files that are being merged. User should supply their own //manifest file when doing the merge. String inputEntryName = inputEntry.getName(); int index = inputEntryName.indexOf("META-INF"); - if (index < 0){ + + if (index < 0) { //META-INF not found in the name of the entry. Go ahead and process it. try { output.putNextEntry(processEntry(zipf, inputEntry)); - } catch (ZipException ex){ + } catch (ZipException ex) { //If we get here, it could be because we are trying to put a //directory entry that already exists. //For example, we're trying to write "com", but a previous @@ -247,139 +245,160 @@ public class jlink extends Object{ //In that case, just ignore the error and go on to the //next entry. String mess = ex.getMessage(); - if (mess.indexOf("duplicate") >= 0){ - //It was the duplicate entry. + + if (mess.indexOf("duplicate") >= 0) { + //It was the duplicate entry. continue; } else { - //I hate to admit it, but we don't know what happened here. Throw the Exception. + //I hate to admit it, but we don't know what happened here. Throw the Exception. throw ex; } } + InputStream in = zipf.getInputStream(inputEntry); int len = buffer.length; int count = -1; - while ((count = in.read(buffer, 0, len)) > 0){ + + while ((count = in.read(buffer, 0, len)) > 0) { output.write(buffer, 0, count); } in.close(); output.closeEntry(); } } - zipf .close(); + zipf.close(); } + /* * Adds contents of a directory to the output. */ - private void addDirContents( ZipOutputStream output, File dir, String prefix, boolean compress ) throws IOException { - String[] contents = dir .list(); - for ( int i = 0; i < contents .length; ++i ) { + private void addDirContents(ZipOutputStream output, File dir, String prefix, boolean compress) throws IOException { + String[] contents = dir.list(); + + for (int i = 0; i < contents.length; ++i) { String name = contents[i]; - File file = new File( dir, name ); - if ( file .isDirectory() ) { - addDirContents( output, file, prefix + name + '/', compress ); - } - else { - addFile( output, file, prefix, compress ); + File file = new File(dir, name); + + if (file.isDirectory()) { + addDirContents(output, file, prefix + name + '/', compress); + } else { + addFile(output, file, prefix, compress); } } } + /* * Gets the name of an entry in the file. This is the real name * which for a class is the name of the package with the class * name appended. */ - private String getEntryName( File file, String prefix ) { - String name = file .getName(); - if ( ! name .endsWith( ".class" ) ) { + private String getEntryName(File file, String prefix) { + String name = file.getName(); + + if (!name.endsWith(".class")) { // see if the file is in fact a .class file, and determine its actual name. - try { - InputStream input = new FileInputStream( file ); - String className = ClassNameReader .getClassName( input ); - input .close(); - if ( className != null ) { - return className .replace( '.', '/' ) + ".class"; + try { + InputStream input = new FileInputStream(file); + String className = ClassNameReader.getClassName(input); + + input.close(); + if (className != null) { + return className.replace('.', '/') + ".class"; } - } catch( IOException ioe ) {} + } catch (IOException ioe) { + } } - System.out.println("From " + file.getPath() + " and prefix " + prefix + ", creating entry " + prefix+name); + System.out.println("From " + file.getPath() + " and prefix " + prefix + ", creating entry " + prefix + name); return (prefix + name); } + /* * Adds a file to the output stream. */ - private void addFile( ZipOutputStream output, File file, String prefix, boolean compress) throws IOException { + private void addFile(ZipOutputStream output, File file, String prefix, boolean compress) throws IOException { //Make sure file exists long checksum = 0; - if ( ! file .exists() ) { - return ; + + if (!file.exists()) { + return; } - ZipEntry entry = new ZipEntry( getEntryName( file, prefix ) ); - entry .setTime( file .lastModified() ); - entry .setSize( file .length() ); - if (! compress){ + ZipEntry entry = new ZipEntry(getEntryName(file, prefix)); + + entry.setTime(file.lastModified()); + entry.setSize(file.length()); + if (!compress) { entry.setCrc(calcChecksum(file)); } - FileInputStream input = new FileInputStream( file ); + FileInputStream input = new FileInputStream(file); + addToOutputStream(output, input, entry); } - + + /* * A convenience method that several other methods might call. */ - private void addToOutputStream(ZipOutputStream output, InputStream input, ZipEntry ze) throws IOException{ + private void addToOutputStream(ZipOutputStream output, InputStream input, ZipEntry ze) throws IOException { try { - output.putNextEntry(ze); + output.putNextEntry(ze); } catch (ZipException zipEx) { //This entry already exists. So, go with the first one. input.close(); return; } + int numBytes = -1; - while((numBytes = input.read(buffer)) > 0){ + + while ((numBytes = input.read(buffer)) > 0) { output.write(buffer, 0, numBytes); } output.closeEntry(); input.close(); } + /* * A method that does the work on a given entry in a mergefile. - * The big deal is to set the right parameters in the ZipEntry + * The big deal is to set the right parameters in the ZipEntry * on the output stream. */ - private ZipEntry processEntry( ZipFile zip, ZipEntry inputEntry ) throws IOException{ + private ZipEntry processEntry(ZipFile zip, ZipEntry inputEntry) throws IOException { /* First, some notes. On MRJ 2.2.2, getting the size, compressed size, and CRC32 from the ZipInputStream does not work for compressed (deflated) files. Those calls return -1. For uncompressed (stored) files, those calls do work. - However, using ZipFile.getEntries() works for both compressed and + However, using ZipFile.getEntries() works for both compressed and uncompressed files. - + Now, from some simple testing I did, it seems that the value of CRC-32 is - independent of the compression setting. So, it should be easy to pass this + independent of the compression setting. So, it should be easy to pass this information on to the output entry. */ - String name = inputEntry .getName(); - if ( ! (inputEntry .isDirectory() || name .endsWith( ".class" )) ) { - try { - InputStream input = zip.getInputStream( zip .getEntry( name ) ); - String className = ClassNameReader .getClassName( input ); - input .close(); - if ( className != null ) { - name = className .replace( '.', '/' ) + ".class"; + String name = inputEntry.getName(); + + if (!(inputEntry.isDirectory() || name.endsWith(".class"))) { + try { + InputStream input = zip.getInputStream(zip.getEntry(name)); + String className = ClassNameReader.getClassName(input); + + input.close(); + if (className != null) { + name = className.replace('.', '/') + ".class"; } - } catch( IOException ioe ) {} + } catch (IOException ioe) { + } } - ZipEntry outputEntry = new ZipEntry( name ); - outputEntry.setTime(inputEntry .getTime() ); + ZipEntry outputEntry = new ZipEntry(name); + + outputEntry.setTime(inputEntry.getTime()); outputEntry.setExtra(inputEntry.getExtra()); outputEntry.setComment(inputEntry.getComment()); outputEntry.setTime(inputEntry.getTime()); - if (compression){ + if (compression) { outputEntry.setMethod(ZipEntry.DEFLATED); //Note, don't need to specify size or crc for compressed files. } else { @@ -389,26 +408,30 @@ public class jlink extends Object{ } return outputEntry; } - + + /* * Necessary in the case where you add a entry that * is not compressed. */ private long calcChecksum(File f) throws IOException { BufferedInputStream in = new BufferedInputStream(new FileInputStream(f)); + return calcChecksum(in, f.length()); } + /* * Necessary in the case where you add a entry that * is not compressed. */ - private long calcChecksum(InputStream in, long size) throws IOException{ + private long calcChecksum(InputStream in, long size) throws IOException { CRC32 crc = new CRC32(); int len = buffer.length; int count = -1; - int haveRead = 0; - while((count=in.read(buffer, 0, len)) > 0){ + int haveRead = 0; + + while ((count = in.read(buffer, 0, len)) > 0) { haveRead += count; crc.update(buffer, 0, count); } @@ -416,14 +439,15 @@ public class jlink extends Object{ return crc.getValue(); } - private String outfile = null; - private Vector mergefiles = new Vector( 10 ); + private String outfile = null; + + private Vector mergefiles = new Vector(10); + + private Vector addfiles = new Vector(10); - private Vector addfiles = new Vector( 10 ); + private boolean compression = false; - private boolean compression = false; - byte[] buffer = new byte[8192]; } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java index 0593a2092..303a01920 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java @@ -118,7 +118,7 @@ public class JspC extends MatchingTask private File destDir; private String packageName ; /** name of the compiler to use */ - private String compilerName="jasper"; + private String compilerName = "jasper"; /** * -ieplugin Java Plugin classid for Internet Explorer @@ -127,7 +127,7 @@ public class JspC extends MatchingTask private boolean mapped ; private int verbose = 0; protected Vector compileList = new Vector(); - Vector javaFiles=new Vector(); + Vector javaFiles = new Vector(); /** * flag to control action on execution trouble @@ -336,7 +336,7 @@ public class JspC extends MatchingTask public void addWebApp(WebAppParameter webappParam) throws BuildException { //demand create vector of filesets - if(webApp == null) { + if (webApp == null) { webApp = webappParam; } else { @@ -352,7 +352,7 @@ public class JspC extends MatchingTask * Sets the compiler to use. Optional: default=jasper */ public void setCompiler(String compiler) { - this.compilerName=compiler; + this.compilerName = compiler; } /** @@ -393,33 +393,33 @@ public class JspC extends MatchingTask JspCompilerAdapterFactory.getCompiler(compilerName, this); // if the compiler does its own dependency stuff, we just call it right now - if(compiler.implementsOwnDependencyChecking()) { + if (compiler.implementsOwnDependencyChecking()) { doCompilation(compiler); return; } //the remainder of this method is only for compilers that need their dependency work done - JspMangler mangler=compiler.createMangler(); + JspMangler mangler = compiler.createMangler(); // scan source directories and dest directory to build up both copy // lists and compile lists resetFileLists(); - int filecount=0; + int filecount = 0; for (int i = 0; i < list.length; i++) { - File srcDir = (File)project.resolveFile(list[i]); + File srcDir = (File) project.resolveFile(list[i]); if (!srcDir.exists()) { throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", location); } DirectoryScanner ds = this.getDirectoryScanner(srcDir); String[] files = ds.getIncludedFiles(); - filecount=files.length; + filecount = files.length; scanDir(srcDir, dest, mangler, files); } // compile the source files - log("compiling "+compileList.size()+" files",Project.MSG_VERBOSE); + log("compiling " + compileList.size() + " files", Project.MSG_VERBOSE); if (compileList.size() > 0) { @@ -431,11 +431,11 @@ public class JspC extends MatchingTask } else { - if(filecount==0) { - log("there were no files to compile",Project.MSG_INFO); + if (filecount == 0) { + log("there were no files to compile", Project.MSG_INFO); } else { - log("all files are up to date",Project.MSG_VERBOSE); + log("all files are up to date", Project.MSG_VERBOSE); } } } @@ -462,7 +462,7 @@ public class JspC extends MatchingTask private void doCompilation(JspCompilerAdapter compiler) throws BuildException { // now we need to populate the compiler adapter - compiler.setJspc( this ); + compiler.setJspc(this); // finally, lets execute the compiler!! if (!compiler.execute()) { @@ -493,17 +493,17 @@ public class JspC extends MatchingTask long now = (new Date()).getTime(); for (int i = 0; i < files.length; i++) { - String filename=files[i]; + String filename = files[i]; File srcFile = new File(srcDir, filename); - File javaFile=mapToJavaFile(mangler,srcFile, srcDir, dest); + File javaFile = mapToJavaFile(mangler, srcFile, srcDir, dest); if (srcFile.lastModified() > now) { - log("Warning: file modified in the future: " +filename, - Project.MSG_WARN); + log("Warning: file modified in the future: " + filename, + Project.MSG_WARN); } - boolean shouldCompile=false; - shouldCompile=isCompileNeeded(srcFile, javaFile); - if(shouldCompile) { + boolean shouldCompile = false; + shouldCompile = isCompileNeeded(srcFile, javaFile); + if (shouldCompile) { compileList.addElement(srcFile.getAbsolutePath()); javaFiles.addElement(javaFile); } @@ -527,25 +527,25 @@ public class JspC extends MatchingTask * */ private boolean isCompileNeeded(File srcFile, File javaFile) { - boolean shouldCompile=false; + boolean shouldCompile = false; if (!javaFile.exists()) { - shouldCompile=true; - log("Compiling " + srcFile.getPath() + - " because java file "+ javaFile.getPath() + " does not exist", - Project.MSG_VERBOSE); + shouldCompile = true; + log("Compiling " + srcFile.getPath() + + " because java file " + javaFile.getPath() + + " does not exist", Project.MSG_VERBOSE); } else { - if( srcFile.lastModified() > javaFile.lastModified()) { - shouldCompile=true; - log("Compiling " + srcFile.getPath() + - " because it is out of date with respect to " + javaFile.getPath(), + if (srcFile.lastModified() > javaFile.lastModified()) { + shouldCompile = true; + log("Compiling " + srcFile.getPath() + + " because it is out of date with respect to " + + javaFile.getPath(), Project.MSG_VERBOSE); } else { - if( javaFile.length()==0) { - shouldCompile=true; - log("Compiling " + srcFile.getPath() + - " because java file "+ javaFile.getPath() - + " is empty", - Project.MSG_VERBOSE); + if (javaFile.length() == 0) { + shouldCompile = true; + log("Compiling " + srcFile.getPath() + + " because java file " + javaFile.getPath() + + " is empty", Project.MSG_VERBOSE); } } } @@ -561,9 +561,9 @@ public class JspC extends MatchingTask if (!srcFile.getName().endsWith(".jsp")) { return null; } - String javaFileName=mangler.mapJspToJavaName(srcFile); + String javaFileName = mangler.mapJspToJavaName(srcFile); // String srcFileDir=srcFile.getParent(); - String packageNameIn=srcFile.getAbsolutePath(); + String packageNameIn = srcFile.getAbsolutePath(); return new File(dest, javaFileName); } @@ -573,12 +573,12 @@ public class JspC extends MatchingTask * fails, it leaves incomplete files around. */ public void deleteEmptyJavaFiles() { - if(javaFiles!=null) { + if (javaFiles != null) { Enumeration enum = javaFiles.elements(); while (enum.hasMoreElements()) { - File file = (File )enum.nextElement(); - if(file.exists() && file.length()==0) { - log("deleting empty output file "+file); + File file = (File) enum.nextElement(); + if (file.exists() && file.length() == 0) { + log("deleting empty output file " + file); file.delete(); } } @@ -607,7 +607,7 @@ public class JspC extends MatchingTask * set directory; alternate syntax */ public void setBaseDir(File directory) { - this.directory=directory; + this.directory = directory; } //end inner class } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java index b9cd10e7f..6eac76e2c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java @@ -146,7 +146,8 @@ public class WLJspc extends MatchingTask String systemClassPath = System.getProperty("java.class.path"); - pathToPackage = this.destinationPackage.replace('.',File.separatorChar); + pathToPackage + = this.destinationPackage.replace('.', File.separatorChar); // get all the files in the sourceDirectory DirectoryScanner ds = super.getDirectoryScanner(sourceDirectory); @@ -162,7 +163,7 @@ public class WLJspc extends MatchingTask // Therefore, takes loads of time // Can pass directories at a time (*.jsp) but easily runs out of memory on hefty dirs // (even on a Sun) - Java helperTask = (Java)project.createTask("java"); + Java helperTask = (Java) project.createTask("java"); helperTask.setFork(true); helperTask.setClassname("weblogic.jspc"); helperTask.setTaskName(getTaskName()); @@ -171,7 +172,7 @@ public class WLJspc extends MatchingTask File jspFile = null; String parents = ""; String arg = ""; - int j=0; + int j = 0; //XXX this array stuff is a remnant of prev trials.. gotta remove. args[j++] = "-d"; args[j++] = destinationDirectory.getAbsolutePath().trim(); @@ -189,9 +190,9 @@ public class WLJspc extends MatchingTask args[j++] = compileClasspath.toString(); this.scanDir(files); - log("Compiling "+filesToDo.size() + " JSP files"); + log("Compiling " + filesToDo.size() + " JSP files"); - for (int i=0;i classFile.lastModified()) { //log("Files are" + srcFile.getAbsolutePath()+" " +classFile.getAbsolutePath()); filesToDo.addElement(files[i]); - log("Recompiling File "+files[i],Project.MSG_VERBOSE); + log("Recompiling File " + files[i], Project.MSG_VERBOSE); } } } - protected String replaceString(String inpString,String escapeChars,String replaceChars) { - String localString=""; - int numTokens=0; - StringTokenizer st=new StringTokenizer(inpString,escapeChars,true); - numTokens=st.countTokens(); - for(int i=0;i 0) { - sb.append("------------- Standard Output ---------------" ) + sb.append("------------- Standard Output ---------------") .append(newLine) .append(systemOutput) - .append("------------- ---------------- ---------------" ) + .append("------------- ---------------- ---------------") .append(newLine); } if (systemError != null && systemError.length() > 0) { - sb.append("------------- Standard Error -----------------" ) + sb.append("------------- Standard Error -----------------") .append(newLine) .append(systemError) - .append("------------- ---------------- ---------------" ) + .append("------------- ---------------- ---------------") .append(newLine); } @@ -206,7 +206,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { } Long l = (Long) testStarts.get(test); wri.println(" took " - + nf.format((System.currentTimeMillis()-l.longValue()) + + nf.format((System.currentTimeMillis() - l.longValue()) / 1000.0) + " sec"); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java index 0cb10df3a..d3da0fa23 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/SummaryJUnitResultFormatter.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -120,11 +120,11 @@ public class SummaryJUnitResultFormatter implements JUnitResultFormatter { this.out = out; } - public void setSystemOutput( String out ) { + public void setSystemOutput(String out) { systemOutput = out; } - public void setSystemError( String err ) { + public void setSystemError(String err) { systemError = err; } @@ -132,7 +132,7 @@ public class SummaryJUnitResultFormatter implements JUnitResultFormatter { * Should the output to System.out and System.err be written to * the summary. */ - public void setWithOutAndErr( boolean value ) { + public void setWithOutAndErr(boolean value) { withOutAndErr = value; } @@ -148,18 +148,18 @@ public class SummaryJUnitResultFormatter implements JUnitResultFormatter { sb.append(", Errors: "); sb.append(suite.errorCount()); sb.append(", Time elapsed: "); - sb.append(nf.format(suite.getRunTime()/1000.0)); + sb.append(nf.format(suite.getRunTime() / 1000.0)); sb.append(" sec"); sb.append(newLine); if (withOutAndErr) { if (systemOutput != null && systemOutput.length() > 0) { - sb.append( "Output:" ).append(newLine).append(systemOutput) + sb.append("Output:").append(newLine).append(systemOutput) .append(newLine); } if (systemError != null && systemError.length() > 0) { - sb.append( "Error: " ).append(newLine).append(systemError) + sb.append("Error: ").append(newLine).append(systemError) .append(newLine); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java index 3c32786d6..717682af5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -92,7 +92,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan try { return DocumentBuilderFactory.newInstance().newDocumentBuilder(); } - catch(Exception exc) { + catch (Exception exc) { throw new ExceptionInInitializerError(exc); } } @@ -160,10 +160,10 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan * The whole testsuite ended. */ public void endTestSuite(JUnitTest suite) throws BuildException { - rootElement.setAttribute(ATTR_TESTS, ""+suite.runCount()); - rootElement.setAttribute(ATTR_FAILURES, ""+suite.failureCount()); - rootElement.setAttribute(ATTR_ERRORS, ""+suite.errorCount()); - rootElement.setAttribute(ATTR_TIME, ""+(suite.getRunTime()/1000.0)); + rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount()); + rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount()); + rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount()); + rootElement.setAttribute(ATTR_TIME, "" + (suite.getRunTime() / 1000.0)); if (out != null) { Writer wri = null; try { @@ -171,7 +171,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan wri.write("\n"); (new DOMElementWriter()).write(rootElement, wri, 0, " "); wri.flush(); - } catch(IOException exc) { + } catch (IOException exc) { throw new BuildException("Unable to write log file", exc); } finally { if (out != System.out && out != System.err) { @@ -218,8 +218,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan Long l = (Long) testStarts.get(test); currentTest.setAttribute(ATTR_TIME, - ""+((System.currentTimeMillis()-l.longValue()) - / 1000.0)); + "" + ((System.currentTimeMillis() - l.longValue()) / 1000.0)); } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java index 93a8b465b..276792f78 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java @@ -160,7 +160,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { File destFile = getDestinationFile(); // write the document try { - writeDOMTree(rootElement.getOwnerDocument(), destFile ); + writeDOMTree(rootElement.getOwnerDocument(), destFile); } catch (IOException e){ throw new BuildException("Unable to write test aggregate to '" + destFile + "'", e); } @@ -204,10 +204,10 @@ public class XMLResultAggregator extends Task implements XMLConstants { String[] f = ds.getIncludedFiles(); for (int j = 0; j < f.length; j++) { String pathname = f[j]; - if ( pathname.endsWith(".xml") ) { + if (pathname.endsWith(".xml")) { File file = new File(ds.getBasedir(), pathname); file = project.resolveFile(file.getPath()); - v.addElement( file ); + v.addElement(file); } } } @@ -229,7 +229,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { OutputStream out = null; PrintWriter wri = null; try { - out = new FileOutputStream( file ); + out = new FileOutputStream(file); wri = new PrintWriter(new OutputStreamWriter(out, "UTF8")); wri.write("\n"); (new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); @@ -270,10 +270,11 @@ public class XMLResultAggregator extends Task implements XMLConstants { //XXX there seems to be a bug in xerces 1.3.0 that doesn't like file object // will investigate later. It does not use the given directory but // the vm dir instead ? Works fine with crimson. - Document testsuiteDoc = builder.parse( "file:///" + files[i].getAbsolutePath() ); + Document testsuiteDoc + = builder.parse("file:///" + files[i].getAbsolutePath()); Element elem = testsuiteDoc.getDocumentElement(); // make sure that this is REALLY a testsuite. - if ( TESTSUITE.equals(elem.getNodeName()) ) { + if (TESTSUITE.equals(elem.getNodeName())) { addTestSuite(rootElement, elem); } else { // issue a warning. @@ -310,7 +311,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { // a missing . might imply no package at all. Don't get fooled. String pkgName = (pos == -1) ? "" : fullclassname.substring(0, pos); String classname = (pos == -1) ? fullclassname : fullclassname.substring(pos + 1); - Element copy = (Element)DOMUtil.importNode(root, testsuite); + Element copy = (Element) DOMUtil.importNode(root, testsuite); // modify the name attribute and set the package copy.setAttribute(ATTR_NAME, classname); @@ -326,7 +327,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { private static DocumentBuilder getDocumentBuilder() { try { return DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } catch(Exception exc) { + } catch (Exception exc) { throw new ExceptionInInitializerError(exc); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java index 92f71e840..63fb13806 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Xalan1Executor.java @@ -78,7 +78,7 @@ public class Xalan1Executor extends XalanExecutor { OutputStream os = getOutputStream(); try { XSLTResultTarget target = new XSLTResultTarget(os); - processor.process( xml_src, xsl_src, target); + processor.process(xml_src, xsl_src, target); } finally { os.close(); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java index 89aa7291c..6db2eecb8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java @@ -190,7 +190,7 @@ public class MParse extends Task { // set the metamata.home property final Commandline.Argument vmArgs = cmdl.createVmArgument(); - vmArgs.setValue("-Dmetamata.home=" + metahome.getAbsolutePath() ); + vmArgs.setValue("-Dmetamata.home=" + metahome.getAbsolutePath()); // write all the options to a temp file and use it ro run the process @@ -254,8 +254,8 @@ public class MParse extends Task { */ protected File[] getMetamataLibs(){ Vector files = new Vector(); - files.addElement( new File(metahome, "lib/metamata.jar") ); - files.addElement( new File(metahome, "bin/lib/JavaCC.zip") ); + files.addElement(new File(metahome, "lib/metamata.jar")); + files.addElement(new File(metahome, "bin/lib/JavaCC.zip")); File[] array = new File[ files.size() ]; files.copyInto(array); @@ -278,12 +278,14 @@ public class MParse extends Task { File[] jars = getMetamataLibs(); for (int i = 0; i < jars.length; i++){ if (!jars[i].exists()){ - throw new BuildException( jars[i] + " does not exist. Check your metamata installation."); + throw new BuildException(jars[i] + + " does not exist. Check your metamata installation."); } } // check that the target is ok and resolve it. - if (target == null || !target.isFile() || !target.getName().endsWith(".jj") ) { + if (target == null || !target.isFile() + || !target.getName().endsWith(".jj")) { throw new BuildException("Invalid target: " + target); } target = project.resolveFile(target.getPath()); @@ -332,7 +334,7 @@ public class MParse extends Task { fw = new FileWriter(tofile); PrintWriter pw = new PrintWriter(fw); for (int i = 0; i < options.length; i++){ - pw.println( options[i] ); + pw.println(options[i]); } pw.flush(); } catch (IOException e){ diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java index d14ca21c1..c0ab9392b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java @@ -51,7 +51,6 @@ * information on the Apache Software Foundation, please see * . */ - package org.apache.tools.ant.taskdefs.optional.net; import com.oroinc.net.ftp.FTPClient; @@ -82,37 +81,35 @@ import java.util.Vector; /** * Basic FTP client that performs the following actions: *

    - *
  • send - send files to a remote server. This is the - * default action.
  • - *
  • get - retrive files from a remote server.
  • - *
  • del - delete files from a remote server.
  • - *
  • list - create a file listing.
  • - *
  • chmod - change unix file permissions.
  • + *
  • send - send files to a remote server. This is the + * default action.
  • + *
  • get - retrive files from a remote server.
  • + *
  • del - delete files from a remote server.
  • + *
  • list - create a file listing.
  • + *
  • chmod - change unix file permissions.
  • *
+ * Note: Some FTP servers - notably the Solaris server - seem + * to hold data ports open after a "retr" operation, allowing them to timeout + * instead of shutting them down cleanly. This happens in active or passive + * mode, and the ports will remain open even after ending the FTP session. FTP + * "send" operations seem to close ports immediately. This behavior may cause + * problems on some systems when downloading large sets of files. * - * Note: - * Some FTP servers - notably the Solaris server - seem to hold data ports - * open after a "retr" operation, allowing them to timeout instead of - * shutting them down cleanly. This happens in active or passive mode, - * and the ports will remain open even after ending the FTP session. - * FTP "send" operations seem to close ports immediately. This behavior - * may cause problems on some systems when downloading large sets of files. - * - * @author Roger Vaughn rvaughn@seaconinc.com - * @author Glenn McAllister glennm@ca.ibm.com + * @author Roger Vaughn + * rvaughn@seaconinc.com + * @author Glenn McAllister + * glennm@ca.ibm.com * @author Magesh Umasankar - * * @since Ant 1.3 */ public class FTP - extends Task -{ - protected final static int SEND_FILES = 0; - protected final static int GET_FILES = 1; - protected final static int DEL_FILES = 2; - protected final static int LIST_FILES = 3; - protected final static int MK_DIR = 4; - protected final static int CHMOD = 5; + extends Task { + protected final static int SEND_FILES = 0; + protected final static int GET_FILES = 1; + protected final static int DEL_FILES = 2; + protected final static int LIST_FILES = 3; + protected final static int MK_DIR = 4; + protected final static int CHMOD = 5; private String remotedir; private String server; @@ -129,9 +126,9 @@ public class FTP private int transferred = 0; private String remoteFileSep = "/"; private int port = 21; - private boolean skipFailedTransfers=false; - private int skipped=0; - private boolean ignoreNoncriticalErrors=false; + private boolean skipFailedTransfers = false; + private int skipped = 0; + private boolean ignoreNoncriticalErrors = false; private String chmod = null; private String umask = null; private FileUtils fileUtils = FileUtils.newFileUtils(); @@ -143,7 +140,7 @@ public class FTP "listing", "making directory", "chmod" - }; + }; protected final static String[] COMPLETED_ACTION_STRS = { "sent", @@ -152,16 +149,19 @@ public class FTP "listed", "created directory", "mode changed" - }; + }; + protected class FTPDirectoryScanner extends DirectoryScanner { protected FTPClient ftp = null; + public FTPDirectoryScanner(FTPClient ftp) { super(); this.ftp = ftp; } + public void scan() { if (includes == null) { // No includes supplied, so set it to 'matches all' @@ -182,13 +182,14 @@ public class FTP try { String cwd = ftp.printWorkingDirectory(); // always start from the current ftp working dir - scandir(".", "", true); + scandir(".", "", true); ftp.changeWorkingDirectory(cwd); } catch (IOException e) { throw new BuildException("Unable to scan FTP server: ", e); } } + protected void scandir(String dir, String vpath, boolean fast) { try { if (!ftp.changeWorkingDirectory(dir)) { @@ -196,6 +197,7 @@ public class FTP } FTPFile[] newfiles = ftp.listFiles(); + if (newfiles == null) { ftp.changeToParentDirectory(); return; @@ -203,8 +205,9 @@ public class FTP for (int i = 0; i < newfiles.length; i++) { FTPFile file = newfiles[i]; - if (!file.getName().equals(".") - && !file.getName().equals("..")) { + + if (!file.getName().equals(".") + && !file.getName().equals("..")) { if (file.isDirectory()) { String name = vpath + file.getName(); if (isIncluded(name)) { @@ -235,6 +238,7 @@ public class FTP } else { if (file.isFile()) { String name = vpath + file.getName(); + if (isIncluded(name)) { if (!isExcluded(name)) { filesIncluded.addElement(name); @@ -251,161 +255,156 @@ public class FTP ftp.changeToParentDirectory(); } catch (IOException e) { throw new BuildException("Error while communicating with FTP " - + "server: ", e); + + "server: ", e); } } } + /** - * Sets the remote directory where files will be placed. This may - * be a relative or absolute path, and must be in the path syntax - * expected by the remote server. No correction of path syntax will - * be performed. + * Sets the remote directory where files will be placed. This may be a + * relative or absolute path, and must be in the path syntax expected by + * the remote server. No correction of path syntax will be performed. */ - public void setRemotedir(String dir) - { + public void setRemotedir(String dir) { this.remotedir = dir; } - /** - * Sets the FTP server to send files to. - */ - public void setServer(String server) - { + + /** Sets the FTP server to send files to. */ + public void setServer(String server) { this.server = server; } - /** - * Sets the FTP port used by the remote server. - */ - public void setPort(int port) - { + + /** Sets the FTP port used by the remote server. */ + public void setPort(int port) { this.port = port; } - /** - * Sets the login user id to use on the specified server. - */ - public void setUserid(String userid) - { + + /** Sets the login user id to use on the specified server. */ + public void setUserid(String userid) { this.userid = userid; } - /** - * Sets the login password for the given user id. - */ - public void setPassword(String password) - { + + /** Sets the login password for the given user id. */ + public void setPassword(String password) { this.password = password; } + /** - * Specifies whether to use binary-mode or text-mode transfers. Set - * to true to send binary mode. Binary mode is enabled by default. + * Specifies whether to use binary-mode or text-mode transfers. Set to + * true to send binary mode. Binary mode is enabled by default. */ - public void setBinary(boolean binary) - { + public void setBinary(boolean binary) { this.binary = binary; } + /** - * Specifies whether to use passive mode. Set to true if you - * are behind a firewall and cannot connect without it. Passive mode - * is disabled by default. + * Specifies whether to use passive mode. Set to true if you are behind a + * firewall and cannot connect without it. Passive mode is disabled by + * default. */ - public void setPassive(boolean passive) - { + public void setPassive(boolean passive) { this.passive = passive; } + /** * Set to true to receive notification about each file as it is * transferred. */ - public void setVerbose(boolean verbose) - { + public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** * Set to true to transmit only files that are new or changed from their - * remote counterparts. The default is to transmit all files. + * remote counterparts. The default is to transmit all files. */ - public void setNewer(boolean newer) - { + public void setNewer(boolean newer) { this.newerOnly = newer; } + /** - * A synonym for setNewer. Set to true to transmit only new or changed + * A synonym for setNewer. Set to true to transmit only new or changed * files. */ - public void setDepends(boolean depends) - { + public void setDepends(boolean depends) { this.newerOnly = depends; } + /** - * Sets the remote file separator character. This normally defaults to - * the Unix standard forward slash, but can be manually overridden using - * this call if the remote server requires some other separator. Only - * the first character of the string is used. + * Sets the remote file separator character. This normally defaults to the + * Unix standard forward slash, but can be manually overridden using this + * call if the remote server requires some other separator. Only the first + * character of the string is used. */ - public void setSeparator(String separator) - { + public void setSeparator(String separator) { remoteFileSep = separator; } + /** * Sets the file permission mode (Unix only) for files sent to the server. - */ + */ public void setChmod(String theMode) { this.chmod = theMode; } - /** - * Sets the default mask for file creation on a unix server. - */ + + /** Sets the default mask for file creation on a unix server. */ public void setUmask(String theUmask) { this.umask = theUmask; } - /** - * Adds a set of files (nested fileset attribute). - */ + + /** Adds a set of files (nested fileset attribute). */ public void addFileset(FileSet set) { filesets.addElement(set); } + /** - * Sets the FTP action to be taken. Currently accepts "put", "get", - * "del", "mkdir" and "list". + * Sets the FTP action to be taken. Currently accepts "put", "get", "del", + * "mkdir" and "list". * * @deprecated setAction(String) is deprecated and is replaced with - * setAction(FTP.Action) to make Ant's Introspection - * mechanism do the work and also to encapsulate operations on - * the type in its own class. + * setAction(FTP.Action) to make Ant's Introspection mechanism do the + * work and also to encapsulate operations on the type in its own + * class. */ public void setAction(String action) throws BuildException { log("DEPRECATED - The setAction(String) method has been deprecated." - + " Use setAction(FTP.Action) instead."); + + " Use setAction(FTP.Action) instead."); + Action a = new Action(); + a.setValue(action); this.action = a.getAction(); } + /** - * Sets the FTP action to be taken. Currently accepts "put", "get", - * "del", "mkdir", "chmod" and "list". + * Sets the FTP action to be taken. Currently accepts "put", "get", "del", + * "mkdir", "chmod" and "list". */ public void setAction(Action action) throws BuildException { this.action = action.getAction(); } + /** - * The output file for the "list" action. This attribute is ignored for + * The output file for the "list" action. This attribute is ignored for * any other actions. */ public void setListing(File listing) throws BuildException { @@ -413,63 +412,56 @@ public class FTP } - /** - * set the failed transfer flag - */ + /** set the failed transfer flag */ public void setSkipFailedTransfers(boolean skipFailedTransfers) { - this.skipFailedTransfers=skipFailedTransfers; + this.skipFailedTransfers = skipFailedTransfers; } + /** * set the flag to skip errors on dir creation (and maybe later other * server specific errors) */ - public void setIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors) { - this.ignoreNoncriticalErrors=ignoreNoncriticalErrors; - } + public void setIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors) { + this.ignoreNoncriticalErrors = ignoreNoncriticalErrors; + } - /** - * Checks to see that all required parameters are set. - */ - protected void checkConfiguration() throws BuildException - { - if (server == null) - { + + /** Checks to see that all required parameters are set. */ + protected void checkConfiguration() throws BuildException { + if (server == null) { throw new BuildException("server attribute must be set!"); } - if (userid == null) - { + if (userid == null) { throw new BuildException("userid attribute must be set!"); } - if (password == null) - { + if (password == null) { throw new BuildException("password attribute must be set!"); } - if ((action == LIST_FILES) && (listing == null)) - { + if ((action == LIST_FILES) && (listing == null)) { throw new BuildException("listing attribute must be set for list " - + "action!"); + + "action!"); } if (action == MK_DIR && remotedir == null) { throw new BuildException("remotedir attribute must be set for " - + "mkdir action!"); + + "mkdir action!"); } if (action == CHMOD && chmod == null) { throw new BuildException("chmod attribute must be set for chmod " - + "action!"); + + "action!"); } } + /** - * For each file in the fileset, do the appropriate action: send, - * get, delete, or list. + * For each file in the fileset, do the appropriate action: send, get, + * delete, or list. */ protected int transferFiles(FTPClient ftp, FileSet fs) - throws IOException, BuildException - { + throws IOException, BuildException { FileScanner ds; if (action == SEND_FILES) { @@ -482,10 +474,11 @@ public class FTP String[] dsfiles = ds.getIncludedFiles(); String dir = null; - if ((ds.getBasedir() == null) - && ((action == SEND_FILES) || (action == GET_FILES))) { + + if ((ds.getBasedir() == null) + && ((action == SEND_FILES) || (action == GET_FILES))) { throw new BuildException("the dir attribute must be set for send " - + "and get actions" ); + + "and get actions"); } else { if ((action == SEND_FILES) || (action == GET_FILES)) { dir = ds.getBasedir().getAbsolutePath(); @@ -494,9 +487,11 @@ public class FTP // If we are doing a listing, we need the output stream created now. BufferedWriter bw = null; + try { if (action == LIST_FILES) { File pd = fileUtils.getParentFile(listing); + if (!pd.exists()) { pd.mkdirs(); } @@ -505,35 +500,41 @@ public class FTP for (int i = 0; i < dsfiles.length; i++) { switch (action) { - case SEND_FILES: { - sendFile(ftp, dir, dsfiles[i]); - break; - } + case SEND_FILES: + { + sendFile(ftp, dir, dsfiles[i]); + break; + } - case GET_FILES: { - getFile(ftp, dir, dsfiles[i]); - break; - } + case GET_FILES: + { + getFile(ftp, dir, dsfiles[i]); + break; + } - case DEL_FILES: { - delFile(ftp, dsfiles[i]); - break; - } - - case LIST_FILES: { - listFile(ftp, bw, dsfiles[i]); - break; - } - - case CHMOD: { - doSiteCommand(ftp, "chmod " + chmod + " " + dsfiles[i]); - transferred++; - break; - } + case DEL_FILES: + { + delFile(ftp, dsfiles[i]); + break; + } - default: { - throw new BuildException("unknown ftp action " + action ); - } + case LIST_FILES: + { + listFile(ftp, bw, dsfiles[i]); + break; + } + + case CHMOD: + { + doSiteCommand(ftp, "chmod " + chmod + " " + dsfiles[i]); + transferred++; + break; + } + + default: + { + throw new BuildException("unknown ftp action " + action); + } } } } finally { @@ -545,128 +546,119 @@ public class FTP return dsfiles.length; } + /** * Sends all files specified by the configured filesets to the remote * server. */ protected void transferFiles(FTPClient ftp) - throws IOException, BuildException - { + throws IOException, BuildException { transferred = 0; - skipped=0; + skipped = 0; - if (filesets.size() == 0) - { + if (filesets.size() == 0) { throw new BuildException("at least one fileset must be specified."); - } - 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) { transferFiles(ftp, fs); } } } log(transferred + " files " + COMPLETED_ACTION_STRS[action]); - if(skipped!=0) { + if (skipped != 0) { log(skipped + " files were not successfully " - + COMPLETED_ACTION_STRS[action]); + + COMPLETED_ACTION_STRS[action]); } } + /** - * Correct a file path to correspond to the remote host requirements. - * This implementation currently assumes that the remote end can - * handle Unix-style paths with forward-slash separators. This can - * be overridden with the separator task parameter. No - * attempt is made to determine what syntax is appropriate for the - * remote host. + * Correct a file path to correspond to the remote host requirements. This + * implementation currently assumes that the remote end can handle + * Unix-style paths with forward-slash separators. This can be overridden + * with the separator task parameter. No attempt is made to + * determine what syntax is appropriate for the remote host. */ - protected String resolveFile(String file) - { + protected String resolveFile(String file) { return file.replace(System.getProperty("file.separator").charAt(0), - remoteFileSep.charAt(0)); + remoteFileSep.charAt(0)); } + /** * Creates all parent directories specified in a complete relative - * pathname. Attempts to create existing directories will not cause + * pathname. Attempts to create existing directories will not cause * errors. */ protected void createParents(FTPClient ftp, String filename) - throws IOException, BuildException - { + throws IOException, BuildException { Vector parents = new Vector(); File dir = new File(filename); String dirname; - while ((dirname = dir.getParent()) != null) - { + while ((dirname = dir.getParent()) != null) { dir = new File(dirname); parents.addElement(dir); } - for (int i = parents.size() - 1; i >= 0; i--) - { - dir = (File)parents.elementAt(i); - if (!dirCache.contains(dir)) - { + for (int i = parents.size() - 1; i >= 0; i--) { + dir = (File) parents.elementAt(i); + if (!dirCache.contains(dir)) { log("creating remote directory " + resolveFile(dir.getPath()), Project.MSG_VERBOSE); ftp.makeDirectory(resolveFile(dir.getPath())); // Both codes 550 and 553 can be produced by FTP Servers // to indicate that an attempt to create a directory has // failed because the directory already exists. - int result=ftp.getReplyCode(); + int result = ftp.getReplyCode(); + if (!FTPReply.isPositiveCompletion(result) && - (result != 550) && (result!= 553) && - !ignoreNoncriticalErrors) - { - throw new BuildException( - "could not create directory: " + - ftp.getReplyString()); + (result != 550) && (result != 553) && + !ignoreNoncriticalErrors) { + throw new BuildException("could not create directory: " + + ftp.getReplyString()); } dirCache.addElement(dir); } } } + /** - * Checks to see if the remote file is current as compared with the - * local file. Returns true if the remote file is up to date. + * Checks to see if the remote file is current as compared with the local + * file. Returns true if the remote file is up to date. */ - protected boolean isUpToDate(FTPClient ftp, File localFile, + protected boolean isUpToDate(FTPClient ftp, File localFile, String remoteFile) - throws IOException, BuildException - { + throws IOException, BuildException { log("checking date for " + remoteFile, Project.MSG_VERBOSE); FTPFile[] files = ftp.listFiles(remoteFile); // For Microsoft's Ftp-Service an Array with length 0 is // returned if configured to return listings in "MS-DOS"-Format - if (files == null || files.length == 0) - { + if (files == null || files.length == 0) { // If we are sending files, then assume out of date. // If we are getting files, then throw an error - if( action == SEND_FILES ) { + if (action == SEND_FILES) { log("Could not date test remote file: " + remoteFile - + "assuming out of date.", Project.MSG_VERBOSE); + + "assuming out of date.", Project.MSG_VERBOSE); return false; } else { throw new BuildException("could not date test remote file: " + - ftp.getReplyString()); + ftp.getReplyString()); } } long remoteTimestamp = files[0].getTimestamp().getTime().getTime(); long localTimestamp = localFile.lastModified(); + if (this.action == SEND_FILES) { return remoteTimestamp > localTimestamp; } else { @@ -674,48 +666,46 @@ public class FTP } } - /** - * Sends a site command to the ftp server - */ + + /** Sends a site command to the ftp server */ protected void doSiteCommand(FTPClient ftp, String TheCMD) - throws IOException, BuildException { + throws IOException, BuildException { boolean rc; String MyReply[] = null; - log("Doing Site Command: " + TheCMD,Project.MSG_VERBOSE); + log("Doing Site Command: " + TheCMD, Project.MSG_VERBOSE); rc = ftp.sendSiteCommand(TheCMD); if (rc == false) { - log("Failed to issue Site Command: " + TheCMD,Project.MSG_WARN); + log("Failed to issue Site Command: " + TheCMD, Project.MSG_WARN); } else { MyReply = ftp.getReplyStrings(); - for (int x=0; x < MyReply.length; x++) { + for (int x = 0; x < MyReply.length; x++) { if (MyReply[x].indexOf("200") == -1) { - log(MyReply[x],Project.MSG_WARN); + log(MyReply[x], Project.MSG_WARN); } } } } + /** - * Sends a single file to the remote host. - * filename may contain a relative path specification. - * When this is the case, sendFile will attempt to create - * any necessary parent directories before sending the file. The file - * will then be sent using the entire relative path spec - no attempt - * is made to change directories. It is anticipated that this may - * eventually cause problems with some FTP servers, but it simplifies - * the coding. + * Sends a single file to the remote host. filename may + * contain a relative path specification. When this is the case, sendFile + * will attempt to create any necessary parent directories before sending + * the file. The file will then be sent using the entire relative path + * spec - no attempt is made to change directories. It is anticipated that + * this may eventually cause problems with some FTP servers, but it + * simplifies the coding. */ protected void sendFile(FTPClient ftp, String dir, String filename) - throws IOException, BuildException - { + throws IOException, BuildException { InputStream instream = null; - try - { + + try { // XXX - why not simply new File(dir, filename)? File file = project.resolveFile(new File(dir, filename).getPath()); @@ -723,8 +713,7 @@ public class FTP return; } - if (verbose) - { + if (verbose) { log("transferring " + file.getAbsolutePath()); } @@ -733,249 +722,226 @@ public class FTP createParents(ftp, filename); ftp.storeFile(resolveFile(filename), instream); - boolean success=FTPReply.isPositiveCompletion(ftp.getReplyCode()); - if (!success) - { - String s="could not put file: " + ftp.getReplyString(); - if(skipFailedTransfers==true) { - log(s,Project.MSG_WARN); + + boolean success = FTPReply.isPositiveCompletion(ftp.getReplyCode()); + + if (!success) { + String s = "could not put file: " + ftp.getReplyString(); + + if (skipFailedTransfers == true) { + log(s, Project.MSG_WARN); skipped++; - } - else { + } else { throw new BuildException(s); } - } - else { - if (chmod != null) { // see if we should issue a chmod command - doSiteCommand(ftp,"chmod " + chmod + " " + filename); + } else { + if (chmod != null) {// see if we should issue a chmod command + doSiteCommand(ftp, "chmod " + chmod + " " + filename); } log("File " + file.getAbsolutePath() + " copied to " + server, Project.MSG_VERBOSE); transferred++; } - } - finally - { - if (instream != null) - { - try - { + } finally { + if (instream != null) { + try { instream.close(); - } - catch(IOException ex) - { + } catch (IOException ex) { // ignore it } } } } - /** - * Delete a file from the remote host. - */ + + /** Delete a file from the remote host. */ protected void delFile(FTPClient ftp, String filename) - throws IOException, BuildException { + throws IOException, BuildException { if (verbose) { log("deleting " + filename); } if (!ftp.deleteFile(resolveFile(filename))) { - String s="could not delete file: " + ftp.getReplyString(); - if(skipFailedTransfers==true) { - log(s,Project.MSG_WARN); + String s = "could not delete file: " + ftp.getReplyString(); + + if (skipFailedTransfers == true) { + log(s, Project.MSG_WARN); skipped++; - } - else { + } else { throw new BuildException(s); } - } - else { + } else { log("File " + filename + " deleted from " + server, Project.MSG_VERBOSE); transferred++; } } + /** - * Retrieve a single file to the remote host. - * filename may contain a relative path specification. + * Retrieve a single file to the remote host. filename may + * contain a relative path specification.

* - *

The file will then be retreived using the entire relative - * path spec - no attempt is made to change directories. It is - * anticipated that this may eventually cause problems with some - * FTP servers, but it simplifies the coding.

+ * The file will then be retreived using the entire relative path spec - + * no attempt is made to change directories. It is anticipated that this + * may eventually cause problems with some FTP servers, but it simplifies + * the coding.

*/ protected void getFile(FTPClient ftp, String dir, String filename) - throws IOException, BuildException - { + throws IOException, BuildException { OutputStream outstream = null; - try - { + + try { File file = project.resolveFile(new File(dir, filename).getPath()); if (newerOnly && isUpToDate(ftp, file, resolveFile(filename))) { return; } - if (verbose) - { - log("transferring " + filename + " to " - + file.getAbsolutePath()); + if (verbose) { + log("transferring " + filename + " to " + + file.getAbsolutePath()); } - File pdir = fileUtils.getParentFile(file); + if (!pdir.exists()) { pdir.mkdirs(); } outstream = new BufferedOutputStream(new FileOutputStream(file)); ftp.retrieveFile(resolveFile(filename), outstream); - if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) - { - String s="could not get file: " + ftp.getReplyString(); - if(skipFailedTransfers==true) { - log(s,Project.MSG_WARN); + if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { + String s = "could not get file: " + ftp.getReplyString(); + + if (skipFailedTransfers == true) { + log(s, Project.MSG_WARN); skipped++; - } - else { + } else { throw new BuildException(s); } - } - else { - log("File " + file.getAbsolutePath() + " copied from " - + server, Project.MSG_VERBOSE); + } else { + log("File " + file.getAbsolutePath() + " copied from " + + server, Project.MSG_VERBOSE); transferred++; } - } - finally - { - if (outstream != null) - { - try - { + } finally { + if (outstream != null) { + try { outstream.close(); - } - catch(IOException ex) - { + } catch (IOException ex) { // ignore it } } } } + /** - * List information about a single file from the remote host. - * filename may contain a relative path specification. + * List information about a single file from the remote host. filename + * may contain a relative path specification.

* - *

The file listing will then be retrieved using the entire - * relative path spec - no attempt is made to change directories. - * It is anticipated that this may eventually cause problems with - * some FTP servers, but it simplifies the coding.

+ * The file listing will then be retrieved using the entire relative path + * spec - no attempt is made to change directories. It is anticipated that + * this may eventually cause problems with some FTP servers, but it + * simplifies the coding.

*/ protected void listFile(FTPClient ftp, BufferedWriter bw, String filename) - throws IOException, BuildException - { + throws IOException, BuildException { if (verbose) { log("listing " + filename); } FTPFile ftpfile = ftp.listFiles(resolveFile(filename))[0]; + bw.write(ftpfile.toString()); bw.newLine(); transferred++; } + /** * Create the specified directory on the remote host. + * * @param ftp The FTP client connection - * @param dir The directory to create (format must be correct for - * host type) + * @param dir The directory to create (format must be correct for host + * type) */ - protected void makeRemoteDir( FTPClient ftp, String dir ) - throws IOException, BuildException - { + protected void makeRemoteDir(FTPClient ftp, String dir) + throws IOException, BuildException { if (verbose) { log("creating directory: " + dir); } - if( ! ftp.makeDirectory( dir ) ) { + if (!ftp.makeDirectory(dir)) { // codes 521, 550 and 553 can be produced by FTP Servers // to indicate that an attempt to create a directory has // failed because the directory already exists. int rc = ftp.getReplyCode(); - if( !(ignoreNoncriticalErrors - && (rc == 550 || rc == 553 || rc==521))) { - throw new BuildException( "could not create directory: " + - ftp.getReplyString() ); + + if (!(ignoreNoncriticalErrors + && (rc == 550 || rc == 553 || rc == 521))) { + throw new BuildException("could not create directory: " + + ftp.getReplyString()); } - if( verbose ) { - log( "directory already exists" ); + if (verbose) { + log("directory already exists"); } } else { - if( verbose ) { - log( "directory created OK" ); + if (verbose) { + log("directory created OK"); } } } - /** - * Runs the task. - */ + + /** Runs the task. */ public void execute() - throws BuildException - { + throws BuildException { checkConfiguration(); FTPClient ftp = null; - try - { + try { log("Opening FTP connection to " + server, Project.MSG_VERBOSE); ftp = new FTPClient(); ftp.connect(server, port); - if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) - { - throw new BuildException("FTP connection failed: " - + ftp.getReplyString()); + if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { + throw new BuildException("FTP connection failed: " + + ftp.getReplyString()); } log("connected", Project.MSG_VERBOSE); log("logging in to FTP server", Project.MSG_VERBOSE); - if (!ftp.login(userid, password)) - { + if (!ftp.login(userid, password)) { throw new BuildException("Could not login to FTP server"); } log("login succeeded", Project.MSG_VERBOSE); - if (binary) - { + if (binary) { ftp.setFileType(com.oroinc.net.ftp.FTP.IMAGE_FILE_TYPE); - if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) - { + if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { throw new BuildException("could not set transfer type: " + - ftp.getReplyString()); + ftp.getReplyString()); } } - if (passive) - { + if (passive) { log("entering passive mode", Project.MSG_VERBOSE); ftp.enterLocalPassiveMode(); - if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) - { + if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { throw new BuildException("could not enter into passive " - + "mode: " + - ftp.getReplyString()); + + "mode: " + + ftp.getReplyString()); } } @@ -989,70 +955,64 @@ public class FTP // If the action is MK_DIR, then the specified remote // directory is the directory to create. - if( action == MK_DIR ) { + if (action == MK_DIR) { - makeRemoteDir( ftp, remotedir ); + makeRemoteDir(ftp, remotedir); } else { - if (remotedir != null) - { + if (remotedir != null) { log("changing the remote directory", Project.MSG_VERBOSE); ftp.changeWorkingDirectory(remotedir); - if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) - { + if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { throw new BuildException("could not change remote " - + "directory: " + - ftp.getReplyString()); + + "directory: " + + ftp.getReplyString()); } } log(ACTION_STRS[action] + " files"); transferFiles(ftp); } - } - catch(IOException ex) - { + } catch (IOException ex) { throw new BuildException("error during FTP transfer: " + ex); - } - finally - { - if (ftp != null && ftp.isConnected()) - { - try - { + } finally { + if (ftp != null && ftp.isConnected()) { + try { log("disconnecting", Project.MSG_VERBOSE); ftp.logout(); ftp.disconnect(); - } - catch(IOException ex) - { + } catch (IOException ex) { // ignore it } } } } + public static class Action extends EnumeratedAttribute { private final static String[] validActions = { - "send", "put", "recv", "get", "del", "delete", "list", "mkdir", + "send", "put", "recv", "get", "del", "delete", "list", "mkdir", "chmod" - }; + }; + public String[] getValues() { return validActions; } + public int getAction() { String actionL = getValue().toLowerCase(Locale.US); + if (actionL.equals("send") || actionL.equals("put")) { return SEND_FILES; } else if (actionL.equals("recv") || - actionL.equals("get")) { + actionL.equals("get")) { return GET_FILES; } else if (actionL.equals("del") || - actionL.equals("delete" )) { + actionL.equals("delete")) { return DEL_FILES; } else if (actionL.equals("list")) { return LIST_FILES; @@ -1065,3 +1025,4 @@ public class FTP } } } + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/MimeMail.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/MimeMail.java index d6b07bbc2..7243bef7f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/MimeMail.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/MimeMail.java @@ -79,7 +79,8 @@ public class MimeMail extends EmailTask public void execute() throws BuildException { - log( "DEPRECATED - The " + getTaskName() + " task is deprecated. Use the mail task instead." ); + log("DEPRECATED - The " + getTaskName() + " task is deprecated. " + + "Use the mail task instead."); super.execute(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java index 3ad9e64af..eeb87453c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java @@ -82,7 +82,7 @@ public class TelnetTask extends Task { /** * The password to login with, if automated login is used */ - private String password= null; + private String password = null; /** * The server to connect to. @@ -123,7 +123,7 @@ public class TelnetTask extends Task { public void execute() throws BuildException { /** A server name is required to continue */ - if (server== null) { + if (server == null) { throw new BuildException("No Server Specified"); } /** A userid and password must appear together @@ -140,8 +140,8 @@ public class TelnetTask extends Task { telnet = new AntTelnetClient(); try { telnet.connect(server, port); - } catch(IOException e) { - throw new BuildException("Can't connect to "+server); + } catch (IOException e) { + throw new BuildException("Can't connect to " + server); } /** Login if userid and password were specified */ if (userid != null && password != null) { @@ -149,11 +149,11 @@ public class TelnetTask extends Task { } /** Process each sub command */ Enumeration tasksToRun = telnetTasks.elements(); - while (tasksToRun!=null && tasksToRun.hasMoreElements()) + while (tasksToRun != null && tasksToRun.hasMoreElements()) { TelnetSubTask task = (TelnetSubTask) tasksToRun.nextElement(); if (task instanceof TelnetRead && defaultTimeout != null) { - ((TelnetRead)task).setDefaultTimeout(defaultTimeout); + ((TelnetRead) task).setDefaultTimeout(defaultTimeout); } task.execute(telnet); } @@ -218,7 +218,7 @@ public class TelnetTask extends Task { public TelnetSubTask createRead() { - TelnetSubTask task = (TelnetSubTask)new TelnetRead(); + TelnetSubTask task = (TelnetSubTask) new TelnetRead(); telnetTasks.addElement(task); return task; } @@ -229,7 +229,7 @@ public class TelnetTask extends Task { */ public TelnetSubTask createWrite() { - TelnetSubTask task = (TelnetSubTask)new TelnetWrite(); + TelnetSubTask task = (TelnetSubTask) new TelnetWrite(); telnetTasks.addElement(task); return task; } @@ -240,7 +240,7 @@ public class TelnetTask extends Task { */ public class TelnetSubTask { - protected String taskString= ""; + protected String taskString = ""; public void execute(AntTelnetClient telnet) throws BuildException { @@ -331,7 +331,7 @@ public class TelnetTask extends Task { */ public void waitForString(String s, Integer timeout) { - InputStream is =this.getInputStream(); + InputStream is = this.getInputStream(); try { StringBuffer sb = new StringBuffer(); if (timeout == null || timeout.intValue() == 0) @@ -344,8 +344,8 @@ public class TelnetTask extends Task { else { Calendar endTime = Calendar.getInstance(); - endTime.add(Calendar.SECOND,timeout.intValue()); - while ( sb.toString().indexOf(s) == -1) + endTime.add(Calendar.SECOND, timeout.intValue()); + while (sb.toString().indexOf(s) == -1) { while (Calendar.getInstance().before(endTime) && is.available() == 0) { @@ -374,7 +374,7 @@ public class TelnetTask extends Task { */ public void sendString(String s, boolean echoString) { - OutputStream os =this.getOutputStream(); + OutputStream os = this.getOutputStream(); try { os.write((s + "\n").getBytes()); if (echoString) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java index 50d537580..dddd7c0d0 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java @@ -90,9 +90,7 @@ public class P4Submit extends P4Base { public void process(String line) { log(line, Project.MSG_VERBOSE); } - } - ); - + }); } else { //here we'd parse the output from change -o into submit -i //in order to support default change. diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java index 4b62b2666..f899c6d6e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java @@ -133,15 +133,16 @@ public class Pvcs extends org.apache.tools.ant.Task { return exe.execute(); } catch (java.io.IOException e) { - String msg = "Failed executing: " + cmd.toString() + ". Exception: "+e.getMessage(); + String msg = "Failed executing: " + cmd.toString() + + ". Exception: " + e.getMessage(); throw new BuildException(msg, location); } } private String getExecutable(String exe) { StringBuffer correctedExe = new StringBuffer(); - if(getPvcsbin()!=null) { - if(pvcsbin.endsWith(File.separator)) { + if (getPvcsbin() != null) { + if (pvcsbin.endsWith(File.separator)) { correctedExe.append(pvcsbin); } else { correctedExe.append(pvcsbin).append(File.separator); @@ -157,7 +158,7 @@ public class Pvcs extends org.apache.tools.ant.Task { Project aProj = getProject(); int result = 0; - if(repository == null || repository.trim().equals("")) { + if (repository == null || repository.trim().equals("")) { throw new BuildException("Required argument repository not specified"); } @@ -171,10 +172,10 @@ public class Pvcs extends org.apache.tools.ant.Task { commandLine.createArgument().setValue("lvf"); commandLine.createArgument().setValue("-z"); commandLine.createArgument().setValue("-aw"); - if(getWorkspace()!=null) { - commandLine.createArgument().setValue("-sp"+getWorkspace()); + if (getWorkspace() != null) { + commandLine.createArgument().setValue("-sp" + getWorkspace()); } - commandLine.createArgument().setValue("-pr"+getRepository()); + commandLine.createArgument().setValue("-pr" + getRepository()); String uid = getUserId(); @@ -183,19 +184,20 @@ public class Pvcs extends org.apache.tools.ant.Task { } // default pvcs project is "/" - if(getPvcsproject() == null && getPvcsprojects().isEmpty()) { + if (getPvcsproject() == null && getPvcsprojects().isEmpty()) { pvcsProject = "/"; } - if(getPvcsproject()!=null) { + if (getPvcsproject() != null) { commandLine.createArgument().setValue(getPvcsproject()); } - if(!getPvcsprojects().isEmpty()) { + if (!getPvcsprojects().isEmpty()) { Enumeration e = getPvcsprojects().elements(); while (e.hasMoreElements()) { - String projectName = ((PvcsProject)e.nextElement()).getName(); + String projectName = ((PvcsProject) e.nextElement()).getName(); if (projectName == null || (projectName.trim()).equals("")) { - throw new BuildException("name is a required attribute of pvcsproject"); + throw new BuildException("name is a required attribute " + + "of pvcsproject"); } commandLine.createArgument().setValue(projectName); } @@ -205,17 +207,21 @@ public class Pvcs extends org.apache.tools.ant.Task { File tmp2 = null; try { Random rand = new Random(System.currentTimeMillis()); - tmp = new File("pvcs_ant_"+rand.nextLong()+".log"); - tmp2 = new File("pvcs_ant_"+rand.nextLong()+".log"); + tmp = new File("pvcs_ant_" + rand.nextLong() + ".log"); + tmp2 = new File("pvcs_ant_" + rand.nextLong() + ".log"); log("Executing " + commandLine.toString(), Project.MSG_VERBOSE); - result = runCmd(commandLine, new PumpStreamHandler(new FileOutputStream(tmp), new LogOutputStream(this,Project.MSG_WARN))); - if ( result != 0 && !ignorerc) { + result = runCmd(commandLine, + new PumpStreamHandler(new FileOutputStream(tmp), + new LogOutputStream(this, Project.MSG_WARN))); + if (result != 0 && !ignorerc) { String msg = "Failed executing: " + commandLine.toString(); throw new BuildException(msg, location); } - if(!tmp.exists()) { - throw new BuildException("Communication between ant and pvcs failed. No output generated from executing PVCS commandline interface \"pcli\" and \"get\""); + if (!tmp.exists()) { + throw new BuildException("Communication between ant and pvcs " + + "failed. No output generated from executing PVCS " + + "commandline interface \"pcli\" and \"get\""); } // Create folders in workspace @@ -229,17 +235,18 @@ public class Pvcs extends org.apache.tools.ant.Task { commandLine.clearArgs(); commandLine.setExecutable(getExecutable(GET_EXE)); - if(getForce()!=null && getForce().equals("yes")) { + if (getForce() != null && getForce().equals("yes")) { commandLine.createArgument().setValue("-Y"); } else { commandLine.createArgument().setValue("-N"); } - if(getPromotiongroup()!=null) { - commandLine.createArgument().setValue("-G"+getPromotiongroup()); + if (getPromotiongroup() != null) { + commandLine.createArgument().setValue("-G" + + getPromotiongroup()); } else { - if(getLabel()!=null) { - commandLine.createArgument().setValue("-r"+getLabel()); + if (getLabel() != null) { + commandLine.createArgument().setValue("-r" + getLabel()); } } @@ -247,24 +254,29 @@ public class Pvcs extends org.apache.tools.ant.Task { commandLine.createArgument().setValue("-U"); } - commandLine.createArgument().setValue("@"+tmp2.getAbsolutePath()); + commandLine.createArgument().setValue("@" + tmp2.getAbsolutePath()); log("Getting files", Project.MSG_INFO); log("Executing " + commandLine.toString(), Project.MSG_VERBOSE); - result = runCmd(commandLine, new LogStreamHandler(this,Project.MSG_INFO, Project.MSG_WARN)); - if ( result != 0 && !ignorerc) { - String msg = "Failed executing: " + commandLine.toString() + ". Return code was "+result; + result = runCmd(commandLine, + new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN)); + if (result != 0 && !ignorerc) { + String msg = "Failed executing: " + commandLine.toString() + + ". Return code was " + result; throw new BuildException(msg, location); } - } catch(FileNotFoundException e) { - String msg = "Failed executing: " + commandLine.toString() + ". Exception: "+e.getMessage(); - throw new BuildException(msg,location); - } catch(IOException e) { - String msg = "Failed executing: " + commandLine.toString() + ". Exception: "+e.getMessage(); - throw new BuildException(msg,location); - } catch(ParseException e) { - String msg = "Failed executing: " + commandLine.toString() + ". Exception: "+e.getMessage(); - throw new BuildException(msg,location); + } catch (FileNotFoundException e) { + String msg = "Failed executing: " + commandLine.toString() + + ". Exception: " + e.getMessage(); + throw new BuildException(msg, location); + } catch (IOException e) { + String msg = "Failed executing: " + commandLine.toString() + + ". Exception: " + e.getMessage(); + throw new BuildException(msg, location); + } catch (ParseException e) { + String msg = "Failed executing: " + commandLine.toString() + + ". Exception: " + e.getMessage(); + throw new BuildException(msg, location); } finally { if (tmp != null) { tmp.delete(); @@ -280,45 +292,50 @@ public class Pvcs extends org.apache.tools.ant.Task { */ private void createFolders(File file) throws IOException, ParseException { BufferedReader in = new BufferedReader(new FileReader(file)); - MessageFormat mf = new MessageFormat( getFilenameFormat() ); + MessageFormat mf = new MessageFormat(getFilenameFormat()); String line = in.readLine(); - while(line != null) { - log("Considering \""+line+"\"", Project.MSG_VERBOSE); - if(line.startsWith("\"\\") || + while (line != null) { + log("Considering \"" + line + "\"", Project.MSG_VERBOSE); + if (line.startsWith("\"\\") || line.startsWith("\"/") || - line.startsWith(getLineStart()) ) { + line.startsWith(getLineStart())) { Object[] objs = mf.parse(line); - String f = (String)objs[1]; + String f = (String) objs[1]; // Extract the name of the directory from the filename int index = f.lastIndexOf(File.separator); if (index > -1) { File dir = new File(f.substring(0, index)); - if(!dir.exists()) { - log("Creating "+dir.getAbsolutePath(), Project.MSG_VERBOSE); - if(dir.mkdirs()) { - log("Created "+dir.getAbsolutePath(), Project.MSG_INFO); + if (!dir.exists()) { + log("Creating " + dir.getAbsolutePath(), + Project.MSG_VERBOSE); + if (dir.mkdirs()) { + log("Created " + dir.getAbsolutePath(), + Project.MSG_INFO); } else { - log("Failed to create "+dir.getAbsolutePath(), Project.MSG_INFO); + log("Failed to create " + dir.getAbsolutePath(), + Project.MSG_INFO); } } else { - log(dir.getAbsolutePath() + " exists. Skipping", Project.MSG_VERBOSE); + log(dir.getAbsolutePath() + " exists. Skipping", + Project.MSG_VERBOSE); } } else { log("File separator problem with " + line, Project.MSG_WARN); } } else { - log("Skipped \""+line+"\"", Project.MSG_VERBOSE); + log("Skipped \"" + line + "\"", Project.MSG_VERBOSE); } line = in.readLine(); } } /** - * Simple hack to handle the PVCS command-line tools botch when handling UNC notation. + * Simple hack to handle the PVCS command-line tools botch when + * handling UNC notation. */ - private void massagePCLI(File in, File out) throws FileNotFoundException, IOException - { + private void massagePCLI(File in, File out) + throws FileNotFoundException, IOException { BufferedReader inReader = new BufferedReader(new FileReader(in)); BufferedWriter outWriter = new BufferedWriter(new FileWriter(out)); String s = null; @@ -432,8 +449,8 @@ public class Pvcs extends org.apache.tools.ant.Task { * @param repo String (yes/no) */ public void setForce(String f) { - if(f!=null && f.equalsIgnoreCase("yes")) { - force="yes"; + if (f != null && f.equalsIgnoreCase("yes")) { + force = "yes"; } else { force = "no"; } @@ -452,7 +469,7 @@ public class Pvcs extends org.apache.tools.ant.Task { * @param repo String */ public void setPromotiongroup(String w) { - promotiongroup=w; + promotiongroup = w; } /** @@ -468,7 +485,7 @@ public class Pvcs extends org.apache.tools.ant.Task { * @param repo String */ public void setLabel(String l) { - label=l; + label = l; } /** @@ -525,12 +542,12 @@ public class Pvcs extends org.apache.tools.ant.Task { workspace = null; repository = null; pvcsbin = null; - force=null; - promotiongroup=null; - label=null; - ignorerc=false; + force = null; + promotiongroup = null; + label = null; + ignorerc = false; updateOnly = false; - lineStart="\"P:"; - filenameFormat="{0}_arc({1})"; + lineStart = "\"P:"; + filenameFormat = "{0}_arc({1})"; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java b/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java index d70fd60a4..772a42aaf 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java @@ -53,7 +53,6 @@ */ package org.apache.tools.ant.taskdefs.optional.scm; - import java.util.StringTokenizer; import com.starbase.starteam.Folder; @@ -114,8 +113,7 @@ import org.apache.tools.ant.Project; * * @ant.task name="starteam" category="scm" */ -public class AntStarTeamCheckOut extends org.apache.tools.ant.Task -{ +public class AntStarTeamCheckOut extends org.apache.tools.ant.Task { /** * This constant sets the filter to include all files. This default has @@ -128,8 +126,8 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task /** * This disables the exclude filter by default. In other words, no files - * are excluded. This setting is equivalent to - * setExcludes(null). + * are excluded. This setting is equivalent to setExcludes(null) + * . * * @see #getExcludes() * @see #setExcludes(String excludes) @@ -137,7 +135,7 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task public final static String DEFAULT_EXCLUDESETTING = null; /** - * The default folder to search; the root folder. Since + * The default folder to search; the root folder. Since * AntStarTeamCheckOut searches subfolders, by default it processes an * entire view. * @@ -152,47 +150,33 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task */ private Folder prevFolder = null; - /** - * This field keeps count of the number of files checked out. - */ + /** This field keeps count of the number of files checked out. */ private int checkedOut = 0; // Change these through their GET and SET methods. - /** - * The name of the server you wish to connect to. - */ + /** The name of the server you wish to connect to. */ private String serverName = null; - /** - * The port on the server used for StarTeam. - */ + /** The port on the server used for StarTeam. */ private int serverPort = -1; - /** - * The name of your project. - */ + /** The name of your project. */ private String projectName = null; /** - * The name of the folder you want to check out files from. All - * subfolders will be searched, as well. + * The name of the folder you want to check out files from. All subfolders + * will be searched, as well. */ private String folderName = DEFAULT_FOLDERSETTING; - /** - * The view that the files you want are in. - */ + /** The view that the files you want are in. */ private String viewName = null; - /** - * Your username on the StarTeam server. - */ + /** Your username on the StarTeam server. */ private String username = null; - /** - * Your StarTeam password. - */ + /** Your StarTeam password. */ private String password = null; /** @@ -214,78 +198,73 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task private boolean verbose = false; /** - * Set recursion to false to check out files in only the given folder - * and not in its subfolders. + * Set recursion to false to check out files in only the given folder and + * not in its subfolders. */ private boolean recursion = true; // These fields deal with includes and excludes - /** - * All files that fit this pattern are checked out. - */ + /** All files that fit this pattern are checked out. */ private String includes = DEFAULT_INCLUDESETTING; - /** - * All files fitting this pattern are ignored. - */ + /** All files fitting this pattern are ignored. */ private String excludes = DEFAULT_EXCLUDESETTING; - /** - * The file delimitor on the user's system. - */ + /** The file delimitor on the user's system. */ private String delim = Platform.getFilePathDelim(); /** - * whether to use the Starteam "default folder" when calculating - * the target paths to which files are checked out (false) or - * if targetFolder represents an absolute mapping to folderName. + * whether to use the Starteam "default folder" when calculating the + * target paths to which files are checked out (false) or if targetFolder + * represents an absolute mapping to folderName. */ private boolean targetFolderAbsolute = false; /** convenient method to check for conditions */ private static void assertTrue(boolean value, String msg) throws BuildException { - if ( !value ) { + if (!value) { throw new BuildException(msg); } } + protected void checkParameters() throws BuildException { // Check all of the properties that are required. - assertTrue( getServerName() != null, "ServerName must be set."); - assertTrue( getServerPort() != -1, "ServerPort must be set."); - assertTrue( getProjectName() != null, "ProjectName must be set."); - assertTrue( getViewName() != null, "ViewName must be set."); - assertTrue( getUsername() != null, "Username must be set."); - assertTrue( getPassword() != null, "Password must be set."); - assertTrue( getTargetFolder() != null, "TargetFolder must be set."); + assertTrue(getServerName() != null, "ServerName must be set."); + assertTrue(getServerPort() != -1, "ServerPort must be set."); + assertTrue(getProjectName() != null, "ProjectName must be set."); + assertTrue(getViewName() != null, "ViewName must be set."); + assertTrue(getUsername() != null, "Username must be set."); + assertTrue(getPassword() != null, "Password must be set."); + assertTrue(getTargetFolder() != null, "TargetFolder must be set."); // Because of the way I create the full target path, there // must be NO slash at the end of targetFolder and folderName // However, if the slash or backslash is the only character, leave it alone if ((getTargetFolder().endsWith("/") || - getTargetFolder().endsWith("\\")) && getTargetFolder().length() > 1) - { + getTargetFolder().endsWith("\\")) + && getTargetFolder().length() > 1) { setTargetFolder(getTargetFolder().substring(0, getTargetFolder().length() - 1)); } // Check to see if the target directory exists. java.io.File dirExist = new java.io.File(getTargetFolder()); - if (dirExist.isDirectory() && !getForce()) - { - throw new BuildException( "Target directory exists. Set \"force\" to \"true\" " + - "to continue anyway." ); + + if (dirExist.isDirectory() && !getForce()) { + throw new BuildException("Target directory exists. Set \"force\" " + + "to \"true\" to continue anyway."); } } + /** * Do the execution. * * @exception BuildException */ - public void execute() throws BuildException - { + public void execute() throws BuildException { log("DEPRECATED - The starteam task is deprecated. Use stcheckout instead.", Project.MSG_WARN); @@ -307,13 +286,13 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task log(checkedOut + " files checked out."); } + /** * Creates and logs in to a StarTeam server. * * @return A StarTeam server. */ - protected Server getServer() - { + protected Server getServer() { // Simplest constructor, uses default encryption algorithm and compression level. Server s = new Server(getServerName(), getServerPort()); @@ -326,22 +305,20 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task return s; } + /** * Searches for the specified project on the server. * - * @param s A StarTeam server. + * @param s A StarTeam server. */ - protected void runServer(Server s) - { + protected void runServer(Server s) { com.starbase.starteam.Project[] projects = s.getProjects(); - for (int i = 0; i < projects.length; i++) - { + + for (int i = 0; i < projects.length; i++) { com.starbase.starteam.Project p = projects[i]; - if (p.getName().equals(getProjectName())) - { - if (getVerbose()) - { + if (p.getName().equals(getProjectName())) { + if (getVerbose()) { log("Found " + getProjectName() + delim); } runProject(s, p); @@ -350,22 +327,21 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task } } + /** * Searches for the given view in the project. * - * @param s A StarTeam server. - * @param p A valid project on the given server. + * @param s A StarTeam server. + * @param p A valid project on the given server. */ - protected void runProject(Server s, com.starbase.starteam.Project p) - { + protected void runProject(Server s, com.starbase.starteam.Project p) { View[] views = p.getViews(); - for (int i = 0; i < views.length; i++) - { + + for (int i = 0; i < views.length; i++) { View v = views[i]; - if (v.getName().equals(getViewName())) - { - if (getVerbose()) - { + + if (v.getName().equals(getViewName())) { + if (getVerbose()) { log("Found " + getProjectName() + delim + getViewName() + delim); } runType(s, p, v, s.typeForName(s.getTypeNames().FILE)); @@ -374,38 +350,33 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task } } + /** * Searches for folders in the given view. * - * @param s A StarTeam server. - * @param p A valid project on the server. - * @param v A view name from the specified project. - * @param t An item type which is currently always "file". + * @param s A StarTeam server. + * @param p A valid project on the server. + * @param v A view name from the specified project. + * @param t An item type which is currently always "file". */ - protected void runType(Server s, com.starbase.starteam.Project p, View v, Type t) - { + protected void runType(Server s, com.starbase.starteam.Project p, View v, Type t) { // This is ugly; checking for the root folder. Folder f = v.getRootFolder(); - if ( getFolderName() != null ) - { - if (getFolderName().equals("\\") || getFolderName().equals("/")) - { + + if (getFolderName() != null) { + if (getFolderName().equals("\\") || getFolderName().equals("/")) { setFolderName(null); - } - else - { + } else { f = StarTeamFinder.findFolder(v.getRootFolder(), getFolderName()); - assertTrue(null != f,"ERROR: " + getProjectName() + delim + getViewName() + delim + - v.getRootFolder() + delim + getFolderName() + delim + - " does not exist."); + assertTrue(null != f, "ERROR: " + getProjectName() + delim + getViewName() + delim + + v.getRootFolder() + delim + getFolderName() + delim + + " does not exist."); } } - - if ( getVerbose() && getFolderName() != null ) - { - log( "Found " + getProjectName() + delim + getViewName() + - delim + getFolderName() + delim + "\n" ); + if (getVerbose() && getFolderName() != null) { + log("Found " + getProjectName() + delim + getViewName() + + delim + getFolderName() + delim + "\n"); } // For performance reasons, it is important to pre-fetch all the @@ -420,18 +391,18 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task // Does this item type have a secondary descriptor? // If so, we'll need it. Property p2 = getSecondaryDescriptor(t); - if (p2 != null) - { + + if (p2 != null) { nProperties++; } // Now, build an array of the property names. String[] strNames = new String[nProperties]; int iProperty = 0; + strNames[iProperty++] = s.getPropertyNames().OBJECT_ID; strNames[iProperty++] = p1.getName(); - if (p2 != null) - { + if (p2 != null) { strNames[iProperty++] = p2.getName(); } @@ -439,148 +410,147 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task f.populateNow(t.getName(), strNames, -1); // Now, search for items in the selected folder. - runFolder(s, p, v, t, f, calcTargetFolder(v,f)); + runFolder(s, p, v, t, f, calcTargetFolder(v, f)); // Free up the memory used by the cached items. f.discardItems(t.getName(), -1); } + /** * Returns a file object that defines the root of the local checkout tree. - * Depending on the value of targetFolderAbsolute, this will be either - * the targetFolder exactly as set by the user or the path formed by appending + * Depending on the value of targetFolderAbsolute, this will be either the + * targetFolder exactly as set by the user or the path formed by appending * the default folder onto the specified target folder. * - * @param v view from which the file is checked out, supplies the "default folder" - * @param rootSourceFolder root folder of the checkout operation in Star Team + * @param v view from which the file is checked out, supplies the "default + * folder" + * @param rootSourceFolder root folder of the checkout operation in Star + * Team * @return an object referencing the local file * @see #getTargetFolderAbsolute() */ - private java.io.File calcTargetFolder(View v, Folder rootSourceFolder) - { - java.io.File root = new java.io.File(getTargetFolder()); - if (!getTargetFolderAbsolute()) - { - // Create a variable dir that contains the name of - // the StarTeam folder that is the root folder in this view. - // Get the default path to the current view. + private java.io.File calcTargetFolder(View v, Folder rootSourceFolder) { + java.io.File root = new java.io.File(getTargetFolder()); + + if (!getTargetFolderAbsolute()) { + // Create a variable dir that contains the name of + // the StarTeam folder that is the root folder in this view. + // Get the default path to the current view. String defaultPath = v.getDefaultPath(); - // convert whatever separator char is in starteam to that of the target system. - defaultPath=defaultPath.replace('/', java.io.File.separatorChar); - defaultPath=defaultPath.replace('\\', java.io.File.separatorChar); + // convert whatever separator char is in starteam to that of the target system. + defaultPath = defaultPath.replace('/', java.io.File.separatorChar); + defaultPath = defaultPath.replace('\\', java.io.File.separatorChar); - java.io.File dir = new java.io.File(defaultPath); - String dirName = dir.getName(); + java.io.File dir = new java.io.File(defaultPath); + String dirName = dir.getName(); // If it ends with separator then strip it off - if (dirName.endsWith(delim)) - { - dirName = dirName.substring(0, dirName.length()-1); - } + if (dirName.endsWith(delim)) { + dirName = dirName.substring(0, dirName.length() - 1); + } - // Replace the projectName in the file's absolute path to the viewName. - // This makes the root target of a checkout operation equal to: - // targetFolder + dirName - StringTokenizer pathTokenizer = new StringTokenizer(rootSourceFolder.getFolderHierarchy(), delim); - String currentToken = null; - boolean foundRoot = false; - while (pathTokenizer.hasMoreTokens()) - { - currentToken = pathTokenizer.nextToken(); - if (currentToken.equals(getProjectName()) && !foundRoot) - { - currentToken = dirName; - foundRoot = true; // only want to do this the first time - } - root = new java.io.File(root, currentToken); + // Replace the projectName in the file's absolute path to the viewName. + // This makes the root target of a checkout operation equal to: + // targetFolder + dirName + StringTokenizer pathTokenizer = new StringTokenizer(rootSourceFolder.getFolderHierarchy(), delim); + String currentToken = null; + boolean foundRoot = false; + + while (pathTokenizer.hasMoreTokens()) { + currentToken = pathTokenizer.nextToken(); + if (currentToken.equals(getProjectName()) && !foundRoot) { + currentToken = dirName; + foundRoot = true;// only want to do this the first time + } + root = new java.io.File(root, currentToken); + } } - } return root; } + /** - * Searches for files in the given folder. This method is recursive and + * Searches for files in the given folder. This method is recursive and * thus searches all subfolders. * - * @param s A StarTeam server. - * @param p A valid project on the server. - * @param v A view name from the specified project. - * @param t An item type which is currently always "file". - * @param f The folder to search. - * @param tgt Target folder on local machine + * @param s A StarTeam server. + * @param p A valid project on the server. + * @param v A view name from the specified project. + * @param t An item type which is currently always "file". + * @param f The folder to search. + * @param tgt Target folder on local machine */ - protected void runFolder( Server s, - com.starbase.starteam.Project p, - View v, - Type t, - Folder f, - java.io.File tgt ) - { + protected void runFolder(Server s, + com.starbase.starteam.Project p, + View v, + Type t, + Folder f, + java.io.File tgt) { // Process all items in this folder. Item[] items = f.getItems(t.getName()); - for (int i = 0; i < items.length; i++) - { + + for (int i = 0; i < items.length; i++) { runItem(s, p, v, t, f, items[i], tgt); } // Process all subfolders recursively if recursion is on. - if (getRecursion()) - { + if (getRecursion()) { Folder[] subfolders = f.getSubFolders(); - for (int i = 0; i < subfolders.length; i++) - { + + for (int i = 0; i < subfolders.length; i++) { runFolder(s, p, v, t, subfolders[i], new java.io.File(tgt, subfolders[i].getName())); } } } + /** - * Check out one file if it matches the include filter but not the - * exclude filter. + * Check out one file if it matches the include filter but not the exclude + * filter. * - * @param s A StarTeam server. - * @param p A valid project on the server. - * @param v A view name from the specified project. - * @param t An item type which is currently always "file". - * @param f The folder the file is localed in. - * @param item The file to check out. - * @param tgt target folder on local machine + * @param s A StarTeam server. + * @param p A valid project on the server. + * @param v A view name from the specified project. + * @param t An item type which is currently always "file". + * @param f The folder the file is localed in. + * @param item The file to check out. + * @param tgt target folder on local machine */ - protected void runItem( Server s, - com.starbase.starteam.Project p, - View v, - Type t, - Folder f, - Item item, - java.io.File tgt ) - { + protected void runItem(Server s, + com.starbase.starteam.Project p, + View v, + Type t, + Folder f, + Item item, + java.io.File tgt) { // Get descriptors for this item type. Property p1 = getPrimaryDescriptor(t); Property p2 = getSecondaryDescriptor(t); - String pName = (String)item.get(p1.getName()); - if ( !shouldCheckout(pName) ) { + String pName = (String) item.get(p1.getName()); + + if (!shouldCheckout(pName)) { return; } // VERBOSE MODE ONLY - if (getVerbose()) - { + if (getVerbose()) { // Show folder only if changed. boolean bShowHeader = (f != prevFolder); - if (bShowHeader) - { + + if (bShowHeader) { // We want to display the folder the same way you would // enter it on the command line ... so we remove the // View name (which is also the name of the root folder, // and therefore shows up at the start of the path). String strFolder = f.getFolderHierarchy(); int i = strFolder.indexOf(delim); - if (i >= 0) - { - strFolder = strFolder.substring(i+1); + + if (i >= 0) { + strFolder = strFolder.substring(i + 1); } log(" Folder: \"" + strFolder + "\""); prevFolder = f; @@ -588,9 +558,9 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task // If we displayed the project, view, item type, or folder, // then show the list of relevant item properties. StringBuffer header = new StringBuffer(" Item"); + header.append(",\t").append(p1.getDisplayName()); - if (p2 != null) - { + if (p2 != null) { header.append(",\t").append(p2.getDisplayName()); } log(header.toString()); @@ -599,6 +569,7 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task // Finally, show the Item properties ... // Always show the ItemID. StringBuffer itemLine = new StringBuffer(" "); + itemLine.append(item.getItemID()); // Show the primary descriptor. @@ -607,19 +578,16 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task // Show the secondary descriptor, if there is one. // Some item types have one, some don't. - if (p2 != null) - { + if (p2 != null) { itemLine.append(",\t").append(formatForDisplay(p2, item.get(p2.getName()))); } // Show if the file is locked. int locker = item.getLocker(); - if (locker>-1) - { + + if (locker > -1) { itemLine.append(",\tLocked by ").append(locker); - } - else - { + } else { itemLine.append(",\tNot locked"); } log(itemLine.toString()); @@ -629,128 +597,122 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task // Check it out; also ugly. // Change the item to be checked out to a StarTeam File. - com.starbase.starteam.File remote = (com.starbase.starteam.File)item; + com.starbase.starteam.File remote = (com.starbase.starteam.File) item; // The local file name is simply the local target path (tgt) which has - // been passed recursively down from the top of the tree, with the item's name appended. - java.io.File local = new java.io.File(tgt,(String)item.get(p1.getName())); + // been passed recursively down from the top of the tree, with the item's name appended. + java.io.File local = new java.io.File(tgt, (String) item.get(p1.getName())); - try - { + try { remote.checkoutTo(local, Item.LockType.UNCHANGED, false, true, true); checkedOut++; - } - catch (Exception e) - { + } catch (Exception e) { throw new BuildException("Failed to checkout '" + local + "'", e); } } + /** - * Look if the file should be checked out. Don't check it out - * if It fits no include filters and It fits an exclude filter. + * Look if the file should be checked out. Don't check it out if It fits + * no include filters and It fits an exclude filter. + * * @param pName the item name to look for being included. * @return whether the file should be checked out or not. */ - protected boolean shouldCheckout(String pName){ + protected boolean shouldCheckout(String pName) { boolean includeIt = matchPatterns(getIncludes(), pName); boolean excludeIt = matchPatterns(getExcludes(), pName); + return (includeIt && !excludeIt); } + /** - * Convenient method to see if a string match a one pattern - * in given set of space-separated patterns. + * Convenient method to see if a string match a one pattern in given set + * of space-separated patterns. + * * @param patterns the space-separated list of patterns. * @param pName the name to look for matching. * @return whether the name match at least one pattern. */ - protected boolean matchPatterns(String patterns, String pName){ - if (patterns == null){ + protected boolean matchPatterns(String patterns, String pName) { + if (patterns == null) { return false; } StringTokenizer exStr = new StringTokenizer(patterns, " "); - while (exStr.hasMoreTokens()) - { - if (DirectoryScanner.match(exStr.nextToken(), pName)) - { + + while (exStr.hasMoreTokens()) { + if (DirectoryScanner.match(exStr.nextToken(), pName)) { return true; } } return false; } + /** - * Get the primary descriptor of the given item type. - * Returns null if there isn't one. - * In practice, all item types have a primary descriptor. + * Get the primary descriptor of the given item type. Returns null if + * there isn't one. In practice, all item types have a primary descriptor. * - * @param t An item type. At this point it will always be "file". + * @param t An item type. At this point it will always be "file". * @return The specified item's primary descriptor. */ - protected Property getPrimaryDescriptor(Type t) - { + protected Property getPrimaryDescriptor(Type t) { Property[] properties = t.getProperties(); - for (int i = 0; i < properties.length; i++) - { + + for (int i = 0; i < properties.length; i++) { Property p = properties[i]; - if (p.isPrimaryDescriptor()) - { + + if (p.isPrimaryDescriptor()) { return p; } } return null; } + /** - * Get the secondary descriptor of the given item type. - * Returns null if there isn't one. + * Get the secondary descriptor of the given item type. Returns null if + * there isn't one. * - * @param t An item type. At this point it will always be "file". - * @return The specified item's secondary descriptor. There may not be - * one for every file. + * @param t An item type. At this point it will always be "file". + * @return The specified item's secondary descriptor. There may not be one + * for every file. */ - protected Property getSecondaryDescriptor(Type t) - { + protected Property getSecondaryDescriptor(Type t) { Property[] properties = t.getProperties(); - for (int i = 0; i < properties.length; i++) - { + + for (int i = 0; i < properties.length; i++) { Property p = properties[i]; - if (p.isDescriptor() && !p.isPrimaryDescriptor()) - { + + if (p.isDescriptor() && !p.isPrimaryDescriptor()) { return p; } } return null; } + /** * Formats a property value for display to the user. * - * @param p An item property to format. + * @param p An item property to format. * @param value * @return A string containing the property, which is truncated to 35 - * characters for display. + * characters for display. */ - protected String formatForDisplay(Property p, Object value) - { - if (p.getTypeCode() == Property.Types.TEXT) - { + protected String formatForDisplay(Property p, Object value) { + if (p.getTypeCode() == Property.Types.TEXT) { String str = value.toString(); - if (str.length() > 35) - { + + if (str.length() > 35) { str = str.substring(0, 32) + "..."; } return "\"" + str + "\""; - } - else - { - if (p.getTypeCode() == Property.Types.ENUMERATED) - { - return "\"" + p.getEnumDisplayName(((Integer)value).intValue()) + "\""; - } - else - { + } else { + if (p.getTypeCode() == Property.Types.ENUMERATED) { + return "\"" + p.getEnumDisplayName(((Integer) value).intValue()) + "\""; + } else { return value.toString(); } } @@ -764,399 +726,389 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task * @param serverName The name of the server you wish to connect to. * @see #getServerName() */ - public void setServerName(String serverName) - { + public void setServerName(String serverName) { this.serverName = serverName; } + /** * Gets the serverName attribute. * * @return The StarTeam server to log in to. * @see #setServerName(String serverName) */ - public String getServerName() - { + public String getServerName() { return serverName; } + /** * Sets the serverPort attribute to the given value. The * given value must be a valid integer, but it must be a string object. * * @param serverPort A string containing the port on the StarTeam server - * to use. + * to use. * @see #getServerPort() */ - public void setServerPort(int serverPort) - { + public void setServerPort(int serverPort) { this.serverPort = serverPort; } + /** * Gets the serverPort attribute. * * @return A string containing the port on the StarTeam server to use. * @see #setServerPort(int) */ - public int getServerPort() - { + public int getServerPort() { return serverPort; } + /** * Sets the projectName attribute to the given value. * - * @param projectName - * The StarTeam project to search. + * @param projectName The StarTeam project to search. * @see #getProjectName() */ - public void setProjectName(String projectName) - { + public void setProjectName(String projectName) { this.projectName = projectName; } + /** * Gets the projectName attribute. * * @return The StarTeam project to search. * @see #setProjectName(String projectName) */ - public String getProjectName() - { + public String getProjectName() { return projectName; } + /** * Sets the viewName attribute to the given value. * * @param viewName The view to find the specified folder in. * @see #getViewName() */ - public void setViewName(String viewName) - { + public void setViewName(String viewName) { this.viewName = viewName; } + /** * Gets the viewName attribute. * * @return The view to find the specified folder in. * @see #setViewName(String viewName) */ - public String getViewName() - { + public String getViewName() { return viewName; } + /** * Sets the folderName attribute to the given value. To - * search the root folder, use a slash or backslash, or simply don't set - * a folder at all. + * search the root folder, use a slash or backslash, or simply don't set a + * folder at all. * * @param folderName The subfolder from which to check out files. * @see #getFolderName() */ - public void setFolderName(String folderName) - { + public void setFolderName(String folderName) { this.folderName = folderName; } + /** * Gets the folderName attribute. * * @return The subfolder from which to check out files. All subfolders - * will be searched, as well. + * will be searched, as well. * @see #setFolderName(String folderName) */ - public String getFolderName() - { + public String getFolderName() { return folderName; } + /** * Sets the username attribute to the given value. * * @param username Your username for the specified StarTeam server. * @see #getUsername() */ - public void setUsername(String username) - { + public void setUsername(String username) { this.username = username; } + /** * Gets the username attribute. * * @return The username given by the user. * @see #setUsername(String username) */ - public String getUsername() - { + public String getUsername() { return username; } + /** * Sets the password attribute to the given value. * * @param password Your password for the specified StarTeam server. * @see #getPassword() */ - public void setPassword(String password) - { + public void setPassword(String password) { this.password = password; } + /** * Gets the password attribute. * * @return The password given by the user. * @see #setPassword(String password) */ - public String getPassword() - { + public String getPassword() { return password; } + /** * Sets the targetFolder attribute to the given value. * * @param target The target path on the local machine to check out to. * @see #getTargetFolder() */ - public void setTargetFolder(String targetFolder) - { + public void setTargetFolder(String targetFolder) { this.targetFolder = targetFolder; } + /** * Gets the targetFolder attribute. * * @return The target path on the local machine to check out to. - * * @see #setTargetFolder(String targetFolder) */ - public String getTargetFolder() - { + public String getTargetFolder() { return targetFolder; } + /** * Sets the force attribute to the given value. * - * @param force if true, it overwrites files in the target - * directory. By default it set to false as a safeguard. - * Note that if the target directory does not exist, this - * setting has no effect. + * @param force if true, it overwrites files in the target directory. By + * default it set to false as a safeguard. Note that if the target + * directory does not exist, this setting has no effect. * @see #getForce() */ - public void setForce(boolean force) - { + public void setForce(boolean force) { this.force = force; } + /** * Gets the force attribute. * * @return whether to continue if the target directory exists. * @see #setForce(boolean) */ - public boolean getForce() - { + public boolean getForce() { return force; } + /** * Turns recursion on or off. * * @param recursion if it is true, the default, subfolders are searched - * recursively for files to check out. Otherwise, only - * files specified by folderName are scanned. + * recursively for files to check out. Otherwise, only files + * specified by folderName are scanned. * @see #getRecursion() */ - public void setRecursion(boolean recursion) - { + public void setRecursion(boolean recursion) { this.recursion = recursion; } + /** * Gets the recursion attribute, which tells * AntStarTeamCheckOut whether to search subfolders when checking out * files. * * @return whether to search subfolders when checking out files. - * * @see #setRecursion(boolean) */ - public boolean getRecursion() - { + public boolean getRecursion() { return recursion; } + /** * Sets the verbose attribute to the given value. * - * @param verbose whether to display all files as it checks them out. - * By default it is false, so the - * program only displays the total number of files unless - * you override this default. + * @param verbose whether to display all files as it checks them out. By + * default it is false, so the program only displays the total number + * of files unless you override this default. * @see #getVerbose() */ - public void setVerbose(boolean verbose) - { + public void setVerbose(boolean verbose) { this.verbose = verbose; } + /** * Gets the verbose attribute. * * @return whether to display all files as it checks them out. * @see #setVerbose(boolean verbose) */ - public boolean getVerbose() - { + public boolean getVerbose() { return verbose; } // Begin filter getters and setters /** - * Sets the include filter. When filtering files, AntStarTeamCheckOut - * uses an unmodified version of DirectoryScanner's - * match method, so here are the patterns straight from the - * Ant source code: - *

+ * Sets the include filter. When filtering files, AntStarTeamCheckOut uses + * an unmodified version of DirectoryScanner's match + * method, so here are the patterns straight from the Ant source code: + *
+ *
* Matches a string against a pattern. The pattern contains two special - * characters: - *
'*' which means zero or more characters, - *
'?' which means one and only one character. - *

- * Separate multiple inlcude filters by spaces, not commas as Ant + * characters:
+ * '*' which means zero or more characters,
+ * '?' which means one and only one character.
+ *
+ * Separate multiple inlcude filters by spaces , not commas as Ant * uses. For example, if you want to check out all .java and .class\ - * files, you would put the following line in your program: - * setIncludes("*.java *.class"); + * files, you would put the following line in your program: setIncludes("*.java *.class"); * Finally, note that filters have no effect on the directories * that are scanned; you could not check out files from directories with - * names beginning only with "build," for instance. Of course, you - * could limit AntStarTeamCheckOut to a particular folder and its - * subfolders with the setFolderName(String folderName) - * command. - *

+ * names beginning only with "build," for instance. Of course, you could + * limit AntStarTeamCheckOut to a particular folder and its subfolders + * with the setFolderName(String folderName) command.
+ *
* Treatment of overlapping inlcudes and excludes: To give a simplistic - * example suppose that you set your include filter to "*.htm *.html" - * and your exclude filter to "index.*". What happens to index.html? + * example suppose that you set your include filter to "*.htm *.html" and + * your exclude filter to "index.*". What happens to index.html? * AntStarTeamCheckOut will not check out index.html, as it matches an - * exclude filter ("index.*"), even though it matches the include - * filter, as well. - *

+ * exclude filter ("index.*"), even though it matches the include filter, + * as well.
+ *
* Please also read the following sections before using filters: * * @param includes A string of filter patterns to include. Separate the - * patterns by spaces. + * patterns by spaces. * @see #getIncludes() * @see #setExcludes(String excludes) * @see #getExcludes() */ - public void setIncludes(String includes) - { + public void setIncludes(String includes) { this.includes = includes; } + /** * Gets the patterns from the include filter. Rather that duplicate the - * details of AntStarTeanCheckOut's filtering here, refer to these - * links: + * details of AntStarTeanCheckOut's filtering here, refer to these links: * * @return A string of filter patterns separated by spaces. * @see #setIncludes(String includes) * @see #setExcludes(String excludes) * @see #getExcludes() */ - public String getIncludes() - { + public String getIncludes() { return includes; } + /** - * Sets the exclude filter. When filtering files, AntStarTeamCheckOut - * uses an unmodified version of DirectoryScanner's - * match method, so here are the patterns straight from the - * Ant source code: - *

+ * Sets the exclude filter. When filtering files, AntStarTeamCheckOut uses + * an unmodified version of DirectoryScanner's match + * method, so here are the patterns straight from the Ant source code: + *
+ *
* Matches a string against a pattern. The pattern contains two special - * characters: - *
'*' which means zero or more characters, - *
'?' which means one and only one character. - *

- * Separate multiple exlcude filters by spaces, not commas as Ant + * characters:
+ * '*' which means zero or more characters,
+ * '?' which means one and only one character.
+ *
+ * Separate multiple exlcude filters by spaces , not commas as Ant * uses. For example, if you want to check out all files except .XML and - * .HTML files, you would put the following line in your program: - * setExcludes("*.XML *.HTML"); + * .HTML files, you would put the following line in your program: setExcludes("*.XML *.HTML"); * Finally, note that filters have no effect on the directories * that are scanned; you could not skip over all files in directories - * whose names begin with "project," for instance. - *

+ * whose names begin with "project," for instance.
+ *
* Treatment of overlapping inlcudes and excludes: To give a simplistic - * example suppose that you set your include filter to "*.htm *.html" - * and your exclude filter to "index.*". What happens to index.html? + * example suppose that you set your include filter to "*.htm *.html" and + * your exclude filter to "index.*". What happens to index.html? * AntStarTeamCheckOut will not check out index.html, as it matches an - * exclude filter ("index.*"), even though it matches the include - * filter, as well. - *

+ * exclude filter ("index.*"), even though it matches the include filter, + * as well.
+ *
* Please also read the following sections before using filters: * * @param excludes A string of filter patterns to exclude. Separate the - * patterns by spaces. + * patterns by spaces. * @see #setIncludes(String includes) * @see #getIncludes() * @see #getExcludes() */ - public void setExcludes(String excludes) - { + public void setExcludes(String excludes) { this.excludes = excludes; } + /** * Gets the patterns from the exclude filter. Rather that duplicate the - * details of AntStarTeanCheckOut's filtering here, refer to these - * links: + * details of AntStarTeanCheckOut's filtering here, refer to these links: * * @return A string of filter patterns separated by spaces. * @see #setExcludes(String excludes) * @see #setIncludes(String includes) * @see #getIncludes() */ - public String getExcludes() - { + public String getExcludes() { return excludes; } /** - * returns whether the StarTeam default path is factored into - * calculated target path locations (false) or whether - * targetFolder is an absolute mapping to the root folder - * named by folderName + * returns whether the StarTeam default path is factored into calculated + * target path locations (false) or whether targetFolder is an absolute + * mapping to the root folder named by folderName * - * @return returns true if absolute mapping is used, false if it is - * not used. + * @return returns true if absolute mapping is used, false if it is not + * used. * @see #setTargetFolderAbsolute(boolean) */ - public boolean getTargetFolderAbsolute() - { + public boolean getTargetFolderAbsolute() { return this.targetFolderAbsolute; } + + /** - * sets the property that indicates whether or not the Star Team - * "default folder" is to be used when calculation paths for items on - * the target (false) or if targetFolder is an absolute mapping to the - * root folder named by foldername. + * sets the property that indicates whether or not the Star Team "default + * folder" is to be used when calculation paths for items on the target + * (false) or if targetFolder is an absolute mapping to the root folder + * named by foldername. * - * @param targetFolderAbsolute true if the absolute mapping is to be used. - * false (the default) if the "default folder" is to be factored in. + * @param targetFolderAbsolute true if the absolute mapping is to + * be used. false (the default) if the "default folder" is + * to be factored in. * @see #getTargetFolderAbsolute() */ public void setTargetFolderAbsolute(boolean targetFolderAbsolute) { this.targetFolderAbsolute = targetFolderAbsolute; } } + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java index 24b8b438d..14c7ff69a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java @@ -141,7 +141,8 @@ public class AntSoundPlayer implements LineListener, BuildListener { audioInputStream = AudioSystem.getAudioInputStream(file); } catch (UnsupportedAudioFileException uafe) { - project.log("Audio format is not yet supported: "+uafe.getMessage()); + project.log("Audio format is not yet supported: " + + uafe.getMessage()); } catch (IOException ioe) { ioe.printStackTrace(); @@ -229,7 +230,7 @@ public class AntSoundPlayer implements LineListener, BuildListener { if (event.getException() == null && fileSuccess != null) { // build successfull! play(event.getProject(), fileSuccess, loopsSuccess, durationSuccess); - } else if ( event.getException() != null && fileFail != null) { + } else if (event.getException() != null && fileFail != null) { play(event.getProject(), fileFail, loopsFail, durationFail); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java index 4f9f0cc8c..bc68c2589 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sound/SoundTask.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -107,7 +107,7 @@ public class SoundTask extends Task { AntSoundPlayer soundPlayer = new AntSoundPlayer(); - if ( success == null ) { + if (success == null) { log("No nested success element found.", Project.MSG_WARN); } else { soundPlayer.addBuildSuccessfulSound(success.getSource(), @@ -165,18 +165,18 @@ public class SoundTask extends Task { public File getSource() { File nofile = null ; // Check if source is a directory - if( source.exists() ) { - if( source.isDirectory() ) { + if (source.exists()) { + if (source.isDirectory()) { // get the list of files in the dir String[] entries = source.list() ; Vector files = new Vector() ; - for (int i=0 ; i < entries.length ; i++) { + for (int i = 0 ; i < entries.length ; i++) { File f = new File(source, entries[i]) ; if (f.isFile()) { files.addElement(f) ; } } - if ( files.size() < 1 ) { + if (files.size() < 1) { throw new BuildException("No files found in directory " + source); } int numfiles = files.size() ; @@ -184,7 +184,7 @@ public class SoundTask extends Task { Random rn = new Random() ; int x = rn.nextInt(numfiles) ; // set the source to the file at that location - this.source = (File)files.elementAt(x) ; + this.source = (File) files.elementAt(x); } } else { log(source + ": invalid path.", Project.MSG_WARN) ; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java index 9b8606524..754cdac2d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java @@ -90,15 +90,15 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { protected void init(ImageIcon img) { - JPanel pan = (JPanel)getContentPane(); + JPanel pan = (JPanel) getContentPane(); JLabel piccy; - if(img == null ) { + if (img == null) { piccy = new JLabel(); } else { piccy = new JLabel(img); } - piccy.setBorder(BorderFactory.createLineBorder(Color.black,1)); + piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1)); text = new JLabel("Building....", JLabel.CENTER); text.setFont(new Font("Sans-Serif", Font.BOLD, 12)); text.setBorder(BorderFactory.createEtchedBorder()); @@ -108,8 +108,8 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { JPanel pan2 = new JPanel(); pan2.setLayout(new BorderLayout()); - pan2.add(text,BorderLayout.NORTH); - pan2.add(pb,BorderLayout.SOUTH); + pan2.add(text, BorderLayout.NORTH); + pan2.add(pb, BorderLayout.SOUTH); pan.setLayout(new BorderLayout()); pan.add(piccy, BorderLayout.CENTER); @@ -121,9 +121,9 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { Dimension size = getSize(); Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); - int x = (scr.width - size.width) /2; - int y = (scr.height - size.height) /2; - setBounds(x,y,size.width, size.height); + int x = (scr.width - size.width) / 2; + int y = (scr.height - size.height) / 2; + setBounds(x, y, size.width, size.height); } public void setText(String txt) { @@ -131,7 +131,7 @@ class SplashScreen extends JWindow implements ActionListener, BuildListener { } public void actionPerformed(ActionEvent a) { - if(total < max) { + if (total < max) { total++; } else { total = min; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java index f8d637e75..edbdeaee2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java @@ -101,7 +101,7 @@ public class SplashTask extends Task { public void execute() throws BuildException { - if (splash != null ) { + if (splash != null) { splash.setVisible(false); getProject().removeBuildListener(splash); splash.dispose(); @@ -112,10 +112,10 @@ public class SplashTask extends Task { InputStream in = null; if (imgurl != null) { - try{ + try { URLConnection conn = null; - if(useProxy && + if (useProxy && (proxy != null && proxy.length() > 0) && (port != null && port.length() > 0)) { @@ -129,7 +129,7 @@ public class SplashTask extends Task { conn = url.openConnection(); if (user != null && user.length() > 0) { String encodedcreds = - new sun.misc.BASE64Encoder().encode((new String(user+":"+password)).getBytes()); + new sun.misc.BASE64Encoder().encode((new String(user + ":" + password)).getBytes()); conn.setRequestProperty("Proxy-Authorization", encodedcreds); } @@ -150,9 +150,11 @@ public class SplashTask extends Task { // Catch everything - some of the above return nulls, throw exceptions or generally misbehave // in the event of a problem etc - } catch(Throwable ioe) { - log("Unable to download image, trying default Ant Logo", Project.MSG_DEBUG); - log("(Exception was \""+ioe.getMessage()+"\"", Project.MSG_DEBUG); + } catch (Throwable ioe) { + log("Unable to download image, trying default Ant Logo", + Project.MSG_DEBUG); + log("(Exception was \"" + ioe.getMessage() + "\"", + Project.MSG_DEBUG); } } @@ -160,14 +162,14 @@ public class SplashTask extends Task { in = SplashTask.class.getClassLoader().getResourceAsStream("images/ant_logo_large.gif"); } - if(in != null) { + if (in != null) { DataInputStream din = new DataInputStream(in); boolean success = false; try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); int data; - while((data = din.read()) != -1) { - bout.write((byte)data); + while ((data = din.read()) != -1) { + bout.write((byte) data); } log("Got ByteArray, creating splash", Project.MSG_DEBUG); @@ -175,7 +177,7 @@ public class SplashTask extends Task { splash = new SplashScreen(img); success = true; - } catch(Exception e) { + } catch (Exception e) { throw new BuildException(e); } finally { try { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java index 60606fc41..c6f6f4d62 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java @@ -250,7 +250,7 @@ public abstract class StarTeamTask extends Task { this.servername + ":" + this.serverport + "/" + this.projectname + "/" + - ((null == this.viewname)?"":this.viewname); + ((null == this.viewname) ? "" : this.viewname); } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java b/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java index 67e884ea9..72d49f6c1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/vss/MSVSS.java @@ -99,7 +99,7 @@ public abstract class MSVSS extends Task { */ public final String getSSCommand() { String toReturn = m_SSDir; - if ( !toReturn.equals("") && !toReturn.endsWith("\\") ) { + if (!toReturn.equals("") && !toReturn.endsWith("\\")) { toReturn += "\\"; } toReturn += SS_EXE; @@ -122,7 +122,7 @@ public abstract class MSVSS extends Task { * @return the appropriate login command if the 'login' attribute was specified, otherwise an empty string */ public void getLoginCommand(Commandline cmd) { - if ( m_vssLogin == null ) { + if (m_vssLogin == null) { return; } else { cmd.createArgument().setValue(FLAG_LOGIN + m_vssLogin); @@ -138,8 +138,8 @@ public abstract class MSVSS extends Task { * @param vssPath */ public final void setVsspath(String vssPath) { - if ( vssPath.startsWith("vss://") ) { - m_vssPath= PROJECT_PREFIX + vssPath.substring(5); + if (vssPath.startsWith("vss://")) { + m_vssPath = PROJECT_PREFIX + vssPath.substring(5); } else { m_vssPath = PROJECT_PREFIX + vssPath; } @@ -171,11 +171,11 @@ public abstract class MSVSS extends Task { // environment-variable SSDIR to this value if (m_serverPath != null) { String[] env = exe.getEnvironment(); - if( env == null ) { + if (env == null) { env = new String[0]; } - String[] newEnv = new String[env.length+1]; - for( int i=0;i 0) { setExecutable(tmp[0]); - for (int i=1; iaddValue or the argument object. */ public String[] getArguments() { - Vector result = new Vector(arguments.size()*2); - for (int i=0; i -1) { throw new BuildException("Can\'t handle single and double quotes in same argument"); } else { - return '\''+argument+'\''; + return '\'' + argument + '\''; } } else if (argument.indexOf("\'") > -1 || argument.indexOf(" ") > -1) { - return '\"'+argument+'\"'; + return '\"' + argument + '\"'; } else { return argument; } @@ -321,7 +321,7 @@ public class Commandline implements Cloneable { // path containing one or more elements final StringBuffer result = new StringBuffer(); - for (int i=0; i < line.length; i++) { + for (int i = 0; i < line.length; i++) { if (i > 0) { result.append(' '); } diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index 8579fb961..64d172343 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -112,11 +112,11 @@ public class CommandlineJava implements Cloneable { try { sys = System.getProperties(); Properties p = new Properties(); - for (Enumeration e = sys.keys(); e.hasMoreElements(); ) { + for (Enumeration e = sys.keys(); e.hasMoreElements();) { Object o = e.nextElement(); p.put(o, sys.get(o)); } - for (Enumeration e = variables.elements(); e.hasMoreElements(); ) { + for (Enumeration e = variables.elements(); e.hasMoreElements();) { Environment.Variable v = (Environment.Variable) e.nextElement(); p.put(v.getKey(), v.getValue()); } @@ -144,7 +144,9 @@ public class CommandlineJava implements Cloneable { SysProperties c = (SysProperties) super.clone(); c.variables = (Vector) variables.clone(); return c; - } catch(CloneNotSupportedException e){return null;} + } catch (CloneNotSupportedException e) { + return null; + } } } @@ -282,7 +284,7 @@ public class CommandlineJava implements Cloneable { } private Commandline getActualVMCommand() { - Commandline actualVMCommand = (Commandline)vmCommand.clone(); + Commandline actualVMCommand = (Commandline) vmCommand.clone(); if (maxMemory != null) { if (vmVersion.startsWith("1.1")) { actualVMCommand.createArgument().setValue("-mx" + maxMemory); diff --git a/src/main/org/apache/tools/ant/types/DataType.java b/src/main/org/apache/tools/ant/types/DataType.java index be36b7e23..52874f3c1 100644 --- a/src/main/org/apache/tools/ant/types/DataType.java +++ b/src/main/org/apache/tools/ant/types/DataType.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -95,8 +95,8 @@ public abstract class DataType extends ProjectComponent { * Sets a description of the current data type. It will be useful * in commenting what we are doing. */ - public void setDescription( String desc ) { - description=desc; + public void setDescription(String desc) { + description = desc; } /** @@ -175,7 +175,7 @@ public abstract class DataType extends ProjectComponent { Object o = ref.getReferencedObject(getProject()); if (!(requiredClass.isAssignableFrom(o.getClass()))) { - String msg = ref.getRefId()+" doesn\'t denote a " + dataTypeName; + String msg = ref.getRefId() + " doesn\'t denote a " + dataTypeName; throw new BuildException(msg); } else { return o; @@ -187,8 +187,8 @@ public abstract class DataType extends ProjectComponent { * only attribute if it is set. */ protected BuildException tooManyAttributes() { - return new BuildException( "You must not specify more than one attribute" + - " when using refid" ); + return new BuildException("You must not specify more than one " + + "attribute when using refid"); } /** @@ -196,7 +196,8 @@ public abstract class DataType extends ProjectComponent { * not have child elements if the refid attribute is set. */ protected BuildException noChildrenAllowed() { - return new BuildException("You must not specify nested elements when using refid"); + return new BuildException("You must not specify nested elements " + + "when using refid"); } /** @@ -204,6 +205,7 @@ public abstract class DataType extends ProjectComponent { * loop of data types referencing each other. */ protected BuildException circularReference() { - return new BuildException("This data type contains a circular reference."); + return new BuildException("This data type contains a circular " + + "reference."); } } diff --git a/src/main/org/apache/tools/ant/types/Environment.java b/src/main/org/apache/tools/ant/types/Environment.java index 104633eec..b49266fbb 100644 --- a/src/main/org/apache/tools/ant/types/Environment.java +++ b/src/main/org/apache/tools/ant/types/Environment.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000,2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -120,7 +120,7 @@ public class Environment { return null; } String[] result = new String[variables.size()]; - for (int i=0; i " + value, Project.MSG_VERBOSE ); + value = (String) tokens.get(token); + log("Replacing: " + beginToken + token + endToken + + " -> " + value, Project.MSG_VERBOSE); b.append(value); - i = index + beginToken.length() + token.length() + endToken.length(); + i = index + beginToken.length() + token.length() + + endToken.length(); } else { // just append beginToken and search further b.append(beginToken); i = index + beginToken.length(); } - } while ((index = line.indexOf( beginToken, i )) > -1 ); + } while ((index = line.indexOf(beginToken, i)) > -1); b.append(line.substring(i)); return b.toString(); diff --git a/src/main/org/apache/tools/ant/types/FilterSetCollection.java b/src/main/org/apache/tools/ant/types/FilterSetCollection.java index be543b81c..cbae7e094 100644 --- a/src/main/org/apache/tools/ant/types/FilterSetCollection.java +++ b/src/main/org/apache/tools/ant/types/FilterSetCollection.java @@ -101,7 +101,7 @@ public class FilterSetCollection { public String replaceTokens(String line) { String replacedLine = line; for (Enumeration e = filterSets.elements(); e.hasMoreElements();) { - FilterSet filterSet = (FilterSet)e.nextElement(); + FilterSet filterSet = (FilterSet) e.nextElement(); replacedLine = filterSet.replaceTokens(replacedLine); } return replacedLine; @@ -114,7 +114,7 @@ public class FilterSetCollection { */ public boolean hasFilters() { for (Enumeration e = filterSets.elements(); e.hasMoreElements();) { - FilterSet filterSet = (FilterSet)e.nextElement(); + FilterSet filterSet = (FilterSet) e.nextElement(); if (filterSet.hasFilters()) { return true; } diff --git a/src/main/org/apache/tools/ant/types/Mapper.java b/src/main/org/apache/tools/ant/types/Mapper.java index e8399077d..70afa1dd8 100644 --- a/src/main/org/apache/tools/ant/types/Mapper.java +++ b/src/main/org/apache/tools/ant/types/Mapper.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -233,7 +233,7 @@ public class Mapper extends DataType implements Cloneable { Object o = ref.getReferencedObject(getProject()); if (!(o instanceof Mapper)) { - String msg = ref.getRefId()+" doesn\'t denote a mapper"; + String msg = ref.getRefId() + " doesn\'t denote a mapper"; throw new BuildException(msg); } else { return (Mapper) o; diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index 880226b3e..359ae6240 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -241,7 +241,7 @@ public class Path extends DataType implements Cloneable { return; } String[] l = other.list(); - for (int i=0; i"); + throw new BuildException("You must either set location or" + + " path on "); } - for (int j=0; j= 0) { // Pull in *.zip from packages directory FileSet msZipFiles = new FileSet(); - msZipFiles.setDir(new File(System.getProperty("java.home") + File.separator + "Packages")); + msZipFiles.setDir(new File(System.getProperty("java.home") + + File.separator + "Packages")); msZipFiles.setIncludes("*.ZIP"); addFileset(msZipFiles); - } else if("Kaffe".equals(System.getProperty("java.vm.name"))) { + } else if ("Kaffe".equals(System.getProperty("java.vm.name"))) { FileSet kaffeJarFiles = new FileSet(); kaffeJarFiles.setDir(new File(System.getProperty("java.home") + File.separator + "share" @@ -599,7 +602,7 @@ public class Path extends DataType implements Cloneable { // sort it out. addExisting(new Path(null, System.getProperty("java.home") - + File.separator +"jre" + + File.separator + "jre" + File.separator + "lib" + File.separator + "rt.jar")); @@ -635,7 +638,7 @@ public class Path extends DataType implements Cloneable { } String[] dirs = extdirs.list(); - for (int i=0; i 0) { tmpNames.addElement(pattern); @@ -436,7 +436,7 @@ public class PatternSet extends DataType { if (includesFileList.size() > 0) { Enumeration e = includesFileList.elements(); while (e.hasMoreElements()) { - NameEntry ne = (NameEntry)e.nextElement(); + NameEntry ne = (NameEntry) e.nextElement(); String fileName = ne.evalName(p); if (fileName != null) { File inclFile = p.resolveFile(fileName); @@ -454,7 +454,7 @@ public class PatternSet extends DataType { if (excludesFileList.size() > 0) { Enumeration e = excludesFileList.elements(); while (e.hasMoreElements()) { - NameEntry ne = (NameEntry)e.nextElement(); + NameEntry ne = (NameEntry) e.nextElement(); String fileName = ne.evalName(p); if (fileName != null) { File exclFile = p.resolveFile(fileName); diff --git a/src/main/org/apache/tools/ant/types/Reference.java b/src/main/org/apache/tools/ant/types/Reference.java index 45e23bfe0..548c130dc 100644 --- a/src/main/org/apache/tools/ant/types/Reference.java +++ b/src/main/org/apache/tools/ant/types/Reference.java @@ -90,7 +90,7 @@ public class Reference { Object o = project.getReference(refid); if (o == null) { - throw new BuildException("Reference "+refid+" not found."); + throw new BuildException("Reference " + refid + " not found."); } return o; } diff --git a/src/main/org/apache/tools/ant/types/RegularExpression.java b/src/main/org/apache/tools/ant/types/RegularExpression.java index 13325e9d4..9afeee202 100644 --- a/src/main/org/apache/tools/ant/types/RegularExpression.java +++ b/src/main/org/apache/tools/ant/types/RegularExpression.java @@ -153,7 +153,8 @@ public class RegularExpression extends DataType Object o = ref.getReferencedObject(p); if (!(o instanceof RegularExpression)) { - String msg = ref.getRefId() + " doesn\'t denote a "+DATA_TYPE_NAME; + String msg = ref.getRefId() + " doesn\'t denote a " + + DATA_TYPE_NAME; throw new BuildException(msg); } else diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java index 83ebd2c83..6316f37a3 100644 --- a/src/main/org/apache/tools/ant/types/XMLCatalog.java +++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java @@ -228,7 +228,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver { log("No match, parser will use: '" + systemId + "'", Project.MSG_DEBUG); } - } catch ( IOException ioe) { + } catch (IOException ioe) { //ignore } } @@ -254,7 +254,7 @@ public class XMLCatalog extends DataType implements Cloneable, EntityResolver { Enumeration elements = getElements().elements(); DTDLocation element = null; while (elements.hasMoreElements()) { - element = (DTDLocation)elements.nextElement(); + element = (DTDLocation) elements.nextElement(); if (element.getPublicId().equals(publicId)) { return element; } diff --git a/src/main/org/apache/tools/ant/types/ZipFileSet.java b/src/main/org/apache/tools/ant/types/ZipFileSet.java index 99452c3d6..618e3a721 100644 --- a/src/main/org/apache/tools/ant/types/ZipFileSet.java +++ b/src/main/org/apache/tools/ant/types/ZipFileSet.java @@ -196,7 +196,7 @@ public class ZipFileSet extends FileSet { Object o = ref.getReferencedObject(p); if (!(o instanceof FileSet)) { - String msg = ref.getRefId()+" doesn\'t denote a fileset"; + String msg = ref.getRefId() + " doesn\'t denote a fileset"; throw new BuildException(msg); } else { return (AbstractFileSet) o; diff --git a/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java b/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java index eb7982e0e..0a5b319e5 100644 --- a/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java +++ b/src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java @@ -132,7 +132,7 @@ public class ClassfileSet extends FileSet { */ protected ClassfileSet(ClassfileSet s) { super(s); - rootClasses = (Vector)s.rootClasses.clone(); + rootClasses = (Vector) s.rootClasses.clone(); } /** @@ -156,9 +156,9 @@ public class ClassfileSet extends FileSet { return getRef(p).getDirectoryScanner(p); } - Vector allRootClasses = (Vector)rootClasses.clone(); + Vector allRootClasses = (Vector) rootClasses.clone(); for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) { - FileSet additionalRootSet = (FileSet)e.nextElement(); + FileSet additionalRootSet = (FileSet) e.nextElement(); DirectoryScanner additionalScanner = additionalRootSet.getDirectoryScanner(p); String[] files = additionalScanner.getIncludedFiles(); diff --git a/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java b/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java index 3800c831e..50e5cc3f7 100644 --- a/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java +++ b/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.java @@ -145,7 +145,7 @@ public class DependScanner extends DirectoryScanner { int count = included.size(); String[] files = new String[count]; for (int i = 0; i < count; i++) { - files[i] = (String)included.elementAt(i); + files[i] = (String) included.elementAt(i); } return files; } @@ -161,7 +161,7 @@ public class DependScanner extends DirectoryScanner { DependencyAnalyzer analyzer = null; try { Class analyzerClass = Class.forName(analyzerClassName); - analyzer = (DependencyAnalyzer)analyzerClass.newInstance(); + analyzer = (DependencyAnalyzer) analyzerClass.newInstance(); } catch (Exception e) { throw new BuildException("Unable to load dependency analyzer: " + analyzerClassName, e); @@ -169,7 +169,7 @@ public class DependScanner extends DirectoryScanner { analyzer.addClassPath(new Path(null, basedir.getPath())); for (Enumeration e = rootClasses.elements(); e.hasMoreElements();) { - String rootClass = (String)e.nextElement(); + String rootClass = (String) e.nextElement(); analyzer.addRootClass(rootClass); } @@ -182,7 +182,7 @@ public class DependScanner extends DirectoryScanner { } while (e.hasMoreElements()) { - String classname = (String)e.nextElement(); + String classname = (String) e.nextElement(); String filename = classname.replace('.', File.separatorChar); filename = filename + ".class"; File depFile = new File(basedir, filename); diff --git a/src/main/org/apache/tools/ant/util/DOMElementWriter.java b/src/main/org/apache/tools/ant/util/DOMElementWriter.java index a1765b71e..217ceb61e 100644 --- a/src/main/org/apache/tools/ant/util/DOMElementWriter.java +++ b/src/main/org/apache/tools/ant/util/DOMElementWriter.java @@ -151,7 +151,7 @@ public class DOMElementWriter { out.write(lSep); hasChildren = true; } - write((Element)child, out, indent + 1, indentWith); + write((Element) child, out, indent + 1, indentWith); break; case Node.TEXT_NODE: @@ -160,7 +160,7 @@ public class DOMElementWriter { case Node.CDATA_SECTION_NODE: out.write(""); break; @@ -174,7 +174,7 @@ public class DOMElementWriter { out.write(" 0 ) { + if (data != null && data.length() > 0) { out.write(' '); out.write(data); } @@ -206,7 +206,7 @@ public class DOMElementWriter { */ public String encode(String value) { sb.setLength(0); - for (int i=0; iSee XML 1.0 2.2 http://www.w3.org/TR/1998/REC-xml-19980210#charsets.

+ * href="http://www.w3.org/TR/1998/REC-xml-19980210#charsets"> + * http://www.w3.org/TR/1998/REC-xml-19980210#charsets.

* * @since 1.10, Ant 1.5 */ diff --git a/src/main/org/apache/tools/ant/util/DateUtils.java b/src/main/org/apache/tools/ant/util/DateUtils.java index 45a7fcf10..b5ec73236 100644 --- a/src/main/org/apache/tools/ant/util/DateUtils.java +++ b/src/main/org/apache/tools/ant/util/DateUtils.java @@ -212,7 +212,7 @@ public final class DateUtils { */ public static int getPhaseOfMoon(Calendar cal) { int dayOfTheYear = cal.get(Calendar.DAY_OF_YEAR); - int yearInMetonicCycle = ((cal.get(Calendar.YEAR)-1900) % 19) + 1; + int yearInMetonicCycle = ((cal.get(Calendar.YEAR) - 1900) % 19) + 1; int epact = (11 * yearInMetonicCycle + 18) % 30; if ((epact == 25 && yearInMetonicCycle > 11) || epact == 24) { epact++; diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 417c25761..c6209a797 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -489,13 +489,10 @@ public class FileUtils { // deal with absolute files if (!onNetWare) { - if (filename.startsWith(File.separator) || - - (filename.length() >= 2 && - Character.isLetter(filename.charAt(0)) && - filename.charAt(1) == ':') - - ) { + if (filename.startsWith(File.separator) + || (filename.length() >= 2 + && Character.isLetter(filename.charAt(0)) + && filename.charAt(1) == ':')) { return normalize(filename); } } else { @@ -503,9 +500,8 @@ public class FileUtils { // the path name breaks down when NetWare is a supported platform. // Netware volumes are of the pattern: "data:\" int colon = filename.indexOf(":"); - if (filename.startsWith(File.separator) || - (colon > -1) - ) { + if (filename.startsWith(File.separator) + || (colon > -1)) { return normalize(filename); } } @@ -562,17 +558,15 @@ public class FileUtils { if (!onNetWare) { if (!path.startsWith(File.separator) && - ! (path.length() >= 2 && + !(path.length() >= 2 && Character.isLetter(path.charAt(0)) && - colon == 1) - ) { + colon == 1)) { String msg = path + " is not an absolute path"; throw new BuildException(msg); } } else { - if (!path.startsWith(File.separator) && - (colon == -1) - ) { + if (!path.startsWith(File.separator) + && (colon == -1)) { String msg = path + " is not an absolute path"; throw new BuildException(msg); } @@ -585,8 +579,7 @@ public class FileUtils { path.length() >= 2 && Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') || - (onNetWare && colon > -1) - ) { + (onNetWare && colon > -1)) { dosWithDrive = true; @@ -603,10 +596,9 @@ public class FileUtils { // Eliminate consecutive slashes after the drive spec StringBuffer sbPath = new StringBuffer(); - for (int i = colon+1; i < ca.length; i++) { + for (int i = colon + 1; i < ca.length; i++) { if ((ca[i] != '\\') || - (ca[i] == '\\' && ca[i - 1] != '\\') - ) { + (ca[i] == '\\' && ca[i - 1] != '\\')) { sbPath.append(ca[i]); } } @@ -618,7 +610,7 @@ public class FileUtils { path = ""; } else if (path.charAt(1) == File.separatorChar) { // UNC drive - root = File.separator+File.separator; + root = File.separator + File.separator; path = path.substring(2); } else { root = File.separator; @@ -635,7 +627,7 @@ public class FileUtils { continue; } else if ("..".equals(thisToken)) { if (s.size() < 2) { - throw new BuildException("Cannot resolve path "+orig); + throw new BuildException("Cannot resolve path " + orig); } else { s.pop(); } @@ -645,7 +637,7 @@ public class FileUtils { } StringBuffer sb = new StringBuffer(); - for (int i=0; i 1) { // not before the filesystem root and not after it, since root // already contains one diff --git a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java index d2ca22a77..0e78fb3a2 100644 --- a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java +++ b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000,2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -109,7 +109,7 @@ public class GlobPatternMapper implements FileNameMapper { fromPostfix = ""; } else { fromPrefix = from.substring(0, index); - fromPostfix = from.substring(index+1); + fromPostfix = from.substring(index + 1); } prefixLength = fromPrefix.length(); postfixLength = fromPostfix.length(); @@ -125,7 +125,7 @@ public class GlobPatternMapper implements FileNameMapper { toPostfix = ""; } else { toPrefix = to.substring(0, index); - toPostfix = to.substring(index+1); + toPostfix = to.substring(index + 1); } } diff --git a/src/main/org/apache/tools/ant/util/LoaderUtils.java b/src/main/org/apache/tools/ant/util/LoaderUtils.java index 042e60ee6..0b903c244 100644 --- a/src/main/org/apache/tools/ant/util/LoaderUtils.java +++ b/src/main/org/apache/tools/ant/util/LoaderUtils.java @@ -124,7 +124,7 @@ public class LoaderUtils { try { Thread currentThread = Thread.currentThread(); - return (ClassLoader)getContextClassLoader.invoke(currentThread, + return (ClassLoader) getContextClassLoader.invoke(currentThread, new Object[0]); } catch (IllegalAccessException e) { throw new BuildException diff --git a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java index 694ff624d..bf1fd158d 100644 --- a/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java +++ b/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000,2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -118,7 +118,7 @@ public class RegexpPatternMapper implements FileNameMapper { Vector v = reg.getGroups(source); result.setLength(0); - for (int i=0; i now) { - task.log("Warning: "+files[i]+" modified in the future.", + task.log("Warning: " + files[i] + " modified in the future.", Project.MSG_WARN); } boolean added = false; targetList.setLength(0); - for (int j=0; !added && j dest.lastModified()) { - task.log(files[i]+" added as "+dest.getAbsolutePath()+" is outdated.", - Project.MSG_VERBOSE); + task.log(files[i] + " added as " + dest.getAbsolutePath() + + " is outdated.", Project.MSG_VERBOSE); v.addElement(files[i]); added = true; } else { @@ -155,7 +155,7 @@ public class SourceFileScanner { } if (!added) { - task.log(files[i]+" omitted as "+targetList.toString() + task.log(files[i] + " omitted as " + targetList.toString() + (targets.length == 1 ? " is" : " are ") + " up to date.", Project.MSG_VERBOSE); } @@ -175,7 +175,7 @@ public class SourceFileScanner { FileNameMapper mapper) { String[] res = restrict(files, srcDir, destDir, mapper); File[] result = new File[res.length]; - for (int i=0; i '9') { + if (magic3 != 'h' || magic4 < '1' || magic4 > '9') { bsFinishedWithStream(); streamEnd = true; return; @@ -316,11 +316,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int zzi; char thech = 0; try { - thech = (char)bsStream.read(); - } catch(IOException e) { + thech = (char) bsStream.read(); + } catch (IOException e) { compressedStreamEOF(); } - if(thech == -1) { + if (thech == -1) { compressedStreamEOF(); } zzi = thech; @@ -329,13 +329,13 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } } - v = (bsBuff >> (bsLive-n)) & ((1 << n)-1); + v = (bsBuff >> (bsLive - n)) & ((1 << n) - 1); bsLive -= n; return v; } private char bsGetUChar() { - return (char)bsR(8); + return (char) bsR(8); } private int bsGetint() { @@ -348,11 +348,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } private int bsGetIntVS(int numBits) { - return (int)bsR(numBits); + return (int) bsR(numBits); } private int bsGetInt32() { - return (int)bsGetint(); + return (int) bsGetint(); } private void hbCreateDecodeTables(int[] limit, int[] base, @@ -361,8 +361,8 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int pp, i, j, vec; pp = 0; - for(i = minLen; i <= maxLen; i++) { - for(j = 0; j < alphaSize; j++) { + for (i = minLen; i <= maxLen; i++) { + for (j = 0; j < alphaSize; j++) { if (length[j] == i) { perm[pp] = j; pp++; @@ -370,15 +370,15 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } }; - for(i = 0; i < MAX_CODE_LEN; i++) { + for (i = 0; i < MAX_CODE_LEN; i++) { base[i] = 0; } - for(i = 0; i < alphaSize; i++) { - base[length[i]+1]++; + for (i = 0; i < alphaSize; i++) { + base[length[i] + 1]++; } - for(i = 1; i < MAX_CODE_LEN; i++) { - base[i] += base[i-1]; + for (i = 1; i < MAX_CODE_LEN; i++) { + base[i] += base[i - 1]; } for (i = 0; i < MAX_CODE_LEN; i++) { @@ -387,12 +387,12 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { vec = 0; for (i = minLen; i <= maxLen; i++) { - vec += (base[i+1] - base[i]); - limit[i] = vec-1; + vec += (base[i + 1] - base[i]); + limit[i] = vec - 1; vec <<= 1; } for (i = minLen + 1; i <= maxLen; i++) { - base[i] = ((limit[i-1] + 1) << 1) - base[i]; + base[i] = ((limit[i - 1] + 1) << 1) - base[i]; } } @@ -426,7 +426,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } makeMaps(); - alphaSize = nInUse+2; + alphaSize = nInUse + 2; /* Now the selectors */ nGroups = bsR(3); @@ -436,7 +436,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { while (bsR(1) == 1) { j++; } - selectorMtf[i] = (char)j; + selectorMtf[i] = (char) j; } /* Undo the MTF values for the selectors. */ @@ -451,7 +451,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { v = selectorMtf[i]; tmp = pos[v]; while (v > 0) { - pos[v] = pos[v-1]; + pos[v] = pos[v - 1]; v--; } pos[0] = tmp; @@ -461,7 +461,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { /* Now the coding tables */ for (t = 0; t < nGroups; t++) { - int curr = bsR ( 5 ); + int curr = bsR(5); for (i = 0; i < alphaSize; i++) { while (bsR(1) == 1) { if (bsR(1) == 0) { @@ -470,7 +470,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { curr--; } } - len[t][i] = (char)curr; + len[t][i] = (char) curr; } } @@ -501,7 +501,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { origPtr = bsGetIntVS(24); recvDecodingTables(); - EOB = nInUse+1; + EOB = nInUse + 1; groupNo = -1; groupPos = 0; @@ -539,11 +539,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int zzi; char thech = 0; try { - thech = (char)bsStream.read(); - } catch(IOException e) { + thech = (char) bsStream.read(); + } catch (IOException e) { compressedStreamEOF(); } - if(thech == -1) { + if (thech == -1) { compressedStreamEOF(); } zzi = thech; @@ -551,7 +551,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { bsLive += 8; } } - zj = (bsBuff >> (bsLive-1)) & 1; + zj = (bsBuff >> (bsLive - 1)) & 1; bsLive--; } zvec = (zvec << 1) | zj; @@ -559,7 +559,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { nextSym = perm[zt][zvec - base[zt][zn]]; } - while(true) { + while (true) { if (nextSym == EOB) { break; @@ -571,9 +571,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int N = 1; do { if (nextSym == RUNA) { - s = s + (0+1) * N; + s = s + (0 + 1) * N; } else if (nextSym == RUNB) { - s = s + (1+1) * N; + s = s + (1 + 1) * N; } N = N * 2; { @@ -594,11 +594,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int zzi; char thech = 0; try { - thech = (char)bsStream.read(); - } catch(IOException e) { + thech = (char) bsStream.read(); + } catch (IOException e) { compressedStreamEOF(); } - if(thech == -1) { + if (thech == -1) { compressedStreamEOF(); } zzi = thech; @@ -606,7 +606,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { bsLive += 8; } } - zj = (bsBuff >> (bsLive-1)) & 1; + zj = (bsBuff >> (bsLive - 1)) & 1; bsLive--; } zvec = (zvec << 1) | zj; @@ -636,7 +636,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { blockOverrun(); } - tmp = yy[nextSym-1]; + tmp = yy[nextSym - 1]; unzftab[seqToUnseq[tmp]]++; ll8[last] = seqToUnseq[tmp]; @@ -647,15 +647,15 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { for (j = nextSym-1; j > 0; j--) yy[j] = yy[j-1]; */ - j = nextSym-1; + j = nextSym - 1; for (; j > 3; j -= 4) { - yy[j] = yy[j-1]; - yy[j-1] = yy[j-2]; - yy[j-2] = yy[j-3]; - yy[j-3] = yy[j-4]; + yy[j] = yy[j - 1]; + yy[j - 1] = yy[j - 2]; + yy[j - 2] = yy[j - 3]; + yy[j - 3] = yy[j - 4]; } for (; j > 0; j--) { - yy[j] = yy[j-1]; + yy[j] = yy[j - 1]; } yy[0] = tmp; @@ -677,8 +677,8 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int zzi; char thech = 0; try { - thech = (char)bsStream.read(); - } catch(IOException e) { + thech = (char) bsStream.read(); + } catch (IOException e) { compressedStreamEOF(); } zzi = thech; @@ -686,7 +686,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { bsLive += 8; } } - zj = (bsBuff >> (bsLive-1)) & 1; + zj = (bsBuff >> (bsLive - 1)) & 1; bsLive--; } zvec = (zvec << 1) | zj; @@ -704,14 +704,14 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { cftab[0] = 0; for (i = 1; i <= 256; i++) { - cftab[i] = unzftab[i-1]; + cftab[i] = unzftab[i - 1]; } for (i = 1; i <= 256; i++) { - cftab[i] += cftab[i-1]; + cftab[i] += cftab[i - 1]; } for (i = 0; i <= last; i++) { - ch = (char)ll8[i]; + ch = (char) ll8[i]; tt[cftab[ch]] = i; cftab[ch]++; } @@ -733,19 +733,19 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } private void setupRandPartA() { - if(i2 <= last) { + if (i2 <= last) { chPrev = ch2; ch2 = ll8[tPos]; tPos = tt[tPos]; if (rNToGo == 0) { rNToGo = rNums[rTPos]; rTPos++; - if(rTPos == 512) { + if (rTPos == 512) { rTPos = 0; } } rNToGo--; - ch2 ^= (int)((rNToGo == 1) ? 1 : 0); + ch2 ^= (int) ((rNToGo == 1) ? 1 : 0); i2++; currentChar = ch2; @@ -759,7 +759,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } private void setupNoRandPartA() { - if(i2 <= last) { + if (i2 <= last) { chPrev = ch2; ch2 = ll8[tPos]; tPos = tt[tPos]; @@ -788,7 +788,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { if (rNToGo == 0) { rNToGo = rNums[rTPos]; rTPos++; - if(rTPos == 512) { + if (rTPos == 512) { rTPos = 0; } } @@ -805,7 +805,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } private void setupRandPartC() { - if(j2 < (int)z) { + if (j2 < (int) z) { currentChar = ch2; mCrc.updateCRC(ch2); j2++; @@ -838,7 +838,7 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } private void setupNoRandPartC() { - if(j2 < (int)z) { + if (j2 < (int) z) { currentChar = ch2; mCrc.updateCRC(ch2); j2++; @@ -851,14 +851,14 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { } private void setDecompressStructureSizes(int newSize100k) { - if (! (0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k + if (!(0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k && blockSize100k <= 9)) { // throw new IOException("Invalid block size"); } blockSize100k = newSize100k; - if(newSize100k == 0) { + if (newSize100k == 0) { return; } diff --git a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java index 09a695710..1fad83964 100644 --- a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java +++ b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -99,8 +99,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { nInUse = 0; for (i = 0; i < 256; i++) { if (inUse[i]) { - seqToUnseq[nInUse] = (char)i; - unseqToSeq[i] = (char)nInUse; + seqToUnseq[nInUse] = (char) i; + unseqToSeq[i] = (char) nInUse; nInUse++; } } @@ -120,7 +120,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int[] parent = new int[MAX_ALPHA_SIZE * 2]; for (i = 0; i < alphaSize; i++) { - weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8; + weight[i + 1] = (freq[i] == 0 ? 1 : freq[i]) << 8; } while (true) { @@ -146,7 +146,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { heap[zz] = tmp; } } - if (!(nHeap < (MAX_ALPHA_SIZE+2))) { + if (!(nHeap < (MAX_ALPHA_SIZE + 2))) { panic(); } @@ -164,7 +164,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { break; } if (yy < nHeap && - weight[heap[yy+1]] < weight[heap[yy]]) { + weight[heap[yy + 1]] < weight[heap[yy]]) { yy++; } if (weight[tmp] < weight[heap[yy]]) { @@ -188,7 +188,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { break; } if (yy < nHeap && - weight[heap[yy+1]] < weight[heap[yy]]) { + weight[heap[yy + 1]] < weight[heap[yy]]) { yy++; } if (weight[tmp] < weight[heap[yy]]) { @@ -235,13 +235,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { k = parent[k]; j++; } - len[i-1] = (char)j; + len[i - 1] = (char) j; if (j > maxLen) { tooLong = true; } } - if (! tooLong) { + if (!tooLong) { break; } @@ -325,10 +325,10 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { bsSetStream(inStream); workFactor = 50; - if(inBlockSize > 9) { + if (inBlockSize > 9) { inBlockSize = 9; } - if(inBlockSize < 1) { + if (inBlockSize < 1) { inBlockSize = 1; } blockSize100k = inBlockSize; @@ -344,10 +344,10 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { */ public void write(int bv) throws IOException { int b = (256 + bv) % 256; - if(currentChar != -1) { - if(currentChar == b) { + if (currentChar != -1) { + if (currentChar == b) { runLength++; - if(runLength > 254) { + if (runLength > 254) { writeRun(); currentChar = -1; runLength = 0; @@ -364,42 +364,42 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } private void writeRun() throws IOException { - if(last < allowableBlockSize) { + if (last < allowableBlockSize) { inUse[currentChar] = true; - for(int i = 0; i < runLength; i++) { - mCrc.updateCRC((char)currentChar); + for (int i = 0; i < runLength; i++) { + mCrc.updateCRC((char) currentChar); } switch (runLength) { case 1: last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; break; case 2: last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; break; case 3: last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; break; default: inUse[runLength - 4] = true; last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; last++; - block[last + 1] = (char)currentChar; + block[last + 1] = (char) currentChar; last++; - block[last + 1] = (char)(runLength - 4); + block[last + 1] = (char) (runLength - 4); break; } } else { @@ -416,11 +416,11 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } public void close() throws IOException { - if(closed) { + if (closed) { return; } - if(runLength > 0) { + if (runLength > 0) { writeRun(); } currentChar = -1; @@ -460,7 +460,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { last = -1; // ch = 0; - for(int i = 0; i < 256; i++) { + for (int i = 0; i < 256; i++) { inUse[i] = false; } @@ -470,7 +470,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { private void endBlock() throws IOException { blockCRC = mCrc.getFinalCRC(); - combinedCRC = (combinedCRC << 1)|(combinedCRC >>> 31); + combinedCRC = (combinedCRC << 1) | (combinedCRC >>> 31); combinedCRC ^= blockCRC; /* sort the block and establish posn of original string */ @@ -501,10 +501,10 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { /* Now a single bit indicating randomisation. */ if (blockRandomised) { - bsW(1,1); + bsW(1, 1); nBlocksRandomised++; } else { - bsW(1,0); + bsW(1, 0); } /* Finally, block's contents proper. */ @@ -561,7 +561,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { try { bsStream.write(ch); // write 8-bit } - catch(IOException e) { + catch (IOException e) { throw e; } bsBuff <<= 8; @@ -576,7 +576,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { try { bsStream.write(ch); // write 8-bit } - catch(IOException e) { + catch (IOException e) { throw e; } bsBuff <<= 8; @@ -612,7 +612,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { alphaSize = nInUse + 2; for (t = 0; t < N_GROUPS; t++) { for (v = 0; v < alphaSize; v++) { - len[t][v] = (char)GREATER_ICOST; + len[t][v] = (char) GREATER_ICOST; } } @@ -625,13 +625,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { nGroups = 2; } else if (nMTF < 600) { nGroups = 3; - } else if (nMTF < 1200) { + } else if (nMTF < 1200) { nGroups = 4; - } else if (nMTF < 2400) { + } else if (nMTF < 2400) { nGroups = 5; - } else { + } else { nGroups = 6; - } + } /* Generate an initial set of coding tables */ { int nPart, remF, tFreq, aFreq; @@ -641,29 +641,29 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { gs = 0; while (nPart > 0) { tFreq = remF / nPart; - ge = gs-1; + ge = gs - 1; aFreq = 0; - while (aFreq < tFreq && ge < alphaSize-1) { + while (aFreq < tFreq && ge < alphaSize - 1) { ge++; aFreq += mtfFreq[ge]; } if (ge > gs && nPart != nGroups && nPart != 1 - && ((nGroups-nPart) % 2 == 1)) { + && ((nGroups - nPart) % 2 == 1)) { aFreq -= mtfFreq[ge]; ge--; } for (v = 0; v < alphaSize; v++) { if (v >= gs && v <= ge) { - len[nPart-1][v] = (char)LESSER_ICOST; + len[nPart - 1][v] = (char) LESSER_ICOST; } else { - len[nPart-1][v] = (char)GREATER_ICOST; + len[nPart - 1][v] = (char) GREATER_ICOST; } } nPart--; - gs = ge+1; + gs = ge + 1; remF -= aFreq; } } @@ -696,7 +696,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } ge = gs + G_SIZE - 1; if (ge >= nMTF) { - ge = nMTF-1; + ge = nMTF - 1; } /* @@ -748,7 +748,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { }; totc += bc; fave[bt]++; - selector[nSelectors] = (char)bt; + selector[nSelectors] = (char) bt; nSelectors++; /* @@ -758,7 +758,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { rfreq[bt][szptr[i]]++; } - gs = ge+1; + gs = ge + 1; } /* @@ -786,20 +786,20 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { char[] pos = new char[N_GROUPS]; char ll_i, tmp2, tmp; for (i = 0; i < nGroups; i++) { - pos[i] = (char)i; + pos[i] = (char) i; } for (i = 0; i < nSelectors; i++) { ll_i = selector[i]; j = 0; tmp = pos[j]; - while ( ll_i != tmp ) { + while (ll_i != tmp) { j++; tmp2 = tmp; tmp = pos[j]; pos[j] = tmp2; } pos[0] = tmp; - selectorMtf[i] = (char)j; + selectorMtf[i] = (char) j; } } @@ -841,9 +841,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { nBytes = bytesOut; for (i = 0; i < 16; i++) { if (inUse16[i]) { - bsW(1,1); + bsW(1, 1); } else { - bsW(1,0); + bsW(1, 0); } } @@ -851,9 +851,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (inUse16[i]) { for (j = 0; j < 16; j++) { if (inUse[i * 16 + j]) { - bsW(1,1); + bsW(1, 1); } else { - bsW(1,0); + bsW(1, 0); } } } @@ -863,13 +863,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { /* Now the selectors. */ nBytes = bytesOut; - bsW ( 3, nGroups ); - bsW ( 15, nSelectors ); + bsW (3, nGroups); + bsW (15, nSelectors); for (i = 0; i < nSelectors; i++) { for (j = 0; j < selectorMtf[i]; j++) { - bsW(1,1); + bsW(1, 1); } - bsW(1,0); + bsW(1, 0); } /* Now the coding tables. */ @@ -880,14 +880,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { bsW(5, curr); for (i = 0; i < alphaSize; i++) { while (curr < len[t][i]) { - bsW(2,2); + bsW(2, 2); curr++; /* 10 */ } while (curr > len[t][i]) { - bsW(2,3); + bsW(2, 3); curr--; /* 11 */ } - bsW ( 1, 0 ); + bsW (1, 0); } } @@ -901,14 +901,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } ge = gs + G_SIZE - 1; if (ge >= nMTF) { - ge = nMTF-1; + ge = nMTF - 1; } for (i = gs; i <= ge; i++) { - bsW(len [selector[selCtr]] [szptr[i]], - code [selector[selCtr]] [szptr[i]] ); + bsW(len[selector[selCtr]][szptr[i]], + code[selector[selCtr]][szptr[i]]); } - gs = ge+1; + gs = ge + 1; selCtr++; } if (!(selCtr == nSelectors)) { @@ -924,7 +924,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { private OutputStream bsStream; - private void simpleSort ( int lo, int hi, int d ) { + private void simpleSort(int lo, int hi, int d) { int i, j, h, bigN, hp; int v; @@ -950,8 +950,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } v = zptr[i]; j = i; - while ( fullGtU ( zptr[j-h]+d, v+d ) ) { - zptr[j] = zptr[j-h]; + while (fullGtU(zptr[j - h] + d, v + d)) { + zptr[j] = zptr[j - h]; j = j - h; if (j <= (lo + h - 1)) { break; @@ -966,8 +966,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } v = zptr[i]; j = i; - while ( fullGtU ( zptr[j-h]+d, v+d ) ) { - zptr[j] = zptr[j-h]; + while (fullGtU(zptr[j - h] + d, v + d)) { + zptr[j] = zptr[j - h]; j = j - h; if (j <= (lo + h - 1)) { break; @@ -982,8 +982,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } v = zptr[i]; j = i; - while ( fullGtU ( zptr[j-h]+d, v+d ) ) { - zptr[j] = zptr[j-h]; + while (fullGtU(zptr[j - h] + d, v + d)) { + zptr[j] = zptr[j - h]; j = j - h; if (j <= (lo + h - 1)) { break; @@ -999,7 +999,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } } - private void vswap ( int p1, int p2, int n ) { + private void vswap(int p1, int p2, int n) { int temp = 0; while (n > 0) { temp = zptr[p1]; @@ -1011,7 +1011,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } } - private char med3( char a, char b, char c ) { + private char med3(char a, char b, char c) { char t; if (a > b) { t = a; @@ -1035,11 +1035,11 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int dd; } - private void qSort3 ( int loSt, int hiSt, int dSt ) { + private void qSort3(int loSt, int hiSt, int dSt) { int unLo, unHi, ltLo, gtHi, med, n, m; int sp, lo, hi, d; StackElem[] stack = new StackElem[QSORT_STACK_SIZE]; - for(int count = 0; count < QSORT_STACK_SIZE; count++) { + for (int count = 0; count < QSORT_STACK_SIZE; count++) { stack[count] = new StackElem(); } @@ -1080,7 +1080,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (unLo > unHi) { break; } - n = ((int)block[zptr[unLo]+d + 1]) - med; + n = ((int) block[zptr[unLo] + d + 1]) - med; if (n == 0) { int temp = 0; temp = zptr[unLo]; @@ -1099,7 +1099,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (unLo > unHi) { break; } - n = ((int)block[zptr[unHi]+d + 1]) - med; + n = ((int) block[zptr[unHi] + d + 1]) - med; if (n == 0) { int temp = 0; temp = zptr[unHi]; @@ -1128,15 +1128,15 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (gtHi < ltLo) { stack[sp].ll = lo; stack[sp].hh = hi; - stack[sp].dd = d+1; + stack[sp].dd = d + 1; sp++; continue; } - n = ((ltLo-lo) < (unLo-ltLo)) ? (ltLo-lo) : (unLo-ltLo); - vswap(lo, unLo-n, n); - m = ((hi-gtHi) < (gtHi-unHi)) ? (hi-gtHi) : (gtHi-unHi); - vswap(unLo, hi-m+1, m); + n = ((ltLo - lo) < (unLo - ltLo)) ? (ltLo - lo) : (unLo - ltLo); + vswap(lo, unLo - n, n); + m = ((hi - gtHi) < (gtHi - unHi)) ? (hi - gtHi) : (gtHi - unHi); + vswap(unLo, hi - m + 1, m); n = lo + unLo - ltLo - 1; m = hi - (gtHi - unHi) + 1; @@ -1148,7 +1148,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { stack[sp].ll = n + 1; stack[sp].hh = m - 1; - stack[sp].dd = d+1; + stack[sp].dd = d + 1; sp++; stack[sp].ll = m; @@ -1172,7 +1172,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { set up the overshoot area for block. */ - // if (verbosity >= 4) fprintf ( stderr, " sort initialise ...\n" ); + // if (verbosity >= 4) fprintf ( stderr, " sort initialise ...\n" ); for (i = 0; i < NUM_OVERSHOOT_BYTES; i++) { block[last + i + 2] = block[(i % (last + 1)) + 1]; } @@ -1180,7 +1180,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { quadrant[i] = 0; } - block[0] = (char)(block[last + 1]); + block[0] = (char) (block[last + 1]); if (last < 4000) { /* @@ -1192,7 +1192,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } firstAttempt = false; workDone = workLimit = 0; - simpleSort ( 0, last, 0 ); + simpleSort(0, last, 0); } else { numQSorted = 0; for (i = 0; i <= 255; i++) { @@ -1249,10 +1249,10 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { for (i = h; i <= 255; i++) { vv = runningOrder[i]; j = i; - while ((ftab[((runningOrder[j-h])+1) << 8] - - ftab[(runningOrder[j-h]) << 8]) > - (ftab[((vv)+1) << 8] - ftab[(vv) << 8])) { - runningOrder[j] = runningOrder[j-h]; + while ((ftab[((runningOrder[j - h]) + 1) << 8] + - ftab[(runningOrder[j - h]) << 8]) > + (ftab[((vv) + 1) << 8] - ftab[(vv) << 8])) { + runningOrder[j] = runningOrder[j - h]; j = j - h; if (j <= (h - 1)) { break; @@ -1282,12 +1282,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { */ for (j = 0; j <= 255; j++) { sb = (ss << 8) + j; - if(!((ftab[sb] & SETMASK) == SETMASK) ) { + if (!((ftab[sb] & SETMASK) == SETMASK)) { int lo = ftab[sb] & CLEARMASK; - int hi = (ftab[sb+1] & CLEARMASK) - 1; + int hi = (ftab[sb + 1] & CLEARMASK) - 1; if (hi > lo) { - qSort3 ( lo, hi, 2 ); - numQSorted += ( hi - lo + 1 ); + qSort3(lo, hi, 2); + numQSorted += (hi - lo + 1); if (workDone > workLimit && firstAttempt) { return; } @@ -1308,7 +1308,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (i < 255) { int bbStart = ftab[ss << 8] & CLEARMASK; - int bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart; + int bbSize = (ftab[(ss + 1) << 8] & CLEARMASK) - bbStart; int shifts = 0; while ((bbSize >> shifts) > 65534) { @@ -1324,7 +1324,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } } - if (! ( ((bbSize-1) >> shifts) <= 65535 )) { + if (!(((bbSize - 1) >> shifts) <= 65535)) { panic(); } } @@ -1338,11 +1338,11 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } for (j = ftab[ss << 8] & CLEARMASK; - j < (ftab[(ss+1) << 8] & CLEARMASK); j++) { + j < (ftab[(ss + 1) << 8] & CLEARMASK); j++) { c1 = block[zptr[j]]; - if ( ! bigDone[c1] ) { + if (!bigDone[c1]) { zptr[copy[c1]] = zptr[j] == 0 ? last : zptr[j] - 1; - copy[c1] ++; + copy[c1]++; } } @@ -1363,9 +1363,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { for (i = 0; i <= last; i++) { if (rNToGo == 0) { - rNToGo = (char)rNums[rTPos]; + rNToGo = (char) rNums[rTPos]; rTPos++; - if(rTPos == 512) { + if (rTPos == 512) { rTPos = 0; } } @@ -1582,7 +1582,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int EOB; makeMaps(); - EOB = nInUse+1; + EOB = nInUse + 1; for (i = 0; i <= EOB; i++) { mtfFreq[i] = 0; @@ -1602,7 +1602,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { j = 0; tmp = yy[j]; - while ( ll_i != tmp ) { + while (ll_i != tmp) { j++; tmp2 = tmp; tmp = yy[j]; @@ -1618,12 +1618,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { while (true) { switch (zPend % 2) { case 0: - szptr[wr] = (short)RUNA; + szptr[wr] = (short) RUNA; wr++; mtfFreq[RUNA]++; break; case 1: - szptr[wr] = (short)RUNB; + szptr[wr] = (short) RUNB; wr++; mtfFreq[RUNB]++; break; @@ -1635,7 +1635,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { }; zPend = 0; } - szptr[wr] = (short)(j + 1); + szptr[wr] = (short) (j + 1); wr++; mtfFreq[j + 1]++; } @@ -1646,12 +1646,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { while (true) { switch (zPend % 2) { case 0: - szptr[wr] = (short)RUNA; + szptr[wr] = (short) RUNA; wr++; mtfFreq[RUNA]++; break; case 1: - szptr[wr] = (short)RUNB; + szptr[wr] = (short) RUNB; wr++; mtfFreq[RUNB]++; break; @@ -1663,7 +1663,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } } - szptr[wr] = (short)EOB; + szptr[wr] = (short) EOB; wr++; mtfFreq[EOB]++; diff --git a/src/main/org/apache/tools/bzip2/CRC.java b/src/main/org/apache/tools/bzip2/CRC.java index 8e55e03ba..f4822a4af 100644 --- a/src/main/org/apache/tools/bzip2/CRC.java +++ b/src/main/org/apache/tools/bzip2/CRC.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -156,7 +156,7 @@ class CRC { void updateCRC(int inCh) { int temp = (globalCrc >> 24) ^ inCh; - if(temp < 0) { + if (temp < 0) { temp = 256 + temp; } globalCrc = (globalCrc << 8) ^ CRC.crc32Table[temp]; diff --git a/src/main/org/apache/tools/tar/TarEntry.java b/src/main/org/apache/tools/tar/TarEntry.java index b247edde0..cdfac95cc 100644 --- a/src/main/org/apache/tools/tar/TarEntry.java +++ b/src/main/org/apache/tools/tar/TarEntry.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -224,7 +224,7 @@ public class TarEntry implements TarConstants { else if (osname.toLowerCase().indexOf("netware") > -1) { int colon = name.indexOf(':'); if (colon != -1) { - name=name.substring(colon+1); + name = name.substring(colon + 1); } } } @@ -517,7 +517,7 @@ public class TarEntry implements TarConstants { * @return An array of TarEntry's for this entry's children. */ public TarEntry[] getDirectoryEntries() { - if (this.file == null ||!this.file.isDirectory()) { + if (this.file == null || !this.file.isDirectory()) { return new TarEntry[0]; } diff --git a/src/main/org/apache/tools/zip/AsiExtraField.java b/src/main/org/apache/tools/zip/AsiExtraField.java index 111c6d905..02bb0126d 100644 --- a/src/main/org/apache/tools/zip/AsiExtraField.java +++ b/src/main/org/apache/tools/zip/AsiExtraField.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -147,12 +147,12 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { * @since 1.1 */ public ZipShort getLocalFileDataLength() { - return new ZipShort( 4 // CRC - + 2 // Mode - + 4 // SizDev - + 2 // UID - + 2 // GID - + getLinkedFile().getBytes().length); + return new ZipShort(4 // CRC + + 2 // Mode + + 4 // SizDev + + 2 // UID + + 2 // GID + + getLinkedFile().getBytes().length); } /** @@ -321,8 +321,8 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { throws ZipException { long givenChecksum = (new ZipLong(data, offset)).getValue(); - byte[] tmp = new byte[length-4]; - System.arraycopy(data, offset+4, tmp, 0, length-4); + byte[] tmp = new byte[length - 4]; + System.arraycopy(data, offset + 4, tmp, 0, length - 4); crc.reset(); crc.update(tmp); long realChecksum = crc.getValue(); diff --git a/src/main/org/apache/tools/zip/ExtraFieldUtils.java b/src/main/org/apache/tools/zip/ExtraFieldUtils.java index 005e98809..04a587e39 100644 --- a/src/main/org/apache/tools/zip/ExtraFieldUtils.java +++ b/src/main/org/apache/tools/zip/ExtraFieldUtils.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -127,25 +127,27 @@ public class ExtraFieldUtils { public static ZipExtraField[] parse(byte[] data) throws ZipException { Vector v = new Vector(); int start = 0; - while (start <= data.length-4) { + while (start <= data.length - 4) { ZipShort headerId = new ZipShort(data, start); - int length = (new ZipShort(data, start+2)).getValue(); - if (start+4+length > data.length) { - throw new ZipException("data starting at "+start+" is in unknown format"); + int length = (new ZipShort(data, start + 2)).getValue(); + if (start + 4 + length > data.length) { + throw new ZipException("data starting at " + start + + " is in unknown format"); } try { ZipExtraField ze = createExtraField(headerId); - ze.parseFromLocalFileData(data, start+4, length); + ze.parseFromLocalFileData(data, start + 4, length); v.addElement(ze); } catch (InstantiationException ie) { throw new ZipException(ie.getMessage()); } catch (IllegalAccessException iae) { throw new ZipException(iae.getMessage()); } - start += (length+4); + start += (length + 4); } if (start != data.length) { // array not exhausted - throw new ZipException("data starting at "+start+" is in unknown format"); + throw new ZipException("data starting at " + start + + " is in unknown format"); } ZipExtraField[] result = new ZipExtraField[v.size()]; @@ -159,20 +161,20 @@ public class ExtraFieldUtils { * @since 1.1 */ public static byte[] mergeLocalFileDataData(ZipExtraField[] data) { - int sum = 4*data.length; - for (int i=0; i