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

Prepare for using new Transport#downloadArtifact #4560

Merged
merged 1 commit into from
Dec 27, 2024
Merged
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 @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

}
Loading