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 --- .../artifactural/gradle/DependencyResolver.java | 28 +++++++++++++++++++--- .../gradle/GradleRepositoryAdapter.java | 23 +++++++++++++----- .../artifactural/gradle/ReflectionUtils.java | 4 ++-- 3 files changed, 44 insertions(+), 11 deletions(-) (limited to 'src/gradlecomp/java/com/amadornes') 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); -- cgit