Skip to content

Commit

Permalink
[incubator-kie-issues#1460] Fix kogito-maven-plugin (apache#3757)
Browse files Browse the repository at this point in the history
* [incubator-kie-issues#1460] Working unit tests. Working external example

* [incubator-kie-issues#1460] Implemented it tests

* [incubator-kie-issues#1460] Adapted tests

* [incubator-kie-issues#1460] Disable flaky test

* [incubator-kie-issues#1460] Fix maven reactor

* [incubator-kie-issues#1460] Fix maven reactor

* [incubator-kie-issues#1460] Fix maven reactor

* [incubator-kie-issues#1460] Optimizing compilation invocation. Removing ProcessClassesMojo.java

* [incubator-kie-issues#1460] Removing left-overs

* [incubator-kie-issues#1460] Moving kogito-maven-plugin-test as standalone module to avoid springboot dependency inside kogito-maven-plugin

* [incubator-kie-issues#1460] Removing leftover properties

---------

Co-authored-by: Gabriele-Cardosi <[email protected]>
  • Loading branch information
2 people authored and rgdoliveira committed Dec 2, 2024
1 parent 86fe149 commit 9fa9e3b
Show file tree
Hide file tree
Showing 44 changed files with 2,320 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,17 @@ public Optional<ApplicationSection> section() {

@Override
protected Collection<GeneratedFile> internalGenerate() {
Collection<GeneratedFile> generatedFiles = new ArrayList<>();

switch (persistenceType()) {
case INFINISPAN_PERSISTENCE_TYPE:
case FILESYSTEM_PERSISTENCE_TYPE:
case MONGODB_PERSISTENCE_TYPE:
case JDBC_PERSISTENCE_TYPE:
case KAFKA_PERSISTENCE_TYPE:
case POSTGRESQL_PERSISTENCE_TYPE:
break;
return generateFiles();
default:
throw new IllegalArgumentException("Unknown persistenceType " + persistenceType());
}

generatedFiles.addAll(generateProtoMarshaller());
generatedFiles.addAll(generateProtoForDataIndex());

return generatedFiles;
}

@Override
Expand All @@ -149,6 +142,13 @@ public String persistenceType() {
return context().getApplicationProperty(KOGITO_PERSISTENCE_TYPE).orElse(PersistenceGenerator.DEFAULT_PERSISTENCE_TYPE);
}

protected Collection<GeneratedFile> generateFiles() {
Collection<GeneratedFile> toReturn = new ArrayList<>();
toReturn.addAll(generateProtoMarshaller());
toReturn.addAll(generateProtoForDataIndex());
return toReturn;
}

protected Collection<GeneratedFile> generateProtoMarshaller() {
if (!hasProtoMarshaller(context())) {
// TODO implement a validation check to verify that data classes implement Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected Proto generate(String messageComment, String fieldComment, String pack
alreadyGenerated.addAll(protoBuiltins());
for (T dataModel : dataModels.stream().filter(this::filterDataModels).toList()) {
try {
LOGGER.debug("internal proto geneartion {}", fqn(dataModel));
LOGGER.debug("internal proto generation {}", fqn(dataModel));
internalGenerate(
proto,
alreadyGenerated,
Expand Down
181 changes: 181 additions & 0 deletions kogito-maven-plugin-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-build-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../kogito-build/kogito-build-parent/pom.xml</relativePath>
</parent>

<artifactId>kogito-maven-plugin-test</artifactId>


<properties>
<java.module.name>org.kie.kogito.maven.plugin.testing</java.module.name>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-spring-boot-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisions-spring-boot-starter</artifactId>
</dependency>

<!--Tests -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Packaging -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${version.jar.plugin}</version>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestEntries combine.children="append">
<Automatic-Module-Name>${java.module.name}</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</execution>
<!-- No OSGi manifestEntries for <goal>jar</goal>: if it supported, then felix has already added them -->
<execution>
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
<excludes>
<exclude>**/logback-test.xml</exclude>
<exclude>**/jndi.properties</exclude>
</excludes>
<archive>
<manifestEntries>
<Bundle-SymbolicName>${java.module.name}.tests</Bundle-SymbolicName>
<Bundle-Version>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}.${osgi.snapshot.qualifier}</Bundle-Version>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Vendor>${project.organization.name}</Bundle-Vendor>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${version.org.springframework.boot}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generateModel</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<systemPropertyVariables>
<java.util.logging.manager>java.util.logging.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>add-it-resources</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/test-run/META-INF</outputDirectory>
<resources>
<resource>
<directory>target/classes/META-INF</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.kie.kogito.traffic;

import java.time.ZonedDateTime;
import java.util.Date;

import org.kie.kogito.traffic.licensevalidation.Driver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class DriverService {

private static Logger LOGGER = LoggerFactory.getLogger(DriverService.class);

public Driver getDriver(String driverId) {
LOGGER.info("Get Driver Information for id = {}", driverId);
//Could call an external service, database, etc.

//Mocking driver details
String[] parts = driverId.split("-");
long days = Long.parseLong(parts[0]);
int points = Integer.parseInt(parts[1]);
Date licenseExpiration = new Date(ZonedDateTime.now().plusDays(days).toInstant().toEpochMilli());
return new Driver(driverId, "Arthur", "SP", "Campinas", points, 30, licenseExpiration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.kie.kogito.traffic;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Fine {

@JsonProperty("Amount")
private Double amount;

@JsonProperty("Points")
private Integer points;

public Double getAmount() {
return amount;
}

public void setAmount(Double amount) {
this.amount = amount;
}

public Integer getPoints() {
return points;
}

public void setPoints(Integer points) {
this.points = points;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.kie.kogito.traffic;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = { "org.kie.kogito.**", "com.example.**" })
public class KogitoApplication {

public static void main(String[] args) {
SpringApplication.run(KogitoApplication.class, args);
}
}
Loading

0 comments on commit 9fa9e3b

Please sign in to comment.