From e4914db591cde0b8619726f1b92dc488ef8bec1d Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 18 Apr 2011 21:43:50 +0200 Subject: [PATCH] [FIXED JENKINS-9326] Jenkins Maven build does not recognize Tycho surfire reports --- .../maven/reporters/SurefireArchiver.java | 10 +++++-- .../jvnet/hudson/test/ExtractResourceSCM.java | 17 +++++++++++ .../java/hudson/maven/Maven3BuildTest.java | 28 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/maven-plugin/src/main/java/hudson/maven/reporters/SurefireArchiver.java b/maven-plugin/src/main/java/hudson/maven/reporters/SurefireArchiver.java index 6b68971c8f..78fdd14337 100644 --- a/maven-plugin/src/main/java/hudson/maven/reporters/SurefireArchiver.java +++ b/maven-plugin/src/main/java/hudson/maven/reporters/SurefireArchiver.java @@ -88,7 +88,7 @@ public class SurefireArchiver extends MavenReporter { // so that we can record this as yellow. // note that because of the way Maven works, just updating system property at this point is too late XmlPlexusConfiguration c = (XmlPlexusConfiguration) mojo.configuration.getChild("testFailureIgnore"); - if(c!=null && c.getValue().equals("${maven.test.failure.ignore}") && System.getProperty("maven.test.failure.ignore")==null) { + if(c!=null && c.getValue() != null && c.getValue().equals("${maven.test.failure.ignore}") && System.getProperty("maven.test.failure.ignore")==null) { if (maven3orLater( build.getMavenBuildInformation().getMavenVersion() )) { String fieldName = "testFailureIgnore"; if (mojo.mojoExecution.getConfiguration().getChild( fieldName ) != null) { @@ -245,6 +245,7 @@ public class SurefireArchiver extends MavenReporter { private boolean isSurefireTest(MojoInfo mojo) { if ((!mojo.is("com.sun.maven", "maven-junit-plugin", "test")) && (!mojo.is("org.sonatype.flexmojos", "flexmojos-maven-plugin", "test-run")) + && (!mojo.is("org.sonatype.tycho", "maven-osgi-test-plugin", "test")) && (!mojo.is("org.apache.maven.plugins", "maven-surefire-plugin", "test")) && (!mojo.is("org.apache.maven.plugins", "maven-failsafe-plugin", "integration-test"))) return false; @@ -284,7 +285,12 @@ public class SurefireArchiver extends MavenReporter { if (((skipTests != null) && (skipTests))) { return false; } - } + } else if (mojo.is("org.sonatype.tycho", "maven-osgi-test-plugin", "test")) { + Boolean skipTests = mojo.getConfigurationValue("skipTest", Boolean.class); + if (((skipTests != null) && (skipTests))) { + return false; + } + } } catch (ComponentConfigurationException e) { return false; diff --git a/test/src/main/java/org/jvnet/hudson/test/ExtractResourceSCM.java b/test/src/main/java/org/jvnet/hudson/test/ExtractResourceSCM.java index 9c09743864..59e37b2c67 100644 --- a/test/src/main/java/org/jvnet/hudson/test/ExtractResourceSCM.java +++ b/test/src/main/java/org/jvnet/hudson/test/ExtractResourceSCM.java @@ -29,6 +29,8 @@ import hudson.model.AbstractBuild; import hudson.model.BuildListener; import hudson.scm.NullSCM; import hudson.scm.SCM; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import java.io.File; import java.io.IOException; @@ -42,12 +44,21 @@ import java.net.URL; public class ExtractResourceSCM extends NullSCM { private final URL zip; + private String parentFolder; + public ExtractResourceSCM(URL zip) { if(zip==null) throw new IllegalArgumentException(); this.zip = zip; } + public ExtractResourceSCM(URL zip, String parentFolder) { + if(zip==null) + throw new IllegalArgumentException(); + this.zip = zip; + this.parentFolder = parentFolder; + } + @Override public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { if (workspace.exists()) { @@ -56,6 +67,12 @@ public class ExtractResourceSCM extends NullSCM { } listener.getLogger().println("Staging "+zip); workspace.unzipFrom(zip.openStream()); + if (parentFolder != null) { + System.out.println("workspace " + workspace.getRemote()); + //Thread.sleep( 100000 ); + FileUtils.copyDirectory( new File(workspace.getRemote() + "/" + parentFolder), new File( workspace.getRemote())); + //FileUtils.moveDirectory( new File(workspace.getRemote() + "/" + parentFolder), new File( workspace.getRemote())); + } return true; } } diff --git a/test/src/test/java/hudson/maven/Maven3BuildTest.java b/test/src/test/java/hudson/maven/Maven3BuildTest.java index 94f92235d6..7a31e5232c 100755 --- a/test/src/test/java/hudson/maven/Maven3BuildTest.java +++ b/test/src/test/java/hudson/maven/Maven3BuildTest.java @@ -1,6 +1,7 @@ package hudson.maven; /* + * Olivier Lamy * 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 @@ -28,6 +29,7 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; +import hudson.tasks.test.AbstractTestResultAction; import hudson.tasks.test.TestResult; import hudson.tasks.test.TestResultProjectAction; import org.apache.commons.io.FileUtils; @@ -193,6 +195,32 @@ public class Maven3BuildTest extends HudsonTestCase { .getAction(TestResultProjectAction.class).getLastTestResultAction().getTotalCount(); assertEquals(4, totalCount); } + + @Bug(9326) + public void testTychoTestResults() throws Exception { + MavenInstallation mavenInstallation = configureMaven3(); + MavenModuleSet m = createMavenProject(); + m.setRootPOM( "org.foobar.build/pom.xml" ); + m.setMaven( mavenInstallation.getName() ); + m.getReporters().add(new TestReporter()); + m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-9326.zip"),"foobar")); + m.setGoals("verify"); + buildAndAssertSuccess(m); + + System.out.println("modules size " + m.getModules()); + + + MavenModule testModule = null; + for (MavenModule mavenModule : m.getModules()) { + System.out.println("module " + mavenModule.getName() + "/" + mavenModule.getDisplayName()); + if ("org.foobar:org.foobar.test".equals( mavenModule.getName() )) testModule = mavenModule; + } + + AbstractTestResultAction trpa = testModule.getLastBuild().getTestResultAction(); + + int totalCount = trpa.getTotalCount(); + assertEquals(1, totalCount); + } private static class TestReporter extends MavenReporter { @Override