From 50fa9dadaeccdcc8bc756fa020c5ad30fe522959 Mon Sep 17 00:00:00 2001 From: yahavi Date: Tue, 21 Nov 2023 09:15:52 +0200 Subject: [PATCH] Support building quarkus 3.2.x application --- .../extractor/maven/BuildInfoRecorder.java | 4 +- .../ArtifactoryResolutionRepositoryBase.java | 16 +- .../ArtifactorySonatypeArtifactResolver.java | 72 ----- .../ArtifactorySonatypeMetadataResolver.java | 61 ---- ...ArtifactorySonatypeRepositoryListener.java | 283 ------------------ .../ArtifactorySonatypeResolution.java | 65 ---- .../ArtifactorySonatypeResolversHelper.java | 77 ----- .../resources/META-INF/plexus/components.xml | 161 ---------- build.gradle | 4 - 9 files changed, 3 insertions(+), 740 deletions(-) delete mode 100644 build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeArtifactResolver.java delete mode 100644 build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeMetadataResolver.java delete mode 100644 build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeRepositoryListener.java delete mode 100644 build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolution.java delete mode 100644 build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolversHelper.java diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/BuildInfoRecorder.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/BuildInfoRecorder.java index 39255eecb..b67d54c52 100644 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/BuildInfoRecorder.java +++ b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/BuildInfoRecorder.java @@ -116,9 +116,7 @@ public void setDependencyParentsMaps(Map dependencyParentsMa } /** - * The repository listeners (either ArtifactoryEclipseRepositoryListener or - * ArtifactorySonatypeRepositoryListener) invoke this method with each - * artifact being resolved by Maven. + * The repository listener invokes this method with each artifact being resolved by Maven. * * @param artifact The artifact being resolved by Maven. */ diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionRepositoryBase.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionRepositoryBase.java index 35917e733..84d1f862a 100644 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionRepositoryBase.java +++ b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionRepositoryBase.java @@ -7,8 +7,8 @@ import org.jfrog.build.extractor.Proxy; import org.jfrog.build.extractor.ProxySelector; -import static org.sonatype.aether.repository.Proxy.TYPE_HTTP; -import static org.sonatype.aether.repository.Proxy.TYPE_HTTPS; +import static org.eclipse.aether.repository.Proxy.TYPE_HTTP; +import static org.eclipse.aether.repository.Proxy.TYPE_HTTPS; public abstract class ArtifactoryResolutionRepositoryBase { protected final String releaseRepoUrl; @@ -65,18 +65,6 @@ public org.apache.maven.repository.Proxy createMavenProxy(String repoUrl) { return proxy; } - public org.sonatype.aether.repository.Proxy createSonatypeProxy(String repoUrl) { - Proxy proxyConfig = proxySelector.getProxy(repoUrl); - if (proxyConfig == null) { - return null; - } - return new org.sonatype.aether.repository.Proxy( - proxyConfig.isHttps() ? TYPE_HTTPS : TYPE_HTTP, - proxyConfig.getHost(), - proxyConfig.getPort(), - StringUtils.isNotBlank(proxyConfig.getUsername()) ? new org.sonatype.aether.repository.Authentication(proxyConfig.getUsername(), proxyConfig.getPassword()) : null); - } - public org.eclipse.aether.repository.Proxy createEclipseProxy(String repoUrl) { Proxy proxyConfig = proxySelector.getProxy(repoUrl); if (proxyConfig == null) { diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeArtifactResolver.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeArtifactResolver.java deleted file mode 100644 index 1c1372b50..000000000 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeArtifactResolver.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.jfrog.build.extractor.maven.resolver; - -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.impl.internal.DefaultArtifactResolver; -import org.sonatype.aether.repository.RemoteRepository; -import org.sonatype.aether.resolution.ArtifactRequest; -import org.sonatype.aether.resolution.ArtifactResolutionException; -import org.sonatype.aether.resolution.ArtifactResult; -import org.sonatype.aether.util.DefaultRepositorySystemSession; - -import javax.inject.Named; -import java.util.Collection; -import java.util.List; - -/** - * The class extends Maven's DefaultArtifactResolver and adds to it code that enforces Artifactory's configured resolution repositories. - */ -@Named -@Component( role = ArtifactorySonatypeArtifactResolver.class ) -public class ArtifactorySonatypeArtifactResolver extends DefaultArtifactResolver { - - @Requirement - private ResolutionHelper resolutionHelper; - - @Requirement - private Logger logger; - - @Requirement - private ArtifactorySonatypeResolversHelper helper; - - public void initResolutionRepositories(RepositorySystemSession session) { - helper.getResolutionRepositories(session); - } - - private void enforceResolutionRepositories(RepositorySystemSession session, ArtifactRequest request) { - // Get the Artifactory repositories configured in the Artifactory plugin: - List repositories = helper.getResolutionRepositories(session); - - // The repositories list can be empty, in case this build is not running from a CI server. - // In that case, we do not want to override Maven's configured repositories: - if (repositories != null && !repositories.isEmpty()) { - request.setRepositories(repositories); - } - } - - public List resolveArtifacts( RepositorySystemSession session, Collection requests ) - throws ArtifactResolutionException { - - if (session instanceof DefaultRepositorySystemSession) { - DefaultRepositorySystemSession defRepoSession = (DefaultRepositorySystemSession)session; - defRepoSession.setNotFoundCachingEnabled(false); - defRepoSession.setTransferErrorCachingEnabled(false); - } - - for(ArtifactRequest request : requests) { - enforceResolutionRepositories(session, request); - } - // Now we let Maven resolve the artifacts: - return super.resolveArtifacts(session, requests); - } - - public RemoteRepository getSnapshotRepository(RepositorySystemSession session) { - return helper.getSnapshotRepository(session); - } - - public RemoteRepository getReleaseRepository(RepositorySystemSession session) { - return helper.getReleaseRepository(session); - } -} diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeMetadataResolver.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeMetadataResolver.java deleted file mode 100644 index a5dd16906..000000000 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeMetadataResolver.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.jfrog.build.extractor.maven.resolver; - -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.impl.internal.DefaultMetadataResolver; -import org.sonatype.aether.metadata.Metadata; -import org.sonatype.aether.repository.RemoteRepository; -import org.sonatype.aether.resolution.MetadataRequest; -import org.sonatype.aether.resolution.MetadataResult; -import org.sonatype.aether.spi.log.Logger; - -import javax.inject.Named; -import java.util.Collection; -import java.util.List; - -@Named -@Component( role = ArtifactorySonatypeMetadataResolver.class ) -public class ArtifactorySonatypeMetadataResolver extends DefaultMetadataResolver { - - @Requirement - private ResolutionHelper resolutionHelper; - - @Requirement - private Logger logger; - - @Requirement - private ArtifactorySonatypeResolversHelper helper; - - private void enforceResolutionRepositories(RepositorySystemSession session, MetadataRequest request) { - // Get the Artifactory repositories configured in the Artifactory plugin: - List repositories = helper.getResolutionRepositories(session); - - // The repositories list can be empty, in case this build is not running from a CI server. - // In that case, we do not want to override Maven's configured repositories: - if (repositories != null && !repositories.isEmpty() && request.getRepository() != null && request.getMetadata() != null) { - if (request.getMetadata().getNature() == Metadata.Nature.SNAPSHOT) { - request.setRepository(getSnapshotRepository(session)); - } else { - request.setRepository(getReleaseRepository(session)); - } - } - } - - @Override - public List resolveMetadata(RepositorySystemSession session, Collection requests ) { - for(MetadataRequest request : requests) { - enforceResolutionRepositories(session, request); - } - // Now we let Maven resolve the artifacts: - return super.resolveMetadata(session, requests); - } - - public RemoteRepository getSnapshotRepository(RepositorySystemSession session) { - return helper.getSnapshotRepository(session); - } - - public RemoteRepository getReleaseRepository(RepositorySystemSession session) { - return helper.getReleaseRepository(session); - } -} diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeRepositoryListener.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeRepositoryListener.java deleted file mode 100644 index 8ad6d2b65..000000000 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeRepositoryListener.java +++ /dev/null @@ -1,283 +0,0 @@ -package org.jfrog.build.extractor.maven.resolver; - -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; -import org.jfrog.build.extractor.maven.BuildInfoRecorder; -import org.sonatype.aether.AbstractRepositoryListener; -import org.sonatype.aether.RepositoryEvent; -import org.sonatype.aether.RepositoryListener; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.impl.ArtifactResolver; -import org.sonatype.aether.impl.MetadataResolver; -import org.sonatype.aether.impl.internal.DefaultRepositorySystem; -import org.sonatype.aether.metadata.Metadata; -import org.sonatype.aether.repository.RemoteRepository; -import org.sonatype.aether.repository.RepositoryPolicy; -import org.sonatype.aether.resolution.ArtifactRequest; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Properties; - -/** - * Repository listener when running in Maven 3.0.x. - * The listener performs the following: - * 1. Enforces artifacts resolution from Artifactory. - * 2. Updates the BuildInfoRecorder with each resolved artifact. - * @author Shay Yaakov - */ -@Component(role = RepositoryListener.class) -public class ArtifactorySonatypeRepositoryListener extends AbstractRepositoryListener implements Contextualizable { - - @Requirement - private Logger logger; - - @Requirement - private ResolutionHelper resolutionHelper; - - @Requirement - private DefaultArtifactDescriptorReader descriptorReader; - - @Requirement - private DefaultRepositorySystem repositorySystem; - - @Requirement - private ArtifactResolver artifactoryArtifactResolver; - - @Requirement - private MetadataResolver artifactoryMetadataResolver; - - BuildInfoRecorder buildInfoRecorder = null; - - private PlexusContainer plexusContainer; - - Boolean artifactoryRepositoriesEnforced = false; - private ArtifactorySonatypeArtifactResolver artifactResolver = null; - private ArtifactorySonatypeMetadataResolver metadataResolver = null; - - /** - * The method replaces the DefaultArtifactResolver instance with an instance of ArtifactorySonatypeArtifactResolver. - * The new class sets the configured Artifactory resolution repositories for each resolved artifact. - * - * @throws ComponentLookupException - * @throws InvocationTargetException - * @throws IllegalAccessException - */ - private void enforceArtifactoryResolver() throws ComponentLookupException, InvocationTargetException, IllegalAccessException { - logger.debug("Enforcing Artifactory artifact resolver"); - - this.artifactResolver = (ArtifactorySonatypeArtifactResolver)artifactoryArtifactResolver; - this.metadataResolver = (ArtifactorySonatypeMetadataResolver)artifactoryMetadataResolver; - - repositorySystem.setArtifactResolver(artifactResolver); - repositorySystem.setMetadataResolver(artifactoryMetadataResolver); - - // Setting the resolver. This is done using reflection, since the signature of the - // DefaultArtifactDescriptorReader.setArtifactResolver method changed in Maven 3.1.x: - Method setArtifactResolverMethod = null; - Method[] methods = DefaultArtifactDescriptorReader.class.getDeclaredMethods(); - for (Method method : methods) { - if ("setArtifactResolver".equals(method.getName())) { - setArtifactResolverMethod = method; - break; - } - } - if (setArtifactResolverMethod == null) { - throw new RuntimeException("Failed to enforce Artifactory resolver. Method DefaultArtifactDescriptorReader.setArtifactResolver does not exist"); - } - setArtifactResolverMethod.invoke(descriptorReader, artifactResolver); - - artifactoryRepositoriesEnforced = true; - synchronized (artifactoryRepositoriesEnforced) { - artifactoryRepositoriesEnforced.notifyAll(); - } - } - - private BuildInfoRecorder getBuildInfoRecorder() { - if (buildInfoRecorder == null) { - try { - buildInfoRecorder = (BuildInfoRecorder)plexusContainer.lookup(BuildInfoRecorder.class.getName()); - } catch (ComponentLookupException e) { - logger.error("Failed while trying to fetch BuildInfoRecorder from the container in " + this.getClass().getName(), e); - } - if (buildInfoRecorder == null) { - logger.error("Could not fetch BuildInfoRecorder from the container in " + this.getClass().getName() + ". Artifacts resolution cannot be recorded."); - } - } - return buildInfoRecorder; - } - - @Override - public void metadataDownloading(RepositoryEvent event) { - verifyArtifactoryResolutionEnforced(event); - } - - @Override - public void artifactDownloading(RepositoryEvent event) { - verifyArtifactoryResolutionEnforced(event); - } - - /** - * The enforceArtifactoryResolver() method replaces the default artifact resolver instance with a resolver that enforces Artifactory - * resolution repositories. However, since there's a chance that Maven started resolving a few artifacts before the instance replacement, - * thsi method makes sure those artifacts will be resolved from Artifactory as well. - * @param event - */ - private void verifyArtifactoryResolutionEnforced(RepositoryEvent event) { - initResolutionHelper(event.getSession()); - if (!resolutionHelper.resolutionRepositoriesConfigured()) { - return; - } - if (event.getArtifact() == null && event.getMetadata() == null) { - return; - } - if (!(event.getRepository() instanceof RemoteRepository)) { - return; - } - - RemoteRepository repo = (RemoteRepository)event.getRepository(); - - // In case the Artifactory resolver is not yet set, we wait for it first: - if (!artifactoryRepositoriesEnforced) { - synchronized (artifactoryRepositoriesEnforced) { - if (!artifactoryRepositoriesEnforced) { - try { - artifactoryRepositoriesEnforced.wait(); - } catch (InterruptedException e) { - logger.error("Failed while waiting for Artifactory repositories enforcement", e); - } - } - } - } - - // Now that the resolver enforcement is done, we make sure that the Artifactory resolution repositories in the resolver are initialized: - artifactResolver.initResolutionRepositories(event.getSession()); - - // Take the Artifactory resolution repositories from the Artifactory resolver: - RemoteRepository artifactorySnapshotRepo; - RemoteRepository artifactoryReleaseRepo; - boolean snapshot; - if (event.getArtifact() != null) { - artifactorySnapshotRepo = artifactResolver.getSnapshotRepository(event.getSession()); - artifactoryReleaseRepo = artifactResolver.getReleaseRepository(event.getSession()); - snapshot = event.getArtifact().isSnapshot(); - } else { - artifactorySnapshotRepo = metadataResolver.getSnapshotRepository(event.getSession()); - artifactoryReleaseRepo = metadataResolver.getReleaseRepository(event.getSession()); - snapshot = event.getMetadata().getNature() == Metadata.Nature.SNAPSHOT; - } - - // If the artifact about to be downloaded was not handled by the Artifactory resolution resolver, but by the default resolver (before - // it had been replaced), modify the repository URL: - try { - if (snapshot && !repo.getUrl().equals(artifactorySnapshotRepo.getUrl())) { - logger.debug("Replacing resolution repository URL: " + repo + " with: " + artifactorySnapshotRepo.getUrl()); - copyRepositoryFields(artifactorySnapshotRepo, repo); - setRepositoryPolicy(repo); - } else - if (!snapshot && !repo.getUrl().equals(artifactoryReleaseRepo.getUrl())) { - logger.debug("Replacing resolution repository URL: " + repo + " with: " + artifactoryReleaseRepo.getUrl()); - copyRepositoryFields(artifactoryReleaseRepo, repo); - setRepositoryPolicy(repo); - } - } catch (Exception e) { - logger.error("Failed while replacing resolution repository URL", e); - } - } - - private void initResolutionHelper(RepositorySystemSession session) { - if (resolutionHelper.isInitialized()) { - return; - } - Properties allMavenProps = new Properties(); - allMavenProps.putAll(session.getSystemProperties()); - allMavenProps.putAll(session.getUserProperties()); - resolutionHelper.init(allMavenProps); - } - - private void copyRepositoryFields(RemoteRepository fromRepo, RemoteRepository toRepo) - throws IllegalAccessException, NoSuchFieldException { - Field url = RemoteRepository.class.getDeclaredField("url"); - url.setAccessible(true); - url.set(toRepo, fromRepo.getUrl()); - if (fromRepo.getAuthentication() != null) { - Field authentication = RemoteRepository.class.getDeclaredField("authentication"); - authentication.setAccessible(true); - authentication.set(toRepo, fromRepo.getAuthentication()); - } - if (fromRepo.getProxy() != null) { - Field proxy = RemoteRepository.class.getDeclaredField("proxy"); - proxy.setAccessible(true); - proxy.set(toRepo, fromRepo.getProxy()); - } - } - - /** - * Enables both snapshot and release polocies for a repository - */ - private void setRepositoryPolicy(RemoteRepository repo) throws NoSuchFieldException, IllegalAccessException { - RepositoryPolicy policy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN); - - Field releasePolicyField = RemoteRepository.class.getDeclaredField("releasePolicy"); - Field snapshotPolicyField = RemoteRepository.class.getDeclaredField("snapshotPolicy"); - releasePolicyField.setAccessible(true); - snapshotPolicyField.setAccessible(true); - releasePolicyField.set(repo, policy); - snapshotPolicyField.set(repo, policy); - } - - /** - * Intercepts resolved artifacts and updates the BuildInfoRecorder, so that build-info includes all resolved artifacts. - */ - @Override - public void artifactResolved(RepositoryEvent event) { - String requestContext = ((ArtifactRequest)event.getTrace().getData()).getRequestContext(); - String scope = resolutionHelper.getScopeByRequestContext(requestContext); - org.apache.maven.artifact.Artifact artifact = toMavenArtifact(event.getArtifact(), scope); - if (event.getRepository() != null) { - logger.debug("[buildinfo] Resolved artifact: " + artifact + " from: " + event.getRepository() + " Context is: " + requestContext); - if (getBuildInfoRecorder() != null) { - getBuildInfoRecorder().artifactResolved(artifact); - } - } else { - logger.debug("[buildinfo] Could not resolve artifact: " + artifact); - } - - super.artifactResolved(event); - } - - /** - * Converts org.sonatype.aether.artifact.Artifact objects into org.apache.maven.artifact.Artifact objects. - */ - private org.apache.maven.artifact.Artifact toMavenArtifact(final org.sonatype.aether.artifact.Artifact art, String scope) { - if (art == null) { - return null; - } - String classifier = art.getClassifier(); - classifier = classifier == null ? "" : classifier; - DefaultArtifact artifact = new DefaultArtifact(art.getGroupId(), art.getArtifactId(), art.getVersion(), scope, art.getExtension(), classifier, null); - - artifact.setFile(art.getFile()); - return artifact; - } - - @Override - public void contextualize(Context context) throws ContextException { - plexusContainer = (PlexusContainer)context.get(PlexusConstants.PLEXUS_KEY); - try { - enforceArtifactoryResolver(); - } catch (Exception e) { - logger.error("Failed while enforcing Artifactory artifact resolver", e); - } - } -} diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolution.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolution.java deleted file mode 100644 index 35a8c5bdf..000000000 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolution.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.jfrog.build.extractor.maven.resolver; - -import org.codehaus.plexus.logging.Logger; -import org.jfrog.build.extractor.ProxySelector; -import org.sonatype.aether.repository.Authentication; -import org.sonatype.aether.repository.Proxy; -import org.sonatype.aether.repository.RemoteRepository; -import org.sonatype.aether.repository.RepositoryPolicy; - -/** - * Based on the Artifactory client configuration, create and configure snapshot and release repositories (e.g. build info properties file). - * Those repositories will replace the default Maven repositories. - */ -public class ArtifactorySonatypeResolution extends ArtifactoryResolutionRepositoryBase { - public ArtifactorySonatypeResolution(String repoReleaseUrl, String snapshotRepoUrl, String repoUsername, String repoPassword, ProxySelector proxySelector, Logger logger) { - super(repoReleaseUrl, snapshotRepoUrl, repoUsername, repoPassword, proxySelector, logger); - } - - public RemoteRepository createSnapshotRepository() { - if (super.shouldCreateSnapshotRepository()) { - return createDefaultRepository(snapshotRepoUrl, "artifactory-snapshot", false, true); - } - return null; - } - - public RemoteRepository createReleaseRepository() { - if (super.shouldCreateReleaseRepository()) { - String repositoryId = snapshotPolicyEnabled() ? "artifactory-release-snapshot" : "artifactory-release"; - return createDefaultRepository(releaseRepoUrl, repositoryId, true, snapshotPolicyEnabled()); - } - return null; - } - - private RemoteRepository createDefaultRepository(String repoUrl, String repoId, Boolean releasePolicy, boolean snapshotPolicy) { - RemoteRepository repository = new RemoteRepository(); - setPolicy(repository, releasePolicy, snapshotPolicy); - repository.setUrl(repoUrl); - repository.setId(repoId); - setAuth(repository); - setProxy(repository); - - return repository; - } - - private void setPolicy(RemoteRepository snapshotPluginRepository, boolean releasePolicyEnabled, boolean snapshotPolicyEnabled) { - RepositoryPolicy releasePolicy = new RepositoryPolicy(releasePolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN); - snapshotPluginRepository.setPolicy(snapshotPolicyEnabled, releasePolicy); - RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN); - snapshotPluginRepository.setPolicy(snapshotPolicyEnabled, snapshotPolicy); - } - - private void setAuth(RemoteRepository snapshotPluginRepository) { - if (shouldSetAuthentication()) { - Authentication authentication = new Authentication(repoUsername, repoPassword); - snapshotPluginRepository.setAuthentication(authentication); - } - } - - private void setProxy(RemoteRepository repository) { - Proxy proxy = createSonatypeProxy(repository.getUrl()); - if (proxy != null) { - repository.setProxy(proxy); - } - } -} diff --git a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolversHelper.java b/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolversHelper.java deleted file mode 100644 index afaba6524..000000000 --- a/build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ArtifactorySonatypeResolversHelper.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.jfrog.build.extractor.maven.resolver; - -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; -import org.jfrog.build.extractor.ProxySelector; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.repository.RemoteRepository; - -import javax.inject.Named; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -@Named -@Component(role = ArtifactorySonatypeResolversHelper.class) -public class ArtifactorySonatypeResolversHelper { - - @Requirement - private ResolutionHelper resolutionHelper; - - @Requirement - private Logger logger; - - private final List resolutionRepositories = new ArrayList<>(); - private RemoteRepository releaseRepository = null; - private RemoteRepository snapshotRepository = null; - - public void initResolutionRepositories(RepositorySystemSession session) { - getResolutionRepositories(session); - } - - /** - * Create a list containing one release and one snapshot resolution repositories, according to the configuration in the Artifactory plugin. - * The list is used to override Maven's default or configured repositories, so that the build dependencies are resolved from Artifactory. - * The list is saved and reused for further invocations to this method. - */ - public List getResolutionRepositories(RepositorySystemSession session) { - if (resolutionRepositories.isEmpty()) { - Properties allMavenProps = new Properties(); - allMavenProps.putAll(session.getSystemProperties()); - allMavenProps.putAll(session.getUserProperties()); - resolutionHelper.init(allMavenProps); - ProxySelector proxySelector = new ProxySelector(resolutionHelper.getHttpProxyHost(), resolutionHelper.getHttpProxyPort(), resolutionHelper.getHttpProxyUsername(), resolutionHelper.getHttpProxyPassword(), resolutionHelper.getHttpsProxyHost(), resolutionHelper.getHttpsProxyPort(), resolutionHelper.getHttpsProxyUsername(), resolutionHelper.getHttpsProxyPassword(), resolutionHelper.getNoProxy()); - - ArtifactorySonatypeResolution artifactoryResolution = new ArtifactorySonatypeResolution(resolutionHelper.getRepoReleaseUrl(), resolutionHelper.getRepoSnapshotUrl(), resolutionHelper.getRepoUsername(), resolutionHelper.getRepoPassword(), proxySelector, logger); - - snapshotRepository = artifactoryResolution.createSnapshotRepository(); - if (snapshotRepository != null) { - resolutionRepositories.add(snapshotRepository); - } - - releaseRepository = artifactoryResolution.createReleaseRepository(); - if (releaseRepository != null) { - resolutionRepositories.add(releaseRepository); - } - } - return resolutionRepositories; - } - - public RemoteRepository getSnapshotRepository(RepositorySystemSession session) { - // Init repositories configured in the Artifactory plugin: - initResolutionRepositories(session); - - if (snapshotRepository != null) { - return snapshotRepository; - } - return releaseRepository; - } - - public RemoteRepository getReleaseRepository(RepositorySystemSession session) { - // Init repositories configured in the Artifactory plugin: - initResolutionRepositories(session); - - return releaseRepository; - } -} \ No newline at end of file diff --git a/build-info-extractor-maven3/src/main/resources/META-INF/plexus/components.xml b/build-info-extractor-maven3/src/main/resources/META-INF/plexus/components.xml index 746e99063..baab3a210 100644 --- a/build-info-extractor-maven3/src/main/resources/META-INF/plexus/components.xml +++ b/build-info-extractor-maven3/src/main/resources/META-INF/plexus/components.xml @@ -102,24 +102,6 @@ - - - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeResolversHelper - default - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeResolversHelper - - - org.codehaus.plexus.logging.Logger - default - logger - - - org.jfrog.build.extractor.maven.resolver.ResolutionHelper - default - resolutionHelper - - - org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseMetadataResolver @@ -193,55 +175,6 @@ - - - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeMetadataResolver - default - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeMetadataResolver - - - - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeResolversHelper - default - helper - - - org.sonatype.aether.spi.log.Logger - default - logger - - - org.jfrog.build.extractor.maven.resolver.ResolutionHelper - default - resolutionHelper - - - org.sonatype.aether.impl.RepositoryEventDispatcher - default - repositoryEventDispatcher - - - org.sonatype.aether.impl.VersionResolver - default - versionResolver - - - org.sonatype.aether.impl.UpdateCheckManager - default - updateCheckManager - - - org.sonatype.aether.impl.RemoteRepositoryManager - default - remoteRepositoryManager - - - org.sonatype.aether.impl.SyncContextFactory - default - syncContextFactory - - - org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseArtifactResolver @@ -320,62 +253,6 @@ - - - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeArtifactResolver - default - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeArtifactResolver - - - - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeResolversHelper - default - helper - - - org.codehaus.plexus.logging.Logger - default - logger - - - org.jfrog.build.extractor.maven.resolver.ResolutionHelper - default - resolutionHelper - - - org.sonatype.aether.spi.io.FileProcessor - default - fileProcessor - - - org.sonatype.aether.impl.RepositoryEventDispatcher - default - repositoryEventDispatcher - - - org.sonatype.aether.impl.VersionResolver - default - versionResolver - - - org.sonatype.aether.impl.UpdateCheckManager - default - updateCheckManager - - - org.sonatype.aether.impl.RemoteRepositoryManager - default - remoteRepositoryManager - - - org.sonatype.aether.impl.SyncContextFactory - default - syncContextFactory - - - - org.eclipse.aether.RepositoryListener default @@ -424,44 +301,6 @@ - - org.sonatype.aether.RepositoryListener - default - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeRepositoryListener - - - - org.codehaus.plexus.logging.Logger - default - logger - - - org.jfrog.build.extractor.maven.resolver.ResolutionHelper - default - resolutionHelper - - - org.sonatype.aether.impl.ArtifactDescriptorReader - default - descriptorReader - - - org.sonatype.aether.RepositorySystem - default - repositorySystem - - - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeArtifactResolver - default - artifactoryArtifactResolver - - - org.jfrog.build.extractor.maven.resolver.ArtifactorySonatypeMetadataResolver - default - artifactoryMetadataResolver - - - org.apache.maven.AbstractMavenLifecycleParticipant org.jfrog.build.extractor.maven.BuildInfoRecorderLifecycleParticipant diff --git a/build.gradle b/build.gradle index 08e3a4791..773af5669 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,6 @@ buildscript { publishPluginVersion = '1.1.0' slf4jVersion = '1.7.36' - sonatypeAetherVersion = '1.13.1' // 7.6+ require Java 11 testNgVersion = '6.14.3' @@ -432,9 +431,6 @@ project('build-info-extractor-maven3') { implementation "org.jdom:jdom2:$jdomVersion", "org.codehaus.groovy:groovy-all:$groovyAllVersion", "org.codehaus.plexus:plexus-container-default:$plexusContainerVersion", - "org.sonatype.aether:aether-api:$sonatypeAetherVersion", - "org.sonatype.aether:aether-util:$sonatypeAetherVersion", - "org.sonatype.aether:aether-impl:$sonatypeAetherVersion", "org.eclipse.aether:aether-api:$eclipseAetherVersion", "org.eclipse.aether:aether-util:$eclipseAetherVersion", "org.eclipse.aether:aether-impl:$eclipseAetherVersion",