Code improvements (#1728)
This commit is contained in:
parent
42de339aea
commit
302609121b
|
|
@ -26,6 +26,6 @@ reload-jcasc-configuration
|
|||
|
||||
- via Groovy script
|
||||
```groovy
|
||||
import io.jenkins.plugins.casc.ConfigurationAsCode;
|
||||
import io.jenkins.plugins.casc.ConfigurationAsCode
|
||||
ConfigurationAsCode.get().configure()
|
||||
```
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class ActiveDirectoryTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("active-directory/README.md")
|
||||
public void configure_active_directory() throws Exception {
|
||||
public void configure_active_directory() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final ActiveDirectorySecurityRealm realm = (ActiveDirectorySecurityRealm) jenkins.getSecurityRealm();
|
||||
assertEquals(1, realm.domains.size());
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class ArtifactManagerS3Test {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme(value = "artifact-manager-s3/README.md")
|
||||
public void configure_artifact_manager() throws Exception {
|
||||
public void configure_artifact_manager() {
|
||||
assertThat(CredentialsAwsGlobalConfiguration.get().getRegion(), is(equalTo("us-east-1")));
|
||||
assertThat(S3BlobStoreConfig.get().getPrefix(), is(equalTo("jenkins_data/")));
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class ArtifactoryTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme(value = "artifactory/README.md")
|
||||
public void configure_artifactory() throws Exception {
|
||||
public void configure_artifactory() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final ArtifactoryBuilder.DescriptorImpl descriptor = (ArtifactoryBuilder.DescriptorImpl) jenkins.getDescriptor(ArtifactoryBuilder.class);
|
||||
assertTrue(descriptor.getUseCredentialsPlugin());
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class BuildAgentsTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme(value = "build_agents/README.md")
|
||||
public void configure_build_agents() throws Exception {
|
||||
public void configure_build_agents() {
|
||||
assertThat(j.getInstance().getComputers().length, is(3));
|
||||
|
||||
Slave slave = (Slave)j.getInstance().getNode("utility-node");
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class ConfigFileProviderTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme(value = "config-file-provider/README.md")
|
||||
public void configure_config_file_provider() throws Exception {
|
||||
public void configure_config_file_provider() {
|
||||
assertThat(GlobalConfigFiles.get().getConfigs(), hasSize(4));
|
||||
|
||||
Config config = GlobalConfigFiles.get().getById("custom-test");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.cloudbees.plugins.credentials.CredentialsScope;
|
|||
import com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator;
|
||||
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
|
||||
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import hudson.ExtensionList;
|
||||
import hudson.util.Secret;
|
||||
import io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator;
|
||||
|
|
@ -16,7 +17,6 @@ import io.jenkins.plugins.casc.model.Mapping;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nonnull;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -140,8 +140,8 @@ public class CredentialsTest {
|
|||
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1", "2", "3", "4")));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private <T> Attribute<T,?> getFromDatabound(Class<T> clazz, @Nonnull String attributeName) {
|
||||
@NonNull
|
||||
private <T> Attribute<T,?> getFromDatabound(Class<T> clazz, @NonNull String attributeName) {
|
||||
DataBoundConfigurator<T> cfg = new DataBoundConfigurator<>(clazz);
|
||||
Set<Attribute<T,?>> attributes = cfg.describe();
|
||||
for (Attribute<T,?> a : attributes) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class Crowd2Test {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("crowd2/README.md")
|
||||
public void configure_artifact_manager() throws Exception {
|
||||
public void configure_artifact_manager() {
|
||||
SecurityRealm realm = Jenkins.get().getSecurityRealm();
|
||||
assertThat(realm, instanceOf(CrowdSecurityRealm.class));
|
||||
CrowdSecurityRealm securityRealm = (CrowdSecurityRealm) realm;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class CustomToolsTest {
|
|||
|
||||
@Test @Issue("#97") @Ignore
|
||||
@ConfiguredWithCode(value = "CustomToolsTest.yml")
|
||||
public void configure_custom_tools() throws Exception {
|
||||
public void configure_custom_tools() {
|
||||
DescriptorImpl descriptor = (DescriptorImpl) j.jenkins.getDescriptorOrDie(CustomTool.class);
|
||||
assertEquals(1, descriptor.getInstallations().length);
|
||||
final CustomTool customTool = descriptor.getInstallations()[0];
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class DockerCloudTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("docker/README.md")
|
||||
public void configure_docker_cloud() throws Exception {
|
||||
public void configure_docker_cloud() {
|
||||
final DockerCloud docker = DockerCloud.getCloudByName("docker");
|
||||
assertNotNull(docker);
|
||||
assertNotNull(docker.getDockerApi());
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class DockerWorkflowSymbolTest {
|
|||
|
||||
@Test
|
||||
@Issue("1260")
|
||||
public void configure_global_definition() throws Exception {
|
||||
public void configure_global_definition() {
|
||||
GlobalConfig config = GlobalConfig.get();
|
||||
|
||||
assertNotNull(config);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class DockerWorkflowTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("docker-workflow/README.md")
|
||||
public void configure_global_definition() throws Exception {
|
||||
public void configure_global_definition() {
|
||||
GlobalConfig config = GlobalConfig.get();
|
||||
|
||||
assertNotNull(config);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class EssentialsTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("EssentialsTest.yml")
|
||||
public void essentialsTest() throws Exception {
|
||||
public void essentialsTest() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertEquals("Welcome to Jenkins Essentials!", jenkins.getSystemMessage());
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class ExternalWorkspaceManagerTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("external-workspace-manager/README.md")
|
||||
public void configure_external_workspace_manager() throws Exception {
|
||||
public void configure_external_workspace_manager() {
|
||||
// Already validated in the plugin itself:
|
||||
// https://github.com/jenkinsci/external-workspace-manager-plugin/pull/68
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class GitHubTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("github/README.md")
|
||||
public void configure_github() throws Exception {
|
||||
public void configure_github() {
|
||||
|
||||
final GitHubPluginConfig configuration = GlobalConfiguration.all().get(GitHubPluginConfig.class);
|
||||
assertThat(configuration.getConfigs(), hasSize(1));
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class GitLabConfigurationTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("gitlab/README.md")
|
||||
public void configure_gitlab_api_token() throws Exception {
|
||||
public void configure_gitlab_api_token() {
|
||||
SystemCredentialsProvider systemCreds = SystemCredentialsProvider.getInstance();
|
||||
List<DomainCredentials> domainCredentials = systemCreds.getDomainCredentials();
|
||||
assertEquals(1, domainCredentials.size());
|
||||
|
|
@ -44,7 +44,7 @@ public class GitLabConfigurationTest {
|
|||
}
|
||||
@Test
|
||||
@ConfiguredWithReadme("gitlab/README.md")
|
||||
public void configure_gitlab_connection() throws Exception {
|
||||
public void configure_gitlab_connection() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final GitLabConnectionConfig gitLabConnections = jenkins.getDescriptorByType(GitLabConnectionConfig.class);
|
||||
assertEquals(1, gitLabConnections.getConnections().size());
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class GitTest {
|
|||
@Test
|
||||
@Issue("JENKINS-57604")
|
||||
@ConfiguredWithCode("GitTest.yml")
|
||||
public void checkAssemblaWebIsLoaded() throws Exception {
|
||||
public void checkAssemblaWebIsLoaded() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final GlobalLibraries libs = jenkins.getExtensionList(GlobalConfiguration.class)
|
||||
.get(GlobalLibraries.class);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class GitToolInstallationTest {
|
|||
public static JenkinsConfiguredWithReadmeRule j = new JenkinsConfiguredWithReadmeRule();
|
||||
|
||||
@Test
|
||||
public void configure_git_installations() throws Exception {
|
||||
public void configure_git_installations() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final GitTool.DescriptorImpl descriptor = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
|
||||
assertEquals(2, descriptor.getInstallations().length);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class GithubOrganisationFolderTest {
|
|||
// @Test
|
||||
// Fails as Items do override submit() with manual data-binding implementation
|
||||
@ConfiguredWithCode("GithubOrganisationFolderTest.yml")
|
||||
public void configure_github_organisation_folder_seed_job() throws Exception {
|
||||
public void configure_github_organisation_folder_seed_job() {
|
||||
final TopLevelItem job = Jenkins.get().getItem("ndeloof");
|
||||
assertNotNull(job);
|
||||
assertTrue(job instanceof OrganizationFolder);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class GlobalLibrariesTest {
|
|||
@Issue("JENKINS-57557")
|
||||
@Test
|
||||
@ConfiguredWithCode("GlobalLibrariesGitHubTest.yml")
|
||||
public void configure_global_library_using_github() throws Exception {
|
||||
public void configure_global_library_using_github() {
|
||||
assertEquals(1, GlobalLibraries.get().getLibraries().size());
|
||||
final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
|
||||
assertEquals("jenkins-pipeline-lib", library.getName());
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class GlobalMatrixAuthorizationTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("matrix-auth/README.md")
|
||||
public void checkCorrectlyConfiguredPermissions() throws Exception {
|
||||
public void checkCorrectlyConfiguredPermissions() {
|
||||
assertEquals("The configured instance must use the Global Matrix Authentication Strategy", GlobalMatrixAuthorizationStrategy.class, Jenkins.get().getAuthorizationStrategy().getClass());
|
||||
GlobalMatrixAuthorizationStrategy gms = (GlobalMatrixAuthorizationStrategy) Jenkins.get().getAuthorizationStrategy();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class GlobalNodePropertiesTest {
|
|||
public static JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule();
|
||||
|
||||
@Test
|
||||
public void configure() throws Exception {
|
||||
public void configure() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
|
||||
DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = jenkins.getGlobalNodeProperties();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class JenkinsDemoTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("jenkins/jenkins.yaml")
|
||||
public void configure_demo_yaml() throws Exception {
|
||||
public void configure_demo_yaml() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
|
||||
assertEquals(5, jenkins.getNumExecutors());
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class JenkinsReadmeDemoTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("jenkins/README.md#0")
|
||||
public void configure_demo_first_code_block() throws Exception {
|
||||
public void configure_demo_first_code_block() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
|
||||
assertEquals(5, jenkins.getNumExecutors());
|
||||
|
|
@ -32,7 +32,7 @@ public class JenkinsReadmeDemoTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("jenkins/README.md#1")
|
||||
public void configure_demo_second_code_block() throws Exception {
|
||||
public void configure_demo_second_code_block() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertThat(jenkins.getSystemMessage(), containsString("Welcome to our build server."));
|
||||
assertEquals(1, jenkins.getNumExecutors());
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class JiraTest {
|
|||
@Test
|
||||
@ConfiguredWithReadme("jira/README.md")
|
||||
@Issue("JENKINS-52906")
|
||||
public void configure_jira_project_globalconfig() throws Exception {
|
||||
public void configure_jira_project_globalconfig() {
|
||||
|
||||
List<JiraSite> sites = JiraGlobalConfiguration.get().getSites();
|
||||
// Was failing due to JENKINS-52906
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class KeycloakTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("keycloak/README.md")
|
||||
public void configure_artifact_manager() throws Exception {
|
||||
public void configure_artifact_manager() {
|
||||
SecurityRealm realm = j.jenkins.get().getSecurityRealm();
|
||||
assertThat(realm, instanceOf(KeycloakSecurityRealm.class));
|
||||
KeycloakSecurityRealm securityRealm = (KeycloakSecurityRealm)realm;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class KubernetesCloudTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("kubernetes/README.md")
|
||||
public void configure_kubernetes_cloud() throws Exception {
|
||||
public void configure_kubernetes_cloud() {
|
||||
final KubernetesCloud cloud = j.jenkins.clouds.get(KubernetesCloud.class);
|
||||
assertNotNull(cloud);
|
||||
assertEquals("advanced-k8s-config", cloud.name);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class MailerTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("mailer/README.md")
|
||||
public void configure_mailer() throws Exception {
|
||||
public void configure_mailer() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final Mailer.DescriptorImpl descriptor = (Mailer.DescriptorImpl) jenkins.getDescriptor(Mailer.class);
|
||||
assertEquals("4441", descriptor.getSmtpPort());
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class MesosTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("mesos/README.md")
|
||||
public void configure_mesos_cloud() throws Exception {
|
||||
public void configure_mesos_cloud() {
|
||||
final MesosCloud cloud = Jenkins.get().clouds.get(MesosCloud.class);
|
||||
assertNotNull(cloud);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class NodeJSTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("nodejs/README.md")
|
||||
public void configure_nodejs() throws Exception {
|
||||
public void configure_nodejs() {
|
||||
final NodeJSInstallation.DescriptorImpl descriptor = ExtensionList.lookupSingleton(NodeJSInstallation.DescriptorImpl.class);
|
||||
assertEquals(1, descriptor.getInstallations().length);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class ProjectMatrixAuthorizationTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("ProjectMatrixStrategy.yml")
|
||||
public void checkCorrectlyConfiguredPermissions() throws Exception {
|
||||
public void checkCorrectlyConfiguredPermissions() {
|
||||
assertEquals("The configured instance must use the Global Matrix Authentication Strategy", ProjectMatrixAuthorizationStrategy.class, Jenkins.get().getAuthorizationStrategy().getClass());
|
||||
ProjectMatrixAuthorizationStrategy gms = (ProjectMatrixAuthorizationStrategy) Jenkins.get().getAuthorizationStrategy();
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class PropertiesSecretSourceTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("PropertiesSecretSourceTest.yaml")
|
||||
public void testReadingSecretsFromProperties() throws Exception {
|
||||
public void testReadingSecretsFromProperties() {
|
||||
List<UsernamePasswordCredentials> credentialList = CredentialsProvider
|
||||
.lookupCredentials(UsernamePasswordCredentials.class,
|
||||
Jenkins.getInstanceOrNull(), null, Collections.emptyList());
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package io.jenkins.plugins.casc;
|
|||
import com.cloudbees.hudson.plugins.folder.Folder;
|
||||
import com.michelin.cio.hudson.plugins.rolestrategy.Role;
|
||||
import com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy;
|
||||
import com.synopsys.arc.jenkins.plugins.rolestrategy.RoleType;
|
||||
import hudson.model.Computer;
|
||||
import hudson.model.FreeStyleProject;
|
||||
import hudson.model.Item;
|
||||
|
|
@ -58,7 +59,7 @@ public class RoleStrategyTest {
|
|||
s, instanceOf(RoleBasedAuthorizationStrategy.class));
|
||||
RoleBasedAuthorizationStrategy rbas = (RoleBasedAuthorizationStrategy) s;
|
||||
|
||||
Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleBasedAuthorizationStrategy.GLOBAL);
|
||||
Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleType.Global);
|
||||
assertThat(globalRoles.size(), equalTo(2));
|
||||
|
||||
// Admin has configuration access
|
||||
|
|
@ -108,13 +109,13 @@ public class RoleStrategyTest {
|
|||
@Test
|
||||
@Issue("Issue #214")
|
||||
@ConfiguredWithCode("RoleStrategy2.yml")
|
||||
public void shouldHandleNullItemsAndAgentsCorrectly() throws Exception {
|
||||
public void shouldHandleNullItemsAndAgentsCorrectly() {
|
||||
AuthorizationStrategy s = j.jenkins.getAuthorizationStrategy();
|
||||
assertThat("Authorization Strategy has been read incorrectly",
|
||||
s, instanceOf(RoleBasedAuthorizationStrategy.class));
|
||||
RoleBasedAuthorizationStrategy rbas = (RoleBasedAuthorizationStrategy) s;
|
||||
|
||||
Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleBasedAuthorizationStrategy.GLOBAL);
|
||||
Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleType.Global);
|
||||
assertThat(globalRoles.size(), equalTo(2));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.cloudbees.plugins.credentials.CredentialsProvider;
|
|||
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
|
||||
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
|
||||
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
|
@ -65,7 +64,7 @@ public class SSHCredentialsTest {
|
|||
@Test
|
||||
@ConfiguredWithCode("SSHCredentialsTest_Multiline_Key.yml")
|
||||
@Issue("https://github.com/jenkinsci/configuration-as-code-plugin/issues/1189")
|
||||
public void shouldSupportMultilineCertificates() throws Exception {
|
||||
public void shouldSupportMultilineCertificates() {
|
||||
BasicSSHUserPrivateKey certKey = getCredentials(BasicSSHUserPrivateKey.class);
|
||||
assertThat("Private key roundtrip failed",
|
||||
certKey.getPrivateKey().trim(), equalTo(MySSHKeySecretSource.PRIVATE_SSH_KEY.trim()));
|
||||
|
|
@ -74,7 +73,7 @@ public class SSHCredentialsTest {
|
|||
@Test
|
||||
@ConfiguredWithCode("SSHCredentialsTest_Singleline_Key.yml")
|
||||
@Issue("https://github.com/jenkinsci/configuration-as-code-plugin/issues/1189")
|
||||
public void shouldSupportSinglelineBase64Certificates() throws Exception {
|
||||
public void shouldSupportSinglelineBase64Certificates() {
|
||||
BasicSSHUserPrivateKey certKey = getCredentials(BasicSSHUserPrivateKey.class);
|
||||
assertThat("Private key roundtrip failed",
|
||||
certKey.getPrivateKey().trim().replace("\r\n", "\n"), equalTo(MySSHKeySecretSource.PRIVATE_SSH_KEY));
|
||||
|
|
@ -85,7 +84,7 @@ public class SSHCredentialsTest {
|
|||
clazz, Jenkins.getInstanceOrNull(),
|
||||
null, Collections.emptyList());
|
||||
assertEquals("There should be only one credential", 1, creds.size());
|
||||
return (T)creds.get(0);
|
||||
return creds.get(0);
|
||||
}
|
||||
|
||||
@TestExtension
|
||||
|
|
@ -104,7 +103,7 @@ public class SSHCredentialsTest {
|
|||
private static final String PRIVATE_SSH_KEY_BASE64 = "LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0NCmIzQmxibk56YUMxclpYa3RkakVBQUFBQUJHNXZibVVBQUFBRWJtOXVaUUFBQUFBQUFBQUJBQUFBTXdBQUFBdHpjMmd0WlcNClF5TlRVeE9RQUFBQ0NZZHZ6NExkSGcwRzVLRlM4UGxhdXVPd1ZCbXM2WTcwRmFMNEpZMVlWYWhnQUFBS0NqSjFsK295ZFoNCmZnQUFBQXR6YzJndFpXUXlOVFV4T1FBQUFDQ1lkdno0TGRIZzBHNUtGUzhQbGF1dU93VkJtczZZNzBGYUw0SlkxWVZhaGcNCkFBQUVCV3J0RlpHWDF5T2cxL2VzZ20zNFRQRTVadzhFWFExT3V4Y2dZR0lhUlJWcGgyL1BndDBlRFFia29WTHcrVnE2NDcNCkJVR2F6cGp2UVZvdmdsalZoVnFHQUFBQUdXOXVaVzVoYzJobGRrQk1RVkJVVDFBdE1qVkxOalZNVDFNQkFnTUUNCi0tLS0tRU5EIE9QRU5TU0ggUFJJVkFURSBLRVktLS0tLQ0K";
|
||||
|
||||
@Override
|
||||
public Optional<String> reveal(String secret) throws IOException {
|
||||
public Optional<String> reveal(String secret) {
|
||||
if (secret.equals("MY_PRIVATE_KEY")) {
|
||||
return Optional.of(PRIVATE_SSH_KEY);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class SeedJobTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("SeedJobTest.yml")
|
||||
public void configure_seed_job() throws Exception {
|
||||
public void configure_seed_job() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertNotNull(jenkins.getItem("testJob1"));
|
||||
assertNotNull(jenkins.getItem("testJob2"));
|
||||
|
|
@ -43,14 +43,14 @@ public class SeedJobTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("SeedJobTest_withSecrets.yml")
|
||||
public void configure_seed_job_with_secrets() throws Exception {
|
||||
public void configure_seed_job_with_secrets() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertNotNull(jenkins.getItem("testJob2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ConfiguredWithCode("SeedJobTest_withEnvVars.yml")
|
||||
public void configure_seed_job_with_env_vars() throws Exception {
|
||||
public void configure_seed_job_with_env_vars() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertNotNull(jenkins.getItem("seedJobWithEnvVars"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class SimpleThemeTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("simple-theme-plugin/README.md")
|
||||
public void configure_simple_theme() throws Exception {
|
||||
public void configure_simple_theme() {
|
||||
// Already tested within the plugin itself, let's run some basic tests.
|
||||
// https://github.com/jenkinsci/simple-theme-plugin/blob/master/src/test/java/org/jenkinsci/plugins/simpletheme/ConfigurationAsCodeTest.java
|
||||
SimpleThemeDecorator decorator = ExtensionList.lookupSingleton(SimpleThemeDecorator.class);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class SlackTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("slack/README.md")
|
||||
public void configure_slack() throws Exception {
|
||||
public void configure_slack() {
|
||||
// Already validated within the plugin itself, so let's run some simple validations
|
||||
// https://github.com/jenkinsci/slack-plugin/pull/582
|
||||
SlackNotifier.DescriptorImpl slackNotifier = ExtensionList.lookupSingleton(SlackNotifier.DescriptorImpl.class);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class StatisticsGathererTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("statistics-gatherer/README.md")
|
||||
public void configure_statistics() throws Exception {
|
||||
public void configure_statistics() {
|
||||
StatisticsConfiguration config = StatisticsConfiguration.get();
|
||||
assertNotNull(config);
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class TopReadmeTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("README.md#0")
|
||||
public void configure_demo_first_code_block() throws Exception {
|
||||
public void configure_demo_first_code_block() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
|
||||
final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
|
||||
|
|
@ -63,7 +63,7 @@ public class TopReadmeTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("README.md#1")
|
||||
public void configure_demo_second_code_block() throws Exception {
|
||||
public void configure_demo_second_code_block() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
|
||||
assertEquals(1, securityRealm.getConfigurations().size());
|
||||
|
|
@ -71,7 +71,7 @@ public class TopReadmeTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("README.md#2")
|
||||
public void configure_demo_third_code_block() throws Exception {
|
||||
public void configure_demo_third_code_block() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertEquals(2, jenkins.getNodes().size());
|
||||
assertEquals("static-agent1", jenkins.getNode("static-agent1").getNodeName());
|
||||
|
|
@ -80,7 +80,7 @@ public class TopReadmeTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("README.md#3")
|
||||
public void configure_demo_fourth_code_block() throws Exception {
|
||||
public void configure_demo_fourth_code_block() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertEquals(2, jenkins.getNodes().size());
|
||||
assertEquals("static-agent1", jenkins.getNode("static-agent1").getNodeName());
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class WorkflowCpsGlobalLibTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("workflow-cps-global-lib/README.md")
|
||||
public void configure_global_library() throws Exception {
|
||||
public void configure_global_library() {
|
||||
assertEquals(1, GlobalLibraries.get().getLibraries().size());
|
||||
final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
|
||||
assertEquals("awesome-lib", library.getName());
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class HudsonPrivateSecurityRealmConfiguratorTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithReadme("embedded-userdatabase/README.md#0")
|
||||
public void configure_local_security_and_admin_user() throws Exception {
|
||||
public void configure_local_security_and_admin_user() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final HudsonPrivateSecurityRealm securityRealm = (HudsonPrivateSecurityRealm) jenkins.getSecurityRealm();
|
||||
assertFalse(securityRealm.allowsSignup());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package io.jenkins.plugins.casc;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import hudson.util.Secret;
|
||||
import io.jenkins.plugins.casc.model.CNode;
|
||||
import io.jenkins.plugins.casc.model.Scalar;
|
||||
|
|
@ -21,8 +23,6 @@ import java.util.Set;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.kohsuke.accmod.AccessRestriction;
|
||||
|
|
@ -257,7 +257,7 @@ public class Attribute<Owner, Type> {
|
|||
seq.add(_describe(c, context, value, shouldBeMasked));
|
||||
}
|
||||
} else {
|
||||
LOGGER.log(Level.FINE, o.getClass().toString() + " is not iterable");
|
||||
LOGGER.log(Level.FINE, o.getClass() + " is not iterable");
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
|
@ -292,7 +292,7 @@ public class Attribute<Owner, Type> {
|
|||
boolean shouldBeMasked = isSecret(instance);
|
||||
if (multiple) {
|
||||
Sequence seq = new Sequence();
|
||||
if (o.getClass().isArray()) o = Arrays.asList(o);
|
||||
if (o.getClass().isArray()) o = Collections.singletonList(o);
|
||||
if (o instanceof Iterable) {
|
||||
for (Object value : (Iterable) o) {
|
||||
seq.add(_describe(c, context, value, shouldBeMasked));
|
||||
|
|
@ -363,7 +363,7 @@ public class Attribute<Owner, Type> {
|
|||
}
|
||||
|
||||
@CheckForNull
|
||||
private static Method locateGetter(Class<?> clazz, @Nonnull String fieldName) {
|
||||
private static Method locateGetter(Class<?> clazz, @NonNull String fieldName) {
|
||||
final String upname = StringUtils.capitalize(fieldName);
|
||||
final List<String> accessors = Arrays.asList("get" + upname, "is" + upname);
|
||||
|
||||
|
|
@ -382,12 +382,12 @@ public class Attribute<Owner, Type> {
|
|||
}
|
||||
|
||||
@CheckForNull
|
||||
private static Field locatePublicField(Class<?> clazz, @Nonnull String fieldName) {
|
||||
private static Field locatePublicField(Class<?> clazz, @NonNull String fieldName) {
|
||||
return ExtraFieldUtils.getField(clazz, fieldName, false);
|
||||
}
|
||||
|
||||
@CheckForNull
|
||||
private static Field locatePrivateFieldInHierarchy(Class<?> clazz, @Nonnull String fieldName) {
|
||||
private static Field locatePrivateFieldInHierarchy(Class<?> clazz, @NonNull String fieldName) {
|
||||
return ExtraFieldUtils.getFieldNoForce(clazz, fieldName);
|
||||
}
|
||||
|
||||
|
|
@ -400,7 +400,7 @@ public class Attribute<Owner, Type> {
|
|||
* {@code false} if not or if there is no conclusive answer.
|
||||
*/
|
||||
@Restricted(NoExternalUse.class)
|
||||
public static boolean calculateIfSecret(@CheckForNull Class<?> targetClass, @Nonnull String fieldName) {
|
||||
public static boolean calculateIfSecret(@CheckForNull Class<?> targetClass, @NonNull String fieldName) {
|
||||
if (targetClass == Secret.class) { // Class is final, so the check is safe
|
||||
LOGGER.log(Level.FINER, "Attribute {0}#{1} is secret, because it has a Secret type",
|
||||
new Object[] {targetClass.getName(), fieldName});
|
||||
|
|
@ -524,7 +524,7 @@ public class Attribute<Owner, Type> {
|
|||
return name.hashCode();
|
||||
}
|
||||
|
||||
public static final <T,V> Setter<T,V> noop() {
|
||||
public static <T,V> Setter<T,V> noop() {
|
||||
return NOOP;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -235,7 +235,6 @@ public abstract class BaseConfigurator<T> implements Configurator<T> {
|
|||
if (superclass instanceof ParameterizedType) {
|
||||
final ParameterizedType psc = (ParameterizedType) superclass;
|
||||
t = psc.getActualTypeArguments()[0];
|
||||
continue;
|
||||
} else {
|
||||
c = (Class) ((TypeVariable) t).getBounds()[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
|
@ -536,7 +535,7 @@ public class ConfigurationAsCode extends ManagementLink {
|
|||
final Mapping mapping = config.asMapping();
|
||||
final List<NodeTuple> tuples = new ArrayList<>();
|
||||
final List<Map.Entry<String, CNode>> entries = new ArrayList<>(mapping.entrySet());
|
||||
entries.sort(Comparator.comparing(Map.Entry::getKey));
|
||||
entries.sort(Map.Entry.comparingByKey());
|
||||
for (Map.Entry<String, CNode> entry : entries) {
|
||||
final Node valueNode = toYaml(entry.getValue());
|
||||
if (valueNode == null) continue;
|
||||
|
|
@ -603,7 +602,7 @@ public class ConfigurationAsCode extends ManagementLink {
|
|||
for (String p : configParameters) {
|
||||
appendSources(configs, p);
|
||||
}
|
||||
sources = Collections.unmodifiableList(configParameters.stream().collect(toList()));
|
||||
sources = Collections.unmodifiableList(new ArrayList<>(configParameters));
|
||||
configureWith(configs);
|
||||
lastTimeLoaded = System.currentTimeMillis();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,8 +196,7 @@ public interface Configurator<T> {
|
|||
* @return CNode describing the attributes.
|
||||
*/
|
||||
@CheckForNull
|
||||
default CNode describeStructure(T instance, ConfigurationContext context)
|
||||
throws Exception {
|
||||
default CNode describeStructure(T instance, ConfigurationContext context) {
|
||||
Mapping mapping = new Mapping();
|
||||
for (Attribute attribute : getAttributes()) {
|
||||
if (context.getMode().equals("JSONSchema")) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import io.jenkins.plugins.casc.impl.attributes.DescribableAttribute;
|
|||
import io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -155,12 +156,12 @@ public class SchemaGeneration {
|
|||
elements.add(attribute);
|
||||
}
|
||||
})
|
||||
.map(attribute -> attribute.getType())
|
||||
.map(type -> context.lookup(type))
|
||||
.filter(obj -> Objects.nonNull(obj))
|
||||
.map(Attribute::getType)
|
||||
.map(context::lookup)
|
||||
.filter(Objects::nonNull)
|
||||
.map(c -> c.getConfigurators(context))
|
||||
.flatMap(configurators -> configurators.stream())
|
||||
.filter(e -> elements.add(e))
|
||||
.flatMap(Collection::stream)
|
||||
.filter(elements::add)
|
||||
.forEach(
|
||||
configurator -> listElements(elements, ((Configurator) configurator).describe(),
|
||||
context, false)
|
||||
|
|
@ -233,10 +234,8 @@ public class SchemaGeneration {
|
|||
if (lookup != null) {
|
||||
lookup
|
||||
.getAttributes()
|
||||
.forEach(attr -> {
|
||||
properties
|
||||
.put(attr.getName(), generateNonEnumAttributeObject(attr, baseConfigurator));
|
||||
});
|
||||
.forEach(attr -> properties
|
||||
.put(attr.getName(), generateNonEnumAttributeObject(attr, baseConfigurator)));
|
||||
}
|
||||
|
||||
JSONObject attributeObject = new JSONObject()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.jenkins.plugins.casc;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -13,7 +14,6 @@ import java.util.Map;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.CheckForNull;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package io.jenkins.plugins.casc;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
import hudson.Extension;
|
||||
import hudson.model.UnprotectedRootAction;
|
||||
import hudson.security.ACL;
|
||||
import hudson.security.ACLContext;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class JenkinsConfigurator extends BaseConfigurator<Jenkins> implements Ro
|
|||
.setter( noop() ));
|
||||
|
||||
attributes.add(new MultivaluedAttribute<Jenkins, LabelAtom>("labelAtoms", LabelAtom.class)
|
||||
.getter(jenkins -> jenkins.getLabelAtoms())
|
||||
.getter(Jenkins::getLabelAtoms)
|
||||
.setter((jenkins, labelAtoms) -> {
|
||||
for (LabelAtom labelAtom : labelAtoms) {
|
||||
// Get or create a LabelAtom instance
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class LabelAtomConfigurator extends BaseConfigurator<LabelAtom> {
|
|||
new Attribute<LabelAtom, String>("name", String.class)
|
||||
.getter(Label::getName),
|
||||
new MultivaluedAttribute<LabelAtom, LabelAtomProperty>("properties", LabelAtomProperty.class)
|
||||
.getter(labelAtom -> labelAtom.getProperties())
|
||||
.getter(LabelAtom::getProperties)
|
||||
.setter((labelAtom, properties) -> labelAtom.getProperties().addAll(properties))
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package io.jenkins.plugins.casc.impl;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.CacheLoader;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
|
|
@ -84,12 +83,7 @@ public class DefaultConfiguratorRegistry implements ConfiguratorRegistry {
|
|||
|
||||
private LoadingCache<Type, Configurator> cache = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10L, TimeUnit.SECONDS)
|
||||
.build(new CacheLoader<Type, Configurator>() {
|
||||
@Override
|
||||
public Configurator load(@NonNull Type type) throws Exception {
|
||||
return internalLookup(type);
|
||||
}
|
||||
});
|
||||
.build(type -> internalLookup(type));
|
||||
|
||||
private Configurator internalLookup(Type type) {
|
||||
Class clazz = Types.erasure(type);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import io.jenkins.plugins.casc.ConfigurationContext;
|
|||
import io.jenkins.plugins.casc.Configurator;
|
||||
import io.jenkins.plugins.casc.ConfiguratorException;
|
||||
import io.jenkins.plugins.casc.model.CNode;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -37,10 +38,10 @@ public class ConfigurableConfigurator<T extends Configurable> implements Configu
|
|||
@Override
|
||||
public T configure(CNode config, ConfigurationContext context) throws ConfiguratorException {
|
||||
try {
|
||||
final T instance = target.newInstance();
|
||||
final T instance = target.getDeclaredConstructor().newInstance();
|
||||
instance.configure(config);
|
||||
return instance;
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new ConfiguratorException("Cannot instantiate Configurable "+target+" with default constructor", e);
|
||||
}
|
||||
}
|
||||
|
|
@ -48,10 +49,10 @@ public class ConfigurableConfigurator<T extends Configurable> implements Configu
|
|||
@Override
|
||||
public T check(CNode config, ConfigurationContext context) throws ConfiguratorException {
|
||||
try {
|
||||
final T instance = target.newInstance();
|
||||
final T instance = target.getDeclaredConstructor().newInstance();
|
||||
instance.check(config);
|
||||
return instance;
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new ConfiguratorException("Cannot instantiate Configurable "+target+" with default constructor", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ public class DataBoundConfigurator<T> extends BaseConfigurator<T> {
|
|||
}
|
||||
throw new ConfiguratorException(this,
|
||||
"Failed to construct instance of " + target +
|
||||
".\n Constructor: " + constructor.toString() +
|
||||
".\n Constructor: " + constructor +
|
||||
".\n Arguments: " + argumentTypes +
|
||||
".\n Expected Parameters: " + String.join(", ",expectedParamList)
|
||||
, ex);
|
||||
|
|
@ -342,25 +342,25 @@ public class DataBoundConfigurator<T> extends BaseConfigurator<T> {
|
|||
return Boolean.FALSE;
|
||||
}
|
||||
if (byte.class == cls) {
|
||||
return Byte.valueOf((byte)0);
|
||||
return (byte) 0;
|
||||
}
|
||||
if (char.class == cls) {
|
||||
return Character.valueOf('\0');
|
||||
return '\0';
|
||||
}
|
||||
if (short.class == cls) {
|
||||
return Short.valueOf((short)0);
|
||||
return (short) 0;
|
||||
}
|
||||
if (int.class == cls) {
|
||||
return Integer.valueOf(0);
|
||||
return 0;
|
||||
}
|
||||
if (long.class == cls) {
|
||||
return Long.valueOf(0L);
|
||||
return 0L;
|
||||
}
|
||||
if (float.class == cls) {
|
||||
return Float.valueOf(0F);
|
||||
return 0F;
|
||||
}
|
||||
if (double.class == cls) {
|
||||
return Double.valueOf(0D);
|
||||
return 0D;
|
||||
}
|
||||
throw new AssertionError("Class is not a primative or missing primative coverage: " + cls.getName());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class ExtensionConfigurator<T> extends BaseConfigurator<T> {
|
|||
@CheckForNull
|
||||
@Override
|
||||
public CNode describe(T instance, ConfigurationContext context) throws Exception {
|
||||
final T ref = target.newInstance();
|
||||
final T ref = target.getDeclaredConstructor().newInstance();
|
||||
return compare(instance, ref, context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -178,9 +178,9 @@ public class HeteroDescribableConfigurator<T extends Describable<T>> implements
|
|||
List<Descriptor<T>> descriptorsWithProperType = new ArrayList<>();
|
||||
Iterator<Descriptor> iterator = parentDescriptorClassList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Descriptor<?> d = iterator.next();
|
||||
Descriptor<T> d = iterator.next();
|
||||
try {
|
||||
descriptorsWithProperType.add((Descriptor<T>) d);
|
||||
descriptorsWithProperType.add(d);
|
||||
LOGGER.log(Level.FINEST, "getDescriptors() for {0}: Accepting {1} as a suitable descriptor",
|
||||
new Object[] {target, d});
|
||||
} catch (ClassCastException ex) {
|
||||
|
|
|
|||
|
|
@ -126,11 +126,13 @@ public final class Scalar implements CNode, CharSequence {
|
|||
return value;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public IntStream chars() {
|
||||
return value.chars();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public IntStream codePoints() {
|
||||
return value.codePoints();
|
||||
|
|
@ -146,6 +148,7 @@ public final class Scalar implements CNode, CharSequence {
|
|||
return value.charAt(index);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
return value.subSequence(start, end);
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
*/
|
||||
package io.jenkins.plugins.casc.util;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.CheckForNull;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.CheckForNull;
|
||||
import org.apache.commons.lang.ClassUtils;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package io.jenkins.plugins.casc.yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Field;
|
||||
import org.yaml.snakeyaml.reader.StreamReader;
|
||||
|
|
@ -11,7 +10,7 @@ import org.yaml.snakeyaml.reader.StreamReader;
|
|||
*/
|
||||
class StreamReaderWithSource extends StreamReader {
|
||||
|
||||
public StreamReaderWithSource(YamlSource source, Reader reader) throws IOException {
|
||||
public StreamReaderWithSource(YamlSource source, Reader reader) {
|
||||
super(reader);
|
||||
try {
|
||||
final Field f = StreamReader.class.getDeclaredField("name");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package io.jenkins.plugins.casc;
|
|||
import java.util.Set;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
|
@ -15,9 +14,6 @@ public class UnknownRootElementTest {
|
|||
@Rule
|
||||
public JenkinsRule j = new JenkinsRule();
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void oneUnknown() {
|
||||
assertThrows("No configurator for the following root elements alice",
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class SecretSourceResolverBenchmark {
|
|||
private ConfigurationContext context = null;
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception {
|
||||
public void setup() {
|
||||
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
|
||||
context = new ConfigurationContext(registry);
|
||||
environmentVariables.set("FOO", "HELLO");
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class YamlExportTest {
|
|||
|
||||
@Test
|
||||
@Issue("SECURITY-1458")
|
||||
public void shouldDiscoverSecretsBasedOnTheAttributeType() throws Exception {
|
||||
public void shouldDiscoverSecretsBasedOnTheAttributeType() {
|
||||
DataBoundConfigurator c = new DataBoundConfigurator<>(AttributeTest.SecretRenamedFieldFithSecretConstructor.class);
|
||||
Set<Attribute> attributes = c.describe();
|
||||
assertThat(attributes.size(), equalTo(1));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package io.jenkins.plugins.casc.yaml;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -15,7 +14,7 @@ import static org.junit.Assert.assertEquals;
|
|||
public class YamlSourceTest {
|
||||
|
||||
@Test
|
||||
public void shouldHaveInformativeToStringForUrlSource() throws IOException {
|
||||
public void shouldHaveInformativeToStringForUrlSource() {
|
||||
//given
|
||||
String testUrl = "http://example.com/foo/bar";
|
||||
//and
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class JenkinsConfiguredWithReadmeRule extends JenkinsConfiguredRule {
|
|||
}
|
||||
|
||||
private List<String> transformFencedCodeBlockFromMarkdownToString(InputStream markdownContent) throws IOException {
|
||||
ArrayList<String> results = new ArrayList<String>();
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
final MutableDataSet FORMAT_OPTIONS = new MutableDataSet();
|
||||
FORMAT_OPTIONS.set(Parser.EXTENSIONS, OPTIONS.get(Parser.EXTENSIONS));
|
||||
Reader targetReader = new InputStreamReader(markdownContent);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.io.File;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.logging.Level;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
|
@ -134,7 +135,7 @@ public abstract class RoundTripAbstractTest {
|
|||
|
||||
private String getResourceContent(String resourcePath) throws IOException {
|
||||
return IOUtils.toString(getClass().getResourceAsStream(resourcePath),
|
||||
"UTF-8");
|
||||
StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private void writeToFile(String text, String path) throws FileNotFoundException {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package io.jenkins.plugins.casc.misc.jmh;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import io.jenkins.plugins.casc.ConfigurationAsCode;
|
||||
import io.jenkins.plugins.casc.ConfiguratorException;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nonnull;
|
||||
import jenkins.benchmark.jmh.JmhBenchmark;
|
||||
import jenkins.benchmark.jmh.JmhBenchmarkState;
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ public abstract class CascJmhBenchmarkState extends JmhBenchmarkState {
|
|||
*
|
||||
* @return String containing the location of YAML file in the classpath
|
||||
*/
|
||||
@Nonnull
|
||||
@NonNull
|
||||
protected abstract String getResourcePath();
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +28,7 @@ public abstract class CascJmhBenchmarkState extends JmhBenchmarkState {
|
|||
*
|
||||
* @return the class containing this benchmark state
|
||||
*/
|
||||
@Nonnull
|
||||
@NonNull
|
||||
protected abstract Class<?> getEnclosingClass();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class AgentProtocolsTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode(value = "AgentProtocolsTest.yml")
|
||||
public void configure_agent_protocols() throws Exception {
|
||||
public void configure_agent_protocols() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
final Set<String> agentProtocols =
|
||||
Arrays.stream(new String[]{"JNLP4-connect", "Ping"}).collect(Collectors.toSet());
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class BackwardCompatibilityTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("BackwardCompatibilityTest.yml")
|
||||
public void should_accept_legacy_symbols_on_descriptors() throws Exception {
|
||||
public void should_accept_legacy_symbols_on_descriptors() {
|
||||
|
||||
final List<Node> nodes = j.jenkins.getNodes();
|
||||
System.out.println(nodes);
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ public class ConfigurationAsCodeTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode(value = {"merge1.yml", "merge3.yml"}, expected = ConfiguratorException.class)
|
||||
public void test_loads_multi_files() throws Exception {
|
||||
public void test_loads_multi_files() {
|
||||
ConfigurationAsCode casc = ConfigurationAsCode.get();
|
||||
|
||||
List<String> sources = casc.getSources();
|
||||
|
|
@ -166,7 +166,7 @@ public class ConfigurationAsCodeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void doCheckNewSource_should_trim_input() throws Exception {
|
||||
public void doCheckNewSource_should_trim_input() {
|
||||
ConfigurationAsCode casc = ConfigurationAsCode.get();
|
||||
|
||||
String configUri = getClass().getResource("merge3.yml").toExternalForm();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class JenkinsConfiguredWithCodeRuleClassRuleTest {
|
|||
public static JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule();
|
||||
|
||||
@Test
|
||||
public void user_created() throws Exception {
|
||||
public void user_created() {
|
||||
User admin = User.get("admin", false, Collections.emptyMap());
|
||||
assertNotNull(admin);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package io.jenkins.plugins.casc;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import io.jenkins.plugins.casc.misc.jmh.CascJmhBenchmarkState;
|
||||
import javax.annotation.Nonnull;
|
||||
import jenkins.benchmark.jmh.JmhBenchmark;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
|
|
@ -11,13 +11,13 @@ import static org.junit.Assert.assertEquals;
|
|||
@JmhBenchmark
|
||||
public class SampleBenchmark {
|
||||
public static class MyState extends CascJmhBenchmarkState {
|
||||
@Nonnull
|
||||
@NonNull
|
||||
@Override
|
||||
protected String getResourcePath() {
|
||||
return "benchmarks.yml";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NonNull
|
||||
@Override
|
||||
protected Class<?> getEnclosingClass() {
|
||||
return SampleBenchmark.class;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class TokenReloadActionTest {
|
|||
|
||||
private ServletResponseSpy response;
|
||||
|
||||
private class ServletResponseSpy extends Response {
|
||||
private static class ServletResponseSpy extends Response {
|
||||
private int error = 200;
|
||||
|
||||
public ServletResponseSpy() {
|
||||
|
|
@ -46,7 +46,7 @@ public class TokenReloadActionTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int sc) throws IOException {
|
||||
public void sendError(int sc) {
|
||||
error = sc;
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ public class TokenReloadActionTest {
|
|||
}
|
||||
}
|
||||
|
||||
private class RequestStub extends Request {
|
||||
private static class RequestStub extends Request {
|
||||
private final String authorization;
|
||||
|
||||
public RequestStub(String authorization) {
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public class JenkinsConfiguratorCloudSupportTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void _terminate(TaskListener taskListener) throws IOException, InterruptedException {
|
||||
protected void _terminate(TaskListener taskListener) {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.jenkins.plugins.casc.core;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import hudson.EnvVars;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.model.labels.LabelAtom;
|
||||
|
|
@ -42,14 +43,14 @@ public class JenkinsConfiguratorTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("Primitives.yml")
|
||||
public void jenkins_primitive_attributes() throws Exception {
|
||||
public void jenkins_primitive_attributes() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertEquals(6666, jenkins.getSlaveAgentPort());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ConfiguredWithCode("HeteroDescribable.yml")
|
||||
public void jenkins_abstract_describable_attributes() throws Exception {
|
||||
public void jenkins_abstract_describable_attributes() {
|
||||
final Jenkins jenkins = Jenkins.get();
|
||||
assertTrue(jenkins.getSecurityRealm() instanceof HudsonPrivateSecurityRealm);
|
||||
assertTrue(jenkins.getAuthorizationStrategy() instanceof FullControlOnceLoggedInAuthorizationStrategy);
|
||||
|
|
@ -109,6 +110,7 @@ public class JenkinsConfiguratorTest {
|
|||
@TestExtension
|
||||
@Symbol("myProperty")
|
||||
public static class DescriptorImpl extends LabelAtomPropertyDescriptor {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "A simple value";
|
||||
|
|
@ -127,6 +129,7 @@ public class JenkinsConfiguratorTest {
|
|||
|
||||
@TestExtension
|
||||
public static class DescriptorImpl extends LabelAtomPropertyDescriptor {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Another simple value";
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class UnsecuredAuthorizationStrategyConfiguratorTest {
|
|||
|
||||
@Test
|
||||
@ConfiguredWithCode("UnsecuredAuthorizationStrategyConfiguratorTest.yml")
|
||||
public void unsecured() throws Exception {
|
||||
public void unsecured() {
|
||||
assertSame(AuthorizationStrategy.UNSECURED, j.jenkins.getAuthorizationStrategy());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class MissingConfiguratorTest {
|
|||
@ConfiguredWithCode(value = "MissingConfiguratorTest.yml", expected = IllegalArgumentException.class,
|
||||
message = "No hudson.security.AuthorizationStrategy implementation found for globalMatrix")
|
||||
@Test
|
||||
public void testThrowsSuggestion() throws Exception {
|
||||
public void testThrowsSuggestion() {
|
||||
//No config check needed, should fail with IllegalArgumentException
|
||||
//We're purposely trying to configure a plugin for which there is no configurator
|
||||
//admin user should not be created due to IllegalArgumentException
|
||||
|
|
|
|||
Loading…
Reference in New Issue