Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 9 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 101 additions and 7 deletions.
  1. +10 −1 changelog.html
  2. +91 −6 maven-plugin/src/main/java/hudson/maven/reporters/MavenFingerprinter.java
View
11 changelog.html
@@ -70,6 +70,9 @@
<li class=bug>
Dependency wasn't recalculated with CLI "update-job" command.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-11636">issue 11636</a>)
+ <li class=bug>
+ Copy artifacts fails on windows slaves due to failing to set a timestamp.
+ (<a href="https://issues.jenkins-ci.org/browse/JENKINS-11073">issue 11073</a>)
<li class=rfe>
Sortable table wasn't "stable" when there are same values in different rows
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-11551">issue 11551</a>)
@@ -78,7 +81,10 @@
(<a href="https://github.com/jenkinsci/jenkins/pull/289">pull #289</a>)
<li class=rfe>
Description field now has the preview button to test it inline.
- (<a href="https://github.com/jenkinsci/jenkins/pull/243">pull #243</a>)
+ (<a href="https://github.com/jenkinsci/jenkins/pull/243">pull #243</a>)
+ <li class=rfe>
+ Record fingerprints of parent POMs - only working with Maven 3.x.
+ (<a href="https://issues.jenkins-ci.org/browse/JENKINS-8383">issue 8383</a>)
<li class=rfe>
Maven mojo records can be now sorted
</ul>
@@ -289,6 +295,9 @@
<li class=rfe>
Introduce a fine-grained permission to control who is allowed to run the Groovy Console.
<li class=rfe>
+ Maven jobs should include fingerprints of their parent POMs
+ (<a href="https://issues.jenkins-ci.org/browse/JENKINS-8383">issue 8383</a>)
+ <li class=rfe>
Add support for maven-android-plugin integration test reports
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-10913">issue 10913</a>)
</ul>
View
97 maven-plugin/src/main/java/hudson/maven/reporters/MavenFingerprinter.java
@@ -38,15 +38,18 @@
import jenkins.model.Jenkins;
import hudson.tasks.Fingerprinter.FingerprintAction;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.project.MavenProject;
-
+import org.apache.maven.project.ProjectBuilderConfiguration;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.logging.Logger;
import java.util.Set;
import java.util.List;
@@ -81,10 +84,12 @@ public boolean preBuild(MavenBuildProxy build, MavenProject pom, BuildListener l
* Mojos perform different dependency resolution, so we need to check this for each mojo.
*/
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException {
- record(pom.getArtifacts(),used);
+ // TODO (kutzi, 2011/09/06): it should be perfectly save to move all these records to the
+ // postBuild method as artifacts should only be added by mojos, but never removed/modified.
+ record(pom.getArtifacts(),used);
record(pom.getArtifact(),produced);
record(pom.getAttachedArtifacts(),produced);
- record(pom.getGroupId(),pom.getFile(),produced);
+ record(pom.getGroupId() + ":" + pom.getArtifactId(),pom.getFile(),produced);
return true;
}
@@ -93,9 +98,12 @@ public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo moj
* Sends the collected fingerprints over to the master and record them.
*/
public boolean postBuild(MavenBuildProxy build, MavenProject pom, BuildListener listener) throws InterruptedException, IOException {
+
+ recordParents(build, pom);
+
build.executeAsync(new BuildCallable<Void,IOException>() {
private static final long serialVersionUID = -1360161848504044869L;
-
+
// record is transient, so needs to make a copy first
private final Map<String,String> u = used;
private final Map<String,String> p = produced;
@@ -121,6 +129,81 @@ public Void call(MavenBuild build) throws IOException, InterruptedException {
return true;
}
+ private void recordParents(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException {
+ MavenProject parent = pom.getParent();
+ while (parent != null) {
+ File parentFile = parent.getFile();
+
+ if (parentFile == null) {
+ String mavenVersion = build.getMavenBuildInformation().getMavenVersion();
+
+ // Parent artifact contains no actual file, so we resolve against
+ // the local repository
+ ArtifactRepository localRepository = getLocalRepository(mavenVersion, parent, pom);
+ if (localRepository != null) {
+ Artifact parentArtifact = getArtifact(parent);
+ // Don't use ArtifactRepository.find(), for compatibility with Maven 2.x
+ if (parentArtifact != null) {
+ parentFile = new File(localRepository.getBasedir(),
+ localRepository.pathOf(parentArtifact));
+ }
+ }
+ }
+
+ if (parentFile != null) {
+ // we need to include the artifact Id for poms as well, otherwise a
+ // project with the same groupId would override its parent's
+ // fingerprint
+ record(parent.getGroupId() + ":" + parent.getArtifactId(),
+ parentFile, used);
+ }
+ parent = parent.getParent();
+ }
+ }
+
+ private Artifact getArtifact(MavenProject parent) {
+ Artifact art = parent.getArtifact();
+ if (art == null) {
+ // happens for Maven 2.x
+ // TODO: this constructor didn't exist in Maven 2.x:
+ //art = new DefaultArtifact(parent.getGroupId(), parent.getGroupId(),
+ // parent.getVersion(), "compile", "pom", null, null);
+ }
+ return art;
+ }
+
+ private ArtifactRepository getLocalRepository(String mavenVersion, MavenProject parent, MavenProject pom) {
+ // Maven 2.0 has no corresponding mechanism
+ if (mavenVersion.startsWith("2.0")) {
+ return null;
+ } else if (mavenVersion.startsWith("2.1") || mavenVersion.startsWith("2.2")) {
+ //return getArtifactRepositoryMaven21(pom);
+ // still fails, because of missing artifact later
+ return null;
+ } else if (mavenVersion.startsWith("3.") || mavenVersion.startsWith("4.") /* who knows? ;) */) {
+ // Maven 3+
+ return parent.getProjectBuildingRequest()
+ .getLocalRepository();
+ } else {
+ LOGGER.warning("Unknown Maven version: "+mavenVersion);
+ return null;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private ArtifactRepository getArtifactRepositoryMaven21(MavenProject pom) {
+ // Maven 2.1,2.2 has a projectBuildConfiguration in the original project (not parent itself), but no direct accessor
+ try {
+ Field field = MavenProject.class.getDeclaredField("projectBuilderConfiguration");
+ field.setAccessible(true);
+ ProjectBuilderConfiguration projBuilderConfig = (ProjectBuilderConfiguration) field.get(pom);
+ return projBuilderConfig != null ? projBuilderConfig.getLocalRepository() : null;
+ } catch(Exception e) {
+ LOGGER.warning(e.toString());
+ return null;
+ }
+ }
+
private void record(Collection<Artifact> artifacts, Map<String,String> record) throws IOException, InterruptedException {
for (Artifact a : artifacts)
record(a,record);
@@ -141,14 +224,14 @@ private void record(Artifact a, Map<String,String> record) throws IOException, I
* This method contains the logic to avoid doubly recording the fingerprint
* of the same file.
*/
- private void record(String groupId, File f, Map<String, String> record) throws IOException, InterruptedException {
+ private void record(String fileNamePrefix, File f, Map<String, String> record) throws IOException, InterruptedException {
if(f==null || files.contains(f) || !f.isFile())
return;
// new file
files.add(f);
String digest = new FilePath(f).digest();
- record.put(groupId+':'+f.getName(),digest);
+ record.put(fileNamePrefix+':'+f.getName(),digest);
}
@Extension
@@ -184,4 +267,6 @@ public static void aggregate(MavenModuleSetBuild mmsb) throws IOException {
}
private static final long serialVersionUID = 1L;
+
+ private static final Logger LOGGER = Logger.getLogger(MavenFingerprinter.class.getName());
}

No commit comments for this range

Something went wrong with that request. Please try again.