Skip to content

Commit

Permalink
[KIE-726] create a maven archetype for rules in yaml format (#5595)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco authored Nov 29, 2023
1 parent 13edb2c commit 75871b8
Show file tree
Hide file tree
Showing 26 changed files with 1,202 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,30 @@
*/
package org.drools.drl.extensions;

import org.drools.base.common.MissingDependencyException;
import org.kie.api.internal.utils.KieService;
import org.kie.api.io.Resource;

public class YamlFactory {

private static final String NO_YAML = "You're trying to parse a rule file in YAML format without having drools yaml support. Please add the module org.drools:drools-drlonyaml-todrl to your classpath.";

private static class YamlProviderHolder {
private static final YamlProvider provider = KieService.load(YamlProvider.class);
}

public static YamlProvider getYamlProvider() {
if (YamlProviderHolder.provider == null) {
throwExceptionForMissingYaml();
}
return YamlProviderHolder.provider;
}

public static String loadFromResource(Resource resource) {
return getYamlProvider().loadFromResource(resource);
}

private static void throwExceptionForMissingYaml() {
throw new MissingDependencyException(NO_YAML);
}
}
14 changes: 14 additions & 0 deletions kie-archetypes/kie-drools-yaml-archetype/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/target
/local

# Eclipse, Netbeans and IntelliJ files
/.*
!.gitignore
/nbproject
/*.ipr
/*.iws
/*.iml
*.xpr

# Repository wide ignore mac DS_Store files
.DS_Store
90 changes: 90 additions & 0 deletions kie-archetypes/kie-drools-yaml-archetype/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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</groupId>
<artifactId>kie-archetypes</artifactId>
<version>8.45.0-SNAPSHOT</version>
</parent>

<artifactId>kie-drools-yaml-archetype</artifactId>
<packaging>maven-archetype</packaging>

<name>KIE :: Drools Maven Archetype with Executable Model and YAML format rules</name>
<description>
Drools rule example with executable model and traditional API and rule style with rules in yaml format.
Use property droolsVersion to specify which version of Drools to use in a generated project.
</description>
<url>http://drools.org</url>

<properties>
<dollar>$</dollar>
</properties>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/pom.xml</exclude>
<exclude>**/archetype.properties</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/pom.xml</include>
<include>**/archetype.properties</include>
</includes>
</testResource>
</testResources>

<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.2.1</version>
</extension>
</extensions>

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<ignoreEOLStyle>true</ignoreEOLStyle>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="drools6test.asd"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<requiredProperties>
<requiredProperty key="droolsVersion">
<defaultValue>${project.version}</defaultValue>
</requiredProperty>
<requiredProperty key="slf4jVersion">
<defaultValue>${version.org.slf4j}</defaultValue>
</requiredProperty>
<requiredProperty key="junitVersion">
<defaultValue>${version.junit}</defaultValue>
</requiredProperty>
<requiredProperty key="logbackVersion">
<defaultValue>${version.ch.qos.logback}</defaultValue>
</requiredProperty>
</requiredProperties>
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.drl.yaml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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>

<groupId>${dollar}{groupId}</groupId>
<artifactId>${dollar}{artifactId}</artifactId>
<version>${dollar}{version}</version>
<packaging>kjar</packaging>

<name>${dollar}{artifactId}</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<drools-version>${droolsVersion}</drools-version>
<slf4j-version>${slf4jVersion}</slf4j-version>
<junit-version>${junitVersion}</junit-version>
<logback-version>${logbackVersion}</logback-version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-bom</artifactId>
<type>pom</type>
<version>${drools-version}</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-engine</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-drlonyaml-todrl</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-xml-support</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>${drools-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>

</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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.
*/
#*
* 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.
*#
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};

public class Measurement {
private String id;
private String val;

public Measurement(String id, String val) {
super();
this.id = id;
this.val = val;
}

public String getId() {
return id;
}

public String getVal() {
return val;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Measurement [");
if (id != null)
builder.append("id=").append(id).append(", ");
if (val != null)
builder.append("val=").append(val);
builder.append("]");
return builder.toString();
}
}
Loading

0 comments on commit 75871b8

Please sign in to comment.