hudson.init.InitMilestone Java Examples

The following examples show how to use hudson.init.InitMilestone. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BackwardCompatibility.java    From lockable-resources-plugin with MIT License 6 votes vote down vote up
@Initializer(after = InitMilestone.JOB_LOADED)
public static void compatibilityMigration() {
	LOG.log(Level.FINE, "lockable-resource-plugin compatibility migration task run");
	List<LockableResource> resources = LockableResourcesManager.get().getResources();
	for (LockableResource resource : resources) {
		List<StepContext> queuedContexts = resource.getQueuedContexts();
		if (!queuedContexts.isEmpty()) {
			for (StepContext queuedContext : queuedContexts) {
				List<String> resourcesNames = new ArrayList<>();
				resourcesNames.add(resource.getName());
				LockableResourcesStruct resourceHolder = new LockableResourcesStruct(resourcesNames, "", 0);
				LockableResourcesManager.get().queueContext(queuedContext, Arrays.asList(resourceHolder), resource.getName(), null);
			}
			queuedContexts.clear();
		}
	}
}
 
Example #2
Source File: GitLabConnection.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Initializer(after = InitMilestone.PLUGINS_STARTED)
public static void migrate() throws IOException {
    GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.get().getDescriptor(GitLabConnectionConfig.class);
    if (descriptor == null) return;
    for (GitLabConnection connection : descriptor.getConnections()) {
        if (connection.apiTokenId == null && connection.apiToken != null) {
            for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
                if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
                    List<Domain> domains = credentialsStore.getDomains();
                    connection.apiTokenId = UUID.randomUUID().toString();
                    credentialsStore.addCredentials(domains.get(0),
                        new GitLabApiTokenImpl(CredentialsScope.SYSTEM, connection.apiTokenId, "GitLab API Token", Secret.fromString(connection.apiToken)));
                }
            }
        }
    }
    descriptor.save();
}
 
Example #3
Source File: DockerSwarmCloud.java    From docker-swarm-plugin with MIT License 6 votes vote down vote up
@Initializer(after = InitMilestone.JOB_LOADED)
public static void initFromYaml() throws IOException {
    File configsDir = new File(Jenkins.getInstance().getRootDir(), "pluginConfigs");
    File swarmConfigYaml = new File(configsDir, "swarm.yml");
    if (swarmConfigYaml.exists()) {
        LOGGER.info("Configuring swarm plugin from " + swarmConfigYaml.getAbsolutePath());
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        try (InputStream in = new BufferedInputStream(new FileInputStream(swarmConfigYaml))) {
            DockerSwarmCloud configuration = mapper.readValue(in, DockerSwarmCloud.class);
            DockerSwarmCloud existingCloud = DockerSwarmCloud.get();
            if (existingCloud != null) {
                Jenkins.getInstance().clouds.remove(existingCloud);
            }
            Jenkins.getInstance().clouds.add(configuration);
        }
    }
    scheduleReaperActor();
    scheduleResetStuckBuildsActor();
}
 
Example #4
Source File: GitLabSCMWebHook.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Initializer(after = InitMilestone.JOB_LOADED)
public static void initialize() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            ACL.impersonate(ACL.SYSTEM, new ListenerInitializerTask(GitLabSCMWebHook.get()));
        }
    }).start();
}
 
Example #5
Source File: GitHubSCMSource.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Override
public void close() throws IOException {
    if (fullScanRequested && iterationCompleted) {
        // we needed a full scan and the scan was completed, so trim the cache entries
        pullRequestMetadataCache.keySet().retainAll(pullRequestMetadataKeys);
        pullRequestContributorCache.keySet().retainAll(pullRequestMetadataKeys);
        if (Jenkins.get().getInitLevel().compareTo(InitMilestone.JOB_LOADED) > 0) {
            // synchronization should be cheap as only writers would be looking for this just to
            // write null
            synchronized (pullRequestSourceMapLock) {
                pullRequestSourceMap = null; // all data has to have been migrated
            }
        }
    }
}
 
