Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MARTIFACT-80] Use per-module ignore configuration when generating ag…
Browse files Browse the repository at this point in the history
…gregated buildinfo in `compare`

Use the per-module ignore configuration when generating buildinfo for comparison in the aggregator (usually the 'last' module). It's a bit of a bodge because it relies on the ignore config being stored when the `compare` goal runs in each module. If for some reason a module doesn't run the `compare` goal then it falls back to whatever config exists in the aggregator.

There's probably a much more complex solution that involves parsing the config out of the project model that would be more consistent.
facboy committed Nov 14, 2024
1 parent 7a82814 commit 2b71741
Showing 10 changed files with 347 additions and 29 deletions.
21 changes: 21 additions & 0 deletions src/it/compare-ignore/invoker.properties
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.

# initial reference build: install
invoker.goals.1=clean install
# second build: verify (could be package, but not install to avoid overriding reference)
invoker.goals.2=clean verify artifact:compare
61 changes: 61 additions & 0 deletions src/it/compare-ignore/modA/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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.apache.maven.plugins.it</groupId>
<artifactId>ignore</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ignore-modA</artifactId>
<packaging>jar</packaging>
<name>ignore module A</name>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<configuration>
<ignore>*/ignore-modA-*.jar</ignore>
</configuration>
<executions>
<execution>
<goals>
<goal>compare</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
18 changes: 18 additions & 0 deletions src/it/compare-ignore/modA/src/main/resources/filtered.properties
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.

project.build.outputTimestamp=${project.build.outputTimestamp}
42 changes: 42 additions & 0 deletions src/it/compare-ignore/modB/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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.apache.maven.plugins.it</groupId>
<artifactId>ignore</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>ignore-modB</artifactId>
<packaging>pom</packaging>
<name>ignore module B</name>

<dependencies>
<dependency>
<groupId>org.apache.maven.plugins.it</groupId>
<artifactId>ignore-modA</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
70 changes: 70 additions & 0 deletions src/it/compare-ignore/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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>org.apache.maven.plugins.it</groupId>
<artifactId>ignore</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<description>An IT verifying compare works when resuming a multi-module build.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<prerequisites>
<maven>3.0.5</maven>
</prerequisites>

<distributionManagement>
<snapshotRepository>
<id>local-snapshots</id>
<url>file://${basedir}/target/remote-repo</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>

<modules>
<module>modB</module>
<module>modA</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>compare</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3 changes: 3 additions & 0 deletions src/it/settings.xml
Original file line number Diff line number Diff line change
@@ -26,6 +26,9 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<reference.repo>nexus</reference.repo>
</properties>
<repositories>
<repository>
<id>local.central</id>
Original file line number Diff line number Diff line change
@@ -76,14 +76,14 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
* Ignore javadoc attached artifacts from buildinfo generation.
*/
@Parameter(property = "buildinfo.ignoreJavadoc", defaultValue = "true")
private boolean ignoreJavadoc;
boolean ignoreJavadoc;

/**
* Artifacts to ignore, specified as a glob matching against <code>${groupId}/${filename}</code>, for example
* <code>*</>/*.xml</code>.
*/
@Parameter(property = "buildinfo.ignore", defaultValue = "")
private List<String> ignore;
List<String> ignore;

/**
* Detect projects/modules with install or deploy skipped: avoid taking fingerprints.
@@ -148,6 +148,8 @@ public void execute() throws MojoExecutionException {

hasBadOutputTimestamp(outputTimestamp, getLog(), project, session.getProjects(), diagnose);

initModuleBuildInfo();

if (!mono) {
// if module skips install and/or deploy
if (isSkip(project)) {
@@ -171,6 +173,10 @@ public void execute() throws MojoExecutionException {
execute(artifacts);
}

protected void initModuleBuildInfo() {
BuildInfoWriter.addModuleBuildInfo(getPluginContext(), ignore, ignoreJavadoc);
}

static boolean hasBadOutputTimestamp(
String outputTimestamp,
Log log,
@@ -303,9 +309,9 @@ protected void copyAggregateToRoot(File aggregate) throws MojoExecutionException

protected BuildInfoWriter newBuildInfoWriter(PrintWriter p, boolean mono) {
BuildInfoWriter bi = new BuildInfoWriter(getLog(), p, mono, rtInformation);
bi.setIgnoreJavadoc(ignoreJavadoc);
bi.setIgnore(ignore);
bi.setToolchain(getToolchain());
bi.setSession(session);
bi.setPluginContext(getPluginContext());

return bi;
}
@@ -329,11 +335,11 @@ protected Map<Artifact, String> generateBuildinfo(boolean mono) throws MojoExecu

// artifact(s) fingerprints
if (mono) {
bi.printArtifacts(project);
bi.printArtifacts(project, project);
} else {
for (MavenProject project : session.getProjects()) {
if (!isSkip(project)) {
bi.printArtifacts(project);
for (MavenProject moduleProject : session.getProjects()) {
if (!isSkip(moduleProject)) {
bi.printArtifacts(moduleProject, project);
}
}
}
Loading

0 comments on commit 2b71741

Please sign in to comment.