forked from redhat-developer/intellij-quarkus
-
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.
Signed-off-by: Fred Bricon <[email protected]>
- Loading branch information
1 parent
db1ab9b
commit 9c95979
Showing
11 changed files
with
380 additions
and
1 deletion.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
projects/quarkus/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/ |
116 changes: 116 additions & 0 deletions
116
projects/quarkus/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
...kus/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
...us/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
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
30 changes: 30 additions & 0 deletions
30
...m/redhat/devtools/intellij/quarkus/psi/internal/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,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.quarkus.psi.internal.builditems; | ||
|
||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.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(); | ||
} | ||
} | ||
|
99 changes: 99 additions & 0 deletions
99
...ools/intellij/quarkus/psi/internal/validators/QuarkusBuildItemDiagnosticsParticipant.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,99 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.quarkus.psi.internal.validators; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.psi.PsiClass; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.PsiModifier; | ||
import com.intellij.psi.util.InheritanceUtil; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.diagnostics.IJavaDiagnosticsParticipant; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.diagnostics.JavaDiagnosticsContext; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.PositionUtils; | ||
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils; | ||
import com.redhat.devtools.intellij.quarkus.QuarkusConstants; | ||
import com.redhat.devtools.intellij.quarkus.psi.internal.builditems.QuarkusBuildItemErrorCode; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4mp.commons.DocumentFormat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Validates <code>io.quarkus.builder.item.BuildItem</code> subclasses. | ||
* <ul> | ||
* <li>checks if the BuildItem is final or abstract</li> | ||
* </ul> | ||
*/ | ||
public class QuarkusBuildItemDiagnosticsParticipant implements IJavaDiagnosticsParticipant { | ||
|
||
private static final String INVALID_MODIFIER = "BuildItem class %2$s%1$s%2$s must either be declared final or abstract"; | ||
|
||
@Override | ||
public boolean isAdaptedForDiagnostics(JavaDiagnosticsContext context) { | ||
// Collection of diagnostics for Quarkus Build Items is done only if | ||
// io.quarkus.builder.item.BuildItem is on the classpath | ||
Module javaProject = context.getJavaProject(); | ||
return PsiTypeUtils.findType(javaProject, QuarkusConstants.QUARKUS_BUILD_ITEM_CLASS_NAME) != null; | ||
} | ||
|
||
@Override | ||
public List<Diagnostic> collectDiagnostics(JavaDiagnosticsContext context) { | ||
PsiFile typeRoot = context.getTypeRoot(); | ||
PsiElement[] elements = typeRoot.getChildren(); | ||
List<Diagnostic> diagnostics = new ArrayList<>(); | ||
collectDiagnostics(elements, diagnostics, context); | ||
return diagnostics; | ||
} | ||
|
||
private static void collectDiagnostics(PsiElement[] elements, List<Diagnostic> diagnostics, | ||
JavaDiagnosticsContext context) { | ||
for (PsiElement element : elements) { | ||
if (element instanceof PsiClass) { | ||
PsiClass psiClass = (PsiClass) element; | ||
if (isBuildItem(psiClass)) { | ||
validateBuildItem(psiClass, diagnostics, context); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static boolean isBuildItem(PsiClass type) { | ||
return InheritanceUtil.isInheritor(type, QuarkusConstants.QUARKUS_BUILD_ITEM_CLASS_NAME); | ||
} | ||
|
||
private static void validateBuildItem(PsiClass psiClass, List<Diagnostic> diagnostics, JavaDiagnosticsContext context) { | ||
if (psiClass.hasModifierProperty(PsiModifier.FINAL) | ||
|| psiClass.hasModifierProperty(PsiModifier.ABSTRACT) | ||
) { | ||
return; | ||
} | ||
Range range = PositionUtils.toClassDeclarationRange(psiClass, context.getUtils()); | ||
Diagnostic d = context.createDiagnostic(context.getUri(), | ||
createDiagnosticMessage(psiClass, context.getDocumentFormat()), | ||
range, QuarkusConstants.QUARKUS_DIAGNOSTIC_SOURCE, | ||
QuarkusBuildItemErrorCode.InvalidModifierBuildItem, | ||
DiagnosticSeverity.Error | ||
); | ||
diagnostics.add(d); | ||
} | ||
|
||
private static String createDiagnosticMessage(PsiClass classType, DocumentFormat documentFormat) { | ||
String quote = DocumentFormat.Markdown.equals(documentFormat)?"`":"'"; | ||
return String.format(INVALID_MODIFIER, classType.getQualifiedName(), quote); | ||
} | ||
} |
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
Oops, something went wrong.