From 8945e551c7d9c74061aa81ca30522619e9f563e1 Mon Sep 17 00:00:00 2001 From: Alex Vasilkov Date: Thu, 19 Apr 2018 18:34:57 +0700 Subject: [PATCH] Added noAuth property to skip authortification for public repos --- .../vcs/dependency/VcsDependency.groovy | 16 ++++++++++------ .../vcs/util/CredentialsHelper.groovy | 16 ++++++++-------- .../com/alexvasilkov/vcs/util/GitHelper.groovy | 2 +- .../com/alexvasilkov/vcs/util/SvnHelper.groovy | 4 ++-- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/groovy/com/alexvasilkov/vcs/dependency/VcsDependency.groovy b/src/main/groovy/com/alexvasilkov/vcs/dependency/VcsDependency.groovy index d12fbdb..5522773 100644 --- a/src/main/groovy/com/alexvasilkov/vcs/dependency/VcsDependency.groovy +++ b/src/main/groovy/com/alexvasilkov/vcs/dependency/VcsDependency.groovy @@ -16,6 +16,7 @@ abstract class VcsDependency { final String path final File dir + final boolean noAuth final String authGroup final String username, password @@ -34,10 +35,13 @@ abstract class VcsDependency { File mapDir = map.dir instanceof String || map.dir instanceof File ? map.dir as File : null dir = (mapDir ? mapDir : getDefaultDir(project)).canonicalFile + noAuth = map.noAuth instanceof Boolean ? map.noAuth : false authGroup = map.authGroup ? map.authGroup : DEFAULT_AUTH_GROUP - username = map.username ? map.username : CredentialsHelper.username(name, authGroup) - password = map.password ? map.password : CredentialsHelper.password(name, authGroup) + username = noAuth ? null + : (map.username ? map.username : CredentialsHelper.username(name, authGroup)) + password = noAuth ? null + : (map.password ? map.password : CredentialsHelper.password(name, authGroup)) includeProject = map.includeProject instanceof Boolean ? map.includeProject : true addDependency = map.addDependency instanceof Boolean ? map.addDependency : true @@ -59,12 +63,12 @@ abstract class VcsDependency { if (!configName) { throw new GradleException("Vcs 'authGroup' cannot be empty for ${name}") } - if (!username) { - throw new GradleException("Vcs 'username' is not specified for '${name}'\n" + + if (!noAuth && !username) { + throw new GradleException("Vcs 'username' is not specified for '${name}'.\n" + "${CredentialsHelper.usernameHelp(name, authGroup)}") } - if (!password) { - throw new GradleException("Vcs 'password' is not specified for '${name}'\n" + + if (!noAuth && !password) { + throw new GradleException("Vcs 'password' is not specified for '${name}'.\n" + "${CredentialsHelper.passwordHelp(name, authGroup)}") } } diff --git a/src/main/groovy/com/alexvasilkov/vcs/util/CredentialsHelper.groovy b/src/main/groovy/com/alexvasilkov/vcs/util/CredentialsHelper.groovy index 47e8adc..e2d1b6b 100644 --- a/src/main/groovy/com/alexvasilkov/vcs/util/CredentialsHelper.groovy +++ b/src/main/groovy/com/alexvasilkov/vcs/util/CredentialsHelper.groovy @@ -29,6 +29,13 @@ class CredentialsHelper { return help(projectName, authGroup, PASSWORD) } + private static String help(String projectName, String authGroup, String suffix) { + return "You should provide either ${projectName.toUpperCase()}${suffix}" + + " or ${authGroup}${suffix} in either ${VCS_FILE}, ${GRADLE_FILE}" + + " or ${gradleUserHome.absolutePath}/${GRADLE_FILE} files" + + " or as environment variable." + } + private static String get(String projectName, String authGroup, String suffix) { if (!projectName) return null @@ -57,14 +64,7 @@ class CredentialsHelper { return System.getenv().get(propName) } - private static String help(String projectName, String authGroup, String suffix) { - return "You should provide either ${projectName.toUpperCase()}${suffix}" + - " or ${authGroup}${suffix} in either ${VCS_FILE}, ${GRADLE_FILE}" + - " or ${gradleUserHome.absolutePath}/${GRADLE_FILE} files" + - " or as environment variable" - } - - public static void init(Gradle gradle) { + static void init(Gradle gradle) { if (isInitialized) return isInitialized = true diff --git a/src/main/groovy/com/alexvasilkov/vcs/util/GitHelper.groovy b/src/main/groovy/com/alexvasilkov/vcs/util/GitHelper.groovy index e6f1b4e..4a8a10d 100644 --- a/src/main/groovy/com/alexvasilkov/vcs/util/GitHelper.groovy +++ b/src/main/groovy/com/alexvasilkov/vcs/util/GitHelper.groovy @@ -90,6 +90,6 @@ class GitHelper { } private static Credentials getCreds(GitDependency repo) { - return new Credentials(repo.username, repo.password) + return repo.noAuth ? null : new Credentials(repo.username, repo.password) } } \ No newline at end of file diff --git a/src/main/groovy/com/alexvasilkov/vcs/util/SvnHelper.groovy b/src/main/groovy/com/alexvasilkov/vcs/util/SvnHelper.groovy index 73034f1..4fec780 100644 --- a/src/main/groovy/com/alexvasilkov/vcs/util/SvnHelper.groovy +++ b/src/main/groovy/com/alexvasilkov/vcs/util/SvnHelper.groovy @@ -70,7 +70,7 @@ class SvnHelper { private static SVNClientManager getClient(SvnDependency repo) { ISVNOptions options = SVNWCUtil.createDefaultOptions(true) ISVNAuthenticationManager auth = - new BasicAuthenticationManager(repo.username, repo.password) + repo.noAuth ? null : new BasicAuthenticationManager(repo.username, repo.password) return SVNClientManager.newInstance(options, auth) } @@ -92,7 +92,7 @@ class SvnHelper { } private static String getRepoUrl(SVNClientManager client, SvnDependency repo) { - SVNStatus status = client.statusClient.doStatus(repo.repoDir, false); + SVNStatus status = client.statusClient.doStatus(repo.repoDir, false) return status.repositoryRootURL.toString() + '/' + status.repositoryRelativePath.toString() }