Refactor, fix and simplify classpath infrastructure
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.ide.vscode.commons.java.ClasspathData;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.util.BasicFileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
public class JandexClasspathTest {
|
||||
|
||||
@Rule public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
class TestProject {
|
||||
String name;
|
||||
File root;
|
||||
File testClassesFolder;
|
||||
File outputFolder;
|
||||
BasicFileObserver fileObserver = new BasicFileObserver();
|
||||
|
||||
TestProject(String name) throws Exception {
|
||||
this.name = name;
|
||||
this.root = new File(JandexClasspathTest.class.getResource("/" + name ).toURI());
|
||||
testClassesFolder = new File(root, "bin");
|
||||
this.outputFolder = folder.newFolder();
|
||||
}
|
||||
|
||||
void createClass(String fqName) throws Exception {
|
||||
String relativePath = fqName.replace('.', '/')+".class";
|
||||
File classFile = new File(testClassesFolder, relativePath);
|
||||
File target = new File(outputFolder, relativePath);
|
||||
target.getParentFile().mkdirs();
|
||||
Files.copy(classFile, target);
|
||||
fileObserver.notifyFileCreated(target.toURI().toString());
|
||||
}
|
||||
|
||||
ClasspathData getClasspath() {
|
||||
return new ClasspathData(name, ImmutableList.of(
|
||||
CPE.source(new File(root, "src"), outputFolder)
|
||||
));
|
||||
}
|
||||
|
||||
JandexClasspath getJandexClasspath() {
|
||||
return new JandexClasspath(getClasspath(), fileObserver);
|
||||
}
|
||||
|
||||
public void deleteClass(String fqName, BiConsumer<BasicFileObserver, String> eventNoficator) {
|
||||
String relativePath = fqName.replace('.', '/')+".class";
|
||||
File classFile = new File(outputFolder, relativePath);
|
||||
classFile.delete();
|
||||
eventNoficator.accept(fileObserver, classFile.toURI().toString());
|
||||
}
|
||||
|
||||
public void deleteClass(String fqName) {
|
||||
deleteClass(fqName, (fileObserver, path) -> fileObserver.notifyFileDeleted(path));
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void classfileChangesShouldTriggerReindexing() throws Exception {
|
||||
TestProject project = new TestProject("simple-java-project");
|
||||
project.createClass("demo.Hello");
|
||||
|
||||
JandexClasspath subject = project.getJandexClasspath();
|
||||
|
||||
assertNotNull(subject.findType("demo.Hello"));
|
||||
assertNull(subject.findType("demo.Goodbye"));
|
||||
|
||||
project.createClass("demo.Goodbye");
|
||||
|
||||
assertNotNull(subject.findType("demo.Hello"));
|
||||
assertNotNull(subject.findType("demo.Goodbye"));
|
||||
|
||||
project.deleteClass("demo.Hello");
|
||||
|
||||
assertNull(subject.findType("demo.Hello"));
|
||||
assertNotNull(subject.findType("demo.Goodbye"));
|
||||
|
||||
project.deleteClass("demo.Goodbye", (fileObserver, deletedFile) -> fileObserver.notifyFileChanged(deletedFile));
|
||||
|
||||
assertNull(subject.findType("demo.Hello"));
|
||||
assertNull(subject.findType("demo.Goodbye"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
2
headless-services/commons/commons-java/src/test/resources/simple-java-project/.gitignore
vendored
Normal file
2
headless-services/commons/commons-java/src/test/resources/simple-java-project/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
!bin/
|
||||
!*.class
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>simple-java-project</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
package demo;
|
||||
|
||||
public class Goodbye {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package demo;
|
||||
|
||||
public class Hello {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user