From 897a13a65e5e4e94b73276753255ba3b7e2a9087 Mon Sep 17 00:00:00 2001 From: Amadornes Date: Sun, 19 Aug 2018 00:19:38 +0200 Subject: Fixed dependencies on gradle repackaged libs --- build.gradle | 31 +++++++++++----- .../artifactural/gradle/DependencyResolver.java | 28 +++++++++++++-- .../gradle/GradleRepositoryAdapter.java | 23 ++++++++---- .../artifactural/gradle/ReflectionUtils.java | 4 +-- .../base/artifact/ArtifactIdentifierImpl.java | 42 ---------------------- .../base/artifact/SimpleArtifactIdentifier.java | 42 ++++++++++++++++++++++ 6 files changed, 108 insertions(+), 62 deletions(-) delete mode 100644 src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactIdentifierImpl.java create mode 100644 src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactIdentifier.java diff --git a/build.gradle b/build.gradle index 64c4c30..3f6f986 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'java' -apply plugin: 'idea' group = 'com.amadornes.artifactural' version = '1.0.0' sourceSets { api - shared - gradlecomp + shared + gradlecomp } repositories { @@ -15,15 +14,29 @@ repositories { mavenCentral() } +configurations { + sharedImplementation.extendsFrom apiImplementation + gradlecompImplementation.extendsFrom sharedImplementation + + compile.extendsFrom sharedImplementation + compile.extendsFrom gradlecompImplementation +} + dependencies { sharedImplementation sourceSets.api.output - - gradlecompImplementation sourceSets.api.output + gradlecompImplementation sourceSets.shared.output gradlecompImplementation gradleApi() - - compile sourceSets.api.output - compile sourceSets.shared.output - compile sourceSets.gradlecomp.output + gradlecompImplementation 'com.google.guava:guava:26.0-jre' + gradlecompImplementation 'commons-io:commons-io:2.4' + + compile sourceSets.api.output + compile sourceSets.shared.output + compile sourceSets.gradlecomp.output } +jar { + from sourceSets.api.output + from sourceSets.shared.output + from sourceSets.gradlecomp.output +} diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java index 12364d7..b97de78 100644 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java +++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java @@ -1,9 +1,14 @@ package com.amadornes.artifactural.gradle; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import org.gradle.api.Project; -import org.gradle.api.artifacts.*; -import org.gradle.internal.impldep.com.google.common.cache.Cache; -import org.gradle.internal.impldep.com.google.common.cache.CacheBuilder; +import org.gradle.api.artifacts.ClientModule; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.DependencyArtifact; +import org.gradle.api.artifacts.FileCollectionDependency; +import org.gradle.api.artifacts.ModuleDependency; import java.io.File; import java.util.Set; @@ -68,6 +73,15 @@ public class DependencyResolver { return files; } + /** + * Resolves a dependency, downloading the file and its transitives + * if not cached and returns the set of files. + */ + public Set resolveDependency(Object dependency) { + Dependency dep = project.getDependencies().create(dependency); + return resolveDependency(dep); + } + /** * Resolves a dependency, downloading the file and its transitives * if not cached and returns the set of files. @@ -80,4 +94,12 @@ public class DependencyResolver { return resolveDependency(dep); } + /** + * Resolves a single dependency without any of its transitives + * if not cached and returns the file. + */ + public File resolveSingleDependency(Object dependency) { + return resolveDependency(dependency, false).iterator().next(); + } + } diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java index a601a1e..4bac887 100644 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java +++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java @@ -3,7 +3,9 @@ package com.amadornes.artifactural.gradle; import com.amadornes.artifactural.api.artifact.Artifact; import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; import com.amadornes.artifactural.api.repository.Repository; -import com.amadornes.artifactural.base.artifact.ArtifactIdentifierImpl; +import com.amadornes.artifactural.base.artifact.SimpleArtifactIdentifier; +import com.google.common.io.CountingInputStream; +import org.apache.commons.io.IOUtils; import org.gradle.api.Action; import org.gradle.api.NamedDomainObjectCollection; import org.gradle.api.Transformer; @@ -18,14 +20,23 @@ import org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceA import org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver; import org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver; import org.gradle.api.resources.ResourceException; -import org.gradle.internal.impldep.com.google.common.io.CountingInputStream; -import org.gradle.internal.impldep.org.apache.commons.io.IOUtils; -import org.gradle.internal.resource.*; +import org.gradle.internal.resource.AbstractExternalResource; +import org.gradle.internal.resource.ExternalResource; +import org.gradle.internal.resource.ExternalResourceName; +import org.gradle.internal.resource.ExternalResourceReadResult; +import org.gradle.internal.resource.ExternalResourceRepository; +import org.gradle.internal.resource.ExternalResourceWriteResult; +import org.gradle.internal.resource.ReadableContent; +import org.gradle.internal.resource.ResourceExceptions; import org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData; import org.gradle.internal.resource.metadata.ExternalResourceMetaData; import javax.annotation.Nullable; -import java.io.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URI; import java.util.List; import java.util.regex.Matcher; @@ -104,7 +115,7 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen URI uri = name.getUri(); Matcher matcher = URL_PATTERN.matcher(uri.getPath()); if (!matcher.matches()) return new NullExternalResource(uri); - ArtifactIdentifier identifier = new ArtifactIdentifierImpl( + ArtifactIdentifier identifier = new SimpleArtifactIdentifier( matcher.group("group").replace('/', '.'), matcher.group("name"), matcher.group("version"), diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java index 4fbe925..5dcb9a3 100644 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java +++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java @@ -12,12 +12,12 @@ public class ReflectionUtils { Field f = null; for (String n : name.split("\\.")) { f = findField(target.getClass(), n); - if(f == null) throw new IllegalStateException("Could not find '" + name + "'"); + if (f == null) throw new IllegalStateException("Could not find '" + name + "'"); f.setAccessible(true); prev = target; target = f.get(target); } - if(f == null) throw new IllegalStateException("Could not find '" + name + "'"); + if (f == null) throw new IllegalStateException("Could not find '" + name + "'"); f.set(prev, operator.apply((T) target)); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); diff --git a/src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactIdentifierImpl.java b/src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactIdentifierImpl.java deleted file mode 100644 index 26acd29..0000000 --- a/src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactIdentifierImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.amadornes.artifactural.base.artifact; - -import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; - -public class ArtifactIdentifierImpl implements ArtifactIdentifier { - - private final String group, name, version, classifier, extension; - - public ArtifactIdentifierImpl(String group, String name, String version, String classifier, String extension) { - this.group = group; - this.name = name; - this.version = version; - this.classifier = classifier; - this.extension = extension; - } - - @Override - public String getGroup() { - return group; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getVersion() { - return version; - } - - @Override - public String getClassifier() { - return classifier; - } - - @Override - public String getExtension() { - return extension; - } - -} diff --git a/src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactIdentifier.java b/src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactIdentifier.java new file mode 100644 index 0000000..231f68b --- /dev/null +++ b/src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactIdentifier.java @@ -0,0 +1,42 @@ +package com.amadornes.artifactural.base.artifact; + +import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; + +public class SimpleArtifactIdentifier implements ArtifactIdentifier { + + private final String group, name, version, classifier, extension; + + public SimpleArtifactIdentifier(String group, String name, String version, String classifier, String extension) { + this.group = group; + this.name = name; + this.version = version; + this.classifier = classifier; + this.extension = extension; + } + + @Override + public String getGroup() { + return group; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getVersion() { + return version; + } + + @Override + public String getClassifier() { + return classifier; + } + + @Override + public String getExtension() { + return extension; + } + +} -- cgit