Example #6
Source File: KubernetesCloud.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addAliases() {
    Jenkins.XSTREAM2.addCompatibilityAlias(
            "org.csanchez.jenkins.plugins.kubernetes.OpenShiftBearerTokenCredentialImpl",
            org.jenkinsci.plugins.kubernetes.credentials.OpenShiftBearerTokenCredentialImpl.class);
    Jenkins.XSTREAM2.addCompatibilityAlias(
            "org.csanchez.jenkins.plugins.kubernetes.OpenShiftTokenCredentialImpl",
            StringCredentialsImpl.class);
    Jenkins.XSTREAM2.addCompatibilityAlias("org.csanchez.jenkins.plugins.kubernetes.ServiceAccountCredential",
            org.jenkinsci.plugins.kubernetes.credentials.FileSystemServiceAccountCredential.class);
}
 
Example #7
Source File: MatrixMultiBranchProject.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
/**
 * Gives this class an alias for configuration XML.
 */
@Initializer(before = InitMilestone.PLUGINS_STARTED)
@SuppressWarnings(UNUSED)
public static void registerXStream() {
    Items.XSTREAM.alias("matrix-multi-branch-project", MatrixMultiBranchProject.class);
}
 
Example #8
Source File: PluginImpl.java    From zulip-plugin with MIT License 4 votes vote down vote up
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addAliases() {
  Items.XSTREAM2.addCompatibilityAlias("hudson.plugins.humbug.HumbugNotifier", ZulipNotifier.class);
}
 
Example #9
Source File: ResteasyGitLabClientBuilder.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void setRuntimeDelegate() {
    RuntimeDelegate.setInstance(new ResteasyProviderFactory());
}
 
Example #10
Source File: MavenMultiBranchProject.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
/**
 * Gives this class an alias for configuration XML.
 */
@Initializer(before = InitMilestone.PLUGINS_STARTED)
@SuppressWarnings(UNUSED)
public static void registerXStream() {
    Items.XSTREAM.alias("maven-multi-branch-project", MavenMultiBranchProject.class);
}
 
Example #11
Source File: FreeStyleMultiBranchProject.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
/**
 * Gives this class an alias for configuration XML.
 */
@Initializer(before = InitMilestone.PLUGINS_STARTED)
@SuppressWarnings("unused")
public static void registerXStream() {
    Items.XSTREAM.alias("freestyle-multi-branch-project", FreeStyleMultiBranchProject.class);
}
 
Example #12
Source File: IvyMultiBranchProject.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
/**
 * Gives this class an alias for configuration XML.
 */
@SuppressWarnings(UNUSED)
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void registerXStream() {
    Items.XSTREAM.alias("ivy-multi-branch-project", IvyMultiBranchProject.class);
}
 
Example #13
Source File: BranchListView.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
/**
 * Gives this class an alias for configuration XML.
 */
@SuppressWarnings(UNUSED)
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void registerXStream() {
    Items.XSTREAM.alias("branch-list-view", BranchListView.class);
}
 
Example #14
Source File: GitHubSCMSource.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addAliases() {
    XSTREAM2.addCompatibilityAlias("org.jenkinsci.plugins.github_branch_source.OriginGitHubSCMSource", GitHubSCMSource.class);
}
 
Example #15
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 4 votes vote down vote up
/**
 * Override to set up your specific external resource.
 * @throws Throwable if setup fails (which will disable {@code after}
 */
