Skip to content

Commit

Permalink
Merge pull request #11 from tomerc/master
Browse files Browse the repository at this point in the history
JENKINS-43446 - java.lang.NoSuchFieldError: DEFAULT_USER_SETTINGS_FILE
  • Loading branch information
aheritier committed Jun 2, 2017
2 parents 084ed65 + 62b24ba commit e1d712c
Show file tree
Hide file tree
Showing 10 changed files with 1,780 additions and 0 deletions.
39 changes: 39 additions & 0 deletions maven35-agent/pom.xml
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<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>
<parent>
<groupId>org.jenkins-ci.main.maven</groupId>
<artifactId>maven-modules</artifactId>
<version>1.9-SNAPSHOT</version>
</parent>
<artifactId>maven35-agent</artifactId>
<name>Jenkins Maven3.5x CLI Agent</name>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.main.maven</groupId>
<artifactId>maven33-interceptor</artifactId>
<scope>provided</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>${maven3.5.x.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.0.0.M2a</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
31 changes: 31 additions & 0 deletions maven35-agent/src/main/java/jenkins/maven3/agent/Maven35Agent.java
@@ -0,0 +1,31 @@
package jenkins.maven3.agent;

/*
* Copyright 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.
*/

/**
* Marker for MavenComputerListener to get the jar
* @author Olivier Lamy
* @since 1.9
*/
public interface Maven35Agent
{
// no op
}
215 changes: 215 additions & 0 deletions maven35-agent/src/main/java/jenkins/maven3/agent/Maven35Main.java
@@ -0,0 +1,215 @@
/*
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Olivier Lamy
*
* 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 jenkins.maven3.agent;

import org.codehaus.plexus.classworlds.launcher.Launcher;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;

import java.io.*;
import java.net.Socket;
import java.net.URL;


/**
* Entry point for launching Maven 3 and Hudson remoting in the same VM, in the
* classloader layout that Maven expects.
*
* <p>
* The actual Maven execution will be started by the program sent through
* remoting.
* </p>
*
* @author Kohsuke Kawaguchi
* @author Olivier Lamy
* @since 1.9
*/
public class Maven35Main
{

/**
* Used to pass the classworld instance to the code running inside the
* remoting system.
*/
private static Launcher launcher;

public static void main(String... args) throws Exception {
String slaveAgentSocket = args[4];
int i = slaveAgentSocket.indexOf(':');
if (i > 0) {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), slaveAgentSocket.substring(0, i), Integer.parseInt(slaveAgentSocket.substring(i+1)));
} else {
main(new File(args[0]), new File(args[1]), new File(args[2]),
new File(args[3]), null, Integer.parseInt(slaveAgentSocket));
}
}

@Deprecated
public static void main(File m2Home, File remotingJar, File interceptorJar
, File interceptorCommonJar, int tcpPort) throws Exception {

main(m2Home, remotingJar, interceptorJar, interceptorCommonJar, null, tcpPort);
}


