提交 ee711d4e 编写于 作者: K kohsuke

added a convenient base class.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@30333 71c3de6d-444a-0410-be80-ed276b4c234a
上级 23c7b05f
/*
* The MIT License
*
* Copyright (c) 2004-2009, Kohsuke Kawaguchi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.model;
/**
* Partial default implementation of {@link Describable}.
*
* @author Kohsuke Kawaguchi
*/
public abstract class AbstractDescribableImpl<T extends AbstractDescribableImpl<T>> implements Describable<T> {
public Descriptor<T> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
}
}
......@@ -26,7 +26,7 @@ package hudson.scm;
import hudson.ExtensionPoint;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.model.Describable;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.Hudson;
......@@ -56,7 +56,7 @@ import org.kohsuke.stapler.export.ExportedBean;
* @see RepositoryBrowsers
*/
@ExportedBean
public abstract class RepositoryBrowser<E extends ChangeLogSet.Entry> implements ExtensionPoint, Describable<RepositoryBrowser<?>>, Serializable {
public abstract class RepositoryBrowser<E extends ChangeLogSet.Entry> extends AbstractDescribableImpl<RepositoryBrowser<?>> implements ExtensionPoint, Serializable {
/**
* Determines the link to the given change set.
*
......@@ -95,10 +95,6 @@ public abstract class RepositoryBrowser<E extends ChangeLogSet.Entry> implements
}
}
public Descriptor<RepositoryBrowser<?>> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
}
/**
* Returns all the registered {@link RepositoryBrowser} descriptors.
*/
......
......@@ -26,16 +26,7 @@ package hudson.security;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.ExtensionPoint;
import hudson.model.AbstractItem;
import hudson.model.AbstractProject;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.model.Node;
import hudson.model.User;
import hudson.model.View;
import hudson.model.*;
import hudson.slaves.Cloud;
import hudson.util.DescriptorList;
......@@ -68,7 +59,7 @@ import org.kohsuke.stapler.StaplerRequest;
* @author Kohsuke Kawaguchi
* @see SecurityRealm
*/
public abstract class AuthorizationStrategy implements Describable<AuthorizationStrategy>, ExtensionPoint {
public abstract class AuthorizationStrategy extends AbstractDescribableImpl<AuthorizationStrategy> implements ExtensionPoint {
/**
* Returns the instance of {@link ACL} where all the other {@link ACL} instances
* for all the other model objects eventually delegate.
......@@ -175,10 +166,6 @@ public abstract class AuthorizationStrategy implements Describable<Authorization
*/
public abstract Collection<String> getGroups();
public Descriptor<AuthorizationStrategy> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
}
/**
* Returns all the registered {@link AuthorizationStrategy} descriptors.
*/
......
......@@ -30,7 +30,7 @@ import hudson.ExtensionPoint;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.cli.CLICommand;
import hudson.model.Describable;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.util.DescriptorList;
......@@ -123,7 +123,7 @@ import java.util.logging.Logger;
* @since 1.160
* @see PluginServletFilter
*/
public abstract class SecurityRealm implements Describable<SecurityRealm>, ExtensionPoint {
public abstract class SecurityRealm extends AbstractDescribableImpl<SecurityRealm> implements ExtensionPoint {
/**
* Creates fully-configured {@link AuthenticationManager} that performs authentication
* against the user realm. The implementation hides how such authentication manager
......@@ -169,7 +169,7 @@ public abstract class SecurityRealm implements Describable<SecurityRealm>, Exten
* <tt>global.jelly</tt>.
*/
public Descriptor<SecurityRealm> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
return super.getDescriptor();
}
/**
......
......@@ -25,15 +25,14 @@ package hudson.slaves;
import hudson.ExtensionPoint;
import hudson.Extension;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.TaskListener;
import hudson.model.*;
import hudson.remoting.Channel;
import hudson.util.DescriptorList;
import hudson.util.StreamTaskListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Extension point to allow control over how {@link Computer}s are "launched",
......@@ -50,7 +49,7 @@ import java.io.IOException;
* @author Stephen Connolly
* @since 24-Apr-2008 22:12:35
*/
public abstract class ComputerLauncher implements Describable<ComputerLauncher>, ExtensionPoint {
public abstract class ComputerLauncher extends AbstractDescribableImpl<ComputerLauncher> implements ExtensionPoint {
/**
* Returns true if this {@link ComputerLauncher} supports
* programatic launch of the slave agent in the target {@link Computer}.
......@@ -63,7 +62,7 @@ public abstract class ComputerLauncher implements Describable<ComputerLauncher>,
* Launches the slave agent for the given {@link Computer}.
*
* <p>
* If the slave agent is launched successfully, {@link SlaveComputer#setChannel(InputStream, OutputStream, OutputStream, Listener)}
* If the slave agent is launched successfully, {@link SlaveComputer#setChannel(InputStream, OutputStream, OutputStream, Channel.Listener)}
* should be invoked in the end to notify Hudson of the established connection.
* The operation could also fail, in which case there's no need to make any callback notification,
* (except to notify the user of the failure through {@link StreamTaskListener}.)
......@@ -129,10 +128,6 @@ public abstract class ComputerLauncher implements Describable<ComputerLauncher>,
return new StreamTaskListener(listener.getLogger());
}
public Descriptor<ComputerLauncher> getDescriptor() {
return (Descriptor<ComputerLauncher>)Hudson.getInstance().getDescriptorOrDie(getClass());
}
/**
* All registered {@link ComputerLauncher} implementations.
*
......
......@@ -27,10 +27,7 @@ import hudson.ExtensionPoint;
import hudson.Util;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.*;
import hudson.util.DescriptorList;
import org.kohsuke.stapler.DataBoundConstructor;
......@@ -43,7 +40,7 @@ import java.util.logging.Logger;
* @author Stephen Connolly
* @author Kohsuke Kawaguchi
*/
public abstract class RetentionStrategy<T extends Computer> implements Describable<RetentionStrategy<?>>, ExtensionPoint {
public abstract class RetentionStrategy<T extends Computer> extends AbstractDescribableImpl<RetentionStrategy<?>> implements ExtensionPoint {
/**
* This method will be called periodically to allow this strategy to decide what to do with it's owning slave.
......@@ -80,10 +77,6 @@ public abstract class RetentionStrategy<T extends Computer> implements Describab
check(c);
}
public Descriptor<RetentionStrategy<?>> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
}
/**
* Returns all the registered {@link RetentionStrategy} descriptors.
*/
......
......@@ -27,15 +27,7 @@ import hudson.ExtensionPoint;
import hudson.Launcher;
import hudson.DescriptorExtensionList;
import hudson.LauncherDecorator;
import hudson.model.AbstractBuild;
import hudson.model.Build;
import hudson.model.BuildListener;
import hudson.model.Describable;
import hudson.model.Project;
import hudson.model.Action;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.Descriptor;
import hudson.model.*;
import hudson.model.Run.RunnerAbortedException;
import java.io.IOException;
......@@ -60,7 +52,7 @@ import java.util.Collections;
*
* @author Kohsuke Kawaguchi
*/
public abstract class BuildWrapper implements ExtensionPoint, Describable<BuildWrapper> {
public abstract class BuildWrapper extends AbstractDescribableImpl<BuildWrapper> implements ExtensionPoint {
/**
* Represents the environment set up by {@link BuildWrapper#setUp(Build,Launcher,BuildListener)}.
*
......@@ -211,12 +203,6 @@ public abstract class BuildWrapper implements ExtensionPoint, Describable<BuildW
return Collections.singletonList(a);
}
public Descriptor<BuildWrapper> getDescriptor() {
return (Descriptor<BuildWrapper>) Hudson.getInstance().getDescriptorOrDie(getClass());
}
/**
* Returns all the registered {@link BuildWrapper} descriptors.
*/
......
......@@ -42,7 +42,7 @@ import java.io.IOException;
*
* @since 1.320
*/
public abstract class TestDataPublisher implements Describable<TestDataPublisher>, ExtensionPoint {
public abstract class TestDataPublisher extends AbstractDescribableImpl<TestDataPublisher> implements ExtensionPoint {
/**
* Called after test results are collected by Hudson, to create a resolver for {@link TestAction}s.
......@@ -54,11 +54,6 @@ public abstract class TestDataPublisher implements Describable<TestDataPublisher
AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener, TestResult testResult) throws IOException, InterruptedException;
@SuppressWarnings("unchecked")
public Descriptor<TestDataPublisher> getDescriptor() {
return Hudson.getInstance().getDescriptorOrDie(getClass());
}
public static DescriptorExtensionList<TestDataPublisher, Descriptor<TestDataPublisher>> all() {
return Hudson.getInstance().getDescriptorList(TestDataPublisher.class);
}
......
......@@ -29,12 +29,7 @@ import hudson.EnvVars;
import hudson.Extension;
import hudson.ExtensionPoint;
import hudson.diagnosis.OldDataMonitor;
import hudson.model.Describable;
import hudson.model.EnvironmentSpecific;
import hudson.model.Hudson;
import hudson.model.Node;
import hudson.model.Saveable;
import hudson.model.TaskListener;
import hudson.model.*;
import hudson.slaves.NodeSpecific;
import hudson.util.DescribableList;
import hudson.util.XStream2;
......@@ -74,7 +69,7 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext;
* @author huybrechts
* @since 1.286
*/
public abstract class ToolInstallation implements Serializable, Describable<ToolInstallation>, ExtensionPoint {
public abstract class ToolInstallation extends AbstractDescribableImpl<ToolInstallation> implements Serializable, ExtensionPoint {
private final String name;
private /*almost final*/ String home;
......@@ -135,10 +130,6 @@ public abstract class ToolInstallation implements Serializable, Describable<Tool
return properties;
}
public ToolDescriptor<?> getDescriptor() {
return (ToolDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass());
}
/**
* Finds a tool on a node.
* Checks if the location of the tool is overridden for the given node, and if so,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册