Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[releases/6.3.z] WINDUPRULE-1041 jakarta-api-to-quarkus groovy rules (#1051) #1054

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package quarkus.javaee

import org.jboss.windup.ast.java.data.TypeReferenceLocation
import org.jboss.windup.config.GraphRewrite
import org.jboss.windup.config.Variables
import org.jboss.windup.config.metadata.TechnologyReference
import org.jboss.windup.config.operation.Iteration
import org.jboss.windup.config.operation.iteration.AbstractIterationOperation
import org.jboss.windup.graph.model.FileLocationModel
import org.jboss.windup.graph.model.FileReferenceModel
import org.jboss.windup.graph.model.ProjectModel
import org.jboss.windup.graph.model.WindupVertexFrame
import org.jboss.windup.graph.model.resource.FileModel
import org.jboss.windup.project.condition.Artifact
import org.jboss.windup.project.condition.Project
import org.jboss.windup.reporting.category.IssueCategory
import org.jboss.windup.reporting.category.IssueCategoryRegistry
import org.jboss.windup.reporting.config.Hint
import org.jboss.windup.reporting.config.Link
import org.jboss.windup.rules.apps.java.condition.JavaClass
import org.ocpsoft.rewrite.config.And
import org.ocpsoft.rewrite.context.EvaluationContext

import java.util.stream.Collectors
import java.util.stream.StreamSupport

final IssueCategory mandatoryIssueCategory = new IssueCategoryRegistry().getByID(IssueCategoryRegistry.MANDATORY)
final Link guideLink = Link.to("Quarkus - Guides", "https://quarkus.io/guides/resteasy-reactive")

static boolean matchesProject(GraphRewrite event, FileLocationModel payload) {
final Iterable<? extends WindupVertexFrame> previouslyFound = Optional.ofNullable(Variables.instance(event).findVariable("discard")).orElse(Collections.emptySet())
final Set<ProjectModel> projectModels = StreamSupport.stream(previouslyFound.spliterator(), false)
.map {
if (it instanceof FileReferenceModel) return ((FileReferenceModel) it).getFile().getProjectModel()
else if (it instanceof FileModel) return ((FileModel) it).getProjectModel()
else return null
}
.collect (Collectors.toSet())
final boolean matchesProject = projectModels.isEmpty() || projectModels.stream().anyMatch{payload.getFile().belongsToProject(it)}
return matchesProject
}

ruleSet("jakarta-api-to-quarkus-groovy")
.addSourceTechnology(new TechnologyReference("java-ee", null))
.addTargetTechnology(new TechnologyReference("quarkus", null))
.addRule()
.when(
And.all(
JavaClass.references("jakarta.ws.rs.{*}").at(TypeReferenceLocation.IMPORT).as("discard"),
Project.dependsOnArtifact(Artifact.withGroupId("jakarta.platform").andArtifactId("jakarta.jakartaee-api")).as("dependency")
)
)
.perform(
Iteration.over("dependency").perform(
new AbstractIterationOperation<FileLocationModel>() {
void perform(GraphRewrite event, EvaluationContext context, FileLocationModel payload) {
if (matchesProject(event, payload)) {
((Hint) Hint.titled("Replace jakarta JAX-RS dependency")
.withText("""
At least one Java class importing from the `jakarta.ws.rs` package has been found so the dependency `jakarta.platform:jakarta.jakartaee-api` has to be replaced with `io.quarkus:quarkus-resteasy-reactive` artifact.
""")
.withIssueCategory(mandatoryIssueCategory)
.with(guideLink)
.withEffort(1)
).performParameterized(event, context, payload)
}
}
}
)
.endIteration()
)
.withId("jakarta-api-to-quarkus-groovy-00000")
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.eap.quickstarts</groupId>
<artifactId>quickstart-parent</artifactId>
<!--
Maintain separation between the artifact id and the version to help prevent
merge conflicts between commits changing the GA and those changing the V.
-->
<version>7.2.0.GA</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>helloworld-rs</artifactId>
<packaging>war</packaging>
<name>Quickstart: helloworld-rs</name>
<description>A simple Hello World project that uses JAX-RS</description>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>


<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.quickstarts.rshelloworld;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;

/**
* A simple REST service which is able to say hello to someone using HelloService Please take a look at the web.xml where JAX-RS
* is enabled
*
* @author [email protected]
*
*/

@Path("/")
public class HelloWorld {
@GET
@Path("/json")
@Produces({ "application/json" })
public String getHelloWorldJSON() {
return "{\"result\":\"" + helloService.createHelloMessage("World") + "\"}";
}

@GET
@Path("/xml")
@Produces({ "application/xml" })
public String getHelloWorldXML() {
return "<xml><result>" + helloService.createHelloMessage("World") + "</result></xml>";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruletest id="jakarta-api-to-quarkus-tests"
xmlns="http://windup.jboss.org/schema/jboss-ruleset"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data/*</testDataPath>
<rulePath>../jakarta-api-to-quarkus.windup.groovy</rulePath>
<ruleset>
<rules>
<rule id="jakarta-api-to-quarkus-groovy-00000-test">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="At least one Java class importing from the `jakarta.ws.rs` package has been found"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[jakarta-api-to-quarkus-groovy-00000] javax.ws.rs transitive dependency hint was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<rule id="javaee-pom-to-quarkus-00000-test">
<when>
<not>
<iterable-filter size="5">
<iterable-filter size="6">
<hint-exists message="The project artifact's current extension \(i.e. `&lt;packaging&gt;` tag value\) is"/>
</iterable-filter>
</not>
Expand All @@ -22,7 +22,7 @@
<rule id="javaee-pom-to-quarkus-00010-test">
<when>
<not>
<iterable-filter size="7">
<iterable-filter size="8">
<hint-exists message="Use the Quarkus BOM to omit the version of the different Quarkus dependencies"/>
</iterable-filter>
</not>
Expand All @@ -34,7 +34,7 @@
<rule id="javaee-pom-to-quarkus-00020-test">
<when>
<not>
<iterable-filter size="7">
<iterable-filter size="8">
<hint-exists message="Use the Quarkus Maven plugin adding the following sections to the `pom.xml` file"/>
</iterable-filter>
</not>
Expand All @@ -46,7 +46,7 @@
<rule id="javaee-pom-to-quarkus-00030-test">
<when>
<not>
<iterable-filter size="7">
<iterable-filter size="8">
<hint-exists message="Use the Maven Compiler plugin adding the following sections to the `pom.xml` file"/>
</iterable-filter>
</not>
Expand All @@ -58,7 +58,7 @@
<rule id="javaee-pom-to-quarkus-00040-test">
<when>
<not>
<iterable-filter size="7">
<iterable-filter size="8">
<hint-exists message="Use the Maven Surefire plugin adding the following sections to the `pom.xml` file"/>
</iterable-filter>
</not>
Expand All @@ -70,7 +70,7 @@
<rule id="javaee-pom-to-quarkus-00050-test">
<when>
<not>
<iterable-filter size="7">
<iterable-filter size="8">
<hint-exists message="Use the Maven Failsafe plugin adding the following sections to the `pom.xml` file"/>
</iterable-filter>
</not>
Expand All @@ -82,7 +82,7 @@
<rule id="javaee-pom-to-quarkus-00060-test">
<when>
<not>
<iterable-filter size="7">
<iterable-filter size="8">
<hint-exists message="Leverage a Maven profile to run the Quarkus native build adding the following section to the `pom.xml` file"/>
</iterable-filter>
</not>
Expand Down