Skip to content

Commit f63a987

Browse files
committed
[MARTIFACT-80] check ignore on .pom and main artifact
1 parent 465f93c commit f63a987

7 files changed

Lines changed: 165 additions & 23 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
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/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.apache.maven.plugins.it</groupId>
25+
<artifactId>multi</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>ignore-all</artifactId>
30+
<name>multi-module ignore all</name>
31+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
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/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.apache.maven.plugins.it</groupId>
25+
<artifactId>multi</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>ignore-jar</artifactId>
30+
<name>multi-module ignore jar (main artifact)</name>
31+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
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/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.apache.maven.plugins.it</groupId>
25+
<artifactId>multi</artifactId>
26+
<version>1.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>ignore-pom</artifactId>
30+
<name>multi-module ignore pom</name>
31+
</project>

src/it/buildinfo-multi/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<modules>
4141
<module>modB</module>
4242
<module>modA</module>
43+
<module>ignore-all</module>
44+
<module>ignore-pom</module>
45+
<module>ignore-jar</module>
4346
</modules>
4447

4548
<distributionManagement>
@@ -80,6 +83,9 @@
8083
<configuration>
8184
<ignore>
8285
<ignore>*/*.spdx.json</ignore>
86+
<ignore>*/ignore-all-*</ignore>
87+
<ignore>*/ignore-pom-*.pom</ignore>
88+
<ignore>*/ignore-jar-*.jar</ignore>
8389
</ignore>
8490
</configuration>
8591
</execution>

src/it/buildinfo-multi/verify.groovy

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,64 @@ assert buildinfoFile.isFile()
2424

2525
File modA = new File( basedir, "modA/target/multi-modA-1.0-SNAPSHOT.buildinfo")
2626
assert !modA.isFile()
27-
2827
File modB = new File( basedir, "modB/target/multi-modB-1.0-SNAPSHOT.buildinfo")
29-
assert modB.isFile()
28+
assert !modB.isFile()
29+
File ignoreAll = new File( basedir, "ignore-all/target/ignore-all-1.0-SNAPSHOT.buildinfo")
30+
assert !ignoreAll.isFile()
31+
File ignorePom = new File( basedir, "ignore-pom/target/ignore-pom-1.0-SNAPSHOT.buildinfo")
32+
assert !ignorePom.isFile()
33+
34+
File ignoreJar = new File( basedir, "ignore-jar/target/ignore-jar-1.0-SNAPSHOT.buildinfo")
35+
assert ignoreJar.isFile()
3036

3137
// check that copy content in root is the same
32-
assert buildinfoFile.text.equals( modB.text )
38+
assert buildinfoFile.text.equals( ignoreJar.text )
3339

3440
// check generated aggregate buildinfo content
35-
String buildinfo = modB.text
41+
String buildinfo = ignoreJar.text
3642
assert buildinfo.contains( "group-id=org.apache.maven.plugins.it" )
3743
assert buildinfo.contains( "artifact-id=multi" )
3844
assert buildinfo.contains( "version=1.0-SNAPSHOT" )
45+
3946
assert buildinfo.contains( "outputs.1.coordinates=org.apache.maven.plugins.it:multi-modA" )
4047
assert buildinfo.contains( "outputs.1.0.filename=multi-modA-1.0-SNAPSHOT.pom" )
4148
assert buildinfo.contains( "outputs.1.1.filename=multi-modA-1.0-SNAPSHOT.jar" )
4249
assert !buildinfo.contains( "outputs.1.2.filename=" )
4350
assert buildinfo.contains( "# ignored multi-modA-1.0-SNAPSHOT.spdx.json" )
51+
4452
assert buildinfo.contains( "outputs.2.coordinates=org.apache.maven.plugins.it:multi-modB" )
4553
assert buildinfo.contains( "outputs.2.0.filename=multi-modB-1.0-SNAPSHOT.pom" )
4654
assert buildinfo.contains( "outputs.2.1.filename=multi-modB-1.0-SNAPSHOT.jar" )
4755
assert !buildinfo.contains( "outputs.2.2.filename=" )
4856
assert buildinfo.contains( "# ignored multi-modB-1.0-SNAPSHOT.spdx.json" )
57+
58+
assert buildinfo.contains( "outputs.3.coordinates=org.apache.maven.plugins.it:ignore-all" )
59+
assert buildinfo.contains( "# ignored ignore-all-1.0-SNAPSHOT.pom" )
60+
assert buildinfo.contains( "# ignored ignore-all-1.0-SNAPSHOT.jar" )
61+
assert !buildinfo.contains( "outputs.3.0.filename=" )
62+
assert buildinfo.contains( "# ignored ignore-pom-1.0-SNAPSHOT.spdx.json" )
63+
64+
assert buildinfo.contains( "outputs.4.coordinates=org.apache.maven.plugins.it:ignore-pom" )
65+
assert buildinfo.contains( "# ignored ignore-pom-1.0-SNAPSHOT.pom" )
66+
assert buildinfo.contains( "outputs.4.0.filename=ignore-pom-1.0-SNAPSHOT.jar" )
67+
assert !buildinfo.contains( "outputs.4.1.filename=" )
68+
assert buildinfo.contains( "# ignored ignore-pom-1.0-SNAPSHOT.spdx.json" )
69+
70+
assert buildinfo.contains( "outputs.5.coordinates=org.apache.maven.plugins.it:ignore-jar" )
71+
assert buildinfo.contains( "outputs.5.0.filename=ignore-jar-1.0-SNAPSHOT.pom" )
72+
assert buildinfo.contains( "# ignored ignore-jar-1.0-SNAPSHOT.jar" )
73+
assert !buildinfo.contains( "outputs.5.1.filename=" )
74+
assert buildinfo.contains( "# ignored ignore-jar-1.0-SNAPSHOT.spdx.json" )
75+
4976
assert !buildinfo.contains( ".buildinfo" )
50-
assert buildinfo.contains( "mvn.aggregate.artifact-id=multi-modB" )
77+
assert buildinfo.contains( "mvn.aggregate.artifact-id=ignore-jar" )
5178

