From c3c6da2620436649340b31e0c42b011343d5dfca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 27 Dec 2024 09:49:29 +0100 Subject: [PATCH] Prepare for using new Transport#downloadArtifact P2 has a new way to download an actual P2 artifact by passing the IArtifactDescriptor to the transport so it can use additional information for caching. This simply prepares the TychoRepositoryTransport for usages by overriding the new method and delegate calls from the old one. --- .../transport/TychoRepositoryTransport.java | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java index 4ae1b71f67..b09f5a991d 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/transport/TychoRepositoryTransport.java @@ -43,6 +43,7 @@ import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; @Component(role = org.eclipse.equinox.internal.p2.repository.Transport.class, hint = "tycho") public class TychoRepositoryTransport extends org.eclipse.equinox.internal.p2.repository.Transport @@ -85,46 +86,32 @@ public TychoRepositoryTransport() { } @Override - public IStatus download(URI toDownload, OutputStream target, long startPos, IProgressMonitor monitor) { - if (startPos > 0) { - return Status.error("range downloads are not implemented"); - } - return download(toDownload, target, monitor); - } - - @Override - public IStatus download(URI toDownload, OutputStream target, IProgressMonitor monitor) { + public IStatus downloadArtifact(URI source, OutputStream target, IArtifactDescriptor descriptor, + IProgressMonitor monitor) { String id = "p2"; // TODO we might compute the id from the IRepositoryIdManager based on the URI? if (cacheConfig.isInteractive()) { - logger.info("Downloading from " + id + ": " + toDownload); + logger.info("Downloading from " + id + ": " + source); } try { DownloadStatusOutputStream statusOutputStream = new DownloadStatusOutputStream(target, - "Download of " + toDownload); - stream(toDownload, monitor).transferTo(statusOutputStream); + "Download of " + source); + stream(source, monitor).transferTo(statusOutputStream); DownloadStatus downloadStatus = statusOutputStream.getStatus(); if (cacheConfig.isInteractive()) { - logger.info("Downloaded from " + id + ": " + toDownload + " (" + logger.info("Downloaded from " + id + ": " + source + " (" + FileUtils.byteCountToDisplaySize(downloadStatus.getFileSize()) + " at " + FileUtils.byteCountToDisplaySize(downloadStatus.getTransferRate()) + "/s)"); } return reportStatus(downloadStatus, target); } catch (AuthenticationFailedException e) { - return Status.error("authentication failed for " + toDownload, e); + return Status.error("authentication failed for " + source, e); } catch (IOException e) { - return reportStatus(Status.error("download from " + toDownload + " failed", e), target); + return reportStatus(Status.error("download from " + source + " failed", e), target); } catch (CoreException e) { return reportStatus(e.getStatus(), target); } } - private IStatus reportStatus(IStatus status, OutputStream target) { - if (target instanceof IStateful stateful) { - stateful.setStatus(status); - } - return status; - } - @Override public InputStream stream(URI toDownload, IProgressMonitor monitor) throws FileNotFoundException, CoreException, AuthenticationFailedException { @@ -168,6 +155,19 @@ public InputStream stream(URI toDownload, IProgressMonitor monitor) } } + @Override + public IStatus download(URI toDownload, OutputStream target, IProgressMonitor monitor) { + return downloadArtifact(toDownload, target, null, monitor); + } + + @Override + public IStatus download(URI toDownload, OutputStream target, long startPos, IProgressMonitor monitor) { + if (startPos > 0) { + return Status.error("range downloads are not implemented"); + } + return downloadArtifact(toDownload, target, null, monitor); + } + TransportProtocolHandler getHandler(URI uri) { String scheme = uri.getScheme(); if (scheme != null) { @@ -230,4 +230,11 @@ TransportCacheConfig getCacheConfig() { return cacheConfig; } + private static IStatus reportStatus(IStatus status, OutputStream target) { + if (target instanceof IStateful stateful) { + stateful.setStatus(status); + } + return status; + } + }