hudson.Plugin类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中hudson.Plugin类的一些代码示例,展示了Plugin类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Plugin类的具体详情如下:
包路径:hudson.Plugin
类名称:Plugin

Plugin介绍

[英]Base class of Hudson plugin.

A plugin needs to derive from this class.

One instance of a plugin is created by Hudson, and used as the entry point to plugin functionality.

A plugin is bound to URL space of Hudson as ${rootURL}/plugin/foo/, where "foo" is taken from your plugin name "foo.hpi". All your web resources in src/main/webapp are visible from this URL, and you can also define Jelly views against your Plugin class, and those are visible in this URL, too.

Plugin can have an optional config.jelly page. If present, it will become a part of the system configuration page (http://server/hudson/configure). This is convenient for exposing/maintaining configuration that doesn't fit any Descriptors.

Up until Hudson 1.150 or something, subclasses of Plugin required @plugin javadoc annotation, but that is no longer a requirement.
[中]Hudson插件的基类。
插件需要从这个类派生。
Hudson创建了一个插件实例,并将其用作插件功能的入口点。
一个插件以${rootURL}/plugin/foo/的形式绑定到Hudson的URL空间,其中“foo”取自您的插件名“foo.hpi”。src/main/webapp中的所有web资源都可以从此URL中看到,您还可以根据插件类定义Jelly视图,这些也可以在此URL中看到。
插件可以有一个可选的配置。果冻页面。如果存在,它将成为系统配置页面的一部分(http://server/hudson/configure)。这便于公开/维护不符合任何描述符的配置。
在Hudson 1.150或其他版本之前,Plugin的子类需要@Plugin javadoc annotation,但这不再是必需的。

代码示例

代码示例来源:origin: stackoverflow.com

ObjectRecipe recipe = new ObjectRecipe(redDefinition.remove("className").toString());
recipe.setAllProperties(redDefinition);

Plugin red = (Plugin) recipe.create();
red.start();

代码示例来源:origin: jenkinsci/jenkins

/**
 * Terminates the plugin.
 */
public void stop() {
  Plugin plugin = getPlugin();
  if (plugin != null) {
    try {
      LOGGER.log(Level.FINE, "Stopping {0}", shortName);
      plugin.stop();
    } catch (Throwable t) {
      LOGGER.log(WARNING, "Failed to shut down " + shortName, t);
    }
  } else {
    LOGGER.log(Level.FINE, "Could not find Plugin instance to stop for {0}", shortName);
  }
  // Work around a bug in commons-logging.
  // See http://www.szegedi.org/articles/memleak.html
  LogFactory.release(classLoader);
}

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

if (plugin.getWrapper().getVersion().equals(p.version)) {
if ("latest".equals(p.version) && plugin != null && plugin.getWrapper().getVersion().equals(installable.version)) {

代码示例来源:origin: jenkinsci/jenkins

Thread.currentThread().setContextClassLoader(wrapper.classLoader);
try {
  String className = wrapper.getPluginClass();
  if(className==null) {
    wrapper.setPlugin(new DummyImpl());
  } else {
    try {
        throw new IOException(className+" doesn't extend from hudson.Plugin");
      wrapper.setPlugin((Plugin) o);
    } catch (LinkageError | ClassNotFoundException e) {
      throw new IOException("Unable to load " + className + " from " + wrapper.getShortName(),e);
    Plugin plugin = wrapper.getPlugin();
    plugin.setServletContext(pluginManager.context);
    startPlugin(wrapper);
  } catch(Throwable t) {

代码示例来源:origin: org.eclipse.hudson/hudson-inject

/**
 * Configures and starts the {@link hudson.Plugin} instance.
 */
private void start(final PluginWrapper plugin) throws Exception {
  assert plugin != null;
  if (log.isDebugEnabled()) {
    log.debug("Starting plugin: {}", plugin.getShortName());
  }
  Plugin instance = plugin.getPlugin();
  instance.setServletContext(Hudson.getInstance().servletContext);
  instance.start();
}

代码示例来源:origin: jenkinsci/jenkins

public void startPlugin(PluginWrapper plugin) throws Exception {
  plugin.getPlugin().start();
}

代码示例来源:origin: etsy/jenkins-master-project

@Override
public boolean isApplicable(Class<? extends Job> jobType) {
  return jobType.equals(MasterProject.class) && hudson.getPlugin("slack") != null && hudson.getPlugin("slack").getWrapper().isActive();
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    try {
      for( JSONObject o : StructuredForm.toList(json, "plugin"))
        Jenkins.get().pluginManager.getPlugin(o.getString("name")).getPlugin().configure(req, o);
      return true;
    } catch (IOException | ServletException e) {
      throw new FormException(e,"plugin");
    }
  }
}

代码示例来源:origin: com.coravy.hudson.plugins.github/github

@Override
public void stop() throws Exception {
  super.stop();
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Handles the submission for the system configuration.
 *
 * <p>
 * If this class defines {@code config.jelly} view, be sure to
 * override this method and persists the submitted values accordingly.
 *
 * <p>
 * The following is a sample {@code config.jelly} that you can start yours with:
 * <pre>{@code <xmp>
 * <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
 *   <f:section title="Locale">
 *     <f:entry title="${%Default Language}" help="/plugin/locale/help/default-language.html">
 *       <f:textbox name="systemLocale" value="${it.systemLocale}" />
 *     </f:entry>
 *   </f:section>
 * </j:jelly>
 * </xmp>}</pre>
 *
 * <p>
 * This allows you to access data as {@code formData.getString("systemLocale")}
 *
 * <p>
 * If you are using this method, you'll likely be interested in
 * using {@link #save()} and {@link #load()}.
 * @since 1.305
 */
public void configure(StaplerRequest req, JSONObject formData) throws IOException, ServletException, FormException {
  configure(formData);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Report to the administrator if the plugin with the given name is older then the required version.
 *
 * @param pluginName shortName of the plugin (artifactId)
 * @param requiredVersion the lowest version which is OK (e.g. 2.2.2)
 * @param message the message to show (plain text)
 */
public void ifPluginOlderThenReport(String pluginName, String requiredVersion, String message){
  Plugin plugin = Jenkins.getInstance().getPlugin(pluginName);
  if(plugin != null){
    if(plugin.getWrapper().getVersionNumber().isOlderThan(new VersionNumber(requiredVersion))) {
      pluginsToBeUpdated.put(pluginName, new PluginUpdateInfo(pluginName, message));
    }
  }
}

代码示例来源:origin: jenkinsci/maven-plugin

if(StringUtils.isNotBlank(this.settingConfigId) || StringUtils.isNotBlank(this.globalSettingConfigId)) {
  plugin = Jenkins.getInstance().getPlugin("config-file-provider");
  if(plugin == null || !plugin.getWrapper().isEnabled()){
    LOGGER.severe(Messages.MavenModuleSet_readResolve_missingConfigProvider());
} else if (plugin != null && StringUtils.isNotBlank(this.settingConfigId)) {
  try {
    Class<? extends SettingsProvider> legacySettings = plugin.getWrapper().classLoader.loadClass("org.jenkinsci.plugins.configfiles.maven.job.MvnSettingsProvider").asSubclass(SettingsProvider.class);
    SettingsProvider newInstance = legacySettings.newInstance();
    PropertyUtils.setProperty(newInstance, "settingsConfigId", this.settingConfigId);
    Class<? extends GlobalSettingsProvider> legacySettings = plugin.getWrapper().classLoader.loadClass("org.jenkinsci.plugins.configfiles.maven.job.MvnGlobalSettingsProvider").asSubclass(GlobalSettingsProvider.class);
    GlobalSettingsProvider newInstance = legacySettings.newInstance();
    PropertyUtils.setProperty(newInstance, "settingsConfigId", this.globalSettingConfigId);

代码示例来源:origin: jenkinsci/jenkins

/**
 * Loads serializable fields of this instance from the persisted storage.
 *
 * <p>
 * If there was no previously persisted state, this method is no-op.
 *
 * @since 1.245
 */
protected void load() throws IOException {
  XmlFile xml = getConfigXml();
  if(xml.exists())
    xml.unmarshal(this);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

Thread.currentThread().setContextClassLoader(wrapper.classLoader);
try {
  String className = wrapper.getPluginClass();
  if(className==null) {
    wrapper.setPlugin(new DummyImpl());
  } else {
    try {
        throw new IOException(className+" doesn't extend from hudson.Plugin");
      wrapper.setPlugin((Plugin) o);
    } catch (LinkageError | ClassNotFoundException e) {
      throw new IOException("Unable to load " + className + " from " + wrapper.getShortName(),e);
    Plugin plugin = wrapper.getPlugin();
    plugin.setServletContext(pluginManager.context);
    startPlugin(wrapper);
  } catch(Throwable t) {

代码示例来源:origin: org.eclipse.hudson.main/hudson-inject

/**
 * Configures and starts the {@link hudson.Plugin} instance.
 */
private void start(final PluginWrapper plugin) throws Exception {
  assert plugin != null;
  if (log.isDebugEnabled()) {
    log.debug("Starting plugin: {}", plugin.getShortName());
  }
  Plugin instance = plugin.getPlugin();
  instance.setServletContext(Hudson.getInstance().servletContext);
  instance.start();
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public void startPlugin(PluginWrapper plugin) throws Exception {
  plugin.getPlugin().start();
}

代码示例来源:origin: jenkinsci/parameterized-trigger-plugin

public static boolean isConditionalBuildStepInstalled(){
      final hudson.Plugin plugin = Jenkins.getInstance().getPlugin("conditional-buildstep");
      return plugin != null ? plugin.getWrapper().isActive() : false;
    }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    try {
      for( JSONObject o : StructuredForm.toList(json, "plugin"))
        Jenkins.getInstance().pluginManager.getPlugin(o.getString("name")).getPlugin().configure(req, o);
      return true;
    } catch (IOException | ServletException e) {
      throw new FormException(e,"plugin");
    }
  }
}

代码示例来源:origin: jenkinsci/virtualbox-plugin

@Override
public void stop() throws Exception {
 LOG.log(Level.INFO, "Stopping {0}", getClass().getSimpleName());
 super.stop();
 // close VirtualBox WEB sessions
 VirtualBoxUtils.disconnectAll();
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Handles the submission for the system configuration.
 *
 * <p> If this class defines <tt>config.jelly</tt> view, be sure to override
 * this method and persists the submitted values accordingly.
 *
 * <p> The following is a sample <tt>config.jelly</tt> that you can start
 * yours with:
 * <pre><xmp>
 * <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
 *   <f:section title="Locale">
 *     <f:entry title="${%Default Language}" help="/plugin/locale/help/default-language.html">
 *       <f:textbox name="systemLocale" value="${it.systemLocale}" />
 *     </f:entry>
 *   </f:section>
 * </j:jelly>
 * </xmp></pre>
 *
 * <p> This allows you to access data as
 * {@code formData.getString("systemLocale")}
 *
 * <p> If you are using this method, you'll likely be interested in using
 * {@link #save()} and {@link #load()}.
 *
 * @since 1.305
 */
public void configure(StaplerRequest req, JSONObject formData) throws IOException, ServletException, FormException {
  configure(formData);
}

相关文章