Skip to content

Commit

Permalink
[ARCHETYPE-574] Use default values in integration tests goal (#232)
Browse files Browse the repository at this point in the history
Co-authored-by: Slawomir Jaranowski <s.jaranowski@gmail.com>
  • Loading branch information
Giovds and slawekjaranowski authored Oct 22, 2024
1 parent 24e70c4 commit 96374eb
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 6 deletions.
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.

invoker.goals = clean verify
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.

artifactId=demo
groupId=com.example
version=1.0.0-SNAPSHOT
package=com.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.

archetypeGroupId=com.example
archetypeArtifactId=demo
archetypeVersion=1.0-SNAPSHOT
archetypeCatalog=local

groupId=com.company
artifactId=project
version=1.0-SNAPSHOT
package=com.company.project
Original file line number Diff line number Diff line change
Expand Up @@ -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 = this is a property that should not be replaced
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = this is a property that should not be replaced
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -477,7 +481,7 @@ private ArchetypeGenerationRequest generate(
File archetypeFile,
Properties properties,
String basedir)
throws IntegrationTestFailure {
throws IntegrationTestFailure, MojoExecutionException {
// @formatter:off
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest()
.setArchetypeGroupId(archetypeGroupId)
Expand All @@ -487,12 +491,17 @@ private ArchetypeGenerationRequest generate(
.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) {
Expand Down

0 comments on commit 96374eb

Please sign in to comment.