diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 6cfc0ff..90b0c7b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,41 +1,12 @@ -import groovy.xml.MarkupBuilder -import java.security.MessageDigest -import java.util.Base64 - plugins { id("net.kyori.blossom") version "2.0.1" } -val libbyMavenResolverRepo = layout.buildDirectory.dir("libby-maven-resolver-repo").get() -val libbyMavenResolverJar = provider {}.flatMap { // Use a provider to not resolve shadowTask task too early - project(":libby-maven-resolver").tasks.named("shadowJar").flatMap { (it as Jar).archiveFile } -} - -val deleteLibbyMavenResolver = tasks.register("deleteLibbyMavenResolver") { - delete(libbyMavenResolverRepo) - isFollowSymlinks = false -} - -val copyLibbyMavenResolver = tasks.register("copyLibbyMavenResolver") { - dependsOn(":libby-maven-resolver:shadowJar") - dependsOn(deleteLibbyMavenResolver) -} -setupCopy() - -tasks.test { - dependsOn(copyLibbyMavenResolver) -} - sourceSets { main { blossom { javaSources { property("version", project.version.toString()) - property("libbyMavenResolverChecksum", provider { - val md = MessageDigest.getInstance("SHA-256") - val sha256 = md.digest(libbyMavenResolverJar.get().asFile.readBytes()) - Base64.getEncoder().encodeToString(sha256) - }) } } } @@ -43,49 +14,6 @@ sourceSets { blossom { javaSources { property("buildDir", layout.buildDirectory.asFile.get().absolutePath.replace("\\", "\\\\")) - property("libbyMavenResolverRepo", libbyMavenResolverRepo.asFile.absolutePath.replace("\\", "\\\\")) - } - } - } -} - -tasks.named("generateJavaTemplates") { - dependsOn(":libby-maven-resolver:shadowJar") -} - -fun setupCopy() { - val version = project.version.toString() - val partialPath = "${project.group.toString().replace('.', '/')}/libby-maven-resolver/${version}" - val mainFolder = libbyMavenResolverRepo.dir(partialPath) - - copyLibbyMavenResolver { - from(libbyMavenResolverJar) - into(mainFolder) - } - - if (!version.endsWith("-SNAPSHOT")) { - return - } - - // Generate snapshot's maven-metadata-local.xml - copyLibbyMavenResolver { - doFirst { - mainFolder.file("maven-metadata-local.xml").asFile.printWriter(Charsets.UTF_8).use { - val builder = MarkupBuilder(it) - builder.doubleQuotes = true - builder.mkp.xmlDeclaration(mapOf("version" to "1.0", "encoding" to "UTF-8")) - builder.withGroovyBuilder { - "metadata"("modelVersion" to "1.1.0") { - "groupId"(project.group.toString()) - "artifactId"("libby-maven-resolver") - "version"(version) - "versioning"() { - "snapshot"() { - "localCopy"(true) - } - } - } - } } } } diff --git a/core/src/main/java-templates/com/alessiodp/libby/LibbyProperties.java b/core/src/main/java-templates/com/alessiodp/libby/LibbyProperties.java index 2dccadd..e146628 100644 --- a/core/src/main/java-templates/com/alessiodp/libby/LibbyProperties.java +++ b/core/src/main/java-templates/com/alessiodp/libby/LibbyProperties.java @@ -13,9 +13,4 @@ public class LibbyProperties { * User agent string to use when downloading libraries */ public static final String HTTP_USER_AGENT = "libby/" + VERSION; - - /** - * Checksum of libby-maven-resolver jar - */ - public static final String LIBBY_MAVEN_RESOLVER_CHECKSUM = "{{ libbyMavenResolverChecksum }}"; } diff --git a/core/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyHelper.java b/core/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyHelper.java index 8ce1390..c9279ab 100644 --- a/core/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyHelper.java +++ b/core/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyHelper.java @@ -1,6 +1,5 @@ package com.alessiodp.libby.transitive; -import com.alessiodp.libby.LibbyProperties; import com.alessiodp.libby.Library; import com.alessiodp.libby.LibraryManager; import com.alessiodp.libby.Util; @@ -25,16 +24,16 @@ /** * A reflection-based helper for resolving transitive dependencies. It automatically - * downloads Maven Resolver Supplier, Maven Resolver Provider and their transitive dependencies to resolve transitive dependencies. + * downloads Libby Maven Resolver to resolve transitive dependencies. * - * @see Apache Maven Artifact Resolver + * @see Libby Maven Resolver */ public class TransitiveDependencyHelper { /** - * com.alessiodp.libby.transitive.TransitiveDependencyCollector class name for reflections + * com.alessiodp.libby.maven.resolver.TransitiveDependencyCollector class name for reflections */ - private static final String TRANSITIVE_DEPENDENCY_COLLECTOR_CLASS = replaceWithDots("com{}alessiodp{}libby{}transitive{}TransitiveDependencyCollector"); + private static final String TRANSITIVE_DEPENDENCY_COLLECTOR_CLASS = replaceWithDots("com{}alessiodp{}libby{}maven{}resolver{}TransitiveDependencyCollector"); /** * org.eclipse.aether.artifact.Artifact class name for reflections @@ -75,10 +74,10 @@ public TransitiveDependencyHelper(@NotNull LibraryManager libraryManager, @NotNu IsolatedClassLoader classLoader = new IsolatedClassLoader(); classLoader.addPath(libraryManager.downloadLibrary(Library.builder() - .groupId("com{}alessiodp{}libby") + .groupId("com{}alessiodp{}libby{}maven{}resolver") .artifactId("libby-maven-resolver") - .version(LibbyProperties.VERSION) - .checksumFromBase64(LibbyProperties.LIBBY_MAVEN_RESOLVER_CHECKSUM) + .version("1.0.0") + .checksumFromBase64("aMujUbcaxqGkNX5LNIwNzJTffn3MH6DrZKzXcu67+Qc=") .build() )); @@ -86,11 +85,11 @@ public TransitiveDependencyHelper(@NotNull LibraryManager libraryManager, @NotNu Class transitiveDependencyCollectorClass = classLoader.loadClass(TRANSITIVE_DEPENDENCY_COLLECTOR_CLASS); Class artifactClass = classLoader.loadClass(ARTIFACT_CLASS); - // com.alessiodp.libby.TransitiveDependencyCollector(Path) + // com.alessiodp.libby.maven.resolver.TransitiveDependencyCollector(Path) Constructor constructor = transitiveDependencyCollectorClass.getConstructor(Path.class); constructor.setAccessible(true); transitiveDependencyCollectorObject = constructor.newInstance(saveDirectory); - // com.alessiodp.libby.TransitiveDependencyCollector#findTransitiveDependencies(String, String, String, String, Stream) + // com.alessiodp.libby.maven.resolver.TransitiveDependencyCollector#findTransitiveDependencies(String, String, String, String, Stream) resolveTransitiveDependenciesMethod = transitiveDependencyCollectorClass.getMethod("findTransitiveDependencies", String.class, String.class, String.class, String.class, Stream.class); resolveTransitiveDependenciesMethod.setAccessible(true); // org.eclipse.aether.artifact.Artifact#getGroupId() diff --git a/core/src/test/java-templates/com/alessiodp/libby/LibbyTestProperties.java b/core/src/test/java-templates/com/alessiodp/libby/LibbyTestProperties.java index 48be0a0..faefd83 100644 --- a/core/src/test/java-templates/com/alessiodp/libby/LibbyTestProperties.java +++ b/core/src/test/java-templates/com/alessiodp/libby/LibbyTestProperties.java @@ -8,9 +8,4 @@ public class LibbyTestProperties { * Build dir path */ public static final String BUILD_DIR = "{{ buildDir }}"; - - /** - * Local repo set up by gradle for libby-maven-resolver - */ - public static final String LIBBY_MAVEN_RESOLVER_REPO = "{{ libbyMavenResolverRepo }}"; } diff --git a/core/src/test/java/com/alessiodp/libby/transitive/TransitiveDownloadingTest.java b/core/src/test/java/com/alessiodp/libby/transitive/TransitiveDownloadingTest.java index df9a5dd..d69eb3c 100644 --- a/core/src/test/java/com/alessiodp/libby/transitive/TransitiveDownloadingTest.java +++ b/core/src/test/java/com/alessiodp/libby/transitive/TransitiveDownloadingTest.java @@ -1,6 +1,5 @@ package com.alessiodp.libby.transitive; -import com.alessiodp.libby.LibbyTestProperties; import com.alessiodp.libby.Library; import com.alessiodp.libby.LibraryManagerMock; import com.alessiodp.libby.TestUtils; @@ -9,7 +8,6 @@ import org.junit.jupiter.api.Test; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.*; import static org.junit.jupiter.api.Assertions.*; @@ -46,8 +44,7 @@ public class TransitiveDownloadingTest { @BeforeEach public void setUp() throws Exception { libraryManager = new LibraryManagerMock(); - // Local repo set up by gradle for libby-maven-resolver - libraryManager.addRepository(Paths.get(LibbyTestProperties.LIBBY_MAVEN_RESOLVER_REPO).toUri().toString()); + libraryManager.addRepository("https://repo.alessiodp.com/releases"); libraryManager.addMavenCentral(); } diff --git a/maven-resolver/build.gradle.kts b/maven-resolver/build.gradle.kts deleted file mode 100644 index f260902..0000000 --- a/maven-resolver/build.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - -plugins { - id("com.github.johnrengelman.shadow") version "8.1.1" -} - -dependencies { - implementation("org.apache.maven.resolver:maven-resolver-impl:1.9.18") - implementation("org.apache.maven.resolver:maven-resolver-supplier:1.9.18") -} - -tasks.withType { - archiveClassifier.set("") - minimize() -} - -tasks.jar { - finalizedBy("shadowJar") -} diff --git a/maven-resolver/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyCollector.java b/maven-resolver/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyCollector.java deleted file mode 100644 index 247f9c3..0000000 --- a/maven-resolver/src/main/java/com/alessiodp/libby/transitive/TransitiveDependencyCollector.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.alessiodp.libby.transitive; - -import org.apache.maven.repository.internal.MavenRepositorySystemUtils; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.repository.ArtifactRepository; -import org.eclipse.aether.repository.LocalRepository; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.aether.resolution.DependencyRequest; -import org.eclipse.aether.resolution.DependencyResolutionException; -import org.eclipse.aether.resolution.DependencyResult; -import org.eclipse.aether.supplier.RepositorySystemSupplier; -import org.eclipse.aether.util.artifact.JavaScopes; -import org.eclipse.aether.util.filter.ScopeDependencyFilter; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.nio.file.Path; -import java.util.AbstractMap.SimpleEntry; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * A supplier-based helper class for providing compile scope transitive dependencies. - * - * @see maven-resolver. - */ -public class TransitiveDependencyCollector { - - /** - * Counter used to generate ids for repositories - * - * @see #newDefaultRepository(String) - */ - private static final AtomicInteger ID_GENERATOR = new AtomicInteger(); - - /** - * Maven repository system - * - * @see #newRepositorySystem() - */ - @NotNull - private final RepositorySystem repositorySystem = newRepositorySystem(); - - /** - * Maven repository system session - * - * @see #newRepositorySystemSession(RepositorySystem) - */ - @NotNull - private final RepositorySystemSession repositorySystemSession; - - /** - * Local repository path - * - * @see LocalRepository - */ - @NotNull - private final Path saveDirectory; - - /** - * Creates a new {@code TransitiveDependencyCollector}. - * - * @param saveDirectory The download directory name - */ - public TransitiveDependencyCollector(@NotNull Path saveDirectory) { - this.saveDirectory = saveDirectory; - this.repositorySystemSession = newRepositorySystemSession(repositorySystem); - } - - /** - * Creates a new instance of {@link RemoteRepository} - * - * @param url Maven repository url - * @return New instance of {@link RemoteRepository} - */ - @NotNull - public static RemoteRepository newDefaultRepository(@NotNull String url) { - return new RemoteRepository.Builder("repo" + ID_GENERATOR.getAndIncrement(), "default", url).build(); - } - - /** - * Resolves transitive dependencies of specific maven artifact. Dependencies with scope {@code JavaScopes.COMPILE}, {@code JavaScopes.RUNTIME} returned only - * - * @param groupId Maven group ID - * @param artifactId Maven artifact ID - * @param version Maven dependency version - * @param classifier Maven artifact classifier. May be null - * @param repositories Maven repositories that would be used for dependency resolution - * @return Transitive dependencies paired with their repository url, exception otherwise - * @throws DependencyResolutionException thrown if dependency doesn't exist on provided repositories - */ - @NotNull - public Collection> findTransitiveDependencies(@NotNull String groupId, @NotNull String artifactId, @NotNull String version, @NotNull String classifier, @NotNull List repositories) throws DependencyResolutionException { - Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, "jar", version); - - CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, JavaScopes.COMPILE), repositories); - DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, new ScopeDependencyFilter(Arrays.asList(JavaScopes.COMPILE, JavaScopes.RUNTIME), Collections.emptyList())); - - DependencyResult dependencyResult = repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest); - - return dependencyResult.getArtifactResults() - .stream() - .filter(ArtifactResult::isResolved) - .map(artifactResult -> { - ArtifactRepository repo = artifactResult.getRepository(); - String url = null; - if (repo instanceof RemoteRepository) { - url = ((RemoteRepository) repo).getUrl(); - } - return new SimpleEntry<>(artifactResult.getArtifact(), url); - }) - .collect(Collectors.toList()); - } - - /** - * Resolves transitive dependencies of specific maven artifact. Dependencies with scope {@code JavaScopes.COMPILE}, {@code JavaScopes.RUNTIME} returned only. Searches provided repository urls only. - * - * @param groupId Maven group ID - * @param artifactId Maven artifact ID - * @param version Maven artifact version - * @param classifier Maven artifact classifier. May be null - * @param repositories Maven repositories for transitive dependencies search - * @return Transitive dependencies paired with their repository url, exception otherwise - * @throws DependencyResolutionException thrown if dependency doesn't exist on provided repositories - * @see #findTransitiveDependencies(String, String, String, String, List) - */ - @NotNull - public Collection> findTransitiveDependencies(@NotNull String groupId, @NotNull String artifactId, @NotNull String version, @NotNull String classifier, @NotNull Stream repositories) throws DependencyResolutionException { - return findTransitiveDependencies(groupId, artifactId, version, classifier, repositories.map(TransitiveDependencyCollector::newDefaultRepository).collect(Collectors.toList())); - } - - /** - * Creates new session by provided {@link RepositorySystem} - * - * @return new session from {@link RepositorySystem} - * @see MavenRepositorySystemUtils#newSession() - */ - @NotNull - private RepositorySystemSession newRepositorySystemSession(RepositorySystem system) { - DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); - - LocalRepository localRepo = new LocalRepository(saveDirectory.toAbsolutePath().toFile()); - session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); - - Properties properties = new Properties(); - properties.putAll(System.getProperties()); - - session.setSystemProperties(properties); - session.setConfigProperties(properties); - - session.setReadOnly(); // Don't allow to modify it further since DefaultRepositorySystemSession isn't thread-safe - - return session; - } - - /** - * Creates a new repository system - * - * @return New supplier repository system - * @see RepositorySystemSupplier - */ - @NotNull - private RepositorySystem newRepositorySystem() { - return new RepositorySystemSupplier().get(); - } - -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 4b0e3ee..d8a2868 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,6 @@ setOf( "bungee", "core", "fabric", - "maven-resolver", "nukkit", "paper", "sponge",