aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-10 15:23:33 (EDT)
committerHenrik Lynggaard Hansen2012-07-10 15:23:33 (EDT)
commitd85f7dfe532a98e25b8e62801d95d9568eb783ff (patch)
tree360f1cb1ece50e7ed449dd5bb8474507bdebb90b
parent6b2a021db07f935226235132973fb64223c07d91 (diff)
downloadorg.eclipse.hudson.core-d85f7dfe532a98e25b8e62801d95d9568eb783ff.zip
org.eclipse.hudson.core-d85f7dfe532a98e25b8e62801d95d9568eb783ff.tar.gz
org.eclipse.hudson.core-d85f7dfe532a98e25b8e62801d95d9568eb783ff.tar.bz2
Reformat of hudson.init.*refs/changes/97/6697/1
Change-Id: Iabd54644c19010f93e1cb82f219ceb244071b19c Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/init/InitMilestone.java62
-rw-r--r--hudson-core/src/main/java/hudson/init/InitReactorListener.java15
-rw-r--r--hudson-core/src/main/java/hudson/init/InitStrategy.java58
-rw-r--r--hudson-core/src/main/java/hudson/init/Initializer.java49
-rw-r--r--hudson-core/src/main/java/hudson/init/InitializerFinder.java46
-rw-r--r--hudson-core/src/main/java/hudson/init/impl/InitialUserContent.java14
-rw-r--r--hudson-core/src/main/java/hudson/init/package-info.java7
7 files changed, 129 insertions, 122 deletions
diff --git a/hudson-core/src/main/java/hudson/init/InitMilestone.java b/hudson-core/src/main/java/hudson/init/InitMilestone.java
index 9dff859..654b0fb 100644
--- a/hudson-core/src/main/java/hudson/init/InitMilestone.java
+++ b/hudson-core/src/main/java/hudson/init/InitMilestone.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -24,62 +24,59 @@ import org.jvnet.hudson.reactor.TaskGraphBuilder;
/**
* Various key milestone in the initialization process of Hudson.
*
- * <p>
- * Plugins can use these milestones to execute their initialization at the right moment
- * (in addition to defining their own milestones by implementing {@link Milestone}.
+ * <p> Plugins can use these milestones to execute their initialization at the
+ * right moment (in addition to defining their own milestones by implementing
+ * {@link Milestone}.
+ *
+ * <p> These milestones are achieve in this order.
*
- * <p>
- * These milestones are achieve in this order.
- *
* @author Kohsuke Kawaguchi
*/
public enum InitMilestone implements Milestone {
+
/**
* The very first milestone that gets achieved without doing anything.
*
- * This is used in {@link Initializer#after()} since annotations cannot have null as the default value.
+ * This is used in {@link Initializer#after()} since annotations cannot have
+ * null as the default value.
*/
STARTED("Started initialization"),
-
/**
- * By this milestone, all plugins metadata are inspected and their dependencies figured out.
+ * By this milestone, all plugins metadata are inspected and their
+ * dependencies figured out.
*/
PLUGINS_LISTED("Listed all plugins"),
-
/**
- * By this milestone, all plugin metadata are loaded and its classloader set up.
+ * By this milestone, all plugin metadata are loaded and its classloader set
+ * up.
*/
PLUGINS_PREPARED("Prepared all plugins"),
-
/**
- * By this milestone, all plugins start executing, all extension points loaded, descriptors instantiated
- * and loaded.
+ * By this milestone, all plugins start executing, all extension points
+ * loaded, descriptors instantiated and loaded.
*
- * <p>
- * This is a separate milestone from {@link #PLUGINS_PREPARED} since the execution
- * of a plugin often involves finding extension point implementations, which in turn
- * require all the classes from all the plugins to be loadable.
+ * <p> This is a separate milestone from {@link #PLUGINS_PREPARED} since the
+ * execution of a plugin often involves finding extension point
+ * implementations, which in turn require all the classes from all the
+ * plugins to be loadable.
*/
PLUGINS_STARTED("Started all plugins"),
-
/**
- * By this milestone, all programmatically constructed extension point implementations
- * should be added.
+ * By this milestone, all programmatically constructed extension point
+ * implementations should be added.
*/
EXTENSIONS_AUGMENTED("Augmented all extensions"),
-
/**
* By this milestone, all jobs and their build records are loaded from disk.
*/
JOB_LOADED("Loaded all jobs"),
-
/**
* The very last milestone
*
- * This is used in {@link Initializer#before()} since annotations cannot have null as the default value.
+ * This is used in {@link Initializer#before()} since annotations cannot
+ * have null as the default value.
*/
COMPLETED("Completed initialization");
-
private final String message;
InitMilestone(String message) {
@@ -87,17 +84,18 @@ public enum InitMilestone implements Milestone {
}
/**
- * Creates a set of dummy tasks to enforce ordering among {@link InitMilestone}s.
+ * Creates a set of dummy tasks to enforce ordering among
+ * {@link InitMilestone}s.
*/
public static TaskBuilder ordering() {
TaskGraphBuilder b = new TaskGraphBuilder();
InitMilestone[] v = values();
- for (int i=0; i<v.length-1; i++)
- b.add(null, Executable.NOOP).requires(v[i]).attains(v[i+1]);
+ for (int i = 0; i < v.length - 1; i++) {
+ b.add(null, Executable.NOOP).requires(v[i]).attains(v[i + 1]);
+ }
return b;
}
-
@Override
public String toString() {
return message;
diff --git a/hudson-core/src/main/java/hudson/init/InitReactorListener.java b/hudson-core/src/main/java/hudson/init/InitReactorListener.java
index b929bf7..d8ac7c9 100644
--- a/hudson-core/src/main/java/hudson/init/InitReactorListener.java
+++ b/hudson-core/src/main/java/hudson/init/InitReactorListener.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -18,15 +18,14 @@ import org.jvnet.hudson.reactor.ReactorListener;
import hudson.model.Hudson;
/**
- * {@link ReactorListener}s that get notified of the Hudson initialization process.
+ * {@link ReactorListener}s that get notified of the Hudson initialization
+ * process.
*
- * <p>
- * Because the act of initializing plugins is a part of the Hudson initialization,
- * this extension point cannot be implemented in a plugin. You need to place your jar
- * inside {@code WEB-INF/lib} instead.
+ * <p> Because the act of initializing plugins is a part of the Hudson
+ * initialization, this extension point cannot be implemented in a plugin. You
+ * need to place your jar inside {@code WEB-INF/lib} instead.
*
- * <p>
- * Register your implementation at META-INF/services.
+ * <p> Register your implementation at META-INF/services.
*
* @author Kohsuke Kawaguchi
* @see Hudson#buildReactorListener()
diff --git a/hudson-core/src/main/java/hudson/init/InitStrategy.java b/hudson-core/src/main/java/hudson/init/InitStrategy.java
index 4f56493..6b22c36 100644
--- a/hudson-core/src/main/java/hudson/init/InitStrategy.java
+++ b/hudson-core/src/main/java/hudson/init/InitStrategy.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -28,34 +28,34 @@ import hudson.PluginManager;
import hudson.util.Service;
/**
- * Strategy pattern of the various key decision making during the Hudson initialization.
+ * Strategy pattern of the various key decision making during the Hudson
+ * initialization.
+ *
+ * <p> Because the act of initializing plugins is a part of the Hudson
+ * initialization, this extension point cannot be implemented in a plugin. You
+ * need to place your jar inside {@code WEB-INF/lib} instead.
*
- * <p>
- * Because the act of initializing plugins is a part of the Hudson initialization,
- * this extension point cannot be implemented in a plugin. You need to place your jar
- * inside {@code WEB-INF/lib} instead.
+ * <p> Register your implementation at META-INF/services.
*
- * <p>
- * Register your implementation at META-INF/services.
- *
* @author Kohsuke Kawaguchi
*/
public class InitStrategy {
+
/**
* Returns the list of *.hpi and *.hpl to expand and load.
*
- * <p>
- * Normally we look at {@code $HUDSON_HOME/plugins/*.hpi} and *.hpl.
+ * <p> Normally we look at {@code $HUDSON_HOME/plugins/*.hpi} and *.hpl.
*
- * @return
- * never null but can be empty. The list can contain different versions of the same plugin,
- * and when that happens, Hudson will ignore all but the first one in the list.
+ * @return never null but can be empty. The list can contain different
+ * versions of the same plugin, and when that happens, Hudson will ignore
+ * all but the first one in the list.
*/
public List<File> listPluginArchives(PluginManager pm) throws IOException {
File[] hpi = pm.rootDir.listFiles(new FilterByExtension(".hpi")); // plugin jar file
File[] hpl = pm.rootDir.listFiles(new FilterByExtension(".hpl")); // linked plugin. for debugging.
- if (hpi==null || hpl==null)
+ if (hpi == null || hpl == null) {
throw new IOException("Hudson is unable to create " + pm.rootDir + "\nPerhaps its security privilege is insufficient");
+ }
List<File> r = new ArrayList<File>();
@@ -72,48 +72,48 @@ public class InitStrategy {
/**
* Lists up additional bundled plugins from the system property.
*
- * For use in the "mvn hudson-dev:run".
- * TODO: maven-hpi-plugin should inject its own InitStrategy instead of having this in the core.
+ * For use in the "mvn hudson-dev:run". TODO: maven-hpi-plugin should inject
+ * its own InitStrategy instead of having this in the core.
*/
protected void getBundledPluginsFromProperty(List<File> r) {
String hplProperty = System.getProperty("hudson.bundled.plugins");
if (hplProperty != null) {
for (String hplLocation : hplProperty.split(",")) {
File hpl = new File(hplLocation.trim());
- if (hpl.exists())
+ if (hpl.exists()) {
r.add(hpl);
- else
+ } else {
LOGGER.warning("bundled plugin " + hplLocation + " does not exist");
+ }
}
}
}
/**
* Selectively skip some of the initialization tasks.
- *
- * @return
- * true to skip the execution.
+ *
+ * @return true to skip the execution.
*/
public boolean skipInitTask(Task task) {
return false;
}
-
/**
* Obtains the instance to be used.
*/
public static InitStrategy get(ClassLoader cl) throws IOException {
List<InitStrategy> r = Service.loadInstances(cl, InitStrategy.class);
- if (r.isEmpty()) return new InitStrategy(); // default
-
+ if (r.isEmpty()) {
+ return new InitStrategy(); // default
+ }
InitStrategy s = r.get(0);
- LOGGER.fine("Using "+s+" as InitStrategy");
+ LOGGER.fine("Using " + s + " as InitStrategy");
return s;
}
-
private static final Logger LOGGER = Logger.getLogger(InitStrategy.class.getName());
private static class FilterByExtension implements FilenameFilter {
+
private final String extension;
public FilterByExtension(String extension) {
@@ -121,8 +121,8 @@ public class InitStrategy {
}
public boolean accept(File dir, String name) {
- return name.endsWith(extension) // plugin jar file
- || name.endsWith(".hpl"); // linked plugin. for debugging.
+ return name.endsWith(extension) // plugin jar file
+ || name.endsWith(".hpl"); // linked plugin. for debugging.
}
}
}
diff --git a/hudson-core/src/main/java/hudson/init/Initializer.java b/hudson-core/src/main/java/hudson/init/Initializer.java
index 4059475..f46d33d 100644
--- a/hudson-core/src/main/java/hudson/init/Initializer.java
+++ b/hudson-core/src/main/java/hudson/init/Initializer.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -29,17 +29,17 @@ import static hudson.init.InitMilestone.STARTED;
import static hudson.init.InitMilestone.COMPLETED;
/**
- * Placed on static methods to indicate that this method is to be run during the Hudson start up to perform
- * some sort of initialization tasks.
+ * Placed on static methods to indicate that this method is to be run during the
+ * Hudson start up to perform some sort of initialization tasks.
*
* <h3>Example</h3>
* <pre>
- &#64;Initializer(after=JOB_LOADED)
- public static void init() throws IOException {
- ....
- }
+ * &#64;Initializer(after=JOB_LOADED)
+ * public static void init() throws IOException {
+ * ....
+ * }
* </pre>
- *
+ *
* @author Kohsuke Kawaguchi
*/
@Indexed
@@ -47,21 +47,23 @@ import static hudson.init.InitMilestone.COMPLETED;
@Retention(RUNTIME)
@Target(METHOD)
public @interface Initializer {
+
/**
- * Indicates that the specified milestone is necessary before executing this initializer.
+ * Indicates that the specified milestone is necessary before executing this
+ * initializer.
*
- * <p>
- * This has the identical purpose as {@link #requires()}, but it's separated to allow better type-safety
- * when using {@link InitMilestone} as a requirement (since enum member definitions need to be constant.)
+ * <p> This has the identical purpose as {@link #requires()}, but it's
+ * separated to allow better type-safety when using {@link InitMilestone} as
+ * a requirement (since enum member definitions need to be constant.)
*/
InitMilestone after() default STARTED;
/**
- * Indicates that this initializer is a necessary step before achieving the specified milestone.
+ * Indicates that this initializer is a necessary step before achieving the
+ * specified milestone.
*
- * <p>
- * This has the identical purpose as {@link #attains()}. See {@link #after()} for why there are two things
- * to achieve the same goal.
+ * <p> This has the identical purpose as {@link #attains()}. See
+ * {@link #after()} for why there are two things to achieve the same goal.
*/
InitMilestone before() default COMPLETED;
@@ -73,21 +75,22 @@ public @interface Initializer {
/**
* Indicates the milestones that this initializer contributes to.
*
- * A milestone is considered attained if all the initializers that attains the given milestone
- * completes. So it works as a kind of join.
+ * A milestone is considered attained if all the initializers that attains
+ * the given milestone completes. So it works as a kind of join.
*/
String[] attains() default {};
/**
- * Key in <tt>Messages.properties</tt> that represents what this task is about. Used for rendering the progress.
- * Defaults to "${short class name}.${method Name}".
+ * Key in <tt>Messages.properties</tt> that represents what this task is
+ * about. Used for rendering the progress. Defaults to "${short class
+ * name}.${method Name}".
*/
String displayName() default "";
/**
* Should the failure in this task prevent Hudson from starting up?
*
- * @see Task#failureIsFatal()
+ * @see Task#failureIsFatal()
*/
boolean fatal() default true;
}
diff --git a/hudson-core/src/main/java/hudson/init/InitializerFinder.java b/hudson-core/src/main/java/hudson/init/InitializerFinder.java
index 4e0749d..2e73887 100644
--- a/hudson-core/src/main/java/hudson/init/InitializerFinder.java
+++ b/hudson-core/src/main/java/hudson/init/InitializerFinder.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -45,8 +45,8 @@ import static java.util.logging.Level.FINEST;
* @author Kohsuke Kawaguchi
*/
public class InitializerFinder extends TaskBuilder {
- private final ClassLoader cl;
+ private final ClassLoader cl;
private final Set<Method> discovered = new HashSet<Method>();
public InitializerFinder(ClassLoader cl) {
@@ -59,16 +59,18 @@ public class InitializerFinder extends TaskBuilder {
public Collection<Task> discoverTasks(Reactor session) throws IOException {
List<Task> result = new ArrayList<Task>();
- for (Method e : Index.list(Initializer.class,cl,Method.class)) {
- if (!discovered.add(e))
+ for (Method e : Index.list(Initializer.class, cl, Method.class)) {
+ if (!discovered.add(e)) {
continue; // already reported once
-
- if (!Modifier.isStatic(e.getModifiers()))
- throw new IOException(e+" is not a static method");
+ }
+ if (!Modifier.isStatic(e.getModifiers())) {
+ throw new IOException(e + " is not a static method");
+ }
Initializer i = e.getAnnotation(Initializer.class);
- if (i==null) continue; // stale index
-
+ if (i == null) {
+ continue; // stale index
+ }
result.add(new TaskImpl(i, e));
}
return result;
@@ -83,11 +85,13 @@ public class InitializerFinder extends TaskBuilder {
ResourceBundleHolder rb = ResourceBundleHolder.get(c.getClassLoader().loadClass(c.getPackage().getName() + ".Messages"));
String key = i.displayName();
- if (key.length()==0) return c.getSimpleName()+"."+e.getName();
+ if (key.length() == 0) {
+ return c.getSimpleName() + "." + e.getName();
+ }
return rb.format(key);
} catch (ClassNotFoundException x) {
- LOGGER.log(FINEST, "Failed to load "+x.getMessage()+" for "+e.toString(),x);
- return c.getSimpleName()+"."+e.getName();
+ LOGGER.log(FINEST, "Failed to load " + x.getMessage() + " for " + e.toString(), x);
+ return c.getSimpleName() + "." + e.getName();
}
}
@@ -98,11 +102,12 @@ public class InitializerFinder extends TaskBuilder {
try {
Class<?>[] pt = e.getParameterTypes();
Object[] args = new Object[pt.length];
- for (int i=0; i<args.length; i++)
+ for (int i = 0; i < args.length; i++) {
args[i] = lookUp(pt[i]);
- e.invoke(null,args);
+ }
+ e.invoke(null, args);
} catch (IllegalAccessException x) {
- throw (Error)new IllegalAccessError().initCause(x);
+ throw (Error) new IllegalAccessError().initCause(x);
} catch (InvocationTargetException x) {
throw new Error(x);
}
@@ -112,15 +117,17 @@ public class InitializerFinder extends TaskBuilder {
* Determines the parameter injection of the initialization method.
*/
private Object lookUp(Class<?> type) {
- if (type== Hudson.class)
+ if (type == Hudson.class) {
return Hudson.getInstance();
- throw new IllegalArgumentException("Unable to inject "+type);
+ }
+ throw new IllegalArgumentException("Unable to inject " + type);
}
/**
* Task implementation.
*/
public class TaskImpl implements Task {
+
final Collection<Milestone> requires;
final Collection<Milestone> attains;
private final Initializer i;
@@ -184,6 +191,5 @@ public class InitializerFinder extends TaskBuilder {
return r;
}
}
-
private static final Logger LOGGER = Logger.getLogger(InitializerFinder.class.getName());
}
diff --git a/hudson-core/src/main/java/hudson/init/impl/InitialUserContent.java b/hudson-core/src/main/java/hudson/init/impl/InitialUserContent.java
index 46e1a34..8c99452 100644
--- a/hudson-core/src/main/java/hudson/init/impl/InitialUserContent.java
+++ b/hudson-core/src/main/java/hudson/init/impl/InitialUserContent.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.io.IOException;
/**
* Prepares userContent folder and put a readme if it doesn't exist.
+ *
* @author Kohsuke Kawaguchi
*/
public class InitialUserContent {
- @Initializer(after=JOB_LOADED)
+
+ @Initializer(after = JOB_LOADED)
public static void init(Hudson h) throws IOException {
File userContentDir = new File(h.getRootDir(), "userContent");
- if(!userContentDir.exists()) {
+ if (!userContentDir.exists()) {
userContentDir.mkdirs();
- FileUtils.writeStringToFile(new File(userContentDir,"readme.txt"), Messages.Hudson_USER_CONTENT_README());
+ FileUtils.writeStringToFile(new File(userContentDir, "readme.txt"), Messages.Hudson_USER_CONTENT_README());
}
}
}
diff --git a/hudson-core/src/main/java/hudson/init/package-info.java b/hudson-core/src/main/java/hudson/init/package-info.java
index 5eb1d9d..2530f98 100644
--- a/hudson-core/src/main/java/hudson/init/package-info.java
+++ b/hudson-core/src/main/java/hudson/init/package-info.java
@@ -7,12 +7,11 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
package hudson.init;
-