/**
*
* @param m2Home
* Maven2 installation. This is where we find Maven jars that
* we'll run.
* @param remotingJar
* Hudson's remoting.jar that we'll load.
* @param interceptorJar
* maven-listener.jar that we'll load.
* @param interceptorCommonJar
* maven3-interceptor-commons.jar we'll load
* @param agentIp
* IP address the TCP socket is bound to
* @param tcpPort
* TCP socket that the launching Hudson will be listening to.
* This is used for the remoting communication.
*/
public static void main(File m2Home, File remotingJar, File interceptorJar,
File interceptorCommonJar, String agentIp, int tcpPort) throws Exception {
// Unix master with Windows slave ends up passing path in Unix format,
// so convert it to Windows format now so that no one chokes with the
// path format later.
try {
m2Home = m2Home.getCanonicalFile();
} catch (IOException e) {
// ignore. We'll check the error later if m2Home exists anyway
}

if (!m2Home.exists()) {
System.err.println("No such directory exists: " + m2Home);
System.exit(1);
}

versionCheck();

// expose variables used in the classworlds configuration
System.setProperty("maven.home", m2Home.getPath());
System.setProperty("maven3.interceptor.common", (interceptorCommonJar != null ? interceptorCommonJar
: interceptorCommonJar).getPath());
System.setProperty("maven3.interceptor", (interceptorJar != null ? interceptorJar
: interceptorJar).getPath());

// load the default realms
launcher = new Launcher();
launcher.setSystemClassLoader(Maven35Main.class.getClassLoader());
launcher.configure(getClassWorldsConfStream());


// create a realm for loading remoting subsystem.
// this needs to be able to see maven.
ClassRealm remoting = launcher.getWorld().newRealm( "hudson-remoting", launcher.getSystemClassLoader() );
remoting.setParentRealm(launcher.getWorld().getRealm("plexus.core"));
remoting.addURL(remotingJar.toURI().toURL());

final Socket s = new Socket(agentIp,tcpPort);

Class remotingLauncher = remoting.loadClass("hudson.remoting.Launcher");
remotingLauncher.getMethod("main",
new Class[] { InputStream.class, OutputStream.class }).invoke(
null,
new Object[] {
// do partial close, since socket.getInputStream and
// getOutputStream doesn't do it by
new BufferedInputStream(new FilterInputStream(s
.getInputStream()) {
public void close() throws IOException {
s.shutdownInput();
}
}),
new BufferedOutputStream(new RealFilter35OutputStream(s
.getOutputStream()) {
public void close() throws IOException {
s.shutdownOutput();
}
}) });
System.exit(0);
}

/**
* Called by the code in remoting to add more plexus components.
* @since 1.3
*/
public static void addPlexusComponents(URL[] modules) {
try {
ClassRealm realm = launcher.getWorld().getRealm("plexus.core");
for (int i=0; i<modules.length; i++) {
realm.addURL(modules[i]);
}
} catch (NoSuchRealmException e) {
throw new Error(e);
}
}

/**
* Called by the code in remoting to launch.
*/
public static int launch( String[] args ) throws Exception {

try {
launcher.launch( args );
} catch ( Throwable e ) {
e.printStackTrace();
throw new Exception( e );
}
return launcher.getExitCode();
}

private static InputStream getClassWorldsConfStream() throws FileNotFoundException {
String classWorldsConfLocation = System.getProperty("classworlds.conf");
if (classWorldsConfLocation == null || classWorldsConfLocation.trim().length() == 0) {
classWorldsConfLocation = System.getenv("classworlds.conf");
if (classWorldsConfLocation == null || classWorldsConfLocation.trim().length() == 0) {
return Maven35Main.class.getResourceAsStream("classworlds.conf");
}
}
return new FileInputStream(new File(classWorldsConfLocation));
}

/**
* Makes sure that this is Java7 or later.
*/
private static void versionCheck() {
String v = System.getProperty("java.class.version");
if (v != null) {
try {
if (Float.parseFloat(v) < 51.0) {
System.err
.println("Native maven support requires Java 1.7 or later, but this Maven is using "
+ System.getProperty("java.home"));
System.err.println("Please use the freestyle project.");
System.exit(1);
}
} catch (NumberFormatException e) {
// couldn't check.
}
}
}

}
@@ -0,0 +1,52 @@
/*
* 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 jenkins.maven3.agent;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
* JDK's {@link FilterOutputStream} has some real issues.
*
* @author Kohsuke Kawaguchi
*/
class RealFilter35OutputStream
extends FilterOutputStream {
public RealFilter35OutputStream(OutputStream core ) {
super(core);
}

public void write(byte[] b) throws IOException {
out.write(b);
}

public void write(byte[] b, int off, int len) throws IOException {
out.write(b, off, len);
}

public void close() throws IOException {
out.close();
}
}
@@ -0,0 +1,12 @@
#
# mostly copied as-is from $MAVEN_HOME/bin/m2.conf
#
main is org.jvnet.hudson.maven3.launcher.Maven35Launcher from plexus.core

set maven.home default ${user.home}/m2

[plexus.core]
load ${maven3.interceptor}
load ${maven3.interceptor.common}
optionally ${maven.home}/lib/ext/*.jar
load ${maven.home}/lib/*.jar

0 comments on commit e1d712c

Please sign in to comment.