From 011680fff9438acd345b5e5b1b6fd56a509e5630 Mon Sep 17 00:00:00 2001 From: Gregor Noczinski Date: Sat, 25 Mar 2017 16:09:23 +0100 Subject: [PATCH] #14 Added possibility to register unknown VCS Repository Providers to support custom ones. --- README.md | 12 ++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- samples/simple-project/build.gradle | 17 ++- .../plugins/golang/DependencyHandler.java | 10 +- .../golang/model/DependenciesSettings.java | 44 +++++- .../golang/model/VcsRepositoryProvider.java | 98 ++++++++++++++ .../plugins/golang/tasks/BaseClean.java | 14 +- .../golang/tasks/BasePrepareSources.java | 1 + .../vcs/CombinedVcsRepositoryProvider.java | 44 +++--- .../golang/vcs/git/GitVcsRepository.java | 2 +- ...java => DefaultVcsRepositoryProvider.java} | 18 ++- .../isps/GitApacheVcsRepositoryProvider.java | 29 ---- .../GitOpenstackVcsRepositoryProvider.java | 29 ---- .../vcs/isps/GithubVcsRepositoryProvider.java | 29 ---- .../isps/GolangOrgVcsRepositoryProvider.java | 7 - .../GoogleGolangOrgVcsRepositoryProvider.java | 7 - .../isps/GopkgInVcsRepositoryProvider.java | 117 ---------------- .../IspBasedVcsRepositoryProviderSupport.java | 105 +-------------- .../SuffixDetectingVcsRepositoryProvider.java | 42 ++++++ .../isps/VcsRepositoryProviderSupport.java | 125 ++++++++++++++++++ .../org/echocat/gradle/plugins/golang/ca.crt | 20 +++ 22 files changed, 416 insertions(+), 360 deletions(-) create mode 100644 src/main/java/org/echocat/gradle/plugins/golang/model/VcsRepositoryProvider.java rename src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/{HubJazzVcsRepositoryProvider.java => DefaultVcsRepositoryProvider.java} (50%) delete mode 100644 src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitApacheVcsRepositoryProvider.java delete mode 100644 src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitOpenstackVcsRepositoryProvider.java delete mode 100644 src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GithubVcsRepositoryProvider.java delete mode 100644 src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GopkgInVcsRepositoryProvider.java create mode 100644 src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/SuffixDetectingVcsRepositoryProvider.java create mode 100644 src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/VcsRepositoryProviderSupport.java diff --git a/README.md b/README.md index c97c33f..95ed7e2 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,18 @@ golang { // Directory where to cache all dependencies in. dependencyCache = 'vendor' // Path + + // Method to register other VCS Repository provider that are not already supported by this plugin. + // vcsType: One of 'git', 'bzr', 'hg' or 'svn' + // prefix: Dependency prefix that identifies this provider. + // IMPORTANT: Add a slash as suffix. + // name: Name of this provider for display in logs etc. + // dependencyPattern: Regular expression (Java compatible) that should match the whole dependency and + // provides a submatch named which matches the base of the dependency + // and another submatch named that matches potential sub paths. + vcsRepositoryProvider('', '', '', '') + // Example: + // vcsRepositoryProvider('git', 'github.com/', 'GitHub', '^(?github\\.com/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(?/[A-Za-z0-9_.\\-]+)*\$') } build { diff --git a/build.gradle b/build.gradle index 98e317e..a9c586d 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ dependencies { compile group: 'com.google.code.gson', name: 'gson', version: '2.6.2' // VCS - compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '4.4.1.201607150455-r' + compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '4.6.1.201703071140-r' // Platform compile gradleApi() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 853eecf..3c89552 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Dec 21 10:57:06 CET 2016 +#Sat Mar 25 13:34:53 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip diff --git a/samples/simple-project/build.gradle b/samples/simple-project/build.gradle index f27c4dd..23b582f 100644 --- a/samples/simple-project/build.gradle +++ b/samples/simple-project/build.gradle @@ -2,7 +2,7 @@ import org.echocat.gradle.plugins.golang.tasks.GolangTask import org.echocat.gradle.plugins.golang.utils.Executor import org.slf4j.* /* -apply plugin: 'org.echocat.golang-minor' +apply plugin: 'org.echocat.golang' buildscript { repositories { @@ -10,13 +10,13 @@ buildscript { mavenLocal() } dependencies { - classpath "org.echocat.gradle.plugins:gradle-golang-plugin:0.1.15-SNAPSHOT" + classpath "org.echocat.gradle.plugins:gradle-golang-plugin:0.1.16-SNAPSHOT" } -} -*/ +} */ + plugins { - id "org.echocat.golang" version "0.1.14" + id "org.echocat.golang" version "0.1.16" } group 'github.com/echocat/gradle-golang-plugin/samples/simple-project' @@ -33,7 +33,10 @@ golang { ] } dependencies { + vcsRepositoryProvider("git", "try.gogs.io/", "Gogs Demo Repository", "^(?try\\.gogs\\.io/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(?/[A-Za-z0-9_.\\-]+)*\$") + test 'gopkg.in/check.v1' + build 'try.gogs.io/rblaubaer/blaubaers-foo' tool 'github.com/golang/lint/golint' tool 'github.com/jstemmer/go-junit-report' } @@ -43,8 +46,8 @@ golang { } } -task moo(type: MooTask, dependsOn: golangTest) -golangBuild.dependsOn moo +task moo(type: MooTask, dependsOn: test) +build.dependsOn moo class MooTask extends GolangTask { diff --git a/src/main/java/org/echocat/gradle/plugins/golang/DependencyHandler.java b/src/main/java/org/echocat/gradle/plugins/golang/DependencyHandler.java index 58a1528..25395b9 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/DependencyHandler.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/DependencyHandler.java @@ -41,7 +41,9 @@ import static org.echocat.gradle.plugins.golang.DependencyHandler.GetResult.downloaded; import static org.echocat.gradle.plugins.golang.model.GolangDependency.Type.*; import static org.echocat.gradle.plugins.golang.model.GolangDependency.newDependency; +import static org.echocat.gradle.plugins.golang.model.VcsRepositoryProvider.toConcrete; import static org.echocat.gradle.plugins.golang.utils.Executor.executor; +import static org.echocat.gradle.plugins.golang.vcs.CombinedVcsRepositoryProvider.delegatesWithDefaults; import static org.echocat.gradle.plugins.golang.vcs.VcsRepository.Utils.progressMonitorFor; public class DependencyHandler { @@ -57,8 +59,7 @@ public boolean accept(Path path) { }; @Nonnull - private final VcsRepositoryProvider _vcsRepositoryProvider = new CombinedVcsRepositoryProvider(); - + private final VcsRepositoryProvider _vcsRepositoryProvider; @Nonnull private final ProgressLoggerFactory _progressLoggerFactory; @Nonnull @@ -71,6 +72,8 @@ public DependencyHandler(@Nonnull ServiceRegistry serviceRegistry, @Nonnull Sett public DependencyHandler(@Nonnull ProgressLoggerFactory progressLoggerFactory, @Nonnull Settings settings) { _progressLoggerFactory = progressLoggerFactory; _settings = settings; + final List delegates = toConcrete(settings.getDependencies().getVcsRepositoryProviders()); + _vcsRepositoryProvider = new CombinedVcsRepositoryProvider(delegatesWithDefaults(delegates)); } @Nonnull @@ -92,7 +95,8 @@ public Map get(@Nonnull GetTask task) throws Except final RawVcsReference reference = dependency.toRawVcsReference(); final VcsRepository repository = _vcsRepositoryProvider.tryProvideFor(reference); if (repository == null) { - throw new RuntimeException("Could not download dependency: " + reference); + throw new IllegalArgumentException("Don't know how to handle dependency '" + reference + "' because there VCS Repository Provider that could handle it.\n" + + "\t\tTry register it under golang.dependencies with vcsRepositoryProvider(...)."); } final String normalizedReferenceId = repository.getReference().getId(); if (!handledReferenceIds.contains(normalizedReferenceId)) { diff --git a/src/main/java/org/echocat/gradle/plugins/golang/model/DependenciesSettings.java b/src/main/java/org/echocat/gradle/plugins/golang/model/DependenciesSettings.java index 3172e0f..1576b02 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/model/DependenciesSettings.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/model/DependenciesSettings.java @@ -13,16 +13,21 @@ import javax.inject.Inject; import java.net.URI; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import static org.echocat.gradle.plugins.golang.Constants.VENDOR_DIRECTORY_NAME; +import static org.echocat.gradle.plugins.golang.vcs.VcsType.git; import static org.gradle.util.ConfigureUtil.configure; public class DependenciesSettings { + protected static final Pattern NOTATION_PATTERN = Pattern.compile("(?[a-zA-Z0-9.\\-_/]+)(?::(?[a-zA-Z0-9.\\-_/]+))?"); + private final boolean _root; @Nonnull @@ -33,6 +38,8 @@ public class DependenciesSettings { private Boolean _deleteAllCachedDependenciesOnClean; private Path _dependencyCache; + private Collection _vcsRepositoryProviders; + @Inject public DependenciesSettings(boolean root, @Nonnull Project project) { _root = root; @@ -75,7 +82,42 @@ public void setDependencyCache(Path dependencyCache) { _dependencyCache = dependencyCache; } - protected static final Pattern NOTATION_PATTERN = Pattern.compile("(?[a-zA-Z0-9.\\-_/]+)(?::(?[a-zA-Z0-9.\\-_/]+))?"); + public Collection getVcsRepositoryProviders() { + return _vcsRepositoryProviders; + } + + public void setVcsRepositoryProviders(Collection vcsRepositoryProviders) { + _vcsRepositoryProviders = vcsRepositoryProviders; + } + + @Nonnull + public VcsRepositoryProvider vcsRepositoryProvider(@Nonnull String prefix, @Nonnull String name, @Nonnull String dependencyPattern) { + return vcsRepositoryProvider(prefix, name, Pattern.compile(dependencyPattern)); + } + + @Nonnull + public VcsRepositoryProvider vcsRepositoryProvider(@Nonnull String prefix, @Nonnull String name, @Nonnull Pattern dependencyPattern) { + return vcsRepositoryProvider(git, prefix, name, dependencyPattern); + } + + @Nonnull + public VcsRepositoryProvider vcsRepositoryProvider(@Nonnull String type, @Nonnull String prefix, @Nonnull String name, @Nonnull String dependencyPattern) { + return vcsRepositoryProvider(VcsType.valueOf(type), prefix, name, Pattern.compile(dependencyPattern)); + } + + @Nonnull + public VcsRepositoryProvider vcsRepositoryProvider(@Nonnull VcsType type, @Nonnull String prefix, @Nonnull String name, @Nonnull Pattern dependencyPattern) { + final VcsRepositoryProvider result = new VcsRepositoryProvider(type, prefix, name, dependencyPattern); + add(result); + return result; + } + + public void add(@Nonnull VcsRepositoryProvider vcsRepositoryProvider) { + if (_vcsRepositoryProviders == null) { + _vcsRepositoryProviders = new ArrayList<>(); + } + _vcsRepositoryProviders.add(vcsRepositoryProvider); + } @Nonnull public Dependency add(@Nonnull String configurationName, @Nonnull Object notation) { diff --git a/src/main/java/org/echocat/gradle/plugins/golang/model/VcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/model/VcsRepositoryProvider.java new file mode 100644 index 0000000..44d3834 --- /dev/null +++ b/src/main/java/org/echocat/gradle/plugins/golang/model/VcsRepositoryProvider.java @@ -0,0 +1,98 @@ +package org.echocat.gradle.plugins.golang.model; + +import org.echocat.gradle.plugins.golang.vcs.VcsType; +import org.echocat.gradle.plugins.golang.vcs.isps.DefaultVcsRepositoryProvider; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static java.util.regex.Pattern.compile; +import static org.echocat.gradle.plugins.golang.vcs.VcsType.git; + +@Immutable +public class VcsRepositoryProvider { + + @Nonnull + private static final List DEFAULTS = unmodifiableList(asList( + new VcsRepositoryProvider(git, "github.com/", "GitHub", compile("^(?github\\.com/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(?/[A-Za-z0-9_.\\-]+)*$")), + new VcsRepositoryProvider(git, "gopkg.in/", "gopkg.in", compile("^(?gopkg\\.in(?(?:/[A-Za-z0-9_.\\-]+){1,2})\\.v(?[0-9]{1,9}))(?/[A-Za-z0-9_.\\-]+)*$")), + new VcsRepositoryProvider(git, "git.apache.org/", "Git at Apache", compile("^(?git.apache.org/[a-z0-9_.\\-]+\\.git)(?/[A-Za-z0-9_.\\-]+)*$")), + new VcsRepositoryProvider(git, "git.openstack.org/", "OpenStack Git Repository", compile("^(?git\\.openstack\\.org/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(\\.git)?(?/[A-Za-z0-9_.\\-]+)*$")), + new VcsRepositoryProvider(git, "hub.jazz.net/git/", "IBM Bluemix DevOps Services", compile("^(?hub\\.jazz\\.net/git/[a-z0-9]+/[A-Za-z0-9_.\\-]+)(?/[A-Za-z0-9_.\\-]+)*$")) + )); + private static final List DEFAULT_CONCRETES = toConcrete(DEFAULTS); + + @Nonnull + public static List defaults() { + return DEFAULTS; + } + + @Nonnull + public static List defaultConcretes() { + return DEFAULT_CONCRETES; + } + + @Nonnull + private final String _prefix; + @Nonnull + private final VcsType _type; + @Nonnull + private final String _name; + @Nonnull + private final Pattern _dependencyPattern; + + public VcsRepositoryProvider(@Nonnull VcsType type, @Nonnull String prefix, @Nonnull String name, @Nonnull Pattern dependencyPattern) { + _prefix = prefix; + _type = type; + _name = name; + _dependencyPattern = dependencyPattern; + } + + @Nonnull + public String getPrefix() { + return _prefix; + } + + @Nonnull + public VcsType getType() { + return _type; + } + + @Nonnull + public String getName() { + return _name; + } + + @Nonnull + public Pattern getDependencyPattern() { + return _dependencyPattern; + } + + @Override + public String toString() { + return getName() + "{prefix: " + getPrefix() + ", type: " + getType() + ", dependencyPattern: " + getDependencyPattern() + "}"; + } + + @Nonnull + public org.echocat.gradle.plugins.golang.vcs.VcsRepositoryProvider toConcrete() { + return new DefaultVcsRepositoryProvider(getType(), getPrefix(), getName(), getDependencyPattern()); + } + + @Nonnull + public static List toConcrete(@Nullable Iterable models) { + final List result = new ArrayList<>(); + if (models != null) { + for (final VcsRepositoryProvider model : models) { + result.add(model.toConcrete()); + } + } + return unmodifiableList(result); + } + +} diff --git a/src/main/java/org/echocat/gradle/plugins/golang/tasks/BaseClean.java b/src/main/java/org/echocat/gradle/plugins/golang/tasks/BaseClean.java index 8016103..d32f1d9 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/tasks/BaseClean.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/tasks/BaseClean.java @@ -52,7 +52,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { try { deleteIfExists(file); } catch (final IOException e) { - LOGGER.warn("Could not delete file {}.", file, e); + LOGGER.warn("Could not delete file '{}': {}", file, e.toString()); } return CONTINUE; } @@ -63,7 +63,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { try { deleteIfExists(dir); } catch (final IOException e) { - LOGGER.warn("Could not delete dir {}.", dir, e); + LOGGER.warn("Could not delete dir '{}': {}.", dir, e.toString()); } return SKIP_SUBTREE; } @@ -72,10 +72,12 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) { - try { - deleteIfExists(dir); - } catch (final IOException e) { - LOGGER.warn("Could not delete dir {}.", dir, e); + if (exc == null) { + try { + deleteIfExists(dir); + } catch (final IOException e) { + LOGGER.warn("Could not delete dir '{}': {}.", dir, e.toString()); + } } return CONTINUE; } diff --git a/src/main/java/org/echocat/gradle/plugins/golang/tasks/BasePrepareSources.java b/src/main/java/org/echocat/gradle/plugins/golang/tasks/BasePrepareSources.java index b1371d3..fbc505d 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/tasks/BasePrepareSources.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/tasks/BasePrepareSources.java @@ -89,6 +89,7 @@ public void run() throws Exception { protected void prepareDependencyCacheIfNeeded(Path packagePath, Path dependencyCachePath) throws IOException { final Path packageVendorPath = packagePath.resolve("vendor"); + createDirectories(dependencyCachePath); if (exists(packageVendorPath)) { if (!isDirectory(packageVendorPath) && !isSymbolicLink(packageVendorPath)) { throw new IllegalStateException(packageVendorPath + " already exists but is not a symbolic link."); diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/CombinedVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/CombinedVcsRepositoryProvider.java index 176e149..6fb5c40 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/CombinedVcsRepositoryProvider.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/CombinedVcsRepositoryProvider.java @@ -1,12 +1,18 @@ package org.echocat.gradle.plugins.golang.vcs; -import org.echocat.gradle.plugins.golang.vcs.isps.*; +import org.echocat.gradle.plugins.golang.vcs.isps.BitbucketVcsRepositoryProvider; +import org.echocat.gradle.plugins.golang.vcs.isps.GolangOrgVcsRepositoryProvider; +import org.echocat.gradle.plugins.golang.vcs.isps.GoogleGolangOrgVcsRepositoryProvider; +import org.echocat.gradle.plugins.golang.vcs.isps.SuffixDetectingVcsRepositoryProvider; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; -import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.echocat.gradle.plugins.golang.model.VcsRepositoryProvider.defaultConcretes; public class CombinedVcsRepositoryProvider implements VcsRepositoryProvider { @@ -14,20 +20,7 @@ public class CombinedVcsRepositoryProvider implements VcsRepositoryProvider { private final Iterable _delegates; public CombinedVcsRepositoryProvider() { - this( - new GithubVcsRepositoryProvider(), - new GopkgInVcsRepositoryProvider(), - new GolangOrgVcsRepositoryProvider(), - new GoogleGolangOrgVcsRepositoryProvider(), - new BitbucketVcsRepositoryProvider(), - new HubJazzVcsRepositoryProvider(), - new GitApacheVcsRepositoryProvider(), - new GitOpenstackVcsRepositoryProvider() - ); - } - - public CombinedVcsRepositoryProvider(@Nullable VcsRepositoryProvider... delegates) { - this(delegates != null ? asList(delegates) : null); + this(delegatesWithDefaults(null)); } public CombinedVcsRepositoryProvider(@Nullable Iterable delegates) { @@ -51,4 +44,23 @@ protected Iterable delegates() { return _delegates; } + @Nonnull + public static Iterable delegatesWithDefaults(@Nullable Iterable delegates) { + final List result = new ArrayList<>(defaultConcretes()); + + result.add(new GolangOrgVcsRepositoryProvider()); + result.add(new GoogleGolangOrgVcsRepositoryProvider()); + result.add(new BitbucketVcsRepositoryProvider()); + + if (delegates != null) { + for (final VcsRepositoryProvider delegate : delegates) { + result.add(delegate); + } + } + + result.add(new SuffixDetectingVcsRepositoryProvider()); + + return unmodifiableList(result); + } + } diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/git/GitVcsRepository.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/git/GitVcsRepository.java index 4a3d5fb..11b1808 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/git/GitVcsRepository.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/git/GitVcsRepository.java @@ -124,7 +124,7 @@ public boolean isCancelled() { protected void removeGitDirectoryIfNeeded(@Nonnull Path targetDirectory, @Nonnull Git git) throws VcsException { git.getRepository().close(); - deleteQuietly(targetDirectory.resolve(".git")); + //deleteQuietly(targetDirectory.resolve(".git")); } @Nonnull diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/HubJazzVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/DefaultVcsRepositoryProvider.java similarity index 50% rename from src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/HubJazzVcsRepositoryProvider.java rename to src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/DefaultVcsRepositoryProvider.java index 12159d6..58a7cfd 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/HubJazzVcsRepositoryProvider.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/DefaultVcsRepositoryProvider.java @@ -5,25 +5,31 @@ import org.echocat.gradle.plugins.golang.vcs.VcsType; import javax.annotation.Nonnull; +import java.util.regex.Pattern; -import static java.util.regex.Pattern.compile; +public class DefaultVcsRepositoryProvider extends IspBasedVcsRepositoryProviderSupport { -public class HubJazzVcsRepositoryProvider extends IspBasedVcsRepositoryProviderSupport { + @Nonnull + private final VcsType _type; + @Nonnull + private final String _name; - public HubJazzVcsRepositoryProvider() { - super("hub.jazz.net/git/", compile("^(?hub\\.jazz\\.net/git/[a-z0-9]+/[A-Za-z0-9_.\\-]+)(?/[A-Za-z0-9_.\\-]+)*$")); + public DefaultVcsRepositoryProvider(@Nonnull VcsType type, @Nonnull String prefix, @Nonnull String name, @Nonnull Pattern dependencyPattern) { + super(prefix, dependencyPattern); + _type = type; + _name = name; } @Nonnull @Override protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { - return fixedVcsTypeFor(rawReference, VcsType.git); + return fixedVcsTypeFor(rawReference, _type); } @Nonnull @Override protected String getName() { - return "IBM Bluemix DevOps Services"; + return _name; } } diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitApacheVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitApacheVcsRepositoryProvider.java deleted file mode 100644 index 5e00055..0000000 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitApacheVcsRepositoryProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.echocat.gradle.plugins.golang.vcs.isps; - -import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; -import org.echocat.gradle.plugins.golang.vcs.VcsException; -import org.echocat.gradle.plugins.golang.vcs.VcsType; - -import javax.annotation.Nonnull; - -import static java.util.regex.Pattern.compile; - -public class GitApacheVcsRepositoryProvider extends IspBasedVcsRepositoryProviderSupport { - - public GitApacheVcsRepositoryProvider() { - super("git.apache.org/", compile("^(?git.apache.org/[a-z0-9_.\\-]+\\.git)(?/[A-Za-z0-9_.\\-]+)*$")); - } - - @Nonnull - @Override - protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { - return fixedVcsTypeFor(rawReference, VcsType.git); - } - - @Nonnull - @Override - protected String getName() { - return "Git at Apache"; - } - -} diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitOpenstackVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitOpenstackVcsRepositoryProvider.java deleted file mode 100644 index 1ab0c38..0000000 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GitOpenstackVcsRepositoryProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.echocat.gradle.plugins.golang.vcs.isps; - -import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; -import org.echocat.gradle.plugins.golang.vcs.VcsException; -import org.echocat.gradle.plugins.golang.vcs.VcsType; - -import javax.annotation.Nonnull; - -import static java.util.regex.Pattern.compile; - -public class GitOpenstackVcsRepositoryProvider extends IspBasedVcsRepositoryProviderSupport { - - public GitOpenstackVcsRepositoryProvider() { - super("git.apache.org/", compile("^(?git\\.openstack\\.org/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(\\.git)?(?/[A-Za-z0-9_.\\-]+)*$")); - } - - @Nonnull - @Override - protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { - return fixedVcsTypeFor(rawReference, VcsType.git); - } - - @Nonnull - @Override - protected String getName() { - return "OpenStack git repository"; - } - -} diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GithubVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GithubVcsRepositoryProvider.java deleted file mode 100644 index f509378..0000000 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GithubVcsRepositoryProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.echocat.gradle.plugins.golang.vcs.isps; - -import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; -import org.echocat.gradle.plugins.golang.vcs.VcsException; -import org.echocat.gradle.plugins.golang.vcs.VcsType; - -import javax.annotation.Nonnull; - -import static java.util.regex.Pattern.compile; - -public class GithubVcsRepositoryProvider extends IspBasedVcsRepositoryProviderSupport { - - public GithubVcsRepositoryProvider() { - super("github.com/", compile("^(?github\\.com/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(?/[A-Za-z0-9_.\\-]+)*$")); - } - - @Nonnull - @Override - protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { - return fixedVcsTypeFor(rawReference, VcsType.git); - } - - @Nonnull - @Override - protected String getName() { - return "GitHub"; - } - -} diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GolangOrgVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GolangOrgVcsRepositoryProvider.java index f1f24bb..302aa8d 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GolangOrgVcsRepositoryProvider.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GolangOrgVcsRepositoryProvider.java @@ -2,7 +2,6 @@ import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; import org.echocat.gradle.plugins.golang.vcs.VcsException; -import org.echocat.gradle.plugins.golang.vcs.VcsType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,12 +23,6 @@ public GolangOrgVcsRepositoryProvider() { super("golang.org/", compile("^(?golang\\.org/x/(?[A-Za-z0-9_.\\-]+))(?/[A-Za-z0-9_.\\-]+)*$")); } - @Nonnull - @Override - protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { - return fixedVcsTypeFor(rawReference, git); - } - @Nonnull @Override protected String rootFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GoogleGolangOrgVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GoogleGolangOrgVcsRepositoryProvider.java index 71e67e1..cb60c10 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GoogleGolangOrgVcsRepositoryProvider.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GoogleGolangOrgVcsRepositoryProvider.java @@ -2,7 +2,6 @@ import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; import org.echocat.gradle.plugins.golang.vcs.VcsException; -import org.echocat.gradle.plugins.golang.vcs.VcsType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,12 +23,6 @@ public GoogleGolangOrgVcsRepositoryProvider() { super("google.golang.org/", compile("^(?google.golang\\.org/(?[A-Za-z0-9_.\\-]+))(?/[A-Za-z0-9_.\\-]+)*$")); } - @Nonnull - @Override - protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { - return fixedVcsTypeFor(rawReference, git); - } - @Nonnull @Override protected String rootFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GopkgInVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GopkgInVcsRepositoryProvider.java deleted file mode 100644 index 0a091ff..0000000 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/GopkgInVcsRepositoryProvider.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.echocat.gradle.plugins.golang.vcs.isps; - -import org.apache.commons.lang3.StringUtils; -import org.echocat.gradle.plugins.golang.model.IntegerVersion; -import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; -import org.echocat.gradle.plugins.golang.vcs.VcsException; -import org.echocat.gradle.plugins.golang.vcs.VcsIllegalReferenceException; -import org.echocat.gradle.plugins.golang.vcs.VcsType; -import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.lib.Ref; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static java.util.regex.Pattern.compile; -import static org.echocat.gradle.plugins.golang.vcs.VcsType.git; - -public class GopkgInVcsRepositoryProvider extends IspBasedVcsRepositoryProviderSupport { - - private static final Logger LOGGER = LoggerFactory.getLogger(GopkgInVcsRepositoryProvider.class); - - protected static final Pattern REF_PATTERN = compile("^refs/(?:heads|tags)/v(?[0-9]{1,9}(?:\\.[0-9]{1,9}(?:\\.[0-9]{1,9})?)?)$"); - - public GopkgInVcsRepositoryProvider() { - super("gopkg.in/", compile("^(?gopkg\\.in(?(?:/[A-Za-z0-9_.\\-]+){1,2})\\.v(?[0-9]{1,9}))(?/[A-Za-z0-9_.\\-]+)*$")); - } - - @Nonnull - @Override - protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { - return fixedVcsTypeFor(rawReference, git); - } - - @Nonnull - @Override - protected String rootFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { - final StringBuilder sb = new StringBuilder(); - sb.append("github.com/"); - final String[] parts = StringUtils.split(matcher.group("repo"), "/", 3); - if (parts.length == 1) { - sb.append("go-").append(parts[0]).append('/').append(parts[0]); - } else { - sb.append(parts[0]).append('/').append(parts[1]); - } - return sb.toString(); - } - - @Nullable - @Override - protected String refFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { - final String root = rootFor(matcher, rawReference); - final String remoteUri = buildUriFor(root, rawReference); - LOGGER.debug("Fetch remote refs for {} from {}...", rawReference.getId(), remoteUri); - final Collection refs; - try { - refs = Git.lsRemoteRepository() - .setRemote(remoteUri) - .call(); - } catch (final GitAPIException e) { - throw new VcsException(e); - } - LOGGER.debug("Fetch remote refs for {} from {}... DONE!", rawReference.getId(), remoteUri); - - return selectBestFitRefFor(matcher, rawReference, refs); - } - - @Nonnull - protected String selectBestFitRefFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference, @Nonnull Collection refs) throws VcsException { - final int expectedVersion = Integer.valueOf(matcher.group("version")); - final Map candidates = asVersionToRef(refs); - Ref lastMatch = null; - for (final Entry candidate : candidates.entrySet()) { - final IntegerVersion version = candidate.getKey(); - if (expectedVersion == version.getMajor()) { - lastMatch = candidate.getValue(); - } - } - if (lastMatch == null) { - throw new VcsIllegalReferenceException("Version " + expectedVersion + " of " + rawReference.getId() + " does not exist."); - } - return lastMatch.getName(); - } - - @Nonnull - protected Map asVersionToRef(@Nonnull Iterable refs) throws VcsException { - final Map result = new TreeMap<>(); - for (final Ref ref : refs) { - final Matcher matcher = REF_PATTERN.matcher(ref.getName()); - if (matcher.matches()) { - final IntegerVersion version = new IntegerVersion(matcher.group("version")); - result.put(version, ref); - } - } - return result; - } - - @Nonnull - protected String buildUriFor(@Nonnull String root, @Nonnull RawVcsReference rawReference) throws VcsException { - return vcsUriPrefixFor(rawReference, git) + root + vcsUriUriSuffixFor(rawReference, git); - } - - @Nonnull - @Override - protected String getName() { - return "gopkg.in"; - } - -} diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/IspBasedVcsRepositoryProviderSupport.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/IspBasedVcsRepositoryProviderSupport.java index fd2e8fe..2590c90 100644 --- a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/IspBasedVcsRepositoryProviderSupport.java +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/IspBasedVcsRepositoryProviderSupport.java @@ -1,104 +1,33 @@ package org.echocat.gradle.plugins.golang.vcs.isps; -import org.echocat.gradle.plugins.golang.vcs.*; +import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; +import org.echocat.gradle.plugins.golang.vcs.VcsException; +import org.echocat.gradle.plugins.golang.vcs.VcsValidationException; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.net.URI; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static java.net.URI.create; import static org.apache.commons.lang3.StringUtils.isEmpty; -public abstract class IspBasedVcsRepositoryProviderSupport implements VcsRepositoryProvider { - - @Nonnull - private final VcsRepositoryFactory _vcsRepositoryFactory = new VcsRepositoryFactory(); +public abstract class IspBasedVcsRepositoryProviderSupport extends VcsRepositoryProviderSupport { @Nullable private final String _prefix; - @Nonnull - private final Pattern _dependencyPattern; public IspBasedVcsRepositoryProviderSupport(@Nullable String prefix, @Nonnull Pattern dependencyPattern) { + super(dependencyPattern); _prefix = prefix; - _dependencyPattern = dependencyPattern; } - @Nullable @Override - public VcsRepository tryProvideFor(@Nonnull RawVcsReference rawReference) throws VcsException { - if (!couldHandle(rawReference)) { - return null; - } - final VcsType vcsType = detectVcsTypeOf(rawReference); - final VcsReference vcsReference = detectVcsUriOf(rawReference, vcsType); - return _vcsRepositoryFactory.createFor(vcsReference); - } - protected boolean couldHandle(@Nonnull RawVcsReference rawReference) { final String name = rawReference.getId(); return name.startsWith(prefix()); } - @Nonnull - protected abstract VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException; - - @Nonnull - protected VcsType fixedVcsTypeFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType fixedType) throws VcsException { - final VcsType selected = rawReference.getType(); - if (selected != null && selected != fixedType) { - throw new VcsValidationException("There was the VCS type " + selected + " explicit selected for dependency " + rawReference + " but this VCS could only be of type " + fixedType + "."); - } - return fixedType; - } - - @Nonnull - protected VcsReference detectVcsUriOf(@Nonnull RawVcsReference rawReference, VcsType vcsType) throws VcsException { - final URI uri = rawReference.getUri(); - if (uri != null) { - final Matcher matcher = nameMatcherFor(rawReference); - final String id = idFor(matcher, rawReference); - final String ref = refFor(matcher, rawReference); - return new VcsReference(vcsType, id, uri, ref, rawReference.getUpdatePolicy(), subPathOf(matcher)); - } - return resolveVcsUriFor(rawReference, vcsType); - } - - @Nonnull - protected VcsReference resolveVcsUriFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType vcsType) throws VcsException { - final Matcher matcher = nameMatcherFor(rawReference); - final String id = idFor(matcher, rawReference); - final String ref = refFor(matcher, rawReference); - final URI uri = create(vcsUriPrefixFor(rawReference, vcsType) + rootFor(matcher, rawReference) + vcsUriUriSuffixFor(rawReference, vcsType)); - return new VcsReference(vcsType, id, uri, ref, rawReference.getUpdatePolicy(), subPathOf(matcher)); - } - - @Nullable - protected String subPathOf(Matcher matcher) { - try { - return matcher.group("subPath"); - } catch (final IllegalArgumentException ignored) { - return null; - } - } - - @Nullable - protected String refFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { - return rawReference.getRef(); - } - - @Nonnull - protected String rootFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { - return matcher.group("root"); - } - - @Nonnull - protected String idFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { - return matcher.group("root"); - } - + @Override @Nonnull protected Matcher nameMatcherFor(@Nonnull RawVcsReference rawReference) throws VcsException { final Matcher matcher = dependencyPattern().matcher(rawReference.getId()); @@ -108,18 +37,6 @@ protected Matcher nameMatcherFor(@Nonnull RawVcsReference rawReference) throws V return matcher; } - @SuppressWarnings("UnusedParameters") - @Nonnull - protected String vcsUriPrefixFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType vcsType) throws VcsException { - return "https://"; - } - - @SuppressWarnings("UnusedParameters") - @Nonnull - protected String vcsUriUriSuffixFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType vcsType) throws VcsException { - return vcsType.getUriSuffix(); - } - @Nonnull protected String prefix() { if (isEmpty(_prefix)) { @@ -128,16 +45,6 @@ protected String prefix() { return _prefix; } - @Nonnull - protected Pattern dependencyPattern() { - return _dependencyPattern; - } - - @Nonnull - protected VcsRepositoryFactory vcsFactory() { - return _vcsRepositoryFactory; - } - @Nonnull protected abstract String getName(); diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/SuffixDetectingVcsRepositoryProvider.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/SuffixDetectingVcsRepositoryProvider.java new file mode 100644 index 0000000..4b16f43 --- /dev/null +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/SuffixDetectingVcsRepositoryProvider.java @@ -0,0 +1,42 @@ +package org.echocat.gradle.plugins.golang.vcs.isps; + +import org.echocat.gradle.plugins.golang.vcs.RawVcsReference; +import org.echocat.gradle.plugins.golang.vcs.VcsException; +import org.echocat.gradle.plugins.golang.vcs.VcsType; +import org.echocat.gradle.plugins.golang.vcs.VcsValidationException; + +import javax.annotation.Nonnull; +import java.util.regex.Matcher; + +import static java.util.regex.Pattern.compile; + +public class SuffixDetectingVcsRepositoryProvider extends VcsRepositoryProviderSupport { + + public SuffixDetectingVcsRepositoryProvider() { + super(compile("^(?(?([a-z0-9.\\-]+\\.)+[a-z0-9.\\-]+(:[0-9]+)?(/~?[A-Za-z0-9_.\\-]+)+?)\\.(?bzr|git|hg|svn))(?/~?[A-Za-z0-9_.\\-]+)*$")); + } + + @Override + @Nonnull + protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { + final Matcher matcher = nameMatcherFor(rawReference); + final VcsType type = VcsType.valueOf(matcher.group("vcs")); + return fixedVcsTypeFor(rawReference, type); + } + + @Override + protected boolean couldHandle(@Nonnull RawVcsReference rawReference) { + return dependencyPattern().matcher(rawReference.getId()).matches(); + } + + @Override + @Nonnull + protected Matcher nameMatcherFor(@Nonnull RawVcsReference rawReference) throws VcsException { + final Matcher matcher = dependencyPattern().matcher(rawReference.getId()); + if (!matcher.matches()) { + throw new VcsValidationException("Name of dependency " + rawReference + " is invalid."); + } + return matcher; + } + +} diff --git a/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/VcsRepositoryProviderSupport.java b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/VcsRepositoryProviderSupport.java new file mode 100644 index 0000000..1cc1053 --- /dev/null +++ b/src/main/java/org/echocat/gradle/plugins/golang/vcs/isps/VcsRepositoryProviderSupport.java @@ -0,0 +1,125 @@ +package org.echocat.gradle.plugins.golang.vcs.isps; + +import org.echocat.gradle.plugins.golang.vcs.*; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.net.URI; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static java.net.URI.create; +import static org.echocat.gradle.plugins.golang.vcs.VcsType.git; + +public abstract class VcsRepositoryProviderSupport implements VcsRepositoryProvider { + + @Nonnull + private final VcsRepositoryFactory _vcsRepositoryFactory = new VcsRepositoryFactory(); + @Nonnull + private final Pattern _dependencyPattern; + + protected VcsRepositoryProviderSupport(@Nonnull Pattern dependencyPattern) { + _dependencyPattern = dependencyPattern; + } + + @Nullable + @Override + public VcsRepository tryProvideFor(@Nonnull RawVcsReference rawReference) throws VcsException { + if (!couldHandle(rawReference)) { + return null; + } + final VcsType vcsType = detectVcsTypeOf(rawReference); + final VcsReference vcsReference = detectVcsUriOf(rawReference, vcsType); + return _vcsRepositoryFactory.createFor(vcsReference); + } + + protected abstract boolean couldHandle(@Nonnull RawVcsReference rawReference); + + @Nonnull + protected VcsType detectVcsTypeOf(@Nonnull RawVcsReference rawReference) throws VcsException { + return fixedVcsTypeFor(rawReference, git); + } + + @Nonnull + protected VcsType fixedVcsTypeFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType fixedType) throws VcsException { + final VcsType selected = rawReference.getType(); + if (selected != null && selected != fixedType) { + throw new VcsValidationException("There was the VCS type " + selected + " explicit selected for dependency " + rawReference + " but this VCS could only be of type " + fixedType + "."); + } + return fixedType; + } + + @Nonnull + protected VcsReference detectVcsUriOf(@Nonnull RawVcsReference rawReference, VcsType vcsType) throws VcsException { + final URI uri = rawReference.getUri(); + if (uri != null) { + final Matcher matcher = nameMatcherFor(rawReference); + final String id = idFor(matcher, rawReference); + final String ref = refFor(matcher, rawReference); + return new VcsReference(vcsType, id, uri, ref, rawReference.getUpdatePolicy(), subPathOf(matcher)); + } + return resolveVcsUriFor(rawReference, vcsType); + } + + @Nonnull + protected VcsReference resolveVcsUriFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType vcsType) throws VcsException { + final Matcher matcher = nameMatcherFor(rawReference); + final String id = idFor(matcher, rawReference); + final String ref = refFor(matcher, rawReference); + String uri = vcsUriPrefixFor(rawReference, vcsType) + rootFor(matcher, rawReference); + final String uriSuffix = vcsUriUriSuffixFor(rawReference, vcsType); + if (!uri.endsWith(uriSuffix)) { + uri += uriSuffix; + } + return new VcsReference(vcsType, id, create(uri), ref, rawReference.getUpdatePolicy(), subPathOf(matcher)); + } + + @Nullable + protected String subPathOf(Matcher matcher) { + try { + return matcher.group("subPath"); + } catch (final IllegalArgumentException ignored) { + return null; + } + } + + @Nullable + protected String refFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { + return rawReference.getRef(); + } + + @Nonnull + protected String rootFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { + return matcher.group("root"); + } + + @Nonnull + protected String idFor(@Nonnull Matcher matcher, @Nonnull RawVcsReference rawReference) throws VcsException { + return matcher.group("root"); + } + + @Nonnull + protected abstract Matcher nameMatcherFor(@Nonnull RawVcsReference rawReference) throws VcsException; + + @SuppressWarnings("UnusedParameters") + @Nonnull + protected String vcsUriPrefixFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType vcsType) throws VcsException { + return "https://"; + } + + @SuppressWarnings("UnusedParameters") + @Nonnull + protected String vcsUriUriSuffixFor(@Nonnull RawVcsReference rawReference, @Nonnull VcsType vcsType) throws VcsException { + return vcsType.getUriSuffix(); + } + + @Nonnull + protected VcsRepositoryFactory vcsFactory() { + return _vcsRepositoryFactory; + } + + @Nonnull + protected Pattern dependencyPattern() { + return _dependencyPattern; + } +} diff --git a/src/main/resources/org/echocat/gradle/plugins/golang/ca.crt b/src/main/resources/org/echocat/gradle/plugins/golang/ca.crt index 960f265..0268678 100644 --- a/src/main/resources/org/echocat/gradle/plugins/golang/ca.crt +++ b/src/main/resources/org/echocat/gradle/plugins/golang/ca.crt @@ -42,3 +42,23 @@ O3NJo2pXh5Tl1njFmUNj403gdy3hZZlyaQQaRwnmDwFWJPsfvw55qVguucQJAX6V um0ABj6y6koQOdjQK/W/7HW/lwLFCRsI3FU34oH7N4RDYiDK51ZLZer+bMEkkySh NOsF/5oirpt9P/FlUQqmMGqz9IgcgA38corog14= -----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE-----