/**
  * Finally activates a plugin. Called once the plugin's requirements are met (see
  * PluginImpl.checkRequirementsForActivation()).
  *
  * <p>Activation comprises: - install the plugin in the database (includes migrations,
  * post-install event, type introduction) - initialize the plugin - register the plugin's
  * listeners - add the plugin to the pool of activated plugins
  *
  * <p>If this plugin is already activated, nothing is performed and false is returned. Otherwise
  * true is returned.
  *
  * <p>Note: this method is synchronized. While a plugin is activated no other plugin must be
  * activated. Otherwise the "type introduction" mechanism might miss some types. Consider this
  * unsynchronized scenario: plugin B starts running its migrations just in the moment between
  * plugin A's type introduction and listener registration. Plugin A might miss some of the types
  * created by plugin B.
  */
 synchronized boolean activatePlugin(PluginImpl plugin) {
   try {
     // Note: we must not activate a plugin twice.
     // This would happen e.g. if a dependency plugin is redeployed.
     if (isPluginActivated(plugin.getUri())) {
       logger.info("Activation of " + plugin + " ABORTED -- already activated");
       return false;
     }
     //
     logger.info("----- Activating " + plugin + " -----");
     plugin.installPluginInDB();
     plugin.initializePlugin();
     plugin.registerListeners();
     // Note: registering the listeners is deferred until the plugin is installed in the database
     // and the
     // POST_INSTALL_PLUGIN event is delivered (see PluginImpl.installPluginInDB()).
     // Consider the Access Control plugin: it can't set a topic's creator before the "admin" user
     // is created.
     addToActivatedPlugins(plugin);
     logger.info("----- Activation of " + plugin + " complete -----");
     return true;
   } catch (Exception e) {
     throw new RuntimeException("Activation of " + plugin + " failed", e);
   }
 }
 Set<PluginInfo> getPluginInfo() {
   Set info = new HashSet();
   for (PluginImpl plugin : activatedPlugins.values()) {
     info.add(plugin.getInfo());
   }
   return info;
 }
 public Collection<String> getServerNames() {
   return Collections2.transform(
       PluginImpl.getInstance().getServers(),
       new Function<Hypervisor, String>() {
         public String apply(@Nullable Hypervisor input) {
           return input.getHypervisorHost();
         }
       });
 }
Esempio n. 4
0
  /**
   * Tests {@link Team#doImportViewsSubmit(String, org.kohsuke.stapler.StaplerRequest,
   * org.kohsuke.stapler.StaplerResponse)}.
   *
   * @throws Exception if so
   */
  public void testDoImportViewsSubmit() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    User user = User.get("bob", true);
    MyViewsProperty property = user.getProperty(MyViewsProperty.class);
    ListView view1 = new ListView("view1");
    view1.add(p);
    property.addView(view1);
    ListView view2 = new ListView("view2");
    property.addView(view2);
    user.save();

    PluginImpl.getInstance().addTeam(new Team("Team1", "Description"));
    Team team = PluginImpl.getInstance().getTeams().get("Team1");
    StaplerRequest request = mock(StaplerRequest.class);
    StaplerResponse response = mock(StaplerResponse.class);

    team.doImportViewsSubmit(user.getId(), request, response);

    verify(response).sendRedirect2(Matchers.contains(team.getUrl()));

    TeamViewsProperty views = team.getProperty(TeamViewsProperty.class);
    Collection<View> collection = views.getViews();
    assertEquals(3, collection.size());

    boolean found1 = false;
    boolean found2 = false;
    for (View next : collection) {
      if (next.getViewName().equals("view1")) {
        found1 = true;
        assertNotSame(view1, next);
        assertEquals(1, next.getItems().size());
      } else if (next.getViewName().equals("view2")) {
        found2 = true;
        assertNotSame(view2, next);
      }
    }
    assertTrue(found1);
    assertTrue(found2);
  }
 /**
  * Tests that legacy causes in {@link PluginImpl#causes} gets converted during startup to a {@link
  * com.sonyericsson.jenkins.plugins.bfa.db.LocalFileKnowledgeBase}.
  *
  * @throws Exception if so.
  */
 @LocalData
 public void testLoadVersion1ConfigXml() throws Exception {
   KnowledgeBase knowledgeBase = PluginImpl.getInstance().getKnowledgeBase();
   Collection<FailureCause> causes = knowledgeBase.getCauses();
   assertEquals(3, causes.size());
   Indication indication = null;
   for (FailureCause c : causes) {
     assertNotNull(c.getName() + " should have an id", fixEmpty(c.getId()));
     if ("The Wrong".equals(c.getName())) {
       indication = c.getIndications().get(0);
     }
   }
   assertNotNull("Missing a cause!", indication);
   assertEquals(".+wrong.*", Whitebox.getInternalState(indication, "pattern").toString());
 }
 void deactivatePlugin(PluginImpl plugin) {
   plugin.unregisterListeners();
   removeFromActivatedPlugins(plugin.getUri());
 }
 private void addToActivatedPlugins(PluginImpl plugin) {
   activatedPlugins.put(plugin.getUri(), plugin);
 }