Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovds committed Nov 22, 2024
1 parent a3c7b89 commit 72c05af
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,16 @@ private void processTemplates(
FileSet fileSet = iterator.next();
count++;

// Evaluate the includeCondition attribute
String includeCondition = fileSet.getIncludeCondition();
if (includeCondition != null && !includeCondition.isEmpty()) {
String evaluatedCondition = evaluateExpression(context, "includeCondition", includeCondition);
if (!Boolean.parseBoolean(evaluatedCondition)) {
LOGGER.debug("Skipping fileset " + fileSet + " due to includeCondition: " + includeCondition);
continue;
}
}

List<String> fileSetResources =
archetypeFilesResolver.filterFiles(moduleOffset, fileSet, archetypeResources);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
<include>**/*.mdo</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false" includeCondition="${extraSupport == 'y'}">
<directory>src/main/extra</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>

</archetype-descriptor>
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@
<required>false</required>
<description>Encoding to use when filtering content.</description>
</field>
<field xml.attribute="true">
<name>includeCondition</name>
<version>1.0.0+</version>
<type>String</type>
<required>false</required>
<description>Condition to include the fileset based on a property value.</description>
</field>
<field>
<name>directory</name>
<version>1.0.0+</version>
Expand Down
20 changes: 20 additions & 0 deletions test-archetype/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<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>

<groupId>com.examples</groupId>
<artifactId>archetype-test</artifactId>
<version>1.0-SNAPSHOT</version>

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

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<archetype-descriptor xmlns="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 http://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd"
name="example" partial="false">

<requiredProperties>
<requiredProperty key="someCondition"></requiredProperty>
</requiredProperties>

<fileSets>
<fileSet encoding="UTF-8" filtered="true" packaged="true">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8" filtered="true" packaged="false">
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8" filtered="true" packaged="true">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8" filtered="true" packaged="false" includeCondition="${someCondition}">
<directory>src/main/resources</directory>
<includes>
<include>**/*.json</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>
23 changes: 23 additions & 0 deletions test-archetype/src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>

<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>

<properties>
<custom-property>${my-property}</custom-property>
<custom-property-2>${my-default-property}</custom-property-2>
<maven.compiler.release>21</maven.compiler.release>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.6.0.Final</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"something": "Hello, World!"
}
23 changes: 23 additions & 0 deletions test-archetype/src/main/resources/archetype-resources/src/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>

<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>

<properties>
<custom-property>${my-property}</custom-property>
<custom-property-2>${my-default-property}</custom-property-2>
<maven.compiler.release>21</maven.compiler.release>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.6.0.Final</version>
</dependency>
</dependencies>

</project>
23 changes: 23 additions & 0 deletions tmp/test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>

<groupId>com.example</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<custom-property>${my-property}</custom-property>
<custom-property-2>${my-default-property}</custom-property-2>
<maven.compiler.release>21</maven.compiler.release>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.6.0.Final</version>
</dependency>
</dependencies>

</project>
3 changes: 3 additions & 0 deletions tmp/test/src/main/resources/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"something": "Hello, World!"
}

0 comments on commit 72c05af

Please sign in to comment.