public void before() throws Throwable {
    for (Handler h : Logger.getLogger("").getHandlers()) {
        if (h instanceof ConsoleHandler) {
            ((ConsoleHandler) h).setFormatter(new DeltaSupportLogFormatter());
        }
    }

    if (Thread.interrupted()) { // JENKINS-30395
        LOGGER.warning("was interrupted before start");
    }

    if(Functions.isWindows()) {
        // JENKINS-4409.
        // URLConnection caches handles to jar files by default,
        // and it prevents delete temporary directories on Windows.
        // Disables caching here.
        // Though defaultUseCache is a static field,
        // its setter and getter are provided as instance methods.
        URLConnection aConnection = new File(".").toURI().toURL().openConnection();
        origDefaultUseCache = aConnection.getDefaultUseCaches();
        aConnection.setDefaultUseCaches(false);
    }
    
    // Not ideal (https://github.com/junit-team/junit/issues/116) but basically works.
    if (Boolean.getBoolean("ignore.random.failures")) {
        RandomlyFails rf = testDescription.getAnnotation(RandomlyFails.class);
        if (rf != null) {
            throw new AssumptionViolatedException("Known to randomly fail: " + rf.value());
        }
    }

    env = new TestEnvironment(testDescription);
    env.pin();
    recipe();
    AbstractProject.WORKSPACE.toString();
    User.clear();

    try {
        Field theInstance = Jenkins.class.getDeclaredField("theInstance");
        theInstance.setAccessible(true);
        if (theInstance.get(null) != null) {
            LOGGER.warning("Jenkins.theInstance was not cleared by a previous test, doing that now");
            theInstance.set(null, null);
        }
    } catch (Exception x) {
        LOGGER.log(Level.WARNING, null, x);
    }

    try {
        jenkins = hudson = newHudson();
        // If the initialization graph is corrupted, we cannot expect that Jenkins is in the good shape.
        // Likely it is an issue in @Initializer() definitions (see JENKINS-37759).
        // So we just fail the test.
        if (jenkins.getInitLevel() != InitMilestone.COMPLETED) {
            throw new Exception("Jenkins initialization has not reached the COMPLETED initialization stage. Current state is " + jenkins.getInitLevel() +
                    ". Likely there is an issue with the Initialization task graph (e.g. usage of @Initializer(after = InitMilestone.COMPLETED)). See JENKINS-37759 for more info");
        }
    } catch (Exception e) {
        // if Hudson instance fails to initialize, it leaves the instance field non-empty and break all the rest of the tests, so clean that up.
        Field f = Jenkins.class.getDeclaredField("theInstance");
        f.setAccessible(true);
        f.set(null,null);
        throw e;
    }

    jenkins.setCrumbIssuer(new TestCrumbIssuer());  // TODO: Move to _configureJenkinsForTest after JENKINS-55240
    _configureJenkinsForTest(jenkins);
    configureUpdateCenter();

    // expose the test instance as a part of URL tree.
    // this allows tests to use a part of the URL space for itself.
    jenkins.getActions().add(this);

    JenkinsLocationConfiguration.get().setUrl(getURL().toString());
}
 
Example #16
Source File: BuildStatusConfig.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
/**
 * Adds compatibility aliases to prevent "old data" warnings.
 */
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addCompatibilityAliases() {
    XSTREAM2.addCompatibilityAlias("org.jenkinsci.plugins.githubautostatus.BuildStageModel", BuildStage.class);
    XSTREAM2.addCompatibilityAlias("org.jenkinsci.plugins.githubautostatus.notifiers.BuildState", BuildState.class);
}
 
Example #17
Source File: IssuesRecorder.java    From warnings-ng-plugin with MIT License 4 votes vote down vote up
/** Retain backward compatibility. */
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addAliases() {
    Run.XSTREAM2.addCompatibilityAlias("io.jenkins.plugins.analysis.core.views.ResultAction",
            ResultAction.class);
}
 
Example #18
Source File: ConfigurationAsCode.java    From configuration-as-code-plugin with MIT License 3 votes vote down vote up
/**
 * Defaults to use a file in the current working directory with the name 'jenkins.yaml'
 *
 * Add the environment variable CASC_JENKINS_CONFIG to override the default. Accepts single file or a directory.
 * If a directory is detected, we scan for all .yml and .yaml files
 *
 * @throws Exception when the file provided cannot be found or parsed
 */
@Restricted(NoExternalUse.class)
@Initializer(after = InitMilestone.SYSTEM_CONFIG_LOADED, before = InitMilestone.SYSTEM_CONFIG_ADAPTED)
public static void init() throws Exception {
    detectVaultPluginMissing();
    get().configure();
}