Fixed a reference counting bug in the remoting layer.
@@ -82,6 +95,10 @@ Upcoming changes
Process the items hierarchy when displaying the Show Poll Thread Count option
(issue 22934)
+
+ Compressed output was turned on even before Access Denied errors were shown for disallowed Remote API requests, yielding a confusing error.
+ (issue 17374)
+ (issue 18116)
Properly close input streams in FileParameterValue
(issue 22693)
@@ -113,11 +130,8 @@ Upcoming changes
Added an option to archive artifacts only when the build is successful
(issue 22699)
diff --git a/cli/pom.xml b/cli/pom.xml
index 711bcde229..d9b86906b0 100644
--- a/cli/pom.xml
+++ b/cli/pom.xml
@@ -5,7 +5,7 @@
pomorg.jenkins-ci.main
- 1.567-SNAPSHOT
+ 1.568-SNAPSHOTcli
diff --git a/core/pom.xml b/core/pom.xml
index cccf922c7d..e9be9512ed 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -29,7 +29,7 @@ THE SOFTWARE.
org.jenkins-ci.mainpom
- 1.567-SNAPSHOT
+ 1.568-SNAPSHOT../pom.xml
diff --git a/core/src/main/java/hudson/Launcher.java b/core/src/main/java/hudson/Launcher.java
index 39d1a56b13..b08dfaf0f1 100644
--- a/core/src/main/java/hudson/Launcher.java
+++ b/core/src/main/java/hudson/Launcher.java
@@ -300,8 +300,13 @@ public abstract class Launcher {
return this;
}
+ /**
+ * Gets a list of environment variables to be set.
+ * Returns an empty array if envs field has not been initialized.
+ * @return If initialized, returns a copy of internal envs array. Otherwise - a new empty array.
+ */
public String[] envs() {
- return envs.clone();
+ return envs != null ? envs.clone() : new String[0];
}
/**
@@ -972,6 +977,88 @@ public abstract class Launcher {
}
}
}
+
+ /**
+ * A launcher which delegates to a provided inner launcher.
+ * Allows subclasses to only implement methods they want to override.
+ * Originally, this launcher has been implemented in
+ *
+ * Custom Tools Plugin.
+ *
+ * @author rcampbell
+ * @author Oleg Nenashev, Synopsys Inc.
+ * @since TODO: define version
+ */
+ public static class DecoratedLauncher extends Launcher {
+
+ private Launcher inner = null;
+
+ public DecoratedLauncher(Launcher inner) {
+ super(inner);
+ this.inner = inner;
+ }
+
+ @Override
+ public Proc launch(ProcStarter starter) throws IOException {
+ return inner.launch(starter);
+ }
+
+ @Override
+ public Channel launchChannel(String[] cmd, OutputStream out,
+ FilePath workDir, Map envVars) throws IOException,
+ InterruptedException {
+ return inner.launchChannel(cmd, out, workDir, envVars);
+ }
+
+ @Override
+ public void kill(Map modelEnvVars) throws IOException,
+ InterruptedException {
+ inner.kill(modelEnvVars);
+ }
+
+ @Override
+ public boolean isUnix() {
+ return inner.isUnix();
+ }
+
+ @Override
+ public Proc launch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException {
+ return inner.launch(cmd, mask, env, in, out, workDir);
+ }
+
+ @Override
+ public Computer getComputer() {
+ return inner.getComputer();
+ }
+
+ @Override
+ public TaskListener getListener() {
+ return inner.getListener();
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "; decorates " + inner.toString();
+ }
+
+ @Override
+ public VirtualChannel getChannel() {
+ return inner.getChannel();
+ }
+
+ @Override
+ public Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException {
+ return inner.launch(cmd, env, in, out, workDir);
+ }
+
+ /**
+ * Gets nested launcher.
+ * @return Inner launcher
+ */
+ public Launcher getInner() {
+ return inner;
+ }
+ }
public static class IOTriplet implements Serializable {
InputStream stdout,stderr;
diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java
index 2934a79a4f..b7725aa68f 100644
--- a/core/src/main/java/hudson/Util.java
+++ b/core/src/main/java/hudson/Util.java
@@ -73,6 +73,9 @@ import hudson.util.jna.Kernel32Utils;
import static hudson.util.jna.GNUCLibrary.LIBC;
import java.security.DigestInputStream;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.apache.commons.codec.digest.DigestUtils;
/**
@@ -94,7 +97,8 @@ public class Util {
* Creates a filtered sublist.
* @since 1.176
*/
- public static List filter( Iterable> base, Class type ) {
+ @Nonnull
+ public static List filter( @Nonnull Iterable> base, @Nonnull Class type ) {
List r = new ArrayList();
for (Object i : base) {
if(type.isInstance(i))
@@ -106,7 +110,8 @@ public class Util {
/**
* Creates a filtered sublist.
*/
- public static List filter( List> base, Class type ) {
+ @Nonnull
+ public static List filter( @Nonnull List> base, @Nonnull Class type ) {
return filter((Iterable)base,type);
}
@@ -122,7 +127,8 @@ public class Util {
* Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.)
*
*/
- public static String replaceMacro(String s, Map properties) {
+ @Nullable
+ public static String replaceMacro( @CheckForNull String s, @Nonnull Map properties) {
return replaceMacro(s,new VariableResolver.ByMap(properties));
}
@@ -132,7 +138,8 @@ public class Util {
*
* Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.)
*/
- public static String replaceMacro(String s, VariableResolver resolver) {
+ @Nullable
+ public static String replaceMacro(@CheckForNull String s, @Nonnull VariableResolver resolver) {
if (s == null) {
return null;
}
@@ -165,11 +172,13 @@ public class Util {
/**
* Loads the contents of a file into a string.
*/
- public static String loadFile(File logfile) throws IOException {
+ @Nonnull
+ public static String loadFile(@Nonnull File logfile) throws IOException {
return loadFile(logfile, Charset.defaultCharset());
}
- public static String loadFile(File logfile,Charset charset) throws IOException {
+ @Nonnull
+ public static String loadFile(@Nonnull File logfile, @Nonnull Charset charset) throws IOException {
if(!logfile.exists())
return "";
@@ -195,7 +204,7 @@ public class Util {
* @throws IOException
* if the operation fails.
*/
- public static void deleteContentsRecursive(File file) throws IOException {
+ public static void deleteContentsRecursive(@Nonnull File file) throws IOException {
File[] files = file.listFiles();
if(files==null)
return; // the directory didn't exist in the first place
@@ -208,7 +217,7 @@ public class Util {
* @param f a file to delete
* @throws IOException if it exists but could not be successfully deleted
*/
- public static void deleteFile(File f) throws IOException {
+ public static void deleteFile(@Nonnull File f) throws IOException {
if (!f.delete()) {
if(!f.exists())
// we are trying to delete a file that no longer exists, so this is not an error
@@ -259,7 +268,7 @@ public class Util {
/**
* Makes the given file writable by any means possible.
*/
- private static void makeWritable(File f) {
+ private static void makeWritable(@Nonnull File f) {
if (f.setWritable(true)) {
return;
}
@@ -287,7 +296,7 @@ public class Util {
}
- public static void deleteRecursive(File dir) throws IOException {
+ public static void deleteRecursive(@Nonnull File dir) throws IOException {
if(!isSymlink(dir))
deleteContentsRecursive(dir);
try {
@@ -321,7 +330,7 @@ public class Util {
* Checks if the given file represents a symlink.
*/
//Taken from http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?view=markup
- public static boolean isSymlink(File file) throws IOException {
+ public static boolean isSymlink(@Nonnull File file) throws IOException {
Boolean r = isSymlinkJava7(file);
if (r != null) {
return r;
@@ -350,7 +359,7 @@ public class Util {
}
@SuppressWarnings("NP_BOOLEAN_RETURN_NULL")
- private static Boolean isSymlinkJava7(File file) throws IOException {
+ private static Boolean isSymlinkJava7(@Nonnull File file) throws IOException {
try {
Object path = File.class.getMethod("toPath").invoke(file);
return (Boolean) Class.forName("java.nio.file.Files").getMethod("isSymbolicLink", Class.forName("java.nio.file.Path")).invoke(null, path);
@@ -379,13 +388,14 @@ public class Util {
* On Windows, error messages for IOException aren't very helpful.
* This method generates additional user-friendly error message to the listener
*/
- public static void displayIOException( IOException e, TaskListener listener ) {
+ public static void displayIOException(@Nonnull IOException e, @Nonnull TaskListener listener ) {
String msg = getWin32ErrorMessage(e);
if(msg!=null)
listener.getLogger().println(msg);
}
- public static String getWin32ErrorMessage(IOException e) {
+ @CheckForNull
+ public static String getWin32ErrorMessage(@Nonnull IOException e) {
return getWin32ErrorMessage((Throwable)e);
}
@@ -395,6 +405,7 @@ public class Util {
* @return
* null if there seems to be no error code or if the platform is not Win32.
*/
+ @CheckForNull
public static String getWin32ErrorMessage(Throwable e) {
String msg = e.getMessage();
if(msg!=null) {
@@ -420,6 +431,7 @@ public class Util {
* @return
* null if no such message is available.
*/
+ @CheckForNull
public static String getWin32ErrorMessage(int n) {
try {
ResourceBundle rb = ResourceBundle.getBundle("/hudson/win32errors");
@@ -433,6 +445,7 @@ public class Util {
/**
* Guesses the current host name.
*/
+ @Nonnull
public static String getHostName() {
try {
return InetAddress.getLocalHost().getHostName();
@@ -441,21 +454,21 @@ public class Util {
}
}
- public static void copyStream(InputStream in,OutputStream out) throws IOException {
+ public static void copyStream(@Nonnull InputStream in,@Nonnull OutputStream out) throws IOException {
byte[] buf = new byte[8192];
int len;
while((len=in.read(buf))>=0)
out.write(buf,0,len);
}
- public static void copyStream(Reader in, Writer out) throws IOException {
+ public static void copyStream(@Nonnull Reader in, @Nonnull Writer out) throws IOException {
char[] buf = new char[8192];
int len;
while((len=in.read(buf))>0)
out.write(buf,0,len);
}
- public static void copyStreamAndClose(InputStream in,OutputStream out) throws IOException {
+ public static void copyStreamAndClose(@Nonnull InputStream in, @Nonnull OutputStream out) throws IOException {
try {
copyStream(in,out);
} finally {
@@ -464,7 +477,7 @@ public class Util {
}
}
- public static void copyStreamAndClose(Reader in,Writer out) throws IOException {
+ public static void copyStreamAndClose(@Nonnull Reader in, @Nonnull Writer out) throws IOException {
try {
copyStream(in,out);
} finally {
@@ -483,18 +496,21 @@ public class Util {
* @since 1.145
* @see QuotedStringTokenizer
*/
- public static String[] tokenize(String s,String delimiter) {
+ @Nonnull
+ public static String[] tokenize(@Nonnull String s, @CheckForNull String delimiter) {
return QuotedStringTokenizer.tokenize(s,delimiter);
}
- public static String[] tokenize(String s) {
+ @Nonnull
+ public static String[] tokenize(@Nonnull String s) {
return tokenize(s," \t\n\r\f");
}
/**
* Converts the map format of the environment variables to the K=V format in the array.
*/
- public static String[] mapToEnv(Map m) {
+ @Nonnull
+ public static String[] mapToEnv(@Nonnull Map m) {
String[] r = new String[m.size()];
int idx=0;
@@ -504,7 +520,7 @@ public class Util {
return r;
}
- public static int min(int x, int... values) {
+ public static int min(int x, @Nonnull int... values) {
for (int i : values) {
if(i List createSubList( Collection> source, Class type ) {
+ @Nonnull
+ public static List createSubList(@Nonnull Collection> source, @Nonnull Class type ) {
List r = new ArrayList();
for (Object item : source) {
if(type.isInstance(item))
@@ -749,7 +780,8 @@ public class Util {
* {@link #rawEncode(String)} should generally be used instead, though be careful to pass only
* a single path component to that method (it will encode /, but this method does not).
*/
- public static String encode(String s) {
+ @Nonnull
+ public static String encode(@Nonnull String s) {
try {
boolean escaped = false;
@@ -806,7 +838,8 @@ public class Util {
* single path component used in constructing a URL.
* Method name inspired by PHP's rawurlencode.
*/
- public static String rawEncode(String s) {
+ @Nonnull
+ public static String rawEncode(@Nonnull String s) {
boolean escaped = false;
StringBuilder out = null;
CharsetEncoder enc = null;
@@ -855,7 +888,8 @@ public class Util {
/**
* Escapes HTML unsafe characters like <, & to the respective character entities.
*/
- public static String escape(String text) {
+ @Nonnull
+ public static String escape(@Nonnull String text) {
if (text==null) return null;
StringBuilder buf = new StringBuilder(text.length()+64);
for( int i=0; i List fixNull(List l) {
+ @Nonnull
+ public static List fixNull(@CheckForNull List l) {
return l!=null ? l : Collections.emptyList();
}
- public static Set fixNull(Set l) {
+ @Nonnull
+ public static Set fixNull(@CheckForNull Set l) {
return l!=null ? l : Collections.emptySet();
}
- public static Collection fixNull(Collection l) {
+ @Nonnull
+ public static Collection fixNull(@CheckForNull Collection l) {
return l!=null ? l : Collections.emptySet();
}
- public static Iterable fixNull(Iterable l) {
+ @Nonnull
+ public static Iterable fixNull(@CheckForNull Iterable l) {
return l!=null ? l : Collections.emptySet();
}
/**
* Cuts all the leading path portion and get just the file name.
*/
- public static String getFileName(String filePath) {
+ @Nonnull
+ public static String getFileName(@Nonnull String filePath) {
int idx = filePath.lastIndexOf('\\');
if(idx>=0)
return getFileName(filePath.substring(idx+1));
@@ -980,7 +1023,8 @@ public class Util {
/**
* Concatenate multiple strings by inserting a separator.
*/
- public static String join(Collection> strings, String separator) {
+ @Nonnull
+ public static String join(@Nonnull Collection> strings, @Nonnull String separator) {
StringBuilder buf = new StringBuilder();
boolean first=true;
for (Object s : strings) {
@@ -994,7 +1038,8 @@ public class Util {
/**
* Combines all the given collections into a single list.
*/
- public static List join(Collection extends T>... items) {
+ @Nonnull
+ public static List join(@Nonnull Collection extends T>... items) {
int size = 0;
for (Collection extends T> item : items)
size += item.size();
@@ -1021,7 +1066,8 @@ public class Util {
* Can be null.
* @since 1.172
*/
- public static FileSet createFileSet(File baseDir, String includes, String excludes) {
+ @Nonnull
+ public static FileSet createFileSet(@Nonnull File baseDir, @Nonnull String includes, @CheckForNull String excludes) {
FileSet fs = new FileSet();
fs.setDir(baseDir);
fs.setProject(new Project());
@@ -1043,7 +1089,8 @@ public class Util {
return fs;
}
- public static FileSet createFileSet(File baseDir, String includes) {
+ @Nonnull
+ public static FileSet createFileSet(@Nonnull File baseDir, @Nonnull String includes) {
return createFileSet(baseDir,includes,null);
}
@@ -1059,7 +1106,8 @@ public class Util {
* @param symlinkPath
* Where to create a symlink in (relative to {@code baseDir})
*/
- public static void createSymlink(File baseDir, String targetPath, String symlinkPath, TaskListener listener) throws InterruptedException {
+ public static void createSymlink(@Nonnull File baseDir, @Nonnull String targetPath,
+ @Nonnull String symlinkPath, @Nonnull TaskListener listener) throws InterruptedException {
try {
if (createSymlinkJava7(baseDir, targetPath, symlinkPath)) {
return;
@@ -1131,7 +1179,7 @@ public class Util {
}
}
- private static boolean createSymlinkJava7(File baseDir, String targetPath, String symlinkPath) throws IOException {
+ private static boolean createSymlinkJava7(@Nonnull File baseDir, @Nonnull String targetPath, @Nonnull String symlinkPath) throws IOException {
try {
Object path = File.class.getMethod("toPath").invoke(new File(baseDir, symlinkPath));
Object target = Class.forName("java.nio.file.Paths").getMethod("get", String.class, String[].class).invoke(null, targetPath, new String[0]);
@@ -1201,7 +1249,8 @@ public class Util {
* @return null
* if the specified file is not a symlink.
*/
- public static File resolveSymlinkToFile(File link) throws InterruptedException, IOException {
+ @CheckForNull
+ public static File resolveSymlinkToFile(@Nonnull File link) throws InterruptedException, IOException {
String target = resolveSymlink(link);
if (target==null) return null;
@@ -1221,7 +1270,8 @@ public class Util {
* If the symlink is relative, the returned string is that relative representation.
* The relative path is meant to be resolved from the location of the symlink.
*/
- public static String resolveSymlink(File link) throws InterruptedException, IOException {
+ @CheckForNull
+ public static String resolveSymlink(@Nonnull File link) throws InterruptedException, IOException {
try { // Java 7
Object path = File.class.getMethod("toPath").invoke(link);
return Class.forName("java.nio.file.Files").getMethod("readSymbolicLink", Class.forName("java.nio.file.Path")).invoke(null, path).toString();
@@ -1306,7 +1356,8 @@ public class Util {
* Wraps with the error icon and the CSS class to render error message.
* @since 1.173
*/
- public static String wrapToErrorSpan(String s) {
+ @Nonnull
+ public static String wrapToErrorSpan(@Nonnull String s) {
s = ""+s+"";
return s;
}
@@ -1319,7 +1370,8 @@ public class Util {
* @param defaultNumber number to return if the string can not be parsed
* @return returns the parsed string; otherwise the default number
*/
- public static Number tryParseNumber(String numberStr, Number defaultNumber) {
+ @CheckForNull
+ public static Number tryParseNumber(@CheckForNull String numberStr, @CheckForNull Number defaultNumber) {
if ((numberStr == null) || (numberStr.length() == 0)) {
return defaultNumber;
}
@@ -1334,7 +1386,7 @@ public class Util {
* Checks if the public method defined on the base type with the given arguments
* are overridden in the given derived type.
*/
- public static boolean isOverridden(Class base, Class derived, String methodName, Class... types) {
+ public static boolean isOverridden(@Nonnull Class base, @Nonnull Class derived, @Nonnull String methodName, @Nonnull Class... types) {
try {
return !base.getMethod(methodName, types).equals(
derived.getMethod(methodName,types));
@@ -1349,7 +1401,8 @@ public class Util {
* @param ext
* For example, ".zip"
*/
- public static File changeExtension(File dst, String ext) {
+ @Nonnull
+ public static File changeExtension(@Nonnull File dst, @Nonnull String ext) {
String p = dst.getPath();
int pos = p.lastIndexOf('.');
if (pos<0) return new File(p+ext);
@@ -1358,8 +1411,10 @@ public class Util {
/**
* Null-safe String intern method.
+ * @return A canonical representation for the string object. Null for null input strings
*/
- public static String intern(String s) {
+ @Nullable
+ public static String intern(@CheckForNull String s) {
return s==null ? s : s.intern();
}
@@ -1370,7 +1425,7 @@ public class Util {
* implementing this by ourselves allow it to be more lenient about
* escaping of URI.
*/
- public static boolean isAbsoluteUri(String uri) {
+ public static boolean isAbsoluteUri(@Nonnull String uri) {
int idx = uri.indexOf(':');
if (idx<0) return false; // no ':'. can't be absolute
@@ -1382,7 +1437,7 @@ public class Util {
* Works like {@link String#indexOf(int)} but 'not found' is returned as s.length(), not -1.
* This enables more straight-forward comparison.
*/
- private static int _indexOf(String s, char ch) {
+ private static int _indexOf(@Nonnull String s, char ch) {
int idx = s.indexOf(ch);
if (idx<0) return s.length();
return idx;
@@ -1392,7 +1447,8 @@ public class Util {
* Loads a key/value pair string as {@link Properties}
* @since 1.392
*/
- public static Properties loadProperties(String properties) throws IOException {
+ @Nonnull
+ public static Properties loadProperties(@Nonnull String properties) throws IOException {
Properties p = new Properties();
p.load(new StringReader(properties));
return p;
diff --git a/core/src/main/java/hudson/cli/InstallToolCommand.java b/core/src/main/java/hudson/cli/InstallToolCommand.java
index fb30efd0c0..f5ad164f95 100644
--- a/core/src/main/java/hudson/cli/InstallToolCommand.java
+++ b/core/src/main/java/hudson/cli/InstallToolCommand.java
@@ -122,6 +122,9 @@ public class InstallToolCommand extends CLICommand {
throw new AbortException(b.getFullDisplayName()+" is not building");
Node node = exec.getOwner().getNode();
+ if (node == null) {
+ throw new AbortException("The node " + exec.getOwner().getDisplayName() + " has been deleted");
+ }
t = t.translate(node, EnvVars.getRemote(checkChannel()), new StreamTaskListener(stderr));
stdout.println(t.getHome());
diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java
index aec68e72ef..14fe40daed 100644
--- a/core/src/main/java/hudson/model/AbstractBuild.java
+++ b/core/src/main/java/hudson/model/AbstractBuild.java
@@ -84,9 +84,11 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
import org.kohsuke.stapler.interceptor.RequirePOST;
import static java.util.logging.Level.WARNING;
+
import jenkins.model.lazy.BuildReference;
import jenkins.model.lazy.LazyBuildMixIn;
@@ -435,9 +437,20 @@ public abstract class AbstractBuild
,R extends Abs
/**
* Returns the current {@link Node} on which we are building.
+ * @return Returns the current {@link Node}
+ * @throws IllegalStateException if that cannot be determined
*/
- protected final Node getCurrentNode() {
- return Executor.currentExecutor().getOwner().getNode();
+ protected final @Nonnull Node getCurrentNode() throws IllegalStateException {
+ Executor exec = Executor.currentExecutor();
+ if (exec == null) {
+ throw new IllegalStateException("not being called from an executor thread");
+ }
+ Computer c = exec.getOwner();
+ Node node = c.getNode();
+ if (node == null) {
+ throw new IllegalStateException("no longer a configured node for " + c.getName());
+ }
+ return node;
}
public Launcher getLauncher() {
@@ -456,7 +469,7 @@ public abstract class AbstractBuild
,R extends Abs
* @param wsl
* Passed in for the convenience. The returned path must be registered to this object.
*/
- protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
+ protected Lease decideWorkspace(@Nonnull Node n, WorkspaceList wsl) throws InterruptedException, IOException {
String customWorkspace = getProject().getCustomWorkspace();
if (customWorkspace != null) {
// we allow custom workspaces to be concurrently used between jobs.
@@ -466,8 +479,9 @@ public abstract class AbstractBuild
,R extends Abs
return wsl.allocate(n.getWorkspaceFor((TopLevelItem)getProject()), getBuild());
}
- public Result run(BuildListener listener) throws Exception {
- Node node = getCurrentNode();
+ public Result run(@Nonnull BuildListener listener) throws Exception {
+ final Node node = getCurrentNode();
+
assert builtOn==null;
builtOn = node.getNodeName();
hudsonVersion = Jenkins.VERSION;
@@ -555,8 +569,10 @@ public abstract class AbstractBuild
,R extends Abs
* @param listener
* Always non-null. Connected to the main build output.
*/
- protected Launcher createLauncher(BuildListener listener) throws IOException, InterruptedException {
- Launcher l = getCurrentNode().createLauncher(listener);
+ @Nonnull
+ protected Launcher createLauncher(@Nonnull BuildListener listener) throws IOException, InterruptedException {
+ final Node currentNode = getCurrentNode();
+ Launcher l = currentNode.createLauncher(listener);
if (project instanceof BuildableItemWithBuildWrappers) {
BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
@@ -580,7 +596,7 @@ public abstract class AbstractBuild
,R extends Abs
}
}
- for (NodeProperty nodeProperty: Computer.currentComputer().getNode().getNodeProperties()) {
+ for (NodeProperty nodeProperty: currentNode.getNodeProperties()) {
Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
if (environment != null) {
buildEnvironments.add(environment);
diff --git a/core/src/main/java/hudson/model/AbstractCIBase.java b/core/src/main/java/hudson/model/AbstractCIBase.java
index 11b1c7cff8..08254d7808 100644
--- a/core/src/main/java/hudson/model/AbstractCIBase.java
+++ b/core/src/main/java/hudson/model/AbstractCIBase.java
@@ -165,9 +165,10 @@ public abstract class AbstractCIBase extends Node implements ItemGroup byName = new HashMap();
for (Computer c : computers.values()) {
- if(c.getNode()==null)
+ Node node = c.getNode();
+ if (node == null)
continue; // this computer is gone
- byName.put(c.getNode().getNodeName(),c);
+ byName.put(node.getNodeName(),c);
}
Set old = new HashSet(computers.values());
diff --git a/core/src/main/java/hudson/model/Api.java b/core/src/main/java/hudson/model/Api.java
index 71b617e46f..ff84f4b66d 100644
--- a/core/src/main/java/hudson/model/Api.java
+++ b/core/src/main/java/hudson/model/Api.java
@@ -154,16 +154,21 @@ public class Api extends AbstractModelObject {
throw new IOException("Failed to do XPath/wrapper handling. Turn on FINER logging to view XML.",e);
}
+
+ if (isSimpleOutput(result) && !permit(req)) {
+ // simple output prohibited
+ rsp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "primitive XPath result sets forbidden; implement jenkins.security.SecureRequester");
+ return;
+ }
+
+ // switch to gzipped output
OutputStream o = rsp.getCompressedOutputStream(req);
try {
- if (result instanceof CharacterData || result instanceof String || result instanceof Number || result instanceof Boolean) {
- if (permit(req)) {
- rsp.setContentType("text/plain;charset=UTF-8");
- String text = result instanceof CharacterData ? ((CharacterData) result).getText() : result.toString();
- o.write(text.getBytes("UTF-8"));
- } else {
- rsp.sendError(HttpURLConnection.HTTP_FORBIDDEN, "primitive XPath result sets forbidden; implement jenkins.security.SecureRequester");
- }
+ if (isSimpleOutput(result)) {
+ // simple output allowed
+ rsp.setContentType("text/plain;charset=UTF-8");
+ String text = result instanceof CharacterData ? ((CharacterData) result).getText() : result.toString();
+ o.write(text.getBytes("UTF-8"));
return;
}
@@ -175,6 +180,10 @@ public class Api extends AbstractModelObject {
}
}
+ private boolean isSimpleOutput(Object result) {
+ return result instanceof CharacterData || result instanceof String || result instanceof Number || result instanceof Boolean;
+ }
+
/**
* Generate schema.
*/
diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java
index 53cbf82af7..99073f1b73 100644
--- a/core/src/main/java/hudson/model/Build.java
+++ b/core/src/main/java/hudson/model/Build.java
@@ -42,6 +42,7 @@ import java.util.logging.Logger;
import java.util.logging.Level;
import static hudson.model.Result.FAILURE;
+import javax.annotation.Nonnull;
/**
* A build of a {@link Project}.
@@ -135,7 +136,7 @@ public abstract class Build
,B extends Build
>
deprecated class here.
*/
- protected Result doRun(BuildListener listener) throws Exception {
+ protected Result doRun(@Nonnull BuildListener listener) throws Exception {
if(!preBuild(listener,project.getBuilders()))
return FAILURE;
if(!preBuild(listener,project.getPublishersList()))
@@ -178,7 +179,7 @@ public abstract class Build
,B extends Build
>
return r;
}
- public void post2(BuildListener listener) throws IOException, InterruptedException {
+ public void post2(@Nonnull BuildListener listener) throws IOException, InterruptedException {
if (!performAllBuildSteps(listener, project.getPublishersList(), true))
setResult(FAILURE);
if (!performAllBuildSteps(listener, project.getProperties(), true))
@@ -186,14 +187,14 @@ public abstract class Build
,B extends Build
>
}
@Override
- public void cleanUp(BuildListener listener) throws Exception {
+ public void cleanUp(@Nonnull BuildListener listener) throws Exception {
// at this point it's too late to mark the build as a failure, so ignore return value.
performAllBuildSteps(listener, project.getPublishersList(), false);
performAllBuildSteps(listener, project.getProperties(), false);
super.cleanUp(listener);
}
- private boolean build(BuildListener listener, Collection steps) throws IOException, InterruptedException {
+ private boolean build(@Nonnull BuildListener listener, @Nonnull Collection steps) throws IOException, InterruptedException {
for( BuildStep bs : steps ) {
if(!perform(bs,listener)) {
LOGGER.log(Level.FINE, "{0} : {1} failed", new Object[] {Build.this, bs});
diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java
index 86fbb6c0ea..33e2721712 100644
--- a/core/src/main/java/hudson/model/Computer.java
+++ b/core/src/main/java/hudson/model/Computer.java
@@ -204,7 +204,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
/**
* This is where the log from the remote agent goes.
- *
+ * The method also creates a log directory if required.
* @see #relocateOldLogs()
*/
protected File getLogFile() {
@@ -1196,7 +1196,11 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
// read
checkPermission(EXTENDED_READ);
rsp.setContentType("application/xml");
- Jenkins.XSTREAM2.toXMLUTF8(getNode(), rsp.getOutputStream());
+ Node node = getNode();
+ if (node == null) {
+ throw HttpResponses.notFound();
+ }
+ Jenkins.XSTREAM2.toXMLUTF8(node, rsp.getOutputStream());
return;
}
if (req.getMethod().equals("POST")) {
@@ -1218,7 +1222,8 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
// replace the old Node object by the new one
synchronized (app) {
List nodes = new ArrayList(app.getNodes());
- int i = nodes.indexOf(getNode());
+ Node node = getNode();
+ int i = (node != null) ? nodes.indexOf(node) : -1;
if(i<0) {
throw new IOException("This slave appears to be removed while you were editing the configuration");
}
@@ -1348,7 +1353,12 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
if (m.matches()) {
File newLocation = new File(dir, "logs/slaves/" + m.group(1) + "/slave.log" + Util.fixNull(m.group(2)));
newLocation.getParentFile().mkdirs();
- f.renameTo(newLocation);
+ boolean relocationSuccessfull=f.renameTo(newLocation);
+ if (relocationSuccessfull) { // The operation will fail if mkdir fails
+ LOGGER.log(Level.INFO, "Relocated log file {0} to {1}",new Object[] {f.getPath(),newLocation.getPath()});
+ } else {
+ LOGGER.log(Level.WARNING, "Cannot relocate log file {0} to {1}",new Object[] {f.getPath(),newLocation.getPath()});
+ }
} else {
assert false;
}
diff --git a/core/src/main/java/hudson/model/Executor.java b/core/src/main/java/hudson/model/Executor.java
index e0cfe64ed7..4353ad7546 100644
--- a/core/src/main/java/hudson/model/Executor.java
+++ b/core/src/main/java/hudson/model/Executor.java
@@ -59,6 +59,7 @@ import java.util.logging.Logger;
import static hudson.model.queue.Executables.*;
import static java.util.logging.Level.*;
import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
/**
@@ -70,7 +71,7 @@ import javax.annotation.CheckForNull;
*/
@ExportedBean
public class Executor extends Thread implements ModelObject {
- protected final Computer owner;
+ protected final @Nonnull Computer owner;
private final Queue queue;
private long startTime;
@@ -111,7 +112,7 @@ public class Executor extends Thread implements ModelObject {
*/
private final List causes = new Vector();
- public Executor(Computer owner, int n) {
+ public Executor(@Nonnull Computer owner, int n) {
super("Executor #"+n+" for "+owner.getDisplayName());
this.owner = owner;
this.queue = Jenkins.getInstance().getQueue();
@@ -534,7 +535,7 @@ public class Executor extends Thread implements ModelObject {
return e!=null && Tasks.getOwnerTaskOf(getParentOf(e)).hasAbortPermission();
}
- public Computer getOwner() {
+ public @Nonnull Computer getOwner() {
return owner;
}
diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java
index fe9fbe0841..e78b2cd5e8 100644
--- a/core/src/main/java/hudson/model/Node.java
+++ b/core/src/main/java/hudson/model/Node.java
@@ -202,7 +202,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
// At startup, we need to restore any previously in-effect temp offline cause.
// We wait until the computer is started rather than getting the data to it sooner
// so that the normal computer start up processing works as expected.
- if (node.temporaryOfflineCause != null && node.temporaryOfflineCause != c.getOfflineCause()) {
+ if (node!= null && node.temporaryOfflineCause != null && node.temporaryOfflineCause != c.getOfflineCause()) {
c.setTemporarilyOffline(true, node.temporaryOfflineCause);
}
}
diff --git a/core/src/main/java/hudson/model/Queue.java b/core/src/main/java/hudson/model/Queue.java
index 518be29e47..c1e4bfa0c8 100644
--- a/core/src/main/java/hudson/model/Queue.java
+++ b/core/src/main/java/hudson/model/Queue.java
@@ -283,6 +283,7 @@ public class Queue extends ResourceController implements Saveable {
return workUnit == null && !executor.getOwner().isOffline() && executor.getOwner().isAcceptingTasks();
}
+ @CheckForNull
public Node getNode() {
return executor.getOwner().getNode();
}
@@ -739,6 +740,8 @@ public class Queue extends ResourceController implements Saveable {
private void _getBuildableItems(Computer c, ItemList col, List result) {
Node node = c.getNode();
+ if (node == null) // Deleted computers cannot take build items...
+ return;
for (BuildableItem p : col.values()) {
if (node.canTake(p) == null)
result.add(p);
diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java
index ee4cd8f56b..bb3873ecbf 100644
--- a/core/src/main/java/hudson/model/Run.java
+++ b/core/src/main/java/hudson/model/Run.java
@@ -111,6 +111,7 @@ import jenkins.model.lazy.BuildReference;
import jenkins.util.VirtualFile;
import jenkins.util.io.OnMaster;
import net.sf.json.JSONObject;
+import org.acegisecurity.AccessDeniedException;
import org.acegisecurity.Authentication;
import org.apache.commons.io.IOUtils;
import org.apache.commons.jelly.XMLOutput;
@@ -136,7 +137,7 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
public abstract class Run ,RunT extends Run>
extends Actionable implements ExtensionPoint, Comparable, AccessControlled, PersistenceRoot, DescriptorByNameOwner, OnMaster {
- protected transient final JobT project;
+ protected transient final @Nonnull JobT project;
/**
* Build number.
@@ -278,8 +279,9 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run getTransientActions() {
List actions = new ArrayList();
for (TransientBuildActionFactory factory: TransientBuildActionFactory.all()) {
- actions.addAll(factory.createFor(this));
- assert !actions.contains(null) : "null action added by " + factory;
+ for (Action created : factory.createFor(this)) {
+ if (created == null) {
+ LOGGER.log(WARNING, "null action added by {0}", factory);
+ continue;
+ }
+ actions.add(created);
+ }
}
return Collections.unmodifiableList(actions);
}
@@ -369,7 +376,7 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run getBadgeActions() {
+ public @Nonnull List getBadgeActions() {
List r = getActions(BuildBadgeAction.class);
if(isKeepLog()) {
r.add(new KeepLogBuildBadge());
@@ -508,7 +516,7 @@ public abstract class Run ,RunT extends Run,RunT extends Run
* If a build sits in the queue for a long time, multiple build requests made during this period
@@ -539,7 +547,7 @@ public abstract class Run ,RunT extends Run getCauses() {
+ public @Nonnull List getCauses() {
CauseAction a = getAction(CauseAction.class);
if (a==null) return Collections.emptyList();
return Collections.unmodifiableList(a.getCauses());
@@ -549,8 +557,8 @@ public abstract class Run ,RunT extends Run T getCause(Class type) {
+ */
+ public @CheckForNull T getCause(Class type) {
for (Cause c : getCauses())
if (type.isInstance(c))
return type.cast(c);
@@ -570,8 +578,8 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run createReference() {
+ */
+ protected @Nonnull BuildReference createReference() {
return new BuildReference(getId(), _this());
}
@@ -798,15 +807,15 @@ public abstract class Run ,RunT extends Run,RunT extends Run
* We basically follow the existing skip list, and wherever we find a non-optimal pointer, we remember them
* in 'fixUp' and update them later.
- */
- public final RunT getPreviousBuildInProgress() {
+ */
+ public final @CheckForNull RunT getPreviousBuildInProgress() {
if(previousBuildInProgress==this) return null; // the most common case
List fixUp = new ArrayList();
@@ -856,8 +865,8 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run getPreviousBuildsOverThreshold(int numberOfBuilds, Result threshold) {
+ */
+ public @Nonnull List getPreviousBuildsOverThreshold(int numberOfBuilds, @Nonnull Result threshold) {
List builds = new ArrayList(numberOfBuilds);
RunT r = getPreviousBuild();
@@ -923,8 +932,8 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run getArtifacts() {
+ * @return The list can be empty but never null
+ */
+ @Exported
+ public @Nonnull List getArtifacts() {
return getArtifactsUpTo(Integer.MAX_VALUE);
}
/**
* Gets the first N artifacts.
- */
- public List getArtifactsUpTo(int n) {
+ * @return The list can be empty but never null
+ */
+ public @Nonnull List getArtifactsUpTo(int artifactsNumber) {
ArtifactList r = new ArtifactList();
try {
- addArtifacts(getArtifactManager().root(), "", "", r, null, n);
+ addArtifacts(getArtifactManager().root(), "", "", r, null, artifactsNumber);
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
@@ -1074,16 +1087,17 @@ public abstract class Run ,RunT extends Run
+ * Check if the {@link Run} contains artifacts.
* The strange method name is so that we can access it from EL.
+ * @return true if this run has any artifacts
*/
public boolean getHasArtifacts() {
return !getArtifactsUpTo(1).isEmpty();
}
- private int addArtifacts(VirtualFile dir, String path, String pathHref, ArtifactList r, Artifact parent, int upTo) throws IOException {
+ private int addArtifacts(@Nonnull VirtualFile dir,
+ @Nonnull String path, @Nonnull String pathHref,
+ @Nonnull ArtifactList r, @Nonnull Artifact parent, int upTo) throws IOException {
VirtualFile[] kids = dir.list();
Arrays.sort(kids);
@@ -1267,7 +1281,7 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run
+ * The method does not close the {@link OutputStream}.
*/
- public void writeWholeLogTo(OutputStream out) throws IOException, InterruptedException {
+ public void writeWholeLogTo(@Nonnull OutputStream out) throws IOException, InterruptedException {
long pos = 0;
AnnotatedLargeText logText;
logText = getLogText();
@@ -1396,13 +1414,14 @@ public abstract class Run ,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run,RunT extends Run getAttributes() {
+ public @Nonnull Map