5279
// check existence of buildinfo in local repository
53-
File localModB = new File( basedir, "../../local-repo/org/apache/maven/plugins/it/multi-modB/1.0-SNAPSHOT/multi-modB-1.0-SNAPSHOT.buildinfo")
54-
assert localModB.isFile()
80+
File localIgnoreJar = new File( basedir, "../../local-repo/org/apache/maven/plugins/it/ignore-jar/1.0-SNAPSHOT/ignore-jar-1.0-SNAPSHOT.buildinfo")
81+
assert localIgnoreJar.isFile()
5582

5683
// check existence of buildinfo in remote repository
57-
File remoteDir = new File( basedir, "modB/target/remote-repo/org/apache/maven/plugins/it/multi-modB/1.0-SNAPSHOT" )
84+
File remoteDir = new File( basedir, "ignore-jar/target/remote-repo/org/apache/maven/plugins/it/ignore-jar/1.0-SNAPSHOT" )
5885
assert remoteDir.isDirectory()
5986
for ( File f : remoteDir.listFiles() )
6087
{

src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,22 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
7474

7575
/**
7676
* Artifacts to ignore, specified as a glob matching against <code>${groupId}/${filename}</code>, for example
77-
* <code>*</>/*.xml</code>.
77+
* <code>*</>/*.xml</code>. If all artifacts from a module are to be ignored, prefer {@code skipModules}.
7878
*/
7979
@Parameter(property = "buildinfo.ignore", defaultValue = "")
8080
private List<String> ignore;
8181

8282
/**
83-
* Detect projects/modules with install or deploy skipped: avoid taking fingerprints.
83+
* Auto-detect projects/modules with install or deploy skipped: avoid taking fingerprints.
84+
* If auto-detection gives unexpected results, prefer handwritten {@code skipModules}.
8485
*/
8586
@Parameter(property = "buildinfo.detect.skip", defaultValue = "true")
8687
private boolean detectSkip;
8788

8889
/**
89-
* Avoid taking fingerprints for modules specified as glob matching against <code>${groupId}/${artifactId}</code>.
90+
* Avoid taking fingerprints for full modules, specified as glob matching against
91+
* <code>${groupId}/${artifactId}</code>.
92+
* For ignoring only a few files instead of full modules, see {@code ignore}.
9093
* @since 3.5.0
9194
*/
9295
@Parameter(property = "buildinfo.skipModules")

src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,32 +185,45 @@ void printArtifacts(MavenProject project) throws MojoExecutionException {
185185
}
186186

187187
artifacts.put(pomArtifact, prefix + n);
188-
printFile(
189-
prefix + n++,
190-
pomArtifact.getGroupId(),
191-
pomArtifact.getFile(),
192-
project.getArtifactId() + '-' + project.getVersion() + ".pom");
188+
if (isIgnore(pomArtifact)) {
189+
p.println("# ignored " + getArtifactFilename(pomArtifact));
190+
} else {
191+
printFile(
192+
prefix + n++,
193+
pomArtifact.getGroupId(),
194+
pomArtifact.getFile(),
195+
project.getArtifactId() + '-' + project.getVersion() + ".pom");
196+
}
193197

194198
if (consumerPom != null) {
195199
// build pom
196200
Artifact buildPomArtifact = new DefaultArtifact(
197201
project.getGroupId(), project.getArtifactId(), "build", "pom", project.getVersion());
198202
buildPomArtifact = buildPomArtifact.setFile(project.getFile());
199203

200-
artifacts.put(buildPomArtifact, prefix + n);
201-
printFile(
202-
prefix + n++,
203-
buildPomArtifact.getGroupId(),
204-
buildPomArtifact.getFile(),
205-
project.getArtifactId() + '-' + project.getVersion() + "-build.pom");
204+
if (isIgnore(buildPomArtifact)) {
205+
p.println("# ignored " + getArtifactFilename(buildPomArtifact));
206+
} else {
207+
artifacts.put(buildPomArtifact, prefix + n);
208+
printFile(
209+
prefix + n++,
210+
buildPomArtifact.getGroupId(),
211+
buildPomArtifact.getFile(),
212+
project.getArtifactId() + '-' + project.getVersion() + "-build.pom");
213+
}
206214
}
207215

208216
if (project.getArtifact() == null) {
209217
return;
210218
}
211219

212220
if (project.getArtifact().getFile() != null) {
213-
printArtifact(prefix, n++, RepositoryUtils.toArtifact(project.getArtifact()));
221+
Artifact main = RepositoryUtils.toArtifact(project.getArtifact());
222+
if (isIgnore(main)) {
223+
p.println("# ignored " + getArtifactFilename(main));
224+
} else {
225+
printArtifact(prefix, n++, RepositoryUtils.toArtifact(project.getArtifact()));
226+
}
214227
}
215228

216229
for (Artifact attached : RepositoryUtils.toArtifacts(project.getAttachedArtifacts())) {

0 commit comments

Comments
 (0)