/*
* Copyright 2016 CloudBees, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jenkins.plugins.customtools.util;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import javax.annotation.Nonnull;
//TODO: remove once the dependency is upgrades to 1.596+
/**
* Helper class for accessing Jenkins instances.
* @author Oleg Nenashev
* @since TODO
*/
@Restricted(NoExternalUse.class)
public class JenkinsHelper {
/**
* Gets Jenkins instance and verifies the return value.
* @return Jenkins instance
* @throws IllegalStateException Jenkins has not been started, or was already shut down
*/
@Nonnull
public static Jenkins getInstanceOrDie() throws IllegalStateException {
final Jenkins instance = Jenkins.getInstance();
if (instance == null) {
throw new IllegalStateException("Jenkins has not been started, or was already shut down");
}
return instance;
}
}