Skip to content

Commit

Permalink
Easily generate all-quarkus-properties.json
Browse files Browse the repository at this point in the history
Fixes redhat-developer#182

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Jan 22, 2020
1 parent 9ff1f4a commit e50f616
Show file tree
Hide file tree
Showing 26 changed files with 24,022 additions and 12,950 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ public MicroProfileProjectInfo getMicroProfileProjectInfo(IJavaProject javaProje
* the search.
* @throws JavaModelException
*/
private IJavaProject configureSearchClasspath(IJavaProject javaProject, boolean excludeTestCode,
SubMonitor mainMonitor) throws JavaModelException {
public IJavaProject configureSearchClasspath(IJavaProject javaProject, boolean excludeTestCode,
IProgressMonitor monitor) throws JavaModelException {
SubMonitor mainMonitor = SubMonitor.convert(monitor);
// Get the java project used for the search
mainMonitor.subTask("Configuring search classpath");
int length = getPropertiesProviders().size();
Expand Down Expand Up @@ -276,6 +277,10 @@ private IJavaSearchScope createSearchScope(IJavaProject project, List<MicroProfi
*/
private IJavaProject getJavaProject(IJavaProject javaProject, boolean excludeTestCode, SubMonitor monitor)
throws JavaModelException {
if (javaProject instanceof FakeJavaProject) {
// The java project is already resolved
return javaProject;
}
int length = getPropertiesProviders().size();
SubMonitor mainMonitor = monitor;
IClasspathEntry[] resolvedClasspath = ((JavaProject) javaProject).getResolvedClasspath();
Expand Down Expand Up @@ -382,13 +387,15 @@ public Location findPropertyLocation(MicroProfilePropertyDefinitionParams params
if (file == null) {
throw new UnsupportedOperationException(String.format("Cannot find IFile for '%s'", params.getUri()));
}
return findPropertyLocation(file, params.getSourceType(), params.getSourceField(), params.getSourceMethod(),
utils, progress);
String projectName = file.getProject().getName();
IJavaProject javaProject = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(projectName);
return findPropertyLocation(javaProject, params.getSourceType(), params.getSourceField(),
params.getSourceMethod(), utils, progress);
}

public Location findPropertyLocation(IFile file, String sourceType, String sourceField, String sourceMethod,
IJDTUtils utils, IProgressMonitor progress) throws JavaModelException, CoreException {
IMember fieldOrMethod = findDeclaredProperty(file, sourceType, sourceField, sourceMethod, progress);
public Location findPropertyLocation(IJavaProject javaProject, String sourceType, String sourceField,
String sourceMethod, IJDTUtils utils, IProgressMonitor progress) throws JavaModelException, CoreException {
IMember fieldOrMethod = findDeclaredProperty(javaProject, sourceType, sourceField, sourceMethod, progress);
if (fieldOrMethod != null) {
IClassFile classFile = fieldOrMethod.getClassFile();
if (classFile != null) {
Expand All @@ -402,25 +409,6 @@ public Location findPropertyLocation(IFile file, String sourceType, String sourc
return null;
}

/**
* Returns the Java field from the given property source
*
* @param file the application.properties file
* @param sourceType the source type (class or interface)
* @param sourceField the source field and null otherwise.
* @param sourceMethod the source method and null otherwise.
* @param progress the progress monitor.
* @return the Java field from the given property source
* @throws JavaModelException
* @throws CoreException
*/
public IMember findDeclaredProperty(IFile file, String sourceType, String sourceField, String sourceMethod,
IProgressMonitor progress) throws JavaModelException, CoreException {
String projectName = file.getProject().getName();
IJavaProject javaProject = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(projectName);
return findDeclaredProperty(javaProject, sourceType, sourceField, sourceMethod, progress);
}

/**
* Returns the Java field from the given property source
*
Expand All @@ -440,6 +428,11 @@ public IMember findDeclaredProperty(IJavaProject javaProject, String sourceType,
if (sourceType == null) {
return null;
}
IJavaProject fakeProject = null;
if (javaProject instanceof FakeJavaProject) {
fakeProject = javaProject;
javaProject = ((FakeJavaProject) fakeProject).getRootProject();
}
// Step1 (20%) : try to find type with the standard classpath
mainMonitor.subTask("Finding type with the standard classpath");
SubMonitor subMonitor = mainMonitor.split(20).setWorkRemaining(100);
Expand All @@ -457,7 +450,9 @@ public IMember findDeclaredProperty(IJavaProject javaProject, String sourceType,
if (type == null) {
// Not found, type could be included in deployment JAR which is not in classpath
// Try to find type from deployment JAR
IJavaProject fakeProject = configureSearchClasspath(javaProject, false, subMonitor);
if (fakeProject == null) {
fakeProject = configureSearchClasspath(javaProject, false, subMonitor);
}
if (mainMonitor.isCanceled()) {
throw new OperationCanceledException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public static String getDefaultValue(IMethod method) {
}

public static String getPropertyType(IType type, String typeName) {
return type != null ? type.getFullyQualifiedName() : typeName;
return type != null ? type.getFullyQualifiedName('.') : typeName;
}

public static String getSourceType(IMember member) {
return member.getDeclaringType().getFullyQualifiedName();
return member.getDeclaringType().getFullyQualifiedName('.');
}

public static String getSourceField(IField field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Require-Bundle: org.junit,
com.google.guava,
com.redhat.microprofile.jdt.quarkus,
org.eclipse.lsp4j
Import-Package: com.google.gson
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,22 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
<artifactId>all-quarkus-extensions</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<quarkus.version>0.21.1</quarkus.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.1.1.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.1.1.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -83,10 +88,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-keycloak</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client</artifactId>
Expand Down Expand Up @@ -243,13 +244,21 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-keycloak-authorization</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
Expand All @@ -258,6 +267,10 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
Expand All @@ -279,21 +292,6 @@
</activation>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
Expand All @@ -313,6 +311,9 @@
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Loading

0 comments on commit e50f616

Please sign in to comment.