150 lines
8.0 KiB
Diff
150 lines
8.0 KiB
Diff
|
|
From e9d5a7bb3db32f2b9cf4accc862ba3a49048433e Mon Sep 17 00:00:00 2001
|
||
|
|
From: Mikolaj Izdebski <mizdebsk@redhat.com>
|
||
|
|
Date: Sun, 9 Nov 2014 21:37:37 +0100
|
||
|
|
Subject: [PATCH 03/18] Implement XMvn repository factory method
|
||
|
|
|
||
|
|
---
|
||
|
|
.../artifacts/BaseRepositoryFactory.java | 3 +
|
||
|
|
.../dsl/DefaultRepositoryHandler.java | 6 ++
|
||
|
|
.../DefaultBaseRepositoryFactory.java | 63 +++++++++++++++++++
|
||
|
|
3 files changed, 72 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/BaseRepositoryFactory.java b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/BaseRepositoryFactory.java
|
||
|
|
index 00ea355013b..2b16b409d4d 100644
|
||
|
|
--- a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/BaseRepositoryFactory.java
|
||
|
|
+++ b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/BaseRepositoryFactory.java
|
||
|
|
@@ -15,6 +15,7 @@
|
||
|
|
*/
|
||
|
|
package org.gradle.api.internal.artifacts;
|
||
|
|
|
||
|
|
+import org.gradle.api.artifacts.repositories.ArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.FlatDirectoryArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
||
|
|
@@ -36,4 +37,6 @@ public interface BaseRepositoryFactory {
|
||
|
|
IvyArtifactRepository createIvyRepository();
|
||
|
|
|
||
|
|
MavenArtifactRepository createMavenRepository();
|
||
|
|
+
|
||
|
|
+ ArtifactRepository createXMvnResolver();
|
||
|
|
}
|
||
|
|
diff --git a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/dsl/DefaultRepositoryHandler.java b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/dsl/DefaultRepositoryHandler.java
|
||
|
|
index af092bab6b9..87ddd6ce6fd 100644
|
||
|
|
--- a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/dsl/DefaultRepositoryHandler.java
|
||
|
|
+++ b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/dsl/DefaultRepositoryHandler.java
|
||
|
|
@@ -18,6 +18,7 @@ package org.gradle.api.internal.artifacts.dsl;
|
||
|
|
import groovy.lang.Closure;
|
||
|
|
import org.gradle.api.Action;
|
||
|
|
import org.gradle.api.artifacts.dsl.RepositoryHandler;
|
||
|
|
+import org.gradle.api.artifacts.repositories.ArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.FlatDirectoryArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
||
|
|
@@ -41,6 +42,7 @@ public class DefaultRepositoryHandler extends DefaultArtifactRepositoryContainer
|
||
|
|
public static final String FLAT_DIR_DEFAULT_NAME = "flatDir";
|
||
|
|
private static final String MAVEN_REPO_DEFAULT_NAME = "maven";
|
||
|
|
private static final String IVY_REPO_DEFAULT_NAME = "ivy";
|
||
|
|
+ private static final String XMVN_REPO_DEFAULT_NAME = "xmvn";
|
||
|
|
|
||
|
|
private final BaseRepositoryFactory repositoryFactory;
|
||
|
|
|
||
|
|
@@ -105,4 +107,8 @@ public class DefaultRepositoryHandler extends DefaultArtifactRepositoryContainer
|
||
|
|
public IvyArtifactRepository ivy(Closure closure) {
|
||
|
|
return ivy(ConfigureUtil.configureUsing(closure));
|
||
|
|
}
|
||
|
|
+
|
||
|
|
+ public ArtifactRepository xmvn() {
|
||
|
|
+ return addRepository(repositoryFactory.createXMvnResolver(), XMVN_REPO_DEFAULT_NAME);
|
||
|
|
+ }
|
||
|
|
}
|
||
|
|
diff --git a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/DefaultBaseRepositoryFactory.java b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/DefaultBaseRepositoryFactory.java
|
||
|
|
index 408f346f6bd..73112106ae1 100644
|
||
|
|
--- a/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/DefaultBaseRepositoryFactory.java
|
||
|
|
+++ b/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/DefaultBaseRepositoryFactory.java
|
||
|
|
@@ -17,6 +17,7 @@
|
||
|
|
package org.gradle.api.internal.artifacts.repositories;
|
||
|
|
|
||
|
|
import org.gradle.api.artifacts.dsl.RepositoryHandler;
|
||
|
|
+import org.gradle.api.artifacts.repositories.ArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.AuthenticationContainer;
|
||
|
|
import org.gradle.api.artifacts.repositories.FlatDirectoryArtifactRepository;
|
||
|
|
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
|
||
|
|
@@ -43,7 +44,14 @@ import org.gradle.internal.resource.local.FileStore;
|
||
|
|
import org.gradle.internal.resource.local.LocallyAvailableResourceFinder;
|
||
|
|
|
||
|
|
import java.io.File;
|
||
|
|
+import java.lang.reflect.Method;
|
||
|
|
+import java.net.MalformedURLException;
|
||
|
|
+import java.net.URL;
|
||
|
|
+import java.net.URLClassLoader;
|
||
|
|
+import java.util.Arrays;
|
||
|
|
+import java.util.LinkedHashSet;
|
||
|
|
import java.util.Map;
|
||
|
|
+import java.util.Set;
|
||
|
|
|
||
|
|
public class DefaultBaseRepositoryFactory implements BaseRepositoryFactory {
|
||
|
|
private final LocalMavenRepositoryLocator localMavenRepositoryLocator;
|
||
|
|
@@ -136,4 +144,59 @@ public class DefaultBaseRepositoryFactory implements BaseRepositoryFactory {
|
||
|
|
|
||
|
|
return container;
|
||
|
|
}
|
||
|
|
+
|
||
|
|
+ public ArtifactRepository createXMvnResolver() {
|
||
|
|
+ // Check if XMvn connector is available and inform user if it's not.
|
||
|
|
+ // This is more user-friendly as it prevents cryptic stack traces.
|
||
|
|
+ if (!new File("/usr/share/java/xmvn/xmvn-connector-gradle.jar").exists())
|
||
|
|
+ throw new RuntimeException("Local mode for Gradle is not available because XMvn Gradle connector is not installed. "
|
||
|
|
+ + "To use local mode you need to install gradle-local package.");
|
||
|
|
+
|
||
|
|
+ // XMvn connector for Gradle is an external library and it is not
|
||
|
|
+ // included in default Gradle classpath. Before it can be accessed
|
||
|
|
+ // we need to add its implementation JARs to current class loader.
|
||
|
|
+ /*
|
||
|
|
+ try {
|
||
|
|
+ ClassLoader classLoader = getClass().getClassLoader();
|
||
|
|
+ Set<URL> newUrls = new LinkedHashSet<URL>();
|
||
|
|
+ newUrls.add(new File("/usr/share/java/xmvn/xmvn-api.jar").toURI().toURL());
|
||
|
|
+ newUrls.add(new File("/usr/share/java/xmvn/xmvn-launcher.jar").toURI().toURL());
|
||
|
|
+ newUrls.add(new File("/usr/share/java/xmvn/xmvn-connector-gradle.jar").toURI().toURL());
|
||
|
|
+ Method getterMethod = classLoader.getClass().getMethod("getURLs");
|
||
|
|
+ Object[] currentUrls = (Object[]) getterMethod.invoke(classLoader);
|
||
|
|
+ newUrls.removeAll(Arrays.asList(currentUrls));
|
||
|
|
+ Method adderMethod = classLoader.getClass().getMethod("addURLs", Iterable.class);
|
||
|
|
+ adderMethod.invoke(classLoader, newUrls);
|
||
|
|
+ } catch (ReflectiveOperationException e) {
|
||
|
|
+ throw new RuntimeException("Unable to inject XMvn JARs to Gradle class loader", e);
|
||
|
|
+ } catch (MalformedURLException e) {
|
||
|
|
+ // Should not happen
|
||
|
|
+ throw new RuntimeException(e);
|
||
|
|
+ }
|
||
|
|
+ */
|
||
|
|
+ Class xmvnClass;
|
||
|
|
+
|
||
|
|
+ try {
|
||
|
|
+ URL[] newUrls = new URL[] {
|
||
|
|
+ new File("/usr/share/java/xmvn/xmvn-api.jar").toURI().toURL(),
|
||
|
|
+ new File("/usr/share/java/xmvn/xmvn-core.jar").toURI().toURL(),
|
||
|
|
+ new File("/usr/share/java/xmvn/xmvn-connector-gradle.jar").toURI().toURL()
|
||
|
|
+ };
|
||
|
|
+ ClassLoader classLoader = new URLClassLoader(newUrls, getClass().getClassLoader());
|
||
|
|
+ String xmvnConnectorRole = "org.fedoraproject.xmvn.connector.gradle.GradleResolver";
|
||
|
|
+ xmvnClass = classLoader.loadClass(xmvnConnectorRole);
|
||
|
|
+ } catch (ClassNotFoundException e) {
|
||
|
|
+ throw new RuntimeException("Unable to inject XMvn JARs to Gradle class loader", e);
|
||
|
|
+ } catch (MalformedURLException e) {
|
||
|
|
+ // Should not happen
|
||
|
|
+ throw new RuntimeException(e);
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ try {
|
||
|
|
+ return (ArtifactRepository) xmvnClass.getConstructor(MetaDataParser.class, ImmutableModuleIdentifierFactory.class, FileResourceRepository.class)
|
||
|
|
+ .newInstance(pomParser, moduleIdentifierFactory, fileResourceRepository);
|
||
|
|
+ } catch (ReflectiveOperationException e) {
|
||
|
|
+ throw new RuntimeException("Failed to inject XMvn resolver", e);
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
}
|
||
|
|
--
|
||
|
|
2.20.1
|
||
|
|
|