Skip to content

Commit

Permalink
[FIXED JENKINS-38347] Use Initializer levels. (#139)
Browse files Browse the repository at this point in the history
* [FIXED JENKINS-38347] Use Initializer levels.

- migrator: Don't throw NPE because Descriptor wasn't ready.
- aliases: user annotation initializer.

* Ensure execution order.

Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>

* Move to javadoc
  • Loading branch information
KostyaSha authored and lanwen committed Sep 20, 2016
1 parent 980faa5 commit cb7525c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/main/java/org/jenkinsci/plugins/github/GitHubPlugin.java
@@ -1,16 +1,19 @@
package org.jenkinsci.plugins.github;

import hudson.Plugin;
import hudson.init.Initializer;
import org.jenkinsci.plugins.github.config.GitHubPluginConfig;
import org.jenkinsci.plugins.github.migration.Migrator;

import javax.annotation.Nonnull;

import static hudson.init.InitMilestone.PLUGINS_PREPARED;
import static hudson.init.InitMilestone.PLUGINS_STARTED;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;

/**
* Main entry point for this plugin
*
* <p>
* Launches migration from old config versions
* Contains helper method to get global plugin configuration - {@link #configuration()}
*
Expand All @@ -19,24 +22,33 @@
public class GitHubPlugin extends Plugin {
/**
* Launched before plugin starts
* Adds alias for {@link GitHubPlugin} to simplify resulting xml
* Adds alias for {@link GitHubPlugin} to simplify resulting xml.
* Expected milestone: @Initializer(before = PLUGINS_STARTED)
* * @see #initializers()
*/
public static void init() {
public static void addXStreamAliases() {
Migrator.enableCompatibilityAliases();
Migrator.enableAliases();
}

@Override
public void start() throws Exception {
init();
/**
* Launches migration after plugin already initialized.
* Expected milestone: @Initializer(after = PLUGINS_PREPARED)
*
* @see #initializers()
*/
public static void runMigrator() throws Exception {
new Migrator().migrate();
}

/**
* Launches migration after plugin already initialized
* We need ensure that migrator will run after xstream aliases will be added.
* Unclear how reactor will sort single methods, so bundle in one step.
*/
@Override
public void postInitialize() throws Exception {
new Migrator().migrate();
@Initializer(after = PLUGINS_PREPARED, before = PLUGINS_STARTED)
public static void initializers() throws Exception {
addXStreamAliases();
runMigrator();
}

/**
Expand Down

0 comments on commit cb7525c

Please sign in to comment.