aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLexManos <LexManos@gmail.com>2018-11-03 01:39:30 -0700
committerLexManos <LexManos@gmail.com>2018-11-03 01:39:30 -0700
commit7fcba8a90b00ede253ba75a697ec6ce9bdd20d39 (patch)
treeac948d191c199e5aaae1cd2d23a016c3a193e357
parent6c19a6e715fd0bf5d7a51963e327f8ce3d50a841 (diff)
downloadArtifactural-7fcba8a90b00ede253ba75a697ec6ce9bdd20d39.tar.gz
Artifactural-7fcba8a90b00ede253ba75a697ec6ce9bdd20d39.tar.bz2
Artifactural-7fcba8a90b00ede253ba75a697ec6ce9bdd20d39.zip
More fixes related to missing repo overrides.
-rw-r--r--src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java11
-rw-r--r--src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java10
2 files changed, 17 insertions, 4 deletions
diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java
index 05f849d..de629fc 100644
--- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java
+++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java
@@ -22,7 +22,6 @@ package com.amadornes.artifactural.gradle;
import com.amadornes.artifactural.api.artifact.Artifact;
import com.amadornes.artifactural.api.artifact.ArtifactIdentifier;
import com.amadornes.artifactural.api.artifact.MissingArtifactException;
-import com.amadornes.artifactural.api.repository.ArtifactProvider;
import com.amadornes.artifactural.api.repository.Repository;
import com.amadornes.artifactural.base.artifact.SimpleArtifactIdentifier;
import com.amadornes.artifactural.base.cache.LocatedArtifactCache;
@@ -38,6 +37,8 @@ import org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.Resol
import org.gradle.api.internal.artifacts.repositories.AbstractArtifactRepository;
import org.gradle.api.internal.artifacts.repositories.DefaultMavenLocalArtifactRepository;
import org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository;
+import org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceArtifactResolver;
+import org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver;
import org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver;
import org.gradle.api.internal.artifacts.repositories.resolver.MetadataFetchingCost;
import org.gradle.api.internal.component.ArtifactType;
@@ -118,10 +119,12 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen
DefaultCacheAwareExternalResourceAccessor accessor = ReflectionUtils.get(resolver, "mavenMetaDataLoader.cacheAwareExternalResourceAccessor.delegate");
ReflectionUtils.alter(accessor, "delegate", prev -> repo); // DefaultCacheAwareExternalResourceAccessor.delegate
ReflectionUtils.alter(accessor, "fileResourceRepository", prev -> repo); // DefaultCacheAwareExternalResourceAccessor.fileResourceRepository
- //ReflectionUtils.alter(resolver, "localAccess", AccessWrapper<MavenLocalRepositoryAccess>::new);
+ ExternalResourceArtifactResolver extResolver = ReflectionUtils.invoke(resolver, ExternalResourceResolver.class, "createArtifactResolver"); //Makes the resolver and caches it.
+ ReflectionUtils.alter(extResolver, "repository", prev -> repo);
+ //File transport references, Would be better to get a reference to the transport and work from there, but don't see it stored anywhere.
+ ReflectionUtils.alter(resolver, "cachingResourceAccessor.this$0.repository", prev -> repo);
+ ReflectionUtils.alter(resolver, "cachingResourceAccessor.delegate.delegate", prev -> repo);
- //return resolver;
- //return new Resolver(resolver);
return new ConfiguredModuleComponentRepository() {
private final ModuleComponentRepositoryAccess local = wrap(resolver.getLocalAccess());
private final ModuleComponentRepositoryAccess remote = wrap(resolver.getRemoteAccess());
diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java
index aaa3dc3..a559a4f 100644
--- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java
+++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java
@@ -21,6 +21,7 @@ package com.amadornes.artifactural.gradle;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.function.UnaryOperator;
public class ReflectionUtils {
@@ -61,6 +62,15 @@ public class ReflectionUtils {
for (Field f : clazz.getDeclaredFields()) {
if (f.getName().equals(name)) {
f.setAccessible(true);
+ if ((f.getModifiers() & Modifier.FINAL) != 0) {
+ try {
+ Field modifiers = Field.class.getDeclaredField("modifiers");
+ modifiers.setAccessible(true);
+ modifiers.setInt(f, f.getModifiers() & ~Modifier.FINAL);
+ } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
return f;
}
}