mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 04:22:16 +00:00
Merge REMERGE_HEAD into HEAD
This commit is contained in:
commit
8b2d70f60b
19 files changed
+526
-65
No files matched your search
@@ -48,7 +48,10 @@ import com.thoughtworks.xstream.XStream;
|
||||
* Base class of Hudson plugin.
|
||||
*
|
||||
* <p>
|
||||
* A plugin needs to derive from this class.
|
||||
* A plugin may derive from this class, or it may directly define extension
|
||||
* points annotated with {@link hudson.Extension}. For a list of extension
|
||||
* points, see <a href="https://wiki.jenkins-ci.org/display/JENKINS/Extension+points">
|
||||
* https://wiki.jenkins-ci.org/display/JENKINS/Extension+points</a>.
|
||||
*
|
||||
* <p>
|
||||
* One instance of a plugin is created by Hudson, and used as the entry point
|
||||
|
||||
@@ -233,7 +233,7 @@ public abstract class LoadStatistics {
|
||||
int q=0;
|
||||
for (Queue.BuildableItem bi : bis) {
|
||||
for (SubTask st : Tasks.getSubTasksOf(bi.task))
|
||||
if (st.getAssignedLabel()==l)
|
||||
if (bi.getAssignedLabelFor(st)==l)
|
||||
q++;
|
||||
}
|
||||
return q;
|
||||
|
||||
@@ -834,11 +834,11 @@ public class Queue extends ResourceController implements Saveable {
|
||||
int r = 0;
|
||||
for (BuildableItem bi : buildables.values())
|
||||
for (SubTask st : bi.task.getSubTasks())
|
||||
if (null==l || st.getAssignedLabel()==l)
|
||||
if (null==l || bi.getAssignedLabelFor(st)==l)
|
||||
r++;
|
||||
for (BuildableItem bi : pendings.values())
|
||||
for (SubTask st : bi.task.getSubTasks())
|
||||
if (null==l || st.getAssignedLabel()==l)
|
||||
if (null==l || bi.getAssignedLabelFor(st)==l)
|
||||
r++;
|
||||
return r;
|
||||
}
|
||||
@@ -1414,6 +1414,21 @@ public class Queue extends ResourceController implements Saveable {
|
||||
}
|
||||
return task.getAssignedLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the specified {@link SubTask} needs to be run on a node with a particular label, and
|
||||
* return that {@link Label}. Otherwise null, indicating it can run on anywhere.
|
||||
*
|
||||
* <p>
|
||||
* This code takes {@link LabelAssignmentAction} into account, then falls back to {@link SubTask#getAssignedLabel()}
|
||||
*/
|
||||
public Label getAssignedLabelFor(SubTask st) {
|
||||
for (LabelAssignmentAction laa : getActions(LabelAssignmentAction.class)) {
|
||||
Label l = laa.getAssignedLabel(st);
|
||||
if (l!=null) return l;
|
||||
}
|
||||
return st.getAssignedLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that returns a read only view of the {@link Cause}s associated with this item in the queue.
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.util.Collections;
|
||||
* with the {@link LabelAtom} object.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @see hudson.model.labels.LabelAtomPropertyDescriptor
|
||||
* @since 1.373
|
||||
*/
|
||||
@ExportedBean
|
||||
|
||||
@@ -31,6 +31,11 @@ import hudson.model.Descriptor;
|
||||
*
|
||||
* <p>
|
||||
* Put {@link Extension} on your descriptor implementation to have it auto-registered.
|
||||
*
|
||||
* <p>
|
||||
* When extending this class, override <code>Descriptor.getDisplayName()</code>. In the
|
||||
* context of LabelAtomPropertyDescriptor, this function is used to determine the label of
|
||||
* the checkbox shown in the label's configuration page to activate the extension.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @since 1.373
|
||||
|
||||
@@ -26,9 +26,11 @@ package hudson.tasks;
|
||||
import hudson.FilePath;
|
||||
import hudson.Extension;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.util.LineEndingConversion;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import java.io.ObjectStreamException;
|
||||
|
||||
/**
|
||||
* Executes commands by using Windows batch file.
|
||||
@@ -38,7 +40,7 @@ import org.kohsuke.stapler.StaplerRequest;
|
||||
public class BatchFile extends CommandInterpreter {
|
||||
@DataBoundConstructor
|
||||
public BatchFile(String command) {
|
||||
super(command);
|
||||
super(LineEndingConversion.convertEOL(command, LineEndingConversion.EOLType.Windows));
|
||||
}
|
||||
|
||||
public String[] buildCommandLine(FilePath script) {
|
||||
@@ -46,13 +48,17 @@ public class BatchFile extends CommandInterpreter {
|
||||
}
|
||||
|
||||
protected String getContents() {
|
||||
return command+"\r\nexit %ERRORLEVEL%";
|
||||
return LineEndingConversion.convertEOL(command+"\r\nexit %ERRORLEVEL%",LineEndingConversion.EOLType.Windows);
|
||||
}
|
||||
|
||||
protected String getFileExtension() {
|
||||
return ".bat";
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
return new BatchFile(command);
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,8 @@ import hudson.remoting.Callable;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.util.FormValidation;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectStreamException;
|
||||
import hudson.util.LineEndingConversion;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
@@ -50,29 +52,7 @@ import java.util.logging.Logger;
|
||||
public class Shell extends CommandInterpreter {
|
||||
@DataBoundConstructor
|
||||
public Shell(String command) {
|
||||
super(fixCrLf(command));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix CR/LF and always make it Unix style.
|
||||
*/
|
||||
private static String fixCrLf(String s) {
|
||||
// eliminate CR
|
||||
int idx;
|
||||
while((idx=s.indexOf("\r\n"))!=-1)
|
||||
s = s.substring(0,idx)+s.substring(idx+1);
|
||||
|
||||
//// add CR back if this is for Windows
|
||||
//if(isWindows()) {
|
||||
// idx=0;
|
||||
// while(true) {
|
||||
// idx = s.indexOf('\n',idx);
|
||||
// if(idx==-1) break;
|
||||
// s = s.substring(0,idx)+'\r'+s.substring(idx);
|
||||
// idx+=2;
|
||||
// }
|
||||
//}
|
||||
return s;
|
||||
super(LineEndingConversion.convertEOL(command, LineEndingConversion.EOLType.Unix));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +60,7 @@ public class Shell extends CommandInterpreter {
|
||||
* makes the shell think the file is a binary file and not a script. Adding
|
||||
* a leading line feed works around this problem.
|
||||
*/
|
||||
private static String addCrForNonASCII(String s) {
|
||||
private static String addLineFeedForNonASCII(String s) {
|
||||
if(!s.startsWith("#!")) {
|
||||
if (s.indexOf('\n')!=0) {
|
||||
return "\n" + s;
|
||||
@@ -105,7 +85,7 @@ public class Shell extends CommandInterpreter {
|
||||
}
|
||||
|
||||
protected String getContents() {
|
||||
return addCrForNonASCII(fixCrLf(command));
|
||||
return addLineFeedForNonASCII(LineEndingConversion.convertEOL(command,LineEndingConversion.EOLType.Unix));
|
||||
}
|
||||
|
||||
protected String getFileExtension() {
|
||||
@@ -117,6 +97,10 @@ public class Shell extends CommandInterpreter {
|
||||
return (DescriptorImpl)super.getDescriptor();
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
return new Shell(command);
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends BuildStepDescriptor<Builder> {
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class AbstractCommandInstaller extends ToolInstaller {
|
||||
|
||||
public AbstractCommandInstaller(String label, String command, String toolHome) {
|
||||
super(label);
|
||||
this.command = fixCrLf(command);
|
||||
this.command = command;
|
||||
this.toolHome = toolHome;
|
||||
}
|
||||
|
||||
@@ -84,19 +84,6 @@ public abstract class AbstractCommandInstaller extends ToolInstaller {
|
||||
return dir.child(getToolHome());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix CR/LF and always make it Unix style.
|
||||
*/
|
||||
//TODO: replace by a Windows style
|
||||
private static String fixCrLf(String s) {
|
||||
// eliminate CR
|
||||
int idx;
|
||||
while ((idx = s.indexOf("\r\n")) != -1) {
|
||||
s = s.substring(0, idx) + s.substring(idx + 1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static abstract class Descriptor<TInstallerClass extends AbstractCommandInstaller>
|
||||
extends ToolInstallerDescriptor<TInstallerClass> {
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ package hudson.tools;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.FilePath;
|
||||
import hudson.util.LineEndingConversion;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import java.io.ObjectStreamException;
|
||||
|
||||
/**
|
||||
* Installs tool via script execution of Batch script.
|
||||
@@ -37,7 +39,7 @@ public class BatchCommandInstaller extends AbstractCommandInstaller {
|
||||
|
||||
@DataBoundConstructor
|
||||
public BatchCommandInstaller(String label, String command, String toolHome) {
|
||||
super(label, command, toolHome);
|
||||
super(label, LineEndingConversion.convertEOL(command, LineEndingConversion.EOLType.Windows), toolHome);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,6 +52,10 @@ public class BatchCommandInstaller extends AbstractCommandInstaller {
|
||||
String[] cmd = {"cmd", "/c", "call", script.getRemote()};
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
return new BatchCommandInstaller(getLabel(), getCommand(), getToolHome());
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<BatchCommandInstaller> {
|
||||
|
||||
@@ -26,7 +26,9 @@ package hudson.tools;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.FilePath;
|
||||
import hudson.util.LineEndingConversion;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import java.io.ObjectStreamException;
|
||||
|
||||
/**
|
||||
* Installs a tool by running an arbitrary shell command.
|
||||
@@ -36,7 +38,7 @@ public class CommandInstaller extends AbstractCommandInstaller {
|
||||
|
||||
@DataBoundConstructor
|
||||
public CommandInstaller(String label, String command, String toolHome) {
|
||||
super(label, command, toolHome);
|
||||
super(label, LineEndingConversion.convertEOL(command, LineEndingConversion.EOLType.Unix), toolHome);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,6 +52,10 @@ public class CommandInstaller extends AbstractCommandInstaller {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
return new CommandInstaller(getLabel(), getCommand(), getToolHome());
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends Descriptor<CommandInstaller> {
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package hudson.util;
|
||||
|
||||
/**
|
||||
* Converts line endings of a string.
|
||||
*
|
||||
* @since TODO
|
||||
* @author David Ruhmann
|
||||
*/
|
||||
public class LineEndingConversion {
|
||||
|
||||
/**
|
||||
* Supported line ending types for conversion
|
||||
*/
|
||||
public enum EOLType {
|
||||
CR,
|
||||
CRLF,
|
||||
LF,
|
||||
LFCR,
|
||||
Mac,
|
||||
Unix,
|
||||
Windows
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert line endings of a string to the given type. Default to Unix type.
|
||||
*
|
||||
* @param input
|
||||
* The string containing line endings to be converted.
|
||||
* @param type
|
||||
* Type of line endings to convert the string into.
|
||||
* @return
|
||||
* String updated with the new line endings or null if given null.
|
||||
*/
|
||||
public static String convertEOL(String input, EOLType type) {
|
||||
if (null == input || 0 == input.length()) {
|
||||
return input;
|
||||
}
|
||||
// Convert line endings to Unix LF,
|
||||
// which also sets up the string for other conversions
|
||||
input = input.replace("\r\n","\n");
|
||||
input = input.replace("\r","\n");
|
||||
switch (type) {
|
||||
case CR:
|
||||
case Mac:
|
||||
// Convert line endings to CR
|
||||
input = input.replace("\n", "\r");
|
||||
break;
|
||||
case CRLF:
|
||||
case Windows:
|
||||
// Convert line endings to Windows CR/LF
|
||||
input = input.replace("\n", "\r\n");
|
||||
break;
|
||||
default:
|
||||
case LF:
|
||||
case Unix:
|
||||
// Conversion already completed
|
||||
return input;
|
||||
case LFCR:
|
||||
// Convert line endings to LF/CR
|
||||
input = input.replace("\n", "\n\r");
|
||||
break;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,28 @@ import hudson.model.Describable;
|
||||
import hudson.model.Descriptor;
|
||||
|
||||
/**
|
||||
* Convenient base class for extensions that contributes to the system configuration page but nothing else.
|
||||
* Convenient base class for extensions that contributes to the system configuration page but nothing
|
||||
* else, or to manage the global configuration of a plugin implementing several extension points.
|
||||
*
|
||||
* <p>
|
||||
* All {@link Descriptor}s are capable of contributing fragment to the system config page, so
|
||||
* this extension point is is really only for those who don't want to contribute anything else.
|
||||
* If you are implementing other extension points and that would like to expose some global configuration,
|
||||
* you can do so with <tt>global.groovy</tt> from your {@link Descriptor} instance.
|
||||
* All {@link Descriptor}s are capable of contributing fragment to the system config page. If you are
|
||||
* implementing other extension points that need to expose some global configuration, you can do so
|
||||
* with <tt>global.groovy</tt> or <tt>global.jelly</tt> from your {@link Descriptor} instance. However
|
||||
* each <tt>global.*</tt> file will appear as its own section in the global configuration page.
|
||||
*
|
||||
* <p>
|
||||
* An option to present a single section for your plugin in the Jenkins global configuration page is
|
||||
* to use this class to manage the configuration for your plugin and its extension points. To access
|
||||
* properties defined in your GlobalConfiguration subclass, here are two possibilities:
|
||||
* <ul><li>@{@link javax.inject.Inject} into your other {@link hudson.Extension}s (so this does <i>not</i> work
|
||||
* for classes not annotated with {@link hudson.Extension})</li>
|
||||
* <li>access it via a call to <code>GlobalConfiguration.all().get(<your GlobalConfiguration subclass>.class)
|
||||
* </code></li></ul>
|
||||
*
|
||||
* <h2>Views</h2>
|
||||
* <p>
|
||||
* Subtypes of this class should define <tt>config.groovy</tt> that gets pulled into the system configuration page.
|
||||
* Subtypes of this class should define a <tt>config.groovy</tt> file or <tt>config.jelly</tt> file
|
||||
* that gets pulled into the system configuration page.
|
||||
*
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
|
||||
Reference in new issue
Block a user