Skip to content

Commit

Permalink
Added noAuth property to skip authortification for public repos
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvasilkov committed Apr 19, 2018
1 parent eeb5018 commit 8945e55
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract class VcsDependency {
final String path
final File dir

final boolean noAuth
final String authGroup
final String username, password

Expand All @@ -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
Expand All @@ -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)}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/com/alexvasilkov/vcs/util/GitHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions src/main/groovy/com/alexvasilkov/vcs/util/SvnHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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()
}

Expand Down

0 comments on commit 8945e55

Please sign in to comment.