forked from eclipse-tycho/tycho
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue eclipse-tycho#797 - add a custom transport based on dumb URL#op…
…enStream() Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
- Loading branch information
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
....p2.resolver.impl/src/main/java/org/eclipse/tycho/p2/remote/TychoRepositoryTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.p2.remote; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.net.URI; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.equinox.internal.p2.repository.AuthenticationFailedException; | ||
import org.eclipse.equinox.p2.core.IProvisioningAgent; | ||
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; | ||
import org.eclipse.tycho.core.shared.MavenContext; | ||
|
||
@SuppressWarnings("restriction") | ||
public class TychoRepositoryTransport extends org.eclipse.equinox.internal.p2.repository.Transport | ||
implements IAgentServiceFactory { | ||
|
||
private MavenContext mavenContext; | ||
|
||
public TychoRepositoryTransport(MavenContext mavenContext) { | ||
this.mavenContext = mavenContext; | ||
File cacheLocation = new File(mavenContext.getLocalRepositoryRoot(), ".cache/tycho/httpcache"); | ||
cacheLocation.mkdirs(); | ||
mavenContext.getLogger().info( | ||
"Using TychoRepositoryTransport for remote P2 access with cache location " + cacheLocation + "..."); | ||
} | ||
|
||
@Override | ||
public IStatus download(URI toDownload, OutputStream target, long startPos, IProgressMonitor monitor) { | ||
if (startPos > 0) { | ||
return new Status(IStatus.ERROR, TychoRepositoryTransport.class.getName(), | ||
"range downloads are not implemented"); | ||
} | ||
return download(toDownload, target, monitor); | ||
} | ||
|
||
@Override | ||
public IStatus download(URI toDownload, OutputStream target, IProgressMonitor monitor) { | ||
try { | ||
IOUtils.copy(stream(toDownload, monitor), target); | ||
return Status.OK_STATUS; | ||
} catch (AuthenticationFailedException e) { | ||
return new Status(IStatus.ERROR, TychoRepositoryTransport.class.getName(), | ||
"authentication failed for " + toDownload, e); | ||
} catch (IOException e) { | ||
return new Status(IStatus.ERROR, TychoRepositoryTransport.class.getName(), | ||
"download from " + toDownload + " failed", e); | ||
} catch (CoreException e) { | ||
return e.getStatus(); | ||
} | ||
} | ||
|
||
@Override | ||
public InputStream stream(URI toDownload, IProgressMonitor monitor) | ||
throws FileNotFoundException, CoreException, AuthenticationFailedException { | ||
mavenContext.getLogger().info("Requested download for " + toDownload + "..."); | ||
try { | ||
return toDownload.toURL().openStream(); | ||
} catch (FileNotFoundException e) { | ||
throw e; | ||
} catch (IOException e) { | ||
throw new CoreException(new Status(IStatus.ERROR, TychoRepositoryTransport.class.getName(), | ||
"download from " + toDownload + " failed", e)); | ||
} | ||
} | ||
|
||
@Override | ||
public long getLastModified(URI toDownload, IProgressMonitor monitor) | ||
throws CoreException, FileNotFoundException, AuthenticationFailedException { | ||
|
||
return System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public Object createService(IProvisioningAgent agent) { | ||
return this; | ||
} | ||
|
||
} |