提交 0993b709 编写于 作者: J Jesse Glick 提交者: Oleg Nenashev

Do not load detached plugins during tests (#2829)

* Do not load detached plugins during tests.
Also warn about plugins which force us to create classes.jar.

* Porting POM fix from #2795: we must allow snapshots from repo.jenkins-ci.org so as to be able to test upstream component PRs.

* Fixed failures in tests which assumed detached plugins were being loaded.

* jenkins-test-harness 2.20

* Unreproducible test failure on CI, probably due to timing.
上级 c33e7dc4
......@@ -194,8 +194,10 @@ public class ClassicPluginStrategy implements PluginStrategy {
baseResourceURL = resolve(archive,atts.getValue("Resource-Path")).toURI().toURL();
} else {
File classes = new File(expandDir, "WEB-INF/classes");
if (classes.exists())
if (classes.exists()) { // should not normally happen, due to createClassJarFromWebInfClasses
LOGGER.log(Level.WARNING, "Deprecated unpacked classes directory found in {0}", classes);
paths.add(classes);
}
File lib = new File(expandDir, "WEB-INF/lib");
File[] libs = lib.listFiles(JAR_FILTER);
if (libs != null)
......@@ -669,6 +671,9 @@ public class ClassicPluginStrategy implements PluginStrategy {
z.add(mapper);
z.execute();
}
if (classesJar.isFile()) {
LOGGER.log(Level.WARNING, "Created {0}; update plugin to a version created with a newer harness", classesJar);
}
}
private static void unzipExceptClasses(File archive, File destDir, Project prj) {
......
......@@ -952,6 +952,7 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
* with a reasonable up-to-date check. A convenience method to be used by the {@link #loadBundledPlugins()}.
*/
protected void copyBundledPlugin(URL src, String fileName) throws IOException {
LOGGER.log(FINE, "Copying {0}", src);
fileName = fileName.replace(".hpi",".jpi"); // normalize fileNames to have the correct suffix
String legacyName = fileName.replace(".jpi",".hpi");
long lastModified = getModificationDate(src);
......
......@@ -56,7 +56,7 @@ THE SOFTWARE.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>2.13</version>
<version>2.20</version>
<scope>test</scope>
<exclusions>
<exclusion>
......@@ -98,12 +98,6 @@ THE SOFTWARE.
</exclusion>
</exclusions>
</dependency>
<dependency> <!-- TODO seems to be used only by PluginManagerTest -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>subversion</artifactId>
<version>1.45</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
......
......@@ -553,6 +553,11 @@ public class AbstractProjectTest {
*/
@Test
public void testConfigDotXmlSubmissionToDifferentType() {
j.jenkins.pluginManager.installDetachedPlugin("javadoc")
j.jenkins.pluginManager.installDetachedPlugin("junit")
j.jenkins.pluginManager.installDetachedPlugin("mailer")
j.jenkins.pluginManager.installDetachedPlugin("maven-plugin")
j.jenkins.crumbIssuer = null
def p = j.createFreeStyleProject()
......
......@@ -60,7 +60,8 @@ public class PluginManagerInstalledGUITest {
try {
return super.loadBundledPlugins();
} finally {
installResourcePlugin("tasks.jpi");
copyBundledPlugin(PluginManagerInstalledGUITest.class.getResource("/WEB-INF/detached-plugins/cvs.hpi"), "cvs.jpi"); // cannot use installDetachedPlugin at this point
copyBundledPlugin(PluginManagerInstalledGUITest.class.getResource("/plugins/tasks.jpi"), "tasks.jpi");
}
}
};
......
......@@ -31,7 +31,6 @@ import hudson.model.UpdateCenter;
import hudson.model.UpdateCenter.UpdateCenterJob;
import hudson.model.UpdateSite;
import hudson.model.User;
import hudson.scm.SubversionSCM;
import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.util.FormValidation;
......@@ -167,7 +166,6 @@ public class PluginManagerTest {
// plugins should be already visible in the UberClassLoader
assertTrue(!activePlugins.isEmpty());
uberClassLoader.loadClass(SubversionSCM.class.getName());
uberClassLoader.loadClass("hudson.plugins.tasks.Messages");
super.startPlugin(plugin);
......
......@@ -29,6 +29,7 @@ import org.junit.Test;
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestPluginManager;
public class PluginTest {
......@@ -36,6 +37,7 @@ public class PluginTest {
@Issue({"SECURITY-131", "SECURITY-155"})
@Test public void doDynamic() throws Exception {
((TestPluginManager) r.jenkins.pluginManager).installDetachedPlugin("credentials");
r.createWebClient().goTo("plugin/credentials/images/24x24/credentials.png", "image/png");
/* Collapsed somewhere before it winds up in restOfPath:
r.createWebClient().assertFails("plugin/credentials/images/../images/24x24/credentials.png", HttpServletResponse.SC_BAD_REQUEST);
......
......@@ -25,13 +25,12 @@ package hudson.model;
import com.google.common.io.Resources;
import com.trilead.ssh2.crypto.Base64;
import hudson.ClassicPluginStrategy;
import hudson.Util;
import hudson.model.UsageStatistics.CombinedCipherInputStream;
import hudson.node_monitors.ArchitectureMonitor;
import hudson.util.VersionNumber;
import java.util.Set;
import jenkins.model.Jenkins;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.junit.Rule;
......@@ -53,11 +52,11 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.zip.GZIPInputStream;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.jvnet.hudson.test.TestPluginManager;
/**
* @author Kohsuke Kawaguchi
......@@ -72,6 +71,7 @@ public class UsageStatisticsTest {
*/
@Test
public void roundtrip() throws Exception {
((TestPluginManager) j.jenkins.pluginManager).installDetachedPlugin("credentials");
j.createOnlineSlave();
warmUpNodeMonitorCache();
......@@ -103,12 +103,6 @@ public class UsageStatisticsTest {
// Validate the plugins format
List<JSONObject> plugins = sortPlugins((List<JSONObject>) o.get("plugins"));
Set<String> detached = new TreeSet<>();
for (ClassicPluginStrategy.DetachedPlugin p: ClassicPluginStrategy.getDetachedPlugins()) {
if (p.getSplitWhen().isOlderThan(Jenkins.getVersion())) {
detached.add(p.getShortName());
}
}
Set<String> keys = new TreeSet<>();
keys.add("name");
keys.add("version");
......@@ -121,12 +115,15 @@ public class UsageStatisticsTest {
assertThat("No duplicates", reported.contains(name), is(false));
reported.add(name);
}
reported.retainAll(detached); // ignore the dependencies of the detached plugins
assertThat(reported, is(detached));
assertThat(reported, containsInAnyOrder("credentials"));
// Compare content to watch out for backwards compatibility
compareWithFile("jobs.json", sortJobTypes((JSONObject) o.get("jobs")));
compareWithFile("nodes.json", o.get("nodes"));
JSONArray nodes = o.getJSONArray("nodes");
for (Object node : nodes) {
((JSONObject) node).remove("os"); // depends on timing of AbstractNodeMonitorDescriptor.get whether or not this will be present
}
compareWithFile("nodes.json", nodes);
}
/**
......@@ -177,9 +174,6 @@ public class UsageStatisticsTest {
fileContent = fileContent.replace("JVMVENDOR", System.getProperty("java.vendor"));
fileContent = fileContent.replace("JVMNAME", System.getProperty("java.vm.name"));
fileContent = fileContent.replace("JVMVERSION", System.getProperty("java.version"));
String os = System.getProperty("os.name");
String arch = System.getProperty("os.arch");
fileContent = fileContent.replace("OSSPEC", os + " (" + arch + ')');
assertEquals(fileContent, object.toString());
}
}
......@@ -33,6 +33,7 @@ import org.xml.sax.SAXException;
import java.io.IOException;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.TestPluginManager;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
......@@ -61,10 +62,12 @@ public class I18nTest {
@Issue("JENKINS-35270")
@Test
public void test_baseName_plugin() throws IOException, SAXException {
// ssh-slaves plugin is installed by default
public void test_baseName_plugin() throws Exception {
((TestPluginManager) jenkinsRule.jenkins.pluginManager).installDetachedPlugin("credentials");
((TestPluginManager) jenkinsRule.jenkins.pluginManager).installDetachedPlugin("ssh-credentials");
((TestPluginManager) jenkinsRule.jenkins.pluginManager).installDetachedPlugin("ssh-slaves");
JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=hudson.plugins.sshslaves.Messages").getJSONObject();
Assert.assertEquals("ok", response.getString("status"));
Assert.assertEquals(response.toString(), "ok", response.getString("status"));
JSONObject data = response.getJSONObject("data");
Assert.assertEquals("The launch timeout must be a number.", data.getString("SSHConnector.LaunchTimeoutMustBeANumber"));
}
......
{"hudson-matrix-MatrixProject":0,"hudson-maven-MavenModuleSet":0,"hudson-model-ExternalJob":0,"hudson-model-FreeStyleProject":0,"org-jvnet-hudson-test-MockFolder":0,"org-jvnet-hudson-test-SecuredMockFolder":0}
\ No newline at end of file
{"hudson-matrix-MatrixProject":0,"hudson-maven-MavenModuleSet":0,"hudson-model-FreeStyleProject":0,"org-jvnet-hudson-test-MockFolder":0,"org-jvnet-hudson-test-SecuredMockFolder":0}
\ No newline at end of file
[{"master":true,"jvm-vendor":"JVMVENDOR","jvm-name":"JVMNAME","jvm-version":"JVMVERSION","executors":2,"os":"OSSPEC"},{"executors":1,"os":"OSSPEC"}]
\ No newline at end of file
[{"master":true,"jvm-vendor":"JVMVENDOR","jvm-name":"JVMNAME","jvm-version":"JVMVERSION","executors":2},{"executors":1}]
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册