forked from redhat-developer/quarkus-ls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve compute of Quarkus/Microprofile properties
Fixes redhat-developer#154 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
041b300
commit 2a4eb79
Showing
468 changed files
with
11,946 additions
and
4,697 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
0
quarkus.jdt/README.md → microprofile.jdt/README.md
100755 → 100644
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
microprofile.jdt/com.redhat.microprofile.jdt.core.test/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: quarkus.jdt.ls Test Fragment | ||
Bundle-SymbolicName: com.redhat.quarkus.jdt.test | ||
Bundle-Version: 0.0.5.qualifier | ||
Fragment-Host: com.redhat.microprofile.jdt.core | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
Require-Bundle: org.junit;bundle-version="4.12", | ||
org.apache.commons.io, | ||
org.apache.commons.lang3, | ||
org.eclipse.jdt.ls.core, | ||
com.google.guava |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
165 changes: 165 additions & 0 deletions
165
...t.core.test/src/main/java/com/redhat/microprofile/jdt/core/BaseJDTQuarkusManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.microprofile.jdt.core; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IProjectDescription; | ||
import org.eclipse.core.resources.IWorkspaceRunnable; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.internal.core.JavaModelManager; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
|
||
import com.redhat.microprofile.commons.ClasspathKind; | ||
import com.redhat.microprofile.commons.QuarkusProjectInfo; | ||
import com.redhat.microprofile.commons.QuarkusPropertiesScope; | ||
import com.redhat.microprofile.jdt.core.DocumentationConverter; | ||
import com.redhat.microprofile.jdt.core.JDTQuarkusManager; | ||
import com.redhat.microprofile.jdt.internal.core.JavaUtils; | ||
import com.redhat.microprofile.jdt.internal.core.JobHelpers; | ||
|
||
/** | ||
* Base class for testing {@link JDTQuarkusManager} to initialize logs. | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class BaseJDTQuarkusManagerTest { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(JDTQuarkusManager.class.getSimpleName()); | ||
private static Level oldLevel; | ||
|
||
public enum MavenProjectName { | ||
|
||
all_quarkus_extensions("all-quarkus-extensions"), // | ||
config_hover("config-hover"), // | ||
config_properties("config-properties"), // | ||
config_quickstart("config-quickstart"), // | ||
config_quickstart_test("config-quickstart-test"), // | ||
hibernate_orm_resteasy("hibernate-orm-resteasy"), // | ||
using_vertx("using-vertx"); | ||
|
||
private final String name; | ||
|
||
private MavenProjectName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
oldLevel = LOGGER.getLevel(); | ||
LOGGER.setLevel(Level.INFO); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
LOGGER.setLevel(oldLevel); | ||
} | ||
|
||
protected static QuarkusProjectInfo getQuarkusProjectInfoFromMavenProject(MavenProjectName mavenProject) | ||
throws CoreException, Exception, JavaModelException { | ||
return getQuarkusProjectInfoFromMavenProject(mavenProject, QuarkusPropertiesScope.classpath); | ||
} | ||
|
||
protected static QuarkusProjectInfo getQuarkusProjectInfoFromMavenProject(MavenProjectName mavenProject, | ||
QuarkusPropertiesScope scope) throws CoreException, Exception, JavaModelException { | ||
IJavaProject javaProject = loadMavenProject(mavenProject); | ||
QuarkusProjectInfo info = JDTQuarkusManager.getInstance().getQuarkusProjectInfo(javaProject, scope, | ||
DocumentationConverter.DEFAULT_CONVERTER, ClasspathKind.SRC, new NullProgressMonitor()); | ||
return info; | ||
} | ||
|
||
public static IJavaProject loadMavenProject(MavenProjectName mavenProject) throws CoreException, Exception { | ||
// Load existing "hibernate-orm-resteasy" maven project | ||
String projectName = mavenProject.getName(); | ||
|
||
// Move project to working directory | ||
File projectFolder = copyProjectToWorkingDirectory(projectName); | ||
|
||
IPath path = new Path(new File(projectFolder, "/.project").getAbsolutePath()); | ||
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(path); | ||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName()); | ||
if (!project.exists()) { | ||
project.create(description, null); | ||
project.open(null); | ||
|
||
// We need to call waitForBackgroundJobs with a Job which does nothing to have a | ||
// resolved classpath (IJavaProject#getResolvedClasspath) when search is done. | ||
IWorkspaceRunnable runnable = new IWorkspaceRunnable() { | ||
@Override | ||
public void run(IProgressMonitor monitor) throws CoreException { | ||
monitor.done(); | ||
|
||
} | ||
}; | ||
IProgressMonitor monitor = new NullProgressMonitor(); | ||
JavaCore.run(runnable, null, monitor); | ||
waitForBackgroundJobs(monitor); | ||
} | ||
// Collect Quarkus properties from the "hibernate-orm-resteasy" project. It | ||
// should collect Quarkus properties from given JAR: | ||
|
||
// 1) quarkus-hibernate-orm.jar which is declared in the dependencies of the | ||
// pom.xml | ||
// <dependency> | ||
// <groupId>io.quarkus</groupId> | ||
// <artifactId>quarkus-hibernate-orm</artifactId> | ||
// </dependency> | ||
|
||
// 2) quarkus-hibernate-orm-deployment.jar which is declared in | ||
// META-INF/quarkus-extension.properties of quarkus-hibernate-orm.jar as | ||
// property: | ||
// deployment-artifact=io.quarkus\:quarkus-hibernate-orm-deployment\:0.21.1 | ||
|
||
IJavaProject javaProject = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(projectName); | ||
return javaProject; | ||
} | ||
|
||
private static File copyProjectToWorkingDirectory(String projectName) throws IOException { | ||
File from = new File("projects/maven/" + projectName); | ||
File to = new File(JavaUtils.getWorkingProjectDirectory(), projectName); | ||
|
||
if (to.exists()) { | ||
FileUtils.forceDelete(to); | ||
} | ||
|
||
if (from.isDirectory()) { | ||
FileUtils.copyDirectory(from, to); | ||
} else { | ||
FileUtils.copyFile(from, to); | ||
} | ||
|
||
return to; | ||
} | ||
|
||
|
||
private static void waitForBackgroundJobs(IProgressMonitor monitor) throws Exception { | ||
JobHelpers.waitForJobsToComplete(monitor); | ||
} | ||
} |
166 changes: 166 additions & 0 deletions
166
...st/src/main/java/com/redhat/microprofile/jdt/core/JDTQuarkusManagerClassPathKindTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.microprofile.jdt.core; | ||
|
||
import static com.redhat.microprofile.jdt.internal.core.QuarkusAssert.assertProperties; | ||
import static com.redhat.microprofile.jdt.internal.core.QuarkusAssert.assertPropertiesDuplicate; | ||
import static com.redhat.microprofile.jdt.internal.core.QuarkusAssert.p; | ||
|
||
import java.io.File; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.redhat.microprofile.commons.ClasspathKind; | ||
import com.redhat.microprofile.commons.QuarkusProjectInfo; | ||
import com.redhat.microprofile.commons.QuarkusPropertiesScope; | ||
import com.redhat.microprofile.jdt.core.DocumentationConverter; | ||
import com.redhat.microprofile.jdt.core.JDTQuarkusManager; | ||
import com.redhat.microprofile.jdt.internal.core.utils.DependencyUtil; | ||
|
||
/** | ||
* Test collect Quarkus properties from classpath kind | ||
* | ||
* <ul> | ||
* <li>not in classpath -> 0 quarkus properties</li> | ||
* <li>in /java/main/src classpath -> N quarkus properties</li> | ||
* <li>in /java/main/test classpath-> N + M quarkus properties</li> | ||
* </ul> | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class JDTQuarkusManagerClassPathKindTest extends BaseJDTQuarkusManagerTest { | ||
|
||
@Test | ||
public void configQuickstartTest() throws Exception { | ||
|
||
IJavaProject javaProject = loadMavenProject(MavenProjectName.config_quickstart_test); | ||
|
||
// not in classpath -> 0 quarkus properties | ||
IFile fileFromNone = javaProject.getProject().getFile(new Path("application.properties")); | ||
QuarkusProjectInfo infoFromNone = JDTQuarkusManager.getInstance().getQuarkusProjectInfo(fileFromNone, | ||
QuarkusPropertiesScope.classpath, DocumentationConverter.DEFAULT_CONVERTER, new NullProgressMonitor()); | ||
Assert.assertEquals(ClasspathKind.NONE, infoFromNone.getClasspathKind()); | ||
Assert.assertEquals(0, infoFromNone.getProperties().size()); | ||
|
||
File resteasyJARFile = DependencyUtil.getArtifact("io.quarkus", "quarkus-resteasy-common-deployment", | ||
"1.0.0.CR1", null); | ||
Assert.assertNotNull("quarkus-resteasy-common-deployment*.jar is missing", resteasyJARFile); | ||
|
||
// in /java/main/src classpath -> N quarkus properties | ||
IFile fileFromSrc = javaProject.getProject().getFile(new Path("src/main/resources/application.properties")); | ||
QuarkusProjectInfo infoFromSrc = JDTQuarkusManager.getInstance().getQuarkusProjectInfo(fileFromSrc, | ||
QuarkusPropertiesScope.classpath, DocumentationConverter.DEFAULT_CONVERTER, new NullProgressMonitor()); | ||
Assert.assertEquals(ClasspathKind.SRC, infoFromSrc.getClasspathKind()); | ||
assertProperties(infoFromSrc, 185 /* properties from JAR */ + 3 /* properties from Java sources */, | ||
|
||
// quarkus-resteasy JAR | ||
p("quarkus-resteasy-common", "quarkus.resteasy.gzip.enabled", "boolean", "If gzip is enabled", | ||
resteasyJARFile.getAbsolutePath(), | ||
"io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor$ResteasyCommonConfigGzip#enabled", | ||
1, null), | ||
|
||
// GreetingResource | ||
// @ConfigProperty(name = "greeting.message") | ||
// String message; | ||
p(null, "greeting.message", "java.lang.String", null, "/config-quickstart-test/src/main/java", | ||
"org.acme.config.GreetingResource#message", 0, null), | ||
|
||
// @ConfigProperty(name = "greeting.suffix" , defaultValue="!") | ||
// String suffix; | ||
p(null, "greeting.suffix", "java.lang.String", null, "/config-quickstart-test/src/main/java", | ||
"org.acme.config.GreetingResource#suffix", 0, "!"), | ||
|
||
// @ConfigProperty(name = "greeting.name") | ||
// Optional<String> name; | ||
p(null, "greeting.name", "java.util.Optional", null, "/config-quickstart-test/src/main/java", | ||
"org.acme.config.GreetingResource#name", 0, null)); | ||
|
||
assertPropertiesDuplicate(infoFromSrc); | ||
|
||
// in /java/main/test classpath-> N + M quarkus properties | ||
File undertowJARFile = DependencyUtil.getArtifact("io.quarkus", "quarkus-undertow-deployment", "1.0.0.CR1", | ||
null); | ||
Assert.assertNotNull("quarkus-undertow-deployment*.jar is missing", undertowJARFile); | ||
|
||
IFile filefromTest = javaProject.getProject().getFile(new Path("src/test/resources/application.properties")); | ||
QuarkusProjectInfo infoFromTest = JDTQuarkusManager.getInstance().getQuarkusProjectInfo(filefromTest, | ||
QuarkusPropertiesScope.classpath, DocumentationConverter.DEFAULT_CONVERTER, new NullProgressMonitor()); | ||
Assert.assertEquals(ClasspathKind.TEST, infoFromTest.getClasspathKind()); | ||
assertProperties(infoFromTest, 185 /* properties from JAR */ + 3 /* properties from JAR (test) */ + 3 /* | ||
* properties | ||
* from | ||
* (src) | ||
* Java | ||
* sources | ||
*/ | ||
+ 3 /* properties from (test) Java sources */, | ||
|
||
// quarkus-resteasy JAR | ||
p("quarkus-resteasy-common", "quarkus.resteasy.gzip.enabled", "boolean", "If gzip is enabled", | ||
resteasyJARFile.getAbsolutePath(), | ||
"io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor$ResteasyCommonConfigGzip#enabled", | ||
1, null), | ||
|
||
// quarkus-undertow has maven test scope, add it | ||
// <dependency> | ||
// <groupId>io.quarkus</groupId> | ||
// <artifactId>quarkus-undertow</artifactId> | ||
// <scope>test</scope> | ||
// </dependency> | ||
|
||
p("quarkus-undertow", "quarkus.servlet.context-path", "java.util.Optional<java.lang.String>", | ||
"The context path to serve all Servlet context from. This will also affect any resources\nthat run as a Servlet, e.g. JAX-RS.\n\nNote that this is relative to the HTTP root path set in quarkus.http.root-path, so if the context path\nis /bar and the http root is /foo then the actual Servlet path will be /foo/bar.", | ||
undertowJARFile.getAbsolutePath(), "io.quarkus.undertow.deployment.ServletConfig#contextPath", | ||
1, null), | ||
|
||
// GreetingResource | ||
// @ConfigProperty(name = "greeting.message") | ||
// String message; | ||
p(null, "greeting.message", "java.lang.String", null, "/config-quickstart-test/src/main/java", | ||
"org.acme.config.GreetingResource#message", 0, null), | ||
|
||
// @ConfigProperty(name = "greeting.suffix" , defaultValue="!") | ||
// String suffix; | ||
p(null, "greeting.suffix", "java.lang.String", null, "/config-quickstart-test/src/main/java", | ||
"org.acme.config.GreetingResource#suffix", 0, "!"), | ||
|
||
// @ConfigProperty(name = "greeting.name") | ||
// Optional<String> name; | ||
p(null, "greeting.name", "java.util.Optional", null, "/config-quickstart-test/src/main/java", | ||
"org.acme.config.GreetingResource#name", 0, null), | ||
|
||
// TestResource | ||
// @ConfigProperty(name = "greeting.message.test") | ||
// String message; | ||
p(null, "greeting.message.test", "java.lang.String", null, "/config-quickstart-test/src/test/java", | ||
"org.acme.config.TestResource#message", 0, null), | ||
|
||
// @ConfigProperty(name = "greeting.suffix.test" , defaultValue="!") | ||
// String suffix; | ||
p(null, "greeting.suffix.test", "java.lang.String", null, "/config-quickstart-test/src/test/java", | ||
"org.acme.config.TestResource#suffix", 0, "!"), | ||
|
||
// @ConfigProperty(name = "greeting.name.test") | ||
// Optional<String> name; | ||
p(null, "greeting.name.test", "java.util.Optional", null, "/config-quickstart-test/src/test/java", | ||
"org.acme.config.TestResource#name", 0, null) | ||
|
||
); | ||
|
||
assertPropertiesDuplicate(infoFromTest); | ||
} | ||
|
||
} |
Oops, something went wrong.