Skip to content

Commit

Permalink
Add warning in strange case
Browse files Browse the repository at this point in the history
The least we can do is compare two language: one of known 'pom'
type and other of project artifact: if both equal, and jar
plugin is "aware" it creates JAR that is "java" language,
emit a warning.
  • Loading branch information
cstamas committed Jun 4, 2024
1 parent 99584ce commit 2fb1877
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/it/MNG-8137/invoker.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.

invoker.goals = jar:jar
42 changes: 42 additions & 0 deletions src/it/MNG-8137/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
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>org.apache.maven.plugins.jar.it</groupId>
<artifactId>mng-8137</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>it-mng-8137</name>

<description>Project w/ pom packaging and jar:jar invoked</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
</build>

</project>
21 changes: 21 additions & 0 deletions src/it/MNG-8137/verify.groovy
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.
*/

String log = new File(basedir, 'build.log').text
assert log.contains('[WARNING] Language of project is \'none\', this is most probably not what you want')
11 changes: 11 additions & 0 deletions src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import java.nio.file.FileSystems;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -130,6 +132,9 @@ public abstract class AbstractJarMojo extends AbstractMojo {
@Component
private MavenProjectHelper projectHelper;

@Component(hint = "pom")
private ArtifactHandler pomArtifactHandler;

/**
* Require the jar plugin to build a new JAR even if none of the contents appear to have changed. By default, this
* plugin looks to see if the output jar exists and inputs have not changed. If these conditions are true, the
Expand Down Expand Up @@ -351,6 +356,12 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException("You have to use a classifier "
+ "to attach supplemental artifacts to the project instead of replacing them.");
}
if (Objects.equals(
pomArtifactHandler.getLanguage(),
getProject().getArtifact().getArtifactHandler().getLanguage())) {
getLog().warn("Language of project is '" + pomArtifactHandler.getLanguage()
+ "', this is most probably not what you want");
}
getProject().getArtifact().setFile(jarFile);
}
}
Expand Down

0 comments on commit 2fb1877

Please sign in to comment.