]> source.dussan.org Git - aspectj.git/commitdiff
Use static imports for file and path separator constants
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Wed, 23 Mar 2022 01:14:58 +0000 (08:14 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Wed, 23 Mar 2022 01:14:58 +0000 (08:14 +0700)
It makes concatenated paths a little more readable.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java
org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java

index ee49dc10abb7850791245c482cc3cca9b8a35f10..e34ce3a380f1595673df3eaf661768406c0ba9ee 100644 (file)
@@ -36,6 +36,9 @@ import org.aspectj.bridge.context.CompilationAndWeavingContext;
 import org.aspectj.testing.util.TestUtil;
 import org.aspectj.util.FileUtil;
 
+import static java.io.File.pathSeparator;
+import static java.io.File.separator;
+
 /**
  * The Ajc class is intended for use as part of a unit-test suite, it drives the AspectJ compiler and lets you check the compilation
  * results. Compilations run in a sandbox that is created in C:\temp\ajcSandbox or /tmp/ajcSandbox depending on your platform.
@@ -51,13 +54,13 @@ public class Ajc {
        private static final String BUILD_OUTPUT_FOLDER = "target";
 
        public static final String outputFolder(String module) {
-               return File.pathSeparator + ".." +File.separator + module + File.separator + BUILD_OUTPUT_FOLDER + File.separator + "classes";
+               return pathSeparator + ".." + separator + module + separator + BUILD_OUTPUT_FOLDER + separator + "classes";
        }
 
        public static final String outputFolders(String... modules) {
                StringBuilder s = new StringBuilder();
                for (String module: modules) {
-                       s.append(File.pathSeparator + ".." +File.separator + module + File.separator + BUILD_OUTPUT_FOLDER + File.separator + "classes");
+                       s.append(pathSeparator + ".." + separator + module + separator + BUILD_OUTPUT_FOLDER + separator + "classes");
                }
                return s.toString();
        }
@@ -67,7 +70,7 @@ public class Ajc {
                outputFolder("testing-client")
                        + outputFolder("runtime")
                        + outputFolder("bcel-builder")
-                       + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "junit" + File.separator + "junit.jar"
+                       + File.pathSeparator + ".." + separator + "lib" + separator + "junit" + separator + "junit.jar"
                        + outputFolder("bridge")
                        + outputFolder("loadtime")
                        + outputFolder("weaver")
@@ -321,17 +324,17 @@ public class Ajc {
                                                hasOutdir = true;
                                        }
                                        boolean isOutjar = args[i].equals("-outjar");
-                                       StringTokenizer strTok = new StringTokenizer(args[++i], File.pathSeparator);
+                                       StringTokenizer strTok = new StringTokenizer(args[++i], pathSeparator);
                                        while (strTok.hasMoreTokens()) {
                                                File f = new File(strTok.nextToken());
                                                buff.append(adjustFileOrDir(f, copyThisTime, isOutjar).getAbsolutePath());
                                                if (strTok.hasMoreTokens())
-                                                       buff.append(File.pathSeparator);
+                                                       buff.append(pathSeparator);
                                        }
                                        newArgs[i] = buff.toString();
                                        if (args[i - 1].equals("-classpath")) {
                                                hasClasspath = true;
-                                               newArgs[i] = newArgs[i] + File.pathSeparator + TESTER_PATH + File.pathSeparator
+                                               newArgs[i] = newArgs[i] + pathSeparator + TESTER_PATH + pathSeparator
                                                                + getSandboxDirectory().getAbsolutePath();
                                        }
                                } else {
@@ -348,7 +351,7 @@ public class Ajc {
                        newArgs = new String[oldArgs.length + 2];
                        System.arraycopy(oldArgs, 0, newArgs, 0, oldArgs.length);
                        newArgs[oldArgs.length] = "-classpath";
-                       newArgs[oldArgs.length + 1] = TESTER_PATH + File.pathSeparator + getSandboxDirectory().getAbsolutePath();
+                       newArgs[oldArgs.length + 1] = TESTER_PATH + pathSeparator + getSandboxDirectory().getAbsolutePath();
                }
                if (!hasOutdir) {
                        String[] oldArgs = newArgs;
@@ -366,7 +369,7 @@ public class Ajc {
                if (!from.isAbsolute()) {
                        ret = new File(sandbox, from.getPath());
                        File fromParent = from.getParentFile();
-                       String relativeToPath = (fromParent != null) ? (fromParent.getPath() + File.separator) : "";
+                       String relativeToPath = (fromParent != null) ? (fromParent.getPath() + separator) : "";
                        if (baseDir != null) {
                                from = new File(baseDir, from.getPath());
                                //                              if (ensureDirsExist) {
index 0bf08886ce790e3b5ec3575b7066e0714ec28d33..b6ae38ba1fcb1007464294bb6d7e31c0009d8feb 100644 (file)
@@ -37,6 +37,9 @@ import org.aspectj.util.LangUtil;
 
 import junit.framework.TestCase;
 
+import static java.io.File.pathSeparator;
+import static java.io.File.separator;
+
 /**
  * A TestCase class that acts as the superclass for all test cases wishing to drive the ajc compiler.
  * <p>
@@ -65,7 +68,7 @@ public abstract class AjcTestCase extends TestCase {
 
        public static final String CLASSPATH_ASM =
                Arrays.stream(System.getProperty("java.class.path")
-                       .split(File.pathSeparator))
+                       .split(pathSeparator))
                        .filter(path -> path.replace('\\', '/').contains("org/ow2/asm/"))
                        .findFirst()
                        .orElseThrow(() -> new RuntimeException("ASM library not found on classpath"));
@@ -73,13 +76,13 @@ public abstract class AjcTestCase extends TestCase {
        // see Ajc and AntSpec
        public static final String DEFAULT_CLASSPATH_ENTRIES =
                        Ajc.outputFolders("bridge","util","loadtime","weaver","asm","testing-client","runtime","org.aspectj.matcher")
-                               + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "junit" + File.separator + "junit.jar"
-                               + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator + "bcel.jar"
-                               + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator + "bcel-verifier.jar"
-                               + File.pathSeparator + CLASSPATH_ASM
-                               + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "testing-client.jar"
+                               + pathSeparator + ".." + separator + "lib" + separator + "junit" + separator + "junit.jar"
+                               + pathSeparator + ".." + separator + "lib" + separator + "bcel" + separator + "bcel.jar"
+                               + pathSeparator + ".." + separator + "lib" + separator + "bcel" + separator + "bcel-verifier.jar"
+                               + pathSeparator + CLASSPATH_ASM
+                               + pathSeparator + ".." + separator + "lib" + separator + "test" + separator + "testing-client.jar"
                                // hmmm, this next one should perhaps point to an aj-build jar...
-                               + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "aspectjrt.jar"
+                               + pathSeparator + ".." + separator + "lib" + separator + "test" + separator + "aspectjrt.jar"
                        ;
 
        /*
@@ -149,7 +152,7 @@ public abstract class AjcTestCase extends TestCase {
                                char[] chars = srcFile.toCharArray();
                                for (char c : chars) {
                                        if ((c == '\\') || (c == '/')) {
-                                               srcFileName.append(File.separator);
+                                               srcFileName.append(separator);
                                        } else {
                                                srcFileName.append(c);
                                        }
@@ -580,7 +583,7 @@ public abstract class AjcTestCase extends TestCase {
                if (classpath != null) {
                        // allow replacing this special variable, rather than copying all files to allow tests of jars that don't end in .jar
                        cp.append(substituteSandbox(classpath));
-                       cp.append(File.pathSeparator);
+                       cp.append(pathSeparator);
                }
                if (moduleName == null) {
                        // When running modules, we want more control so don't try to be helpful by adding all jars
@@ -590,7 +593,7 @@ public abstract class AjcTestCase extends TestCase {
                StringBuilder mp = new StringBuilder();
                if (modulepath != null) {
                        mp.append(substituteSandbox(modulepath));
-                       mp.append(File.pathSeparator);
+                       mp.append(pathSeparator);
                }
 
                URLClassLoader sandboxLoader;
@@ -620,7 +623,7 @@ public abstract class AjcTestCase extends TestCase {
 
                        File directory = new File (".");
                        String absPath = directory.getAbsolutePath();
-                       String javaagent= absPath+File.separator+".."+File.separator+"aj-build"+File.separator+"dist"+File.separator+"tools"+File.separator+"lib"+File.separator+"aspectjweaver.jar";
+                       String javaagent= absPath+separator+".."+separator+"aj-build"+separator+"dist"+separator+"tools"+separator+"lib"+separator+"aspectjweaver.jar";
                        try {
                                String command ="java " +vmargs+ " -classpath " + cp +" -javaagent:"+javaagent + " " + className ;
 
@@ -650,7 +653,7 @@ public abstract class AjcTestCase extends TestCase {
                                        mp = mp.replace(mp.indexOf("$runtime"),"$runtime".length(),TestUtil.aspectjrtPath().toString());
                                }
                                if (cp.indexOf("aspectjrt")==-1) {
-                                       cp.append(TestUtil.aspectjrtPath().getPath()).append(File.pathSeparator);
+                                       cp.append(TestUtil.aspectjrtPath().getPath()).append(pathSeparator);
                                }
                                String command = LangUtil.getJavaExecutable().getAbsolutePath() + " " +vmargs+ (cp.length()==0?"":" -classpath " + cp) + " -p "+mp+" --module "+moduleName   ;
                                if (Ajc.verbose) {
@@ -676,7 +679,7 @@ public abstract class AjcTestCase extends TestCase {
                                //                                      mp = mp.replace(mp.indexOf("$runtime"),"$runtime".length(),TestUtil.aspectjrtPath().toString());
                                //                              }
                                if (cp.indexOf("aspectjrt")==-1) {
-                                       cp.append(File.pathSeparator).append(TestUtil.aspectjrtPath().getPath());
+                                       cp.append(pathSeparator).append(TestUtil.aspectjrtPath().getPath());
                                }
                                String command = LangUtil.getJavaExecutable().getAbsolutePath() + " " +vmargs+ (cp.length()==0?"":" -classpath " + cp) + " " + className   ;
                                if (Ajc.verbose) {
@@ -867,7 +870,7 @@ public abstract class AjcTestCase extends TestCase {
        }
 
        private URL[] getURLs(String classpath) {
-               StringTokenizer strTok = new StringTokenizer(classpath, File.pathSeparator);
+               StringTokenizer strTok = new StringTokenizer(classpath, pathSeparator);
                URL[] urls = new URL[strTok.countTokens()];
                try {
                        for (int i = 0; i < urls.length; i++) {
@@ -926,7 +929,7 @@ public abstract class AjcTestCase extends TestCase {
                                cpIndex++;
                                String[] newargs = new String[args.length];
                                System.arraycopy(args, 0, newargs, 0, args.length);
-                               newargs[cpIndex] = args[cpIndex] + File.pathSeparator + TestUtil.aspectjrtPath().getPath();
+                               newargs[cpIndex] = args[cpIndex] + pathSeparator + TestUtil.aspectjrtPath().getPath();
                                args = newargs;
                        }
                }
@@ -934,7 +937,7 @@ public abstract class AjcTestCase extends TestCase {
                if (needsJRTFS) {
                        if (!args[cpIndex].contains(LangUtil.JRT_FS)) {
                                String jrtfsPath = LangUtil.getJrtFsFilePath();
-                               args[cpIndex] = jrtfsPath + File.pathSeparator + args[cpIndex];
+                               args[cpIndex] = jrtfsPath + pathSeparator + args[cpIndex];
                        }
                }
                return args;
@@ -1014,7 +1017,7 @@ public abstract class AjcTestCase extends TestCase {
                File[] files = dir.listFiles();
                for (File file : files) {
                        if (file.getName().endsWith(".jar")) {
-                               buff.append(File.pathSeparator);
+                               buff.append(pathSeparator);
                                buff.append(file.getAbsolutePath());
                        } else if (file.isDirectory()) {
                                getAnyJars(file, buff);