Remove roaster java parser lib to reduce jar footprint to 14Mb
This commit is contained in:
@@ -40,17 +40,6 @@
|
||||
<artifactId>javaparser-core</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.forge.roaster</groupId>
|
||||
<artifactId>roaster-api</artifactId>
|
||||
<version>${roaster.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.forge.roaster</groupId>
|
||||
<artifactId>roaster-jdt</artifactId>
|
||||
<version>${roaster.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- Reactor -->
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.java.roaster;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jboss.forge.roaster.Roaster;
|
||||
import org.jboss.forge.roaster.model.JavaUnit;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
public interface JavaUnitIndex {
|
||||
|
||||
static final JavaUnitIndex DEFAULT = new JavaUnitIndex() {
|
||||
|
||||
private LoadingCache<URL, JavaUnit> cache = CacheBuilder.newBuilder().build(new CacheLoader<URL, JavaUnit>() {
|
||||
|
||||
@Override
|
||||
public JavaUnit load(URL url) throws Exception {
|
||||
InputStream in = url.openStream();
|
||||
try {
|
||||
return Roaster.parseUnit(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public JavaUnit getJavaUnit(URL url) {
|
||||
try {
|
||||
return cache.get(url);
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
JavaUnit getJavaUnit(URL url);
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.java.roaster;
|
||||
|
||||
import org.jboss.forge.roaster.model.JavaDoc;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
|
||||
public class RoasterJavadoc implements IJavadoc {
|
||||
|
||||
private JavaDoc<?> javadoc;
|
||||
|
||||
public RoasterJavadoc(JavaDoc<?> javadoc) {
|
||||
this.javadoc = javadoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
return javadoc.getFullText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderable getRenderable() {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.java.roaster;
|
||||
|
||||
import org.jboss.forge.roaster.model.Field;
|
||||
import org.jboss.forge.roaster.model.FieldHolder;
|
||||
import org.jboss.forge.roaster.model.JavaDocCapable;
|
||||
import org.jboss.forge.roaster.model.JavaType;
|
||||
import org.jboss.forge.roaster.model.JavaUnit;
|
||||
import org.jboss.forge.roaster.model.Method;
|
||||
import org.jboss.forge.roaster.model.MethodHolder;
|
||||
import org.jboss.forge.roaster.model.TypeHolder;
|
||||
import org.jboss.forge.roaster.model.source.JavaClassSource;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.javadoc.SourceUrlProvider;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
public class RoasterJavadocProvider implements IJavadocProvider {
|
||||
|
||||
private SourceUrlProvider sourceUrlProvider;
|
||||
|
||||
public RoasterJavadocProvider(SourceUrlProvider sourceUrlProvider) {
|
||||
this.sourceUrlProvider = sourceUrlProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IType type) {
|
||||
try {
|
||||
JavaClassSource declaration = (JavaClassSource) getDeclaration(type);
|
||||
return new RoasterJavadoc(declaration.getJavaDoc());
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IField field) {
|
||||
try {
|
||||
JavaType<?> typeDeclaration = getDeclaration(field.getDeclaringType());
|
||||
if (typeDeclaration instanceof FieldHolder) {
|
||||
Field<?> fieldDeclaration = ((FieldHolder<?>)typeDeclaration).getField(field.getElementName());
|
||||
if (fieldDeclaration instanceof JavaDocCapable) {
|
||||
return new RoasterJavadoc(((JavaDocCapable<?>)fieldDeclaration).getJavaDoc());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IMethod method) {
|
||||
if (method.parameters().findFirst().isPresent()) {
|
||||
throw new UnsupportedOperationException("Only methods with no parameters are supported");
|
||||
}
|
||||
try {
|
||||
JavaType<?> typeDeclaration = getDeclaration(method.getDeclaringType());
|
||||
if (typeDeclaration instanceof MethodHolder) {
|
||||
Method<?, ?> methodDeclaration = ((MethodHolder<?>)typeDeclaration).getMethod(method.getElementName());
|
||||
if (methodDeclaration instanceof JavaDocCapable) {
|
||||
return new RoasterJavadoc(((JavaDocCapable<?>)methodDeclaration).getJavaDoc());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IAnnotation annotation) {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
private JavaUnit getJavaUnit(IType type) throws Exception {
|
||||
return JavaUnitIndex.DEFAULT.getJavaUnit(sourceUrlProvider.sourceUrl(type));
|
||||
}
|
||||
|
||||
private JavaType<?> getDeclaration(IType type) throws Exception {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
IType declaringType = type.getDeclaringType();
|
||||
if (declaringType == null) {
|
||||
JavaUnit ju = getJavaUnit(type);
|
||||
return ju.getTopLevelTypes().stream().filter(jt -> jt.getName().equals(type.getElementName())).findFirst().orElse(null);
|
||||
} else {
|
||||
JavaType<?> declaringTypeDeclaration = getDeclaration(declaringType);
|
||||
if (declaringTypeDeclaration instanceof TypeHolder) {
|
||||
return ((TypeHolder<?>)declaringTypeDeclaration).getNestedType(type.getElementName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject.TypeFilter;
|
||||
import org.springframework.ide.vscode.commons.java.parser.ParserJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.roaster.RoasterJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.javadoc.SourceUrlProviderFromSourceContainer;
|
||||
import org.springframework.ide.vscode.commons.maven.MavenCore;
|
||||
@@ -53,7 +52,7 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
|
||||
public enum JavadocProviderTypes {
|
||||
JAVA_PARSER,
|
||||
ROASTER,
|
||||
// ROASTER,
|
||||
HTML
|
||||
}
|
||||
|
||||
@@ -79,8 +78,8 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
switch (providerType) {
|
||||
case JAVA_PARSER:
|
||||
return createParserJavadocProvider(classpathResource);
|
||||
case ROASTER:
|
||||
return createRoasterJavadocProvider(classpathResource);
|
||||
// case ROASTER:
|
||||
// return createRoasterJavadocProvider(classpathResource);
|
||||
default:
|
||||
return createHtmlJavdocProvider(classpathResource);
|
||||
}
|
||||
@@ -136,39 +135,42 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
return Arrays.stream(scanner.getIncludedFiles());
|
||||
});
|
||||
}
|
||||
|
||||
private IJavadocProvider createRoasterJavadocProvider(File classpathResource) {
|
||||
if (classpathResource.isDirectory()) {
|
||||
if (classpathResource.toString().startsWith(project.getBuild().getOutputDirectory())) {
|
||||
return new RoasterJavadocProvider(type -> {
|
||||
return SourceUrlProviderFromSourceContainer.SOURCE_FOLDER_URL_SUPPLIER
|
||||
.sourceUrl(new File(project.getBuild().getSourceDirectory()).toURI().toURL(), type);
|
||||
});
|
||||
} else if (classpathResource.toString().startsWith(project.getBuild().getTestOutputDirectory())) {
|
||||
return new RoasterJavadocProvider(type -> {
|
||||
return SourceUrlProviderFromSourceContainer.SOURCE_FOLDER_URL_SUPPLIER
|
||||
.sourceUrl(new File(project.getBuild().getTestSourceDirectory()).toURI().toURL(), type);
|
||||
});
|
||||
} else {
|
||||
throw new IllegalArgumentException("Cannot find source folder for " + classpathResource);
|
||||
}
|
||||
} else {
|
||||
// Assume it's a JAR file
|
||||
return new RoasterJavadocProvider(type -> {
|
||||
try {
|
||||
Artifact artifact = getArtifactFromJarFile(classpathResource).get();
|
||||
URL sourceContainer = maven.getSources(artifact).getFile().toURI().toURL();
|
||||
return SourceUrlProviderFromSourceContainer.JAR_SOURCE_URL_PROVIDER.sourceUrl(sourceContainer,
|
||||
type);
|
||||
} catch (MavenException e) {
|
||||
Log.log("Failed to find sources JAR for " + classpathResource, e);
|
||||
} catch (MalformedURLException e) {
|
||||
Log.log("Invalid URL for sources JAR for " + classpathResource, e);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Roaster lib is experiment to generate javadoc from source. Commented out for now since roaster lib is taken out
|
||||
*/
|
||||
// private IJavadocProvider createRoasterJavadocProvider(File classpathResource) {
|
||||
// if (classpathResource.isDirectory()) {
|
||||
// if (classpathResource.toString().startsWith(project.getBuild().getOutputDirectory())) {
|
||||
// return new RoasterJavadocProvider(type -> {
|
||||
// return SourceUrlProviderFromSourceContainer.SOURCE_FOLDER_URL_SUPPLIER
|
||||
// .sourceUrl(new File(project.getBuild().getSourceDirectory()).toURI().toURL(), type);
|
||||
// });
|
||||
// } else if (classpathResource.toString().startsWith(project.getBuild().getTestOutputDirectory())) {
|
||||
// return new RoasterJavadocProvider(type -> {
|
||||
// return SourceUrlProviderFromSourceContainer.SOURCE_FOLDER_URL_SUPPLIER
|
||||
// .sourceUrl(new File(project.getBuild().getTestSourceDirectory()).toURI().toURL(), type);
|
||||
// });
|
||||
// } else {
|
||||
// throw new IllegalArgumentException("Cannot find source folder for " + classpathResource);
|
||||
// }
|
||||
// } else {
|
||||
// // Assume it's a JAR file
|
||||
// return new RoasterJavadocProvider(type -> {
|
||||
// try {
|
||||
// Artifact artifact = getArtifactFromJarFile(classpathResource).get();
|
||||
// URL sourceContainer = maven.getSources(artifact).getFile().toURI().toURL();
|
||||
// return SourceUrlProviderFromSourceContainer.JAR_SOURCE_URL_PROVIDER.sourceUrl(sourceContainer,
|
||||
// type);
|
||||
// } catch (MavenException e) {
|
||||
// Log.log("Failed to find sources JAR for " + classpathResource, e);
|
||||
// } catch (MalformedURLException e) {
|
||||
// Log.log("Invalid URL for sources JAR for " + classpathResource, e);
|
||||
// }
|
||||
// return null;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
private IJavadocProvider createParserJavadocProvider(File classpathResource) {
|
||||
if (classpathResource.isDirectory()) {
|
||||
|
||||
@@ -250,77 +250,6 @@ public class JavaIndexTest {
|
||||
assertEquals(expected, method.getJavaDoc().raw().trim().substring(0, expected.length()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roaster_testClassJavadocForOutputFolder() throws Exception {
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.ROASTER;
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
IType type = project.findType("hello.Greeting");
|
||||
|
||||
assertNotNull(type);
|
||||
assertEquals("Comment for Greeting class", type.getJavaDoc().raw());
|
||||
|
||||
IField field = type.getField("id");
|
||||
assertNotNull(field);
|
||||
assertEquals("Comment for id field", field.getJavaDoc().raw());
|
||||
|
||||
IMethod method = type.getMethod("getId", Stream.empty());
|
||||
assertNotNull(method);
|
||||
assertEquals("Comment for getId()", method.getJavaDoc().raw());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roaster_testInnerClassJavadocForOutputFolder() throws Exception {
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.ROASTER;
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
IType type = project.findType("hello.Greeting$TestInnerClass");
|
||||
assertNotNull(type);
|
||||
assertEquals("Comment for inner class", type.getJavaDoc().raw());
|
||||
|
||||
IField field = type.getField("innerField");
|
||||
assertNotNull(field);
|
||||
assertEquals("Comment for inner field", field.getJavaDoc().raw());
|
||||
|
||||
IMethod method = type.getMethod("getInnerField", Stream.empty());
|
||||
assertNotNull(method);
|
||||
assertEquals("Comment for method inside nested class", method.getJavaDoc().raw());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roaster_testClassJavadocForJar() throws Exception {
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.ROASTER;
|
||||
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
|
||||
IType type = project.findType("org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener");
|
||||
assertNotNull(type);
|
||||
String expected = "{@link ApplicationListener} that replaces the liquibase {@link ServiceLocator} with a";
|
||||
assertEquals(expected, type.getJavaDoc().raw().substring(0, expected.length()));
|
||||
|
||||
type = project.findType("org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener$LiquibasePresent");
|
||||
assertNotNull(type);
|
||||
assertEquals("Inner class to prevent class not found issues.", type.getJavaDoc().raw());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roaster_testFieldAndMethodJavadocForJar() throws Exception {
|
||||
MavenProjectClasspath.providerType = JavadocProviderTypes.ROASTER;
|
||||
|
||||
MavenJavaProject project = createMavenProject(projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"));
|
||||
|
||||
IType type = project.findType("org.springframework.boot.SpringApplication");
|
||||
assertNotNull(type);
|
||||
|
||||
IField field = type.getField("BANNER_LOCATION_PROPERTY_VALUE");
|
||||
assertNotNull(field);
|
||||
assertEquals("Default banner location.", field.getJavaDoc().raw());
|
||||
|
||||
IMethod method = type.getMethod("getListeners", Stream.empty());
|
||||
assertNotNull(method);
|
||||
String expected = "Returns read-only ordered Set of the {@link ApplicationListener} s that will be";
|
||||
assertEquals(expected, method.getJavaDoc().raw().substring(0, expected.length()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void html_testClassJavadoc() throws Exception {
|
||||
Assume.assumeTrue(javaVersionHigherThan(6));
|
||||
|
||||
Reference in New Issue
Block a user