Browse Source

Tidy up the code

master
Gintas Grigelionis 7 years ago
parent
commit
3af9a7305a
25 changed files with 70 additions and 74 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  2. +8
    -9
      src/main/org/apache/tools/ant/RuntimeConfigurable.java
  3. +2
    -3
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  4. +1
    -1
      src/main/org/apache/tools/ant/launch/Launcher.java
  5. +1
    -1
      src/main/org/apache/tools/ant/launch/Locator.java
  6. +0
    -1
      src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
  7. +10
    -10
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  8. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  9. +3
    -4
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  10. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  11. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java
  12. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
  13. +1
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java
  14. +1
    -1
      src/main/org/apache/tools/ant/types/Commandline.java
  15. +1
    -2
      src/main/org/apache/tools/ant/types/Path.java
  16. +1
    -2
      src/main/org/apache/tools/ant/types/resources/ResourceList.java
  17. +1
    -1
      src/main/org/apache/tools/ant/types/resources/selectors/Name.java
  18. +1
    -1
      src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
  19. +1
    -1
      src/main/org/apache/tools/ant/util/GlobPatternMapper.java
  20. +4
    -4
      src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java
  21. +7
    -7
      src/main/org/apache/tools/zip/ZipOutputStream.java
  22. +10
    -6
      src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java
  23. +2
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
  24. +2
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java
  25. +3
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java

