Review changes

#PL-1977
This commit is contained in:
Eugeny Degtyarjov 2013-03-25 13:20:23 +00:00
parent dbbef243fb
commit 16eb75e82a
9 changed files with 22 additions and 22 deletions

View File

@ -126,7 +126,7 @@ public class JavaClassLoader extends URLClassLoader {
Map<String, Class> compiledClasses = createCompiler().compile(sourcesForCompilation, errs); Map<String, Class> compiledClasses = createCompiler().compile(sourcesForCompilation, errs);
Map<String, TimestampClass> compiledTimestampClasses = convertCompiledClassesAndDependencies(compiledClasses, sourcesAndDependencies.dependecies); Map<String, TimestampClass> compiledTimestampClasses = convertCompiledClassesAndDependencies(compiledClasses, sourcesAndDependencies.dependencies);
compiled.putAll(compiledTimestampClasses); compiled.putAll(compiledTimestampClasses);

View File

@ -36,27 +36,27 @@ class SourceProvider {
public File getSourceFile(String name) { public File getSourceFile(String name) {
String path = name.replace(".", "/"); 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; return srcFile;
} }
public boolean sourceExistsInFileSystem(String className) { public boolean sourceExistsInFileSystem(String className) {
String path = className.replace('.', '/'); String path = className.replace('.', '/');
File file = new File(rootDir + "/" + path + JAVA_EXT); File file = new File(rootDir, path + JAVA_EXT);
return file.exists(); return file.exists();
} }
public boolean directoryExistsInFileSystem(String packageName) { public boolean directoryExistsInFileSystem(String packageName) {
String path = packageName.replace('.', '/'); String path = packageName.replace('.', '/');
File dir = new File(rootDir + "/" + path); File dir = new File(rootDir, path);
return dir.exists(); return dir.exists();
} }
public List<String> getAllClassesFromPackage(String packageName) { public List<String> getAllClassesFromPackage(String packageName) {
String path = packageName.replace(".", "/"); String path = packageName.replace(".", "/");
File srcDir = new File(String.format("%s/%s", rootDir, path)); File srcDir = new File(rootDir, path);
String[] fileNames = srcDir.list(); String[] fileNames = srcDir.list();
List<String> classNames = new ArrayList<String>(); List<String> classNames = new ArrayList<>();
for (String fileName : fileNames) { for (String fileName : fileNames) {
if (fileName.endsWith(JAVA_EXT)) { if (fileName.endsWith(JAVA_EXT)) {
classNames.add(packageName + "." + fileName.replace(JAVA_EXT, "")); classNames.add(packageName + "." + fileName.replace(JAVA_EXT, ""));

View File

@ -23,8 +23,8 @@ class SourcesAndDependencies {
private static final String IMPORT_STATIC_PATTERN = "import static (.+)\\..+?;"; private static final String IMPORT_STATIC_PATTERN = "import static (.+)\\..+?;";
public static final String WHOLE_PACKAGE_PLACEHOLDER = ".*"; public static final String WHOLE_PACKAGE_PLACEHOLDER = ".*";
final Map<String, CharSequence> sources = new HashMap<String, CharSequence>(); final Map<String, CharSequence> sources = new HashMap<>();
final Multimap<String, String> dependecies = HashMultimap.create(); final Multimap<String, String> dependencies = HashMultimap.create();
private final SourceProvider sourceProvider; private final SourceProvider sourceProvider;
@ -39,7 +39,6 @@ class SourcesAndDependencies {
/** /**
* Recursively collects all dependencies for class using imports * Recursively collects all dependencies for class using imports
* *
* @param className
* @throws IOException * @throws IOException
*/ */
public void collectDependencies(String className) throws IOException { public void collectDependencies(String className) throws IOException {
@ -58,9 +57,9 @@ class SourcesAndDependencies {
} }
} }
private void addDependency(String dependendFrom, String dependency) { private void addDependency(String dependentFrom, String dependency) {
if (!dependendFrom.equals(dependency)) { if (!dependentFrom.equals(dependency)) {
dependecies.put(dependendFrom, dependency); dependencies.put(dependentFrom, dependency);
} }
} }
@ -82,7 +81,7 @@ class SourcesAndDependencies {
} }
private List<String> getDynamicallyLoadedImports(CharSequence src) { private List<String> getDynamicallyLoadedImports(CharSequence src) {
List<String> importedClassNames = new ArrayList<String>(); List<String> importedClassNames = new ArrayList<>();
List<String> importValues = getMatchedStrings(src, IMPORT_PATTERN, 1); List<String> importValues = getMatchedStrings(src, IMPORT_PATTERN, 1);
for (String importValue : importValues) { for (String importValue : importValues) {
@ -97,7 +96,7 @@ class SourcesAndDependencies {
} }
private List<String> getMatchedStrings(CharSequence source, String pattern, int groupNumber) { private List<String> getMatchedStrings(CharSequence source, String pattern, int groupNumber) {
ArrayList<String> result = new ArrayList<String>(); ArrayList<String> result = new ArrayList<>();
Pattern importPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); Pattern importPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher matcher = importPattern.matcher(source); Matcher matcher = importPattern.matcher(source);
while (matcher.find()) { while (matcher.find()) {

View File

@ -10,12 +10,13 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
public class JavaClassLoaderTest { public class JavaClassLoaderTest {
@Test @Test
public void testDependencies() throws Exception { 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 @Override
protected Date getCurrentTimestamp() { protected Date getCurrentTimestamp() {
return new Date(); return new Date();
@ -24,7 +25,7 @@ public class JavaClassLoaderTest {
Class<?> class1 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); Class<?> class1 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass");
System.out.println("Class loaded"); 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"); System.out.println("SimpleClass modified");
Class<?> class2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); Class<?> class2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass");
Assert.assertNotSame(class1, class2); Assert.assertNotSame(class1, class2);
@ -36,7 +37,7 @@ public class JavaClassLoaderTest {
Assert.assertEquals(class2, class3); Assert.assertEquals(class2, class3);
System.out.println("Class reloaded, same class received"); 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"); System.out.println("SimpleClass1 modified");
Class<?> class4 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); Class<?> class4 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass");
@ -46,7 +47,7 @@ public class JavaClassLoaderTest {
@Test @Test
public void testDependent() throws Exception { public void testDependent() throws Exception {
JavaClassLoader javaClassLoader = new JavaClassLoader(null, ".\\modules\\global\\sourcefiles\\", "") { JavaClassLoader javaClassLoader = new JavaClassLoader(null, "./test-data/javacl-sources/", "") {
@Override @Override
protected Date getCurrentTimestamp() { protected Date getCurrentTimestamp() {
return new Date(); return new Date();
@ -58,7 +59,7 @@ public class JavaClassLoaderTest {
Class<?> simpleClass = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass"); Class<?> simpleClass = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass");
System.out.println("SimpleClass loaded " + simpleClass.hashCode()); 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"); Class<?> simpleClass_2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass");
System.out.println("SimpleClass loaded " + simpleClass_2.hashCode()); System.out.println("SimpleClass loaded " + simpleClass_2.hashCode());
@ -79,7 +80,7 @@ public class JavaClassLoaderTest {
@Test @Test
public void testLinkageError() throws Exception { public void testLinkageError() throws Exception {
JavaClassLoader javaClassLoader = new JavaClassLoader(null, ".\\modules\\global\\sourcefiles\\", "") { JavaClassLoader javaClassLoader = new JavaClassLoader(null, "./test-data/javacl-sources/", "") {
@Override @Override
protected Date getCurrentTimestamp() { protected Date getCurrentTimestamp() {
return new Date(); return new Date();
@ -92,7 +93,7 @@ public class JavaClassLoaderTest {
Object o = class1.newInstance(); Object o = class1.newInstance();
System.out.println(o.toString()); 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"); Class<?> class2 = javaClassLoader.loadClass("com.haulmont.cuba.core.sys.javacl.test.SimpleClass");
System.out.println("Class loaded " + class2.hashCode()); System.out.println("Class loaded " + class2.hashCode());