From cdede6da8be04746b9958a47e3ccdfe67bd0cd5a Mon Sep 17 00:00:00 2001 From: wisberg Date: Thu, 5 May 2005 06:48:52 +0000 Subject: [PATCH] nit - consolidating "/" and File.separator --- .../tools/ant/taskdefs/AntBuilder.java | 11 +++---- .../aspectj/internal/tools/build/Builder.java | 4 +-- .../aspectj/internal/tools/build/Module.java | 32 ++----------------- .../aspectj/internal/tools/build/Util.java | 17 ++++++++++ build/testsrc/BuildModuleTests.java | 11 ++++--- .../internal/build/BuildModuleTest.java | 2 +- .../aspectj/internal/build/ModulesTest.java | 4 ++- 7 files changed, 36 insertions(+), 45 deletions(-) diff --git a/build/src/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java b/build/src/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java index 40c6bb3c9..8b3021ab8 100644 --- a/build/src/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java +++ b/build/src/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java @@ -587,8 +587,8 @@ public class AntBuilder extends Builder { libDirs[i] = project.getProperty(libDirNames[i]); } if (null != libDirs[i]) { - libDirs[i] += File.separator + "lib"; - result = new Path(project, libDirs[i] + File.separator + name); + libDirs[i] = Util.path(libDirs[i], "lib"); + result = new Path(project, Util.path(libDirs[i], name)); String path = result.toString(); if (new File(path).canRead()) { return result; @@ -705,13 +705,12 @@ class ProductBuilder extends AntBuilder { private static String getProductInstallResourcesSrc(BuildSpec buildSpec) { final String resourcesName = "installer-resources"; // XXXFileLiteral File dir = buildSpec.productDir.getParentFile(); -// String result = null; if (null == dir) { - return "../../" + resourcesName; + return Util.path(new String[] {"..", "..", resourcesName}); } dir = dir.getParentFile(); if (null == dir) { - return "../" + resourcesName; + return Util.path("..", resourcesName); } else { dir = new File(dir, resourcesName); return dir.getPath(); @@ -842,7 +841,7 @@ class ProductBuilder extends AntBuilder { // copy binaries associated with module flag files for (int i = 0; i < productModules.length; i++) { ProductModule product = productModules[i]; - String targPath = targDirPath + "/" + product.relativePath; + String targPath = Util.path(targDirPath, product.relativePath); File jarFile = (product.assembleAll ? product.module.getAssembledJar() : product.module.getModuleJar() ); diff --git a/build/src/org/aspectj/internal/tools/build/Builder.java b/build/src/org/aspectj/internal/tools/build/Builder.java index dbb0c40fe..b9303ffb8 100644 --- a/build/src/org/aspectj/internal/tools/build/Builder.java +++ b/build/src/org/aspectj/internal/tools/build/Builder.java @@ -466,11 +466,11 @@ public abstract class Builder { FILTER_OFF)) { return false; } - + // duplicate code? // copy binaries associated with module flag files for (int i = 0; i < productModules.length; i++) { ProductModule product = productModules[i]; - String targPath = targDirPath + "/" + product.relativePath; + String targPath = Util.path(targDirPath, product.relativePath); File jarFile = (product.assembleAll ? product.module.getAssembledJar() diff --git a/build/src/org/aspectj/internal/tools/build/Module.java b/build/src/org/aspectj/internal/tools/build/Module.java index 28cdbd35d..8aea24dff 100644 --- a/build/src/org/aspectj/internal/tools/build/Module.java +++ b/build/src/org/aspectj/internal/tools/build/Module.java @@ -113,33 +113,6 @@ public class Module { } } -// /** XXX gack explicitly skip Ant, sun tools.jar except for testing... modules */ -// private static boolean skipLibraryJarAntecedant(Module module, File libJar) { -// if (null == libJar) { -// return true; -// } -// if (!module.name.startsWith("testing")) { -// String path = libJar.getPath().replace('\\', '/'); -// path = path.replace(File.separatorChar, '/'); -// if (-1 != path.indexOf("/lib/ant/lib/")) { -// return true; -// } else if (-1 != path.indexOf("/tools.jar")) { -// return true; -// } -// } -// return false; -// } -// -// /** XXX gack explicitly skip runtime */ -// private static boolean skipModuleJarAntecedant(File requiredJar) { -// if (null == requiredJar) { -// return true; -// } else { -// //return "runtime.jar".equals(requiredJar.getName()); -// return false; -// } -// } - /**@return true if this is a source file */ private static boolean isSourceFile(File file) { String path = file.getPath(); @@ -376,7 +349,6 @@ public class Module { String line; XMLEntry entry = new XMLEntry("classpathentry", ATTS); -// String lastKind = null; while (null != (line = reader.readLine())) { // we assume no internal spaces... entry.acceptTokens(line); @@ -429,11 +401,11 @@ public class Module { path = path.substring(JAVA_HOME.length()); String home = System.getProperty("java.home"); if (null != home) { - libPath = home + File.separator + path; + libPath = Util.path(home, path); File f = new File(libPath); if (!f.exists() && home.endsWith("jre")) { f = new File(home).getParentFile(); - libPath = f.getPath() + File.separator + path; + libPath = Util.path(f.getPath(), path); } } } diff --git a/build/src/org/aspectj/internal/tools/build/Util.java b/build/src/org/aspectj/internal/tools/build/Util.java index 563a5c195..806154c20 100644 --- a/build/src/org/aspectj/internal/tools/build/Util.java +++ b/build/src/org/aspectj/internal/tools/build/Util.java @@ -136,6 +136,23 @@ public class Util { return (null != dir) && dir.canWrite() && dir.isDirectory(); } + public static String path(String first, String second) { + return first + File.separator + second; + } + + public static String path(String[] segments) { + StringBuffer sb = new StringBuffer(); + if ((null != segments)) { + for (int i = 0; i < segments.length; i++) { + if (0 < i) { + sb.append(File.separator); + } + sb.append(segments[i]); + } + } + return sb.toString(); + } + /** @return true if dir is a readable directory */ public static boolean canReadDir(File dir) { return (null != dir) && dir.canRead() && dir.isDirectory(); diff --git a/build/testsrc/BuildModuleTests.java b/build/testsrc/BuildModuleTests.java index 60c5b091a..6939c6db4 100644 --- a/build/testsrc/BuildModuleTests.java +++ b/build/testsrc/BuildModuleTests.java @@ -16,6 +16,7 @@ import org.aspectj.internal.tools.ant.taskdefs.Checklics; import org.aspectj.internal.tools.build.Builder; +import org.aspectj.internal.tools.build.Util; import org.aspectj.internal.build.BuildModuleTest; import org.aspectj.internal.build.ModulesTest; @@ -42,7 +43,7 @@ public class BuildModuleTests extends TestCase { /** replace commented out below - if any replace failed, halt all */ private static boolean replaceFailed = false; - private static final String BASE_DIR = "../"; + private static final String BASE_DIR = ".." + File.separator; private static final String[] JDT_SOURCE_DIRS = new String[] {}; public static Test suite() { @@ -111,7 +112,7 @@ public class BuildModuleTests extends TestCase { } public void testLicense_org_eclipse_jdt_core() { final String mod = "org.eclipse.jdt.core"; - final String pre = BASE_DIR + mod + "/"; + final String pre = BASE_DIR + mod + File.separator; for (int i = 0; i < JDT_SOURCE_DIRS.length; i++) { checkSourceDirectory(new File(pre + JDT_SOURCE_DIRS[i]), mod); } @@ -140,12 +141,12 @@ public class BuildModuleTests extends TestCase { } public void testLicense_weaver() { String module = "weaver"; - checkSourceDirectory(new File("../" + module + "/src"), module); - checkSourceDirectory(new File("../" + module + "/testsrc/org"), module); + checkSourceDirectory(new File(Util.path(new String[] {"..", module, "src"})), module); + checkSourceDirectory(new File(Util.path(new String[] {"..", module, "testsrc", "org"})), module); } void checkLicense(String module) { - File moduleDir = new File(".." + File.separator + module); + File moduleDir = new File(Util.path("..", module)); File[] srcDirs = findSourceRoots(moduleDir); for (int i = 0; i < srcDirs.length; i++) { checkSourceDirectory(srcDirs[i], module); diff --git a/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java b/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java index 295ee1e83..8a7f1edd0 100644 --- a/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java +++ b/build/testsrc/org/aspectj/internal/build/BuildModuleTest.java @@ -200,7 +200,7 @@ public class BuildModuleTest extends TestCase { File jarDir = getJarDir(); assertTrue(jarDir.canWrite() || jarDir.mkdirs()); tempFiles.add(jarDir); - File moduleDir = new File("../" + module); + File moduleDir = new File(Util.path("..", module)); assertTrue(moduleDir.canRead()); task.setModuledir(new Path(project, moduleDir.getAbsolutePath())); task.setJardir(new Path(project, jarDir.getAbsolutePath())); diff --git a/build/testsrc/org/aspectj/internal/build/ModulesTest.java b/build/testsrc/org/aspectj/internal/build/ModulesTest.java index fee0d5cf6..2715e22b9 100644 --- a/build/testsrc/org/aspectj/internal/build/ModulesTest.java +++ b/build/testsrc/org/aspectj/internal/build/ModulesTest.java @@ -31,6 +31,7 @@ import org.aspectj.internal.tools.ant.taskdefs.BuildModule; import org.aspectj.internal.tools.build.Messager; import org.aspectj.internal.tools.build.Module; import org.aspectj.internal.tools.build.Modules; +import org.aspectj.internal.tools.build.Util; /** * */ @@ -183,7 +184,8 @@ public class ModulesTest extends TestCase { File buildDir = new File(modulesDir, "aj-build"); File distDir = new File(buildDir, "dist"); File jarDir = new File(buildDir, "jars"); - File productDir = new File(modulesDir, "build/products/" + productName); + File productDir = new File(modulesDir, + Util.path(new String[] {"build", "products", productName})); jarDir.mkdirs(); distDir.mkdirs(); -- 2.39.5