+ 1
- 1
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -394,7 +394,7 @@ public final class IntrospectionHelper {
dc.setDynamicAttribute(attributeName.toLowerCase(Locale.ENGLISH), value.toString());
return;
}
if (attributeName.indexOf(':') >= 0) {
if (attributeName.contains(":")) {
return; // Ignore attribute from unknown uri's
}
final String msg = getElementName(p, element)


+ 8
- 9
src/main/org/apache/tools/ant/RuntimeConfigurable.java View File

@@ -154,7 +154,7 @@ public class RuntimeConfigurable implements Serializable {
* @return AttributeComponentInformation instance
*/
private AttributeComponentInformation isRestrictedAttribute(String name, ComponentHelper componentHelper) {
if (name.indexOf(':') == -1) {
if (!name.contains(":")) {
return new AttributeComponentInformation(null, false);
}
String componentName = attrToComponent(name);
@@ -184,16 +184,15 @@ public class RuntimeConfigurable implements Serializable {
ComponentHelper componentHelper = ComponentHelper
.getComponentHelper(owner.getProject());

IntrospectionHelper ih
= IntrospectionHelper.getHelper(
owner.getProject(), EnableAttributeConsumer.class);
for (int i = 0; i < attributeMap.keySet().size(); ++i) {
String name = (String) attributeMap.keySet().toArray()[i];
AttributeComponentInformation attributeComponentInformation = isRestrictedAttribute(name, componentHelper);
IntrospectionHelper ih = IntrospectionHelper.getHelper(owner.getProject(),
EnableAttributeConsumer.class);
for (Map.Entry<String, Object> entry : attributeMap.entrySet()) {
AttributeComponentInformation attributeComponentInformation
= isRestrictedAttribute(entry.getKey(), componentHelper);
if (!attributeComponentInformation.isRestricted()) {
continue;
}
String value = (String) attributeMap.get(name);
String value = (String) entry.getValue();
EnableAttribute enable = null;
try {
enable = (EnableAttribute)
@@ -287,7 +286,7 @@ public class RuntimeConfigurable implements Serializable {
* @param value the attribute's value.
*/
public synchronized void setAttribute(String name, String value) {
if (name.indexOf(':') != -1) {
if (name.contains(":")) {
namespacedAttribute = true;
}
setAttribute(name, (Object) value);


+ 2
- 3
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -253,9 +253,8 @@ public class ProjectHelper2 extends ProjectHelper {
inputStream = Files.newInputStream(buildFile.toPath());
} else {
uri = url.toString();
int pling = -1;
if (uri.startsWith("jar:file")
&& (pling = uri.indexOf("!/")) > -1) {
int pling = uri.indexOf("!/");
if (uri.startsWith("jar:file") && pling > -1) {
zf = new ZipFile(org.apache.tools.ant.launch.Locator
.fromJarURI(uri), "UTF-8");
inputStream =


+ 1
- 1
src/main/org/apache/tools/ant/launch/Launcher.java View File

@@ -139,7 +139,7 @@ public class Launcher {
while (tokenizer.hasMoreElements()) {
final String elementName = tokenizer.nextToken();
final File element = new File(elementName);
if (elementName.indexOf('%') != -1 && !element.exists()) {
if (elementName.contains("%") && !element.exists()) {
continue;
}
if (getJars && element.isDirectory()) {


+ 1
- 1
src/main/org/apache/tools/ant/launch/Locator.java View File

@@ -282,7 +282,7 @@ public final class Locator {
* @since Ant 1.7
*/
public static String decodeUri(String uri) throws UnsupportedEncodingException {
if (uri.indexOf('%') == -1) {
if (!uri.contains("%")) {
return uri;
}
ByteArrayOutputStream sb = new ByteArrayOutputStream(uri.length());


+ 0
- 1
src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java View File

@@ -458,7 +458,6 @@ public abstract class AbstractCvsTask extends Task {
int startproto = cmdLine.indexOf(':', start);
int startuser = cmdLine.indexOf(':', startproto + 1);
int startpass = cmdLine.indexOf(':', startuser + 1);
stop = cmdLine.indexOf('@', start);
if (stop >= 0 && startpass > startproto && startpass < stop) {
for (int i = startpass + 1; i < stop; i++) {
buf.replace(i, i + 1, "*");


+ 10
- 10
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -136,17 +136,9 @@ public class Execute {
return procEnvironment;
}
StringBuilder var = null;
String line, lineSep = StringUtils.LINE_SEP;
String line;
while ((line = in.readLine()) != null) {
if (line.indexOf('=') == -1) {
// Chunk part of previous env var (UNIX env vars can
// contain embedded new lines).
if (var == null) {
var = new StringBuilder(lineSep + line);
} else {
var.append(lineSep).append(line);
}
} else {
if (line.contains("=")) {
// New env var...append the previous one if we have it.
if (var != null) {
int eq = var.toString().indexOf('=');
@@ -154,6 +146,14 @@ public class Execute {
var.substring(eq + 1));
}
var = new StringBuilder(line);
} else {
// Chunk part of previous env var (UNIX env vars can
// contain embedded new lines).
if (var == null) {
var = new StringBuilder(StringUtils.LINE_SEP + line);
} else {
var.append(StringUtils.LINE_SEP).append(line);
}
}
}
// Since we "look ahead" before adding, there's one last env var.


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -671,7 +671,7 @@ public class Jar extends Zip {
+ " be replaced by a newly generated one.",
Project.MSG_WARN);
} else {
if (index && vPath.indexOf('/') == -1) {
if (index && !vPath.contains("/")) {
rootEntries.add(vPath);
}
super.zipFile(is, zOut, vPath, lastModified, fromArchive, mode);
@@ -1083,7 +1083,7 @@ public class Jar extends Zip {
String name = ze.getName();
if (ze.isDirectory()) {
dirSet.add(name);
} else if (name.indexOf('/') == -1) {
} else if (!name.contains("/")) {
files.add(name);
} else {
// a file, not in the root


+ 3
- 4
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -2203,7 +2203,7 @@ public class Javadoc extends Task {
if (useExternalFile) {
// TODO what is the following doing?
// should it run if !javadoc4 && executable != null?
if (sourceFileName.indexOf(' ') > -1) {
if (sourceFileName.contains(" ")) {
String name = sourceFileName;
if (File.separatorChar == '\\') {
name = sourceFileName.replace(File.separatorChar, '/');
@@ -2227,11 +2227,10 @@ public class Javadoc extends Task {
*/
private String quoteString(final String str) {
if (!containsWhitespace(str)
&& str.indexOf('\'') == -1
&& str.indexOf('"') == -1) {
&& !str.contains("'") && !str.contains("\"")) {
return str;
}
if (str.indexOf('\'') == -1) {
if (!str.contains("'")) {
return quoteString(str, '\'');
}
return quoteString(str, '"');


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -548,7 +548,7 @@ public abstract class DefaultCompilerAdapter
try (BufferedWriter out =
new BufferedWriter(new FileWriter(tmpFile))) {
for (int i = firstFileName; i < args.length; i++) {
if (quoteFiles && args[i].indexOf(' ') > -1) {
if (quoteFiles && args[i].contains(" ")) {
args[i] =
args[i].replace(File.separatorChar, '/');
out.write("\"" + args[i] + "\"");


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java View File

@@ -483,12 +483,12 @@ public class Depend extends MatchingTask {
// without closure we may delete an inner class but not the
// top level class which would not trigger a recompile.

if (affectedClass.indexOf('$') == -1) {
int aci = affectedClass.indexOf('$');
if (aci == -1) {
continue;
}
// need to delete the main class
String topLevelClassName
= affectedClass.substring(0, affectedClass.indexOf('$'));
String topLevelClassName = affectedClass.substring(0, aci);
log("Top level class = " + topLevelClassName,
Project.MSG_VERBOSE);
ClassFileInfo topLevelClassInfo


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java View File

@@ -269,7 +269,7 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm

private void createClassHeader() throws IOException {
String className = getLocationName().replace('\\', '/');
if (className.indexOf('/') > -1) {
if (className.contains("/")) {
className = className.substring(className.lastIndexOf('/') + 1);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss,SSS");
@@ -352,8 +352,8 @@ public class FailureRecorder extends ProjectComponent implements JUnitResultForm
*/
public TestInfos(Test test) {
className = test.getClass().getName();
String _methodName = test.toString();
methodName = _methodName.substring(0, _methodName.indexOf('('));
String methodName = test.toString();
this.methodName = methodName.substring(0, methodName.indexOf('('));
}

/**


+ 1
- 6
src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java View File

@@ -457,12 +457,7 @@ public class Scp extends SSHBase {
}

private static boolean isRemoteUri(final String uri) {
boolean isRemote = true;
final int indexOfAt = uri.indexOf('@');
if (indexOfAt < 0) {
isRemote = false;
}
return isRemote;
return uri.contains("@");
}

private Directory createDirectory(final FileSet set) {


+ 1
- 1
src/main/org/apache/tools/ant/types/Commandline.java View File

@@ -437,7 +437,7 @@ public class Commandline implements Cloneable {
}
if (argument.contains("\'") || argument.contains(" ")
// WIN9x uses a bat file for executing commands
|| (IS_WIN_9X && argument.indexOf(';') != -1)) {
|| (IS_WIN_9X && argument.contains(";"))) {
return '\"' + argument + '\"';
}
return argument;


+ 1
- 2
src/main/org/apache/tools/ant/types/Path.java View File

@@ -774,8 +774,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* @since Ant 1.8.2
*/
private static boolean containsWildcards(String path) {
return path != null
&& (path.indexOf('*') > -1 || path.indexOf('?') > -1);
return path != null && (path.contains("*") || path.contains("?"));
}

}

+ 1
- 2
src/main/org/apache/tools/ant/types/resources/ResourceList.java View File

@@ -231,8 +231,7 @@ public class ResourceList extends DataType implements ResourceCollection {
return (Resource) expanded;
}
String expandedLine = expanded.toString();
int colon = expandedLine.indexOf(':');
if (colon >= 0) {
if (expandedLine.contains(":")) {
// could be an URL or an absolute file on an OS with drives
try {
return new URLResource(expandedLine);


+ 1
- 1
src/main/org/apache/tools/ant/types/resources/selectors/Name.java View File

@@ -142,7 +142,7 @@ public class Name implements ResourceSelector {
}

private String modify(String s) {
if (s == null || !handleDirSep || s.indexOf('\\') < 0) {
if (s == null || !handleDirSep || !s.contains("\\")) {
return s;
}
return s.replace('\\', '/');


+ 1
- 1
src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java View File

@@ -647,7 +647,7 @@ public final class SelectorUtils {
* @return true if the string contains at least a star or a question mark
*/
public static boolean hasWildcards(String input) {
return input.indexOf('*') != -1 || input.indexOf('?') != -1;
return input.contains("*") || input.contains("?");
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/util/GlobPatternMapper.java View File

@@ -199,7 +199,7 @@ public class GlobPatternMapper implements FileNameMapper {
name = name.toLowerCase();
}
if (handleDirSep) {
if (name.indexOf('\\') != -1) {
if (name.contains("\\")) {
name = name.replace('\\', '/');
}
}


+ 4
- 4
src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java View File

@@ -62,10 +62,10 @@ public class RegexpUtil {
public static int asOptions(String flags) {
int options = RegexpMatcher.MATCH_DEFAULT;
if (flags != null) {
options = asOptions(flags.indexOf('i') == -1,
flags.indexOf('m') != -1,
flags.indexOf('s') != -1);
if (flags.indexOf('g') != -1) {
options = asOptions(!flags.contains("i"),
flags.contains("m"),
flags.contains("s"));
if (flags.contains("g")) {
options |= Regexp.REPLACE_ALL;
}
}


+ 7
- 7
src/main/org/apache/tools/zip/ZipOutputStream.java View File

@@ -343,22 +343,22 @@ public class ZipOutputStream extends FilterOutputStream {
*/
public ZipOutputStream(File file) throws IOException {
super(null);
RandomAccessFile _raf = null;
RandomAccessFile ranf = null;
try {
_raf = new RandomAccessFile(file, "rw");
_raf.setLength(0);
ranf = new RandomAccessFile(file, "rw");
ranf.setLength(0);
} catch (IOException e) {
if (_raf != null) {
if (ranf != null) {
try {
_raf.close();
ranf.close();
} catch (IOException inner) { // NOPMD
// ignore
}
_raf = null;
ranf = null;
}
out = Files.newOutputStream(file.toPath());
}
raf = _raf;
raf = ranf;
}

/**


+ 10
- 6
src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java View File

@@ -289,12 +289,16 @@ public class JarTest {

String line = r.readLine();
while (line != null) {
if (line.equals("foo")) {
foundFoo = true;
} else if (line.equals("sub")) {
foundSub = true;
} else if (line.equals("sub/foo")) {
foundSubFoo = true;
switch (line) {
case "foo":
foundFoo = true;
break;
case "sub":
foundSub = true;
break;
case "sub/foo":
foundSubFoo = true;
break;
}
line = r.readLine();
}


+ 2
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java View File

@@ -36,6 +36,7 @@ import org.junit.Test;

import static org.apache.tools.ant.AntAssert.assertContains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -398,8 +399,8 @@ public class ManifestTest {
assertNotNull(mf);
mfAsString = mf.toString();
assertNotNull(mfAsString);
assertEquals(-1, mfAsString.indexOf("Foo: Bar"));
assertTrue(mfAsString.contains("Foo: Baz"));
assertFalse(mfAsString.contains("Foo: Bar"));
}

@Test


+ 2
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java View File

@@ -35,6 +35,7 @@ import org.junit.Test;

import static org.apache.tools.ant.AntAssert.assertContains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@@ -149,7 +150,7 @@ public class ZipTest {
@Test
public void testUpdateNotNecessary() {
buildRule.executeTarget("testUpdateNotNecessary");
assertEquals(-1, buildRule.getLog().indexOf("Updating"));
assertFalse(buildRule.getLog().contains("Updating"));
}

@Test


+ 3
- 2
src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java View File

@@ -36,6 +36,7 @@ import org.apache.tools.ant.util.FileUtils;

import static org.apache.tools.ant.AntAssert.assertContains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@@ -268,7 +269,7 @@ public class DefaultCompilerAdapterTest {
assertNotNull(cmd[0]);
final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline());
//No modulesourcepath
assertEquals(-1, cmdLine.indexOf("--module-source-path"));
assertFalse(cmdLine.contains("--module-source-path"));
//The -sourcepath has to be followed by src
int index = cmdLine.indexOf("-sourcepath");
assertTrue(index != -1 && index < cmdLine.size() - 1);
@@ -326,7 +327,7 @@ public class DefaultCompilerAdapterTest {
assertNotNull(cmd[0]);
final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline());
//No sourcepath
assertEquals(-1, cmdLine.indexOf("-sourcepath"));
assertFalse(cmdLine.contains("-sourcepath"));
//The --module-source-path has to be followed by the pattern
int index = cmdLine.indexOf("--module-source-path");
assertTrue(index != -1 && index < cmdLine.size() - 1);


Loading…
Cancel
Save