Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRESOLVER-644] Artifact Transformer SPI #605

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator;
import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory;
import org.eclipse.aether.spi.artifact.transformer.ArtifactTransformer;
import org.eclipse.aether.spi.connector.ArtifactUpload;
import org.eclipse.aether.spi.connector.MetadataDownload;
import org.eclipse.aether.spi.connector.MetadataUpload;
Expand Down Expand Up @@ -99,6 +100,8 @@ public class DefaultDeployer implements Deployer {

private final Map<String, MetadataGeneratorFactory> metadataFactories;

private final Map<String, ArtifactTransformer> artifactTransformers;

private final SyncContextFactory syncContextFactory;

private final OfflineController offlineController;
Expand All @@ -113,6 +116,7 @@ public DefaultDeployer(
UpdateCheckManager updateCheckManager,
Map<String, ArtifactGeneratorFactory> artifactFactories,
Map<String, MetadataGeneratorFactory> metadataFactories,
Map<String, ArtifactTransformer> artifactTransformers,
SyncContextFactory syncContextFactory,
OfflineController offlineController) {
this.pathProcessor = requireNonNull(pathProcessor, "path processor cannot be null");
Expand All @@ -125,6 +129,7 @@ public DefaultDeployer(
this.updateCheckManager = requireNonNull(updateCheckManager, "update check manager cannot be null");
this.artifactFactories = Collections.unmodifiableMap(artifactFactories);
this.metadataFactories = Collections.unmodifiableMap(metadataFactories);
this.artifactTransformers = Collections.unmodifiableMap(artifactTransformers);
this.syncContextFactory = requireNonNull(syncContextFactory, "sync context factory cannot be null");
this.offlineController = requireNonNull(offlineController, "offline controller cannot be null");
}
Expand All @@ -142,6 +147,9 @@ public DeployResult deploy(RepositorySystemSession session, DeployRequest reques
e);
}

for (ArtifactTransformer transformer : artifactTransformers.values()) {
request = transformer.transformDeployArtifacts(session, request);
}
try (SyncContext syncContext = syncContextFactory.newInstance(session, true)) {
return deploy(syncContext, session, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.eclipse.aether.repository.LocalRepositoryManager;
import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator;
import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory;
import org.eclipse.aether.spi.artifact.transformer.ArtifactTransformer;
import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.spi.synccontext.SyncContextFactory;
import org.slf4j.Logger;
Expand All @@ -74,6 +75,8 @@ public class DefaultInstaller implements Installer {

private final Map<String, MetadataGeneratorFactory> metadataFactories;

private final Map<String, ArtifactTransformer> artifactTransformers;

private final SyncContextFactory syncContextFactory;

@Inject
Expand All @@ -82,19 +85,24 @@ public DefaultInstaller(
RepositoryEventDispatcher repositoryEventDispatcher,
Map<String, ArtifactGeneratorFactory> artifactFactories,
Map<String, MetadataGeneratorFactory> metadataFactories,
Map<String, ArtifactTransformer> artifactTransformers,
SyncContextFactory syncContextFactory) {
this.pathProcessor = requireNonNull(pathProcessor, "path processor cannot be null");
this.repositoryEventDispatcher =
requireNonNull(repositoryEventDispatcher, "repository event dispatcher cannot be null");
this.artifactFactories = Collections.unmodifiableMap(artifactFactories);
this.metadataFactories = Collections.unmodifiableMap(metadataFactories);
this.artifactTransformers = Collections.unmodifiableMap(artifactTransformers);
this.syncContextFactory = requireNonNull(syncContextFactory, "sync context factory cannot be null");
}

@Override
public InstallResult install(RepositorySystemSession session, InstallRequest request) throws InstallationException {
requireNonNull(session, "session cannot be null");
requireNonNull(request, "request cannot be null");
for (ArtifactTransformer transformer : artifactTransformers.values()) {
request = transformer.transformInstallArtifacts(session, request);
}
try (SyncContext syncContext = syncContextFactory.newInstance(session, false)) {
return install(syncContext, session, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void setup() throws IOException {
new StaticUpdateCheckManager(true),
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap(),
new StubSyncContextFactory(),
new DefaultOfflineController());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void setup() throws IOException {
new StubRepositoryEventDispatcher(),
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap(),
new StubSyncContextFactory());
request = new InstallRequest();
listener = new RecordingRepositoryListener();
Expand Down Expand Up @@ -339,6 +340,7 @@ public long copy(Path src, Path target, ProgressListener listener) throws IOExce
new StubRepositoryEventDispatcher(),
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap(),
new StubSyncContextFactory());

request = new InstallRequest();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.eclipse.aether.spi.artifact.transformer;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.installation.InstallRequest;

/**
* Install and deploy artifact transformer. This component can mangle install and deploy requests, replace artifacts,
* add new artifacts and so on.
*
* @since 2.0.5
*/
public interface ArtifactTransformer {
/**
* Transform install artifacts.
*
* @param session never {@code null}
* @param request never {@code null}
* @return the transformed request, never {@code null}
*/
default InstallRequest transformInstallArtifacts(RepositorySystemSession session, InstallRequest request) {
return request;
}

/**
* Transform deploy artifacts.
*
* @param session never {@code null}
* @param request never {@code null}
* @return the transformed request, never {@code null}
*/
default DeployRequest transformDeployArtifacts(RepositorySystemSession session, DeployRequest request) {
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
import org.eclipse.aether.spi.artifact.ArtifactPredicateFactory;
import org.eclipse.aether.spi.artifact.decorator.ArtifactDecoratorFactory;
import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory;
import org.eclipse.aether.spi.artifact.transformer.ArtifactTransformer;
import org.eclipse.aether.spi.checksums.ProvidedChecksumsSource;
import org.eclipse.aether.spi.checksums.TrustedChecksumsSource;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
Expand Down Expand Up @@ -728,6 +729,7 @@ protected Installer createInstaller() {
getRepositoryEventDispatcher(),
getArtifactGeneratorFactories(),
getMetadataGeneratorFactories(),
getArtifactTransformers(),
getSyncContextFactory());
}

Expand All @@ -750,6 +752,7 @@ protected Deployer createDeployer() {
getUpdateCheckManager(),
getArtifactGeneratorFactories(),
getMetadataGeneratorFactories(),
getArtifactTransformers(),
getSyncContextFactory(),
getOfflineController());
}
Expand Down Expand Up @@ -911,6 +914,20 @@ protected Map<String, ArtifactDecoratorFactory> createArtifactDecoratorFactories

// Maven provided

private Map<String, ArtifactTransformer> artifactTransformers;

public final Map<String, ArtifactTransformer> getArtifactTransformers() {
checkClosed();
if (artifactTransformers == null) {
artifactTransformers = createArtifactTransformers();
}
return artifactTransformers;
}

protected Map<String, ArtifactTransformer> createArtifactTransformers() {
return new HashMap<>();
}

private Map<String, MetadataGeneratorFactory> metadataGeneratorFactories;

public final Map<String, MetadataGeneratorFactory> getMetadataGeneratorFactories() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
import org.eclipse.aether.spi.artifact.ArtifactPredicateFactory;
import org.eclipse.aether.spi.artifact.decorator.ArtifactDecoratorFactory;
import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory;
import org.eclipse.aether.spi.artifact.transformer.ArtifactTransformer;
import org.eclipse.aether.spi.checksums.ProvidedChecksumsSource;
import org.eclipse.aether.spi.checksums.TrustedChecksumsSource;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
Expand Down Expand Up @@ -732,6 +733,7 @@ protected Installer createInstaller() {
getRepositoryEventDispatcher(),
getArtifactGeneratorFactories(),
getMetadataGeneratorFactories(),
getArtifactTransformers(),
getSyncContextFactory());
}

Expand All @@ -754,6 +756,7 @@ protected Deployer createDeployer() {
getUpdateCheckManager(),
getArtifactGeneratorFactories(),
getMetadataGeneratorFactories(),
getArtifactTransformers(),
getSyncContextFactory(),
getOfflineController());
}
Expand Down Expand Up @@ -915,6 +918,20 @@ protected Map<String, ArtifactDecoratorFactory> createArtifactDecoratorFactories

// Maven provided

private Map<String, ArtifactTransformer> artifactTransformers;

public final Map<String, ArtifactTransformer> getArtifactTransformers() {
checkClosed();
if (artifactTransformers == null) {
artifactTransformers = createArtifactTransformers();
}
return artifactTransformers;
}

protected Map<String, ArtifactTransformer> createArtifactTransformers() {
return new HashMap<>();
}

private Map<String, MetadataGeneratorFactory> metadataGeneratorFactories;

public final Map<String, MetadataGeneratorFactory> getMetadataGeneratorFactories() {
Expand Down
Loading