Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 target Jenkins v164.1 #790

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion integrations/pom.xml
Expand Up @@ -12,7 +12,6 @@
<name>Configuration as Code Integration tests</name>

<properties>
<jenkins.version>2.164.1</jenkins.version> <!-- Remove when parent base is updated. -->
<maven.deploy.skip>true</maven.deploy.skip> <!-- no need to be deployed during release, this is a test-only module -->
<enforcer.skip>true</enforcer.skip> <!-- no need to be enforced, this is a test-only module -->
</properties>
Expand Down
Expand Up @@ -146,7 +146,7 @@ public List<String> getSources() {

@RequirePOST
public void doReload(StaplerRequest request, StaplerResponse response) throws Exception {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Expand All @@ -156,7 +156,7 @@ public void doReload(StaplerRequest request, StaplerResponse response) throws Ex

@RequirePOST
public void doReplace(StaplerRequest request, StaplerResponse response) throws Exception {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Expand Down Expand Up @@ -199,7 +199,7 @@ private boolean canApplyFrom(List<YamlSource> yamlSources) {

@POST
public FormValidation doCheckNewSource(@QueryParameter String newSource) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
String normalizedSource = Util.fixEmptyAndTrim(newSource);
File file = new File(Util.fixNull(normalizedSource));
if (normalizedSource == null) {
Expand Down Expand Up @@ -302,7 +302,7 @@ private List<String> getStandardConfig() {
}

if (configParameter == null) {
String fullPath = Jenkins.getInstance().getRootDir() + File.separator + DEFAULT_JENKINS_YAML_PATH;
String fullPath = Jenkins.get().getRootDir() + File.separator + DEFAULT_JENKINS_YAML_PATH;
if (Files.exists(Paths.get(fullPath))) {
configParameter = fullPath;
}
Expand All @@ -324,7 +324,7 @@ public List<String> getBundledCasCURIs() {
final String cascDirectory = "/WEB-INF/" + DEFAULT_JENKINS_YAML_PATH + ".d/";
List<String> res = new ArrayList<>();

final ServletContext servletContext = Jenkins.getInstance().servletContext;
final ServletContext servletContext = Jenkins.get().servletContext;
try {
URL bundled = servletContext.getResource(cascFile);
if (bundled != null) {
Expand Down Expand Up @@ -356,7 +356,7 @@ public List<String> getBundledCasCURIs() {
@RequirePOST
public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
res.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Expand All @@ -372,7 +372,7 @@ public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception {
@RequirePOST
public void doApply(StaplerRequest req, StaplerResponse res) throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
res.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Expand All @@ -386,7 +386,7 @@ public void doApply(StaplerRequest req, StaplerResponse res) throws Exception {
@RequirePOST
public void doExport(StaplerRequest req, StaplerResponse res) throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
res.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Expand Down Expand Up @@ -668,7 +668,7 @@ public Map<Source, String> checkWith(Mapping entries) throws ConfiguratorExcepti


public static ConfigurationAsCode get() {
return Jenkins.getInstance().getExtensionList(ConfigurationAsCode.class).get(0);
return Jenkins.get().getExtensionList(ConfigurationAsCode.class).get(0);
}

/**
Expand Down
Expand Up @@ -40,6 +40,6 @@ public interface ConfiguratorRegistry {
* Retrieve default implementation from Jenkins
*/
static ConfiguratorRegistry get() {
return Jenkins.getInstance().getExtensionList(ConfiguratorRegistry.class).get(0);
return Jenkins.get().getExtensionList(ConfiguratorRegistry.class).get(0);
}
}
Expand Up @@ -19,7 +19,7 @@ public interface RootElementConfigurator<T> extends Configurator<T> {

static List<RootElementConfigurator> all() {
List<RootElementConfigurator> configurators = new ArrayList<>();
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
configurators.addAll(jenkins.getExtensionList(RootElementConfigurator.class));

for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) {
Expand All @@ -28,7 +28,7 @@ static List<RootElementConfigurator> all() {

for (ManagementLink link : ManagementLink.all()) {
final String name = link.getUrlName();
final Descriptor descriptor = Jenkins.getInstance().getDescriptor(name);
final Descriptor descriptor = Jenkins.get().getDescriptor(name);
if (descriptor != null)
configurators.add(new DescriptorConfigurator(descriptor));
}
Expand Down
Expand Up @@ -24,7 +24,7 @@ public void init() {

public static List<SecretSource> all() {
List<SecretSource> all = new ArrayList<>();
all.addAll(Jenkins.getInstance().getExtensionList(SecretSource.class));
all.addAll(Jenkins.get().getExtensionList(SecretSource.class));
return all;
}
}
Expand Up @@ -23,7 +23,7 @@ public String getShortDescription() {
@Override
protected int run() throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return -1;
}

Expand Down
Expand Up @@ -25,7 +25,7 @@ public String getShortDescription() {
@Override
protected int run() throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return -1;
}

Expand Down
Expand Up @@ -22,7 +22,7 @@ public String getShortDescription() {
@Override
protected int run() throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return -1;
}

Expand Down
Expand Up @@ -22,7 +22,7 @@ public String getShortDescription() {
@Override
protected int run() throws Exception {

if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return -1;
}

Expand Down
Expand Up @@ -38,7 +38,7 @@ public Class<Jenkins> getTarget() {

@Override
public Jenkins getTargetComponent(ConfigurationContext context) {
return Jenkins.getInstance();
return Jenkins.get();
}

@Override
Expand Down
Expand Up @@ -48,7 +48,7 @@ protected GlobalMavenConfig instance(Mapping mapping, ConfigurationContext conte
@Override
public Set<Attribute<GlobalMavenConfig,?>> describe() {
final Set<Attribute<GlobalMavenConfig,?>> attributes = super.describe();
final Descriptor descriptor = Jenkins.getInstance().getDescriptorOrDie(Maven.class);
final Descriptor descriptor = Jenkins.get().getDescriptorOrDie(Maven.class);
final Configurator<Descriptor> task = new DescriptorConfigurator(descriptor);

for (Attribute attribute : task.describe()) {
Expand Down
Expand Up @@ -34,7 +34,7 @@ public Class getImplementedAPI() {

@Override
public String getDisplayName() {
return Jenkins.getInstance().getDescriptorOrDie(Unsecured.class).getDisplayName();
return Jenkins.get().getDescriptorOrDie(Unsecured.class).getDisplayName();
}

@Override
Expand Down
Expand Up @@ -38,7 +38,7 @@ protected void configure(Mapping config, UpdateCenter instance, boolean dryrun,

@Override
protected UpdateCenter instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException {
return Jenkins.getInstance().getUpdateCenter();
return Jenkins.get().getUpdateCenter();
}

@Override
Expand Down
Expand Up @@ -101,7 +101,7 @@ public Configurator load(@NonNull Type type) throws Exception {
private Configurator internalLookup(Type type) {
Class clazz = Types.erasure(type);

final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
final ExtensionList<Configurator> l = jenkins.getExtensionList(Configurator.class);
for (Configurator c : l) {
if (c.canConfigure(clazz)) {
Expand Down
Expand Up @@ -25,7 +25,7 @@ public DescribableAttribute(String name, Class<? extends Describable> type) {

@Override
public List<String> possibleValues() {
final List<Descriptor> descriptors = Jenkins.getInstance().getDescriptorList(type);
final List<Descriptor> descriptors = Jenkins.get().getDescriptorList(type);
return descriptors.stream()
.map(d -> getPreferredSymbol(d, type, d.getKlass().toJavaClass()))
.collect(Collectors.toList());
Expand Down
Expand Up @@ -165,7 +165,7 @@ public String getName() {
}

private Descriptor getDescriptor() {
return Jenkins.getInstance().getDescriptor(getTarget());
return Jenkins.get().getDescriptor(getTarget());
}

@NonNull
Expand Down
Expand Up @@ -35,7 +35,7 @@ public Class<T> getTarget() {

@Override
protected T instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException {
final ExtensionList<T> list = Jenkins.getInstance().getExtensionList(target);
final ExtensionList<T> list = Jenkins.get().getExtensionList(target);
if (list.size() != 1) {
throw new ConfiguratorException("Expected a unique instance of extension "+target);
}
Expand Down
Expand Up @@ -72,7 +72,7 @@ protected GlobalConfigurationCategory instance(Mapping mapping, ConfigurationCon
@NonNull
@Override
public Set describe() {
return (Set) Jenkins.getInstance().getExtensionList(Descriptor.class).stream()
return (Set) Jenkins.get().getExtensionList(Descriptor.class).stream()
.filter(d -> d.getCategory() == category)
.filter(d -> d.getGlobalConfigPage() != null)
.map(DescriptorConfigurator::new)
Expand All @@ -94,7 +94,7 @@ public static boolean reportDescriptorWithoutSetters(Configurator c) {
public CNode describe(GlobalConfigurationCategory instance, ConfigurationContext context) {

final Mapping mapping = new Mapping();
Jenkins.getInstance().getExtensionList(Descriptor.class).stream()
Jenkins.get().getExtensionList(Descriptor.class).stream()
.filter(this::filterDescriptors)
.forEach(d -> describe(d, mapping, context));
return mapping;
Expand Down
Expand Up @@ -134,7 +134,7 @@ private Configurator<T> forceLookupConfigurator(ConfigurationContext context, De
}

private Stream<Descriptor<T>> getDescriptors() {
return Stream.ofAll(Jenkins.getInstance().getDescriptorList(target));
return Stream.ofAll(Jenkins.get().getDescriptorList(target));
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -181,7 +181,7 @@ private String preferredSymbol(Descriptor<?> descriptor) {
}

private Boolean lookupPlugin(String name) {
return Option.of(Jenkins.getInstance().getPlugin(name)).isDefined();
return Option.of(Jenkins.get().getPlugin(name)).isDefined();
}

private HashMap<String, Descriptor<T>> handleDuplicateSymbols(HashMap<String, Descriptor<T>> r, Tuple2<String, Descriptor<T>> t) {
Expand Down
Expand Up @@ -22,7 +22,7 @@ public class AgentProtocolsTest {
@Test
@ConfiguredWithCode(value = "AgentProtocolsTest.yml")
public void configure_agent_protocols() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
final Set<String> agentProtocols =
Arrays.stream(new String[]{"JNLP4-connect", "Ping"}).collect(Collectors.toSet());
assertEquals(agentProtocols, jenkins.getAgentProtocols());
Expand Down
Expand Up @@ -29,15 +29,15 @@ public class JenkinsConfigTest {

@Test
public void loadFromCASC_JENKINS_CONFIG() {
Jenkins j = Jenkins.getInstance();
Jenkins j = Jenkins.get();
assertEquals("configuration as code - JenkinsConfigTest", j.getSystemMessage());
assertEquals(10, j.getQuietPeriod());
}


@Test
public void shouldExportEvenOnError() throws Exception {
Jenkins j = Jenkins.getInstance();
Jenkins j = Jenkins.get();
j.setCrumbIssuer(new BrokenCrumbIssuer("bar"));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
ConfigurationAsCode.get().export(out);
Expand Down
Expand Up @@ -48,7 +48,7 @@ public class AdminWhitelistRuleConfiguratorTest {
@Issue("Issue #28")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_enabled.yml")
public void checkM2ASecurityKillSwitch_disabled() {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
Assert.assertFalse("MasterToAgent Security should be disabled", rule.getMasterKillSwitch());
}
Expand All @@ -57,7 +57,7 @@ public void checkM2ASecurityKillSwitch_disabled() {
@Issue("Issue #28")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_disabled.yml")
public void checkM2ASecurityKillSwitch_enabled() {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
Assert.assertTrue("MasterToAgent Security should be enabled", rule.getMasterKillSwitch());
}
Expand All @@ -66,7 +66,7 @@ public void checkM2ASecurityKillSwitch_enabled() {
@Issue("Issue #172")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_enabled.yml")
public void checkA2MAccessControl_enabled() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
MasterKillSwitchConfiguration config = jenkins.getDescriptorByType(MasterKillSwitchConfiguration.class);
Assert.assertTrue("Agent → Master Access Control should be enabled", config.getMasterToSlaveAccessControl());
AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
Expand All @@ -82,7 +82,7 @@ public void checkA2MAccessControl_enabled() throws Exception {
@Issue("Issue #172")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_disabled.yml")
public void checkA2MAccessControl_disable() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
MasterKillSwitchConfiguration config = jenkins.getDescriptorByType(MasterKillSwitchConfiguration.class);
Assert.assertFalse("Agent → Master Access Control should be disabled", config.getMasterToSlaveAccessControl());
AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class HudsonPrivateSecurityRealmConfiguratorTest {
@Test
@ConfiguredWithCode("HudsonPrivateSecurityRealmConfiguratorTest.yml")
public void configure_local_security_and_admin_user() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
final HudsonPrivateSecurityRealm securityRealm = (HudsonPrivateSecurityRealm) jenkins.getSecurityRealm();
assertFalse(securityRealm.allowsSignup());
final User admin = User.getById("admin", false);
Expand Down
Expand Up @@ -29,14 +29,14 @@ public class JenkinsConfiguratorTest {
@Test
@ConfiguredWithCode("Primitives.yml")
public void jenkins_primitive_attributes() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
assertEquals(6666, jenkins.getSlaveAgentPort());
}

@Test
@ConfiguredWithCode("HeteroDescribable.yml")
public void jenkins_abstract_describable_attributes() throws Exception {
final Jenkins jenkins = Jenkins.getInstance();
final Jenkins jenkins = Jenkins.get();
assertTrue(jenkins.getSecurityRealm() instanceof HudsonPrivateSecurityRealm);
assertTrue(jenkins.getAuthorizationStrategy() instanceof FullControlOnceLoggedInAuthorizationStrategy);
assertFalse(((FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy()).isAllowAnonymousRead());
Expand All @@ -46,7 +46,7 @@ public void jenkins_abstract_describable_attributes() throws Exception {
@Issue("Issue #173")
@ConfiguredWithCode("SetEnvironmentVariable.yml")
public void shouldSetEnvironmentVariable() throws Exception {
final DescribableList<NodeProperty<?>, NodePropertyDescriptor> properties = Jenkins.getInstance().getNodeProperties();
final DescribableList<NodeProperty<?>, NodePropertyDescriptor> properties = Jenkins.get().getNodeProperties();
EnvVars env = new EnvVars();
for (NodeProperty<?> property : properties) {
property.buildEnvVars(env, TaskListener.NULL);
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class SelfConfiguratorTest {
@Test
@ConfiguredWithCode(value = "SelfConfiguratorTest.yml")
public void self_configure() {
assertEquals("/tmp", Jenkins.getInstance().getRawBuildsDir());
assertEquals("/tmp", Jenkins.get().getRawBuildsDir());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -22,7 +22,7 @@
<properties>
<revision>1.13</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.60.3</jenkins.version>
<jenkins.version>2.164.1</jenkins.version>
<java.level>8</java.level>
<tagNameFormat>configuration-as-code-@{project.version}</tagNameFormat>
</properties>
Expand Down