mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
Sorry my mistake.
This commit is contained in:
1 parent
535e9686bc
commit
c85e60f14e
88 files changed
+4757
-667
No files matched your search
@@ -2,7 +2,7 @@
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi,
|
||||
* Red Hat, Inc., Victor Glushenkov, Alan Harder
|
||||
* Red Hat, Inc., Victor Glushenkov, Alan Harder, 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
|
||||
@@ -24,13 +24,29 @@
|
||||
*/
|
||||
package hudson.maven;
|
||||
|
||||
import hudson.*;
|
||||
import static hudson.model.Result.FAILURE;
|
||||
import hudson.AbortException;
|
||||
import hudson.EnvVars;
|
||||
import hudson.FilePath;
|
||||
import hudson.FilePath.FileCallable;
|
||||
import hudson.Launcher;
|
||||
import hudson.Util;
|
||||
import hudson.maven.MavenBuild.ProxyImpl2;
|
||||
import hudson.maven.reporters.MavenFingerprinter;
|
||||
import hudson.maven.reporters.MavenMailer;
|
||||
import hudson.model.*;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.Action;
|
||||
import hudson.model.Build;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Cause.UpstreamCause;
|
||||
import hudson.model.Computer;
|
||||
import hudson.model.Environment;
|
||||
import hudson.model.Fingerprint;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.ParametersAction;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.remoting.Channel;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.scm.ChangeLogSet;
|
||||
@@ -39,9 +55,33 @@ import hudson.tasks.MailSender;
|
||||
import hudson.tasks.Maven.MavenInstallation;
|
||||
import hudson.util.ArgumentListBuilder;
|
||||
import hudson.util.IOUtils;
|
||||
import hudson.util.MaskingClassLoader;
|
||||
import hudson.util.StreamTaskListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.BuildFailureException;
|
||||
import org.apache.maven.embedder.MavenEmbedderException;
|
||||
import org.apache.maven.artifact.versioning.ComparableVersion;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
@@ -50,15 +90,9 @@ import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static hudson.model.Result.FAILURE;
|
||||
import org.sonatype.aether.transfer.TransferCancelledException;
|
||||
import org.sonatype.aether.transfer.TransferEvent;
|
||||
import org.sonatype.aether.transfer.TransferListener;
|
||||
|
||||
/**
|
||||
* {@link Build} for {@link MavenModuleSet}.
|
||||
@@ -427,6 +461,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
PrintStream logger = listener.getLogger();
|
||||
Result r = null;
|
||||
try {
|
||||
|
||||
EnvVars envVars = getEnvironment(listener);
|
||||
MavenInstallation mvn = project.getMaven();
|
||||
if(mvn==null)
|
||||
@@ -435,6 +470,14 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
|
||||
mvn = mvn.forEnvironment(envVars).forNode(Computer.currentComputer().getNode(), listener);
|
||||
|
||||
MavenInformation mavenInformation = getModuleRoot().act( new MavenVersionCallable( mvn.getHome() ));
|
||||
|
||||
String mavenVersion = mavenInformation.getVersion();
|
||||
|
||||
project.setMavenVersionUsed( mavenVersion );
|
||||
|
||||
listener.getLogger().println("Found mavenVersion " + mavenVersion + " from file " + mavenInformation.getVersionResourcePath());
|
||||
|
||||
if(!project.isAggregatorStyleBuild()) {
|
||||
parsePoms(listener, logger, envVars, mvn);
|
||||
// start module builds
|
||||
@@ -473,9 +516,9 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
// we act as if incrementalBuild is not set if there are no changes.
|
||||
if (!MavenModuleSetBuild.this.getChangeSet().isEmptySet()
|
||||
&& project.isIncrementalBuild()) {
|
||||
// If there are changes for this module, add it.
|
||||
// Also add it if we've never seen this module before,
|
||||
// or if the previous build of this module failed or was unstable.
|
||||
//If there are changes for this module, add it.
|
||||
// Also add it if we've never seen this module before,
|
||||
// or if the previous build of this module failed or was unstable.
|
||||
if ((mb.getPreviousBuiltBuild() == null) ||
|
||||
(!getChangeSetFor(m).isEmpty())
|
||||
|| (mb.getPreviousBuiltBuild().getResult().isWorseThan(Result.SUCCESS))) {
|
||||
@@ -499,16 +542,34 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
if(!pom.exists() && parentLoc.exists())
|
||||
pom = parentLoc;
|
||||
|
||||
ProcessCache.MavenProcess process = MavenBuild.mavenProcessCache.get(launcher.getChannel(), slistener,
|
||||
new MavenProcessFactory(project,launcher,envVars,pom.getParent()));
|
||||
|
||||
|
||||
ProcessCache.MavenProcess process = null;
|
||||
|
||||
boolean maven3orLater = MavenUtil.maven3orLater( mavenVersion );
|
||||
|
||||
if ( maven3orLater )
|
||||
{
|
||||
LOGGER.info( "using maven 3 " + mavenVersion );
|
||||
process =
|
||||
MavenBuild.mavenProcessCache.get( launcher.getChannel(), slistener,
|
||||
new Maven3ProcessFactory( project, launcher, envVars,
|
||||
pom.getParent() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
process =
|
||||
MavenBuild.mavenProcessCache.get( launcher.getChannel(), slistener,
|
||||
new MavenProcessFactory( project, launcher, envVars,
|
||||
pom.getParent() ) );
|
||||
}
|
||||
ArgumentListBuilder margs = new ArgumentListBuilder().add("-B").add("-f", pom.getRemote());
|
||||
if(project.usesPrivateRepository())
|
||||
margs.add("-Dmaven.repo.local="+getWorkspace().child(".repository"));
|
||||
// If incrementalBuild is set, and we're on Maven 2.1 or later, *and* there's at least one module
|
||||
// listed in changedModules, do the Maven incremental build commands - if there are no changed modules,
|
||||
// We're building everything anyway.
|
||||
if (project.isIncrementalBuild() && mvn.isMaven2_1(launcher) && !changedModules.isEmpty()) {
|
||||
boolean maven2_1orLater = new ComparableVersion (mavenVersion).compareTo( new ComparableVersion ("2.1") ) >= 0;
|
||||
if (project.isIncrementalBuild() && maven2_1orLater && !changedModules.isEmpty()) {
|
||||
margs.add("-amd");
|
||||
margs.add("-pl", Util.join(changedModules, ","));
|
||||
}
|
||||
@@ -527,18 +588,41 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
}
|
||||
|
||||
margs.addTokenized(envVars.expand(project.getGoals()));
|
||||
|
||||
Builder builder = new Builder(slistener, proxies, project.sortedActiveModules, margs.toList(), envVars);
|
||||
MavenProbeAction mpa=null;
|
||||
try {
|
||||
mpa = new MavenProbeAction(project,process.channel);
|
||||
addAction(mpa);
|
||||
r = process.call(builder);
|
||||
return r;
|
||||
} finally {
|
||||
builder.end(launcher);
|
||||
getActions().remove(mpa);
|
||||
process.discard();
|
||||
if (maven3orLater)
|
||||
{
|
||||
|
||||
Map<ModuleName,List<MavenReporter>> reporters = new HashMap<ModuleName, List<MavenReporter>>(project.sortedActiveModules.size());
|
||||
for (MavenModule mavenModule : project.sortedActiveModules)
|
||||
{
|
||||
reporters.put( mavenModule.getModuleName(), mavenModule.createReporters() );
|
||||
}
|
||||
Maven3Builder maven3Builder = new Maven3Builder( slistener, proxies, reporters, margs.toList(), envVars );
|
||||
MavenProbeAction mpa=null;
|
||||
try {
|
||||
mpa = new MavenProbeAction(project,process.channel);
|
||||
addAction(mpa);
|
||||
r = process.call(maven3Builder);
|
||||
return r;
|
||||
} finally {
|
||||
maven3Builder.end(launcher);
|
||||
getActions().remove(mpa);
|
||||
process.discard();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Builder builder = new Builder(slistener, proxies, project.sortedActiveModules, margs.toList(), envVars);
|
||||
MavenProbeAction mpa=null;
|
||||
try {
|
||||
mpa = new MavenProbeAction(project,process.channel);
|
||||
addAction(mpa);
|
||||
r = process.call(builder);
|
||||
return r;
|
||||
} finally {
|
||||
builder.end(launcher);
|
||||
getActions().remove(mpa);
|
||||
process.discard();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (r != null) {
|
||||
@@ -741,6 +825,9 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
@Override
|
||||
public Result call() throws IOException {
|
||||
try {
|
||||
if (debug) {
|
||||
listener.getLogger().println("Builder extends MavenBuilder in call " + Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
return super.call();
|
||||
} finally {
|
||||
if(lastProxy!=null)
|
||||
@@ -748,6 +835,7 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void preBuild(MavenSession session, ReactorManager rm, EventDispatcher dispatcher) throws BuildFailureException, LifecycleExecutionException, IOException, InterruptedException {
|
||||
// set all modules which are not actually being build (in incremental builds) to NOT_BUILD
|
||||
@@ -832,8 +920,16 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
if(!r.reportGenerated(proxy,project,report,listener))
|
||||
throw new hudson.maven.agent.AbortException(r+" failed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public ClassLoader getClassLoader()
|
||||
{
|
||||
return new MaskingClassLoader( super.getClassLoader() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -872,7 +968,6 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
private final boolean nonRecursive;
|
||||
// We're called against the module root, not the workspace, which can cause a lot of confusion.
|
||||
private final String workspaceProper;
|
||||
|
||||
public PomParser(BuildListener listener, MavenInstallation mavenHome, MavenModuleSet project) {
|
||||
// project cannot be shipped to the remote JVM, so all the relevant properties need to be captured now.
|
||||
this.listener = listener;
|
||||
@@ -888,7 +983,6 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
this.privateRepository = null;
|
||||
}
|
||||
this.alternateSettings = project.getAlternateSettings();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -956,32 +1050,51 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
if (!settingsLoc.exists() && mrSettingsLoc.exists())
|
||||
settingsLoc = mrSettingsLoc;
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
logger.println("use settingsLoc " + settingsLoc + " , privateRepository " + privateRepository);
|
||||
}
|
||||
if ((settingsLoc != null) && (!settingsLoc.exists())) {
|
||||
throw new AbortException(Messages.MavenModuleSetBuild_NoSuchAlternateSettings(settingsLoc.getAbsolutePath()));
|
||||
}
|
||||
|
||||
try {
|
||||
MavenEmbedder embedder = MavenUtil.
|
||||
createEmbedder(listener, mavenHome.getHomeDir(), profiles,
|
||||
properties, privateRepository, settingsLoc);
|
||||
MavenProject mp = embedder.readProject(pom);
|
||||
Map<MavenProject,String> relPath = new HashMap<MavenProject,String>();
|
||||
MavenUtil.resolveModules(embedder,mp,getRootPath(rootPOMRelPrefix),relPath,listener,nonRecursive);
|
||||
MavenEmbedderRequest mavenEmbedderRequest = new MavenEmbedderRequest( listener, mavenHome.getHomeDir(),
|
||||
profiles, properties,
|
||||
privateRepository, settingsLoc );
|
||||
mavenEmbedderRequest.setTransferListener( new SimpleTransferListener(listener) );
|
||||
MavenEmbedder embedder = MavenUtil.createEmbedder( mavenEmbedderRequest );
|
||||
|
||||
List<MavenProject> mps = embedder.readProjects( pom,true);
|
||||
Map<String,MavenProject> canonicalPaths = new HashMap<String, MavenProject>( mps.size() );
|
||||
for(MavenProject mp : mps) {
|
||||
canonicalPaths.put( mp.getBasedir().getCanonicalPath(), mp );
|
||||
}
|
||||
//MavenUtil.resolveModules(embedder,mp,getRootPath(rootPOMRelPrefix),relPath,listener,nonRecursive);
|
||||
|
||||
if(verbose) {
|
||||
for (Entry<MavenProject, String> e : relPath.entrySet())
|
||||
logger.printf("Discovered %s at %s\n",e.getKey().getId(),e.getValue());
|
||||
for (Entry<String,MavenProject> e : canonicalPaths.entrySet())
|
||||
logger.printf("Discovered %s at %s\n",e.getValue().getId(),e.getKey());
|
||||
}
|
||||
|
||||
List<PomInfo> infos = new ArrayList<PomInfo>();
|
||||
toPomInfo(mp,null,relPath,infos);
|
||||
Set<PomInfo> infos = new LinkedHashSet<PomInfo>();
|
||||
MavenProject rootProject = null;
|
||||
for (MavenProject mp : mps) {
|
||||
if (mp.isExecutionRoot()) {
|
||||
rootProject = mp;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// if rootProject is null but no reason :-) use the first one
|
||||
if (rootProject == null) {
|
||||
rootProject = mps.get( 0 );
|
||||
}
|
||||
toPomInfo(rootProject,null,canonicalPaths,infos);
|
||||
|
||||
for (PomInfo pi : infos)
|
||||
pi.cutCycle();
|
||||
|
||||
embedder.stop();
|
||||
return infos;
|
||||
return new ArrayList<PomInfo>(infos);
|
||||
} catch (MavenEmbedderException e) {
|
||||
throw new MavenExecutionException(e);
|
||||
} catch (ProjectBuildingException e) {
|
||||
@@ -989,11 +1102,28 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
}
|
||||
}
|
||||
|
||||
private void toPomInfo(MavenProject mp, PomInfo parent, Map<MavenProject,String> relPath, List<PomInfo> infos) {
|
||||
PomInfo pi = new PomInfo(mp, parent, relPath.get(mp));
|
||||
private void toPomInfo(MavenProject mp, PomInfo parent, Map<String,MavenProject> abslPath, Set<PomInfo> infos) throws IOException {
|
||||
String absolutePath = FilenameUtils.normalize( mp.getBasedir().getAbsolutePath());
|
||||
String relPath = StringUtils.removeStart( absolutePath, this.workspaceProper );
|
||||
|
||||
relPath = StringUtils.remove( relPath, '/' );
|
||||
|
||||
// root must be marked with only /
|
||||
if (StringUtils.isBlank( relPath )) {
|
||||
relPath = "/";
|
||||
}
|
||||
|
||||
PomInfo pi = new PomInfo(mp, parent, relPath);
|
||||
infos.add(pi);
|
||||
for (MavenProject child : (List<MavenProject>)mp.getCollectedProjects())
|
||||
toPomInfo(child,pi,relPath,infos);
|
||||
for (String modulePath : mp.getModules())
|
||||
{
|
||||
if (StringUtils.isBlank( modulePath )) {
|
||||
continue;
|
||||
}
|
||||
File path = new File(mp.getBasedir(), modulePath);
|
||||
MavenProject child = abslPath.get( path.getCanonicalPath());
|
||||
toPomInfo(child,pi,abslPath,infos);
|
||||
}
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -1004,10 +1134,60 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
|
||||
/**
|
||||
* Extra verbose debug switch.
|
||||
*/
|
||||
public static boolean debug = false;
|
||||
public static boolean debug = Boolean.getBoolean( "hudson.maven.debug" );
|
||||
|
||||
@Override
|
||||
public MavenModuleSet getParent() {// don't know why, but javac wants this
|
||||
return super.getParent();
|
||||
}
|
||||
|
||||
/**
|
||||
* will log in the {@link TaskListener} when transferFailed and transferSucceeded
|
||||
* @author Olivier Lamy
|
||||
* @since
|
||||
*/
|
||||
public static class SimpleTransferListener implements TransferListener
|
||||
{
|
||||
private TaskListener taskListener;
|
||||
public SimpleTransferListener(TaskListener taskListener)
|
||||
{
|
||||
this.taskListener = taskListener;
|
||||
}
|
||||
|
||||
public void transferCorrupted( TransferEvent arg0 )
|
||||
throws TransferCancelledException
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
public void transferFailed( TransferEvent transferEvent )
|
||||
{
|
||||
taskListener.getLogger().println("failed to transfer " + transferEvent.getException().getMessage());
|
||||
}
|
||||
|
||||
public void transferInitiated( TransferEvent arg0 )
|
||||
throws TransferCancelledException
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
public void transferProgressed( TransferEvent arg0 )
|
||||
throws TransferCancelledException
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
public void transferStarted( TransferEvent arg0 )
|
||||
throws TransferCancelledException
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
public void transferSucceeded( TransferEvent transferEvent )
|
||||
{
|
||||
taskListener.getLogger().println( "downloaded artifact " + transferEvent.getResource().getRepositoryUrl()
|
||||
+ "/" + transferEvent.getResource().getResourceName() );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user