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.
feat: Validate if a BuildItem is final or abstract
Fixes redhat-developer#926 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
009ea17
commit 89fdddf
Showing
14 changed files
with
432 additions
and
4 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/quarkus-builditems/.classpath
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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
43 changes: 43 additions & 0 deletions
43
...ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/quarkus-builditems/.gitignore
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,43 @@ | ||
#Maven | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
release.properties | ||
.flattened-pom.xml | ||
|
||
# Eclipse | ||
#.project | ||
#.classpath | ||
.settings/ | ||
bin/ | ||
|
||
# IntelliJ | ||
.idea | ||
*.ipr | ||
*.iml | ||
*.iws | ||
|
||
# NetBeans | ||
nb-configuration.xml | ||
|
||
# Visual Studio Code | ||
.vscode | ||
.factorypath | ||
|
||
# OSX | ||
.DS_Store | ||
|
||
# Vim | ||
*.swp | ||
*.swo | ||
|
||
# patch | ||
*.orig | ||
*.rej | ||
|
||
# Local environment | ||
.env | ||
|
||
# Plugin directory | ||
/.quarkus/cli/plugins/ |
23 changes: 23 additions & 0 deletions
23
...t.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/quarkus-builditems/.project
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>quarkus-builditems</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
116 changes: 116 additions & 0 deletions
116
...dt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/quarkus-builditems/pom.xml
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,116 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.acme</groupId> | ||
<artifactId>quarkus-builditems</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<properties> | ||
<compiler-plugin.version>3.11.0</compiler-plugin.version> | ||
<maven.compiler.release>17</maven.compiler.release> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> | ||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> | ||
<quarkus.platform.version>3.3.1</quarkus.platform.version> | ||
<skipITs>true</skipITs> | ||
<surefire-plugin.version>3.1.2</surefire-plugin.version> | ||
</properties> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${quarkus.platform.group-id}</groupId> | ||
<artifactId>${quarkus.platform.artifact-id}</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>${quarkus.platform.group-id}</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<version>${quarkus.platform.version}</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
<goal>generate-code</goal> | ||
<goal>generate-code-tests</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${compiler-plugin.version}</version> | ||
<configuration> | ||
<compilerArgs> | ||
<arg>-parameters</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire-plugin.version}</version> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>${surefire-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<properties> | ||
<skipITs>false</skipITs> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
</project> |
6 changes: 6 additions & 0 deletions
6
...est/projects/maven/quarkus-builditems/src/main/java/org/acme/builditems/BadBuildItem.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,6 @@ | ||
package org.acme.builditems; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
public class BadBuildItem extends MultiBuildItem { | ||
} |
6 changes: 6 additions & 0 deletions
6
...st/projects/maven/quarkus-builditems/src/main/java/org/acme/builditems/GoodBuildItem.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,6 @@ | ||
package org.acme.builditems; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class GoodBuildItem extends SimpleBuildItem { | ||
} |
Empty file.
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
54 changes: 54 additions & 0 deletions
54
...n/java/com/redhat/microprofile/jdt/quarkus/builditems/QuarkusBuildItemASTVisitorTest.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,54 @@ | ||
package com.redhat.microprofile.jdt.quarkus.builditems; | ||
|
||
import static org.eclipse.lsp4mp.jdt.core.MicroProfileForJavaAssert.assertJavaDiagnostics; | ||
import static org.eclipse.lsp4mp.jdt.core.MicroProfileForJavaAssert.d; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4mp.commons.DocumentFormat; | ||
import org.eclipse.lsp4mp.commons.MicroProfileJavaDiagnosticsParams; | ||
import org.eclipse.lsp4mp.jdt.core.BasePropertiesManagerTest; | ||
import org.junit.Test; | ||
|
||
import com.redhat.microprofile.jdt.internal.quarkus.QuarkusConstants; | ||
import com.redhat.microprofile.jdt.internal.quarkus.builditems.QuarkusBuildItemErrorCode; | ||
import com.redhat.microprofile.jdt.quarkus.QuarkusMavenProjectName; | ||
|
||
public class QuarkusBuildItemASTVisitorTest extends BasePropertiesManagerTest { | ||
|
||
@Test | ||
public void buildItemClassifier() throws Exception { | ||
IJavaProject javaProject = loadMavenProject(QuarkusMavenProjectName.quarkus_builditems); | ||
|
||
{ // Bad BuildItem shows error | ||
MicroProfileJavaDiagnosticsParams diagnosticsParams = new MicroProfileJavaDiagnosticsParams(); | ||
IFile javaFile = javaProject.getProject() | ||
.getFile(new Path("src/main/java/org/acme/builditems/BadBuildItem.java")); | ||
String uri = javaFile.getLocation().toFile().toURI().toASCIIString(); | ||
diagnosticsParams.setUris(Arrays.asList(uri)); | ||
diagnosticsParams.setDocumentFormat(DocumentFormat.Markdown); | ||
|
||
Diagnostic d = d(4, 13, 25, | ||
"BuildItem class `org.acme.builditems.BadBuildItem` must either be declared final or abstract", | ||
DiagnosticSeverity.Error, QuarkusConstants.QUARKUS_DIAGNOSTIC_SOURCE, | ||
QuarkusBuildItemErrorCode.InvalidModifierBuildItem); | ||
assertJavaDiagnostics(diagnosticsParams, JDT_UTILS, d); | ||
} | ||
|
||
{ // Good BuildItem shows no error | ||
MicroProfileJavaDiagnosticsParams diagnosticsParams = new MicroProfileJavaDiagnosticsParams(); | ||
IFile javaFile = javaProject.getProject() | ||
.getFile(new Path("src/main/java/org/acme/builditems/GoodBuildItem.java")); | ||
String uri = javaFile.getLocation().toFile().toURI().toASCIIString(); | ||
diagnosticsParams.setUris(Arrays.asList(uri)); | ||
diagnosticsParams.setDocumentFormat(DocumentFormat.Markdown); | ||
assertJavaDiagnostics(diagnosticsParams, JDT_UTILS); | ||
} | ||
|
||
} | ||
} |
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
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
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
28 changes: 28 additions & 0 deletions
28
...va/com/redhat/microprofile/jdt/internal/quarkus/builditems/QuarkusBuildItemErrorCode.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,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.microprofile.jdt.internal.quarkus.builditems; | ||
|
||
import org.eclipse.lsp4mp.jdt.core.java.diagnostics.IJavaErrorCode; | ||
|
||
/** | ||
* Represents error codes for validation issues in classes inheriting | ||
* <code>io.quarkus.builder.item.BuildItem</code>. | ||
*/ | ||
public enum QuarkusBuildItemErrorCode implements IJavaErrorCode { | ||
|
||
InvalidModifierBuildItem; | ||
|
||
@Override | ||
public String getCode() { | ||
return name(); | ||
} | ||
} |
Oops, something went wrong.