| author | Henrik Lynggaard Hansen | 2012-07-11 14:58:24 (EDT) |
|---|---|---|
| committer | Henrik Lynggaard Hansen | 2012-07-11 14:58:24 (EDT) |
| commit | 456f959c01b48494465dd6f8d84cf27ef41786d5 (patch) (side-by-side diff) | |
| tree | b4db5f48506df4d567f3f5257987a25de0752604 | |
| parent | 6b2a021db07f935226235132973fb64223c07d91 (diff) | |
| download | org.eclipse.hudson.core-456f959c01b48494465dd6f8d84cf27ef41786d5.zip org.eclipse.hudson.core-456f959c01b48494465dd6f8d84cf27ef41786d5.tar.gz org.eclipse.hudson.core-456f959c01b48494465dd6f8d84cf27ef41786d5.tar.bz2 | |
Reformat of the subpackages of hudson.modelrefs/changes/19/6719/1
Change-Id: Ib832d06d6f8e8c84da65ca33d4fdead55f077ad1
Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
32 files changed, 687 insertions, 564 deletions
diff --git a/hudson-core/src/main/java/hudson/model/labels/LabelAtom.java b/hudson-core/src/main/java/hudson/model/labels/LabelAtom.java index cb17457..471d069 100644 --- a/hudson-core/src/main/java/hudson/model/labels/LabelAtom.java +++ b/hudson-core/src/main/java/hudson/model/labels/LabelAtom.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -49,14 +49,14 @@ import java.util.logging.Logger; /** * Atomic single token label, like "foo" or "bar". - * + * * @author Kohsuke Kawaguchi - * @since 1.372 + * @since 1.372 */ public class LabelAtom extends Label implements Saveable { - private DescribableList<LabelAtomProperty,LabelAtomPropertyDescriptor> properties = - new DescribableList<LabelAtomProperty,LabelAtomPropertyDescriptor>(this); + private DescribableList<LabelAtomProperty, LabelAtomPropertyDescriptor> properties = + new DescribableList<LabelAtomProperty, LabelAtomPropertyDescriptor>(this); @CopyOnWrite protected transient volatile List<Action> transientActions = new Vector<Action>(); @@ -75,10 +75,9 @@ public class LabelAtom extends Label implements Saveable { /** * {@inheritDoc} * - * <p> - * Note that this method returns a read-only view of {@link Action}s. - * {@link LabelAtomProperty}s who want to add a project action - * should do so by implementing {@link LabelAtomProperty#getActions(LabelAtom)}. + * <p> Note that this method returns a read-only view of {@link Action}s. + * {@link LabelAtomProperty}s who want to add a project action should do so + * by implementing {@link LabelAtomProperty#getActions(LabelAtom)}. */ @Override public synchronized List<Action> getActions() { @@ -97,10 +96,11 @@ public class LabelAtom extends Label implements Saveable { // if there's no property descriptor, there's nothing interesting to configure. ta.add(new Action() { public String getIconFileName() { - if (Hudson.getInstance().hasPermission(Hudson.ADMINISTER)) + if (Hudson.getInstance().hasPermission(Hudson.ADMINISTER)) { return "setting.png"; - else + } else { return null; + } } public String getDisplayName() { @@ -113,8 +113,9 @@ public class LabelAtom extends Label implements Saveable { }); } - for (LabelAtomProperty p : properties) + for (LabelAtomProperty p : properties) { ta.addAll(p.getActions(this)); + } transientActions = ta; } @@ -142,26 +143,28 @@ public class LabelAtom extends Label implements Saveable { } /*package*/ XmlFile getConfigFile() { - return new XmlFile(XSTREAM, new File(Hudson.getInstance().root, "labels/"+name+".xml")); + return new XmlFile(XSTREAM, new File(Hudson.getInstance().root, "labels/" + name + ".xml")); } public void save() throws IOException { - if(BulkChange.contains(this)) return; + if (BulkChange.contains(this)) { + return; + } try { getConfigFile().write(this); SaveableListener.fireOnChange(this, getConfigFile()); } catch (IOException e) { - LOGGER.log(Level.WARNING, "Failed to save "+getConfigFile(),e); + LOGGER.log(Level.WARNING, "Failed to save " + getConfigFile(), e); } } public void load() { XmlFile file = getConfigFile(); - if(file.exists()) { + if (file.exists()) { try { file.unmarshal(this); } catch (IOException e) { - LOGGER.log(Level.WARNING, "Failed to load "+file, e); + LOGGER.log(Level.WARNING, "Failed to load " + file, e); } } properties.setOwner(this); @@ -169,8 +172,8 @@ public class LabelAtom extends Label implements Saveable { } /** - * Returns all the {@link LabelAtomPropertyDescriptor}s that can be potentially configured - * on this label. + * Returns all the {@link LabelAtomPropertyDescriptor}s that can be + * potentially configured on this label. */ public List<LabelAtomPropertyDescriptor> getApplicablePropertyDescriptors() { return LabelAtomProperty.all(); @@ -179,7 +182,7 @@ public class LabelAtom extends Label implements Saveable { /** * Accepts the update to the node configuration. */ - public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException { + public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { final Hudson app = Hudson.getInstance(); app.checkPermission(Hudson.ADMINISTER); @@ -203,10 +206,11 @@ public class LabelAtom extends Label implements Saveable { try { Hudson.checkGoodName(name); // additional restricted chars - for( int i=0; i<name.length(); i++ ) { + for (int i = 0; i < name.length(); i++) { char ch = name.charAt(i); - if(" ()\t\n".indexOf(ch)!=-1) + if (" ()\t\n".indexOf(ch) != -1) { return true; + } } return false; } catch (Failure failure) { @@ -215,13 +219,12 @@ public class LabelAtom extends Label implements Saveable { } public static String escape(String name) { - if (needsEscape(name)) + if (needsEscape(name)) { return QuotedStringTokenizer.quote(name); + } return name; } - private static final Logger LOGGER = Logger.getLogger(LabelAtom.class.getName()); - private static final XStream2 XSTREAM = new XStream2(); static { @@ -231,6 +234,7 @@ public class LabelAtom extends Label implements Saveable { // class name is not ConverterImpl, to avoid getting picked up by AssociatedConverterImpl private static class LabelAtomConverter extends XStream2.PassthruConverter<LabelAtom> { + private Label.ConverterImpl leafLabelConverter = new Label.ConverterImpl(); private LabelAtomConverter() { @@ -242,34 +246,35 @@ public class LabelAtom extends Label implements Saveable { } public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { - if (context.get(IN_NESTED)==null) { - context.put(IN_NESTED,true); + if (context.get(IN_NESTED) == null) { + context.put(IN_NESTED, true); try { - super.marshal(source,writer,context); + super.marshal(source, writer, context); } finally { - context.put(IN_NESTED,false); + context.put(IN_NESTED, false); } - } else - leafLabelConverter.marshal(source,writer,context); + } else { + leafLabelConverter.marshal(source, writer, context); + } } public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { - if (context.get(IN_NESTED)==null) { - context.put(IN_NESTED,true); + if (context.get(IN_NESTED) == null) { + context.put(IN_NESTED, true); try { - return super.unmarshal(reader,context); + return super.unmarshal(reader, context); } finally { - context.put(IN_NESTED,false); + context.put(IN_NESTED, false); } - } else - return leafLabelConverter.unmarshal(reader,context); + } else { + return leafLabelConverter.unmarshal(reader, context); + } } @Override protected void callback(LabelAtom obj, UnmarshallingContext context) { // noop } - private static final Object IN_NESTED = "VisitingInnerLabelAtom"; } } diff --git a/hudson-core/src/main/java/hudson/model/labels/LabelAtomProperty.java b/hudson-core/src/main/java/hudson/model/labels/LabelAtomProperty.java index 0d39b29..52e53cc 100644 --- a/hudson-core/src/main/java/hudson/model/labels/LabelAtomProperty.java +++ b/hudson-core/src/main/java/hudson/model/labels/LabelAtomProperty.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -29,30 +29,32 @@ import java.util.Collections; /** * Extensible property of {@link LabelAtom}. * - * <p> - * Plugins can contribute this extension point to add additional data or UI actions to {@link LabelAtom}. - * {@link LabelAtomProperty}s show up in the configuration screen of a label, and they are persisted - * with the {@link LabelAtom} object. + * <p> Plugins can contribute this extension point to add additional data or UI + * actions to {@link LabelAtom}. {@link LabelAtomProperty}s show up in the + * configuration screen of a label, and they are persisted with the + * {@link LabelAtom} object. * * @author Kohsuke Kawaguchi * @since 1.373 */ @ExportedBean public class LabelAtomProperty extends AbstractDescribableImpl<LabelAtomProperty> implements ExtensionPoint { + /** * Contributes {@link Action}s to the label. * - * This allows properties to create additional links in the left navigation bar and - * hook into the URL space of the label atom. + * This allows properties to create additional links in the left navigation + * bar and hook into the URL space of the label atom. */ public Collection<? extends Action> getActions(LabelAtom atom) { return Collections.emptyList(); } /** - * Lists up all the registered {@link LabelAtomPropertyDescriptor}s in the system. + * Lists up all the registered {@link LabelAtomPropertyDescriptor}s in the + * system. */ - public static DescriptorExtensionList<LabelAtomProperty,LabelAtomPropertyDescriptor> all() { - return Hudson.getInstance().<LabelAtomProperty,LabelAtomPropertyDescriptor>getDescriptorList(LabelAtomProperty.class); + public static DescriptorExtensionList<LabelAtomProperty, LabelAtomPropertyDescriptor> all() { + return Hudson.getInstance().<LabelAtomProperty, LabelAtomPropertyDescriptor>getDescriptorList(LabelAtomProperty.class); } } diff --git a/hudson-core/src/main/java/hudson/model/labels/LabelAtomPropertyDescriptor.java b/hudson-core/src/main/java/hudson/model/labels/LabelAtomPropertyDescriptor.java index 116214e..8812490 100644 --- a/hudson-core/src/main/java/hudson/model/labels/LabelAtomPropertyDescriptor.java +++ b/hudson-core/src/main/java/hudson/model/labels/LabelAtomPropertyDescriptor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -22,12 +22,11 @@ import hudson.model.Descriptor; /** * {@link Descriptor} for {@link LabelAtom}. * - * <p> - * Put {@link Extension} on your descriptor implementation to have it auto-registered. + * <p> Put {@link Extension} on your descriptor implementation to have it + * auto-registered. * * @author Kohsuke Kawaguchi * @since 1.373 */ public abstract class LabelAtomPropertyDescriptor extends Descriptor<LabelAtomProperty> { - } diff --git a/hudson-core/src/main/java/hudson/model/labels/LabelExpression.java b/hudson-core/src/main/java/hudson/model/labels/LabelExpression.java index 267b1bd..ad653b4 100644 --- a/hudson-core/src/main/java/hudson/model/labels/LabelExpression.java +++ b/hudson-core/src/main/java/hudson/model/labels/LabelExpression.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -21,11 +21,12 @@ import hudson.util.VariableResolver; /** * Boolean expression of labels. - * + * * @author Kohsuke Kawaguchi - * @since 1.372 + * @since 1.372 */ public abstract class LabelExpression extends Label { + protected LabelExpression(String name) { super(name); } @@ -36,10 +37,11 @@ public abstract class LabelExpression extends Label { } public static class Not extends LabelExpression { + private final Label base; public Not(Label base) { - super('!'+paren(LabelOperatorPrecedence.NOT,base)); + super('!' + paren(LabelOperatorPrecedence.NOT, base)); this.base = base; } @@ -58,10 +60,11 @@ public abstract class LabelExpression extends Label { * No-op but useful for preserving the parenthesis in the user input. */ public static class Paren extends LabelExpression { + private final Label base; public Paren(Label base) { - super('('+base.getExpression()+')'); + super('(' + base.getExpression() + ')'); this.base = base; } @@ -77,16 +80,19 @@ public abstract class LabelExpression extends Label { } /** - * Puts the label name into a parenthesis if the given operator will have a higher precedence. + * Puts the label name into a parenthesis if the given operator will have a + * higher precedence. */ static String paren(LabelOperatorPrecedence op, Label l) { - if (op.compareTo(l.precedence())<0) - return '('+l.getExpression()+')'; + if (op.compareTo(l.precedence()) < 0) { + return '(' + l.getExpression() + ')'; + } return l.getExpression(); } public static abstract class Binary extends LabelExpression { - private final Label lhs,rhs; + + private final Label lhs, rhs; public Binary(Label lhs, Label rhs, LabelOperatorPrecedence op) { super(combine(lhs, rhs, op)); @@ -95,7 +101,7 @@ public abstract class LabelExpression extends Label { } private static String combine(Label lhs, Label rhs, LabelOperatorPrecedence op) { - return paren(op,lhs)+op.str+paren(op,rhs); + return paren(op, lhs) + op.str + paren(op, rhs); } /** @@ -104,13 +110,14 @@ public abstract class LabelExpression extends Label { */ @Override public boolean matches(VariableResolver<Boolean> resolver) { - return op(lhs.matches(resolver),rhs.matches(resolver)); + return op(lhs.matches(resolver), rhs.matches(resolver)); } protected abstract boolean op(boolean a, boolean b); } public static final class And extends Binary { + public And(Label lhs, Label rhs) { super(lhs, rhs, LabelOperatorPrecedence.AND); } @@ -127,6 +134,7 @@ public abstract class LabelExpression extends Label { } public static final class Or extends Binary { + public Or(Label lhs, Label rhs) { super(lhs, rhs, LabelOperatorPrecedence.OR); } @@ -143,6 +151,7 @@ public abstract class LabelExpression extends Label { } public static final class Iff extends Binary { + public Iff(Label lhs, Label rhs) { super(lhs, rhs, LabelOperatorPrecedence.IFF); } @@ -159,6 +168,7 @@ public abstract class LabelExpression extends Label { } public static final class Implies extends Binary { + public Implies(Label lhs, Label rhs) { super(lhs, rhs, LabelOperatorPrecedence.IMPLIES); } diff --git a/hudson-core/src/main/java/hudson/model/labels/LabelOperatorPrecedence.java b/hudson-core/src/main/java/hudson/model/labels/LabelOperatorPrecedence.java index 76a4f45..5d7f728 100644 --- a/hudson-core/src/main/java/hudson/model/labels/LabelOperatorPrecedence.java +++ b/hudson-core/src/main/java/hudson/model/labels/LabelOperatorPrecedence.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -23,8 +23,8 @@ package hudson.model.labels; * @since 1.372 */ public enum LabelOperatorPrecedence { - ATOM(null), NOT("!"), AND("&&"), OR("||"), IMPLIES("->"), IFF("<->"); + ATOM(null), NOT("!"), AND("&&"), OR("||"), IMPLIES("->"), IFF("<->"); /** * String representation of this operator. */ diff --git a/hudson-core/src/main/java/hudson/model/labels/package-info.java b/hudson-core/src/main/java/hudson/model/labels/package-info.java index c5e34d5..bf0a163 100644 --- a/hudson-core/src/main/java/hudson/model/labels/package-info.java +++ b/hudson-core/src/main/java/hudson/model/labels/package-info.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ /** diff --git a/hudson-core/src/main/java/hudson/model/listeners/ItemListener.java b/hudson-core/src/main/java/hudson/model/listeners/ItemListener.java index 26638d0..fc572e9 100644 --- a/hudson-core/src/main/java/hudson/model/listeners/ItemListener.java +++ b/hudson-core/src/main/java/hudson/model/listeners/ItemListener.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi - * + * Contributors: + * + * Kohsuke Kawaguchi + * * *******************************************************************************/ @@ -29,12 +29,12 @@ import hudson.model.Item; * @author Kohsuke Kawaguchi */ public class ItemListener implements ExtensionPoint { + /** - * Called after a new job is created and added to {@link Hudson}, - * before the initial configuration page is provided. - * <p> - * This is useful for changing the default initial configuration of newly created jobs. - * For example, you can enable/add builders, etc. + * Called after a new job is created and added to {@link Hudson}, before the + * initial configuration page is provided. <p> This is useful for changing + * the default initial configuration of newly created jobs. For example, you + * can enable/add builders, etc. */ public void onCreated(Item item) { } @@ -42,17 +42,16 @@ public class ItemListener implements ExtensionPoint { /** * Called after a new job is created by copying from an existing job. * - * For backward compatibility, the default implementation of this method calls {@link #onCreated(Item)}. - * If you choose to handle this method, think about whether you want to call super.onCopied or not. + * For backward compatibility, the default implementation of this method + * calls {@link #onCreated(Item)}. If you choose to handle this method, + * think about whether you want to call super.onCopied or not. * * - * @param src - * The source item that the new one was copied from. Never null. - * @param item - * The newly created item. Never null. + * @param src The source item that the new one was copied from. Never null. + * @param item The newly created item. Never null. * - * @since 1.325 - * Before this version, a copy triggered {@link #onCreated(Item)}. + * @since 1.325 Before this version, a copy triggered + * {@link #onCreated(Item)}. */ public void onCopied(Item src, Item item) { onCreated(item); @@ -76,12 +75,9 @@ public class ItemListener implements ExtensionPoint { /** * Called after a job is renamed. * - * @param item - * The job being renamed. - * @param oldName - * The old name of the job. - * @param newName - * The new name of the job. Same as {@link Item#getName()}. + * @param item The job being renamed. + * @param oldName The old name of the job. + * @param newName The new name of the job. Same as {@link Item#getName()}. * @since 1.146 */ public void onRenamed(Item item, String oldName, String newName) { @@ -90,8 +86,8 @@ public class ItemListener implements ExtensionPoint { /** * Registers this instance to Hudson and start getting notifications. * - * @deprecated as of 1.286 - * put {@link Extension} on your class to have it auto-registered. + * @deprecated as of 1.286 put {@link Extension} on your class to have it + * auto-registered. */ public void register() { all().add(this); @@ -105,12 +101,14 @@ public class ItemListener implements ExtensionPoint { } public static void fireOnCopied(Item src, Item result) { - for (ItemListener l : all()) - l.onCopied(src,result); + for (ItemListener l : all()) { + l.onCopied(src, result); + } } public static void fireOnCreated(Item item) { - for (ItemListener l : all()) + for (ItemListener l : all()) { l.onCreated(item); + } } } diff --git a/hudson-core/src/main/java/hudson/model/listeners/RunListener.java b/hudson-core/src/main/java/hudson/model/listeners/RunListener.java index 81195f3..d732e32 100644 --- a/hudson-core/src/main/java/hudson/model/listeners/RunListener.java +++ b/hudson-core/src/main/java/hudson/model/listeners/RunListener.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Tom Huybrechts - * + * Contributors: + * + * Kohsuke Kawaguchi, Tom Huybrechts + * * *******************************************************************************/ @@ -32,18 +32,18 @@ import java.lang.reflect.Type; /** * Receives notifications about builds. * - * <p> - * Listener is always Hudson-wide, so once registered it gets notifications for every build - * that happens in this Hudson. + * <p> Listener is always Hudson-wide, so once registered it gets notifications + * for every build that happens in this Hudson. + * + * <p> This is an abstract class so that methods added in the future won't break + * existing listeners. * - * <p> - * This is an abstract class so that methods added in the future won't break existing listeners. - * * @author Kohsuke Kawaguchi * @since 1.145 */ public abstract class RunListener<R extends Run> implements ExtensionPoint { //TODO: review and check whether we can do it private + public final Class<R> targetType; protected RunListener(Class<R> targetType) { @@ -52,10 +52,11 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint { protected RunListener() { Type type = Types.getBaseClass(getClass(), RunListener.class); - if (type instanceof ParameterizedType) - targetType = Types.erasure(Types.getTypeArgument(type,0)); - else - throw new IllegalStateException(getClass()+" uses the raw type for extending RunListener"); + if (type instanceof ParameterizedType) { + targetType = Types.erasure(Types.getTypeArgument(type, 0)); + } else { + throw new IllegalStateException(getClass() + " uses the raw type for extending RunListener"); + } } public Class<R> getTargetType() { @@ -65,49 +66,51 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint { /** * Called after a build is completed. * - * @param r - * The completed build. - * @param listener - * The listener for this build. This can be used to produce log messages, for example, - * which becomes a part of the "console output" of this build. But when this method runs, - * the build is considered completed, so its status cannot be changed anymore. + * @param r The completed build. + * @param listener The listener for this build. This can be used to produce + * log messages, for example, which becomes a part of the "console output" + * of this build. But when this method runs, the build is considered + * completed, so its status cannot be changed anymore. */ - public void onCompleted(R r, TaskListener listener) {} + public void onCompleted(R r, TaskListener listener) { + } /** * Called after a build is moved to the {@link Run.State#COMPLETED} state. * - * <p> - * At this point, all the records related to a build is written down to the disk. As such, - * {@link TaskListener} is no longer available. This happens later than {@link #onCompleted(Run, TaskListener)}. + * <p> At this point, all the records related to a build is written down to + * the disk. As such, {@link TaskListener} is no longer available. This + * happens later than {@link #onCompleted(Run, TaskListener)}. */ - public void onFinalized(R r) {} + public void onFinalized(R r) { + } /** - * Called when a build is started (i.e. it was in the queue, and will now start running - * on an executor) + * Called when a build is started (i.e. it was in the queue, and will now + * start running on an executor) * - * @param r - * The started build. - * @param listener - * The listener for this build. This can be used to produce log messages, for example, - * which becomes a part of the "console output" of this build. + * @param r The started build. + * @param listener The listener for this build. This can be used to produce + * log messages, for example, which becomes a part of the "console output" + * of this build. */ - public void onStarted(R r, TaskListener listener) {} + public void onStarted(R r, TaskListener listener) { + } /** * Called right before a build is going to be deleted. * * @param r The build. */ - public void onDeleted(R r) {} + public void onDeleted(R r) { + } /** * Registers this object as an active listener so that it can start getting * callbacks invoked. * - * @deprecated as of 1.281 - * Put {@link Extension} on your class to get it auto-registered. + * @deprecated as of 1.281 Put {@link Extension} on your class to get it + * auto-registered. */ public void register() { all().add(this); @@ -119,11 +122,11 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint { public void unregister() { all().remove(this); } - /** * List of registered listeners. - * @deprecated as of 1.281 - * Use {@link #all()} for read access, and use {@link Extension} for registration. + * + * @deprecated as of 1.281 Use {@link #all()} for read access, and use + * {@link Extension} for registration. */ public static final CopyOnWriteList<RunListener> LISTENERS = ExtensionListView.createCopyOnWriteList(RunListener.class); @@ -132,8 +135,9 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint { */ public static void fireCompleted(Run r, TaskListener listener) { for (RunListener l : all()) { - if(l.targetType.isInstance(r)) - l.onCompleted(r,listener); + if (l.targetType.isInstance(r)) { + l.onCompleted(r, listener); + } } } @@ -142,8 +146,9 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint { */ public static void fireStarted(Run r, TaskListener listener) { for (RunListener l : all()) { - if(l.targetType.isInstance(r)) - l.onStarted(r,listener); + if (l.targetType.isInstance(r)) { + l.onStarted(r, listener); + } } } @@ -152,8 +157,9 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint { */ public static void fireFinalized(Run r) { for (RunListener l : all()) { - if(l.targetType.isInstance(r)) + if (l.targetType.isInstance(r)) { l.onFinalized(r); + } } } @@ -162,8 +168,9 @@ public abstract class RunListener<R extends Run> implements ExtensionPoint { */ public static void fireDeleted(Run r) { for (RunListener l : all()) { - if(l.targetType.isInstance(r)) + if (l.targetType.isInstance(r)) { l.onDeleted(r); + } } } diff --git a/hudson-core/src/main/java/hudson/model/listeners/SCMListener.java b/hudson-core/src/main/java/hudson/model/listeners/SCMListener.java index 52a5bdd..88da29b 100644 --- a/hudson-core/src/main/java/hudson/model/listeners/SCMListener.java +++ b/hudson-core/src/main/java/hudson/model/listeners/SCMListener.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* + * Contributors: + * * Kohsuke Kawaguchi - * + * * *******************************************************************************/ @@ -27,72 +27,68 @@ import hudson.ExtensionPoint; /** * Receives notifications about SCM activities in Hudson. * - * <p> - * This is an abstract class so that methods added in the future won't break existing listeners. + * <p> This is an abstract class so that methods added in the future won't break + * existing listeners. * - * <p> - * Once instanciated, use the {@link #register()} method to start receiving events. + * <p> Once instanciated, use the {@link #register()} method to start receiving + * events. * * @author Kohsuke Kawaguchi * @see Hudson#getSCMListeners() * @since 1.70 */ public abstract class SCMListener implements ExtensionPoint { + /** * Called once the changelog is determined. * - * <p> - * During a build, Hudson fetches the update of the workspace from SCM, + * <p> During a build, Hudson fetches the update of the workspace from SCM, * and determines the changelog (see {@link SCM#checkout}). Immediately * after that, a build will invoke this method on all registered * {@link SCMListener}s. * - * <p> - * If a build failed before we successfully determine changelog, this method - * will not be invoked (for example, if "cvs update" failed.) OTOH, this method - * is invoked before the actual build (like ant invocation) happens. + * <p> If a build failed before we successfully determine changelog, this + * method will not be invoked (for example, if "cvs update" failed.) OTOH, + * this method is invoked before the actual build (like ant invocation) + * happens. * - * <p> - * This is an opportunity for SCM-related plugins to act on changelog. - * A typical usage includes parsing commit messages and do cross-referencing + * <p> This is an opportunity for SCM-related plugins to act on changelog. A + * typical usage includes parsing commit messages and do cross-referencing * between other systems. Implementations can also contribute {@link Action} * to {@link AbstractBuild} (by {@code build.getActions().add(...)} to * display additional data on build views. * - * <p> - * TODO: once we have cvsnews plugin, refer to its usage. + * <p> TODO: once we have cvsnews plugin, refer to its usage. * - * @param build - * The build in progress, which just finished determining changelog. - * At this point this build is still in progress. Never null. - * @param listener - * {@link BuildListener} for on-going build. This can be used to report - * any errors or the general logging of what's going on. This will show - * up in the "console output" of the build. Never null. - * @param changelog - * Set of changes detected in this build. This is the same value - * returned from {@link AbstractBuild#getChangeSet()} but passed - * separately for convenience. + * @param build The build in progress, which just finished determining + * changelog. At this point this build is still in progress. Never null. + * @param listener {@link BuildListener} for on-going build. This can be + * used to report any errors or the general logging of what's going on. This + * will show up in the "console output" of the build. Never null. + * @param changelog Set of changes detected in this build. This is the same + * value returned from {@link AbstractBuild#getChangeSet()} but passed + * separately for convenience. * - * @throws Exception - * If any exception is thrown from this method, it will be recorded - * and causes the build to fail. + * @throws Exception If any exception is thrown from this method, it will be + * recorded and causes the build to fail. */ - public void onChangeLogParsed(AbstractBuild<?,?> build, BuildListener listener, ChangeLogSet<?> changelog) throws Exception { + public void onChangeLogParsed(AbstractBuild<?, ?> build, BuildListener listener, ChangeLogSet<?> changelog) throws Exception { } /** - * Registers this {@link SCMListener} so that it will start receiving events. + * Registers this {@link SCMListener} so that it will start receiving + * events. */ public final void register() { Hudson.getInstance().getSCMListeners().add(this); } /** - * Unregisters this {@link SCMListener} so that it will never receive further events. + * Unregisters this {@link SCMListener} so that it will never receive + * further events. * - * <p> - * Unless {@link SCMListener} is unregistered, it will never be a subject of GC. + * <p> Unless {@link SCMListener} is unregistered, it will never be a + * subject of GC. */ public final boolean unregister() { return Hudson.getInstance().getSCMListeners().remove(this); diff --git a/hudson-core/src/main/java/hudson/model/listeners/SaveableListener.java b/hudson-core/src/main/java/hudson/model/listeners/SaveableListener.java index fb8e359..cf90440 100644 --- a/hudson-core/src/main/java/hudson/model/listeners/SaveableListener.java +++ b/hudson-core/src/main/java/hudson/model/listeners/SaveableListener.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Tom Huybrechts, Andrew Bayer - * + * Contributors: + * + * Kohsuke Kawaguchi, Tom Huybrechts, Andrew Bayer + * * *******************************************************************************/ @@ -24,10 +24,11 @@ import hudson.model.Hudson; import hudson.model.Saveable; /** - * Receives notifications about save actions on {@link Saveable} objects in Hudson. + * Receives notifications about save actions on {@link Saveable} objects in + * Hudson. * - * <p> - * This is an abstract class so that methods added in the future won't break existing listeners. + * <p> This is an abstract class so that methods added in the future won't break + * existing listeners. * * @author Andrew Bayer * @since 1.334 @@ -37,19 +38,18 @@ public abstract class SaveableListener implements ExtensionPoint { /** * Called when a change is made to a {@link Saveable} object. * - * @param o - * The saveable object. - * @param file - * The {@link XmlFile} for this saveable object. + * @param o The saveable object. + * @param file The {@link XmlFile} for this saveable object. */ - public void onChange(Saveable o, XmlFile file) {} + public void onChange(Saveable o, XmlFile file) { + } /** * Registers this object as an active listener so that it can start getting * callbacks invoked. * - * @deprecated as of 1.281 - * Put {@link Extension} on your class to get it auto-registered. + * @deprecated as of 1.281 Put {@link Extension} on your class to get it + * auto-registered. */ public void register() { all().add(this); @@ -67,7 +67,7 @@ public abstract class SaveableListener implements ExtensionPoint { */ public static void fireOnChange(Saveable o, XmlFile file) { for (SaveableListener l : all()) { - l.onChange(o,file); + l.onChange(o, file); } } diff --git a/hudson-core/src/main/java/hudson/model/listeners/package.html b/hudson-core/src/main/java/hudson/model/listeners/package.html index 81a627c..cca0973 100644 --- a/hudson-core/src/main/java/hudson/model/listeners/package.html +++ b/hudson-core/src/main/java/hudson/model/listeners/package.html @@ -16,5 +16,5 @@ --> <html><head/><body> -Listener interfaces for various events that occur inside the server. -</body></html>
\ No newline at end of file + Listener interfaces for various events that occur inside the server. + </body></html>
\ No newline at end of file diff --git a/hudson-core/src/main/java/hudson/model/queue/AbstractQueueSorterImpl.java b/hudson-core/src/main/java/hudson/model/queue/AbstractQueueSorterImpl.java index 6eb8ad0..696857f 100644 --- a/hudson-core/src/main/java/hudson/model/queue/AbstractQueueSorterImpl.java +++ b/hudson-core/src/main/java/hudson/model/queue/AbstractQueueSorterImpl.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ @@ -27,31 +27,35 @@ import java.util.List; * @since 1.343 */ public abstract class AbstractQueueSorterImpl extends QueueSorter implements Comparator<BuildableItem> { + @Override public void sortBuildableItems(List<BuildableItem> buildables) { - Collections.sort(buildables,this); // sort is ascending order + Collections.sort(buildables, this); // sort is ascending order } /** * Override this method to provide the ordering of the sort. * - * <p> - * if lhs should be build before rhs, return a negative value. Or put another way, think of the comparison - * as a process of converting a {@link BuildableItem} into a number, then doing num(lhs)-num(rhs). + * <p> if lhs should be build before rhs, return a negative value. Or put + * another way, think of the comparison as a process of converting a + * {@link BuildableItem} into a number, then doing num(lhs)-num(rhs). * - * <p> - * The default implementation does FIFO. + * <p> The default implementation does FIFO. */ public int compare(BuildableItem lhs, BuildableItem rhs) { - return compare(lhs.buildableStartMilliseconds,rhs.buildableStartMilliseconds); + return compare(lhs.buildableStartMilliseconds, rhs.buildableStartMilliseconds); } /** * sign(a-b). */ protected static int compare(long a, long b) { - if (a>b) return 1; - if (a<b) return -1; + if (a > b) { + return 1; + } + if (a < b) { + return -1; + } return 0; } @@ -59,8 +63,12 @@ public abstract class AbstractQueueSorterImpl extends QueueSorter implements Com * sign(a-b). */ protected static int compare(int a, int b) { - if (a>b) return 1; - if (a<b) return -1; + if (a > b) { + return 1; + } + if (a < b) { + return -1; + } return 0; } } diff --git a/hudson-core/src/main/java/hudson/model/queue/AbstractQueueTask.java b/hudson-core/src/main/java/hudson/model/queue/AbstractQueueTask.java index c07f12a..aaf57c3 100644 --- a/hudson-core/src/main/java/hudson/model/queue/AbstractQueueTask.java +++ b/hudson-core/src/main/java/hudson/model/queue/AbstractQueueTask.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -23,13 +23,14 @@ import java.util.Collection; import java.util.Collections; /** - * Abstract base class for {@link Queue.Task} to protect plugins - * from new additions to the interface. + * Abstract base class for {@link Queue.Task} to protect plugins from new + * additions to the interface. * * @author Kohsuke Kawaguchi * @since 1.360 */ public abstract class AbstractQueueTask implements Queue.Task { + public Collection<? extends SubTask> getSubTasks() { return Collections.singleton(this); } diff --git a/hudson-core/src/main/java/hudson/model/queue/AbstractSubTask.java b/hudson-core/src/main/java/hudson/model/queue/AbstractSubTask.java index d7f326a..83511bb 100644 --- a/hudson-core/src/main/java/hudson/model/queue/AbstractSubTask.java +++ b/hudson-core/src/main/java/hudson/model/queue/AbstractSubTask.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -27,6 +27,7 @@ import hudson.model.ResourceList; * @author Kohsuke Kawaguchi */ public abstract class AbstractSubTask implements SubTask { + public Label getAssignedLabel() { return null; } diff --git a/hudson-core/src/main/java/hudson/model/queue/BackFiller.java b/hudson-core/src/main/java/hudson/model/queue/BackFiller.java index a7ed84c..6968627 100644 --- a/hudson-core/src/main/java/hudson/model/queue/BackFiller.java +++ b/hudson-core/src/main/java/hudson/model/queue/BackFiller.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ @@ -40,6 +40,7 @@ import java.util.Map.Entry; * @author Kohsuke Kawaguchi */ public class BackFiller extends LoadPredictor { + private boolean recursion = false; @Override @@ -49,9 +50,11 @@ public class BackFiller extends LoadPredictor { for (BuildableItem bi : Hudson.getInstance().getQueue().getBuildableItems()) { TentativePlan tp = bi.getAction(TentativePlan.class); - if (tp==null) {// do this even for bi==plan.item ensures that we have FIFO semantics in tentative plans. + if (tp == null) {// do this even for bi==plan.item ensures that we have FIFO semantics in tentative plans. tp = makeTentativePlan(bi); - if (tp==null) continue; // no viable plan. + if (tp == null) { + continue; // no viable plan. + } } if (tp.isStale()) { @@ -62,15 +65,21 @@ public class BackFiller extends LoadPredictor { } // don't let its own tentative plan count when considering a scheduling for a job - if (plan.item==bi) continue; + if (plan.item == bi) { + continue; + } // no overlap in the time span, meaning this plan is for a distant future - if (!timeRange.overlapsWith(tp.range)) continue; + if (!timeRange.overlapsWith(tp.range)) { + continue; + } // if this tentative plan has no baring on this computer, that's ignorable Integer i = tp.footprint.get(computer); - if (i==null) continue; + if (i == null) { + continue; + } return Collections.singleton(tp.range.toFutureLoad(i)); } @@ -79,6 +88,7 @@ public class BackFiller extends LoadPredictor { } private static final class PseudoExecutorSlot extends ExecutorSlot { + private Executor executor; private PseudoExecutorSlot(Executor executor) { @@ -103,13 +113,17 @@ public class BackFiller extends LoadPredictor { } private TentativePlan makeTentativePlan(BuildableItem bi) { - if (recursion) return null; + if (recursion) { + return null; + } recursion = true; try { // pretend for now that all executors are available and decide some assignment that's executable. List<PseudoExecutorSlot> slots = new ArrayList<PseudoExecutorSlot>(); for (Computer c : Hudson.getInstance().getComputers()) { - if (c.isOffline()) continue; + if (c.isOffline()) { + continue; + } for (Executor e : c.getExecutors()) { slots.add(new PseudoExecutorSlot(e)); } @@ -119,16 +133,20 @@ public class BackFiller extends LoadPredictor { // and we are not trying to figure out if this task is executable right now. MappingWorksheet worksheet = new MappingWorksheet(bi, slots, Collections.<LoadPredictor>emptyList()); Mapping m = Hudson.getInstance().getQueue().getLoadBalancer().map(bi.task, worksheet); - if (m==null) return null; + if (m == null) { + return null; + } // figure out how many executors we need on each computer? - Map<Computer,Integer> footprint = new HashMap<Computer, Integer>(); + Map<Computer, Integer> footprint = new HashMap<Computer, Integer>(); for (Entry<WorkChunk, ExecutorChunk> e : m.toMap().entrySet()) { Computer c = e.getValue().computer; Integer v = footprint.get(c); - if (v==null) v = 0; + if (v == null) { + v = 0; + } v += e.getKey().size(); - footprint.put(c,v); + footprint.put(c, v); } // the point of a tentative plan is to displace other jobs to create a point in time @@ -137,7 +155,9 @@ public class BackFiller extends LoadPredictor { // The downside of guessing the duration wrong is that we can end up creating tentative plans // afterward that may be incorrect, but those plans will be rebuilt. long d = bi.task.getEstimatedDuration(); - if (d<=0) d = TimeUnit2.MINUTES.toMillis(5); + if (d <= 0) { + d = TimeUnit2.MINUTES.toMillis(5); + } TimeRange slot = new TimeRange(System.currentTimeMillis(), d); @@ -147,14 +167,16 @@ public class BackFiller extends LoadPredictor { Computer computer = e.getKey(); Timeline timeline = new Timeline(); for (LoadPredictor lp : LoadPredictor.all()) { - for (FutureLoad fl : Iterables.limit(lp.predict(worksheet, computer, slot.start, slot.end),100)) { - timeline.insert(fl.startTime, fl.startTime+fl.duration, fl.numExecutors); + for (FutureLoad fl : Iterables.limit(lp.predict(worksheet, computer, slot.start, slot.end), 100)) { + timeline.insert(fl.startTime, fl.startTime + fl.duration, fl.numExecutors); } } - Long x = timeline.fit(slot.start, slot.duration, computer.countExecutors()-e.getValue()); + Long x = timeline.fit(slot.start, slot.duration, computer.countExecutors() - e.getValue()); // if no suitable range was found in [slot.start,slot.end), slot.end would be a good approximation - if (x==null) x = slot.end; + if (x == null) { + x = slot.end; + } slot = slot.shiftTo(x); } @@ -170,6 +192,7 @@ public class BackFiller extends LoadPredictor { * Represents a duration in time. */ private static final class TimeRange { + public final long start; public final long duration; public final long end; @@ -177,26 +200,29 @@ public class BackFiller extends LoadPredictor { private TimeRange(long start, long duration) { this.start = start; this.duration = duration; - this.end = start+duration; + this.end = start + duration; } public boolean overlapsWith(TimeRange that) { - return (this.start <= that.start && that.start <=this.end) - || (that.start <= this.start && this.start <=that.end); + return (this.start <= that.start && that.start <= this.end) + || (that.start <= this.start && this.start <= that.end); } public FutureLoad toFutureLoad(int size) { - return new FutureLoad(start,duration,size); + return new FutureLoad(start, duration, size); } public TimeRange shiftTo(long newStart) { - if (newStart==start) return this; - return new TimeRange(newStart,duration); + if (newStart == start) { + return this; + } + return new TimeRange(newStart, duration); } } public static final class TentativePlan extends InvisibleAction { - private final Map<Computer,Integer> footprint; + + private final Map<Computer, Integer> footprint; public final TimeRange range; public TentativePlan(Map<Computer, Integer> footprint, TimeRange range) { @@ -218,8 +244,9 @@ public class BackFiller extends LoadPredictor { */ @Extension public static BackFiller newInstance() { - if (Boolean.getBoolean(BackFiller.class.getName())) + if (Boolean.getBoolean(BackFiller.class.getName())) { return new BackFiller(); + } return null; } } diff --git a/hudson-core/src/main/java/hudson/model/queue/CauseOfBlockage.java b/hudson-core/src/main/java/hudson/model/queue/CauseOfBlockage.java index 57d53f0..254a069 100644 --- a/hudson-core/src/main/java/hudson/model/queue/CauseOfBlockage.java +++ b/hudson-core/src/main/java/hudson/model/queue/CauseOfBlockage.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ @@ -21,16 +21,17 @@ import hudson.model.Label; import org.jvnet.localizer.Localizable; /** - * If a {@link Task} execution is blocked in the queue, this object represents why. + * If a {@link Task} execution is blocked in the queue, this object represents + * why. * - * <h2>View</h2> - * <tt>summary.jelly</tt> should do one-line HTML rendering to be used while rendering - * "build history" widget, next to the blocking build. By default it simply renders - * {@link #getShortDescription()} text. + * <h2>View</h2> <tt>summary.jelly</tt> should do one-line HTML rendering to be + * used while rendering "build history" widget, next to the blocking build. By + * default it simply renders {@link #getShortDescription()} text. * * @since 1.330 */ public abstract class CauseOfBlockage { + /** * Human readable description of why the build is blocked. */ @@ -52,6 +53,7 @@ public abstract class CauseOfBlockage { */ public static final class BecauseNodeIsOffline extends CauseOfBlockage { //TODO: review and check whether we can do it private + public final Node node; public Node getNode() { @@ -68,10 +70,12 @@ public abstract class CauseOfBlockage { } /** - * Build is blocked because all the nodes that match a given label is offline. + * Build is blocked because all the nodes that match a given label is + * offline. */ public static final class BecauseLabelIsOffline extends CauseOfBlockage { //TODO: review and check whether we can do it private + public final Label label; public Label getLabel() { @@ -92,6 +96,7 @@ public abstract class CauseOfBlockage { */ public static final class BecauseNodeIsBusy extends CauseOfBlockage { //TODO: review and check whether we can do it private + public final Node node; public Node getNode() { @@ -108,10 +113,12 @@ public abstract class CauseOfBlockage { } /** - * Build is blocked because everyone that matches the specified label is fully busy + * Build is blocked because everyone that matches the specified label is + * fully busy */ public static final class BecauseLabelIsBusy extends CauseOfBlockage { //TODO: review and check whether we can do it private + public final Label label; public Label getLabel() { diff --git a/hudson-core/src/main/java/hudson/model/queue/Executables.java b/hudson-core/src/main/java/hudson/model/queue/Executables.java index 65374a1..2062fa0 100644 --- a/hudson-core/src/main/java/hudson/model/queue/Executables.java +++ b/hudson-core/src/main/java/hudson/model/queue/Executables.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -27,8 +27,10 @@ import java.lang.reflect.Method; * @author Kohsuke Kawaguchi */ public class Executables { + /** - * Due to the return type change in {@link Executable}, the caller needs a special precaution now. + * Due to the return type change in {@link Executable}, the caller needs a + * special precaution now. */ public static SubTask getParentOf(Executable e) { try { @@ -39,30 +41,34 @@ public class Executables { m.setAccessible(true); return (SubTask) m.invoke(e); } catch (IllegalAccessException x) { - throw (Error)new IllegalAccessError().initCause(x); + throw (Error) new IllegalAccessError().initCause(x); } catch (NoSuchMethodException x) { - throw (Error)new NoSuchMethodError().initCause(x); + throw (Error) new NoSuchMethodError().initCause(x); } catch (InvocationTargetException x) { Throwable y = x.getTargetException(); - if (y instanceof Error) throw (Error)y; - if (y instanceof RuntimeException) throw (RuntimeException)y; + if (y instanceof Error) { + throw (Error) y; + } + if (y instanceof RuntimeException) { + throw (RuntimeException) y; + } throw new Error(x); } } } /** - * A pointless function to work around what appears to be a HotSpot problem. See HUDSON-5756 and bug 6933067 - * on BugParade for more details. + * A pointless function to work around what appears to be a HotSpot problem. + * See HUDSON-5756 and bug 6933067 on BugParade for more details. */ private static SubTask _getParentOf(Executable e) { return e.getParent(); } /** - * Returns the estimated duration for the executable. - * Protects against {@link AbstractMethodError}s if the {@link Executable} implementation - * was compiled against Hudson < 1.383 + * Returns the estimated duration for the executable. Protects against + * {@link AbstractMethodError}s if the {@link Executable} implementation was + * compiled against Hudson < 1.383 */ public static long getEstimatedDurationFor(Executable e) { try { @@ -73,8 +79,8 @@ public class Executables { } /** - * A pointless function to work around what appears to be a HotSpot problem. See HUDSON-5756 and bug 6933067 - * on BugParade for more details. + * A pointless function to work around what appears to be a HotSpot problem. + * See HUDSON-5756 and bug 6933067 on BugParade for more details. */ private static long _getEstimatedDuration(Executable e) { return e.getEstimatedDuration(); diff --git a/hudson-core/src/main/java/hudson/model/queue/FoldableAction.java b/hudson-core/src/main/java/hudson/model/queue/FoldableAction.java index 1b1da64..e3d90e2 100644 --- a/hudson-core/src/main/java/hudson/model/queue/FoldableAction.java +++ b/hudson-core/src/main/java/hudson/model/queue/FoldableAction.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -25,28 +25,28 @@ import java.util.List; /** * An action interface that allows action data to be folded together. * - * <p> - * {@link Action} can implement this optional marker interface to be notified when - * the {@link Task} that it's added to the queue with is determined to be "already in the queue". + * <p> {@link Action} can implement this optional marker interface to be + * notified when the {@link Task} that it's added to the queue with is + * determined to be "already in the queue". * - * <p> - * This is useful for passing on parameters to the task that's already in the queue. + * <p> This is useful for passing on parameters to the task that's already in + * the queue. * * @author mdonohue * @since 1.300-ish. */ public interface FoldableAction extends Action { + /** - * Notifies that the {@link Task} that "owns" this action (that is, the task for which this action is submitted) - * is considered as a duplicate. + * Notifies that the {@link Task} that "owns" this action (that is, the task + * for which this action is submitted) is considered as a duplicate. * - * @param item - * The existing {@link Queue.Item} in the queue against which we are judged as a duplicate. Never null. - * @param owner - * The {@link Task} with which this action was submitted to the queue. Never null. - * @param otherActions - * Other {@link Action}s that are submitted with the task. (One of them is this {@link FoldableAction}.) - * Never null. + * @param item The existing {@link Queue.Item} in the queue against which we + * are judged as a duplicate. Never null. + * @param owner The {@link Task} with which this action was submitted to the + * queue. Never null. + * @param otherActions Other {@link Action}s that are submitted with the + * task. (One of them is this {@link FoldableAction}.) Never null. */ void foldIntoExisting(Queue.Item item, Task owner, List<Action> otherActions); } diff --git a/hudson-core/src/main/java/hudson/model/queue/FutureImpl.java b/hudson-core/src/main/java/hudson/model/queue/FutureImpl.java index 8adc3cc..b9ea034 100644 --- a/hudson-core/src/main/java/hudson/model/queue/FutureImpl.java +++ b/hudson-core/src/main/java/hudson/model/queue/FutureImpl.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -27,15 +27,17 @@ import java.util.HashSet; import java.util.Set; /** - * Created when {@link Queue.Item} is created so that the caller can track the progress of the task. + * Created when {@link Queue.Item} is created so that the caller can track the + * progress of the task. * * @author Kohsuke Kawaguchi */ public final class FutureImpl extends AsyncFutureImpl<Executable> { - private final Task task; + private final Task task; /** - * If the computation has started, set to {@link Executor}s that are running the build. + * If the computation has started, set to {@link Executor}s that are running + * the build. */ private final Set<Executor> executors = new HashSet<Executor>(); @@ -48,10 +50,12 @@ public final class FutureImpl extends AsyncFutureImpl<Executable> { Queue q = Hudson.getInstance().getQueue(); synchronized (q) { synchronized (this) { - if(!executors.isEmpty()) { - if(mayInterruptIfRunning) - for (Executor e : executors) + if (!executors.isEmpty()) { + if (mayInterruptIfRunning) { + for (Executor e : executors) { e.interrupt(); + } + } return mayInterruptIfRunning; } return q.cancel(task); diff --git a/hudson-core/src/main/java/hudson/model/queue/FutureLoad.java b/hudson-core/src/main/java/hudson/model/queue/FutureLoad.java index eb95ba0..dba4020 100644 --- a/hudson-core/src/main/java/hudson/model/queue/FutureLoad.java +++ b/hudson-core/src/main/java/hudson/model/queue/FutureLoad.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -23,6 +23,7 @@ package hudson.model.queue; * @see LoadPredictor */ public final class FutureLoad { + /** * When is this load expected to start? */ @@ -43,6 +44,6 @@ public final class FutureLoad { } public String toString() { - return "startTime="+startTime+",#executors="+numExecutors+",duration="+duration; + return "startTime=" + startTime + ",#executors=" + numExecutors + ",duration=" + duration; } } diff --git a/hudson-core/src/main/java/hudson/model/queue/Latch.java b/hudson-core/src/main/java/hudson/model/queue/Latch.java index c605126..f3f5651 100644 --- a/hudson-core/src/main/java/hudson/model/queue/Latch.java +++ b/hudson-core/src/main/java/hudson/model/queue/Latch.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -19,19 +19,19 @@ package hudson.model.queue; import hudson.AbortException; /** - * A concurrency primitive that waits for N number of threads to synchronize. - * If any of the threads are interrupted while waiting for the completion of the condition, - * then all the involved threads get interrupted. + * A concurrency primitive that waits for N number of threads to synchronize. If + * any of the threads are interrupted while waiting for the completion of the + * condition, then all the involved threads get interrupted. * * @author Kohsuke Kawaguchi */ class Latch { + private final int n; - private int i=0; + private int i = 0; /** - * If the synchronization on the latch is aborted/interrupted, - * point to the stack trace where that happened. If null, - * no interruption happened. + * If the synchronization on the latch is aborted/interrupted, point to the + * stack trace where that happened. If null, no interruption happened. */ private Exception interrupted; @@ -41,12 +41,12 @@ class Latch { public synchronized void abort(Throwable cause) { interrupted = new AbortException(); - if (cause!=null) + if (cause != null) { interrupted.initCause(cause); + } notifyAll(); } - public synchronized void synchronize() throws InterruptedException { check(n); @@ -60,15 +60,15 @@ class Latch { throw e; } - check(n*2); + check(n * 2); } private void check(int threshold) throws InterruptedException { i++; - if (i==threshold) { + if (i == threshold) { notifyAll(); } else { - while (i<threshold && interrupted==null) { + while (i < threshold && interrupted == null) { try { wait(); } catch (InterruptedException e) { @@ -80,9 +80,11 @@ class Latch { } // all of us either leave normally or get interrupted - if (interrupted!=null) - throw (InterruptedException)new InterruptedException().initCause(interrupted); + if (interrupted != null) { + throw (InterruptedException) new InterruptedException().initCause(interrupted); + } } - protected void onCriteriaMet() throws InterruptedException {} + protected void onCriteriaMet() throws InterruptedException { + } } diff --git a/hudson-core/src/main/java/hudson/model/queue/LoadPredictor.java b/hudson-core/src/main/java/hudson/model/queue/LoadPredictor.java index e355601..8181470 100644 --- a/hudson-core/src/main/java/hudson/model/queue/LoadPredictor.java +++ b/hudson-core/src/main/java/hudson/model/queue/LoadPredictor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -30,41 +30,43 @@ import java.util.List; /** * Predicts future load to the system, to assist the scheduling decisions * - * <p> - * When Hudson makes a scheduling decision, Hudson considers predicted future load - * — e.g., "We do currently have one available executor, but we know we need this for something else in 30 minutes, - * so we can't currently schedule a build that takes 1 hour." + * <p> When Hudson makes a scheduling decision, Hudson considers predicted + * future load — e.g., "We do currently have one available executor, but + * we know we need this for something else in 30 minutes, so we can't currently + * schedule a build that takes 1 hour." * - * <p> - * This extension point plugs in such estimation of future load. + * <p> This extension point plugs in such estimation of future load. * * @author Kohsuke Kawaguchi */ public abstract class LoadPredictor implements ExtensionPoint { + /** - * Estimates load starting from the 'start' timestamp, up to the 'end' timestamp. + * Estimates load starting from the 'start' timestamp, up to the 'end' + * timestamp. * - * @param start - * Where to start enumeration. Always bigger or equal to the current time of the execution. - * @param plan - * This is the execution plan for which we are making a load prediction. Never null. While - * this object is still being partially constructed when this method is called, some - * of its properties (like {@link MappingWorksheet#item} provide access to more contextual - * information. + * @param start Where to start enumeration. Always bigger or equal to the + * current time of the execution. + * @param plan This is the execution plan for which we are making a load + * prediction. Never null. While this object is still being partially + * constructed when this method is called, some of its properties (like + * {@link MappingWorksheet#item} provide access to more contextual + * information. * @since 1.380 */ public Iterable<FutureLoad> predict(MappingWorksheet plan, Computer computer, long start, long end) { // maintain backward compatibility by calling the old signature. - return predict(computer,start,end); + return predict(computer, start, end); } /** - * Estimates load starting from the 'start' timestamp, up to the 'end' timestamp. + * Estimates load starting from the 'start' timestamp, up to the 'end' + * timestamp. * - * @param start - * Where to start enumeration. Always bigger or equal to the current time of the execution. - * @deprecated as of 1.380 - * Use {@link #predict(MappingWorksheet, Computer, long, long)} + * @param start Where to start enumeration. Always bigger or equal to the + * current time of the execution. + * @deprecated as of 1.380 Use + * {@link #predict(MappingWorksheet, Computer, long, long)} */ public Iterable<FutureLoad> predict(Computer computer, long start, long end) { return Collections.emptyList(); @@ -82,17 +84,22 @@ public abstract class LoadPredictor implements ExtensionPoint { */ @Extension public static class CurrentlyRunningTasks extends LoadPredictor { + @Override public Iterable<FutureLoad> predict(MappingWorksheet plan, final Computer computer, long start, long eternity) { long now = System.currentTimeMillis(); List<FutureLoad> fl = new ArrayList<FutureLoad>(); for (Executor e : computer.getExecutors()) { - if (e.isIdle()) continue; + if (e.isIdle()) { + continue; + } long eta = e.getEstimatedRemainingTimeMillis(); - long end = eta<0 ? eternity : now + eta; // when does this task end? - if (end < start) continue; // should be over by the 'start' time. - fl.add(new FutureLoad(start, end-start, 1)); + long end = eta < 0 ? eternity : now + eta; // when does this task end? + if (end < start) { + continue; // should be over by the 'start' time. + } + fl.add(new FutureLoad(start, end - start, 1)); } return fl; } diff --git a/hudson-core/src/main/java/hudson/model/queue/MappingWorksheet.java b/hudson-core/src/main/java/hudson/model/queue/MappingWorksheet.java index 3276c5e..368805d 100644 --- a/hudson-core/src/main/java/hudson/model/queue/MappingWorksheet.java +++ b/hudson-core/src/main/java/hudson/model/queue/MappingWorksheet.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -42,45 +42,44 @@ import static java.lang.Math.*; /** * Defines a mapping problem for answering "where do we execute this task?" * - * <p> - * The heart of the placement problem is a mapping problem. We are given a {@link Task}, - * (which in the general case consists of a set of {@link SubTask}s), and we are also given a number - * of idle {@link Executor}s, and our goal is to find a mapping from the former to the latter, - * which determines where each {@link SubTask} gets executed. + * <p> The heart of the placement problem is a mapping problem. We are given a + * {@link Task}, (which in the general case consists of a set of + * {@link SubTask}s), and we are also given a number of idle {@link Executor}s, + * and our goal is to find a mapping from the former to the latter, which + * determines where each {@link SubTask} gets executed. * - * <p> - * This mapping is done under two constraints: + * <p> This mapping is done under two constraints: * - * <ul> - * <li> - * "Same node" constraint. Some of the subtasks need to be co-located on the same node. - * See {@link SubTask#getSameNodeConstraint()} - * <li> - * Label constraint. {@link SubTask}s can specify that it can be only run on nodes that has the label. - * </ul> + * <ul> <li> "Same node" constraint. Some of the subtasks need to be co-located + * on the same node. See {@link SubTask#getSameNodeConstraint()} <li> Label + * constraint. {@link SubTask}s can specify that it can be only run on nodes + * that has the label. </ul> * - * <p> - * We first fold the former constraint into the problem definition. That is, we now consider - * a set of {@link SubTask}s that need to be co-located as a single {@link WorkChunk}. Similarly, - * we consider a set of all {@link Executor}s from the same node as {@link ExecutorChunk}. - * Now, the problem becomes the weighted matching problem from {@link WorkChunk} to {@link ExecutorChunk}. + * <p> We first fold the former constraint into the problem definition. That is, + * we now consider a set of {@link SubTask}s that need to be co-located as a + * single {@link WorkChunk}. Similarly, we consider a set of all + * {@link Executor}s from the same node as {@link ExecutorChunk}. Now, the + * problem becomes the weighted matching problem from {@link WorkChunk} to + * {@link ExecutorChunk}. * - * <p> - * An instance of {@link MappingWorksheet} captures a problem definition, plus which - * {@link ExecutorChunk} and {@link WorkChunk} are compatible. The purpose of this class - * (and {@link ExecutorChunk} and {@link WorkChunk}) are to expose a lot of convenience methods - * to assist various algorithms that produce the solution of this mapping problem, - * which is represented as {@link Mapping}. + * <p> An instance of {@link MappingWorksheet} captures a problem definition, + * plus which {@link ExecutorChunk} and {@link WorkChunk} are compatible. The + * purpose of this class (and {@link ExecutorChunk} and {@link WorkChunk}) are + * to expose a lot of convenience methods to assist various algorithms that + * produce the solution of this mapping problem, which is represented as + * {@link Mapping}. * * @see LoadBalancer#map(Task, MappingWorksheet) * @author Kohsuke Kawaguchi */ public class MappingWorksheet { //TODO: review and check whether we can do it private + public final List<ExecutorChunk> executors; public final List<WorkChunk> works; /** - * {@link BuildableItem} for which we are trying to figure out the execution plan. Never null. + * {@link BuildableItem} for which we are trying to figure out the execution + * plan. Never null. */ public final BuildableItem item; @@ -97,6 +96,7 @@ public class MappingWorksheet { } private static class ReadOnlyList<E> extends AbstractList<E> { + protected final List<E> base; ReadOnlyList(List<E> base) { @@ -114,6 +114,7 @@ public class MappingWorksheet { public final class ExecutorChunk extends ReadOnlyList<ExecutorSlot> { //TODO: review and check whether we can do it private + public final int index; public final Computer computer; public final Node node; @@ -139,11 +140,12 @@ public class MappingWorksheet { } /** - * Is this executor chunk and the given work chunk compatible? Can the latter be run on the former? + * Is this executor chunk and the given work chunk compatible? Can the + * latter be run on the former? */ public boolean canAccept(WorkChunk c) { return this.size() >= c.size() - && (c.assignedLabel==null || c.assignedLabel.contains(node)); + && (c.assignedLabel == null || c.assignedLabel.contains(node)); } /** @@ -154,8 +156,7 @@ public class MappingWorksheet { } /** - * Number of executors in this chunk. - * Alias for size but more readable. + * Number of executors in this chunk. Alias for size but more readable. */ public int capacity() { return size(); @@ -165,37 +166,34 @@ public class MappingWorksheet { assert capacity() >= wc.size(); int e = 0; for (SubTask s : wc) { - while (!get(e).isAvailable()) + while (!get(e).isAvailable()) { e++; + } get(e++).set(wuc.createWorkUnit(s)); } } } public class WorkChunk extends ReadOnlyList<SubTask> { - public final int index; + public final int index; // the main should be always at position 0 // /** // * This chunk includes {@linkplain WorkUnit#isMainWork() the main work unit}. // */ // public final boolean isMain; - /** * If this task needs to be run on a node with a particular label, - * return that {@link Label}. Otherwise null, indicating - * it can run on anywhere. + * return that {@link Label}. Otherwise null, indicating it can run on + * anywhere. */ public final Label assignedLabel; - /** - * If the previous execution of this task run on a certain node - * and this task prefers to run on the same node, return that. - * Otherwise null. + * If the previous execution of this task run on a certain node and this + * task prefers to run on the same node, return that. Otherwise null. */ public final ExecutorChunk lastBuiltOn; - private WorkChunk(List<SubTask> base, int index) { super(base); assert !base.isEmpty(); @@ -204,7 +202,7 @@ public class MappingWorksheet { Node lbo = base.get(0).getLastBuiltOn(); for (ExecutorChunk ec : executors) { - if (ec.node==lbo) { + if (ec.node == lbo) { lastBuiltOn = ec; return; } @@ -215,20 +213,22 @@ public class MappingWorksheet { public List<ExecutorChunk> applicableExecutorChunks() { List<ExecutorChunk> r = new ArrayList<ExecutorChunk>(executors.size()); for (ExecutorChunk e : executors) { - if (e.canAccept(this)) + if (e.canAccept(this)) { r.add(e); + } } return r; } } /** - * Represents the solution to the mapping problem. - * It's a mapping from every {@link WorkChunk} to {@link ExecutorChunk} - * that satisfies the constraints. + * Represents the solution to the mapping problem. It's a mapping from every + * {@link WorkChunk} to {@link ExecutorChunk} that satisfies the + * constraints. */ public final class Mapping { // for each WorkChunk, identify ExecutorChunk where it is assigned to. + private final ExecutorChunk[] mapping = new ExecutorChunk[works.size()]; /** @@ -246,7 +246,8 @@ public class MappingWorksheet { } /** - * Update the mapping to execute n-th {@link WorkChunk} on the specified {@link ExecutorChunk}. + * Update the mapping to execute n-th {@link WorkChunk} on the specified + * {@link ExecutorChunk}. */ public ExecutorChunk assign(int index, ExecutorChunk element) { ExecutorChunk o = mapping[index]; @@ -264,65 +265,78 @@ public class MappingWorksheet { /** * Returns the assignment as a map. */ - public Map<WorkChunk,ExecutorChunk> toMap() { - Map<WorkChunk,ExecutorChunk> r = new HashMap<WorkChunk,ExecutorChunk>(); - for (int i=0; i<size(); i++) - r.put(get(i),assigned(i)); + public Map<WorkChunk, ExecutorChunk> toMap() { + Map<WorkChunk, ExecutorChunk> r = new HashMap<WorkChunk, ExecutorChunk>(); + for (int i = 0; i < size(); i++) { + r.put(get(i), assigned(i)); + } return r; } /** - * Checks if the assignments made thus far are valid an within the constraints. + * Checks if the assignments made thus far are valid an within the + * constraints. */ public boolean isPartiallyValid() { int[] used = new int[executors.size()]; - for (int i=0; i<mapping.length; i++) { + for (int i = 0; i < mapping.length; i++) { ExecutorChunk ec = mapping[i]; - if (ec==null) continue; - if (!ec.canAccept(works(i))) + if (ec == null) { + continue; + } + if (!ec.canAccept(works(i))) { return false; // invalid assignment - if ((used[ec.index] += works(i).size()) > ec.capacity()) + } + if ((used[ec.index] += works(i).size()) > ec.capacity()) { return false; + } } return true; } /** - * Makes sure that all the assignments are made and it is within the constraints. + * Makes sure that all the assignments are made and it is within the + * constraints. */ public boolean isCompletelyValid() { - for (ExecutorChunk ec : mapping) - if (ec==null) return false; // unassigned + for (ExecutorChunk ec : mapping) { + if (ec == null) { + return false; // unassigned + } + } return isPartiallyValid(); } /** - * Executes this mapping by handing over {@link Executable}s to {@link JobOffer} - * as defined by the mapping. + * Executes this mapping by handing over {@link Executable}s to + * {@link JobOffer} as defined by the mapping. */ public void execute(WorkUnitContext wuc) { - if (!isCompletelyValid()) + if (!isCompletelyValid()) { throw new IllegalStateException(); + } - for (int i=0; i<size(); i++) - assigned(i).execute(get(i),wuc); + for (int i = 0; i < size(); i++) { + assigned(i).execute(get(i), wuc); + } } } public MappingWorksheet(BuildableItem item, List<? extends ExecutorSlot> offers) { - this(item,offers,LoadPredictor.all()); + this(item, offers, LoadPredictor.all()); } public MappingWorksheet(BuildableItem item, List<? extends ExecutorSlot> offers, Collection<? extends LoadPredictor> loadPredictors) { this.item = item; - + // group executors by their computers - Map<Computer,List<ExecutorSlot>> j = new HashMap<Computer, List<ExecutorSlot>>(); + Map<Computer, List<ExecutorSlot>> j = new HashMap<Computer, List<ExecutorSlot>>(); for (ExecutorSlot o : offers) { Computer c = o.getExecutor().getOwner(); List<ExecutorSlot> l = j.get(c); - if (l==null) - j.put(c,l=new ArrayList<ExecutorSlot>()); + if (l == null) { + j.put(c, l = new ArrayList<ExecutorSlot>()); + } l.add(o); } @@ -339,15 +353,18 @@ public class MappingWorksheet { int peak = 0; OUTER: for (LoadPredictor lp : loadPredictors) { - for (FutureLoad fl : Iterables.limit(lp.predict(this,e.getKey(), now, now + duration),100)) { - peak = max(peak,timeline.insert(fl.startTime, fl.startTime+fl.duration, fl.numExecutors)); - if (peak>=max) break OUTER; + for (FutureLoad fl : Iterables.limit(lp.predict(this, e.getKey(), now, now + duration), 100)) { + peak = max(peak, timeline.insert(fl.startTime, fl.startTime + fl.duration, fl.numExecutors)); + if (peak >= max) { + break OUTER; + } } } - int minIdle = max-peak; // minimum number of idle nodes during this time period - if (minIdle<list.size()) - e.setValue(list.subList(0,minIdle)); + int minIdle = max - peak; // minimum number of idle nodes during this time period + if (minIdle < list.size()) { + e.setValue(list.subList(0, minIdle)); + } } } } @@ -355,29 +372,36 @@ public class MappingWorksheet { // build into the final shape List<ExecutorChunk> executors = new ArrayList<ExecutorChunk>(); for (List<ExecutorSlot> group : j.values()) { - if (group.isEmpty()) continue; // evict empty group + if (group.isEmpty()) { + continue; // evict empty group + } ExecutorChunk ec = new ExecutorChunk(group, executors.size()); - if (ec.node==null) continue; // evict out of sync node + if (ec.node == null) { + continue; // evict out of sync node + } executors.add(ec); } this.executors = ImmutableList.copyOf(executors); // group execution units into chunks. use of LinkedHashMap ensures that the main work comes at the top - Map<Object,List<SubTask>> m = new LinkedHashMap<Object,List<SubTask>>(); + Map<Object, List<SubTask>> m = new LinkedHashMap<Object, List<SubTask>>(); for (SubTask meu : Tasks.getSubTasksOf(item.task)) { Object c = Tasks.getSameNodeConstraintOf(meu); - if (c==null) c = new Object(); + if (c == null) { + c = new Object(); + } List<SubTask> l = m.get(c); - if (l==null) - m.put(c,l= new ArrayList<SubTask>()); + if (l == null) { + m.put(c, l = new ArrayList<SubTask>()); + } l.add(meu); } // build into the final shape List<WorkChunk> works = new ArrayList<WorkChunk>(); for (List<SubTask> group : m.values()) { - works.add(new WorkChunk(group,works.size())); + works.add(new WorkChunk(group, works.size())); } this.works = ImmutableList.copyOf(works); } @@ -391,6 +415,7 @@ public class MappingWorksheet { } public static abstract class ExecutorSlot { + public abstract Executor getExecutor(); public abstract boolean isAvailable(); diff --git a/hudson-core/src/main/java/hudson/model/queue/QueueSorter.java b/hudson-core/src/main/java/hudson/model/queue/QueueSorter.java index 76155cb..501775c 100644 --- a/hudson-core/src/main/java/hudson/model/queue/QueueSorter.java +++ b/hudson-core/src/main/java/hudson/model/queue/QueueSorter.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ @@ -32,18 +32,18 @@ import static hudson.init.InitMilestone.JOB_LOADED; * @since 1.343 */ public abstract class QueueSorter implements ExtensionPoint { + /** - * Sorts the buildable items list. The items at the beginning will be executed - * before the items at the end of the list. + * Sorts the buildable items list. The items at the beginning will be + * executed before the items at the end of the list. * - * @param buildables - * List of buildable items in the queue. Never null. + * @param buildables List of buildable items in the queue. Never null. */ public abstract void sortBuildableItems(List<BuildableItem> buildables); /** - * All registered {@link QueueSorter}s. Only the first one will be picked up, - * unless explicitly overridden by {@link Queue#setSorter(QueueSorter)}. + * All registered {@link QueueSorter}s. Only the first one will be picked + * up, unless explicitly overridden by {@link Queue#setSorter(QueueSorter)}. */ public static ExtensionList<QueueSorter> all() { return Hudson.getInstance().getExtensionList(QueueSorter.class); @@ -54,18 +54,21 @@ public abstract class QueueSorter implements ExtensionPoint { * * {@link Queue#Queue(hudson.model.LoadBalancer)} is too early to do this */ - @Initializer(after=JOB_LOADED) + @Initializer(after = JOB_LOADED) public static void installDefaultQueueSorter() { ExtensionList<QueueSorter> all = all(); - if (all.isEmpty()) return; + if (all.isEmpty()) { + return; + } Queue q = Hudson.getInstance().getQueue(); - if (q.getSorter()!=null) return; // someone has already installed something. leave that alone. - + if (q.getSorter() != null) { + return; // someone has already installed something. leave that alone. + } q.setSorter(all.get(0)); - if (all.size()>1) - LOGGER.warning("Multiple QueueSorters are registered. Only the first one is used and the rest are ignored: "+all); + if (all.size() > 1) { + LOGGER.warning("Multiple QueueSorters are registered. Only the first one is used and the rest are ignored: " + all); + } } - private static final Logger LOGGER = Logger.getLogger(QueueSorter.class.getName()); } diff --git a/hudson-core/src/main/java/hudson/model/queue/QueueTaskDispatcher.java b/hudson-core/src/main/java/hudson/model/queue/QueueTaskDispatcher.java index 555aa6f..1946df0 100644 --- a/hudson-core/src/main/java/hudson/model/queue/QueueTaskDispatcher.java +++ b/hudson-core/src/main/java/hudson/model/queue/QueueTaskDispatcher.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -27,30 +27,33 @@ import hudson.model.Queue.Task; /** * Vetos the execution of a task on a node * - * <p> - * To register your dispatcher implementations, put @{@link Extension} on your subtypes. + * <p> To register your dispatcher implementations, put + * + * @{@link Extension} on your subtypes. * * @author Kohsuke Kawaguchi * @since 1.360 */ public abstract class QueueTaskDispatcher implements ExtensionPoint { + /** - * Called whenever {@link Queue} is considering to execute the given task on a given node. + * Called whenever {@link Queue} is considering to execute the given task on + * a given node. * - * <p> - * Implementations can return null to indicate that the assignment is fine, or it can return - * a non-null instance to block the execution of the task on the given node. + * <p> Implementations can return null to indicate that the assignment is + * fine, or it can return a non-null instance to block the execution of the + * task on the given node. * - * <p> - * Queue doesn't remember/cache the response from dispatchers, and instead it'll keep asking. - * The upside of this is that it's very easy to block execution for a limited time period ( - * as you just need to return null when it's ready to execute.) The downside of this is that - * the decision needs to be made quickly. + * <p> Queue doesn't remember/cache the response from dispatchers, and + * instead it'll keep asking. The upside of this is that it's very easy to + * block execution for a limited time period ( as you just need to return + * null when it's ready to execute.) The downside of this is that the + * decision needs to be made quickly. * - * <p> - * Vetos are additive. When multiple {@link QueueTaskDispatcher}s are in the system, - * the task won't run on the given node if any one of them returns a non-null value. - * (This relationship is also the same with built-in check logic.) + * <p> Vetos are additive. When multiple {@link QueueTaskDispatcher}s are in + * the system, the task won't run on the given node if any one of them + * returns a non-null value. (This relationship is also the same with + * built-in check logic.) */ public abstract CauseOfBlockage canTake(Node node, Task task); diff --git a/hudson-core/src/main/java/hudson/model/queue/QueueTaskFilter.java b/hudson-core/src/main/java/hudson/model/queue/QueueTaskFilter.java index 1c73c9f..e17178c 100644 --- a/hudson-core/src/main/java/hudson/model/queue/QueueTaskFilter.java +++ b/hudson-core/src/main/java/hudson/model/queue/QueueTaskFilter.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -33,6 +33,7 @@ import java.util.Collection; * @since 1.360 */ public abstract class QueueTaskFilter implements Queue.Task { + private final Queue.Task base; protected QueueTaskFilter(Task base) { diff --git a/hudson-core/src/main/java/hudson/model/queue/SubTask.java b/hudson-core/src/main/java/hudson/model/queue/SubTask.java index 1bc2e14..2582967 100644 --- a/hudson-core/src/main/java/hudson/model/queue/SubTask.java +++ b/hudson-core/src/main/java/hudson/model/queue/SubTask.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -26,42 +26,42 @@ import hudson.model.ResourceActivity; import java.io.IOException; /** - * A component of {@link Task} that represents a computation carried out by a single {@link Executor}. + * A component of {@link Task} that represents a computation carried out by a + * single {@link Executor}. * * A {@link Task} consists of a number of {@link SubTask}. * - * <p> - * Plugins are encouraged to extend from {@link AbstractSubTask} - * instead of implementing this interface directly, to maintain - * compatibility with future changes to this interface. + * <p> Plugins are encouraged to extend from {@link AbstractSubTask} instead of + * implementing this interface directly, to maintain compatibility with future + * changes to this interface. * * @since 1.377 */ public interface SubTask extends ResourceActivity { + /** - * If this task needs to be run on a node with a particular label, - * return that {@link Label}. Otherwise null, indicating - * it can run on anywhere. + * If this task needs to be run on a node with a particular label, return + * that {@link Label}. Otherwise null, indicating it can run on anywhere. */ Label getAssignedLabel(); /** - * If the previous execution of this task run on a certain node - * and this task prefers to run on the same node, return that. - * Otherwise null. + * If the previous execution of this task run on a certain node and this + * task prefers to run on the same node, return that. Otherwise null. */ Node getLastBuiltOn(); /** - * Estimate of how long will it take to execute this task. - * Measured in milliseconds. + * Estimate of how long will it take to execute this task. Measured in + * milliseconds. * * @return -1 if it's impossible to estimate. */ long getEstimatedDuration(); /** - * Creates {@link Executable}, which performs the actual execution of the task. + * Creates {@link Executable}, which performs the actual execution of the + * task. */ Executable createExecutable() throws IOException; @@ -71,9 +71,10 @@ public interface SubTask extends ResourceActivity { Task getOwnerTask(); /** - * If a subset of {@link SubTask}s of a {@link Task} needs to be collocated with other {@link SubTask}s, - * those {@link SubTask}s should return the equal object here. If null, the execution unit isn't under a - * colocation constraint. + * If a subset of {@link SubTask}s of a {@link Task} needs to be collocated + * with other {@link SubTask}s, those {@link SubTask}s should return the + * equal object here. If null, the execution unit isn't under a colocation + * constraint. */ Object getSameNodeConstraint(); } diff --git a/hudson-core/src/main/java/hudson/model/queue/SubTaskContributor.java b/hudson-core/src/main/java/hudson/model/queue/SubTaskContributor.java index bbcee35..c5e0529 100644 --- a/hudson-core/src/main/java/hudson/model/queue/SubTaskContributor.java +++ b/hudson-core/src/main/java/hudson/model/queue/SubTaskContributor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -26,16 +26,19 @@ import java.util.Collection; import java.util.Collections; /** - * Externally contributes {@link SubTask}s to {@link AbstractProject#getSubTasks()}. + * Externally contributes {@link SubTask}s to + * {@link AbstractProject#getSubTasks()}. * - * <p> - * Put @{@link Extension} on your implementation classes to register them. + * <p> Put + * + * @{@link Extension} on your implementation classes to register them. * * @author Kohsuke Kawaguchi * @since 1.377 */ public abstract class SubTaskContributor implements ExtensionPoint { - public Collection<? extends SubTask> forProject(AbstractProject<?,?> p) { + + public Collection<? extends SubTask> forProject(AbstractProject<?, ?> p) { return Collections.emptyList(); } diff --git a/hudson-core/src/main/java/hudson/model/queue/Tasks.java b/hudson-core/src/main/java/hudson/model/queue/Tasks.java index fb7d2e6..a718212 100644 --- a/hudson-core/src/main/java/hudson/model/queue/Tasks.java +++ b/hudson-core/src/main/java/hudson/model/queue/Tasks.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -30,8 +30,8 @@ import java.util.Collections; public class Tasks { /** - * A pointless function to work around what appears to be a HotSpot problem. See HUDSON-5756 and bug 6933067 - * on BugParade for more details. + * A pointless function to work around what appears to be a HotSpot problem. + * See HUDSON-5756 and bug 6933067 on BugParade for more details. */ private static Collection<? extends SubTask> _getSubTasksOf(Task task) { return task.getSubTasks(); @@ -46,8 +46,8 @@ public class Tasks { } /** - * A pointless function to work around what appears to be a HotSpot problem. See HUDSON-5756 and bug 6933067 - * on BugParade for more details. + * A pointless function to work around what appears to be a HotSpot problem. + * See HUDSON-5756 and bug 6933067 on BugParade for more details. */ private static Object _getSameNodeConstraintOf(SubTask t) { return t.getSameNodeConstraint(); @@ -62,8 +62,8 @@ public class Tasks { } /** - * A pointless function to work around what appears to be a HotSpot problem. See HUDSON-5756 and bug 6933067 - * on BugParade for more details. + * A pointless function to work around what appears to be a HotSpot problem. + * See HUDSON-5756 and bug 6933067 on BugParade for more details. */ public static Task _getOwnerTaskOf(SubTask t) { return t.getOwnerTask(); @@ -73,7 +73,7 @@ public class Tasks { try { return _getOwnerTaskOf(t); } catch (AbstractMethodError e) { - return (Task)t; + return (Task) t; } } } diff --git a/hudson-core/src/main/java/hudson/model/queue/Timeline.java b/hudson-core/src/main/java/hudson/model/queue/Timeline.java index 795fefa..d82ed05 100644 --- a/hudson-core/src/main/java/hudson/model/queue/Timeline.java +++ b/hudson-core/src/main/java/hudson/model/queue/Timeline.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -23,22 +23,24 @@ import java.util.TreeMap; import static java.lang.Math.*; /** -* Represents a mutable q(t), a discrete value that changes over the time. -* -* <p> -* Internally represented by a set of ranges and the value of q(t) in that range, -* as a map from "starting time of a range" to "value of q(t)". -*/ + * Represents a mutable q(t), a discrete value that changes over the time. + * +* <p> Internally represented by a set of ranges and the value of q(t) in that + * range, as a map from "starting time of a range" to "value of q(t)". + */ final class Timeline { // int[] is always length=1 + private final TreeMap<Long, int[]> data = new TreeMap<Long, int[]>(); /** * Obtains q(t) for the given t. */ private int at(long t) { - SortedMap<Long, int[]> head = data.subMap(t,Long.MAX_VALUE); - if (head.isEmpty()) return 0; + SortedMap<Long, int[]> head = data.subMap(t, Long.MAX_VALUE); + if (head.isEmpty()) { + return 0; + } return data.get(head.firstKey())[0]; } @@ -56,8 +58,9 @@ final class Timeline { * Splits the range set at the given timestamp (if it hasn't been split yet) */ private void splitAt(long t) { - if (data.containsKey(t)) return; // already split at this timestamp - + if (data.containsKey(t)) { + return; // already split at this timestamp + } SortedMap<Long, int[]> head = data.headMap(t); int v = head.isEmpty() ? 0 : data.get(head.lastKey())[0]; @@ -81,33 +84,33 @@ final class Timeline { } /** - * Finds a "valley" in this timeline that fits the given duration. - * <p> - * More formally, find smallest x that: - * <ul> - * <li>x >= start - * <li>q(t) <= n for all t \in [x,x+duration) - * </ul> + * Finds a "valley" in this timeline that fits the given duration. <p> More + * formally, find smallest x that: <ul> <li>x >= start <li>q(t) <= n for all + * t \in [x,x+duration) </ul> * - * @return null - * if no such x was found. + * @return null if no such x was found. */ Long fit(long start, long duration, int n) { OUTER: while (true) { long t = start; // check if 'start' satisfies the two conditions by moving t across [start,start+duration) - while ((t-start)<duration) { - if (at(t)>n) { + while ((t - start) < duration) { + if (at(t) > n) { // value too big. what's the next t that's worth trying? Long nxt = next(t); - if (nxt==null) return null; + if (nxt == null) { + return null; + } start = nxt; continue OUTER; } else { Long nxt = next(t); - if (nxt==null) t = Long.MAX_VALUE; - else t = nxt; + if (nxt == null) { + t = Long.MAX_VALUE; + } else { + t = nxt; + } } } // q(t) looks good at the entire [start,start+duration) diff --git a/hudson-core/src/main/java/hudson/model/queue/WorkUnit.java b/hudson-core/src/main/java/hudson/model/queue/WorkUnit.java index 6bd9b8f..6bc820b 100644 --- a/hudson-core/src/main/java/hudson/model/queue/WorkUnit.java +++ b/hudson-core/src/main/java/hudson/model/queue/WorkUnit.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -30,18 +30,17 @@ import org.kohsuke.stapler.export.ExportedBean; */ @ExportedBean public final class WorkUnit { + /** * Task to be executed. */ //TODO: review and check whether we can do it private public final SubTask work; - /** * Shared context among {@link WorkUnit}s. */ //TODO: review and check whether we can do it private public final WorkUnitContext context; - private volatile Executor executor; WorkUnit(WorkUnitContext context, SubTask work) { @@ -58,8 +57,7 @@ public final class WorkUnit { } /** - * {@link Executor} running this work unit. - * <p> + * {@link Executor} running this work unit. <p> * {@link Executor#getCurrentWorkUnit()} and {@link WorkUnit#getExecutor()} * form a bi-directional reachability between them. */ @@ -75,7 +73,7 @@ public final class WorkUnit { * If the execution has already started, return the current executable. */ public Executable getExecutable() { - return executor!=null ? executor.getCurrentExecutable() : null; + return executor != null ? executor.getCurrentExecutable() : null; } /** @@ -83,6 +81,6 @@ public final class WorkUnit { * represented by {@link Task} itself. */ public boolean isMainWork() { - return context.task==work; + return context.task == work; } } diff --git a/hudson-core/src/main/java/hudson/model/queue/WorkUnitContext.java b/hudson-core/src/main/java/hudson/model/queue/WorkUnitContext.java index 73b57e5..925cae6 100644 --- a/hudson-core/src/main/java/hudson/model/queue/WorkUnitContext.java +++ b/hudson-core/src/main/java/hudson/model/queue/WorkUnitContext.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -27,7 +27,8 @@ import java.util.Collections; import java.util.List; /** - * Holds the information shared between {@link WorkUnit}s created from the same {@link Task}. + * Holds the information shared between {@link WorkUnit}s created from the same + * {@link Task}. * * @author Kohsuke Kawaguchi */ @@ -35,37 +36,33 @@ public final class WorkUnitContext { //TODO: review and check whether we can do it private public final BuildableItem item; - //TODO: review and check whether we can do it private public final Task task; - /** - * Once the execution is complete, update this future object with the outcome. + * Once the execution is complete, update this future object with the + * outcome. */ //TODO: review and check whether we can do it private public final FutureImpl future; - /** * Associated parameters to the build. */ //TODO: review and check whether we can do it private public final List<Action> actions; - private final Latch startLatch, endLatch; - private List<WorkUnit> workUnits = new ArrayList<WorkUnit>(); - /** - * If the execution is aborted, set to non-null that indicates where it was aborted. + * If the execution is aborted, set to non-null that indicates where it was + * aborted. */ private volatile Throwable aborted; public WorkUnitContext(BuildableItem item) { this.item = item; this.task = item.task; - this.future = (FutureImpl)item.getFuture(); + this.future = (FutureImpl) item.getFuture(); this.actions = item.getActions(); - + // +1 for the main task int workUnitSize = Tasks.getSubTasksOf(task).size(); startLatch = new Latch(workUnitSize) { @@ -75,7 +72,7 @@ public final class WorkUnitContext { // the one that executes the main thing will send notifications Executor e = Executor.currentExecutor(); if (e.getCurrentWorkUnit().isMainWork()) { - e.getOwner().taskAccepted(e,task); + e.getOwner().taskAccepted(e, task); } } }; @@ -100,8 +97,8 @@ public final class WorkUnitContext { } /** - * Called by the executor that executes a member {@link SubTask} that belongs to this task - * to create its {@link WorkUnit}. + * Called by the executor that executes a member {@link SubTask} that + * belongs to this task to create its {@link WorkUnit}. */ public WorkUnit createWorkUnit(SubTask execUnit) { future.addExecutor(Executor.currentExecutor()); @@ -119,18 +116,20 @@ public final class WorkUnitContext { } /** - * All the {@link Executor}s that jointly execute a {@link Task} call this method to synchronize on the start. + * All the {@link Executor}s that jointly execute a {@link Task} call this + * method to synchronize on the start. */ public void synchronizeStart() throws InterruptedException { startLatch.synchronize(); } /** - * All the {@link Executor}s that jointly execute a {@link Task} call this method to synchronize on the end of the task. + * All the {@link Executor}s that jointly execute a {@link Task} call this + * method to synchronize on the end of the task. * - * @throws InterruptedException - * If any of the member thread is interrupted while waiting for other threads to join, all - * the member threads will report {@link InterruptedException}. + * @throws InterruptedException If any of the member thread is interrupted + * while waiting for other threads to join, all the member threads will + * report {@link InterruptedException}. */ public void synchronizeEnd(Queue.Executable executable, Throwable problems, long duration) throws InterruptedException { endLatch.synchronize(); @@ -150,11 +149,16 @@ public final class WorkUnitContext { } /** - * When one of the work unit is aborted, call this method to abort all the other work units. + * When one of the work unit is aborted, call this method to abort all the + * other work units. */ public synchronized void abort(Throwable cause) { - if (cause==null) throw new IllegalArgumentException(); - if (aborted!=null) return; // already aborted + if (cause == null) { + throw new IllegalArgumentException(); + } + if (aborted != null) { + return; // already aborted + } aborted = cause; startLatch.abort(cause); endLatch.abort(cause); @@ -162,8 +166,9 @@ public final class WorkUnitContext { Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); - if (e!=null && e!=c) + if (e != null && e != c) { e.interrupt(); + } } } } |

