Skip to content

Commit

Permalink
[JENKINS-24827] Complete compatibility with jetty 8.x
Browse files Browse the repository at this point in the history
- Update jetty to latest 8.x
- Expose jetty packages to webapp as it is required for jndi initial
factory
- Rename org.mortbay.jetty to org.eclipse.jetty
  • Loading branch information
Vlatombe committed May 11, 2015
1 parent 2634db7 commit b93b423
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 53 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -94,7 +94,7 @@
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler-groovy</artifactId>
<version>1.169</version>
<version>1.237</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -119,7 +119,7 @@
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.14.v20131031</version>
<version>8.1.16.v20140903</version>
</dependency>
<dependency>
<groupId>net.java.sezpoz</groupId>
Expand Down
Expand Up @@ -632,7 +632,7 @@ public void configureWebApplication () throws Exception
* files change.
*
*/
protected void startScanner() throws Exception
private void startScanner() throws Exception
{
// check if scanning is enabled
if (getScanIntervalSeconds() <= 0) return;
Expand Down
@@ -0,0 +1,41 @@
package org.jenkinsci.maven.plugins.hpi;

import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;

/**
* Only exposes Servlet API and Jetty to the web application, then JavaSE.
*
* <p>
* This is because the classloader that loads this plugin brings in a whole lot of baggage, such as
* Maven, Xalan, commons libraries, and etc., which can interfere with what's in Jenkins and plugins.
*
* @author Kohsuke Kawaguchi
*/
public class JettyAndServletApiOnlyClassLoader extends ClassLoader {
private final ClassLoader jettyClassLoader;

public JettyAndServletApiOnlyClassLoader(ClassLoader parent, ClassLoader jettyClassLoader) {
super(parent);
this.jettyClassLoader = jettyClassLoader;
}

@Override
public Enumeration<URL> getResources(String name) throws IOException {
if (name.equals("jndi.properties")) {
return jettyClassLoader.getResources(name);
}
return Collections.emptyEnumeration();
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.startsWith("javax.")
|| name.startsWith("org.eclipse.jetty."))
return jettyClassLoader.loadClass(name);
else
throw new ClassNotFoundException(name);
}
}
45 changes: 22 additions & 23 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/RunMojo.java
Expand Up @@ -33,6 +33,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProjectBuilder;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.Scanner;
Expand All @@ -45,7 +46,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -90,7 +90,7 @@ public class RunMojo extends AbstractJettyMojo {
* </p>
*/
@Parameter
private File webApp;
private File webAppFile;

/**
* Path to <tt>$JENKINS_HOME</tt>. The launched Jenkins will use this directory as the workspace.
Expand Down Expand Up @@ -230,7 +230,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// auto-enable stapler trace, unless otherwise configured already.
setSystemPropertyIfEmpty("stapler.trace", "true");
// allow Jetty to accept a bigger form so that it can handle update center JSON post
setSystemPropertyIfEmpty("org.mortbay.jetty.Request.maxFormContentSize","-1");
setSystemPropertyIfEmpty("org.eclipse.jetty.Request.maxFormContentSize","-1");
// general-purpose system property so that we can tell from Jenkins if we are running in the hpi:run mode.
setSystemPropertyIfEmpty("hudson.hpi.run","true");
// this adds 3 secs to the shutdown time. Skip it.
Expand All @@ -251,7 +251,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.groupIdIs("org.jenkins-ci.main","org.jvnet.hudson.main")
.artifactIdIsNot("remoting"); // remoting moved to its own release cycle

webApp = getJenkinsWarArtifact().getFile();
webAppFile = getJenkinsWarArtifact().getFile();

// make sure all the relevant Jenkins artifacts have the same version
for (Artifact a : jenkinsArtifacts) {
Expand All @@ -268,10 +268,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// enable view auto refreshing via stapler
setSystemPropertyIfEmpty("stapler.jelly.noCache","true");

List res = getProject().getBuild().getResources();
List<Resource> res = getProject().getBuild().getResources();
if(!res.isEmpty()) {
// pick up the first one and use it
Resource r = (Resource) res.get(0);
Resource r = res.get(0);
setSystemPropertyIfEmpty("stapler.resourcePath",r.getDirectory());
}

Expand Down Expand Up @@ -408,12 +408,16 @@ private void generateHpl() throws MojoExecutionException, MojoFailureException {
public void configureWebApplication() throws Exception {
// Jetty tries to do this in WebAppContext.resolveWebApp but it failed to delete the directory.
File extractedWebAppDir= new File(getTmpDirectory(), "webapp");
if (isExtractedWebAppDirStale(extractedWebAppDir, webApp)) {
if (isExtractedWebAppDirStale(extractedWebAppDir, webAppFile)) {
FileUtils.deleteDirectory(extractedWebAppDir);
}

super.configureWebApplication();
getWebAppConfig().setWar(webApp.getCanonicalPath());
getWebAppConfig().setWar(webAppFile.getCanonicalPath());
// cf. https://wiki.jenkins-ci.org/display/JENKINS/Jetty
HashLoginService hashLoginService = (new HashLoginService("Jenkins Realm"));
hashLoginService.setConfig(System.getProperty("jetty.home", ".") + "/etc/realm.properties");
getWebAppConfig().getSecurityHandler().setLoginService(hashLoginService);
}

private static final String VERSION_PATH = "META-INF/maven/org.jenkins-ci.main/jenkins-war/pom.properties";
Expand Down Expand Up @@ -478,7 +482,7 @@ private String loadVersion(InputStream is) throws IOException {
}

public void configureScanner() throws MojoExecutionException {
setUpScanList(new ArrayList());
setUpScanList(new ArrayList<File>());

ArrayList<Scanner.BulkListener> listeners = new ArrayList<Scanner.BulkListener>();
listeners.add(new Scanner.BulkListener() {
Expand Down Expand Up @@ -508,7 +512,7 @@ public void restartWebApp(boolean reconfigureScanner) throws Exception {
if (reconfigureScanner) {
getLog().info("Reconfiguring scanner after change to pom.xml ...");
generateHpl(); // regenerate hpl if POM changes.
ArrayList scanList = getScanList();
ArrayList<File> scanList = getScanList();
scanList.clear();
setUpScanList(scanList);
getScanner().setScanDirs(scanList);
Expand All @@ -519,33 +523,28 @@ public void restartWebApp(boolean reconfigureScanner) throws Exception {
getLog().info("Restart completed.");
}

private void setUpScanList(ArrayList scanList) {
private void setUpScanList(ArrayList<File> scanList) {
scanList.add(getProject().getFile());
scanList.add(webApp);
scanList.add(webAppFile);
scanList.add(new File(getProject().getBuild().getOutputDirectory()));
setScanList(scanList);
}

@Override
protected void startScanner() throws Exception {
super.startScanner();

protected void startConsoleScanner() throws Exception {
if (consoleForceReload) {
getLog().info("Console reloading is ENABLED. Hit ENTER on the console to restart the context.");
new ConsoleScanner(this).start();
consoleScanner = new ConsoleScanner(this);
consoleScanner.start();
}
}

public void checkPomConfiguration() throws MojoExecutionException {
}

public void finishConfigurationBeforeStart() {
// working around JETTY-1226. This bug affects those who use Axis from plugins, for example.
public void finishConfigurationBeforeStart() throws Exception {
super.finishConfigurationBeforeStart();
WebAppContext wac = getWebAppConfig();
List<String> sc = new ArrayList<String>(Arrays.asList(wac.getSystemClasses()));
sc.add("javax.activation.");
wac.setSystemClasses(sc.toArray(new String[sc.size()]));

// to allow the development environment to run multiple "mvn hpi:run" with different port,
// use different session cookie names. Otherwise they can mix up. See
// http://stackoverflow.com/questions/1612177/are-http-cookies-port-specific
Expand All @@ -555,7 +554,7 @@ public void finishConfigurationBeforeStart() {
try {
// for Jenkins modules, swap the component from jenkins.war by target/classes
// via classloader magic
WebAppClassLoader wacl = new WebAppClassLoader(new ServletApiOnlyClassLoader(null,getClass().getClassLoader()),wac) {
WebAppClassLoader wacl = new WebAppClassLoader(new JettyAndServletApiOnlyClassLoader(null,getClass().getClassLoader()),wac) {
private final Pattern exclusionPattern;
{
if (getProject().getPackaging().equals("jenkins-module")) {
Expand Down

This file was deleted.

0 comments on commit b93b423

Please sign in to comment.