From 16eb75e82a4d0367a639e8e738c2b1e20070de13 Mon Sep 17 00:00:00 2001 From: Eugeny Degtyarjov Date: Mon, 25 Mar 2013 13:20:23 +0000 Subject: [PATCH] Review changes #PL-1977 --- .../cuba/core/sys/javacl/JavaClassLoader.java | 2 +- .../cuba/core/sys/javacl/SourceProvider.java | 10 +++++----- .../core/sys/javacl/SourcesAndDependencies.java | 15 +++++++-------- .../cuba/core/sys/javacl/test/SimpleClass.java | 0 .../sys/javacl/test/pack1/SimpleClass1.java | 0 .../sys/javacl/test/pack2/SimpleClass2.java | 0 .../sys/javacl/test/pack3/SimpleClass3.java | 0 .../sys/javacl/test/pack4/SimpleClass4.java | 0 .../core/sys/javacl/JavaClassLoaderTest.java | 17 +++++++++-------- 9 files changed, 22 insertions(+), 22 deletions(-) rename modules/global/{sourcefiles => test-data/javacl-sources}/com/haulmont/cuba/core/sys/javacl/test/SimpleClass.java (100%) rename modules/global/{sourcefiles => test-data/javacl-sources}/com/haulmont/cuba/core/sys/javacl/test/pack1/SimpleClass1.java (100%) rename modules/global/{sourcefiles => test-data/javacl-sources}/com/haulmont/cuba/core/sys/javacl/test/pack2/SimpleClass2.java (100%) rename modules/global/{sourcefiles => test-data/javacl-sources}/com/haulmont/cuba/core/sys/javacl/test/pack3/SimpleClass3.java (100%) rename modules/global/{sourcefiles => test-data/javacl-sources}/com/haulmont/cuba/core/sys/javacl/test/pack4/SimpleClass4.java (100%) diff --git a/modules/global/src/com/haulmont/cuba/core/sys/javacl/JavaClassLoader.java b/modules/global/src/com/haulmont/cuba/core/sys/javacl/JavaClassLoader.java index c2afa6d1b7..140d72e0e9 100644 --- a/modules/global/src/com/haulmont/cuba/core/sys/javacl/JavaClassLoader.java +++ b/modules/global/src/com/haulmont/cuba/core/sys/javacl/JavaClassLoader.java @@ -126,7 +126,7 @@ public class JavaClassLoader extends URLClassLoader { Map compiledClasses = createCompiler().compile(sourcesForCompilation, errs); - Map compiledTimestampClasses = convertCompiledClassesAndDependencies(compiledClasses, sourcesAndDependencies.dependecies); + Map compiledTimestampClasses = convertCompiledClassesAndDependencies(compiledClasses, sourcesAndDependencies.dependencies); compiled.putAll(compiledTimestampClasses); diff --git a/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourceProvider.java b/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourceProvider.java index cad13c4104..9c5c6b920c 100644 --- a/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourceProvider.java +++ b/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourceProvider.java @@ -36,27 +36,27 @@ class SourceProvider { public File getSourceFile(String name) { String path = name.replace(".", "/"); - File srcFile = new File(String.format("%s/%s.java", rootDir, path)); + File srcFile = new File(rootDir, path + JAVA_EXT); return srcFile; } public boolean sourceExistsInFileSystem(String className) { String path = className.replace('.', '/'); - File file = new File(rootDir + "/" + path + JAVA_EXT); + File file = new File(rootDir, path + JAVA_EXT); return file.exists(); } public boolean directoryExistsInFileSystem(String packageName) { String path = packageName.replace('.', '/'); - File dir = new File(rootDir + "/" + path); + File dir = new File(rootDir, path); return dir.exists(); } public List getAllClassesFromPackage(String packageName) { String path = packageName.replace(".", "/"); - File srcDir = new File(String.format("%s/%s", rootDir, path)); + File srcDir = new File(rootDir, path); String[] fileNames = srcDir.list(); - List classNames = new ArrayList(); + List classNames = new ArrayList<>(); for (String fileName : fileNames) { if (fileName.endsWith(JAVA_EXT)) { classNames.add(packageName + "." + fileName.replace(JAVA_EXT, "")); diff --git a/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourcesAndDependencies.java b/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourcesAndDependencies.java index e6e8fc4c0a..d097b5e40a 100644 --- a/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourcesAndDependencies.java +++ b/modules/global/src/com/haulmont/cuba/core/sys/javacl/SourcesAndDependencies.java @@ -23,8 +23,8 @@ class SourcesAndDependencies { private static final String IMPORT_STATIC_PATTERN = "import static (.+)\\..+?;"; public static final String WHOLE_PACKAGE_PLACEHOLDER = ".*"; - final Map sources = new HashMap(); - final Multimap dependecies = HashMultimap.create(); + final Map sources = new HashMap<>(); + final Multimap dependencies = HashMultimap.create(); private final SourceProvider sourceProvider; @@ -39,7 +39,6 @@ class SourcesAndDependencies { /** * Recursively collects all dependencies for class using imports * - * @param className * @throws IOException */ public void collectDependencies(String className) throws IOException { @@ -58,9 +57,9 @@ class SourcesAndDependencies { } } - private void addDependency(String dependendFrom, String dependency) { - if (!dependendFrom.equals(dependency)) { - dependecies.put(dependendFrom, dependency); + private void addDependency(String dependentFrom, String dependency) { + if (!dependentFrom.equals(dependency)) { + dependencies.put(dependentFrom, dependency); } } @@ -82,7 +81,7 @@ class SourcesAndDependencies { } private List getDynamicallyLoadedImports(CharSequence src) { - List importedClassNames = new ArrayList(); + List importedClassNames = new ArrayList<>(); List importValues = getMatchedStrings(src, IMPORT_PATTERN, 1); for (String importValue : importValues) { @@ -97,7 +96,7 @@ class SourcesAndDependencies { } private List getMatchedStrings(CharSequence source, String pattern, int groupNumber) { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); Pattern importPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); Matcher matcher = importPattern.matcher(source); while (matcher.find()) { diff --git a/modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/SimpleClass.java b/modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/SimpleClass.java similarity index 100% rename from modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/SimpleClass.java rename to modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/SimpleClass.java diff --git a/modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack1/SimpleClass1.java b/modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack1/SimpleClass1.java similarity index 100% rename from modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack1/SimpleClass1.java rename to modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack1/SimpleClass1.java diff --git a/modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack2/SimpleClass2.java b/modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack2/SimpleClass2.java similarity index 100% rename from modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack2/SimpleClass2.java rename to modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack2/SimpleClass2.java diff --git a/modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack3/SimpleClass3.java b/modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack3/SimpleClass3.java similarity index 100% rename from modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack3/SimpleClass3.java rename to modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack3/SimpleClass3.java diff --git a/modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack4/SimpleClass4.java b/modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack4/SimpleClass4.java similarity index 100% rename from modules/global/sourcefiles/com/haulmont/cuba/core/sys/javacl/test/pack4/SimpleClass4.java rename to modules/global/test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack4/SimpleClass4.java diff --git a/modules/global/test/com/haulmont/cuba/core/sys/javacl/JavaClassLoaderTest.java b/modules/global/test/com/haulmont/cuba/core/sys/javacl/JavaClassLoaderTest.java index 1b04ba85b2..7690e69e06 100644 --- a/modules/global/test/com/haulmont/cuba/core/sys/javacl/JavaClassLoaderTest.java +++ b/modules/global/test/com/haulmont/cuba/core/sys/javacl/JavaClassLoaderTest.java @@ -10,12 +10,13 @@ import org.junit.Test; import java.io.File; import java.util.Date; -import java.util.HashMap; public class JavaClassLoaderTest { @Test public void testDependencies() throws Exception { - JavaClassLoader javaClassLoader = new JavaClassLoader(null, ".\\modules\\global\\sourcefiles\\", "") { + System.out.println(new File(".").getAbsolutePath()); + + JavaClassLoader javaClassLoader = new JavaClassLoader(null, "./test-data/javacl-sources/", "") { @Override protected Date getCurrentTimestamp() { return new Date(); @@ -24,7 +25,7 @@ public class JavaClassLoaderTest { Class class1 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); System.out.println("Class loaded"); - modifyFile(".\\modules\\global\\sourcefiles\\com\\haulmont\\cuba\\core\\sys\\javacl\\test\\SimpleClass.java"); + modifyFile("./test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/SimpleClass.java"); System.out.println("SimpleClass modified"); Class class2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); Assert.assertNotSame(class1, class2); @@ -36,7 +37,7 @@ public class JavaClassLoaderTest { Assert.assertEquals(class2, class3); System.out.println("Class reloaded, same class received"); - modifyFile(".\\modules\\global\\sourcefiles\\com\\haulmont\\cuba\\core\\sys\\javacl\\test\\pack1\\SimpleClass1.java"); + modifyFile("./test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack1/SimpleClass1.java"); System.out.println("SimpleClass1 modified"); Class class4 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); @@ -46,7 +47,7 @@ public class JavaClassLoaderTest { @Test public void testDependent() throws Exception { - JavaClassLoader javaClassLoader = new JavaClassLoader(null, ".\\modules\\global\\sourcefiles\\", "") { + JavaClassLoader javaClassLoader = new JavaClassLoader(null, "./test-data/javacl-sources/", "") { @Override protected Date getCurrentTimestamp() { return new Date(); @@ -58,7 +59,7 @@ public class JavaClassLoaderTest { Class simpleClass = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); System.out.println("SimpleClass loaded " + simpleClass.hashCode()); - modifyFile(".\\modules\\global\\sourcefiles\\com\\haulmont\\cuba\\core\\sys\\javacl\\test\\SimpleClass.java"); + modifyFile("./test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/SimpleClass.java"); Class simpleClass_2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); System.out.println("SimpleClass loaded " + simpleClass_2.hashCode()); @@ -79,7 +80,7 @@ public class JavaClassLoaderTest { @Test public void testLinkageError() throws Exception { - JavaClassLoader javaClassLoader = new JavaClassLoader(null, ".\\modules\\global\\sourcefiles\\", "") { + JavaClassLoader javaClassLoader = new JavaClassLoader(null, "./test-data/javacl-sources/", "") { @Override protected Date getCurrentTimestamp() { return new Date(); @@ -92,7 +93,7 @@ public class JavaClassLoaderTest { Object o = class1.newInstance(); System.out.println(o.toString()); - modifyFile(".\\modules\\global\\sourcefiles\\com\\haulmont\\cuba\\core\\sys\\javacl\\test\\pack2\\SimpleClass2.java"); + modifyFile("./test-data/javacl-sources/com/haulmont/cuba/core/sys/javacl/test/pack2/SimpleClass2.java"); Class class2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); System.out.println("Class loaded " + class2.hashCode());