diff --git a/src/main/i18n/develocity-bamboo-plugin.properties b/src/main/i18n/develocity-bamboo-plugin.properties index 377a05f..0318af8 100644 --- a/src/main/i18n/develocity-bamboo-plugin.properties +++ b/src/main/i18n/develocity-bamboo-plugin.properties @@ -17,6 +17,8 @@ develocity.config.maven-extension.enabled=Enables Develocity Maven extension aut develocity.config.maven-settings.title=Maven settings develocity.config.plugin-repository.description=The URL of the repository to use when resolving the Develocity and Common Custom User Data plugins. Defaults to the Gradle Plugin Portal. develocity.config.plugin-repository=Gradle plugin repository URL +develocity.config.plugin-repository-credential-name=Gradle plugin repository credential name +develocity.config.plugin-repository-credential-name.description=The name of the plugin repository credential of type ‘Username and password’ containing the username and password for authenticating with the Gradle Plugin Repository. develocity.config.server.description=The URL of the Develocity server. develocity.config.server=Develocity server URL develocity.config.shared-credential-name.description=The name of the shared credential of type ‘Username and password’ containing the access key for authenticating with the Develocity server. diff --git a/src/main/java/com/gradle/develocity/bamboo/GradleBuildScanInjector.java b/src/main/java/com/gradle/develocity/bamboo/GradleBuildScanInjector.java index 3bc9d4e..001ee64 100644 --- a/src/main/java/com/gradle/develocity/bamboo/GradleBuildScanInjector.java +++ b/src/main/java/com/gradle/develocity/bamboo/GradleBuildScanInjector.java @@ -10,6 +10,8 @@ import com.gradle.develocity.bamboo.config.GradleConfiguration; import com.gradle.develocity.bamboo.config.PersistentConfiguration; import com.gradle.develocity.bamboo.config.PersistentConfigurationManager; +import com.gradle.develocity.bamboo.config.UsernameAndPassword; +import com.gradle.develocity.bamboo.config.UsernameAndPasswordCredentialsProvider; import com.gradle.develocity.bamboo.utils.Objects; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -45,29 +47,32 @@ public class GradleBuildScanInjector extends AbstractBuildScanInjector> GRADLE_BUILDERS = - ImmutableSet.of( - eq(SCRIPT_PLUGIN_KEY), - eq(COMMAND_PLUGIN_KEY), - eq(BOB_SWIFT_GROOVY_TASKS_PLUGIN_GRADLE_KEY), - eq(BOB_SWIFT_GROOVY_TASKS_PLUGIN_GRADLE_WRAPPER_KEY), - eq(BOB_SWIFT_GROOVY_TASKS_PLUGIN_GRADLEW_KEY), - endsWith(ARTIFACTORY_GRADLE_TASK_KEY_SUFFIX) - ); + ImmutableSet.of( + eq(SCRIPT_PLUGIN_KEY), + eq(COMMAND_PLUGIN_KEY), + eq(BOB_SWIFT_GROOVY_TASKS_PLUGIN_GRADLE_KEY), + eq(BOB_SWIFT_GROOVY_TASKS_PLUGIN_GRADLE_WRAPPER_KEY), + eq(BOB_SWIFT_GROOVY_TASKS_PLUGIN_GRADLEW_KEY), + endsWith(ARTIFACTORY_GRADLE_TASK_KEY_SUFFIX) + ); private final EnvironmentVariableAccessor environmentVariableAccessor; private final DevelocityAccessKeyExporter accessKeyExporter; + private final UsernameAndPasswordCredentialsProvider credentialsProvider; private final GradleEmbeddedResources gradleEmbeddedResources = new GradleEmbeddedResources(); @Autowired public GradleBuildScanInjector( - @ComponentImport BuildLoggerManager buildLoggerManager, - PersistentConfigurationManager configurationManager, - @ComponentImport EnvironmentVariableAccessor environmentVariableAccessor, - DevelocityAccessKeyExporter accessKeyExporter + @ComponentImport BuildLoggerManager buildLoggerManager, + PersistentConfigurationManager configurationManager, + @ComponentImport EnvironmentVariableAccessor environmentVariableAccessor, + DevelocityAccessKeyExporter accessKeyExporter, + UsernameAndPasswordCredentialsProvider credentialsProvider ) { super(buildLoggerManager, configurationManager); this.environmentVariableAccessor = environmentVariableAccessor; this.accessKeyExporter = accessKeyExporter; + this.credentialsProvider = credentialsProvider; } @Override @@ -114,7 +119,7 @@ private void inject(BuildContext buildContext, Collection File initScript = gradleEmbeddedResources.copyInitScript(home); LOGGER.debug("Gradle init script: {}", initScript.getAbsolutePath()); - prepareEnvironment(buildContext, config); + prepareEnvironment(buildContext, config, tasks); registerDevelocityResources(buildContext, initScript); setupBuildScansLogInterceptor(buildContext); @@ -123,13 +128,30 @@ private void inject(BuildContext buildContext, Collection LOGGER.debug("Develocity Gradle auto-injection completed"); } - private void prepareEnvironment(BuildContext buildContext, GradleConfiguration config) { + private void prepareEnvironment(BuildContext buildContext, GradleConfiguration config, Collection tasks) { VariableContext variableContext = buildContext.getVariableContext(); - Objects.runIfNotNull(config.server, s -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_DEVELOCITY_URL", s)); + Objects.runIfNotNull(config.server, it -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_DEVELOCITY_URL", it)); Objects.runIfTrue(config.allowUntrustedServer, () -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_DEVELOCITY_ALLOW_UNTRUSTED_SERVER", "true")); - Objects.runIfNotNull(config.develocityPluginVersion, v -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_DEVELOCITY_PLUGIN_VERSION", v)); - Objects.runIfNotNull(config.ccudPluginVersion, v -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_CCUD_PLUGIN_VERSION", v)); - Objects.runIfNotNull(config.pluginRepository, r -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_GRADLE_PLUGIN_REPOSITORY_URL", r)); + Objects.runIfNotNull(config.develocityPluginVersion, it -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_DEVELOCITY_PLUGIN_VERSION", it)); + Objects.runIfNotNull(config.ccudPluginVersion, it -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_CCUD_PLUGIN_VERSION", it)); + Objects.runIfNotNull(config.pluginRepository, it -> variableContext.addLocalVariable("DEVELOCITY_PLUGIN_GRADLE_PLUGIN_REPOSITORY_URL", it)); + + Objects.runIfNotNull( + config.pluginRepositoryCredentialName, + it -> { + UsernameAndPassword credentials = credentialsProvider.findByName(it).orElse(null); + if (credentials == null) { + LOGGER.warn("Plugin repository credentials with the name {} are not found.", it); + } else { + if (credentials.getUsername() == null || credentials.getPassword() == null) { + LOGGER.warn("Plugin repository credentials {} do not have username or password set.", it); + } else { + variableContext.addLocalVariable("DEVELOCITY_PLUGIN_GRADLE_PLUGIN_REPOSITORY_USERNAME", credentials.getUsername()); + variableContext.addLocalVariable("DEVELOCITY_PLUGIN_GRADLE_PLUGIN_REPOSITORY_PASSWORD", credentials.getPassword()); + } + } + } + ); } } diff --git a/src/main/java/com/gradle/develocity/bamboo/admin/BuildScansConfigAction.java b/src/main/java/com/gradle/develocity/bamboo/admin/BuildScansConfigAction.java index 5274343..bcb248f 100644 --- a/src/main/java/com/gradle/develocity/bamboo/admin/BuildScansConfigAction.java +++ b/src/main/java/com/gradle/develocity/bamboo/admin/BuildScansConfigAction.java @@ -1,6 +1,7 @@ package com.gradle.develocity.bamboo.admin; import com.atlassian.bamboo.configuration.GlobalAdminAction; +import com.atlassian.bamboo.repository.NameValuePair; import com.gradle.develocity.bamboo.MavenCoordinates; import com.gradle.develocity.bamboo.config.PersistentConfiguration; import com.gradle.develocity.bamboo.config.PersistentConfigurationManager; @@ -10,7 +11,9 @@ import java.net.MalformedURLException; import java.net.URL; +import java.util.List; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class BuildScansConfigAction extends GlobalAdminAction { @@ -26,6 +29,7 @@ public class BuildScansConfigAction extends GlobalAdminAction { private String develocityPluginVersion; private String ccudPluginVersion; private String pluginRepository; + private String pluginRepositoryCredentialName; /* Maven specific parameters */ private boolean injectMavenExtension; @@ -52,6 +56,7 @@ public String input() { develocityPluginVersion = config.getDevelocityPluginVersion(); ccudPluginVersion = config.getCcudPluginVersion(); pluginRepository = config.getPluginRepository(); + pluginRepositoryCredentialName = config.getPluginRepositoryCredentialName(); injectMavenExtension = config.isInjectMavenExtension(); injectCcudExtension = config.isInjectCcudExtension(); mavenExtensionCustomCoordinates = config.getMavenExtensionCustomCoordinates(); @@ -94,6 +99,13 @@ public void validate() { addFieldError("pluginRepository", "Please specify a valid URL of the Gradle plugins repository."); } + if (StringUtils.isNotBlank(pluginRepositoryCredentialName)) { + UsernameAndPassword credentials = credentialsProvider.findByName(pluginRepositoryCredentialName).orElse(null); + if (credentials == null) { + addFieldError("pluginRepositoryCredentialName", "Please specify the name of the existing repository credential of type 'Username and password'."); + } + } + if (!isBlankOrValidGavc(mavenExtensionCustomCoordinates)) { addFieldError("mavenExtensionCustomCoordinates", "Please specify a valid Maven groupId:artifactId(:version)."); } @@ -104,6 +116,17 @@ public void validate() { } + public List getUsernameAndPasswordCredentialNames() { + List usernameAndPasswordCredentials = credentialsProvider.getAllUsernameAndPasswordCredentials() + .stream() + .map(credentialName -> new NameValuePair(credentialName, credentialName)) + .collect(Collectors.toList()); + + usernameAndPasswordCredentials.add(0, new NameValuePair("", "None")); + + return usernameAndPasswordCredentials; + } + private boolean isBlankOrValidGavc(String coordinates) { if (StringUtils.isBlank(coordinates)) { return true; @@ -138,6 +161,7 @@ public String save() { .setSharedCredentialName(sharedCredentialName) .setEnforceUrl(enforceUrl) .setPluginRepository(pluginRepository) + .setPluginRepositoryCredentialName(pluginRepositoryCredentialName) .setDevelocityPluginVersion(develocityPluginVersion) .setCcudPluginVersion(ccudPluginVersion) .setInjectMavenExtension(injectMavenExtension) @@ -204,6 +228,14 @@ public void setPluginRepository(String pluginRepository) { this.pluginRepository = pluginRepository; } + public String getPluginRepositoryCredentialName() { + return pluginRepositoryCredentialName; + } + + public void setPluginRepositoryCredentialName(String pluginRepositoryCredentialName) { + this.pluginRepositoryCredentialName = pluginRepositoryCredentialName; + } + public boolean isInjectMavenExtension() { return injectMavenExtension; } diff --git a/src/main/java/com/gradle/develocity/bamboo/config/GradleConfiguration.java b/src/main/java/com/gradle/develocity/bamboo/config/GradleConfiguration.java index a8b09f8..1f0b540 100644 --- a/src/main/java/com/gradle/develocity/bamboo/config/GradleConfiguration.java +++ b/src/main/java/com/gradle/develocity/bamboo/config/GradleConfiguration.java @@ -10,18 +10,24 @@ public final class GradleConfiguration extends BuildToolConfiguration { public final String ccudPluginVersion; @Nullable public final String pluginRepository; + @Nullable + public final String pluginRepositoryCredentialName; - private GradleConfiguration(@Nullable String server, - boolean allowUntrustedServer, - @Nullable String sharedCredentialName, - @Nullable String develocityPluginVersion, - @Nullable String ccudPluginVersion, - @Nullable String pluginRepository, - boolean enforceUrl) { + private GradleConfiguration( + @Nullable String server, + boolean allowUntrustedServer, + @Nullable String sharedCredentialName, + @Nullable String develocityPluginVersion, + @Nullable String ccudPluginVersion, + @Nullable String pluginRepository, + @Nullable String pluginRepositoryCredentialName, + boolean enforceUrl + ) { super(server, allowUntrustedServer, sharedCredentialName, enforceUrl); this.develocityPluginVersion = develocityPluginVersion; this.ccudPluginVersion = ccudPluginVersion; this.pluginRepository = pluginRepository; + this.pluginRepositoryCredentialName = pluginRepositoryCredentialName; } public static GradleConfiguration of(PersistentConfiguration configuration) { @@ -32,7 +38,9 @@ public static GradleConfiguration of(PersistentConfiguration configuration) { configuration.getDevelocityPluginVersion(), configuration.getCcudPluginVersion(), configuration.getPluginRepository(), - configuration.isEnforceUrl()); + configuration.getPluginRepositoryCredentialName(), + configuration.isEnforceUrl() + ); } @Override diff --git a/src/main/java/com/gradle/develocity/bamboo/config/PersistentConfiguration.java b/src/main/java/com/gradle/develocity/bamboo/config/PersistentConfiguration.java index cd34e0b..9bad971 100644 --- a/src/main/java/com/gradle/develocity/bamboo/config/PersistentConfiguration.java +++ b/src/main/java/com/gradle/develocity/bamboo/config/PersistentConfiguration.java @@ -21,6 +21,8 @@ public class PersistentConfiguration { private String ccudPluginVersion; @Nullable private String pluginRepository; + @Nullable + private String pluginRepositoryCredentialName; private boolean injectMavenExtension; private boolean injectCcudExtension; @@ -99,6 +101,16 @@ public PersistentConfiguration setPluginRepository(String pluginRepository) { return this; } + @Nullable + public String getPluginRepositoryCredentialName() { + return pluginRepositoryCredentialName; + } + + public PersistentConfiguration setPluginRepositoryCredentialName(@Nullable String pluginRepositoryCredentialName) { + this.pluginRepositoryCredentialName = StringUtils.trimToNull(pluginRepositoryCredentialName); + return this; + } + public boolean isInjectMavenExtension() { return injectMavenExtension; } @@ -147,6 +159,7 @@ public String toString() { .append("develocityPluginVersion", develocityPluginVersion) .append("ccudPluginVersion", ccudPluginVersion) .append("pluginRepository", pluginRepository) + .append("pluginRepositoryCredentialName", pluginRepositoryCredentialName) .append("injectMavenExtension", injectMavenExtension) .append("injectCcudExtension", injectCcudExtension) .append("customMavenExtension", mavenExtensionCustomCoordinates) @@ -168,6 +181,7 @@ public boolean equals(Object o) { Objects.equals(develocityPluginVersion, that.develocityPluginVersion) && Objects.equals(ccudPluginVersion, that.ccudPluginVersion) && Objects.equals(pluginRepository, that.pluginRepository) && + Objects.equals(pluginRepositoryCredentialName, that.pluginRepositoryCredentialName) && Objects.equals(mavenExtensionCustomCoordinates, that.mavenExtensionCustomCoordinates) && Objects.equals(ccudExtensionCustomCoordinates, that.ccudExtensionCustomCoordinates); } @@ -175,6 +189,6 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash(server, allowUntrustedServer, sharedCredentialName, enforceUrl, develocityPluginVersion, ccudPluginVersion, - pluginRepository, injectMavenExtension, injectCcudExtension, mavenExtensionCustomCoordinates, ccudExtensionCustomCoordinates); + pluginRepository, pluginRepositoryCredentialName, injectMavenExtension, injectCcudExtension, mavenExtensionCustomCoordinates, ccudExtensionCustomCoordinates); } } diff --git a/src/main/java/com/gradle/develocity/bamboo/config/UsernameAndPasswordCredentialsProvider.java b/src/main/java/com/gradle/develocity/bamboo/config/UsernameAndPasswordCredentialsProvider.java index 33da94f..160031b 100644 --- a/src/main/java/com/gradle/develocity/bamboo/config/UsernameAndPasswordCredentialsProvider.java +++ b/src/main/java/com/gradle/develocity/bamboo/config/UsernameAndPasswordCredentialsProvider.java @@ -1,11 +1,17 @@ package com.gradle.develocity.bamboo.config; import com.atlassian.bamboo.credentials.CredentialsAccessor; +import com.atlassian.bamboo.credentials.CredentialsData; import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import static com.gradle.develocity.bamboo.config.UsernameAndPassword.SHARED_USERNAME_PASSWORD_PLUGIN_KEY; @Component public class UsernameAndPasswordCredentialsProvider { @@ -19,6 +25,14 @@ public UsernameAndPasswordCredentialsProvider(@ComponentImport CredentialsAccess public Optional findByName(String name) { return Optional.ofNullable(credentialsAccessor.getCredentialsByName(name)) - .map(UsernameAndPassword::of); + .map(UsernameAndPassword::of); + } + + public List getAllUsernameAndPasswordCredentials() { + return StreamSupport.stream(credentialsAccessor.getAllCredentials().spliterator(), false) + .filter(it -> SHARED_USERNAME_PASSWORD_PLUGIN_KEY.equals(it.getPluginKey())) + .map(CredentialsData::getName) + .collect(Collectors.toList()); } + } diff --git a/src/main/java/com/gradle/develocity/bamboo/utils/Objects.java b/src/main/java/com/gradle/develocity/bamboo/utils/Objects.java index 15164b9..b78346b 100644 --- a/src/main/java/com/gradle/develocity/bamboo/utils/Objects.java +++ b/src/main/java/com/gradle/develocity/bamboo/utils/Objects.java @@ -18,4 +18,5 @@ public static void runIfTrue(boolean shouldRun, Runnable action) { action.run(); } } + } diff --git a/src/main/resources/develocity/gradle/develocity-init-script.gradle b/src/main/resources/develocity/gradle/develocity-init-script.gradle index 4b0e489..eaa45bd 100644 --- a/src/main/resources/develocity/gradle/develocity-init-script.gradle +++ b/src/main/resources/develocity/gradle/develocity-init-script.gradle @@ -15,6 +15,8 @@ initscript { } def pluginRepositoryUrl = getInputParam('develocity-plugin.gradle.plugin-repository.url') + def pluginRepositoryUsername = getInputParam('develocity-plugin.gradle.plugin-repository.username') + def pluginRepositoryPassword = getInputParam('develocity-plugin.gradle.plugin-repository.password') def develocityPluginVersion = getInputParam('develocity-plugin.develocity.plugin.version') def ccudPluginVersion = getInputParam('develocity-plugin.ccud.plugin.version') @@ -26,7 +28,19 @@ initscript { logger.lifecycle("Develocity plugins resolution: $pluginRepositoryUrl") repositories { - maven { url pluginRepositoryUrl } + maven { + url pluginRepositoryUrl + if (pluginRepositoryUsername && pluginRepositoryPassword) { + logger.lifecycle("Using credentials for plugin repository") + credentials { + username(pluginRepositoryUsername) + password(pluginRepositoryPassword) + } + authentication { + basic(BasicAuthentication) + } + } + } // TODO remove before merge maven { url "https://repo.grdev.net/artifactory/public" diff --git a/src/main/resources/templates/views/admin/buildScansConfig.ftl b/src/main/resources/templates/views/admin/buildScansConfig.ftl index 9007d7c..659b59b 100644 --- a/src/main/resources/templates/views/admin/buildScansConfig.ftl +++ b/src/main/resources/templates/views/admin/buildScansConfig.ftl @@ -18,7 +18,12 @@ [@ww.textfield labelKey="develocity.config.server" name="server" autofocus=true/] [@ww.checkbox labelKey="develocity.config.allow-untrusted-server" name="allowUntrustedServer" toggle="true"/] [@ww.checkbox labelKey="develocity.config.enforce-url" name="enforceUrl" toggle="true"/] - [@ww.textfield labelKey="develocity.config.shared-credential-name" name="sharedCredentialName"/] + [@ww.select labelKey='develocity.config.shared-credential-name' name='sharedCredentialName' + toggle='true' + list=usernameAndPasswordCredentialNames + listKey='name' + listValue='label'] + [/@ww.select]
[@ui.messageBox type="info"] @@ -32,6 +37,12 @@ [@ww.textfield labelKey="develocity.config.develocity-plugin.version" name="develocityPluginVersion"/] [@ww.textfield labelKey="develocity.config.ccud-plugin.version" name="ccudPluginVersion"/] [@ww.textfield labelKey="develocity.config.plugin-repository" name="pluginRepository"/] + [@ww.select labelKey='develocity.config.plugin-repository-credential-name' name='pluginRepositoryCredentialName' + toggle='true' + list=usernameAndPasswordCredentialNames + listKey='name' + listValue='label'] + [/@ww.select] [/@ui.bambooSection] [@ui.bambooSection titleKey="develocity.config.maven-settings.title" headerWeight="h2"] diff --git a/src/test/java/com/gradle/develocity/bamboo/DevelocityPreJobActionTest.java b/src/test/java/com/gradle/develocity/bamboo/DevelocityPreJobActionTest.java index e534f5e..4a63d17 100644 --- a/src/test/java/com/gradle/develocity/bamboo/DevelocityPreJobActionTest.java +++ b/src/test/java/com/gradle/develocity/bamboo/DevelocityPreJobActionTest.java @@ -39,7 +39,7 @@ class DevelocityPreJobActionTest { private final VariableContext variableContext = mock(VariableContext.class); private final GradleBuildScanInjector gradleBuildScanInjector = - new GradleBuildScanInjector(null, null, null, null); + new GradleBuildScanInjector(null, null, null, null, null); private final DevelocityPreJobAction develocityPreJobAction = new DevelocityPreJobAction( diff --git a/src/test/java/com/gradle/develocity/bamboo/config/ConfigurationMigratorTest.java b/src/test/java/com/gradle/develocity/bamboo/config/ConfigurationMigratorTest.java index da5e17e..b520c60 100644 --- a/src/test/java/com/gradle/develocity/bamboo/config/ConfigurationMigratorTest.java +++ b/src/test/java/com/gradle/develocity/bamboo/config/ConfigurationMigratorTest.java @@ -34,7 +34,7 @@ void runsMigrateConfigV0ToV1() { new ConfigurationMigrator(bandanaManager).onPluginEnabled(pluginEnabledEvent); verify(bandanaManager, times(1)).setValue(any(BandanaContext.class), eq("com.gradle.bamboo.plugins.develocity.config.v1"), - eq("{\"server\":\"https://mycomp\",\"allowUntrustedServer\":false,\"sharedCredentialName\":null,\"enforceUrl\":false,\"develocityPluginVersion\":null,\"ccudPluginVersion\":null,\"pluginRepository\":null,\"injectMavenExtension\":false,\"injectCcudExtension\":false,\"mavenExtensionCustomCoordinates\":null,\"ccudExtensionCustomCoordinates\":null}")); + eq("{\"server\":\"https://mycomp\",\"allowUntrustedServer\":false,\"sharedCredentialName\":null,\"enforceUrl\":false,\"develocityPluginVersion\":null,\"ccudPluginVersion\":null,\"pluginRepository\":null,\"pluginRepositoryCredentialName\":null,\"injectMavenExtension\":false,\"injectCcudExtension\":false,\"mavenExtensionCustomCoordinates\":null,\"ccudExtensionCustomCoordinates\":null}")); verify(bandanaManager, times(1)).removeValue(any(BandanaContext.class), eq("com.gradle.bamboo.plugins.develocity.config")); } diff --git a/src/test/java/com/gradle/develocity/bamboo/config/JsonConfigurationConverterTest.java b/src/test/java/com/gradle/develocity/bamboo/config/JsonConfigurationConverterTest.java index f9f7b4f..00d856e 100644 --- a/src/test/java/com/gradle/develocity/bamboo/config/JsonConfigurationConverterTest.java +++ b/src/test/java/com/gradle/develocity/bamboo/config/JsonConfigurationConverterTest.java @@ -16,6 +16,7 @@ class JsonConfigurationConverterTest { .setServer("https://mycompany.com") .setDevelocityPluginVersion("3.11") .setPluginRepository("https://plugins.mycompany.com") + .setPluginRepositoryCredentialName("plugin-creds") .setSharedCredentialName("develocity-creds") .setAllowUntrustedServer(true) .setCcudPluginVersion("1.11") @@ -26,7 +27,7 @@ class JsonConfigurationConverterTest { private static final String json = "{\"server\":\"https://mycompany.com\",\"allowUntrustedServer\":true," + "\"sharedCredentialName\":\"develocity-creds\",\"enforceUrl\":false,\"develocityPluginVersion\":\"3.11\",\"ccudPluginVersion\":\"1.11\"," + - "\"pluginRepository\":\"https://plugins.mycompany.com\",\"injectMavenExtension\":true," + + "\"pluginRepository\":\"https://plugins.mycompany.com\",\"pluginRepositoryCredentialName\":\"plugin-creds\",\"injectMavenExtension\":true," + "\"injectCcudExtension\":true," + "\"mavenExtensionCustomCoordinates\":\"foo:bar\",\"ccudExtensionCustomCoordinates\":\"foo:ccud-bar\"}"; diff --git a/src/test/java/it/com/gradle/develocity/bamboo/BrowserTest.java b/src/test/java/it/com/gradle/develocity/bamboo/BrowserTest.java index 8e785a1..60193d4 100644 --- a/src/test/java/it/com/gradle/develocity/bamboo/BrowserTest.java +++ b/src/test/java/it/com/gradle/develocity/bamboo/BrowserTest.java @@ -107,7 +107,15 @@ public final void loginAs(TestUser user) { page.locator("#loginForm_save").click(); } + public final String storePluginCredentialInSharedCredentials(String username, String password) { + return storeSharedCredential(username, password); + } + public final String storeAccessKeyInSharedCredentials(@Nullable String accessKey) { + return storeSharedCredential("develocity", accessKey); + } + + private String storeSharedCredential(String username, String password) { gotoAdminPage(); String credentialsName = randomString(); @@ -121,9 +129,9 @@ public final String storeAccessKeyInSharedCredentials(@Nullable String accessKey } page.getByLabel("Credential name (required)").fill(credentialsName); - page.getByLabel("Username (required)").fill("develocity"); // Hardcoded value, because it's not used - if (accessKey != null) { - page.getByLabel("Password").fill("test"); + page.getByLabel("Username (required)").fill(username); + if (password != null) { + page.getByLabel("Password").fill(password); } page.locator("#createSharedCredentials_save").click(); page.reload(); diff --git a/src/test/java/it/com/gradle/develocity/bamboo/BuildScansConfigurationForm.java b/src/test/java/it/com/gradle/develocity/bamboo/BuildScansConfigurationForm.java index c43716e..7982196 100644 --- a/src/test/java/it/com/gradle/develocity/bamboo/BuildScansConfigurationForm.java +++ b/src/test/java/it/com/gradle/develocity/bamboo/BuildScansConfigurationForm.java @@ -16,12 +16,15 @@ public BuildScansConfigurationForm(Page page) { } public BuildScansConfigurationForm clear() { - Stream.of(getServerLocator(), getSharedCredentialNameLocator(), getPluginRepositoryLocator(), getDevelocityPluginVersionLocator(), getCcudPluginVersionLocator()) + Stream.of(getServerLocator(), getPluginRepositoryLocator(), getDevelocityPluginVersionLocator(), getCcudPluginVersionLocator()) .forEach(Locator::clear); Stream.of(getAllowUntrustedServerLocator(), getInjectMavenExtensionLocator(), getInjectCcudExtensionLocator()) .forEach(Locator::uncheck); + Stream.of(getSharedCredentialNameLocator(), getPluginRepositoryCredentialNameLocator()) + .forEach(it -> it.selectOption("None")); + return save(); } @@ -41,7 +44,7 @@ public BuildScansConfigurationForm setServer(String url) { } public BuildScansConfigurationForm setSharedCredentialName(String name) { - getSharedCredentialNameLocator().fill(name); + getSharedCredentialNameLocator().selectOption(name); return this; } @@ -64,6 +67,11 @@ public BuildScansConfigurationForm setPluginRepository(String url) { return this; } + public BuildScansConfigurationForm setPluginRepositoryCredentialName(String name) { + getPluginRepositoryCredentialNameLocator().selectOption(name); + return this; + } + public BuildScansConfigurationForm allowUntrustedServer() { getAllowUntrustedServerLocator().check(); return this; @@ -113,6 +121,10 @@ public Locator getPluginRepositoryLocator() { return page.getByLabel("Gradle plugin repository URL"); } + public Locator getPluginRepositoryCredentialNameLocator() { + return page.getByLabel("Gradle plugin repository credential name"); + } + public Locator getAllowUntrustedServerLocator() { return page.getByText("Allow untrusted server"); } diff --git a/src/test/java/it/com/gradle/develocity/bamboo/browser/PluginConfigurationBrowserTest.java b/src/test/java/it/com/gradle/develocity/bamboo/browser/PluginConfigurationBrowserTest.java index 5398cb8..ec182c2 100644 --- a/src/test/java/it/com/gradle/develocity/bamboo/browser/PluginConfigurationBrowserTest.java +++ b/src/test/java/it/com/gradle/develocity/bamboo/browser/PluginConfigurationBrowserTest.java @@ -25,8 +25,8 @@ void login() { @Test void shouldConfigureAllFields() { - String accessKey = String.format("scans.gradle.com=%s", randomString()); - String sharedCredentialName = storeAccessKeyInSharedCredentials(accessKey); + String sharedCredentialName = storeAccessKeyInSharedCredentials(String.format("scans.gradle.com=%s", randomString())); + String pluginRepositoryCredentialName = storePluginCredentialInSharedCredentials(randomString(), randomString()); assertPluginConfiguration( form -> form @@ -35,6 +35,7 @@ void shouldConfigureAllFields() { .setDevelocityPluginVersion("3.12") .setCcudPluginVersion("1.8.2") .setPluginRepository("https://plugins.gradle.org") + .setPluginRepositoryCredentialName(pluginRepositoryCredentialName) .allowUntrustedServer() .enableGeExtensionAutoInjection() .enableCcudExtensionAutoInjection(), @@ -45,6 +46,7 @@ void shouldConfigureAllFields() { assertThat(form.getDevelocityPluginVersionLocator()).hasValue("3.12"); assertThat(form.getCcudPluginVersionLocator()).hasValue("1.8.2"); assertThat(form.getPluginRepositoryLocator()).hasValue("https://plugins.gradle.org"); + assertThat(form.getPluginRepositoryCredentialNameLocator()).hasValue(pluginRepositoryCredentialName); assertThat(form.getAllowUntrustedServerLocator()).isChecked(); assertThat(form.getInjectMavenExtensionLocator()).isChecked(); @@ -84,15 +86,6 @@ void sharedCredentialWithoutPassword() { ); } - @Test - void sharedCredentialDoesNotExist() { - assertInvalidInput( - form -> form.setSharedCredentialName(randomString()), - "#fieldArea_saveBuildScansConfig_sharedCredentialName > div.error.control-form-error", - "Please specify the name of the existing shared credential of type 'Username and password'." - ); - } - @Test void invalidDevelocityPluginVersion() { assertInvalidInput(