Skip to content

Commit

Permalink
[MRESOLVER-338] Drop FileTransform API (#337)
Browse files Browse the repository at this point in the history
To streamline logic all way down to transport and remove OOM prone code.

Note: japicmp config was added, as we did a mistake, we deprecated types, but not related methods, so without these japicm would fail the build due breakages.

---

https://issues.apache.org/jira/browse/MRESOLVER-338
  • Loading branch information
cstamas authored Oct 14, 2023
1 parent 6bc4c21 commit c6b8a72
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.aether.resolution.ArtifactDescriptorPolicy;
import org.eclipse.aether.resolution.ResolutionErrorPolicy;
import org.eclipse.aether.transfer.TransferListener;
import org.eclipse.aether.transform.FileTransformerManager;

/**
* A special repository system session to enable decorating or proxying another session. To do so, clients have to
Expand Down Expand Up @@ -186,9 +185,4 @@ public SessionData getData() {
public RepositoryCache getCache() {
return getSession().getCache();
}

@Override
public FileTransformerManager getFileTransformerManager() {
return getSession().getFileTransformerManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
*/
package org.eclipse.aether;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.ArtifactType;
import org.eclipse.aether.artifact.ArtifactTypeRegistry;
import org.eclipse.aether.collection.DependencyGraphTransformer;
Expand All @@ -44,8 +42,6 @@
import org.eclipse.aether.resolution.ArtifactDescriptorPolicy;
import org.eclipse.aether.resolution.ResolutionErrorPolicy;
import org.eclipse.aether.transfer.TransferListener;
import org.eclipse.aether.transform.FileTransformer;
import org.eclipse.aether.transform.FileTransformerManager;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -77,8 +73,6 @@ public final class DefaultRepositorySystemSession implements RepositorySystemSes

private LocalRepositoryManager localRepositoryManager;

private FileTransformerManager fileTransformerManager;

private WorkspaceReader workspaceReader;

private RepositoryListener repositoryListener;
Expand Down Expand Up @@ -135,7 +129,6 @@ public DefaultRepositorySystemSession() {
proxySelector = NullProxySelector.INSTANCE;
authenticationSelector = NullAuthenticationSelector.INSTANCE;
artifactTypeRegistry = NullArtifactTypeRegistry.INSTANCE;
fileTransformerManager = NullFileTransformerManager.INSTANCE;
data = new DefaultSessionData();
}

Expand Down Expand Up @@ -173,7 +166,6 @@ public DefaultRepositorySystemSession(RepositorySystemSession session) {
setDependencySelector(session.getDependencySelector());
setVersionFilter(session.getVersionFilter());
setDependencyGraphTransformer(session.getDependencyGraphTransformer());
setFileTransformerManager(session.getFileTransformerManager());
setData(session.getData());
setCache(session.getCache());
}
Expand Down Expand Up @@ -341,20 +333,6 @@ public DefaultRepositorySystemSession setLocalRepositoryManager(LocalRepositoryM
return this;
}

@Override
public FileTransformerManager getFileTransformerManager() {
return fileTransformerManager;
}

public DefaultRepositorySystemSession setFileTransformerManager(FileTransformerManager fileTransformerManager) {
verifyStateForMutation();
this.fileTransformerManager = fileTransformerManager;
if (this.fileTransformerManager == null) {
this.fileTransformerManager = NullFileTransformerManager.INSTANCE;
}
return this;
}

@Override
public WorkspaceReader getWorkspaceReader() {
return workspaceReader;
Expand Down Expand Up @@ -814,13 +792,4 @@ public ArtifactType get(String typeId) {
return null;
}
}

static final class NullFileTransformerManager implements FileTransformerManager {
public static final FileTransformerManager INSTANCE = new NullFileTransformerManager();

@Override
public Collection<FileTransformer> getTransformersForArtifact(Artifact artifact) {
return Collections.emptyList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eclipse.aether.resolution.ArtifactDescriptorPolicy;
import org.eclipse.aether.resolution.ResolutionErrorPolicy;
import org.eclipse.aether.transfer.TransferListener;
import org.eclipse.aether.transform.FileTransformerManager;

/**
* Defines settings and components that control the repository system. Once initialized, the session object itself is
Expand Down Expand Up @@ -270,14 +269,4 @@ public interface RepositorySystemSession {
* @return The repository cache or {@code null} if none.
*/
RepositoryCache getCache();

/**
* Get the file transformer manager
*
* @return the manager, never {@code null}
* @deprecated Without any direct replacement for now. This API is OOM-prone, and also lacks a lot of context about
* transforming.
*/
@Deprecated
FileTransformerManager getFileTransformerManager();
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
*/
package org.eclipse.aether.connector.basic;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -61,7 +59,6 @@
import org.eclipse.aether.transfer.NoTransporterException;
import org.eclipse.aether.transfer.TransferEvent;
import org.eclipse.aether.transfer.TransferResource;
import org.eclipse.aether.transform.FileTransformer;
import org.eclipse.aether.util.ConfigUtils;
import org.eclipse.aether.util.FileUtils;
import org.eclipse.aether.util.concurrency.ExecutorUtils;
Expand Down Expand Up @@ -291,8 +288,7 @@ public void put(
List<RepositoryLayout.ChecksumLocation> checksumLocations =
layout.getChecksumLocations(transfer.getArtifact(), true, location);

Runnable task = new PutTaskRunner(
location, transfer.getFile(), transfer.getFileTransformer(), checksumLocations, listener);
Runnable task = new PutTaskRunner(location, transfer.getFile(), checksumLocations, listener);
if (first) {
task.run();
first = false;
Expand Down Expand Up @@ -509,61 +505,23 @@ class PutTaskRunner extends TaskRunner {

private final File file;

private final FileTransformer fileTransformer;

private final Collection<RepositoryLayout.ChecksumLocation> checksumLocations;

PutTaskRunner(
URI path,
File file,
List<RepositoryLayout.ChecksumLocation> checksumLocations,
TransferTransportListener<?> listener) {
this(path, file, null, checksumLocations, listener);
}

/**
* <strong>IMPORTANT</strong> When using a fileTransformer, the content of the file is stored in memory to
* ensure that file content and checksums stay in sync!
*
* @param path
* @param file
* @param fileTransformer
* @param checksumLocations
* @param listener
*/
PutTaskRunner(
URI path,
File file,
FileTransformer fileTransformer,
List<RepositoryLayout.ChecksumLocation> checksumLocations,
TransferTransportListener<?> listener) {
super(path, listener);
this.file = requireNonNull(file, "source file cannot be null");
this.fileTransformer = fileTransformer;
this.checksumLocations = safe(checksumLocations);
}

@SuppressWarnings("checkstyle:innerassignment")
@Override
protected void runTask() throws Exception {
if (fileTransformer != null) {
// transform data once to byte array, ensure constant data for checksum
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];

try (InputStream transformData = fileTransformer.transformData(file)) {
for (int read; (read = transformData.read(buffer, 0, buffer.length)) != -1; ) {
baos.write(buffer, 0, read);
}
}

byte[] bytes = baos.toByteArray();
transporter.put(new PutTask(path).setDataBytes(bytes).setListener(listener));
uploadChecksums(file, bytes);
} else {
transporter.put(new PutTask(path).setDataFile(file).setListener(listener));
uploadChecksums(file, null);
}
transporter.put(new PutTask(path).setDataFile(file).setListener(listener));
uploadChecksums(file, null);
}

/**
Expand Down
Loading

0 comments on commit c6b8a72

Please sign in to comment.