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

Split of test harness into separate artifact.

上级 f7172520
......@@ -50,6 +50,8 @@ THE SOFTWARE.
<modules>
<module>core</module>
<module>war</module>
<module>test-harness</module>
<module>test-harness-tools</module>
<module>test</module>
<module>cli</module>
<module>plugins</module>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>pom</artifactId>
<version>1.645-SNAPSHOT</version>
</parent>
<artifactId>jenkins-test-harness-tools</artifactId>
<name>Test harness tools</name>
<description>Tool installations that may be used by functional tests.</description>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ant</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
/*
* The MIT License
*
* Copyright 2016 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.
*/
package org.jvnet.hudson.test;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.tasks.Ant;
import hudson.tasks.Maven;
import hudson.util.StreamTaskListener;
import hudson.util.jna.GNUCLibrary;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.junit.rules.TemporaryFolder;
/**
* Utility to install standard tools in the Jenkins under test.
*/
public class ToolInstallations {
private static final Logger LOGGER = Logger.getLogger(ToolInstallations.class.getName());
/**
* Returns the older default Maven, while still allowing specification of
* other bundled Mavens.
*/
public static Maven.MavenInstallation configureDefaultMaven() throws Exception {
return configureDefaultMaven("apache-maven-2.2.1", Maven.MavenInstallation.MAVEN_20);
}
public static Maven.MavenInstallation configureMaven3() throws Exception {
Maven.MavenInstallation mvn = configureDefaultMaven("apache-maven-3.0.1", Maven.MavenInstallation.MAVEN_30);
Maven.MavenInstallation m3 = new Maven.MavenInstallation("apache-maven-3.0.1", mvn.getHome(), JenkinsRule.NO_PROPERTIES);
Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(m3);
return m3;
}
/**
* Locates Maven2 and configure that as the only Maven in the system.
*/
public static Maven.MavenInstallation configureDefaultMaven(String mavenVersion, int mavenReqVersion) throws Exception {
// first if we are running inside Maven, pick that Maven, if it meets the criteria we require..
File buildDirectory = new File(System.getProperty("buildDirectory", "target")); // TODO relative path
File mvnHome = new File(buildDirectory, mavenVersion);
if (mvnHome.exists()) {
Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default", mvnHome.getAbsolutePath(), JenkinsRule.NO_PROPERTIES);
Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
// Does maven.home point to a Maven installation which satisfies mavenReqVersion?
String home = System.getProperty("maven.home");
if (home != null) {
Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default", home, JenkinsRule.NO_PROPERTIES);
if (mavenInstallation.meetsMavenReqVersion(new Launcher.LocalLauncher(StreamTaskListener.fromStdout()), mavenReqVersion)) {
Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
}
// otherwise extract the copy we have.
// this happens when a test is invoked from an IDE, for example.
LOGGER.log(Level.WARNING,"Extracting a copy of Maven bundled in the test harness into {0}. "
+ "To avoid a performance hit, set the system property ''maven.home'' to point to a Maven2 installation.", mvnHome);
FilePath mvn = Jenkins.getInstance().getRootPath().createTempFile("maven", "zip");
mvn.copyFrom(JenkinsRule.class.getClassLoader().getResource(mavenVersion + "-bin.zip"));
mvn.unzip(new FilePath(buildDirectory));
// TODO: switch to tar that preserves file permissions more easily
try {
GNUCLibrary.LIBC.chmod(new File(mvnHome, "bin/mvn").getPath(), 0755);
} catch (LinkageError x) {
// skip; TODO 1.630+ can use Functions.isGlibcSupported
}
Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default",
mvnHome.getAbsolutePath(), JenkinsRule.NO_PROPERTIES);
Jenkins.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
/**
* Extracts Ant and configures it.
*/
public static Ant.AntInstallation configureDefaultAnt(TemporaryFolder tmp) throws Exception {
Ant.AntInstallation antInstallation;
if (System.getenv("ANT_HOME") != null) {
antInstallation = new Ant.AntInstallation("default", System.getenv("ANT_HOME"), JenkinsRule.NO_PROPERTIES);
} else {
LOGGER.warning("Extracting a copy of Ant bundled in the test harness. "
+ "To avoid a performance hit, set the environment variable ANT_HOME to point to an Ant installation.");
FilePath ant = Jenkins.getInstance().getRootPath().createTempFile("ant", "zip");
ant.copyFrom(JenkinsRule.class.getClassLoader().getResource("apache-ant-1.8.1-bin.zip"));
File antHome = tmp.newFolder("antHome");
ant.unzip(new FilePath(antHome));
// TODO: switch to tar that preserves file permissions more easily
try {
GNUCLibrary.LIBC.chmod(new File(antHome, "apache-ant-1.8.1/bin/ant").getPath(), 0755);
} catch (LinkageError x) {
// skip; TODO 1.630+ can use Functions.isGlibcSupported
}
antInstallation = new Ant.AntInstallation("default", new File(antHome, "apache-ant-1.8.1").getAbsolutePath(), JenkinsRule.NO_PROPERTIES);
}
Jenkins.getInstance().getDescriptorByType(Ant.DescriptorImpl.class).setInstallations(antInstallation);
return antInstallation;
}
private ToolInstallations() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>pom</artifactId>
<version>1.645-SNAPSHOT</version>
</parent>
<artifactId>jenkins-test-harness</artifactId>
<name>Test harness for Jenkins and plugins</name>
<description>Harness used to run functional tests of Jenkins core and plugins.</description>
<dependencies>
<dependency>
<!--
put hudson.war in the classpath. we can't pull in the war artifact directly
because Maven excludes all wars from classpath automatically. so we need a jar artifact.
-->
<groupId>${project.groupId}</groupId>
<artifactId>jenkins-war</artifactId>
<version>1.580.1</version>
<classifier>war-for-test</classifier>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>sshd</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.18</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>embedded-rhino-debugger</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>org.jvnet.hudson</groupId>
<artifactId>htmlunit-core-js</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.netbeans.modules</groupId>
<artifactId>org-netbeans-insane</artifactId>
<version>RELEASE72</version>
</dependency>
<dependency>
<groupId>com.github.stephenc.findbugs</groupId>
<artifactId>findbugs-annotations</artifactId>
<version>1.3.9-1</version>
</dependency>
<dependency> <!-- TODO can we switch this to use Aether directly? -->
<groupId>org.jenkins-ci.lib</groupId>
<artifactId>lib-jenkins-maven-embedder</artifactId>
<version>3.11</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>maven-stapler-plugin</artifactId>
<!-- version specified in grandparent pom -->
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- version specified in grandparent pom -->
<configuration>
<argLine>-Dfile.encoding=UTF-8 -Xmx256m -XX:MaxPermSize=128m</argLine>
<systemPropertyVariables>
<!-- use AntClassLoader that supports predictable file handle release -->
<hudson.ClassicPluginStrategy.useAntClassLoader>true</hudson.ClassicPluginStrategy.useAntClassLoader>
<hudson.maven.debug>${mavenDebug}</hudson.maven.debug>
<buildDirectory>${project.build.directory}</buildDirectory>
<ignore.random.failures>${ignore.random.failures}</ignore.random.failures>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<!-- version specified in grandparent pom -->
<executions>
<execution>
<id>preset-packager</id>
<phase>process-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${pom.basedir}/src/main/preset-data/package.groovy</source>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.0</version>
</dependency>
<!-- Usually a dependency of ant, but some people seem to have an incomplete ant POM. See JENKINS-11416 -->
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-launcher</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>1.5-jenkins-1</version>
</dependency>
</dependencies>
<configuration>
<providerSelection>2.0</providerSelection>
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -27,18 +27,22 @@ package hudson.cli;
import hudson.Extension;
import hudson.model.User;
import hudson.security.ACL;
import hudson.security.AuthorizationStrategy;
import hudson.security.Permission;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.security.SidACL;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import jenkins.model.Jenkins;
import org.acegisecurity.acls.sid.PrincipalSid;
import org.acegisecurity.acls.sid.Sid;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
......@@ -120,6 +124,37 @@ public class CLICommandInvoker {
return new Result(returnCode, out, err);
}
private static class GrantPermissions extends AuthorizationStrategy {
final String username;
final List<Permission> permissions;
GrantPermissions(String username, List<Permission> permissions) {
this.username = username;
this.permissions = permissions;
for (Permission p : permissions) {
p.setEnabled(true);
}
}
@Override
public ACL getRootACL() {
return new SidACL() {
@Override
protected Boolean hasPermission(Sid u, Permission permission) {
if (u instanceof PrincipalSid && ((PrincipalSid) u).getPrincipal().equals(username)) {
for (Permission p = permission; p != null; p = p.impliedBy) {
if (permissions.contains(p)) {
return true;
}
}
}
return false;
}
};
}
@Override
public Collection<String> getGroups() {
return Collections.emptySet();
}
}
private void setAuth() {
if (permissions.isEmpty()) return;
......@@ -128,12 +163,7 @@ public class CLICommandInvoker {
realm.addGroups(username, "group");
rule.jenkins.setSecurityRealm(realm);
GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
for(Permission p: permissions) {
p.setEnabled(true);
auth.add(p, username);
}
rule.jenkins.setAuthorizationStrategy(auth);
rule.jenkins.setAuthorizationStrategy(new GrantPermissions(username, permissions));
command.setTransportAuth(user().impersonate());
// Otherwise it is SYSTEM, which would be relevant for a command overriding main:
......
......@@ -57,5 +57,10 @@ public class ComputerConnectorTester extends AbstractDescribableImpl<ComputerCon
}
@Extension
public static class DescriptorImpl extends Descriptor<ComputerConnectorTester> {}
public static class DescriptorImpl extends Descriptor<ComputerConnectorTester> {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "ComputerConnectorTester";
}
}
}
......@@ -142,7 +142,12 @@ public class ExtractResourceWithChangesSCM extends NullSCM {
private Object writeReplace() { return new Object(); }
@Override public SCMDescriptor<?> getDescriptor() {
return new SCMDescriptor<ExtractResourceWithChangesSCM>(ExtractResourceWithChangesSCM.class, null) {};
return new SCMDescriptor<ExtractResourceWithChangesSCM>(ExtractResourceWithChangesSCM.class, null) {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "ExtractResourceWithChangesSCM";
}
};
}
}
......@@ -45,5 +45,10 @@ public class FailureBuilder extends MockBuilder {
public FailureBuilder newInstance(StaplerRequest req, JSONObject data) {
return new FailureBuilder();
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "FailureBuilder";
}
}
}
......@@ -77,7 +77,12 @@ public class FakeChangeLogSCM extends NullSCM {
}
@Override public SCMDescriptor<?> getDescriptor() {
return new SCMDescriptor<SCM>(null) {};
return new SCMDescriptor<SCM>(null) {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "FakeChangeLogSCM";
}
};
}
public static class ChangelogAction extends InvisibleAction {
......
......@@ -39,7 +39,6 @@ import hudson.DescriptorExtensionList;
import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.Functions;
import hudson.Functions.ThreadGroupMap;
import hudson.Launcher;
......@@ -48,16 +47,6 @@ import hudson.Main;
import hudson.PluginManager;
import hudson.Util;
import hudson.WebAppMain;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.matrix.MatrixRun;
import hudson.maven.MavenBuild;
import hudson.maven.MavenEmbedder;
import hudson.maven.MavenEmbedderException;
import hudson.maven.MavenModule;
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.maven.MavenUtil;
import hudson.model.*;
import hudson.model.Executor;
import hudson.model.Node.Mode;
......@@ -75,14 +64,9 @@ import hudson.slaves.ComputerListener;
import hudson.slaves.DumbSlave;
import hudson.slaves.NodeProperty;
import hudson.slaves.RetentionStrategy;
import hudson.tasks.Ant;
import hudson.tasks.Ant.AntInstallation;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import hudson.tasks.Builder;
import hudson.tasks.Mailer;
import hudson.tasks.Maven;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.Publisher;
import hudson.tools.ToolProperty;
import hudson.util.PersistedList;
......@@ -106,7 +90,6 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
......@@ -187,6 +170,10 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory;
import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest;
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import hudson.maven.MavenEmbedder;
import hudson.maven.MavenEmbedderException;
import hudson.maven.MavenRequest;
import java.net.HttpURLConnection;
import jenkins.model.JenkinsLocationConfiguration;
......@@ -343,8 +330,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
jenkins.servletContext.setAttribute("app", jenkins);
jenkins.servletContext.setAttribute("version","?");
WebAppMain.installExpressionFactory(new ServletContextEvent(jenkins.servletContext));
Mailer.descriptor().setHudsonUrl(getURL().toExternalForm()); // for compatibility only
JenkinsLocationConfiguration.get().setUrl(getURL().toString()); // in case we are using older mailer plugin
JenkinsLocationConfiguration.get().setUrl(getURL().toString());
// set a default JDK to be the one that the harness is using.
jenkins.getJDKs().add(new JDK("default",System.getProperty("java.home")));
......@@ -564,96 +550,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
return realm;
}
/**
* Returns the older default Maven, while still allowing specification of other bundled Mavens.
*/
protected MavenInstallation configureDefaultMaven() throws Exception {
return configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_20);
}
protected MavenInstallation configureMaven3() throws Exception {
MavenInstallation mvn = configureDefaultMaven("apache-maven-3.0.1", MavenInstallation.MAVEN_30);
MavenInstallation m3 = new MavenInstallation("apache-maven-3.0.1",mvn.getHome(), NO_PROPERTIES);
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(m3);
return m3;
}
protected MavenInstallation configureMaven31() throws Exception {
MavenInstallation mvn = configureDefaultMaven("apache-maven-3.1.0", MavenInstallation.MAVEN_30);
MavenInstallation m3 = new MavenInstallation("apache-maven-3.1.0",mvn.getHome(), NO_PROPERTIES);
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(m3);
return m3;
}
/**
* Locates Maven and configures that as the only Maven in the system.
*/
protected MavenInstallation configureDefaultMaven(String mavenVersion, int mavenReqVersion) throws Exception {
// Does it exists in the buildDirectory - i.e. already extracted from previous test?
// defined in jenkins-test-harness POM, but not plugins; TODO should not use relative paths as we do not know what CWD is
File buildDirectory = new File(System.getProperty("buildDirectory", "target"));
File mvnHome = new File(buildDirectory, mavenVersion);
if (mvnHome.exists()) {
MavenInstallation mavenInstallation = new MavenInstallation("default", mvnHome.getAbsolutePath(), NO_PROPERTIES);
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
// Does maven.home point to a Maven installation which satisfies mavenReqVersion?
String home = System.getProperty("maven.home");
if(home!=null) {
MavenInstallation mavenInstallation = new MavenInstallation("default",home, NO_PROPERTIES);
if (mavenInstallation.meetsMavenReqVersion(createLocalLauncher(), mavenReqVersion)) {
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
}
// otherwise extract the copy we have.
// this happens when a test is invoked from an IDE, for example.
LOGGER.warning("Extracting a copy of Maven bundled in the test harness into " + mvnHome + ". " +
"To avoid a performance hit, set the system property 'maven.home' to point to a Maven2 installation.");
FilePath mvn = jenkins.getRootPath().createTempFile("maven", "zip");
mvn.copyFrom(HudsonTestCase.class.getClassLoader().getResource(mavenVersion + "-bin.zip"));
mvn.unzip(new FilePath(buildDirectory));
// TODO: switch to tar that preserves file permissions more easily
if(!Functions.isWindows()) {
PosixAPI.jnr().chmod(new File(mvnHome, "bin/mvn").getPath(), 0755);
}
MavenInstallation mavenInstallation = new MavenInstallation("default",
mvnHome.getAbsolutePath(), NO_PROPERTIES);
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
/**
* Extracts Ant and configures it.
*/
protected Ant.AntInstallation configureDefaultAnt() throws Exception {
Ant.AntInstallation antInstallation;
if (System.getenv("ANT_HOME") != null) {
antInstallation = new AntInstallation("default", System.getenv("ANT_HOME"), NO_PROPERTIES);
} else {
LOGGER.warning("Extracting a copy of Ant bundled in the test harness. " +
"To avoid a performance hit, set the environment variable ANT_HOME to point to an Ant installation.");
FilePath ant = jenkins.getRootPath().createTempFile("ant", "zip");
ant.copyFrom(HudsonTestCase.class.getClassLoader().getResource("apache-ant-1.8.1-bin.zip"));
File antHome = createTmpDir();
ant.unzip(new FilePath(antHome));
// TODO: switch to tar that preserves file permissions more easily
if(!Functions.isWindows()) {
PosixAPI.jnr().chmod(new File(antHome,"apache-ant-1.8.1/bin/ant").getPath(),0755);
}
antInstallation = new AntInstallation("default", new File(antHome,"apache-ant-1.8.1").getAbsolutePath(),NO_PROPERTIES);
}
jenkins.getDescriptorByType(Ant.DescriptorImpl.class).setInstallations(antInstallation);
return antInstallation;
}
//
// Convenience methods
//
......@@ -666,34 +562,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
return jenkins.createProject(FreeStyleProject.class, name);
}
protected MatrixProject createMatrixProject() throws IOException {
return createMatrixProject(createUniqueProjectName());
}
protected MatrixProject createMatrixProject(String name) throws IOException {
return jenkins.createProject(MatrixProject.class, name);
}
/**
* Creates a empty Maven project with an unique name.
*
* @see #configureDefaultMaven()
*/
protected MavenModuleSet createMavenProject() throws IOException {
return createMavenProject(createUniqueProjectName());
}
/**
* Creates a empty Maven project with the given name.
*
* @see #configureDefaultMaven()
*/
protected MavenModuleSet createMavenProject(String name) throws IOException {
MavenModuleSet mavenModuleSet = jenkins.createProject(MavenModuleSet.class,name);
mavenModuleSet.setRunHeadless( true );
return mavenModuleSet;
}
protected String createUniqueProjectName() {
return "test"+ jenkins.getItems().size();
}
......@@ -957,12 +825,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
// dump the build output in failure message
String msg = "unexpected build status; build log was:\n------\n" + getLog(r) + "\n------\n";
if(r instanceof MatrixBuild) {
MatrixBuild mb = (MatrixBuild)r;
for (MatrixRun mr : mb.getRuns()) {
msg+="--- "+mr.getParent().getCombination()+" ---\n"+getLog(mr)+"\n------\n";
}
}
assertEquals(msg, status,r.getResult());
return r;
}
......@@ -1007,12 +869,6 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
public FreeStyleBuild buildAndAssertSuccess(FreeStyleProject job) throws Exception {
return assertBuildStatusSuccess(job.scheduleBuild2(0));
}
public MavenModuleSetBuild buildAndAssertSuccess(MavenModuleSet job) throws Exception {
return assertBuildStatusSuccess(job.scheduleBuild2(0));
}
public MavenBuild buildAndAssertSuccess(MavenModule job) throws Exception {
return assertBuildStatusSuccess(job.scheduleBuild2(0));
}
/**
* Asserts that the console output of the build contains the given substring.
......@@ -1466,7 +1322,8 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
String dependencies = m.getMainAttributes().getValue("Plugin-Dependencies");
if(dependencies!=null) {
MavenEmbedder embedder = MavenUtil.createEmbedder(new StreamTaskListener(System.out,Charset.defaultCharset()),(File)null,null);
// TODO can we switch this to use Aether directly?
MavenEmbedder embedder = new MavenEmbedder(MavenEmbedder.class.getClassLoader(), new MavenRequest());
for( String dep : dependencies.split(",")) {
String suffix = ";resolution:=optional";
boolean optional = dep.endsWith(suffix);
......@@ -1542,7 +1399,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
private File resolvePluginFile(MavenEmbedder embedder, String artifactId, String version, String groupId, String type)
throws MavenEmbedderException, ComponentLookupException, AbstractArtifactResolutionException {
final Artifact jpi = embedder.createArtifact(groupId, artifactId, version, "compile"/*doesn't matter*/, type);
embedder.resolve(jpi, Arrays.asList(embedder.createRepository("http://maven.glassfish.org/content/groups/public/","repo")),embedder.getLocalRepository());
embedder.resolve(jpi, Arrays.asList(embedder.createRepository("http://repo.jenkins-ci.org/public/", "repo.jenkins-ci.org")),embedder.getLocalRepository());
return jpi.getFile();
}
......@@ -2046,6 +1903,11 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
public BuildWrapper newInstance(StaplerRequest req, JSONObject formData) {
throw new UnsupportedOperationException();
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "TestBuildWrapper";
}
}
}
}
......@@ -58,5 +58,10 @@ public class JenkinsComputerConnectorTester extends AbstractDescribableImpl<Jenk
}
@Extension
public static class DescriptorImpl extends Descriptor<JenkinsComputerConnectorTester> {}
public static class DescriptorImpl extends Descriptor<JenkinsComputerConnectorTester> {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "JenkinsComputerConnectorTester";
}
}
}
......@@ -53,23 +53,14 @@ import hudson.DescriptorExtensionList;
import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.Main;
import hudson.PluginManager;
import hudson.Util;
import hudson.WebAppMain;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.matrix.MatrixRun;
import hudson.maven.MavenBuild;
import hudson.maven.MavenEmbedder;
import hudson.maven.MavenEmbedderException;
import hudson.maven.MavenModule;
import hudson.maven.MavenModuleSet;
import hudson.maven.MavenModuleSetBuild;
import hudson.maven.MavenUtil;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
......@@ -105,11 +96,9 @@ import hudson.slaves.ComputerListener;
import hudson.slaves.DumbSlave;
import hudson.slaves.OfflineCause;
import hudson.slaves.RetentionStrategy;
import hudson.tasks.Ant;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import hudson.tasks.Builder;
import hudson.tasks.Maven;
import hudson.tasks.Publisher;
import hudson.tools.ToolProperty;
import hudson.util.PersistedList;
......@@ -133,7 +122,6 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
......@@ -195,6 +183,8 @@ import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import com.gargoylesoftware.htmlunit.html.DomNodeUtil;
import com.gargoylesoftware.htmlunit.html.HtmlFormUtil;
import hudson.maven.MavenRequest;
import java.net.HttpURLConnection;
import java.nio.channels.ClosedByInterruptException;
import org.jvnet.hudson.test.recipes.Recipe;
import org.jvnet.hudson.test.rhino.JavaScriptDebugger;
......@@ -654,86 +644,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
return realm;
}
/**
* Returns the older default Maven, while still allowing specification of other bundled Mavens.
*/
public Maven.MavenInstallation configureDefaultMaven() throws Exception {
return configureDefaultMaven("apache-maven-2.2.1", Maven.MavenInstallation.MAVEN_20);
}
public Maven.MavenInstallation configureMaven3() throws Exception {
Maven.MavenInstallation mvn = configureDefaultMaven("apache-maven-3.0.1", Maven.MavenInstallation.MAVEN_30);
Maven.MavenInstallation m3 = new Maven.MavenInstallation("apache-maven-3.0.1",mvn.getHome(), NO_PROPERTIES);
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(m3);
return m3;
}
/**
* Locates Maven2 and configure that as the only Maven in the system.
*/
public Maven.MavenInstallation configureDefaultMaven(String mavenVersion, int mavenReqVersion) throws Exception {
// first if we are running inside Maven, pick that Maven, if it meets the criteria we require..
File buildDirectory = new File(System.getProperty("buildDirectory", "target")); // TODO relative path
File mvnHome = new File(buildDirectory, mavenVersion);
if (mvnHome.exists()) {
Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default", mvnHome.getAbsolutePath(), NO_PROPERTIES);
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
// Does maven.home point to a Maven installation which satisfies mavenReqVersion?
String home = System.getProperty("maven.home");
if(home!=null) {
Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default",home, NO_PROPERTIES);
if (mavenInstallation.meetsMavenReqVersion(createLocalLauncher(), mavenReqVersion)) {
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
}
// otherwise extract the copy we have.
// this happens when a test is invoked from an IDE, for example.
LOGGER.warning("Extracting a copy of Maven bundled in the test harness into " + mvnHome + ". " +
"To avoid a performance hit, set the system property 'maven.home' to point to a Maven2 installation.");
FilePath mvn = jenkins.getRootPath().createTempFile("maven", "zip");
mvn.copyFrom(JenkinsRule.class.getClassLoader().getResource(mavenVersion + "-bin.zip"));
mvn.unzip(new FilePath(buildDirectory));
// TODO: switch to tar that preserves file permissions more easily
if(Functions.isGlibcSupported())
GNUCLibrary.LIBC.chmod(new File(mvnHome, "bin/mvn").getPath(),0755);
Maven.MavenInstallation mavenInstallation = new Maven.MavenInstallation("default",
mvnHome.getAbsolutePath(), NO_PROPERTIES);
jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(mavenInstallation);
return mavenInstallation;
}
/**
* Extracts Ant and configures it.
*/
public Ant.AntInstallation configureDefaultAnt() throws Exception {
Ant.AntInstallation antInstallation;
if (System.getenv("ANT_HOME") != null) {
antInstallation = new Ant.AntInstallation("default", System.getenv("ANT_HOME"), NO_PROPERTIES);
} else {
LOGGER.warning("Extracting a copy of Ant bundled in the test harness. " +
"To avoid a performance hit, set the environment variable ANT_HOME to point to an Ant installation.");
FilePath ant = jenkins.getRootPath().createTempFile("ant", "zip");
ant.copyFrom(JenkinsRule.class.getClassLoader().getResource("apache-ant-1.8.1-bin.zip"));
File antHome = createTmpDir();
ant.unzip(new FilePath(antHome));
// TODO: switch to tar that preserves file permissions more easily
if(Functions.isGlibcSupported())
GNUCLibrary.LIBC.chmod(new File(antHome,"apache-ant-1.8.1/bin/ant").getPath(),0755);
antInstallation = new Ant.AntInstallation("default", new File(antHome,"apache-ant-1.8.1").getAbsolutePath(),NO_PROPERTIES);
}
jenkins.getDescriptorByType(Ant.DescriptorImpl.class).setInstallations(antInstallation);
return antInstallation;
}
//
// Convenience methods
//
......@@ -746,34 +656,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
return jenkins.createProject(FreeStyleProject.class, name);
}
public MatrixProject createMatrixProject() throws IOException {
return createMatrixProject(createUniqueProjectName());
}
public MatrixProject createMatrixProject(String name) throws IOException {
return jenkins.createProject(MatrixProject.class, name);
}
/**
* Creates a empty Maven project with an unique name.
*
* @see #configureDefaultMaven()
*/
public MavenModuleSet createMavenProject() throws IOException {
return createMavenProject(createUniqueProjectName());
}
/**
* Creates a empty Maven project with the given name.
*
* @see #configureDefaultMaven()
*/
public MavenModuleSet createMavenProject(String name) throws IOException {
MavenModuleSet mavenModuleSet = jenkins.createProject(MavenModuleSet.class,name);
mavenModuleSet.setRunHeadless( true );
return mavenModuleSet;
}
/**
* Creates a simple folder that other jobs can be placed in.
* @since 1.494
......@@ -1102,14 +984,8 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
if(status==r.getResult())
return r;
// dump the build output in failure message
// dump the build output in failure message (in case BuildWatcher is not being used)
String msg = "unexpected build status; build log was:\n------\n" + getLog(r) + "\n------\n";
if(r instanceof MatrixBuild) {
MatrixBuild mb = (MatrixBuild)r;
for (MatrixRun mr : mb.getRuns()) {
msg+="--- "+mr.getParent().getCombination()+" ---\n"+getLog(mr)+"\n------\n";
}
}
assertThat(msg, r.getResult(), is(status));
return r;
}
......@@ -1154,12 +1030,6 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
public FreeStyleBuild buildAndAssertSuccess(FreeStyleProject job) throws Exception {
return assertBuildStatusSuccess(job.scheduleBuild2(0));
}
public MavenModuleSetBuild buildAndAssertSuccess(MavenModuleSet job) throws Exception {
return assertBuildStatusSuccess(job.scheduleBuild2(0));
}
public MavenBuild buildAndAssertSuccess(MavenModule job) throws Exception {
return assertBuildStatusSuccess(job.scheduleBuild2(0));
}
/**
* Asserts that the console output of the build contains the given substring.
......@@ -1716,8 +1586,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
private MavenEmbedder getMavenEmbedder() throws MavenEmbedderException, IOException {
if (embedder==null)
embedder = MavenUtil.createEmbedder(new StreamTaskListener(System.out, Charset.defaultCharset()),
(File) null, null);
embedder = new MavenEmbedder(MavenEmbedder.class.getClassLoader(), new MavenRequest());
return embedder;
}
......@@ -1789,7 +1658,7 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
private @CheckForNull File resolvePluginFile(String artifactId, String version, String groupId, String type) throws Exception {
final Artifact jpi = getMavenEmbedder().createArtifact(groupId, artifactId, version, "compile"/*doesn't matter*/, type);
getMavenEmbedder().resolve(jpi,
Arrays.asList(getMavenEmbedder().createRepository("http://maven.glassfish.org/content/groups/public/", "repo")), embedder.getLocalRepository());
Arrays.asList(getMavenEmbedder().createRepository("http://repo.jenkins-ci.org/public/", "repo.jenkins-ci.org")), embedder.getLocalRepository());
return jpi.getFile();
}
......@@ -2330,13 +2199,13 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
// this also prevents tests from falsely advertising Hudson
DNSMultiCast.disabled = true;
if (Functions.isGlibcSupported()) {
try {
GNUCLibrary.LIBC.unsetenv("MAVEN_OPTS");
GNUCLibrary.LIBC.unsetenv("MAVEN_DEBUG_OPTS");
} catch (Exception e) {
LOGGER.log(Level.WARNING,"Failed to cancel out MAVEN_OPTS",e);
}
try {
GNUCLibrary.LIBC.unsetenv("MAVEN_OPTS");
GNUCLibrary.LIBC.unsetenv("MAVEN_DEBUG_OPTS");
} catch (LinkageError x) {
// skip; TODO 1.630+ can use Functions.isGlibcSupported
} catch (Exception e) {
LOGGER.log(Level.WARNING,"Failed to cancel out MAVEN_OPTS",e);
}
}
......@@ -2365,6 +2234,11 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
public BuildWrapper newInstance(StaplerRequest req, JSONObject formData) {
throw new UnsupportedOperationException();
}
@Override
public String getDisplayName() {
return "TestBuildWrapper";
}
}
}
......
......@@ -41,6 +41,11 @@ public class MockBuilder extends Builder {
public Builder newInstance(StaplerRequest req, JSONObject data) {
throw new UnsupportedOperationException();
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "MockBuilder";
}
}
}
......@@ -275,6 +275,11 @@ public class MockFolder extends AbstractItem implements DirectlyModifiableTopLev
return new MockFolder(parent, name);
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "MockFolder";
}
}
}
......@@ -59,6 +59,11 @@ public final class MockQueueItemAuthenticator extends QueueItemAuthenticator {
}
}
@Extension public static final class DescriptorImpl extends QueueItemAuthenticatorDescriptor {}
@Extension public static final class DescriptorImpl extends QueueItemAuthenticatorDescriptor {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "MockQueueItemAuthenticator";
}
}
}
......@@ -53,5 +53,10 @@ public class PretendSlave extends Slave {
}
@Extension
public static final class DescriptorImpl extends SlaveDescriptor {}
public static final class DescriptorImpl extends SlaveDescriptor {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "PretendSlave";
}
}
}
......@@ -53,5 +53,10 @@ public class SleepBuilder extends Builder {
}
@Extension
public static final class DescriptorImpl extends Descriptor<Builder> {}
public static final class DescriptorImpl extends Descriptor<Builder> {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "SleepBuilder";
}
}
}
......@@ -53,6 +53,11 @@ public abstract class TestBuilder extends Builder {
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "TestBuilder";
}
};
}
......
......@@ -45,6 +45,11 @@ public class TestCrumbIssuer extends CrumbIssuer
public TestCrumbIssuer newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new TestCrumbIssuer();
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "TestCrumbIssuer";
}
}
}
......@@ -41,6 +41,10 @@ public abstract class TestNotifier extends Notifier {
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "TestNotifier";
}
};
}
......
......@@ -45,5 +45,10 @@ public class UnstableBuilder extends MockBuilder {
public UnstableBuilder newInstance(StaplerRequest req, JSONObject data) {
return new UnstableBuilder();
}
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "UnstableBuilder";
}
}
}
......@@ -31,7 +31,6 @@ targetDir.mkdirs();
File dataSetRoot = new File(baseDir,"src/main/preset-data");
dataSetRoot.eachDir { d ->
if(d.name==".svn") return;
// if(!new File(d,"config.xml").exists()) return;
Zip zip = new Zip();
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册