提交 2652a6e3 编写于 作者: K kohsuke

[FIXED HUDSON-4640] applied the patch with some improvements in the backward...

[FIXED HUDSON-4640] applied the patch with some improvements in the backward compatibility handling.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@36010 71c3de6d-444a-0410-be80-ed276b4c234a
上级 e86b3a34
......@@ -230,7 +230,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
public final FilePath getModuleRoot() {
FilePath ws = getWorkspace();
if (ws==null) return null;
return getParent().getScm().getModuleRoot(ws);
return getParent().getScm().getModuleRoot(ws,this);
}
/**
......@@ -243,7 +243,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
public FilePath[] getModuleRoots() {
FilePath ws = getWorkspace();
if (ws==null) return null;
return getParent().getScm().getModuleRoots(ws);
return getParent().getScm().getModuleRoots(ws,this);
}
/**
......
......@@ -374,17 +374,29 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* use {@link #getSomeWorkspace()}
*/
public final FilePath getWorkspace() {
AbstractBuild b = getBuildForDeprecatedMethods();
return b != null ? b.getWorkspace() : null;
}
/**
* Various deprecated methods in this class all need the 'current' build. This method returns
* the build suitable for that purpose.
*
* @return An AbstractBuild for deprecated methods to use.
*/
private AbstractBuild getBuildForDeprecatedMethods() {
Executor e = Executor.currentExecutor();
if(e!=null) {
Executable exe = e.getCurrentExecutable();
if (exe instanceof AbstractBuild) {
AbstractBuild b = (AbstractBuild) exe;
if(b.getProject()==this)
return b.getWorkspace();
return b;
}
}
R lb = getLastBuild();
if(lb!=null) return lb.getWorkspace();
if(lb!=null) return lb;
return null;
}
......@@ -429,9 +441,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* See {@link #getWorkspace()} for a migration strategy.
*/
public FilePath getModuleRoot() {
FilePath ws = getWorkspace();
if(ws==null) return null;
return getScm().getModuleRoot(ws);
AbstractBuild b = getBuildForDeprecatedMethods();
return b != null ? b.getModuleRoot() : null;
}
/**
......@@ -445,7 +456,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* See {@link #getWorkspace()} for a migration strategy.
*/
public FilePath[] getModuleRoots() {
return getScm().getModuleRoots(getWorkspace());
AbstractBuild b = getBuildForDeprecatedMethods();
return b != null ? b.getModuleRoots() : null;
}
public int getQuietPeriod() {
......
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Stephen Connolly
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Stephen Connolly, InfraDNA, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -28,8 +28,10 @@ import hudson.FilePath;
import hudson.Launcher;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.Util;
import hudson.security.PermissionGroup;
import hudson.security.Permission;
import hudson.slaves.OfflineCause;
import hudson.tasks.Builder;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
......@@ -470,8 +472,27 @@ public abstract class SCM implements Describable<SCM>, ExtensionPoint {
*
* @param workspace
* The workspace root directory.
* @param build
* The build for which the module root is desired.
* This parameter is null when existing legacy code calls deprecated {@link #getModuleRoot(FilePath)}.
* Handle this situation gracefully if your can, but otherwise you can just fail with an exception, too.
*
* @since 1.382
*/
public FilePath getModuleRoot(FilePath workspace, AbstractBuild build) {
// For backwards compatibility, call the one argument version of the method.
return getModuleRoot(workspace);
}
/**
* @deprecated since 1.382
* Use/override {@link #getModuleRoot(FilePath, AbstractBuild)} instead.
*/
public FilePath getModuleRoot(FilePath workspace) {
if (Util.isOverridden(SCM.class,getClass(),"getModuleRoot", FilePath.class,AbstractBuild.class))
// if the subtype already implements newer getModuleRoot(FilePath,AbstractBuild), call that.
return getModuleRoot(workspace,null);
return workspace;
}
......@@ -497,12 +518,36 @@ public abstract class SCM implements Describable<SCM>, ExtensionPoint {
*
* <p>
* For normal SCMs, the array will be of length <code>1</code> and it's contents
* will be identical to calling {@link #getModuleRoot(FilePath)}.
* will be identical to calling {@link #getModuleRoot(FilePath, AbstractBuild)}.
*
* @param workspace The workspace root directory
* @param build
* The build for which the module roots are desired.
* This parameter is null when existing legacy code calls deprecated {@link #getModuleRoot(FilePath)}.
* Handle this situation gracefully if your can, but otherwise you can just fail with an exception, too.
*
* @return An array of all module roots.
* @since 1.382
*/
public FilePath[] getModuleRoots(FilePath workspace, AbstractBuild build) {
if (Util.isOverridden(SCM.class,getClass(),"getModuleRoots", FilePath.class))
// if the subtype derives legacy getModuleRoots(FilePath), delegate to it
return getModuleRoots(workspace);
// otherwise the default implementation
return new FilePath[]{getModuleRoot(workspace,build)};
}
/**
* @deprecated as of 1.382.
* Use/derive from {@link #getModuleRoots(FilePath, AbstractBuild)} instead.
*/
public FilePath[] getModuleRoots(FilePath workspace) {
if (Util.isOverridden(SCM.class,getClass(),"getModuleRoots", FilePath.class, AbstractBuild.class))
// if the subtype already derives newer getModuleRoots(FilePath,AbstractBuild), delegate to it
return getModuleRoots(workspace,null);
// otherwise the default implementation
return new FilePath[] { getModuleRoot(workspace), };
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册