| author | Henrik Lynggaard Hansen | 2012-07-15 14:52:20 (EDT) |
|---|---|---|
| committer | Henrik Lynggaard Hansen | 2012-07-15 14:52:20 (EDT) |
| commit | 920393b85239cf430a97f5f1f27fed9a5db0f9cd (patch) (side-by-side diff) | |
| tree | 99ddff8494d3c9f021b11f682b993e5c06a589b3 | |
| parent | 2e3f55d880a7c54c95afb2f243678f960c79c6bf (diff) | |
| download | org.eclipse.hudson.core-920393b85239cf430a97f5f1f27fed9a5db0f9cd.zip org.eclipse.hudson.core-920393b85239cf430a97f5f1f27fed9a5db0f9cd.tar.gz org.eclipse.hudson.core-920393b85239cf430a97f5f1f27fed9a5db0f9cd.tar.bz2 | |
Reformat hudson.tools and hudson.triggersrefs/changes/90/6790/1
Change-Id: I4a5470ccde28e446500f1729a9692816f94f487f
Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
21 files changed, 520 insertions, 455 deletions
diff --git a/hudson-core/src/main/java/hudson/tools/CommandInstaller.java b/hudson-core/src/main/java/hudson/tools/CommandInstaller.java index 8fd4922..93fe1bd 100644 --- a/hudson-core/src/main/java/hudson/tools/CommandInstaller.java +++ b/hudson-core/src/main/java/hudson/tools/CommandInstaller.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -28,6 +28,7 @@ import org.kohsuke.stapler.QueryParameter; /** * Installs a tool by running an arbitrary shell command. + * * @since 1.305 */ public class CommandInstaller extends ToolInstaller { @@ -36,7 +37,6 @@ public class CommandInstaller extends ToolInstaller { * Command to execute, similar to {@link CommandInterpreter#command}. */ private final String command; - /** * Resulting tool home directory. */ @@ -95,7 +95,5 @@ public class CommandInstaller extends ToolInstaller { return FormValidation.error(Messages.CommandInstaller_no_toolHome()); } } - } - } diff --git a/hudson-core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java b/hudson-core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java index b90faa1..aa0e269 100644 --- a/hudson-core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java +++ b/hudson-core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ @@ -28,17 +28,18 @@ import java.util.List; import java.net.URL; /** - * Partial convenience implementation of {@link ToolInstaller} that just downloads - * an archive from the URL and extracts it. + * Partial convenience implementation of {@link ToolInstaller} that just + * downloads an archive from the URL and extracts it. * - * <p> - * Each instance of this is configured to download from a specific URL identified by an ID. + * <p> Each instance of this is configured to download from a specific URL + * identified by an ID. * * @author Kohsuke Kawaguchi * @since 1.308 */ public abstract class DownloadFromUrlInstaller extends ToolInstaller { //TODO: review and check whether we can do it private + public final String id; @DataBoundConstructor @@ -54,10 +55,12 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { } /** - * Checks if the specified expected location already contains the installed version of the tool. + * Checks if the specified expected location already contains the installed + * version of the tool. * - * This check needs to run fairly efficiently. The current implementation uses the souce URL of {@link Installable}, - * based on the assumption that released bits do not change its content. + * This check needs to run fairly efficiently. The current implementation + * uses the souce URL of {@link Installable}, based on the assumption that + * released bits do not change its content. */ protected boolean isUpToDate(FilePath expectedLocation, Installable i) throws IOException, InterruptedException { FilePath marker = expectedLocation.child(".installedFrom"); @@ -70,9 +73,11 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { * @return null if no such ID is found. */ public Installable getInstallable() throws IOException { - for (Installable i : ((DescriptorImpl<?>)getDescriptor()).getInstallables()) - if(id.equals(i.id)) + for (Installable i : ((DescriptorImpl<?>) getDescriptor()).getInstallables()) { + if (id.equals(i.id)) { return i; + } + } return null; } @@ -80,21 +85,23 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { FilePath expected = preferredLocation(tool, node); Installable inst = getInstallable(); - if(inst==null) { - log.getLogger().println("Invalid tool ID "+id); + if (inst == null) { + log.getLogger().println("Invalid tool ID " + id); return expected; } - if(isUpToDate(expected,inst)) + if (isUpToDate(expected, inst)) { return expected; + } - if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) { + if (expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) { expected.child(".timestamp").delete(); // we don't use the timestamp FilePath base = findPullUpDirectory(expected); - if(base!=null && base!=expected) + if (base != null && base != expected) { base.moveAllChildrenTo(expected); + } // leave a record for the next up-to-date check - expected.child(".installedFrom").write(inst.url,"UTF-8"); + expected.child(".installedFrom").write(inst.url, "UTF-8"); expected.act(new ZipExtractionInstaller.ChmodRecAPlusX()); } @@ -102,41 +109,43 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { } /** - * Often an archive contains an extra top-level directory that's unnecessary when extracted on the disk - * into the expected location. If your installation sources provide that kind of archives, override - * this method to find the real root location. + * Often an archive contains an extra top-level directory that's unnecessary + * when extracted on the disk into the expected location. If your + * installation sources provide that kind of archives, override this method + * to find the real root location. * - * <p> - * The caller will "pull up" the discovered real root by throw away the intermediate directory, - * so that the user-configured "tool home" directory contains the right files. + * <p> The caller will "pull up" the discovered real root by throw away the + * intermediate directory, so that the user-configured "tool home" directory + * contains the right files. * - * <p> - * The default implementation applies some heuristics to auto-determine if the pull up is necessary. - * This should work for typical archive files. + * <p> The default implementation applies some heuristics to auto-determine + * if the pull up is necessary. This should work for typical archive files. * - * @param root - * The directory that contains the extracted archive. This directory contains nothing but the - * extracted archive. For example, if the user installed - * http://archive.apache.org/dist/ant/binaries/jakarta-ant-1.1.zip , this directory would contain - * a single directory "jakarta-ant". + * @param root The directory that contains the extracted archive. This + * directory contains nothing but the extracted archive. For example, if the + * user installed + * http://archive.apache.org/dist/ant/binaries/jakarta-ant-1.1.zip , this + * directory would contain a single directory "jakarta-ant". * - * @return - * Return the real top directory inside {@code root} that contains the meat. In the above example, - * <tt>root.child("jakarta-ant")</tt> should be returned. If there's no directory to pull up, - * return null. + * @return Return the real top directory inside {@code root} that contains + * the meat. In the above example, <tt>root.child("jakarta-ant")</tt> should + * be returned. If there's no directory to pull up, return null. */ protected FilePath findPullUpDirectory(FilePath root) throws IOException, InterruptedException { // if the directory just contains one directory and that alone, assume that's the pull up subject // otherwise leave it as is. List<FilePath> children = root.list(); - if(children.size()!=1) return null; - if(children.get(0).isDirectory()) + if (children.size() != 1) { + return null; + } + if (children.get(0).isDirectory()) { return children.get(0); + } return null; } public static abstract class DescriptorImpl<T extends DownloadFromUrlInstaller> extends ToolInstallerDescriptor<T> { - + @SuppressWarnings("deprecation") // intentionally adding dynamic item here protected DescriptorImpl() { Downloadable.all().add(createDownloadable()); @@ -147,27 +156,29 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { } /** - * This ID needs to be unique, and needs to match the ID token in the JSON update file. - * <p> - * By default we use the fully-qualified class name of the {@link DownloadFromUrlInstaller} subtype. + * This ID needs to be unique, and needs to match the ID token in the + * JSON update file. <p> By default we use the fully-qualified class + * name of the {@link DownloadFromUrlInstaller} subtype. */ public String getId() { - return clazz.getName().replace('$','.'); + return clazz.getName().replace('$', '.'); } /** * List of installable tools. * - * <p> - * The UI uses this information to populate the drop-down. Subtypes can override this method - * if it wants to change the way the list is filled. + * <p> The UI uses this information to populate the drop-down. Subtypes + * can override this method if it wants to change the way the list is + * filled. * * @return never null. */ public List<? extends Installable> getInstallables() throws IOException { JSONObject d = Downloadable.get(getId()).getData(); - if(d==null) return Collections.emptyList(); - return Arrays.asList(((InstallableList)JSONObject.toBean(d,InstallableList.class)).list); + if (d == null) { + return Collections.emptyList(); + } + return Arrays.asList(((InstallableList) JSONObject.toBean(d, InstallableList.class)).list); } } @@ -177,6 +188,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { public static class InstallableList { // initialize with an empty array just in case JSON doesn't have the list field (which shouldn't happen.) //TODO: review and check whether we can do it private + public Installable[] list = new Installable[0]; public Installable[] getList() { @@ -193,6 +205,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { */ public static class Installable { //TODO: review and check whether we can do it private + /** * Used internally to uniquely identify the name. */ diff --git a/hudson-core/src/main/java/hudson/tools/InstallSourceProperty.java b/hudson-core/src/main/java/hudson/tools/InstallSourceProperty.java index 7f88482..c8f78ab 100644 --- a/hudson-core/src/main/java/hudson/tools/InstallSourceProperty.java +++ b/hudson-core/src/main/java/hudson/tools/InstallSourceProperty.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -34,6 +34,7 @@ import java.io.IOException; public class InstallSourceProperty extends ToolProperty<ToolInstallation> { // TODO: get the proper Saveable //TODO: review and check whether we can do it private + public final DescribableList<ToolInstaller, Descriptor<ToolInstaller>> installers = new DescribableList<ToolInstaller, Descriptor<ToolInstaller>>(Saveable.NOOP); @@ -51,8 +52,9 @@ public class InstallSourceProperty extends ToolProperty<ToolInstallation> { @Override public void setTool(ToolInstallation t) { super.setTool(t); - for (ToolInstaller installer : installers) + for (ToolInstaller installer : installers) { installer.setTool(t); + } } public Class<ToolInstallation> type() { @@ -61,6 +63,7 @@ public class InstallSourceProperty extends ToolProperty<ToolInstallation> { @Extension public static class DescriptorImpl extends ToolPropertyDescriptor { + public String getDisplayName() { return Messages.InstallSourceProperty_DescriptorImpl_displayName(); } diff --git a/hudson-core/src/main/java/hudson/tools/InstallerTranslator.java b/hudson-core/src/main/java/hudson/tools/InstallerTranslator.java index b7c1d39..140222b 100644 --- a/hudson-core/src/main/java/hudson/tools/InstallerTranslator.java +++ b/hudson-core/src/main/java/hudson/tools/InstallerTranslator.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -26,12 +26,13 @@ import java.util.concurrent.Semaphore; /** * Actually runs installations. + * * @since 1.305 */ @Extension public class InstallerTranslator extends ToolLocationTranslator { - private static final Map<Node,Map<ToolInstallation,Semaphore>> mutexByNode = new WeakHashMap<Node,Map<ToolInstallation,Semaphore>>(); + private static final Map<Node, Map<ToolInstallation, Semaphore>> mutexByNode = new WeakHashMap<Node, Map<ToolInstallation, Semaphore>>(); public String getToolHome(Node node, ToolInstallation tool, TaskListener log) throws IOException, InterruptedException { InstallSourceProperty isp = tool.getProperties().get(InstallSourceProperty.class); @@ -58,5 +59,4 @@ public class InstallerTranslator extends ToolLocationTranslator { } return null; } - } diff --git a/hudson-core/src/main/java/hudson/tools/PropertyDescriptor.java b/hudson-core/src/main/java/hudson/tools/PropertyDescriptor.java index ccf0051..754282f 100644 --- a/hudson-core/src/main/java/hudson/tools/PropertyDescriptor.java +++ b/hudson-core/src/main/java/hudson/tools/PropertyDescriptor.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ @@ -24,14 +24,14 @@ import java.util.List; /** * Base {@link Descriptor} type used for {@code XyzProperty} classes. * - * @param <P> - * Type of the {@code XyzProperty}. Called 'property type' - * @param <T> - * Type of the {@code Xyz}, that the property attaches to. Called 'target type' + * @param <P> Type of the {@code XyzProperty}. Called 'property type' + * @param <T> Type of the {@code Xyz}, that the property attaches to. Called + * 'target type' * @author Kohsuke Kawaguchi * @since 1.305 */ -public abstract class PropertyDescriptor<P extends Describable<P>,T> extends Descriptor<P> { +public abstract class PropertyDescriptor<P extends Describable<P>, T> extends Descriptor<P> { + protected PropertyDescriptor(Class<? extends P> clazz) { super(clazz); } @@ -43,35 +43,36 @@ public abstract class PropertyDescriptor<P extends Describable<P>,T> extends Des * Infer the type parameterization 'P' */ private Class<P> getP() { - return Functions.getTypeParameter(getClass(),Descriptor.class,0); + return Functions.getTypeParameter(getClass(), Descriptor.class, 0); } /** - * Returns true if this property type is applicable to the - * given target type. + * Returns true if this property type is applicable to the given target + * type. * - * <p> - * The default implementation of this method checks if the given node type is assignable - * according to the parameterization, but subtypes can extend this to change this behavior. + * <p> The default implementation of this method checks if the given node + * type is assignable according to the parameterization, but subtypes can + * extend this to change this behavior. * - * @return - * true to indicate applicable, in which case the property will be - * displayed in the configuration screen of the target, for example. + * @return true to indicate applicable, in which case the property will be + * displayed in the configuration screen of the target, for example. */ public boolean isApplicable(Class<? extends T> targetType) { - Class<? extends T> applicable = Functions.getTypeParameter(clazz,getP(),0); + Class<? extends T> applicable = Functions.getTypeParameter(clazz, getP(), 0); return applicable.isAssignableFrom(targetType); } - public static <D extends PropertyDescriptor<?,T>,T> List<D> for_(List<D> all, Class<? extends T> target) { + public static <D extends PropertyDescriptor<?, T>, T> List<D> for_(List<D> all, Class<? extends T> target) { List<D> result = new ArrayList<D>(); - for (D d : all) - if (d.isApplicable(target)) + for (D d : all) { + if (d.isApplicable(target)) { result.add(d); + } + } return result; } - public static <D extends PropertyDescriptor<?,T>,T> List<D> for_(List<D> all, T target) { - return for_(all,(Class)target.getClass()); + public static <D extends PropertyDescriptor<?, T>, T> List<D> for_(List<D> all, T target) { + return for_(all, (Class) target.getClass()); } } diff --git a/hudson-core/src/main/java/hudson/tools/ToolDescriptor.java b/hudson-core/src/main/java/hudson/tools/ToolDescriptor.java index c8b8914..f77cafd 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolDescriptor.java +++ b/hudson-core/src/main/java/hudson/tools/ToolDescriptor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Tom Huybrechts - * + * Contributors: + * + * Tom Huybrechts + * * *******************************************************************************/ @@ -39,41 +39,42 @@ public abstract class ToolDescriptor<T extends ToolInstallation> extends Descrip /** * Configured instances of {@link ToolInstallation}s. * - * @return read-only list of installations; - * can be empty but never null. + * @return read-only list of installations; can be empty but never null. */ public T[] getInstallations() { - - if (installations != null){ + + if (installations != null) { installations.clone(); - }else{ - Class<?> arrayType = installations.getClass().getComponentType(); - installations = (T[])Array.newInstance(arrayType, 0); + } else { + Class<?> arrayType = installations.getClass().getComponentType(); + installations = (T[]) Array.newInstance(arrayType, 0); } - return installations; + return installations; } /** * Overwrites {@link ToolInstallation}s. * - * @param installations list of installations; - * can be empty but never null. + * @param installations list of installations; can be empty but never null. */ public void setInstallations(T... installations) { this.installations = installations.clone(); } /** - * Lists up {@link ToolPropertyDescriptor}s that are applicable to this {@link ToolInstallation}. + * Lists up {@link ToolPropertyDescriptor}s that are applicable to this + * {@link ToolInstallation}. */ public List<ToolPropertyDescriptor> getPropertyDescriptors() { - return PropertyDescriptor.for_(ToolProperty.all(),clazz); + return PropertyDescriptor.for_(ToolProperty.all(), clazz); } /** - * Optional list of installers to be configured by default for new tools of this type. - * If there are popular versions of the tool available using generic installation techniques, - * they can be returned here for the user's convenience. + * Optional list of installers to be configured by default for new tools of + * this type. If there are popular versions of the tool available using + * generic installation techniques, they can be returned here for the user's + * convenience. + * * @since 1.305 */ public List<? extends ToolInstaller> getDefaultInstallers() { @@ -81,16 +82,18 @@ public abstract class ToolDescriptor<T extends ToolInstallation> extends Descrip } /** - * Default value for {@link ToolInstallation#getProperties()} used in the form binding. + * Default value for {@link ToolInstallation#getProperties()} used in the + * form binding. + * * @since 1.305 */ - public DescribableList<ToolProperty<?>,ToolPropertyDescriptor> getDefaultProperties() throws IOException { - DescribableList<ToolProperty<?>,ToolPropertyDescriptor> r - = new DescribableList<ToolProperty<?>, ToolPropertyDescriptor>(NOOP); + public DescribableList<ToolProperty<?>, ToolPropertyDescriptor> getDefaultProperties() throws IOException { + DescribableList<ToolProperty<?>, ToolPropertyDescriptor> r = new DescribableList<ToolProperty<?>, ToolPropertyDescriptor>(NOOP); List<? extends ToolInstaller> installers = getDefaultInstallers(); - if(!installers.isEmpty()) + if (!installers.isEmpty()) { r.add(new InstallSourceProperty(installers)); + } return r; } @@ -101,5 +104,4 @@ public abstract class ToolDescriptor<T extends ToolInstallation> extends Descrip setInstallations(req.bindJSONToList(clazz, json.get("tool")).toArray((T[]) Array.newInstance(clazz, 0))); return true; } - } diff --git a/hudson-core/src/main/java/hudson/tools/ToolInstallation.java b/hudson-core/src/main/java/hudson/tools/ToolInstallation.java index be87081..205299d 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolInstallation.java +++ b/hudson-core/src/main/java/hudson/tools/ToolInstallation.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: * * Tom Huybrechts - * + * * *******************************************************************************/ @@ -34,47 +34,42 @@ import com.thoughtworks.xstream.annotations.XStreamSerializable; import com.thoughtworks.xstream.converters.UnmarshallingContext; /** - * Formalization of a tool installed in nodes used for builds - * (examples include things like JDKs, Ants, Mavens, etc..) + * Formalization of a tool installed in nodes used for builds (examples include + * things like JDKs, Ants, Mavens, etc..) * - * <p> - * You can define such a concept in your plugin entirely on your own, without extending from - * this class, but choosing this class as a base class has several benefits: + * <p> You can define such a concept in your plugin entirely on your own, + * without extending from this class, but choosing this class as a base class + * has several benefits: * - * <ul> - * <li>Hudson allows admins to specify different locations for tools on some slaves. - * For example, JDK on the master might be on /usr/local/java but on a Windows slave - * it could be at c:\Program Files\Java - * <li>Hudson can verify the existence of tools and provide warnings and diagnostics for - * admins. (TBD) - * <li>Hudson can perform automatic installations for users. (TBD) - * </ul> + * <ul> <li>Hudson allows admins to specify different locations for tools on + * some slaves. For example, JDK on the master might be on /usr/local/java but + * on a Windows slave it could be at c:\Program Files\Java <li>Hudson can verify + * the existence of tools and provide warnings and diagnostics for admins. (TBD) + * <li>Hudson can perform automatic installations for users. (TBD) </ul> * - * <p> - * Implementations of this class are strongly encouraged to also implement {@link NodeSpecific} - * (by using {@link #translateFor(Node, TaskListener)}) and + * <p> Implementations of this class are strongly encouraged to also implement + * {@link NodeSpecific} (by using {@link #translateFor(Node, TaskListener)}) and * {@link EnvironmentSpecific} (by using {@link EnvVars#expand(String)}.) * - * <p> - * To contribute an extension point, put {@link Extension} on your {@link ToolDescriptor} class. + * <p> To contribute an extension point, put {@link Extension} on your + * {@link ToolDescriptor} class. * * @author huybrechts * @since 1.286 */ public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInstallation> implements Serializable, ExtensionPoint { + private final String name; private /*almost final*/ String home; - /** * {@link ToolProperty}s that are associated with this tool. */ @XStreamSerializable - private transient /*almost final*/ DescribableList<ToolProperty<?>,ToolPropertyDescriptor> properties - = new DescribableList<ToolProperty<?>,ToolPropertyDescriptor>(Saveable.NOOP); + private transient /*almost final*/ DescribableList<ToolProperty<?>, ToolPropertyDescriptor> properties = new DescribableList<ToolProperty<?>, ToolPropertyDescriptor>(Saveable.NOOP); /** - * @deprecated - * as of 1.302. Use {@link #ToolInstallation(String, String, List)} + * @deprecated as of 1.302. Use + * {@link #ToolInstallation(String, String, List)} */ public ToolInstallation(String name, String home) { this.name = name; @@ -84,11 +79,12 @@ public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInsta public ToolInstallation(String name, String home, List<? extends ToolProperty<?>> properties) { this.name = name; this.home = home; - if(properties!=null) { + if (properties != null) { try { this.properties.replaceBy(properties); - for (ToolProperty<?> p : properties) - _setTool(p,this); + for (ToolProperty<?> p : properties) { + _setTool(p, this); + } } catch (IOException e) { throw new AssertionError(e); // no Saveable, so can't happen } @@ -101,7 +97,8 @@ public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInsta } /** - * Gets the human readable name that identifies this tool among other {@link ToolInstallation}s of the same kind. + * Gets the human readable name that identifies this tool among other + * {@link ToolInstallation}s of the same kind. */ public String getName() { return name; @@ -109,32 +106,31 @@ public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInsta /** * Gets the home directory of this tool. - * - * The path can be in Unix format as well as in Windows format. - * Must be absolute. + * + * The path can be in Unix format as well as in Windows format. Must be + * absolute. */ public String getHome() { return home; } - public DescribableList<ToolProperty<?>,ToolPropertyDescriptor> getProperties() { - assert properties!=null; + public DescribableList<ToolProperty<?>, ToolPropertyDescriptor> getProperties() { + assert properties != null; return properties; } /** - * Finds a tool on a node. - * Checks if the location of the tool is overridden for the given node, and if so, - * return the node-specific home directory. - * Also checks available {@link ToolLocationTranslator}s. - * Otherwise returns {@code installation.getHome()}. + * Finds a tool on a node. Checks if the location of the tool is overridden + * for the given node, and if so, return the node-specific home directory. + * Also checks available {@link ToolLocationTranslator}s. Otherwise returns + * {@code installation.getHome()}. * - * <p> - * This is the core logic behind {@link NodeSpecific#forNode(Node, TaskListener)} for {@link ToolInstallation}, - * and meant to be used by the {@code forNode} implementations. + * <p> This is the core logic behind + * {@link NodeSpecific#forNode(Node, TaskListener)} for + * {@link ToolInstallation}, and meant to be used by the {@code forNode} + * implementations. * - * @return - * never null. + * @return never null. */ @SuppressWarnings("deprecation") protected String translateFor(Node node, TaskListener log) throws IOException, InterruptedException { @@ -145,18 +141,25 @@ public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInsta * Invoked by XStream when this object is read into memory. */ private Object readResolve() { - if(properties==null) - properties = new DescribableList<ToolProperty<?>,ToolPropertyDescriptor>(Saveable.NOOP); - for (ToolProperty<?> p : properties) + if (properties == null) { + properties = new DescribableList<ToolProperty<?>, ToolPropertyDescriptor>(Saveable.NOOP); + } + for (ToolProperty<?> p : properties) { _setTool(p, this); + } return this; } /** - * Subclasses can extend this for data migration from old field storing home directory. + * Subclasses can extend this for data migration from old field storing home + * directory. */ protected static abstract class ToolConverter extends XStream2.PassthruConverter<ToolInstallation> { - public ToolConverter(XStream2 xstream) { super(xstream); } + + public ToolConverter(XStream2 xstream) { + super(xstream); + } + protected void callback(ToolInstallation obj, UnmarshallingContext context) { String s; if (obj.home == null && (s = oldHomeField(obj)) != null) { @@ -164,16 +167,16 @@ public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInsta OldDataMonitor.report(context, "1.286"); } } + protected abstract String oldHomeField(ToolInstallation obj); } /** * Returns all the registered {@link ToolDescriptor}s. */ - public static DescriptorExtensionList<ToolInstallation,ToolDescriptor<?>> all() { + public static DescriptorExtensionList<ToolInstallation, ToolDescriptor<?>> all() { // use getDescriptorList and not getExtensionList to pick up legacy instances - return Hudson.getInstance().<ToolInstallation,ToolDescriptor<?>>getDescriptorList(ToolInstallation.class); + return Hudson.getInstance().<ToolInstallation, ToolDescriptor<?>>getDescriptorList(ToolInstallation.class); } - private static final long serialVersionUID = 1L; } diff --git a/hudson-core/src/main/java/hudson/tools/ToolInstaller.java b/hudson-core/src/main/java/hudson/tools/ToolInstaller.java index 17db0d8..55dbf6c 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolInstaller.java +++ b/hudson-core/src/main/java/hudson/tools/ToolInstaller.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -28,46 +28,50 @@ import java.io.IOException; import org.kohsuke.stapler.DataBoundConstructor; /** - * An object which can ensure that a generic {@link ToolInstallation} in fact exists on a node. + * An object which can ensure that a generic {@link ToolInstallation} in fact + * exists on a node. * - * The subclass should have a {@link ToolInstallerDescriptor}. - * A {@code config.jelly} should be provided to customize specific fields; + * The subclass should have a {@link ToolInstallerDescriptor}. A + * {@code config.jelly} should be provided to customize specific fields; * {@code <t:label xmlns:t="/hudson/tools"/>} to customize {@code label}. - * @see <a href="http://wiki.hudson-ci.org/display/HUDSON/Tool+Auto-Installation">Tool Auto-Installation</a> + * + * @see <a + * href="http://wiki.hudson-ci.org/display/HUDSON/Tool+Auto-Installation">Tool + * Auto-Installation</a> * @since 1.305 */ public abstract class ToolInstaller implements Describable<ToolInstaller>, ExtensionPoint { private final String label; - protected transient ToolInstallation tool; /** - * Subclasses should pass these parameters in using {@link DataBoundConstructor}. + * Subclasses should pass these parameters in using + * {@link DataBoundConstructor}. */ protected ToolInstaller(String label) { this.label = Util.fixEmptyAndTrim(label); } /** - * Called during the initialization to tell {@link ToolInstaller} what {@link ToolInstallation} - * it is configured against. + * Called during the initialization to tell {@link ToolInstaller} what + * {@link ToolInstallation} it is configured against. */ protected void setTool(ToolInstallation t) { this.tool = t; } /** - * Label to limit which nodes this installation can be performed on. - * Can be null to not impose a limit. + * Label to limit which nodes this installation can be performed on. Can be + * null to not impose a limit. */ public final String getLabel() { return label; } /** - * Checks whether this installer can be applied to a given node. - * (By default, just checks the label.) + * Checks whether this installer can be applied to a given node. (By + * default, just checks the label.) */ public boolean appliesTo(Node node) { Label l = Hudson.getInstance().getLabel(label); @@ -75,14 +79,14 @@ public abstract class ToolInstaller implements Describable<ToolInstaller>, Exten } /** - * Ensure that the configured tool is really installed. - * If it is already installed, do nothing. - * Called only if {@link #appliesTo(Node)} are true. + * Ensure that the configured tool is really installed. If it is already + * installed, do nothing. Called only if {@link #appliesTo(Node)} are true. + * * @param tool the tool being installed * @param node the computer on which to install the tool * @param log any status messages produced by the installation go here - * @return the (directory) path at which the tool can be found, - * typically coming from {@link #preferredLocation} + * @return the (directory) path at which the tool can be found, typically + * coming from {@link #preferredLocation} * @throws IOException if installation fails * @throws InterruptedException if communication with a slave is interrupted */ @@ -90,10 +94,12 @@ public abstract class ToolInstaller implements Describable<ToolInstaller>, Exten /** * Convenience method to find a location to install a tool. + * * @param tool the tool being installed * @param node the computer on which to install the tool - * @return {@link ToolInstallation#getHome} if specified, else a path within the local - * Hudson work area named according to {@link ToolInstallation#getName} + * @return {@link ToolInstallation#getHome} if specified, else a path within + * the local Hudson work area named according to + * {@link ToolInstallation#getName} * @since 1.310 */ protected final FilePath preferredLocation(ToolInstallation tool, Node node) { diff --git a/hudson-core/src/main/java/hudson/tools/ToolInstallerDescriptor.java b/hudson-core/src/main/java/hudson/tools/ToolInstallerDescriptor.java index 01c0bb7..236454d 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolInstallerDescriptor.java +++ b/hudson-core/src/main/java/hudson/tools/ToolInstallerDescriptor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -25,33 +25,37 @@ import java.util.ArrayList; /** * Descriptor for a {@link ToolInstaller}. + * * @since 1.305 */ public abstract class ToolInstallerDescriptor<T extends ToolInstaller> extends Descriptor<ToolInstaller> { /** - * Controls what kind of {@link ToolInstallation} this installer can be applied to. + * Controls what kind of {@link ToolInstallation} this installer can be + * applied to. * - * <p> - * By default, this method just returns true to everything, claiming it's applicable to any tool installations. + * <p> By default, this method just returns true to everything, claiming + * it's applicable to any tool installations. */ public boolean isApplicable(Class<? extends ToolInstallation> toolType) { return true; } - public static DescriptorExtensionList<ToolInstaller,ToolInstallerDescriptor<?>> all() { - return Hudson.getInstance().<ToolInstaller,ToolInstallerDescriptor<?>>getDescriptorList(ToolInstaller.class); + public static DescriptorExtensionList<ToolInstaller, ToolInstallerDescriptor<?>> all() { + return Hudson.getInstance().<ToolInstaller, ToolInstallerDescriptor<?>>getDescriptorList(ToolInstaller.class); } /** - * Filters {@link #all()} by eliminating things that are not applicable to the given type. + * Filters {@link #all()} by eliminating things that are not applicable to + * the given type. */ public static List<ToolInstallerDescriptor<?>> for_(Class<? extends ToolInstallation> type) { List<ToolInstallerDescriptor<?>> r = new ArrayList<ToolInstallerDescriptor<?>>(); - for (ToolInstallerDescriptor<?> d : all()) - if(d.isApplicable(type)) + for (ToolInstallerDescriptor<?> d : all()) { + if (d.isApplicable(type)) { r.add(d); + } + } return r; } - } diff --git a/hudson-core/src/main/java/hudson/tools/ToolLocationNodeProperty.java b/hudson-core/src/main/java/hudson/tools/ToolLocationNodeProperty.java index 9856b62..08ea7b4 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolLocationNodeProperty.java +++ b/hudson-core/src/main/java/hudson/tools/ToolLocationNodeProperty.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Tom Huybrechts - * + * Contributors: + * + * Tom Huybrechts + * * *******************************************************************************/ @@ -33,11 +33,13 @@ import java.util.Collections; import java.util.List; /** - * {@link NodeProperty} that allows users to specify different locations for {@link ToolInstallation}s. + * {@link NodeProperty} that allows users to specify different locations for + * {@link ToolInstallation}s. * * @since 1.286 */ public class ToolLocationNodeProperty extends NodeProperty<Node> { + /** * Override locations. Never null. */ @@ -45,7 +47,9 @@ public class ToolLocationNodeProperty extends NodeProperty<Node> { @DataBoundConstructor public ToolLocationNodeProperty(List<ToolLocation> locations) { - if(locations==null) throw new IllegalArgumentException(); + if (locations == null) { + throw new IllegalArgumentException(); + } this.locations = locations; } @@ -67,29 +71,35 @@ public class ToolLocationNodeProperty extends NodeProperty<Node> { } /** - * Checks if the location of the tool is overridden for the given node, and if so, - * return the node-specific home directory. Otherwise return {@code installation.getHome()} + * Checks if the location of the tool is overridden for the given node, and + * if so, return the node-specific home directory. Otherwise return + * {@code installation.getHome()} * - * <p> - * This is the core logic behind {@link NodeSpecific#forNode(Node)} for {@link ToolInstallation}. + * <p> This is the core logic behind {@link NodeSpecific#forNode(Node)} for + * {@link ToolInstallation}. * - * @return - * never null. - * @deprecated since 2009-04-09. - * Use {@link ToolInstallation#translateFor(Node,TaskListener)} + * @return never null. + * @deprecated since 2009-04-09. Use + * {@link ToolInstallation#translateFor(Node,TaskListener)} */ public static String getToolHome(Node node, ToolInstallation installation, TaskListener log) throws IOException, InterruptedException { String result = null; // node-specific configuration takes precedence ToolLocationNodeProperty property = node.getNodeProperties().get(ToolLocationNodeProperty.class); - if (property != null) result = property.getHome(installation); - if (result != null) return result; + if (property != null) { + result = property.getHome(installation); + } + if (result != null) { + return result; + } // consult translators - for( ToolLocationTranslator t : ToolLocationTranslator.all() ) { + for (ToolLocationTranslator t : ToolLocationTranslator.all()) { result = t.getToolHome(node, installation, log); - if(result!=null) return result; + if (result != null) { + return result; + } } // fall back is no-op @@ -103,7 +113,7 @@ public class ToolLocationNodeProperty extends NodeProperty<Node> { return Messages.ToolLocationNodeProperty_displayName(); } - public DescriptorExtensionList<ToolInstallation,ToolDescriptor<?>> getToolDescriptors() { + public DescriptorExtensionList<ToolInstallation, ToolDescriptor<?>> getToolDescriptors() { return ToolInstallation.all(); } @@ -118,6 +128,7 @@ public class ToolLocationNodeProperty extends NodeProperty<Node> { } public static final class ToolLocation { + private final String type; private final String name; private final String home; @@ -129,10 +140,10 @@ public class ToolLocationNodeProperty extends NodeProperty<Node> { this.name = name; this.home = home; } - + @DataBoundConstructor public ToolLocation(String key, String home) { - this.type = key.substring(0, key.indexOf('@')); + this.type = key.substring(0, key.indexOf('@')); this.name = key.substring(key.indexOf('@') + 1); this.home = home; } @@ -146,15 +157,14 @@ public class ToolLocationNodeProperty extends NodeProperty<Node> { } public ToolDescriptor getType() { - if (descriptor == null) descriptor = (ToolDescriptor) Descriptor.find(type); + if (descriptor == null) { + descriptor = (ToolDescriptor) Descriptor.find(type); + } return descriptor; } public String getKey() { return type + "@" + name; } - } - - } diff --git a/hudson-core/src/main/java/hudson/tools/ToolLocationTranslator.java b/hudson-core/src/main/java/hudson/tools/ToolLocationTranslator.java index e6fbfa0..fb1ff0a 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolLocationTranslator.java +++ b/hudson-core/src/main/java/hudson/tools/ToolLocationTranslator.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* + * Contributors: + * * Tom Huybrechts - * + * * *******************************************************************************/ @@ -26,35 +26,36 @@ import java.io.File; import java.io.IOException; /** - * This Hudson-wide extension points can participate in determining the actual node-specific path - * of the {@link ToolInstallation} for the given {@link Node}. + * This Hudson-wide extension points can participate in determining the actual + * node-specific path of the {@link ToolInstallation} for the given + * {@link Node}. * - * <p> - * This extension point is useful when there's a deterministic rule of where tools are installed. - * One can program such a logic and contribute a {@link ToolLocationTranslator}. - * Compared to manually specifying {@link ToolLocationNodeProperty}, duplicated configurations - * can be avoided this way. + * <p> This extension point is useful when there's a deterministic rule of where + * tools are installed. One can program such a logic and contribute a + * {@link ToolLocationTranslator}. Compared to manually specifying + * {@link ToolLocationNodeProperty}, duplicated configurations can be avoided + * this way. * - * <p> - * Entry point to the translation process is + * <p> Entry point to the translation process is * * @author Kohsuke Kawaguchi * @since 1.299 * @see ToolInstallation#translateFor(Node, TaskListener) */ public abstract class ToolLocationTranslator implements ExtensionPoint { + /** - * Called for each {@link ToolInstallation#translateFor(Node, TaskListener)} invocations - * (which normally means it's invoked for each {@link NodeSpecific#forNode(Node, TaskListener)}) - * to translate the tool location into the node specific location. + * Called for each {@link ToolInstallation#translateFor(Node, TaskListener)} + * invocations (which normally means it's invoked for each + * {@link NodeSpecific#forNode(Node, TaskListener)}) to translate the tool + * location into the node specific location. * - * <p> - * If this implementation is capable of determining the location, return the path in the absolute file name. - * (This method doesn't return {@link File} so that it can handle path names of a different OS. + * <p> If this implementation is capable of determining the location, return + * the path in the absolute file name. (This method doesn't return + * {@link File} so that it can handle path names of a different OS. * - * <p> - * Otherwise return null to let other {@link ToolLocationTranslator}s a chance to do translations - * on their own. + * <p> Otherwise return null to let other {@link ToolLocationTranslator}s a + * chance to do translations on their own. */ public abstract String getToolHome(Node node, ToolInstallation installation, TaskListener log) throws IOException, InterruptedException; diff --git a/hudson-core/src/main/java/hudson/tools/ToolProperty.java b/hudson-core/src/main/java/hudson/tools/ToolProperty.java index 137e762..bbaf264 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolProperty.java +++ b/hudson-core/src/main/java/hudson/tools/ToolProperty.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -24,24 +24,23 @@ import hudson.model.Hudson; /** * Extensible property of {@link ToolInstallation}. * - * <p> - * Plugins can contribute this extension point to add additional data or UI actions to {@link ToolInstallation}. - * {@link ToolProperty}s show up in the configuration screen of a tool, and they are persisted with the {@link ToolInstallation} object. + * <p> Plugins can contribute this extension point to add additional data or UI + * actions to {@link ToolInstallation}. {@link ToolProperty}s show up in the + * configuration screen of a tool, and they are persisted with the + * {@link ToolInstallation} object. * * - * <h2>Views</h2> - * <dl> - * <dt>config.jelly</dt> - * <dd>Added to the configuration page of the tool. - * </dl> + * <h2>Views</h2> <dl> <dt>config.jelly</dt> <dd>Added to the configuration page + * of the tool. </dl> * - * @param <T> - * {@link ToolProperty} can choose to only work with a certain subtype of {@link ToolInstallation}, and this 'T' - * represents that type. Also see {@link ToolPropertyDescriptor#isApplicable(Class)}. + * @param <T> {@link ToolProperty} can choose to only work with a certain + * subtype of {@link ToolInstallation}, and this 'T' represents that type. Also + * see {@link ToolPropertyDescriptor#isApplicable(Class)}. * * @since 1.303 */ public abstract class ToolProperty<T extends ToolInstallation> implements Describable<ToolProperty<?>>, ExtensionPoint { + protected transient T tool; protected void setTool(T tool) { @@ -58,11 +57,12 @@ public abstract class ToolProperty<T extends ToolInstallation> implements Descri public abstract Class<T> type(); /** - * Lists up all the registered {@link ToolPropertyDescriptor}s in the system. + * Lists up all the registered {@link ToolPropertyDescriptor}s in the + * system. * - * @see ToolDescriptor#getPropertyDescriptors() + * @see ToolDescriptor#getPropertyDescriptors() */ - public static DescriptorExtensionList<ToolProperty<?>,ToolPropertyDescriptor> all() { - return (DescriptorExtensionList)Hudson.getInstance().getDescriptorList(ToolProperty.class); + public static DescriptorExtensionList<ToolProperty<?>, ToolPropertyDescriptor> all() { + return (DescriptorExtensionList) Hudson.getInstance().getDescriptorList(ToolProperty.class); } } diff --git a/hudson-core/src/main/java/hudson/tools/ToolPropertyDescriptor.java b/hudson-core/src/main/java/hudson/tools/ToolPropertyDescriptor.java index 1b29553..2eae647 100644 --- a/hudson-core/src/main/java/hudson/tools/ToolPropertyDescriptor.java +++ b/hudson-core/src/main/java/hudson/tools/ToolPropertyDescriptor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -21,14 +21,15 @@ import hudson.Extension; /** * Descriptor for {@link ToolProperty}. * - * <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. * * @since 1.286 * @see ToolProperty * @author Kohsuke Kawaguchi */ -public abstract class ToolPropertyDescriptor extends PropertyDescriptor<ToolProperty<?>,ToolInstallation> { +public abstract class ToolPropertyDescriptor extends PropertyDescriptor<ToolProperty<?>, ToolInstallation> { + protected ToolPropertyDescriptor(Class<? extends ToolProperty<?>> clazz) { super(clazz); } @@ -36,4 +37,3 @@ public abstract class ToolPropertyDescriptor extends PropertyDescriptor<ToolProp protected ToolPropertyDescriptor() { } } - diff --git a/hudson-core/src/main/java/hudson/tools/ZipExtractionInstaller.java b/hudson-core/src/main/java/hudson/tools/ZipExtractionInstaller.java index dd53499..60ff778 100644 --- a/hudson-core/src/main/java/hudson/tools/ZipExtractionInstaller.java +++ b/hudson-core/src/main/java/hudson/tools/ZipExtractionInstaller.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -37,7 +37,9 @@ import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; /** - * Installs a tool into the Hudson working area by downloading and unpacking a ZIP file. + * Installs a tool into the Hudson working area by downloading and unpacking a + * ZIP file. + * * @since 1.305 */ public class ZipExtractionInstaller extends ToolInstaller { @@ -98,10 +100,9 @@ public class ZipExtractionInstaller extends ToolInstaller { } catch (MalformedURLException x) { return FormValidation.error(Messages.ZipExtractionInstaller_malformed_url()); } catch (IOException x) { - return FormValidation.error(x,Messages.ZipExtractionInstaller_could_not_connect()); + return FormValidation.error(x, Messages.ZipExtractionInstaller_could_not_connect()); } } - } /** @@ -109,12 +110,16 @@ public class ZipExtractionInstaller extends ToolInstaller { * Work around, is there a better way? */ static class ChmodRecAPlusX implements FileCallable<Void> { + private static final long serialVersionUID = 1L; + public Void invoke(File d, VirtualChannel channel) throws IOException { - if(!Functions.isWindows()) + if (!Functions.isWindows()) { process(d); + } return null; } + private void process(File f) { if (f.isFile()) { if (Functions.isMustangOrAbove()) { @@ -132,5 +137,4 @@ public class ZipExtractionInstaller extends ToolInstaller { } } } - } diff --git a/hudson-core/src/main/java/hudson/triggers/SCMTrigger.java b/hudson-core/src/main/java/hudson/triggers/SCMTrigger.java index 9772e13..e551388 100644 --- a/hudson-core/src/main/java/hudson/triggers/SCMTrigger.java +++ b/hudson-core/src/main/java/hudson/triggers/SCMTrigger.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Brian Westrich, Jean-Baptiste Quenot, id:cactusman - * + * Contributors: + * + * Kohsuke Kawaguchi, Brian Westrich, Jean-Baptiste Quenot, id:cactusman + * * *******************************************************************************/ @@ -62,6 +62,7 @@ import org.antlr.runtime.RecognitionException; * @author Kohsuke Kawaguchi */ public class SCMTrigger extends Trigger<SCMedItem> { + @DataBoundConstructor public SCMTrigger(String scmpoll_spec) throws RecognitionException { super(scmpoll_spec); @@ -73,28 +74,29 @@ public class SCMTrigger extends Trigger<SCMedItem> { } /** - * Run the SCM trigger with additional build actions. Used by SubversionRepositoryStatus - * to trigger a build at a specific revisionn number. - * + * Run the SCM trigger with additional build actions. Used by + * SubversionRepositoryStatus to trigger a build at a specific revisionn + * number. + * * @param additionalActions * @since 1.375 */ public void run(Action[] additionalActions) { - if(Hudson.getInstance().isQuietingDown()) + if (Hudson.getInstance().isQuietingDown()) { return; // noop - + } DescriptorImpl d = getDescriptor(); - LOGGER.fine("Scheduling a polling for "+job); + LOGGER.fine("Scheduling a polling for " + job); if (d.synchronousPolling) { - LOGGER.fine("Running the trigger directly without threading, " + - "as it's already taken care of by Trigger.Cron"); + LOGGER.fine("Running the trigger directly without threading, " + + "as it's already taken care of by Trigger.Cron"); new Runner(additionalActions).run(); } else { // schedule the polling. // even if we end up submitting this too many times, that's OK. // the real exclusion control happens inside Runner. - LOGGER.fine("scheduling the trigger to (asynchronously) run"); + LOGGER.fine("scheduling the trigger to (asynchronously) run"); d.queue.execute(new Runner(additionalActions)); d.clogCheck(); } @@ -102,7 +104,7 @@ public class SCMTrigger extends Trigger<SCMedItem> { @Override public DescriptorImpl getDescriptor() { - return (DescriptorImpl)super.getDescriptor(); + return (DescriptorImpl) super.getDescriptor(); } @Override @@ -114,31 +116,31 @@ public class SCMTrigger extends Trigger<SCMedItem> { * Returns the file that records the last/current polling activity. */ public File getLogFile() { - return new File(job.getRootDir(),"scm-polling.log"); + return new File(job.getRootDir(), "scm-polling.log"); } @Extension public static class DescriptorImpl extends TriggerDescriptor { + /** - * Used to control the execution of the polling tasks. - * <p> - * This executor implementation has a semantics suitable for polling. Namely, no two threads will try to poll the same project - * at once, and multiple polling requests to the same job will be combined into one. Note that because executor isn't aware - * of a potential workspace lock between a build and a polling, we may end up using executor threads unwisely --- they - * may block. + * Used to control the execution of the polling tasks. <p> This executor + * implementation has a semantics suitable for polling. Namely, no two + * threads will try to poll the same project at once, and multiple + * polling requests to the same job will be combined into one. Note that + * because executor isn't aware of a potential workspace lock between a + * build and a polling, we may end up using executor threads unwisely + * --- they may block. */ private transient final SequentialExecutionQueue queue = new SequentialExecutionQueue(Executors.newSingleThreadExecutor()); - /** - * Whether the projects should be polled all in one go in the order of dependencies. The default behavior is - * that each project polls for changes independently. + * Whether the projects should be polled all in one go in the order of + * dependencies. The default behavior is that each project polls for + * changes independently. */ //TODO: review and check whether we can do it private public boolean synchronousPolling = false; - /** - * Max number of threads for SCM polling. - * 0 for unbounded. + * Max number of threads for SCM polling. 0 for unbounded. */ private int maximumThreads; @@ -160,16 +162,16 @@ public class SCMTrigger extends Trigger<SCMedItem> { } /** - * Returns true if the SCM polling thread queue has too many jobs - * than it can handle. + * Returns true if the SCM polling thread queue has too many jobs than + * it can handle. */ public boolean isClogged() { return queue.isStarving(STARVATION_THRESHOLD); } /** - * Checks if the queue is clogged, and if so, - * activate {@link AdministrativeMonitorImpl}. + * Checks if the queue is clogged, and if so, activate + * {@link AdministrativeMonitorImpl}. */ public void clogCheck() { AdministrativeMonitor.all().get(AdministrativeMonitorImpl.class).on = isClogged(); @@ -179,16 +181,18 @@ public class SCMTrigger extends Trigger<SCMedItem> { * Gets the snapshot of {@link Runner}s that are performing polling. */ public List<Runner> getRunners() { - return Util.filter(queue.getInProgress(),Runner.class); + return Util.filter(queue.getInProgress(), Runner.class); } /** - * Gets the snapshot of {@link SCMedItem}s that are being polled at this very moment. + * Gets the snapshot of {@link SCMedItem}s that are being polled at this + * very moment. */ public List<SCMedItem> getItemsBeingPolled() { List<SCMedItem> r = new ArrayList<SCMedItem>(); - for (Runner i : getRunners()) + for (Runner i : getRunners()) { r.add(i.getTarget()); + } return r; } @@ -199,21 +203,27 @@ public class SCMTrigger extends Trigger<SCMedItem> { /** * Gets the number of concurrent threads used for polling. * - * @return - * 0 if unlimited. + * @return 0 if unlimited. */ public int getPollingThreadCount() { return maximumThreads; } /** - * Sets the number of concurrent threads used for SCM polling and resizes the thread pool accordingly - * @param n number of concurrent threads, zero or less means unlimited, maximum is 100 + * Sets the number of concurrent threads used for SCM polling and + * resizes the thread pool accordingly + * + * @param n number of concurrent threads, zero or less means unlimited, + * maximum is 100 */ public void setPollingThreadCount(int n) { // fool proof - if(n<0) n=0; - if(n>100) n=100; + if (n < 0) { + n = 0; + } + if (n > 100) { + n = 100; + } maximumThreads = n; @@ -225,16 +235,17 @@ public class SCMTrigger extends Trigger<SCMedItem> { */ /*package*/ synchronized void resizeThreadPool() { queue.setExecutors( - (maximumThreads==0 ? Executors.newCachedThreadPool() : Executors.newFixedThreadPool(maximumThreads))); + (maximumThreads == 0 ? Executors.newCachedThreadPool() : Executors.newFixedThreadPool(maximumThreads))); } @Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { - String t = json.optString("pollingThreadCount",null); - if(t==null || t.length()==0) + String t = json.optString("pollingThreadCount", null); + if (t == null || t.length() == 0) { setPollingThreadCount(0); - else + } else { setPollingThreadCount(Integer.parseInt(t)); + } // Save configuration save(); @@ -243,14 +254,16 @@ public class SCMTrigger extends Trigger<SCMedItem> { } public FormValidation doCheckPollingThreadCount(@QueryParameter String value) { - if (value != null && "".equals(value.trim())) + if (value != null && "".equals(value.trim())) { return FormValidation.ok(); + } return FormValidation.validateNonNegativeInteger(value); } } @Extension public static final class AdministrativeMonitorImpl extends AdministrativeMonitor { + private boolean on; public boolean isActivated() { @@ -259,13 +272,14 @@ public class SCMTrigger extends Trigger<SCMedItem> { } /** - * Associated with {@link AbstractBuild} to show the polling log - * that triggered that build. + * Associated with {@link AbstractBuild} to show the polling log that + * triggered that build. * * @since 1.376 */ public static class BuildAction implements Action { //TODO: review and check if we can do it private + public final AbstractBuild build; public BuildAction(AbstractBuild build) { @@ -276,7 +290,7 @@ public class SCMTrigger extends Trigger<SCMedItem> { * Polling log that triggered the build. */ public File getPollingLogFile() { - return new File(build.getRootDir(),"polling.log"); + return new File(build.getRootDir(), "polling.log"); } public String getIconFileName() { @@ -301,7 +315,7 @@ public class SCMTrigger extends Trigger<SCMedItem> { public void doPollingLog(StaplerRequest req, StaplerResponse rsp) throws IOException { rsp.setContentType("text/plain;charset=UTF-8"); // Prevent jelly from flushing stream so Content-Length header can be added afterwards - FlushProofOutputStream out = null; + FlushProofOutputStream out = null; try { out = new FlushProofOutputStream(rsp.getCompressedOutputStream(req)); getPollingLogText().writeLogTo(0, out); @@ -313,9 +327,10 @@ public class SCMTrigger extends Trigger<SCMedItem> { public AnnotatedLargeText getPollingLogText() { return new AnnotatedLargeText<BuildAction>(getPollingLogFile(), Charset.defaultCharset(), true, this); } - + /** - * Used from <tt>polling.jelly</tt> to write annotated polling log to the given output. + * Used from <tt>polling.jelly</tt> to write annotated polling log to + * the given output. */ public void writePollingLogTo(long offset, XMLOutput out) throws IOException { // TODO: resurrect compressed log file support @@ -327,7 +342,8 @@ public class SCMTrigger extends Trigger<SCMedItem> { * Action object for {@link Project}. Used to display the last polling log. */ public final class SCMAction implements Action { - public AbstractProject<?,?> getOwner() { + + public AbstractProject<?, ?> getOwner() { return job.asProject(); } @@ -349,13 +365,13 @@ public class SCMTrigger extends Trigger<SCMedItem> { /** * Writes the annotated log to the given output. + * * @since 1.350 */ public void writeLogTo(XMLOutput out) throws IOException { - new AnnotatedLargeText<SCMAction>(getLogFile(),Charset.defaultCharset(),true,this).writeHtmlTo(0,out.asWriter()); + new AnnotatedLargeText<SCMAction>(getLogFile(), Charset.defaultCharset(), true, this).writeHtmlTo(0, out.asWriter()); } } - private static final Logger LOGGER = Logger.getLogger(SCMTrigger.class.getName()); /** @@ -367,13 +383,12 @@ public class SCMTrigger extends Trigger<SCMedItem> { * When did the polling start? */ private volatile long startTime; - private Action[] additionalActions; public Runner() { additionalActions = new Action[0]; } - + public Runner(Action[] actions) { if (actions == null) { additionalActions = new Action[0]; @@ -381,7 +396,7 @@ public class SCMTrigger extends Trigger<SCMedItem> { additionalActions = actions; } } - + /** * Where the log file is written. */ @@ -407,7 +422,7 @@ public class SCMTrigger extends Trigger<SCMedItem> { * Human readable string of when this polling is started. */ public String getDuration() { - return Util.getTimeSpanString(System.currentTimeMillis()-startTime); + return Util.getTimeSpanString(System.currentTimeMillis() - startTime); } private boolean runPolling() { @@ -419,50 +434,51 @@ public class SCMTrigger extends Trigger<SCMedItem> { try { PrintStream logger = listener.getLogger(); long start = System.currentTimeMillis(); - logger.println("Started on "+ DateFormat.getDateTimeInstance().format(new Date())); + logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); boolean result = job.poll(listener).hasChanges(); - logger.println("Done. Took "+ Util.getTimeSpanString(System.currentTimeMillis()-start)); - if(result) + logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start)); + if (result) { logger.println("Changes found"); - else + } else { logger.println("No changes"); + } return result; } catch (Error e) { e.printStackTrace(listener.error("Failed to record SCM polling")); - LOGGER.log(Level.SEVERE,"Failed to record SCM polling",e); + LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); throw e; } catch (RuntimeException e) { e.printStackTrace(listener.error("Failed to record SCM polling")); - LOGGER.log(Level.SEVERE,"Failed to record SCM polling",e); + LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); throw e; } finally { listener.close(); } } catch (IOException e) { - LOGGER.log(Level.SEVERE,"Failed to record SCM polling",e); + LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); return false; } } public void run() { String threadName = Thread.currentThread().getName(); - Thread.currentThread().setName("SCM polling for "+job); + Thread.currentThread().setName("SCM polling for " + job); try { startTime = System.currentTimeMillis(); - if(runPolling()) { + if (runPolling()) { AbstractProject p = job.asProject(); - String name = " #"+p.getNextBuildNumber(); + String name = " #" + p.getNextBuildNumber(); SCMTriggerCause cause; try { cause = new SCMTriggerCause(getLogFile()); } catch (IOException e) { - LOGGER.log(WARNING, "Failed to parse the polling log",e); + LOGGER.log(WARNING, "Failed to parse the polling log", e); cause = new SCMTriggerCause(); } - if(p.scheduleBuild(p.getQuietPeriod(), cause, additionalActions)) { - LOGGER.info("SCM changes detected in "+ job.getName()+". Triggering "+name); + if (p.scheduleBuild(p.getQuietPeriod(), cause, additionalActions)) { + LOGGER.info("SCM changes detected in " + job.getName() + ". Triggering " + name); } else { - LOGGER.info("SCM changes detected in "+ job.getName()+". Job is already in the queue"); + LOGGER.info("SCM changes detected in " + job.getName() + ". Job is already in the queue"); } } } finally { @@ -477,7 +493,7 @@ public class SCMTrigger extends Trigger<SCMedItem> { // as per the requirement of SequentialExecutionQueue, value equality is necessary @Override public boolean equals(Object that) { - return that instanceof Runner && job()==((Runner)that).job(); + return that instanceof Runner && job() == ((Runner) that).job(); } @Override @@ -487,9 +503,10 @@ public class SCMTrigger extends Trigger<SCMedItem> { } public static class SCMTriggerCause extends Cause { + /** - * Only used while ths cause is in the queue. - * Once attached to the build, we'll move this into a file to reduce the memory footprint. + * Only used while ths cause is in the queue. Once attached to the + * build, we'll move this into a file to reduce the memory footprint. */ private String pollingLog; @@ -503,8 +520,7 @@ public class SCMTrigger extends Trigger<SCMedItem> { } /** - * @deprecated - * Use {@link #SCMTriggerCause(String)}. + * @deprecated Use {@link #SCMTriggerCause(String)}. */ public SCMTriggerCause() { this(""); @@ -514,10 +530,10 @@ public class SCMTrigger extends Trigger<SCMedItem> { public void onAddedTo(AbstractBuild build) { try { BuildAction a = new BuildAction(build); - FileUtils.writeStringToFile(a.getPollingLogFile(),pollingLog); + FileUtils.writeStringToFile(a.getPollingLogFile(), pollingLog); build.addAction(a); } catch (IOException e) { - LOGGER.log(WARNING,"Failed to persist the polling log",e); + LOGGER.log(WARNING, "Failed to persist the polling log", e); } pollingLog = null; } @@ -537,9 +553,8 @@ public class SCMTrigger extends Trigger<SCMedItem> { return 3; } } - /** * How long is too long for a polling activity to be in the queue? */ - public static long STARVATION_THRESHOLD =Long.getLong(SCMTrigger.class.getName()+".starvationThreshold", TimeUnit2.HOURS.toMillis(1)); + public static long STARVATION_THRESHOLD = Long.getLong(SCMTrigger.class.getName() + ".starvationThreshold", TimeUnit2.HOURS.toMillis(1)); } diff --git a/hudson-core/src/main/java/hudson/triggers/SafeTimerTask.java b/hudson-core/src/main/java/hudson/triggers/SafeTimerTask.java index 90922fb..857ed3b 100644 --- a/hudson-core/src/main/java/hudson/triggers/SafeTimerTask.java +++ b/hudson-core/src/main/java/hudson/triggers/SafeTimerTask.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, Winston Prakash - * + * *******************************************************************************/ package hudson.triggers; @@ -22,18 +22,18 @@ import java.util.logging.Level; import org.eclipse.hudson.security.HudsonSecurityManager; /** - * {@link Timer} wrapper so that a fatal error in {@link TimerTask} - * won't terminate the timer. + * {@link Timer} wrapper so that a fatal error in {@link TimerTask} won't + * terminate the timer. * - * <p> - * {@link Trigger#timer} is a shared timer instance that can be used inside Hudson to - * schedule a recurring work. + * <p> {@link Trigger#timer} is a shared timer instance that can be used inside + * Hudson to schedule a recurring work. * * @author Kohsuke Kawaguchi * @since 1.124 * @see Trigger#timer */ public abstract class SafeTimerTask extends TimerTask { + public final void run() { // background activity gets system credential, // just like executors get it. @@ -41,14 +41,13 @@ public abstract class SafeTimerTask extends TimerTask { try { doRun(); - } catch(Throwable t) { - LOGGER.log(Level.SEVERE, "Timer task "+this+" failed",t); + } catch (Throwable t) { + LOGGER.log(Level.SEVERE, "Timer task " + this + " failed", t); } finally { HudsonSecurityManager.resetFullControl(); } } protected abstract void doRun() throws Exception; - private static final Logger LOGGER = Logger.getLogger(SafeTimerTask.class.getName()); } diff --git a/hudson-core/src/main/java/hudson/triggers/TimerTrigger.java b/hudson-core/src/main/java/hudson/triggers/TimerTrigger.java index f254bb5..6b6fe06 100644 --- a/hudson-core/src/main/java/hudson/triggers/TimerTrigger.java +++ b/hudson-core/src/main/java/hudson/triggers/TimerTrigger.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Jean-Baptiste Quenot, Martin Eigenbrodt - * + * Contributors: + * + * Kohsuke Kawaguchi, Jean-Baptiste Quenot, Martin Eigenbrodt + * * *******************************************************************************/ @@ -28,7 +28,6 @@ import org.antlr.runtime.RecognitionException; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; - /** * {@link Trigger} that runs a job periodically. * @@ -48,6 +47,7 @@ public class TimerTrigger extends Trigger<BuildableItem> { @Extension public static class DescriptorImpl extends TriggerDescriptor { + public boolean isApplicable(Item item) { return item instanceof BuildableItem; } @@ -60,22 +60,25 @@ public class TimerTrigger extends Trigger<BuildableItem> { public FormValidation doCheck(@QueryParameter String value) { return doCheckSpec(value); } - + /** * Performs syntax check. */ public FormValidation doCheckSpec(@QueryParameter String value) { try { String msg = CronTabList.create(fixNull(value)).checkSanity(); - if(msg!=null) return FormValidation.warning(msg); + if (msg != null) { + return FormValidation.warning(msg); + } return FormValidation.ok(); } catch (RecognitionException e) { return FormValidation.error(e.getMessage()); } } } - + public static class TimerTriggerCause extends Cause { + @Override public String getShortDescription() { return Messages.TimerTrigger_TimerTriggerCause_ShortDescription(); diff --git a/hudson-core/src/main/java/hudson/triggers/Trigger.java b/hudson-core/src/main/java/hudson/triggers/Trigger.java index fb37485..8b20a2b 100644 --- a/hudson-core/src/main/java/hudson/triggers/Trigger.java +++ b/hudson-core/src/main/java/hudson/triggers/Trigger.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Brian Westrich, Jean-Baptiste Quenot, Stephen Connolly, Tom Huybrechts, Nikita Levyankov - * + * Contributors: + * + * Kohsuke Kawaguchi, Brian Westrich, Jean-Baptiste Quenot, Stephen Connolly, Tom Huybrechts, Nikita Levyankov + * * *******************************************************************************/ @@ -56,9 +56,8 @@ import org.antlr.runtime.RecognitionException; /** * Triggers a {@link Build}. * - * <p> - * To register a custom {@link Trigger} from a plugin, - * put {@link Extension} on your {@link TriggerDescriptor} class. + * <p> To register a custom {@link Trigger} from a plugin, put {@link Extension} + * on your {@link TriggerDescriptor} class. * * @author Kohsuke Kawaguchi */ @@ -67,11 +66,11 @@ public abstract class Trigger<J extends Item> implements Describable<Trigger<?>> /** * Called when a {@link Trigger} is loaded into memory and started. * - * @param project - * given so that the persisted form of this object won't have to have a back pointer. - * @param newInstance - * True if this is a newly created trigger first attached to the {@link Project}. - * False if this is invoked for a {@link Project} loaded from disk. + * @param project given so that the persisted form of this object won't have + * to have a back pointer. + * @param newInstance True if this is a newly created trigger first attached + * to the {@link Project}. False if this is invoked for a {@link Project} + * loaded from disk. */ public void start(J project, boolean newInstance) { this.job = project; @@ -80,28 +79,28 @@ public abstract class Trigger<J extends Item> implements Describable<Trigger<?>> /** * Executes the triggered task. * - * This method is invoked when {@link #Trigger(String)} is used - * to create an instance, and the crontab matches the current time. + * This method is invoked when {@link #Trigger(String)} is used to create an + * instance, and the crontab matches the current time. */ - public void run() {} + public void run() { + } /** - * Called before a {@link Trigger} is removed. - * Under some circumstances, this may be invoked more than once for - * a given {@link Trigger}, so be prepared for that. + * Called before a {@link Trigger} is removed. Under some circumstances, + * this may be invoked more than once for a given {@link Trigger}, so be + * prepared for that. * - * <p> - * When the configuration is changed for a project, all triggers - * are removed once and then added back. + * <p> When the configuration is changed for a project, all triggers are + * removed once and then added back. */ - public void stop() {} + public void stop() { + } /** - * Returns an action object if this {@link Trigger} has an action - * to contribute to a {@link Project}. + * Returns an action object if this {@link Trigger} has an action to + * contribute to a {@link Project}. * - * @deprecated as of 1.341 - * Use {@link #getProjectActions()} instead. + * @deprecated as of 1.341 Use {@link #getProjectActions()} instead. */ public Action getProjectAction() { return null; @@ -110,31 +109,28 @@ public abstract class Trigger<J extends Item> implements Describable<Trigger<?>> /** * {@link Action}s to be displayed in the job page. * - * @return - * can be empty but never null + * @return can be empty but never null * @since 1.341 */ public Collection<? extends Action> getProjectActions() { // delegate to getJobAction (singular) for backward compatible behavior Action a = getProjectAction(); - if (a==null) return Collections.emptyList(); + if (a == null) { + return Collections.emptyList(); + } return Collections.singletonList(a); } public TriggerDescriptor getDescriptor() { - return (TriggerDescriptor)Hudson.getInstance().getDescriptorOrDie(getClass()); + return (TriggerDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass()); } - - - protected final String spec; protected transient CronTabList tabs; protected transient J job; /** - * Creates a new {@link Trigger} that gets {@link #run() run} - * periodically. This is useful when your trigger does - * some polling work. + * Creates a new {@link Trigger} that gets {@link #run() run} periodically. + * This is useful when your trigger does some polling work. */ protected Trigger(String cronTabSpec) throws RecognitionException { this.spec = cronTabSpec; @@ -169,12 +165,12 @@ public abstract class Trigger<J extends Item> implements Describable<Trigger<?>> return this; } - /** * Runs every minute to check {@link TimerTrigger} and schedules build. */ @Extension public static class Cron extends PeriodicWork { + private final Calendar cal = new GregorianCalendar(); public long getRecurrencePeriod() { @@ -182,22 +178,21 @@ public abstract class Trigger<J extends Item> implements Describable<Trigger<?>> } public void doRun() { - while(new Date().getTime()-cal.getTimeInMillis()>1000) { - LOGGER.fine("cron checking "+cal.getTime().toLocaleString()); + while (new Date().getTime() - cal.getTimeInMillis() > 1000) { + LOGGER.fine("cron checking " + cal.getTime().toLocaleString()); try { checkTriggers(cal); } catch (Throwable e) { - LOGGER.log(Level.WARNING,"Cron thread throw an exception",e); + LOGGER.log(Level.WARNING, "Cron thread throw an exception", e); // bug in the code. Don't let the thread die. e.printStackTrace(); } - cal.add(Calendar.MINUTE,1); + cal.add(Calendar.MINUTE, 1); } } } - private static Future previousSynchronousPolling; public static void checkTriggers(final Calendar cal) { @@ -230,74 +225,80 @@ public abstract class Trigger<J extends Item> implements Describable<Trigger<?>> } // Process all triggers, except SCMTriggers when synchronousPolling is set - for (AbstractProject<?,?> p : inst.getAllItems(AbstractProject.class)) { + for (AbstractProject<?, ?> p : inst.getAllItems(AbstractProject.class)) { for (Trigger t : p.getTriggers().values()) { - if (! (t instanceof SCMTrigger && scmd.synchronousPolling)) { - LOGGER.fine("cron checking "+p.getName()); + if (!(t instanceof SCMTrigger && scmd.synchronousPolling)) { + LOGGER.fine("cron checking " + p.getName()); if (t.tabs.check(cal)) { - LOGGER.config("cron triggered "+p.getName()); + LOGGER.config("cron triggered " + p.getName()); try { t.run(); } catch (Throwable e) { // t.run() is a plugin, and some of them throw RuntimeException and other things. // don't let that cancel the polling activity. report and move on. - LOGGER.log(Level.WARNING, t.getClass().getName()+".run() failed for "+p.getName(),e); + LOGGER.log(Level.WARNING, t.getClass().getName() + ".run() failed for " + p.getName(), e); } } } } } } - private static final Logger LOGGER = Logger.getLogger(Trigger.class.getName()); - /** * This timer is available for all the components inside Hudson to schedule * some work. * - * Initialized and cleaned up by {@link Hudson}, but value kept here for compatibility. + * Initialized and cleaned up by {@link Hudson}, but value kept here for + * compatibility. * - * If plugins want to run periodic jobs, they should implement {@link PeriodicWork}. + * If plugins want to run periodic jobs, they should implement + * {@link PeriodicWork}. */ public static Timer timer; - @Initializer(after=JOB_LOADED) + @Initializer(after = JOB_LOADED) public static void init() { new DoubleLaunchChecker().schedule(); // start all PeridocWorks - for(PeriodicWork p : PeriodicWork.all()) - timer.scheduleAtFixedRate(p,p.getInitialDelay(),p.getRecurrencePeriod()); + for (PeriodicWork p : PeriodicWork.all()) { + timer.scheduleAtFixedRate(p, p.getInitialDelay(), p.getRecurrencePeriod()); + } // start monitoring nodes, although there's no hurry. timer.schedule(new SafeTimerTask() { public void doRun() { ComputerSet.initialize(); } - }, 1000*10); + }, 1000 * 10); } /** * Returns all the registered {@link Trigger} descriptors. */ - public static DescriptorExtensionList<Trigger<?>,TriggerDescriptor> all() { - return (DescriptorExtensionList)Hudson.getInstance().getDescriptorList(Trigger.class); + public static DescriptorExtensionList<Trigger<?>, TriggerDescriptor> all() { + return (DescriptorExtensionList) Hudson.getInstance().getDescriptorList(Trigger.class); } /** - * Returns a subset of {@link TriggerDescriptor}s that applys to the given item. + * Returns a subset of {@link TriggerDescriptor}s that applys to the given + * item. */ public static List<TriggerDescriptor> for_(Item i) { List<TriggerDescriptor> r = new ArrayList<TriggerDescriptor>(); for (TriggerDescriptor t : all()) { - if(!t.isApplicable(i)) continue; + if (!t.isApplicable(i)) { + continue; + } if (i instanceof TopLevelItem) {// ugly TopLevelItemDescriptor tld = ((TopLevelItem) i).getDescriptor(); // tld shouldn't be really null in contract, but we often write test Describables that // doesn't have a Descriptor. - if(tld!=null && !tld.isApplicable(t)) continue; + if (tld != null && !tld.isApplicable(t)) { + continue; + } } r.add(t); diff --git a/hudson-core/src/main/java/hudson/triggers/TriggerDescriptor.java b/hudson-core/src/main/java/hudson/triggers/TriggerDescriptor.java index 2ceaedf..e7d02be 100644 --- a/hudson-core/src/main/java/hudson/triggers/TriggerDescriptor.java +++ b/hudson-core/src/main/java/hudson/triggers/TriggerDescriptor.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 + * * *******************************************************************************/ @@ -22,17 +22,20 @@ import hudson.scm.SCM; /** * {@link Descriptor} for Trigger. + * * @author Kohsuke Kawaguchi */ public abstract class TriggerDescriptor extends Descriptor<Trigger<?>> { + protected TriggerDescriptor(Class<? extends Trigger<?>> clazz) { super(clazz); } /** * Infers the type of the corresponding {@link SCM} from the outer class. - * This version works when you follow the common convention, where a descriptor - * is written as the static nested class of the describable class. + * This version works when you follow the common convention, where a + * descriptor is written as the static nested class of the describable + * class. * * @since 1.278 */ @@ -40,11 +43,9 @@ public abstract class TriggerDescriptor extends Descriptor<Trigger<?>> { } /** - * Returns true if this trigger is applicable to the - * given {@link Item}. + * Returns true if this trigger is applicable to the given {@link Item}. * - * @return - * true to allow user to configure a trigger for this item. + * @return true to allow user to configure a trigger for this item. */ public abstract boolean isApplicable(Item item); } diff --git a/hudson-core/src/main/java/hudson/triggers/Triggers.java b/hudson-core/src/main/java/hudson/triggers/Triggers.java index 239d06e..1396fd5 100644 --- a/hudson-core/src/main/java/hudson/triggers/Triggers.java +++ b/hudson-core/src/main/java/hudson/triggers/Triggers.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 + * * *******************************************************************************/ @@ -26,26 +26,27 @@ import java.util.List; * List of all installed {@link Trigger}s. * * @author Kohsuke Kawaguchi - * @deprecated as of 1.286 - * See each member for how to migrate your code. + * @deprecated as of 1.286 See each member for how to migrate your code. */ public class Triggers { + /** * All registered {@link TriggerDescriptor} implementations. - * @deprecated as of 1.286 - * Use {@link Trigger#all()} for read access, and {@link Extension} for registration. + * + * @deprecated as of 1.286 Use {@link Trigger#all()} for read access, and + * {@link Extension} for registration. */ - public static final List<TriggerDescriptor> TRIGGERS = (List)new DescriptorList<Trigger<?>>((Class)Trigger.class); + public static final List<TriggerDescriptor> TRIGGERS = (List) new DescriptorList<Trigger<?>>((Class) Trigger.class); // Descriptor.toList( // SCMTrigger.DESCRIPTOR, // TimerTrigger.DESCRIPTOR // ); /** - * Returns a subset of {@link TriggerDescriptor}s that applys to the given item. + * Returns a subset of {@link TriggerDescriptor}s that applys to the given + * item. * - * @deprecated as of 1.286 - * Use {@link Trigger#for_(Item)}. + * @deprecated as of 1.286 Use {@link Trigger#for_(Item)}. */ public static List<TriggerDescriptor> getApplicableTriggers(Item i) { return Trigger.for_(i); diff --git a/hudson-core/src/main/java/hudson/triggers/package.html b/hudson-core/src/main/java/hudson/triggers/package.html index df4f66f..13e65bc 100644 --- a/hudson-core/src/main/java/hudson/triggers/package.html +++ b/hudson-core/src/main/java/hudson/triggers/package.html @@ -16,5 +16,5 @@ --> <html><head/><body> -Built-in <a href="Trigger.html"><tt>Trigger</tt></a>s that run periodically to kick a new build. -</body></html>
\ No newline at end of file + Built-in <a href="Trigger.html"><tt>Trigger</tt></a>s that run periodically to kick a new build. + </body></html>
\ No newline at end of file |

