Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mvn compile in multimodule projects #235

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/it/compile-multimodule-it/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# 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=-Dstyle.color=always -ntp clean compile
14 changes: 14 additions & 0 deletions src/it/compile-multimodule-it/plugin1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<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>

<parent>
<groupId>org.jenkins-ci.tools.hpi.its</groupId>
<artifactId>compile-multimodule-it-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>compile-multimodule-it-plugin1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>hpi</packaging>
</project>
21 changes: 21 additions & 0 deletions src/it/compile-multimodule-it/plugin2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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>

<parent>
<groupId>org.jenkins-ci.tools.hpi.its</groupId>
<artifactId>compile-multimodule-it-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>compile-multimodule-it-plugin2</artifactId>
<packaging>hpi</packaging>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>compile-multimodule-it-plugin1</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
44 changes: 44 additions & 0 deletions src/it/compile-multimodule-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<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>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.25</version>
</parent>

<groupId>org.jenkins-ci.tools.hpi.its</groupId>
<artifactId>compile-multimodule-it-parent</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>pom</packaging>
<properties>
<java.level>8</java.level>
</properties>

<modules>
<module>plugin1</module>
<module>plugin2</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
Vlatombe marked this conversation as resolved.
Show resolved Hide resolved
</build>

</project>
26 changes: 17 additions & 9 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/ValidateHpiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Sets;
import hudson.util.VersionNumber;
import java.io.File;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand Down Expand Up @@ -41,17 +42,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

private VersionNumber getDependencyCoreVersion(MavenArtifact artifact) throws IOException, MojoExecutionException {
Attributes mainAttributes = new JarFile(artifact.getFile()).getManifest().getMainAttributes();
Attributes.Name jName = new Attributes.Name("Jenkins-Version");
if (mainAttributes.containsKey(jName)) {
return new VersionNumber(mainAttributes.getValue(jName));
} else {
Attributes.Name hName = new Attributes.Name("Hudson-Version");
if (mainAttributes.containsKey(hName)) {
return new VersionNumber(mainAttributes.getValue(hName));
File file = artifact.getFile();
if (file.isFile()) {
Attributes mainAttributes = new JarFile(file).getManifest().getMainAttributes();
Attributes.Name jName = new Attributes.Name("Jenkins-Version");
if (mainAttributes.containsKey(jName)) {
return new VersionNumber(mainAttributes.getValue(jName));
} else {
throw new MojoExecutionException("Could not find Jenkins Version in manifest for " + artifact);
Attributes.Name hName = new Attributes.Name("Hudson-Version");
if (mainAttributes.containsKey(hName)) {
return new VersionNumber(mainAttributes.getValue(hName));
} else {
throw new MojoExecutionException("Could not find Jenkins Version in manifest for " + artifact);
}
}
} else {
getLog().warn("Skipping jenkins-core validation for " + artifact + " since we rely on sources and don't have a manifest. Use 'package' goal to get validation");
// Assume the version is the same
return new VersionNumber(findJenkinsVersion());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this could be missing the core version check, as it is not really returning the dependency version but the current project core version. IMO, this should throw an exception pointing the user to run mvn package instead of mvn compile (or any goal before package in the maven lifecycle).

Proper validation runs on mvn deploy so releases are safe, but still... getting mvn test to not catch a Jenkins core version mismatch does not sound good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mvn test checks it through InjectedTest, see #191

}
}
}