You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2024/10/22 15:27:55 UTC
(maven-archetype) branch master updated: [ARCHETYPE-574] Use default values in integration tests goal (#232)
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-archetype.git
The following commit(s) were added to refs/heads/master by this push:
new 96374eb3 [ARCHETYPE-574] Use default values in integration tests goal (#232)
96374eb3 is described below
commit 96374eb3ea5b61f346f5291d6092159229caff9e
Author: Giovanni van der Schelde <27...@users.noreply.github.com>
AuthorDate: Tue Oct 22 17:27:50 2024 +0200
[ARCHETYPE-574] Use default values in integration tests goal (#232)
Co-authored-by: Slawomir Jaranowski <s....@gmail.com>
---
.../invoker.properties} | 11 +----
.../pom.xml | 57 ++++++++++++++++++++++
.../META-INF/maven/archetype-metadata.xml | 38 +++++++++++++++
.../src/main/resources/archetype-resources/pom.xml | 27 ++++++++++
.../src/main/java/SomeClass.java | 23 +++++++++
.../resources/projects/it1}/archetype.properties | 18 +++----
.../src/test/resources/projects/it1/goal.txt | 0
.../test.properties} | 17 +++----
.../resources/projects/basic/archetype.properties | 2 +-
.../src/main/resources/test-basic.properties | 2 +-
.../resources/projects/basic/archetype.properties | 2 +-
.../src/main/resources/test-basic.properties | 2 +-
.../maven/archetype/mojos/IntegrationTestMojo.java | 13 ++++-
13 files changed, 175 insertions(+), 37 deletions(-)
diff --git a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/invoker.properties
similarity index 68%
copy from maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
copy to maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/invoker.properties
index 01013f2d..e71f103f 100644
--- a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
+++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/invoker.properties
@@ -15,13 +15,4 @@
# specific language governing permissions and limitations
# under the License.
-version=0.1-SNAPSHOT
-groupId=archetype.it
-artifactId=basic
-package=build.archetype
-
-requiredPropertyWithoutDefaultValue=a value defined in archetype.properties
-
-requiredPropertyWithDefaultValue=not the default value, but a value defined in archetype.properties
-
-nonRequiredProperty=a property that is not defined as requiredProperty in the archetype descriptor
\ No newline at end of file
+invoker.goals = clean verify
diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/pom.xml b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/pom.xml
new file mode 100644
index 00000000..a8b4d080
--- /dev/null
+++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/pom.xml
@@ -0,0 +1,57 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.example</groupId>
+ <artifactId>demo</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <!-- Packaging type + build extension -->
+ <packaging>maven-archetype</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <settingsFile>${basedir}/test-settings.xml</settingsFile>
+ <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+ <ignoreEOLStyle>true</ignoreEOLStyle>
+ <useDefaultExcludes>false</useDefaultExcludes>
+ <properties>
+ <maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
+ <maven.compiler.target>${maven.compiler.target}</maven.compiler.target>
+ </properties>
+ </configuration>
+ </plugin>
+ </plugins>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>@project.version@</version>
+ </extension>
+ </extensions>
+ </build>
+
+</project>
diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 00000000..1dbb6122
--- /dev/null
+++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,38 @@
+<?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 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="demo-archetype" partial="false">
+
+ <requiredProperties>
+ <requiredProperty key="example-prop">
+ <defaultValue>Hi</defaultValue>
+ </requiredProperty>
+ </requiredProperties>
+
+ <fileSets>
+ <fileSet encoding="UTF-8" filtered="true" packaged="true">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/archetype-resources/pom.xml b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 00000000..0d3672a2
--- /dev/null
+++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,27 @@
+<?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>${groupID}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}}</version>
+
+</project>
diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/archetype-resources/src/main/java/SomeClass.java b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/archetype-resources/src/main/java/SomeClass.java
new file mode 100644
index 00000000..89658aa0
--- /dev/null
+++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/main/resources/archetype-resources/src/main/java/SomeClass.java
@@ -0,0 +1,23 @@
+/*
+ * 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 ${groupId};
+
+public class SomeClass {
+ String name;
+}
diff --git a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/test/resources/projects/it1/archetype.properties
similarity index 68%
copy from maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
copy to maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/test/resources/projects/it1/archetype.properties
index 01013f2d..a4984635 100644
--- a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
+++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/test/resources/projects/it1/archetype.properties
@@ -5,9 +5,9 @@
# 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
@@ -15,13 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-version=0.1-SNAPSHOT
-groupId=archetype.it
-artifactId=basic
-package=build.archetype
-
-requiredPropertyWithoutDefaultValue=a value defined in archetype.properties
-
-requiredPropertyWithDefaultValue=not the default value, but a value defined in archetype.properties
-
-nonRequiredProperty=a property that is not defined as requiredProperty in the archetype descriptor
\ No newline at end of file
+artifactId=demo
+groupId=com.example
+version=1.0.0-SNAPSHOT
+package=com.example
diff --git a/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/test/resources/projects/it1/goal.txt b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/src/test/resources/projects/it1/goal.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/test.properties
similarity index 68%
copy from maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
copy to maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/test.properties
index 01013f2d..ec37f16b 100644
--- a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
+++ b/maven-archetype-plugin/src/it/projects/ARCHETYPE-574_default-value-should-be-used-in-integration-test/test.properties
@@ -15,13 +15,12 @@
# specific language governing permissions and limitations
# under the License.
-version=0.1-SNAPSHOT
-groupId=archetype.it
-artifactId=basic
-package=build.archetype
+archetypeGroupId=com.example
+archetypeArtifactId=demo
+archetypeVersion=1.0-SNAPSHOT
+archetypeCatalog=local
-requiredPropertyWithoutDefaultValue=a value defined in archetype.properties
-
-requiredPropertyWithDefaultValue=not the default value, but a value defined in archetype.properties
-
-nonRequiredProperty=a property that is not defined as requiredProperty in the archetype descriptor
\ No newline at end of file
+groupId=com.company
+artifactId=project
+version=1.0-SNAPSHOT
+package=com.company.project
diff --git a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties b/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
index 01013f2d..6e6ee8ad 100644
--- a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
+++ b/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/archetype.properties
@@ -24,4 +24,4 @@ requiredPropertyWithoutDefaultValue=a value defined in archetype.properties
requiredPropertyWithDefaultValue=not the default value, but a value defined in archetype.properties
-nonRequiredProperty=a property that is not defined as requiredProperty in the archetype descriptor
\ No newline at end of file
+nonRequiredProperty = this is a property that should not be replaced
diff --git a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties b/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties
index bc7e8cde..75669cf1 100644
--- a/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties
+++ b/maven-archetype-plugin/src/it/projects/build-archetype/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties
@@ -24,4 +24,4 @@ requiredPropertyWithoutDefaultValue = a value defined in archetype.properties
requiredPropertyWithDefaultValue = not the default value, but a value defined in archetype.properties
-nonRequiredProperty = a property that is not defined as requiredProperty in the archetype descriptor
+nonRequiredProperty = ${nonRequiredProperty}
diff --git a/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/archetype.properties b/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/archetype.properties
index 01013f2d..6e6ee8ad 100644
--- a/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/archetype.properties
+++ b/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/archetype.properties
@@ -24,4 +24,4 @@ requiredPropertyWithoutDefaultValue=a value defined in archetype.properties
requiredPropertyWithDefaultValue=not the default value, but a value defined in archetype.properties
-nonRequiredProperty=a property that is not defined as requiredProperty in the archetype descriptor
\ No newline at end of file
+nonRequiredProperty = this is a property that should not be replaced
diff --git a/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties b/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties
index bc7e8cde..75669cf1 100644
--- a/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties
+++ b/maven-archetype-plugin/src/it/projects/build-ignore-eol/src/test/resources/projects/basic/reference/src/main/resources/test-basic.properties
@@ -24,4 +24,4 @@ requiredPropertyWithoutDefaultValue = a value defined in archetype.properties
requiredPropertyWithDefaultValue = not the default value, but a value defined in archetype.properties
-nonRequiredProperty = a property that is not defined as requiredProperty in the archetype descriptor
+nonRequiredProperty = ${nonRequiredProperty}
diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
index e08d6a19..e96975c8 100644
--- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
+++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
@@ -46,6 +46,7 @@ import org.apache.maven.archetype.downloader.DownloadException;
import org.apache.maven.archetype.downloader.Downloader;
import org.apache.maven.archetype.exception.ArchetypeNotConfigured;
import org.apache.maven.archetype.generator.ArchetypeGenerator;
+import org.apache.maven.archetype.ui.generation.ArchetypeGenerationConfigurator;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -139,6 +140,9 @@ public class IntegrationTestMojo extends AbstractMojo {
@Component
private Invoker invoker;
+ @Component
+ private ArchetypeGenerationConfigurator archetypeGenerationConfigurator;
+
/**
* The archetype project to execute the integration tests on.
*/
@@ -477,7 +481,7 @@ public class IntegrationTestMojo extends AbstractMojo {
File archetypeFile,
Properties properties,
String basedir)
- throws IntegrationTestFailure {
+ throws IntegrationTestFailure, MojoExecutionException {
// @formatter:off
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest()
.setArchetypeGroupId(archetypeGroupId)
@@ -487,12 +491,17 @@ public class IntegrationTestMojo extends AbstractMojo {
.setArtifactId(properties.getProperty(Constants.ARTIFACT_ID))
.setVersion(properties.getProperty(Constants.VERSION))
.setPackage(properties.getProperty(Constants.PACKAGE))
+ .setRepositorySession(session.getRepositorySession())
.setOutputDirectory(basedir)
.setProperties(properties);
// @formatter:on
ArchetypeGenerationResult result = new ArchetypeGenerationResult();
-
+ try {
+ archetypeGenerationConfigurator.configureArchetype(request, false, properties);
+ } catch (Exception e) {
+ throw new MojoExecutionException("Cannot configure archetype", e);
+ }
archetypeGenerator.generateArchetype(request, archetypeFile, result);
if (result.getCause() != null) {