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

[ARCHETYPE-274] Conditionally include or exclude a file from archetype during generation #244

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).

Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ public void createArchetype(ArchetypeCreationRequest request, ArchetypeCreationR
Model pom = pomManager.readPom(project.getFile());

List<String> excludePatterns = configurationProperties.getProperty(Constants.EXCLUDE_PATTERNS) != null
? Arrays.asList(
StringUtils.split(configurationProperties.getProperty(Constants.EXCLUDE_PATTERNS), ","))
? Arrays.asList(configurationProperties
.getProperty(Constants.EXCLUDE_PATTERNS)
.split(","))
: Collections.emptyList();

List<String> fileNames = resolveFileNames(pom, basedir, excludePatterns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,17 @@ private void processTemplates(
FileSet fileSet = iterator.next();
count++;

final String includeCondition = fileSet.getIncludeCondition();
if (includeCondition != null && !includeCondition.isEmpty()) {
final String evaluatedCondition = evaluateExpression(context, "includeCondition", includeCondition);
if (!Boolean.parseBoolean(evaluatedCondition)) {
LOGGER.debug(String.format(
"Skipping fileset %s due to includeCondition: %s being: %s",
fileSet, includeCondition, evaluatedCondition));
continue;
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
<!-- empty dependencies, with comments -->
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
<module>subproject</module>
</modules>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
<module>subsubproject</module>
</modules>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
<name>Maven archetype Test Subsubfolder</name>
<packaging>jar</packaging>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
<!-- empty dependencies, with comments -->
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
</plugin>
</plugins>
</reporting>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-archetype-quickstart</artifactId>
<version>1.0-alpha-1-SNAPSHOT</version>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@
<required>false</required>
<description>Encoding to use when filtering content.</description>
</field>
<field xml.attribute="true">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does xml.attribute come from? Per XML 1.0 spec "Names beginning with the string 'xml', or with any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that is seriously broken. Not something we can fix in this PR, but another reason to avoid Modello.

<name>includeCondition</name>
<version>1.1.0+</version>
<type>String</type>
<required>false</required>
<description>A string value that should resolve to a boolean value to conditionally include filesets.
This condition should be either a boolean as String or a velocity template language statement that resolves
to a boolean value. If the descriptor contains includeCondition="${shouldInclude}" and the archetype has
a (required) property like shouldInclude=true the fileset is included.</description>
</field>
<field>
<name>directory</name>
<version>1.0.0+</version>
Expand Down
2 changes: 1 addition & 1 deletion archetype-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
<archetype.properties>archetype.properties</archetype.properties>
</properties>

</project>
</project>
1 change: 0 additions & 1 deletion deploySite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@

mvn package site site:stage -Preporting $@
mvn scm-publish:publish-scm $@

Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ under the License.
</parent>
<artifactId>${projectName}-test2</artifactId>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ under the License.
</parent>
<artifactId>${rootArtifactId}-test1</artifactId>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ under the License.
<module>${projectName}-test2</module>
</modules>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

excludePatterns=build.log,invoker.properties,verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
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.apache.maven.plugins.archetype.its</groupId>
<artifactId>archetype274-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>archetype274-archetype</artifactId>
<packaging>maven-archetype</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<archetypeDirectory>src/main/resources</archetypeDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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 name="include-condition-test">

<requiredProperties>
<requiredProperty key="extraSupport"/>
<requiredProperty key="anotherSupport"/>
</requiredProperties>

<fileSets>
<fileSet filtered="true" packaged="true">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="false" packaged="false" includeCondition="${extraSupport}">
<directory>src/main/resources</directory>
<includes>
<include>**/include-without-filter.txt</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false" includeCondition="${extraSupport}">
<directory>src/main/resources</directory>
<includes>
<include>**/include-with-filter.txt</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false" includeCondition="${anotherSupport}">
<directory>src/main/resources</directory>
<includes>
<include>**/exclude-with-filter.txt</include>
</includes>
</fileSet>
<fileSet filtered="false" packaged="false" includeCondition="${anotherSupport}">
<directory>src/main/resources</directory>
<includes>
<include>**/exclude-without-filter.txt</include>
</includes>
</fileSet>
</fileSets>

</archetype-descriptor>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
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>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>pom</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

public class App {
public static void main(String[] args) {
System.out.println("This file should not be included");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

this should be excluded: ${package}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

this should be excluded: ${package}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

this should be included: ${package}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

this should be included: ${package}
Loading
Loading