Skip to content
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 @@ -54,13 +54,13 @@
import org.eclipse.aether.spi.connector.transport.Transporter;
import org.eclipse.aether.spi.connector.transport.TransporterProvider;
import org.eclipse.aether.spi.io.ChecksumProcessor;
import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.transfer.ChecksumFailureException;
import org.eclipse.aether.transfer.NoRepositoryConnectorException;
import org.eclipse.aether.transfer.NoRepositoryLayoutException;
import org.eclipse.aether.transfer.TransferEvent;
import org.eclipse.aether.transfer.TransferResource;
import org.eclipse.aether.util.ConfigUtils;
import org.eclipse.aether.util.FileUtils;
import org.eclipse.aether.util.concurrency.RunnableErrorForwarder;
import org.eclipse.aether.util.concurrency.SmartExecutor;
import org.eclipse.aether.util.concurrency.SmartExecutorUtils;
Expand All @@ -87,6 +87,8 @@ final class BasicRepositoryConnector implements RepositoryConnector {

private final Map<String, ProvidedChecksumsSource> providedChecksumsSources;

private final PathProcessor pathProcessor;

private final ChecksumProcessor checksumProcessor;

private final RemoteRepository repository;
Expand All @@ -113,12 +115,14 @@ final class BasicRepositoryConnector implements RepositoryConnector {

private final AtomicBoolean closed;

@SuppressWarnings("checkstyle:parameternumber")
BasicRepositoryConnector(
RepositorySystemSession session,
RemoteRepository repository,
TransporterProvider transporterProvider,
RepositoryLayoutProvider layoutProvider,
ChecksumPolicyProvider checksumPolicyProvider,
PathProcessor pathProcessor,
ChecksumProcessor checksumProcessor,
Map<String, ProvidedChecksumsSource> providedChecksumsSources)
throws NoRepositoryConnectorException {
Expand All @@ -140,6 +144,7 @@ final class BasicRepositoryConnector implements RepositoryConnector {
this.session = session;
this.repository = repository;
this.checksumProcessor = checksumProcessor;
this.pathProcessor = pathProcessor;
this.providedChecksumsSources = providedChecksumsSources;
this.executors = new ConcurrentHashMap<>();
this.closed = new AtomicBoolean(false);
Expand Down Expand Up @@ -496,6 +501,7 @@ class GetTaskRunner extends TaskRunner implements ChecksumValidator.ChecksumFetc
checksumValidator = new ChecksumValidator(
file,
checksumAlgorithmFactories,
pathProcessor,
checksumProcessor,
this,
checksumPolicy,
Expand All @@ -518,7 +524,7 @@ public boolean fetchChecksum(URI remote, Path local) throws Exception {

@Override
protected void runTask() throws Exception {
try (FileUtils.CollocatedTempFile tempFile = FileUtils.newTempFile(file)) {
try (PathProcessor.CollocatedTempFile tempFile = pathProcessor.newTempFile(file)) {
final Path tmp = tempFile.getPath();
listener.setChecksumCalculator(checksumValidator.newChecksumCalculator(tmp));
for (int firstTrial = 0, lastTrial = 1, trial = firstTrial; ; trial++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider;
import org.eclipse.aether.spi.connector.transport.TransporterProvider;
import org.eclipse.aether.spi.io.ChecksumProcessor;
import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.transfer.NoRepositoryConnectorException;

import static java.util.Objects.requireNonNull;
Expand All @@ -50,6 +51,8 @@ public final class BasicRepositoryConnectorFactory implements RepositoryConnecto

private final ChecksumPolicyProvider checksumPolicyProvider;

private final PathProcessor pathProcessor;

private final ChecksumProcessor checksumProcessor;

private final Map<String, ProvidedChecksumsSource> providedChecksumsSources;
Expand All @@ -61,11 +64,13 @@ public BasicRepositoryConnectorFactory(
TransporterProvider transporterProvider,
RepositoryLayoutProvider layoutProvider,
ChecksumPolicyProvider checksumPolicyProvider,
PathProcessor pathProcessor,
ChecksumProcessor checksumProcessor,
Map<String, ProvidedChecksumsSource> providedChecksumsSources) {
this.transporterProvider = requireNonNull(transporterProvider, "transporter provider cannot be null");
this.layoutProvider = requireNonNull(layoutProvider, "repository layout provider cannot be null");
this.checksumPolicyProvider = requireNonNull(checksumPolicyProvider, "checksum policy provider cannot be null");
this.pathProcessor = requireNonNull(pathProcessor, "path processor cannot be null");
this.checksumProcessor = requireNonNull(checksumProcessor, "checksum processor cannot be null");
this.providedChecksumsSources =
requireNonNull(providedChecksumsSources, "provided checksum sources cannot be null");
Expand Down Expand Up @@ -99,6 +104,7 @@ public RepositoryConnector newInstance(RepositorySystemSession session, RemoteRe
transporterProvider,
layoutProvider,
checksumPolicyProvider,
pathProcessor,
checksumProcessor,
providedChecksumsSources);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.eclipse.aether.spi.connector.checksum.ChecksumPolicy.ChecksumKind;
import org.eclipse.aether.spi.connector.layout.RepositoryLayout.ChecksumLocation;
import org.eclipse.aether.spi.io.ChecksumProcessor;
import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.transfer.ChecksumFailureException;
import org.eclipse.aether.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -56,6 +56,8 @@ interface ChecksumFetcher {

private final Collection<ChecksumAlgorithmFactory> checksumAlgorithmFactories;

private final PathProcessor pathProcessor;

private final ChecksumProcessor checksumProcessor;

private final ChecksumFetcher checksumFetcher;
Expand All @@ -68,16 +70,19 @@ interface ChecksumFetcher {

private final Map<Path, String> checksumExpectedValues;

@SuppressWarnings("checkstyle:parameternumber")
ChecksumValidator(
Path dataPath,
Collection<ChecksumAlgorithmFactory> checksumAlgorithmFactories,
PathProcessor pathProcessor,
ChecksumProcessor checksumProcessor,
ChecksumFetcher checksumFetcher,
ChecksumPolicy checksumPolicy,
Map<String, String> providedChecksums,
Collection<ChecksumLocation> checksumLocations) {
this.dataPath = dataPath;
this.checksumAlgorithmFactories = checksumAlgorithmFactories;
this.pathProcessor = pathProcessor;
this.checksumProcessor = checksumProcessor;
this.checksumFetcher = checksumFetcher;
this.checksumPolicy = checksumPolicy;
Expand Down Expand Up @@ -156,7 +161,7 @@ private boolean validateExternalChecksums(Map<String, ?> actualChecksums) throws
continue;
}
Path checksumFile = getChecksumPath(checksumLocation.getChecksumAlgorithmFactory());
try (FileUtils.TempFile tempFile = FileUtils.newTempFile()) {
try (PathProcessor.TempFile tempFile = pathProcessor.newTempFile()) {
Path tmp = tempFile.getPath();
try {
if (!checksumFetcher.fetchChecksum(checksumLocation.getLocation(), tmp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.aether.spi.connector.checksum.ChecksumPolicy;
import org.eclipse.aether.spi.connector.checksum.ChecksumPolicy.ChecksumKind;
import org.eclipse.aether.spi.connector.layout.RepositoryLayout;
import org.eclipse.aether.spi.io.PathProcessorSupport;
import org.eclipse.aether.transfer.ChecksumFailureException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -189,6 +190,7 @@ private ChecksumValidator newValidator(Map<String, String> providedChecksums, St
return new ChecksumValidator(
dataFile.toPath(),
checksumAlgorithmFactories,
new PathProcessorSupport(),
new TestChecksumProcessor(),
fetcher,
policy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.generator.sigstore.internal.FulcioOidHelper;
import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator;
import org.eclipse.aether.util.FileUtils;
import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.util.artifact.SubArtifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class SigstoreSignatureArtifactGenerator implements ArtifactGenerator {
private static final String ARTIFACT_EXTENSION = ".sigstore.json";
private final Logger logger = LoggerFactory.getLogger(getClass());
private final PathProcessor pathProcessor;
private final ArrayList<Artifact> artifacts;
private final Predicate<Artifact> signableArtifactPredicate;
private final boolean publicStaging;
private final ArrayList<Path> signatureTempFiles;

SigstoreSignatureArtifactGenerator(
Collection<Artifact> artifacts, Predicate<Artifact> signableArtifactPredicate, boolean publicStaging) {
PathProcessor pathProcessor,
Collection<Artifact> artifacts,
Predicate<Artifact> signableArtifactPredicate,
boolean publicStaging) {
this.pathProcessor = pathProcessor;
this.artifacts = new ArrayList<>(artifacts);
this.signableArtifactPredicate = signableArtifactPredicate;
this.publicStaging = publicStaging;
Expand Down Expand Up @@ -107,7 +112,7 @@ public Collection<? extends Artifact> generate(Collection<? extends Artifact> ge
+ FulcioOidHelper.getIssuerV2(cert)
+ " IdP)");

FileUtils.writeFile(signatureTempFile, p -> Files.writeString(p, bundle.toJson()));
pathProcessor.write(signatureTempFile, bundle.toJson());

long duration = System.currentTimeMillis() - start;
logger.debug(" > Rekor entry "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.aether.spi.artifact.ArtifactPredicateFactory;
import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator;
import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory;
import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.util.ConfigUtils;

@Singleton
Expand All @@ -40,10 +41,13 @@ public final class SigstoreSignatureArtifactGeneratorFactory implements Artifact
public static final String NAME = "sigstore";

private final ArtifactPredicateFactory artifactPredicateFactory;
private final PathProcessor pathProcessor;

@Inject
public SigstoreSignatureArtifactGeneratorFactory(ArtifactPredicateFactory artifactPredicateFactory) {
public SigstoreSignatureArtifactGeneratorFactory(
ArtifactPredicateFactory artifactPredicateFactory, PathProcessor pathProcessor) {
this.artifactPredicateFactory = artifactPredicateFactory;
this.pathProcessor = pathProcessor;
}

@Override
Expand All @@ -68,7 +72,7 @@ private ArtifactGenerator newInstance(RepositorySystemSession session, Collectio
SigstoreConfigurationKeys.CONFIG_PROP_PUBLIC_STAGING);

return new SigstoreSignatureArtifactGenerator(
artifacts, artifactPredicateFactory.newInstance(session)::hasChecksums, publicStaging);
pathProcessor, artifacts, artifactPredicateFactory.newInstance(session)::hasChecksums, publicStaging);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.aether.spi.artifact.ArtifactPredicate;
import org.eclipse.aether.spi.artifact.ArtifactPredicateFactory;
import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator;
import org.eclipse.aether.spi.io.PathProcessorSupport;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand All @@ -57,7 +58,7 @@ private SigstoreSignatureArtifactGeneratorFactory createFactory() throws Excepti
when(artifactPredicateFactory.newInstance(any(RepositorySystemSession.class)))
.thenReturn(artifactPredicate);

return new SigstoreSignatureArtifactGeneratorFactory(artifactPredicateFactory);
return new SigstoreSignatureArtifactGeneratorFactory(artifactPredicateFactory, new PathProcessorSupport());
}

private RepositorySystemSession createSession() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,95 +21,11 @@
import javax.inject.Named;
import javax.inject.Singleton;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.AccessDeniedException;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime;

import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.aether.spi.io.PathProcessorSupport;

/**
* A utility class helping with file-based operations.
* Exposing path processor (from SPI).
*/
@Singleton
@Named
public class DefaultPathProcessor implements PathProcessor {
private final Logger logger = LoggerFactory.getLogger(getClass());

@Override
public void setLastModified(Path path, long value) throws IOException {
try {
Files.setLastModifiedTime(path, FileTime.fromMillis(value));
} catch (FileSystemException e) {
// MRESOLVER-536: Java uses generic FileSystemException for some weird cases,
// but some subclasses like AccessDeniedEx should be re-thrown
if (e instanceof AccessDeniedException) {
throw e;
}
logger.trace("Failed to set last modified date: {}", path, e);
}
}

@Override
public void write(Path target, String data) throws IOException {
FileUtils.writeFile(target, p -> Files.write(p, data.getBytes(StandardCharsets.UTF_8)));
}

@Override
public void write(Path target, InputStream source) throws IOException {
FileUtils.writeFile(target, p -> Files.copy(source, p, StandardCopyOption.REPLACE_EXISTING));
}

@Override
public long copy(Path source, Path target, ProgressListener listener) throws IOException {
try (InputStream in = new BufferedInputStream(Files.newInputStream(source));
FileUtils.CollocatedTempFile tempTarget = FileUtils.newTempFile(target);
OutputStream out = new BufferedOutputStream(Files.newOutputStream(tempTarget.getPath()))) {
long result = copy(out, in, listener);
tempTarget.move();
return result;
}
}

private long copy(OutputStream os, InputStream is, ProgressListener listener) throws IOException {
long total = 0L;
byte[] buffer = new byte[1024 * 32];
while (true) {
int bytes = is.read(buffer);
if (bytes < 0) {
break;
}

os.write(buffer, 0, bytes);

total += bytes;

if (listener != null && bytes > 0) {
try {
listener.progressed(ByteBuffer.wrap(buffer, 0, bytes));
} catch (Exception e) {
// too bad
}
}
}

return total;
}

@Override
public void move(Path source, Path target) throws IOException {
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
}
}
public class DefaultPathProcessor extends PathProcessorSupport {}
Loading