提交 facfc178 编写于 作者: J Jesse Glick

Moving hudson.maven tests to maven-plugin.

上级 8deb42bf
......@@ -161,12 +161,6 @@ THE SOFTWARE.
<artifactId>geb-implicit-assertions</artifactId>
<version>0.7.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.test</groupId>
<artifactId>sample-plexus-component</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
package hudson.maven;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Result;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import java.io.IOException;
public class AbortedMavenBuildTest extends HudsonTestCase {
@Bug(8054)
public void testBuildWrapperSeesAbortedStatus() throws Exception {
configureDefaultMaven();
MavenModuleSet project = createMavenProject();
TestBuildWrapper wrapper = new TestBuildWrapper();
project.getBuildWrappersList().add(wrapper);
project.getReporters().add(new AbortingReporter());
project.setGoals("clean");
project.setScm(new ExtractResourceSCM(getClass().getResource("maven-empty-mod.zip")));
MavenModuleSetBuild build = project.scheduleBuild2(0).get();
assertEquals(Result.ABORTED, build.getResult());
assertEquals(Result.ABORTED, wrapper.buildResultInTearDown);
}
private static class AbortingReporter extends MavenReporter {
private static final long serialVersionUID = 1L;
@Override
public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
throw new InterruptedException();
}
}
}
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
* 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.
*/
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestResultProjectAction;
import org.apache.commons.io.FileUtils;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
/**
* @author Olivier Lamy
*/
public abstract class AbstractMaven3xBuildTest
extends HudsonTestCase {
public abstract MavenInstallation configureMaven3x() throws Exception;
public void testSimpleMaven3Build() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3x();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
m.setGoals( "clean install" );
MavenModuleSetBuild b = buildAndAssertSuccess(m);
assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
}
public void testSimpleMaven3BuildRedeployPublisher() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3x();
m.setMaven( mavenInstallation.getName() );
File repo = createTmpDir();
FileUtils.cleanDirectory( repo );
m.getReporters().add(new TestReporter());
m.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
m.setGoals( "clean install" );
MavenModuleSetBuild b = buildAndAssertSuccess(m);
assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
File artifactDir = new File(repo,"com/mycompany/app/my-app/1.7-SNAPSHOT/");
String[] files = artifactDir.list( new FilenameFilter()
{
public boolean accept( File dir, String name )
{
System.out.println("file name : " +name );
return name.endsWith( ".jar" );
}
});
assertTrue("SNAPSHOT exist",!files[0].contains( "SNAPSHOT" ));
assertTrue("file not ended with -1.jar", files[0].endsWith( "-1.jar" ));
}
public void testSiteBuildWithForkedMojo() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3x();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
m.setGoals( "clean site" );
MavenModuleSetBuild b = buildAndAssertSuccess(m);
assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
}
@Bug(value=8395)
public void testMaven3BuildWrongScope() throws Exception {
File pom = new File(this.getClass().getResource("test-pom-8395.xml").toURI());
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3x();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setRootPOM(pom.getAbsolutePath());
m.setGoals( "clean validate" );
MavenModuleSetBuild mmsb = m.scheduleBuild2( 0 ).get();
assertBuildStatus( Result.FAILURE, mmsb );
System.out.println("mmsb.getProject().getModules " + mmsb.getProject().getModules() );
assertTrue( mmsb.getProject().getModules().isEmpty());
}
@Bug(value=8390)
public void testMaven3BuildWrongInheritence() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3x();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("incorrect-inheritence-testcase.zip")));
m.setGoals( "clean validate" );
MavenModuleSetBuild mmsb = m.scheduleBuild2( 0 ).get();
assertBuildStatus( Result.FAILURE, mmsb );
System.out.println("mmsb.getProject().getModules " + mmsb.getProject().getModules() );
assertTrue( mmsb.getProject().getModules().isEmpty());
}
@Bug(value=8445)
public void testMavenSeveralModulesInDirectory() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3x();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("several-modules-in-directory.zip")));
m.setGoals( "clean validate" );
MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
assertFalse( mmsb.getProject().getModules().isEmpty());
}
@Email("https://groups.google.com/d/msg/hudson-users/Xhw00UopVN0/FA9YqDAIsSYJ")
public void testMavenWithDependencyVersionInEnvVar() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3x();
ParametersDefinitionProperty parametersDefinitionProperty =
new ParametersDefinitionProperty(new StringParameterDefinition( "JUNITVERSION", "3.8.2" ));
m.addProperty( parametersDefinitionProperty );
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("envars-maven-project.zip")));
m.setGoals( "clean test-compile" );
MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
assertFalse( mmsb.getProject().getModules().isEmpty());
}
@Bug(8484)
public void testMultiModMavenNonRecursive() throws Exception {
MavenInstallation mavenInstallation = configureMaven3x();
MavenModuleSet m = createMavenProject();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip")));
m.setGoals( "-N validate" );
assertTrue("MavenModuleSet.isNonRecursive() should be true", m.isNonRecursive());
buildAndAssertSuccess(m);
assertEquals("not only one module", 1, m.getModules().size());
}
@Bug(8573)
public void testBuildTimeStampProperty() throws Exception {
MavenInstallation mavenInstallation = configureMaven3x();
MavenModuleSet m = createMavenProject();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-8573.zip")));
m.setGoals( "process-resources" );
buildAndAssertSuccess(m);
String content = m.getLastBuild().getWorkspace().child( "target/classes/test.txt" ).readToString();
assertFalse( content.contains( "${maven.build.timestamp}") );
assertFalse( content.contains( "${maven.build.timestamp}") );
}
@Bug(1557)
public void testDuplicateTestResults() throws Exception {
MavenInstallation mavenInstallation = configureMaven3x();
MavenModuleSet m = createMavenProject();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-1557.zip")));
m.setGoals("verify");
buildAndAssertSuccess(m);
int totalCount = m.getModules().iterator().next()
.getAction(TestResultProjectAction.class).getLastTestResultAction().getTotalCount();
assertEquals(4, totalCount);
}
@Bug(9326)
public void testTychoTestResults() throws Exception {
MavenInstallation mavenInstallation = configureMaven3x();
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);
}
@Bug(9326)
public void testTychoEclipseTestResults() throws Exception {
MavenInstallation mavenInstallation = configureMaven3x();
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("foobar_eclipse_with_fix.zip"),"foobar_eclipse"));
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
public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
assertNotNull(build.getProject().getWorkspace());
assertNotNull(build.getWorkspace());
return true;
}
}
}
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
* 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.
*/
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.tasks.Maven;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestResultProjectAction;
import org.apache.commons.io.FileUtils;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
/**
* @author Olivier Lamy
*/
public class Maven30xBuildTest
extends AbstractMaven3xBuildTest {
@Override
public MavenInstallation configureMaven3x()
throws Exception
{
return configureMaven3();
}
}
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
* 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.
*/
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.tasks.Maven;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.TestResultProjectAction;
import org.apache.commons.io.FileUtils;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
/**
* @author Olivier Lamy
*/
public class Maven31xBuildTest
extends AbstractMaven3xBuildTest {
@Override
public MavenInstallation configureMaven3x()
throws Exception
{
return configureMaven31();
}
}
package hudson.maven;
/*
* The MIT License
*
* Copyright (c) 2011, Dominik Bartholdi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import hudson.tasks.Maven.MavenInstallation;
import hudson.util.ArgumentListBuilder;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import net.sf.json.JSONObject;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import org.kohsuke.stapler.StaplerRequest;
/**
* @author Dominik Bartholdi (imod)
*/
public class MavenArgumentInterceptorTest extends HudsonTestCase {
public void testSimpleMaven3BuildWithArgInterceptor_Goals() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3();
m.setMaven(mavenInstallation.getName());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
m.setGoals("dummygoal"); // build would fail with this goal
// add an action to build, redefining the goals and options to be
// executed
m.getBuildWrappersList().add(new TestMvnBuildWrapper("clean"));
MavenModuleSetBuild b = buildAndAssertSuccess(m);
assertTrue(MavenUtil.maven3orLater(b.getMavenVersionUsed()));
}
public void testSimpleMaven3BuildWithArgInterceptor_ArgBuilder() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureMaven3();
m.setMaven(mavenInstallation.getName());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
m.setGoals("clean install"); // build would fail because of failing unit
// tests
// add an action to build, adding argument to skip the test execution
m.getBuildWrappersList().add(new TestMvnBuildWrapper(Arrays.asList("-DskipTests")));
MavenModuleSetBuild b = buildAndAssertSuccess(m);
assertTrue(MavenUtil.maven3orLater(b.getMavenVersionUsed()));
}
private static class TestMvnArgInterceptor implements MavenArgumentInterceptorAction {
private String goalsAndOptions;
private List<String> args;
public TestMvnArgInterceptor(String goalsAndOptions) {
this.goalsAndOptions = goalsAndOptions;
}
public TestMvnArgInterceptor(List<String> args) {
this.args = args;
}
public String getIconFileName() {
return null;
}
public String getDisplayName() {
return null;
}
public String getUrlName() {
return null;
}
public String getGoalsAndOptions(MavenModuleSetBuild build) {
return goalsAndOptions;
}
public ArgumentListBuilder intercept(ArgumentListBuilder mavenargs, MavenModuleSetBuild build) {
if (args != null) {
for (String arg : this.args) {
mavenargs.add(arg);
}
}
return mavenargs;
}
}
public static class TestMvnBuildWrapper extends BuildWrapper {
public Result buildResultInTearDown;
private String goalsAndOptions;
private List<String> args;
public TestMvnBuildWrapper(String goalsAndOptions) {
this.goalsAndOptions = goalsAndOptions;
}
public TestMvnBuildWrapper(List<String> args) {
this.args = args;
}
@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
if (goalsAndOptions != null) {
build.addAction(new TestMvnArgInterceptor(goalsAndOptions));
} else if (args != null) {
build.addAction(new TestMvnArgInterceptor(args));
}
return new BuildWrapper.Environment() {
@Override
public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
buildResultInTearDown = build.getResult();
return true;
}
};
}
@Extension
public static class TestMvnBuildWrapperDescriptor extends BuildWrapperDescriptor {
@Override
public boolean isApplicable(AbstractProject<?, ?> project) {
return true;
}
@Override
public BuildWrapper newInstance(StaplerRequest req, JSONObject formData) {
throw new UnsupportedOperationException();
}
@Override
public String getDisplayName() {
return this.getClass().getName();
}
}
}
}
package hudson.maven;
import hudson.model.Result;
import hudson.tasks.Shell;
import java.util.concurrent.Callable;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.RunLoadCounter;
/**
* @author Olivier Lamy
*/
public class MavenBuildSurefireFailedTest extends HudsonTestCase {
@Bug(8415)
public void testMaven2Unstable() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}
@Bug(8415)
public void testMaven2Failed() throws Exception {
configureDefaultMaven();
final MavenModuleSet m = createMavenProject();
m.setGoals( "test -Dmaven.test.failure.ignore=false" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.FAILURE, m.scheduleBuild2(0).get());
// JENKINS-18895:
MavenModule failing = m.getModule("com.mycompany.app:my-app");
assertEquals(Result.FAILURE, failing.getLastBuild().getResult());
RunLoadCounter.prepare(failing);
assertEquals(Result.FAILURE, RunLoadCounter.assertMaxLoads(failing, 0, new Callable<Result>() {
@Override public Result call() throws Exception {
return m.getLastBuild().getResult();
}
}));
}
@Bug(8415)
public void testMaven3Unstable() throws Exception {
MavenModuleSet m = createMavenProject();
m.setMaven( configureMaven3().getName() );
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}
@Bug(8415)
public void testMaven3Failed() throws Exception {
MavenModuleSet m = createMavenProject();
m.setMaven( configureMaven3().getName() );
m.setGoals( "test -Dmaven.test.failure.ignore=false" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.FAILURE, m.scheduleBuild2(0).get());
}
@Bug(14102)
public void testMaven3SkipPostBuilder() throws Exception {
MavenModuleSet m = createMavenProject();
m.setMaven( configureMaven3().getName() );
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
// run dummy command only if build state is SUCCESS
m.setRunPostStepsIfResult(Result.SUCCESS);
m.addPostBuilder(new Shell("no-valid-command"));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}
@Bug(14102)
public void testMaven2SkipPostBuilder() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setGoals( "test" );
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimodule-unit-failure.zip")));
// run dummy command only if build state is SUCCESS
m.setRunPostStepsIfResult(Result.SUCCESS);
m.addPostBuilder(new Shell("no-valid-command"));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}
}
package hudson.maven;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.test.AbstractTestResultAction;
import hudson.tasks.test.AggregatedTestResultAction;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.SingleFileSCM;
/**
* @author Kohsuke Kawaguchi
*/
public class MavenBuildTest extends HudsonTestCase {
/**
* NPE in {@code build.getProject().getWorkspace()} for {@link MavenBuild}.
*/
@Bug(4192)
public void testMavenWorkspaceExists() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("HUDSON-4192.zip")));
buildAndAssertSuccess(m);
}
/**
* {@link Result} getting set to SUCCESS even if there's a test failure, when the test failure
* does not happen in the final task segment.
*/
@Bug(4177)
public void testTestFailureInEarlyTaskSegment() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setGoals("clean install findbugs:findbugs");
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-test-failure-findbugs.zip")));
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
}
/**
* Verify that a compilation error properly shows up as a failure.
*/
public void testCompilationFailure() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setGoals("clean install");
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-compilation-failure.zip")));
assertBuildStatus(Result.FAILURE, m.scheduleBuild2(0).get());
}
/**
* Workspace determination problem on non-aggregator style build.
*/
@Bug(4226)
public void testParallelModuleBuild() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("multimodule-maven.zip")));
buildAndAssertSuccess(m);
m.setAggregatorStyleBuild(false);
// run module builds
buildAndAssertSuccess(m.getModule("test$module1"));
buildAndAssertSuccess(m.getModule("test$module1"));
}
@Bug(value=8395)
public void testMaven2BuildWrongScope() throws Exception {
File pom = new File(this.getClass().getResource("test-pom-8395.xml").toURI());
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureDefaultMaven();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setRootPOM(pom.getAbsolutePath());
m.setGoals( "clean validate" );
MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
assertFalse( mmsb.getProject().getModules().isEmpty());
}
@Bug(value=8390)
public void testMaven2BuildWrongInheritence() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureDefaultMaven();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("incorrect-inheritence-testcase.zip")));
m.setGoals( "clean validate" );
MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
assertFalse( mmsb.getProject().getModules().isEmpty());
}
@Bug(value=8445)
public void testMaven2SeveralModulesInDirectory() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureDefaultMaven();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("several-modules-in-directory.zip")));
m.setGoals( "clean validate" );
MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
assertFalse( mmsb.getProject().getModules().isEmpty());
}
@Email("https://groups.google.com/d/msg/hudson-users/Xhw00UopVN0/FA9YqDAIsSYJ")
public void testMavenWithDependencyVersionInEnvVar() throws Exception {
MavenModuleSet m = createMavenProject();
MavenInstallation mavenInstallation = configureDefaultMaven();
ParametersDefinitionProperty parametersDefinitionProperty =
new ParametersDefinitionProperty(new StringParameterDefinition( "JUNITVERSION", "3.8.2" ));
m.addProperty( parametersDefinitionProperty );
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("envars-maven-project.zip")));
m.setGoals( "clean test-compile" );
MavenModuleSetBuild mmsb = buildAndAssertSuccess(m);
assertFalse( mmsb.getProject().getModules().isEmpty());
}
@Bug(8573)
public void testBuildTimeStampProperty() throws Exception {
MavenInstallation mavenInstallation = configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setMaven( mavenInstallation.getName() );
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-8573.zip")));
m.setGoals( "process-resources" );
buildAndAssertSuccess(m);
String content = m.getLastBuild().getWorkspace().child( "target/classes/test.txt" ).readToString();
assertFalse( content.contains( "${maven.build.timestamp}") );
assertFalse( content.contains( "${maven.build.timestamp}") );
System.out.println( "content " + content );
}
@Bug(value=15865)
public void testMavenFailsafePluginTestResultsAreRecorded() throws Exception {
// GIVEN: a Maven project with maven-failsafe-plugin and Maven 2.2.1
MavenModuleSet mavenProject = createMavenProject();
MavenInstallation mavenInstallation = configureDefaultMaven();
mavenProject.setMaven(mavenInstallation.getName());
mavenProject.getReporters().add(new TestReporter());
mavenProject.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-15865.zip")));
mavenProject.setGoals( "clean install" );
// WHEN project is build
MavenModuleSetBuild mmsb = buildAndAssertSuccess(mavenProject);
// THEN we have a testresult recorded
AggregatedTestResultAction aggregatedTestResultAction = mmsb.getAggregatedTestResultAction();
assertNotNull(aggregatedTestResultAction);
assertEquals(1, aggregatedTestResultAction.getTotalCount());
Map<MavenModule, MavenBuild> moduleBuilds = mmsb.getModuleLastBuilds();
assertEquals(1, moduleBuilds.size());
MavenBuild moduleBuild = moduleBuilds.values().iterator().next();
AbstractTestResultAction<?> testResultAction = moduleBuild.getTestResultAction();
assertNotNull(testResultAction);
assertEquals(1, testResultAction.getTotalCount());
}
@Bug(18178)
public void testExtensionsConflictingWithCore() throws Exception {
MavenModuleSet m = createMavenProject();
m.setMaven(configureDefaultMaven().getName());
m.setScm(new SingleFileSCM("pom.xml",
"<project><modelVersion>4.0.0</modelVersion>" +
"<groupId>g</groupId><artifactId>a</artifactId><version>0</version>" +
"<build><extensions>" +
"<extension><groupId>org.springframework.build.aws</groupId><artifactId>org.springframework.build.aws.maven</artifactId><version>3.0.0.RELEASE</version></extension>" +
"</extensions></build></project>"));
buildAndAssertSuccess(m);
}
private static class TestReporter extends MavenReporter {
private static final long serialVersionUID = 1L;
@Override
public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
assertNotNull(build.getWorkspace());
return true;
}
}
}
package hudson.maven;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import hudson.Launcher;
import hudson.model.BuildListener;
import java.io.IOException;
/**
* @author Andrew Bayer
*/
public class MavenEmptyModuleTest extends HudsonTestCase {
/**
* Verify that a build will work with a module <module></module> and a module <module> </module>
*/
@Bug(4442)
public void testEmptyModuleParsesAndBuilds() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-empty-mod.zip")));
buildAndAssertSuccess(m);
}
private static class TestReporter extends MavenReporter {
private static final long serialVersionUID = 1L;
@Override
public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
assertNotNull(build.getWorkspace());
return true;
}
}
}
\ No newline at end of file
package hudson.maven;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.EnvironmentContributingAction;
import hudson.model.InvisibleAction;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Cause;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import hudson.util.ArgumentListBuilder;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import net.sf.json.JSONObject;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.JenkinsRule;
import org.kohsuke.stapler.StaplerRequest;
/**
* This test case verifies that a maven build also takes EnvironmentContributingAction into account to resolve variables on the command line
*
* @see EnvironmentContributingAction
* @author Dominik Bartholdi (imod)
*/
public class MavenEnvironmentContributingActionTest {
@Rule
public JenkinsRule j = new JenkinsRule();
@Test
@Bug(17555)
public void envVariableFromEnvironmentContributingActionMustBeAvailableInMavenModuleSetBuild() throws Exception {
j.jenkins.getInjector().injectMembers(this);
final MavenModuleSet p = j.createMavenProject("mvn");
p.setMaven(j.configureMaven3().getName());
p.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip")));
p.setGoals("initialize -Dval=${KEY}");
p.getBuildWrappersList().add(new TestMvnBuildWrapper("-Dval=MY_VALUE"));
j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0, new Cause.UserIdCause()).get());
}
/**
* This action contributes env variables
*/
private static final class TestAction extends InvisibleAction implements EnvironmentContributingAction {
private final String key, value;
public TestAction(String key, String value) {
this.key = key;
this.value = value;
}
@Override
public void buildEnvVars(AbstractBuild<?, ?> arg0, EnvVars vars) {
vars.put(key, value);
}
}
/**
* This action verifies that the variable in the maven arguments got replaced
*/
private static class MvnCmdLineVerifier extends InvisibleAction implements MavenArgumentInterceptorAction {
private String containsString;
public MvnCmdLineVerifier(String containsString) {
this.containsString = containsString;
}
@Override
public ArgumentListBuilder intercept(ArgumentListBuilder cli, MavenModuleSetBuild arg1) {
String all = cli.toString();
Assert.assertTrue(containsString + " was not found in the goals arguments", all.contains(containsString));
return cli;
}
@Override
public String getGoalsAndOptions(MavenModuleSetBuild arg0) {
return null;
}
}
/**
* This wrapper adds a EnvironmentContributingAction to the build (see TestAction) and also adds the MvnCmdLineVerifier to the build to test whether the variable really got replaced
*/
public static class TestMvnBuildWrapper extends BuildWrapper {
private String containsString;
public TestMvnBuildWrapper(String expectedString) {
this.containsString = expectedString;
}
@Override
public Collection<? extends Action> getProjectActions(AbstractProject job) {
return Collections.singletonList(new TestAction("KEY", "MY_VALUE"));
}
@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
build.addAction(new MvnCmdLineVerifier(containsString));
return new BuildWrapper.Environment() {
};
}
@Extension
public static class TestMvnBuildWrapperDescriptor extends BuildWrapperDescriptor {
@Override
public boolean isApplicable(AbstractProject<?, ?> project) {
return true;
}
@Override
public BuildWrapper newInstance(StaplerRequest req, JSONObject formData) {
throw new UnsupportedOperationException();
}
@Override
public String getDisplayName() {
return this.getClass().getName();
}
}
}
}
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven;
import hudson.remoting.Which;
import junit.framework.Test;
import junit.framework.TestCase;
import org.jvnet.hudson.test.JellyTestSuiteBuilder;
/**
* Runs Jelly checks on maven-plugin.
*
* @author Andrew Bayer
*/
public class MavenJellyTest extends TestCase {
public static Test suite() throws Exception {
return JellyTestSuiteBuilder.build(Which.jarFile(MavenModuleSet.class),true);
}
}
package hudson.maven;
import hudson.maven.local_repo.PerJobLocalRepositoryLocator;
import hudson.model.Item;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* @author Kohsuke Kawaguchi
*/
public class MavenModuleSetTest extends HudsonTestCase {
public void testConfigRoundtripLocalRepository() throws Exception {
MavenModuleSet p = createMavenProject();
configRoundtrip((Item) p);
assertNull(p.getExplicitLocalRepository());
// make sure it roundtrips
PerJobLocalRepositoryLocator before = new PerJobLocalRepositoryLocator();
p.setLocalRepository(before);
configRoundtrip((Item)p);
assertEqualDataBoundBeans(p.getLocalRepository(),before);
assertTrue(before!=p.getLocalRepository());
}
@Bug(17402)
public void testGetItem() throws Exception {
assertNull(createMavenProject().getItem("invalid"));
}
}
/**
*
*/
package hudson.maven;
import hudson.FilePath;
import hudson.Launcher;
import hudson.maven.reporters.MavenFingerprinter;
import hudson.model.BuildListener;
import hudson.tasks.LogRotator;
import hudson.tasks.Maven.MavenInstallation;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceWithChangesSCM;
import org.jvnet.hudson.test.For;
import org.jvnet.hudson.test.JenkinsRule;
/**
*
* Test that looks in jobs archive with 2 builds. When LogRotator set as build
* discarder with settings to keep only 1 build with artifacts, test searches
* for jars in archive for build one and build two, expecting no jars in build 1
* and expecting jars in build 2.
*
*
*/
public class MavenMultiModuleLogRotatorCleanArtifactsTest {
@Rule
public JenkinsRule j = new JenkinsRule();
private MavenModuleSet m;
private FilePath jobs;
private static class TestReporter extends MavenReporter {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public boolean end(MavenBuild build, Launcher launcher,
BuildListener listener) throws InterruptedException,
IOException {
Assert.assertNotNull(build.getProject().getSomeWorkspace());
Assert.assertNotNull(build.getWorkspace());
return true;
}
}
@Before
public void setUp() throws Exception {
j.configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
m = j.createMavenProject();
m.setBuildDiscarder(new LogRotator("-1", "2", "-1", "1"));
m.getReporters().add(new TestReporter());
m.getReporters().add(new MavenFingerprinter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource(
"maven-multimod.zip"), getClass().getResource(
"maven-multimod-changes.zip")));
j.buildAndAssertSuccess(m);
// Now run a second build with the changes.
m.setIncrementalBuild(false);
j.buildAndAssertSuccess(m);
FilePath workspace = m.getSomeWorkspace();
FilePath parent = workspace.getParent().getParent();
jobs = new FilePath(parent, "jobs");
}
@Test
@Bug(17508)
@For({MavenModuleSetBuild.class, LogRotator.class})
@SuppressWarnings("unchecked")
public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun()
throws Exception {
File directory = new File(new FilePath(jobs, "test0/builds/1").getRemote());
Collection<File> files = FileUtils.listFiles(directory,
new String[] { "jar" }, true);
Assert.assertTrue(
"Found jars in previous build, that should not happen",
files.isEmpty());
Collection<File> files2 = FileUtils.listFiles(new File(new FilePath(
jobs, "test0/builds/2").getRemote()), new String[] { "jar" }, true);
Assert.assertFalse("No jars in last build ALERT!", files2.isEmpty());
}
/**
* Performs a third build and expecting build one to be deleted
* @throws Exception
*/
@For({MavenModuleSetBuild.class, LogRotator.class})
@Test
public void testArtifactsOldBuildsDeletedWhenBuildDiscarderRun()
throws Exception {
j.buildAndAssertSuccess(m);
File directory = new File(new FilePath(jobs, "test0/builds/1").getRemote());
Assert.assertFalse("oops the build should have been deleted", directory.exists());
}
}
package hudson.maven;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.tasks.Maven.MavenInstallation;
import java.io.IOException;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractChangeLogSet;
import org.jvnet.hudson.test.ExtractResourceWithChangesSCM;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* @author Andrew Bayer
*/
public class MavenMultiModuleTestIncremental extends HudsonTestCase {
@Bug(7684)
public void testRelRootPom() throws Exception {
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.setRootPOM("parent/pom.xml");
m.getReporters().add(new TestReporter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource("maven-multimod-rel-base.zip"),
getClass().getResource("maven-multimod-changes.zip")));
buildAndAssertSuccess(m);
// Now run a second build with the changes.
m.setIncrementalBuild(true);
buildAndAssertSuccess(m);
MavenModuleSetBuild pBuild = m.getLastBuild();
ExtractChangeLogSet changeSet = (ExtractChangeLogSet) pBuild.getChangeSet();
assertFalse("ExtractChangeLogSet should not be empty.", changeSet.isEmptySet());
for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) {
String parentModuleName = modBuild.getParent().getModuleName().toString();
if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleA")) {
assertEquals("moduleA should have Result.NOT_BUILT", Result.NOT_BUILT, modBuild.getResult());
}
else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleB")) {
assertEquals("moduleB should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult());
}
else if (parentModuleName.equals("org.jvnet.hudson.main.test.multimod:moduleC")) {
assertEquals("moduleC should have Result.SUCCESS", Result.SUCCESS, modBuild.getResult());
}
}
long summedModuleDuration = 0;
for (MavenBuild modBuild : pBuild.getModuleLastBuilds().values()) {
summedModuleDuration += modBuild.getDuration();
}
assertTrue("duration of moduleset build should be greater-equal than sum of the module builds",
pBuild.getDuration() >= summedModuleDuration);
}
private static class TestReporter extends MavenReporter {
private static final long serialVersionUID = 1L;
@Override
public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
assertNotNull(build.getWorkspace());
return true;
}
}
}
package hudson.maven;
import hudson.maven.MavenModuleSet.DescriptorImpl;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import hudson.EnvVars;
import hudson.model.Result;
import hudson.tasks.Maven.MavenInstallation;
/**
* @author Andrew Bayer
*/
public class MavenOptsTest extends HudsonTestCase {
DescriptorImpl d;
@Override
protected void setUp() throws Exception {
super.setUp();
d = jenkins.getDescriptorByType(DescriptorImpl.class);
}
@Override
protected void tearDown() throws Exception {
d.setGlobalMavenOpts(null);
super.tearDown();
}
public void testEnvMavenOptsNoneInProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.setAssignedLabel(createSlave(new EnvVars("MAVEN_OPTS", "-Dhudson.mavenOpt.test=foo")).getSelfLabel());
buildAndAssertSuccess(m);
assertLogContains("[hudson.mavenOpt.test=foo]", m.getLastBuild());
}
public void testEnvMavenOptsOverriddenByProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.setMavenOpts("-Dhudson.mavenOpt.test=bar");
m.setAssignedLabel(createSlave(new EnvVars("MAVEN_OPTS", "-Dhudson.mavenOpt.test=foo")).getSelfLabel());
buildAndAssertSuccess(m);
assertLogContains("[hudson.mavenOpt.test=bar]", m.getLastBuild());
}
public void testEnvAndGlobalMavenOptsOverriddenByProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
d.setGlobalMavenOpts("-Dhudson.mavenOpt.test=bar");
m.setAssignedLabel(createSlave(new EnvVars("MAVEN_OPTS", "-Dhudson.mavenOpt.test=foo")).getSelfLabel());
m.setMavenOpts("-Dhudson.mavenOpt.test=baz");
buildAndAssertSuccess(m);
assertLogContains("[hudson.mavenOpt.test=baz]", m.getLastBuild());
}
public void testGlobalMavenOpts() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
d.setGlobalMavenOpts("-Dhudson.mavenOpt.test=bar");
buildAndAssertSuccess(m);
assertLogContains("[hudson.mavenOpt.test=bar]", m.getLastBuild());
}
public void testGlobalMavenOptsOverridenByProject() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
d.setGlobalMavenOpts("-Dhudson.mavenOpt.test=bar");
m.setMavenOpts("-Dhudson.mavenOpt.test=foo");
buildAndAssertSuccess(m);
assertLogContains("[hudson.mavenOpt.test=foo]", m.getLastBuild());
}
@Bug(5651)
public void testNewlinesInOptsRemoved() throws Exception {
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-surefire-unstable.zip")));
m.setMavenOpts("-XX:MaxPermSize=512m\r\n-Xms128m\r\n-Xmx512m");
m.setGoals("install");
assertBuildStatus(Result.UNSTABLE, m.scheduleBuild2(0).get());
MavenModuleSetBuild pBuild = m.getLastBuild();
assertEquals("Parent build should have Result.UNSTABLE", Result.UNSTABLE, pBuild.getResult());
}
/**
* Makes sure that environment variables in MAVEN_OPTS are properly expanded.
*/
public void testEnvironmentVariableExpansion() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setMavenOpts("$FOO");
m.setScm(new ExtractResourceSCM(getClass().getResource("maven-opts-echo.zip")));
m.setGoals("validate");
m.setAssignedLabel(createSlave(new EnvVars("FOO", "-Dhudson.mavenOpt.test=foo -Dhudson.mavenOpt.test2=bar")).getSelfLabel());
buildAndAssertSuccess(m);
assertLogContains("[hudson.mavenOpt.test=foo]", m.getLastBuild());
}
}
/*
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven;
import hudson.maven.local_repo.DefaultLocalRepositoryLocator;
import hudson.maven.local_repo.PerJobLocalRepositoryLocator;
import hudson.model.AbstractProject;
import hudson.model.Item;
import hudson.model.Result;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.Shell;
import java.io.File;
import jenkins.model.Jenkins;
import jenkins.mvn.DefaultGlobalSettingsProvider;
import jenkins.mvn.DefaultSettingsProvider;
import jenkins.mvn.FilePathGlobalSettingsProvider;
import jenkins.mvn.FilePathSettingsProvider;
import jenkins.mvn.GlobalMavenConfig;
import org.junit.Assert;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import java.net.HttpURLConnection;
/**
* @author huybrechts
*/
public class MavenProjectTest extends HudsonTestCase {
public void testOnMaster() throws Exception {
MavenModuleSet project = createSimpleProject();
project.setGoals("validate");
buildAndAssertSuccess(project);
}
@Bug(16499)
public void testCopyFromExistingMavenProject() throws Exception {
MavenModuleSet project = createSimpleProject();
project.setGoals("abcdefg");
project.save();
MavenModuleSet copy = (MavenModuleSet) Jenkins.getInstance().copy((AbstractProject<?, ?>)project, "copy" + System.currentTimeMillis());
assertNotNull("Copied project must not be null", copy);
assertEquals(project.getGoals(), copy.getGoals());
}
private MavenModuleSet createSimpleProject() throws Exception {
return createProject("/simple-projects.zip");
}
private MavenModuleSet createProject(final String scmResource) throws Exception {
MavenModuleSet project = createMavenProject();
MavenInstallation mi = configureDefaultMaven();
project.setScm(new ExtractResourceSCM(getClass().getResource(
scmResource)));
project.setMaven(mi.getName());
project.setLocalRepository(new PerJobLocalRepositoryLocator());
return project;
}
public void testOnSlave() throws Exception {
MavenModuleSet project = createSimpleProject();
project.setGoals("validate");
project.setAssignedLabel(createSlave().getSelfLabel());
buildAndAssertSuccess(project);
}
/**
* Check if the generated site is linked correctly.
*/
@Bug(3497)
public void testSiteBuild() throws Exception {
MavenModuleSet project = createSimpleProject();
project.setGoals("site");
buildAndAssertSuccess(project);
// this should succeed
HudsonTestCase.WebClient wc = new WebClient();
wc.getPage(project,"site");
wc.assertFails(project.getUrl() + "site/no-such-file", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Check if the generated site is linked correctly for multi module projects.
*/
public void testMultiModuleSiteBuild() throws Exception {
MavenModuleSet project = createProject("maven-multimodule-site.zip");
project.setGoals("site");
buildAndAssertSuccess(project);
// this should succeed
HudsonTestCase.WebClient wc = new WebClient();
wc.getPage(project, "site");
wc.getPage(project, "site/core");
wc.getPage(project, "site/client");
//@Bug(7577): check that site generation succeeds also if only a single module is build
MavenModule coreModule = project.getModule("mmtest:core");
Assert.assertEquals("site", coreModule.getGoals());
buildAndAssertSuccess(coreModule);
wc.getPage(project, "site/core");
}
/**
* Check if the the site goal will work when run from a slave.
*/
@Bug(5943)
public void testMultiModuleSiteBuildOnSlave() throws Exception {
MavenModuleSet project = createProject("maven-multimodule-site.zip");
project.setGoals("site");
project.setAssignedLabel(createSlave().getSelfLabel());
buildAndAssertSuccess(project);
// this should succeed
HudsonTestCase.WebClient wc = new WebClient();
wc.getPage(project, "site");
wc.getPage(project, "site/core");
wc.getPage(project, "site/client");
}
@Bug(6779)
public void testDeleteSetBuildDeletesModuleBuilds() throws Exception {
MavenModuleSet project = createProject("maven-multimod.zip");
project.setLocalRepository(new DefaultLocalRepositoryLocator());
project.setGoals("install");
buildAndAssertSuccess(project);
buildAndAssertSuccess(project.getModule("org.jvnet.hudson.main.test.multimod:moduleB"));
buildAndAssertSuccess(project);
assertEquals(2, project.getBuilds().size()); // Module build does not add a ModuleSetBuild
project.getFirstBuild().delete();
// A#1, B#1 and B#2 should all be deleted too
assertEquals(1, project.getModule("org.jvnet.hudson.main.test.multimod:moduleA").getBuilds().size());
assertEquals(1, project.getModule("org.jvnet.hudson.main.test.multimod:moduleB").getBuilds().size());
}
@Bug(7261)
public void testAbsolutePathPom() throws Exception {
File pom = new File(this.getClass().getResource("test-pom-7162.xml").toURI());
MavenModuleSet project = createMavenProject();
MavenInstallation mi = configureDefaultMaven();
project.setMaven(mi.getName());
project.setRootPOM(pom.getAbsolutePath());
project.setGoals("install");
buildAndAssertSuccess(project);
}
@Bug(17177)
public void testCorrectResultInPostStepAfterFailedPreBuildStep() throws Exception {
MavenModuleSet p = createSimpleProject();
MavenInstallation mi = configureDefaultMaven();
p.setMaven(mi.getName());
p.setGoals("initialize");
Shell pre = new Shell("exit 1"); // must fail to simulate scenario!
p.getPrebuilders().add(pre);
ResultExposingBuilder resultExposer = new ResultExposingBuilder();
p.getPostbuilders().add(resultExposer);
assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
assertEquals("The result passed to the post build step was not the one from the pre build step", Result.FAILURE, resultExposer.getResult());
}
/**
* Config roundtrip test around pre/post build step
*/
public void testConfigRoundtrip() throws Exception {
MavenModuleSet m = createMavenProject();
Shell b1 = new Shell("1");
Shell b2 = new Shell("2");
m.getPrebuilders().add(b1);
m.getPostbuilders().add(b2);
configRoundtrip((Item)m);
assertEquals(1, m.getPrebuilders().size());
assertNotSame(b1,m.getPrebuilders().get(Shell.class));
assertEquals("1",m.getPrebuilders().get(Shell.class).getCommand());
assertEquals(1, m.getPostbuilders().size());
assertNotSame(b2,m.getPostbuilders().get(Shell.class));
assertEquals("2",m.getPostbuilders().get(Shell.class).getCommand());
for (Result r : new Result[]{Result.SUCCESS, Result.UNSTABLE, Result.FAILURE}) {
m.setRunPostStepsIfResult(r);
configRoundtrip((Item)m);
assertEquals(r,m.getRunPostStepsIfResult());
}
}
public void testDefaultSettingsProvider() throws Exception {
{
MavenModuleSet m = createMavenProject();
assertNotNull(m);
assertEquals(DefaultSettingsProvider.class, m.getSettings().getClass());
assertEquals(DefaultGlobalSettingsProvider.class, m.getGlobalSettings().getClass());
}
{
GlobalMavenConfig globalMavenConfig = GlobalMavenConfig.get();
assertNotNull("No global Maven Config available", globalMavenConfig);
globalMavenConfig.setSettingsProvider(new FilePathSettingsProvider("/tmp/settigns.xml"));
globalMavenConfig.setGlobalSettingsProvider(new FilePathGlobalSettingsProvider("/tmp/global-settigns.xml"));
MavenModuleSet m = createMavenProject();
assertEquals(FilePathSettingsProvider.class, m.getSettings().getClass());
assertEquals("/tmp/settigns.xml", ((FilePathSettingsProvider)m.getSettings()).getPath());
assertEquals("/tmp/global-settigns.xml", ((FilePathGlobalSettingsProvider)m.getGlobalSettings()).getPath());
}
}
}
package hudson.maven;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* Tests that Maven jobs are triggered, when snapshot dependencies of them were build.
*
* @author Andrew Bayer
*/
public class MavenSnapshotTriggerTest extends HudsonTestCase {
/**
* Verifies dependency build ordering of SNAPSHOT dependency.
* Note - has to build the projects once each first in order to get dependency info.
*/
public void testSnapshotDependencyBuildTrigger() throws Exception {
configureDefaultMaven();
MavenModuleSet projA = createMavenProject("snap-dep-test-up");
projA.setGoals("clean install");
projA.setScm(new ExtractResourceSCM(getClass().getResource("maven-dep-test-A.zip")));
MavenModuleSet projB = createMavenProject("snap-dep-test-down");
projB.setGoals("clean install");
projB.setIgnoreUpstremChanges(false);
projB.setQuietPeriod(0);
projB.setScm(new ExtractResourceSCM(getClass().getResource("maven-dep-test-B.zip")));
buildAndAssertSuccess(projA);
buildAndAssertSuccess(projB);
projA.setScm(new ExtractResourceSCM(getClass().getResource("maven-dep-test-A-changed.zip")));
buildAndAssertSuccess(projA);
// at this point runB2 should be in the queue, so wait until that completes.
waitUntilNoActivityUpTo(90*1000);
assertEquals("Expected most recent build of second project to be #2", 2, projB.getLastBuild().getNumber());
}
/**
* Verifies dependency build ordering of multiple SNAPSHOT dependencies.
* Note - has to build the projects once each first in order to get dependency info.
* B depends on A, C depends on A and B. Build order should be A->B->C.
*/
public void testMixedTransitiveSnapshotTrigger() throws Exception {
configureDefaultMaven();
MavenModuleSet projA = createMavenProject("snap-dep-test-up");
projA.setGoals("clean install");
projA.setScm(new ExtractResourceSCM(getClass().getResource("maven-dep-test-A.zip")));
MavenModuleSet projB = createMavenProject("snap-dep-test-mid");
projB.setGoals("clean install");
projB.setIgnoreUpstremChanges(false);
projB.setQuietPeriod(0);
projB.setScm(new ExtractResourceSCM(getClass().getResource("maven-dep-test-B.zip")));
MavenModuleSet projC = createMavenProject("snap-dep-test-down");
projC.setGoals("clean install");
projC.setIgnoreUpstremChanges(false);
projC.setQuietPeriod(0);
projC.setScm(new ExtractResourceSCM(getClass().getResource("maven-dep-test-C.zip")));
buildAndAssertSuccess(projA);
buildAndAssertSuccess(projB);
buildAndAssertSuccess(projC);
projA.setScm(new ExtractResourceSCM(getClass().getResource("maven-dep-test-A-changed.zip")));
buildAndAssertSuccess(projA);
waitUntilNoActivityUpTo(90*1000); // wait until dependency build trickles down
assertEquals("Expected most recent build of second project to be #2", 2, projB.getLastBuild().getNumber());
assertEquals("Expected most recent build of third project to be #2", 2, projC.getLastBuild().getNumber());
}
}
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven;
import hudson.ExtensionPoint;
import hudson.ExtensionList;
import hudson.Extension;
import jenkins.model.Jenkins;
import org.apache.maven.project.MavenProject;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* Extension point in Hudson to find additional dependencies from {@link MavenProject}.
*
* <p>
* Maven plugin configurations often have additional configuration entries to specify
* artifacts that a build depends on. Plugins can contribute an implementation of
* this interface to find such hidden dependencies.
*
* <p>
* To register implementations, put {@link Extension} on your subclass.
*
* @author Kohsuke Kawaguchi
* @since 1.264
* @see HUDSON-2685
*/
public abstract class ModuleDependencyLocator implements ExtensionPoint {
/**
* Discovers hidden dependencies.
*
* @param project
* In memory representation of Maven project, from which the hidden dependencies will be extracted.
* Never null.
* @param pomInfo
* Partially filled {@link PomInfo} object. Dependencies returned from this method will be
* added to this object by the caller.
*/
public abstract Collection<ModuleDependency> find(MavenProject project, PomInfo pomInfo);
/**
* Returns all the registered {@link ModuleDependencyLocator} descriptors.
*/
public static ExtensionList<ModuleDependencyLocator> all() {
return Jenkins.getInstance().getExtensionList(ModuleDependencyLocator.class);
}
/**
* Facade of {@link ModuleDependencyLocator}.
*/
/*package*/ static class ModuleDependencyLocatorFacade extends ModuleDependencyLocator {
@Override
public Collection<ModuleDependency> find(MavenProject project, PomInfo pomInfo) {
Set<ModuleDependency> r = new HashSet<ModuleDependency>();
for (ModuleDependencyLocator m : all())
r.addAll(m.find(project,pomInfo));
return r;
}
}
}
package hudson.maven;
import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.remoting.Which;
import hudson.slaves.DumbSlave;
import hudson.tasks.Maven.MavenInstallation;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.SingleFileSCM;
import org.jvnet.hudson.test.TestExtension;
import test.BogusPlexusComponent;
import java.io.File;
import java.io.IOException;
/**
* @author Kohsuke Kawaguchi
*/
public class PlexusModuleContributorTest {
@Rule
public JenkinsRule j = new JenkinsRule();
/**
* Tests the effect of PlexusModuleContributor by trying to parse a POM that uses a custom packaging
* that only exists inside our custom jar.
*/
@Test
public void testCustomPlexusComponent() throws Exception {
j.configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
MavenModuleSet p = j.createMavenProject();
p.setScm(new SingleFileSCM("pom.xml",getClass().getResource("custom-plexus-component.pom")));
p.setGoals("clean");
j.assertBuildStatusSuccess(p.scheduleBuild2(0));
}
@Test
public void testCustomPlexusComponent_Maven3() throws Exception {
j.configureDefaultMaven("apache-maven-3.0.1", MavenInstallation.MAVEN_30);
MavenModuleSet p = j.createMavenProject();
p.setScm(new SingleFileSCM("pom.xml",getClass().getResource("custom-plexus-component.pom")));
p.setGoals("clean");
j.assertBuildStatusSuccess(p.scheduleBuild2(0));
}
@Test
public void testCustomPlexusComponent_Maven3_slave() throws Exception {
j.configureDefaultMaven("apache-maven-3.0.1", MavenInstallation.MAVEN_30);
DumbSlave s = j.createSlave();
s.toComputer().connect(false).get();
MavenModuleSet p = j.createMavenProject();
p.setAssignedLabel(s.getSelfLabel());
p.setScm(new SingleFileSCM("pom.xml",getClass().getResource("custom-plexus-component.pom")));
p.setGoals("clean");
j.assertBuildStatusSuccess(p.scheduleBuild2(0));
}
@TestExtension
public static class PlexusLoader extends PlexusModuleContributorFactory {
@Override
public PlexusModuleContributor createFor(AbstractBuild<?, ?> context) throws IOException, InterruptedException {
File bogusPlexusJar = Which.jarFile(BogusPlexusComponent.class);
final FilePath localJar = context.getBuiltOn().getRootPath().child("cache/bogusPlexus.jar");
localJar.copyFrom(new FilePath(bogusPlexusJar));
return PlexusModuleContributor.of(localJar);
}
}
}
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven;
import hudson.model.Result;
import hudson.tasks.Maven.MavenInstallation;
import org.apache.commons.lang.StringUtils;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.SingleFileSCM;
import org.jvnet.hudson.test.Email;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import static org.junit.Assert.*;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.JenkinsRule;
/**
* @author Kohsuke Kawaguchi
*/
public class RedeployPublisherTest {
@Rule public JenkinsRule j = new JenkinsRule();
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Bug(2593)
@Test
public void testBug2593() throws Exception {
Assume.assumeFalse("Not a v4.0.0 POM. for project org.jvnet.maven-antrun-extended-plugin:maven-antrun-extended-plugin at /home/jenkins/.m2/repository/org/jvnet/maven-antrun-extended-plugin/maven-antrun-extended-plugin/1.39/maven-antrun-extended-plugin-1.39.pom", "https://jenkins.ci.cloudbees.com/job/core/job/jenkins_main_trunk/".equals(System.getenv("JOB_URL")));
j.configureDefaultMaven();
MavenModuleSet m2 = j.createMavenProject();
File repo = tmp.getRoot();
// a fake build
m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("big-artifact.pom")));
m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b);
// TODO: confirm that the artifacts use a consistent timestamp
// TODO: we need to somehow introduce a large delay between deploy since timestamp is only second precision
// TODO: or maybe we could use a btrace like capability to count the # of invocations?
System.out.println(repo);
}
@Test
public void testConfigRoundtrip() throws Exception {
MavenModuleSet p = j.createMavenProject();
RedeployPublisher rp = new RedeployPublisher("theId", "http://some.url/", true, true);
p.getPublishersList().add(rp);
j.submit(j.new WebClient().getPage(p,"configure").getFormByName("config"));
j.assertEqualBeans(rp,p.getPublishersList().get(RedeployPublisher.class),"id,url,uniqueVersion,evenIfUnstable");
}
// /**
// * Makes sure that the webdav wagon component we bundle is compatible.
// */
// public void testWebDavDeployment() throws Exception {
// configureDefaultMaven();
// MavenModuleSet m2 = createMavenProject();
//
// // a fake build
// m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("big-artifact.pom")));
// m2.getPublishersList().add(new RedeployPublisher("","dav:http://localhost/dav/",true));
//
// MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
// assertBuildStatus(Result.SUCCESS, b);
// }
/**
* Are we having a problem in handling file names with multiple extensions, like ".tar.gz"?
*/
@Email("http://www.nabble.com/tar.gz-becomes-.gz-after-Hudson-deployment-td25391364.html")
@Bug(3814)
@Test
public void testTarGz() throws Exception {
j.configureDefaultMaven();
MavenModuleSet m2 = j.createMavenProject();
File repo = tmp.getRoot();
// a fake build
m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),false, false));
MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b);
assertTrue("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
}
@Test
public void testTarGzUniqueVersionTrue() throws Exception {
j.configureDefaultMaven();
MavenModuleSet m2 = j.createMavenProject();
File repo = tmp.getRoot();
// a fake build
m2.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b);
File artifactDir = new File(repo,"test/test/0.1-SNAPSHOT/");
String[] files = artifactDir.list( new FilenameFilter()
{
public boolean accept( File dir, String name )
{
System.out.print( "deployed file " + name );
return name.contains( "-bin.tar.gz" ) || name.endsWith( ".jar" ) || name.endsWith( "-bin.zip" );
}
});
System.out.println("deployed files " + Arrays.asList( files ));
assertFalse("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
assertTrue("tar.gz doesn't exist",!files[0].contains( "SNAPSHOT" ));
for (String file : files) {
if (file.endsWith( "-bin.tar.gz" )) {
String ver = StringUtils.remove( file, "-bin.tar.gz" );
ver = ver.substring( ver.length() - 1, ver.length() );
assertEquals("-bin.tar.gz not ended with 1 , file " + file , "1", ver);
}
if (file.endsWith( ".jar" )) {
String ver = StringUtils.remove( file, ".jar" );
ver = ver.substring( ver.length() - 1, ver.length() );
assertEquals(".jar not ended with 1 , file " + file , "1", ver);
}
if (file.endsWith( "-bin.zip" )) {
String ver = StringUtils.remove( file, "-bin.zip" );
ver = ver.substring( ver.length() - 1, ver.length() );
assertEquals("-bin.zip not ended with 1 , file " + file , "1", ver);
}
}
}
@Test
public void testTarGzMaven3() throws Exception {
MavenModuleSet m3 = j.createMavenProject();
MavenInstallation mvn = j.configureMaven3();
m3.setMaven( mvn.getName() );
File repo = tmp.getRoot();
// a fake build
m3.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
m3.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),false, false));
MavenModuleSetBuild b = m3.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b);
assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
File artifactDir = new File(repo,"test/test/0.1-SNAPSHOT/");
String[] files = artifactDir.list( new FilenameFilter()
{
public boolean accept( File dir, String name )
{
return name.endsWith( "tar.gz" );
}
});
assertFalse("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
assertTrue("tar.gz doesn't exist",!files[0].contains( "SNAPSHOT" ));
}
@Test
public void testTarGzUniqueVersionTrueMaven3() throws Exception {
MavenModuleSet m3 = j.createMavenProject();
MavenInstallation mvn = j.configureMaven3();
m3.setMaven( mvn.getName() );
File repo = tmp.getRoot();
// a fake build
m3.setScm(new SingleFileSCM("pom.xml",getClass().getResource("targz-artifact.pom")));
m3.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false));
MavenModuleSetBuild b = m3.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b);
assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) );
File artifactDir = new File(repo,"test/test/0.1-SNAPSHOT/");
String[] files = artifactDir.list( new FilenameFilter()
{
public boolean accept( File dir, String name )
{
return name.contains( "-bin.tar.gz" ) || name.endsWith( ".jar" ) || name.endsWith( "-bin.zip" );
}
});
System.out.println("deployed files " + Arrays.asList( files ));
assertFalse("tar.gz doesn't exist",new File(repo,"test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists());
assertTrue("tar.gz doesn't exist",!files[0].contains( "SNAPSHOT" ));
for (String file : files) {
if (file.endsWith( "-bin.tar.gz" )) {
String ver = StringUtils.remove( file, "-bin.tar.gz" );
ver = ver.substring( ver.length() - 1, ver.length() );
assertEquals("-bin.tar.gz not ended with 1 , file " + file , "1", ver);
}
if (file.endsWith( ".jar" )) {
String ver = StringUtils.remove( file, ".jar" );
ver = ver.substring( ver.length() - 1, ver.length() );
assertEquals(".jar not ended with 1 , file " + file , "1", ver);
}
if (file.endsWith( "-bin.zip" )) {
String ver = StringUtils.remove( file, "-bin.zip" );
ver = ver.substring( ver.length() - 1, ver.length() );
assertEquals("-bin.zip not ended with 1 , file " + file , "1", ver);
}
}
}
@Bug(3773)
@Test
public void testDeployUnstable() throws Exception {
j.configureDefaultMaven();
MavenModuleSet m2 = j.createMavenProject();
File repo = tmp.getRoot();
// a build with a failing unit tests
m2.setScm(new ExtractResourceSCM(getClass().getResource("maven-test-failure-findbugs.zip")));
m2.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),false, true));
MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
j.assertBuildStatus(Result.UNSTABLE, b);
assertTrue("Artifact should have been published even when the build is unstable",
new File(repo,"test/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar").exists());
}
}
/*
* The MIT License
*
* Copyright (c) 2013, Dominik Bartholdi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.tasks.Builder;
import java.io.IOException;
/**
* @author Dominik Bartholdi (imod)
*/
public class ResultExposingBuilder extends Builder {
private Result result;
public ResultExposingBuilder() {
}
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
result = build.getResult();
return super.perform(build, launcher, listener);
}
public Result getResult() {
return result;
}
}
\ No newline at end of file
/*
* The MIT License
*
* Copyright (c) 2011, Dominik Bartholdi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven.reporters;
import hudson.maven.MavenModuleSet;
import hudson.model.Result;
import hudson.tasks.Mailer;
import hudson.tasks.Mailer.DescriptorImpl;
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.mock_javamail.Mailbox;
/**
*
* @author imod (Dominik Bartholdi)
*
*/
public class MavenMailerTest extends HudsonTestCase {
@Bug(5695)
public void testMulipleMails() throws Exception {
// there is one module failing in the build, therefore we expect one mail for the failed module and one for the over all build status
final Mailbox inbox = runMailTest(true);
assertEquals(2, inbox.size());
}
@Bug(5695)
public void testSingleMails() throws Exception {
final Mailbox inbox = runMailTest(false);
assertEquals(1, inbox.size());
}
public Mailbox runMailTest(boolean perModuleEamil) throws Exception {
final DescriptorImpl mailDesc = Jenkins.getInstance().getDescriptorByType(Mailer.DescriptorImpl.class);
// intentionally give the whole thin in a double quote
Mailer.descriptor().setAdminAddress("\"me <me@sun.com>\"");
String recipient = "you <you@sun.com>";
Mailbox yourInbox = Mailbox.get(new InternetAddress(recipient));
yourInbox.clear();
configureDefaultMaven();
MavenModuleSet mms = createMavenProject();
mms.setGoals("test");
mms.setScm(new ExtractResourceSCM(getClass().getResource("/hudson/maven/maven-multimodule-unit-failure.zip")));
assertBuildStatus(Result.UNSTABLE, mms.scheduleBuild2(0).get());
MavenMailer m = new MavenMailer();
m.recipients = recipient;
m.perModuleEmail = perModuleEamil;
mms.getReporters().add(m);
mms.scheduleBuild2(0).get();
Address[] senders = yourInbox.get(0).getFrom();
assertEquals(1, senders.length);
assertEquals("me <me@sun.com>", senders[0].toString());
return yourInbox;
}
}
package hudson.maven.reporters;
import org.jvnet.hudson.test.HudsonTestCase;
import hudson.maven.MavenProjectTest;
/**
* @author Kohsuke Kawaguchi
*/
public class MavenSiteArchiverTest extends HudsonTestCase {
/**
* Makes sure that the site archiving happens automatically.
* The actual test resides in {@link MavenProjectTest#testSiteBuild()}
*/
public void testSiteArchiving() throws Exception {
}
}
/*
* The MIT License
*
* Copyright (c) 2010, InfraDNA, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven.reporters;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.maven.MavenProjectActionBuilder;
import hudson.maven.reporters.SurefireArchiver.FactoryImpl;
import hudson.model.Result;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* @author Kohsuke Kawaguchi
*/
public class SurefireArchiverTest extends HudsonTestCase {
public void testSerialization() throws Exception {
configureDefaultMaven();
MavenModuleSet m = createMavenProject();
m.setScm(new ExtractResourceSCM(getClass().getResource("../maven-surefire-unstable.zip")));
m.setGoals("install");
MavenModuleSetBuild b = m.scheduleBuild2(0).get();
assertBuildStatus(Result.UNSTABLE, b);
MavenBuild mb = b.getModuleLastBuilds().values().iterator().next();
boolean foundFactory=false,foundSurefire=false;
for (MavenProjectActionBuilder x : mb.getProjectActionBuilders()) {
if (x instanceof FactoryImpl)
foundFactory = true;
if (x instanceof SurefireArchiver)
foundSurefire = true;
}
assertTrue(foundFactory);
assertFalse(foundSurefire);
}
}
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!--
POM that create several big artifacts, so that HUDSON-2539 can be tested
-->
<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>test</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<version>1.39</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<echo file="artifact1.txt">This is my artifact</echo>
<echo file="artifact2.txt">So is this</echo>
<attachArtifact file="artifact1.txt" />
<attachArtifact file="artifact2.txt" classifier="sources" type="txt"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>m.g.o-public</id>
<url>http://maven.glassfish.org/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2012- CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!--
POM that refers to a custom Plexus component
-->
<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>test</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>bogus</packaging>
</project>
\ No newline at end of file
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!--
POM that create several big artifacts, so that HUDSON-2539 can be tested
-->
<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>test</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>bin</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.infradna.support</groupId>
<artifactId>query</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>query</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<foo>bar</foo>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<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.hudson-ci.testcase</groupId>
<artifactId>testcase-wrong-plugin-dep-scope</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册