mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 03:38:33 +08:00
Review changes
#PL-1977
This commit is contained in:
parent
dbbef243fb
commit
16eb75e82a
@ -126,7 +126,7 @@ public class JavaClassLoader extends URLClassLoader {
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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<String> 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<String> classNames = new ArrayList<String>();
|
||||
List<String> classNames = new ArrayList<>();
|
||||
for (String fileName : fileNames) {
|
||||
if (fileName.endsWith(JAVA_EXT)) {
|
||||
classNames.add(packageName + "." + fileName.replace(JAVA_EXT, ""));
|
||||
|
@ -23,8 +23,8 @@ class SourcesAndDependencies {
|
||||
private static final String IMPORT_STATIC_PATTERN = "import static (.+)\\..+?;";
|
||||
public static final String WHOLE_PACKAGE_PLACEHOLDER = ".*";
|
||||
|
||||
final Map<String, CharSequence> sources = new HashMap<String, CharSequence>();
|
||||
final Multimap<String, String> dependecies = HashMultimap.create();
|
||||
final Map<String, CharSequence> sources = new HashMap<>();
|
||||
final Multimap<String, String> 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<String> getDynamicallyLoadedImports(CharSequence src) {
|
||||
List<String> importedClassNames = new ArrayList<String>();
|
||||
List<String> importedClassNames = new ArrayList<>();
|
||||
|
||||
List<String> importValues = getMatchedStrings(src, IMPORT_PATTERN, 1);
|
||||
for (String importValue : importValues) {
|
||||
@ -97,7 +96,7 @@ class SourcesAndDependencies {
|
||||
}
|
||||
|
||||
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);
|
||||
Matcher matcher = importPattern.matcher(source);
|
||||
while (matcher.find()) {
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user