Skip to content

Commit

Permalink
Do not load detached plugins during tests (#2829)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jglick authored and oleg-nenashev committed May 1, 2017
1 parent c33e7dc commit 0993b70
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 32 deletions.
7 changes: 6 additions & 1 deletion core/src/main/java/hudson/ClassicPluginStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ private static Manifest loadLinkedManifest(File archive) throws IOException {
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)
Expand Down Expand Up @@ -669,6 +671,9 @@ protected void zipDir(Resource dir, ZipOutputStream zOut, String vPath,
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) {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ public synchronized void resolveDependantPlugins() {
* 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);
Expand Down
8 changes: 1 addition & 7 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions test/src/test/groovy/hudson/model/AbstractProjectTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion test/src/test/java/hudson/PluginManagerInstalledGUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ protected Collection<String> loadBundledPlugins() throws Exception {
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");
}
}
};
Expand Down
2 changes: 0 additions & 2 deletions test/src/test/java/hudson/PluginManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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;
Expand Down Expand Up @@ -167,7 +166,6 @@ public void startPlugin(PluginWrapper plugin) throws Exception {
// 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);
Expand Down
2 changes: 2 additions & 0 deletions test/src/test/java/hudson/PluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
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 {

@Rule public JenkinsRule r = new JenkinsRule();

@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);
Expand Down
26 changes: 10 additions & 16 deletions test/src/test/java/hudson/model/UsageStatisticsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@

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;
Expand All @@ -53,11 +52,11 @@
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
Expand All @@ -72,6 +71,7 @@ public class UsageStatisticsTest {
*/
@Test
public void roundtrip() throws Exception {
((TestPluginManager) j.jenkins.pluginManager).installDetachedPlugin("credentials");

j.createOnlineSlave();
warmUpNodeMonitorCache();
Expand Down Expand Up @@ -103,12 +103,6 @@ public void roundtrip() throws Exception {

// 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");
Expand All @@ -121,12 +115,15 @@ public void roundtrip() throws Exception {
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);
}

/**
Expand Down Expand Up @@ -177,9 +174,6 @@ private void compareWithFile(String fileName, Object object) throws IOException
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());
}
}
9 changes: 6 additions & 3 deletions test/src/test/java/jenkins/I18nTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

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>
Expand Down Expand Up @@ -61,10 +62,12 @@ public void test_baseName_unknown() throws IOException, SAXException {

@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"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"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}
{"hudson-matrix-MatrixProject":0,"hudson-maven-MavenModuleSet":0,"hudson-model-FreeStyleProject":0,"org-jvnet-hudson-test-MockFolder":0,"org-jvnet-hudson-test-SecuredMockFolder":0}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"master":true,"jvm-vendor":"JVMVENDOR","jvm-name":"JVMNAME","jvm-version":"JVMVERSION","executors":2,"os":"OSSPEC"},{"executors":1,"os":"OSSPEC"}]
[{"master":true,"jvm-vendor":"JVMVENDOR","jvm-name":"JVMNAME","jvm-version":"JVMVERSION","executors":2},{"executors":1}]

0 comments on commit 0993b70

Please sign in to comment.