org.apache.maven.wagon.ResourceDoesNotExistException Java Examples

The following examples show how to use org.apache.maven.wagon.ResourceDoesNotExistException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryModelResolver.java    From archiva with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param wagon The wagon instance that should be connected.
 * @param remoteRepository The repository from where the checksum file should be retrieved
 * @param remotePath The remote path of the artifact (without extension)
 * @param resource The local artifact (without extension)
 * @param workingDir The working directory where the downloaded file should be placed to
 * @param ext The extension of th checksum file
 * @return The file where the data has been downloaded to.
 * @throws AuthorizationException
 * @throws TransferFailedException
 * @throws ResourceDoesNotExistException
 */
private Path transferChecksum( final Wagon wagon, final RemoteRepository remoteRepository,
                               final String remotePath, final Path resource,
                               final Path workingDir, final String ext )
    throws AuthorizationException, TransferFailedException, ResourceDoesNotExistException
{
    Path destFile = workingDir.resolve( resource.getFileName() + ext );
    String remoteChecksumPath = remotePath + ext;

    log.info( "Retrieving {} from {}", remoteChecksumPath, remoteRepository.getName() );

    wagon.get( addParameters( remoteChecksumPath, remoteRepository ), destFile.toFile() );

    log.debug( "Downloaded successfully." );

    return destFile;
}
 
Example #2
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void putResourceDoesNotExistException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    ResourceDoesNotExistException exception = new ResourceDoesNotExistException("");
    doThrow(exception).when(this.wagon).putResource(eq(new File("foo")), eq("bar"), any(TransferProgress.class));

    try {
        this.wagon.put(new File("foo"), "bar");
        fail();
    } catch (ResourceDoesNotExistException e) {
        verify(this.transferListenerSupport).fireTransferInitiated(new Resource("bar"), TransferEvent.REQUEST_PUT);
        verify(this.transferListenerSupport).fireTransferStarted(new Resource("bar"), TransferEvent.REQUEST_PUT);
        verify(this.transferListenerSupport).fireTransferError(new Resource("bar"), TransferEvent.REQUEST_PUT,
                exception);
    }
}
 
Example #3
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void putAuthorizationException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    AuthorizationException exception = new AuthorizationException("");
    doThrow(exception).when(this.wagon).putResource(eq(new File("foo")), eq("bar"), any(TransferProgress.class));

    try {
        this.wagon.put(new File("foo"), "bar");
        fail();
    } catch (AuthorizationException e) {
        verify(this.transferListenerSupport).fireTransferInitiated(new Resource("bar"), TransferEvent.REQUEST_PUT);
        verify(this.transferListenerSupport).fireTransferStarted(new Resource("bar"), TransferEvent.REQUEST_PUT);
        verify(this.transferListenerSupport).fireTransferError(new Resource("bar"), TransferEvent.REQUEST_PUT,
                exception);
    }
}
 
Example #4
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void getAuthorizationException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    AuthorizationException exception = new AuthorizationException("");
    doThrow(exception).when(this.wagon).getResource(eq("foo"), eq(new File("bar")), any(TransferProgress.class));

    try {
        this.wagon.get("foo", new File("bar"));
        fail();
    } catch (AuthorizationException e) {
        verify(this.transferListenerSupport).fireTransferInitiated(new Resource("foo"), TransferEvent.REQUEST_GET);
        verify(this.transferListenerSupport).fireTransferStarted(new Resource("foo"), TransferEvent.REQUEST_GET);
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #5
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void getResourceDoesNotExistException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    ResourceDoesNotExistException exception = new ResourceDoesNotExistException("");
    doThrow(exception).when(this.wagon).getResource(eq("foo"), eq(new File("bar")), any(TransferProgress.class));

    try {
        this.wagon.get("foo", new File("bar"));
        fail();
    } catch (ResourceDoesNotExistException e) {
        verify(this.transferListenerSupport).fireTransferInitiated(new Resource("foo"), TransferEvent.REQUEST_GET);
        verify(this.transferListenerSupport).fireTransferStarted(new Resource("foo"), TransferEvent.REQUEST_GET);
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #6
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void getTransferFailedException() throws ResourceDoesNotExistException, AuthorizationException,
        TransferFailedException {
    TransferFailedException exception = new TransferFailedException("");
    doThrow(exception).when(this.wagon).getResource(eq("foo"), eq(new File("bar")), any(TransferProgress.class));

    try {
        this.wagon.get("foo", new File("bar"));
        fail();
    } catch (TransferFailedException e) {
        verify(this.transferListenerSupport).fireTransferInitiated(new Resource("foo"), TransferEvent.REQUEST_GET);
        verify(this.transferListenerSupport).fireTransferStarted(new Resource("foo"), TransferEvent.REQUEST_GET);
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #7
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void putDirectory() throws IOException, TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    File directory = new File("target/test");
    directory.mkdirs();
    File file = new File(directory, "test.txt");
    file.createNewFile();

    this.wagon.putDirectory(directory, "foo");

    verify(this.transferListenerSupport).fireTransferInitiated(new Resource("foo/test.txt"),
            TransferEvent.REQUEST_PUT);
    verify(this.transferListenerSupport).fireTransferStarted(new Resource("foo/test.txt"),
            TransferEvent.REQUEST_PUT);
    verify(this.wagon).putResource(eq(new File("target/test/test.txt")), eq("foo/test.txt"),
            any(TransferProgress.class));
    verify(this.transferListenerSupport).fireTransferCompleted(new Resource("foo/test.txt"),
            TransferEvent.REQUEST_PUT);
}
 
Example #8
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void putTransferFailedException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    TransferFailedException exception = new TransferFailedException("");
    doThrow(exception).when(this.wagon).putResource(eq(new File("foo")), eq("bar"), any(TransferProgress.class));

    try {
        this.wagon.put(new File("foo"), "bar");
        fail();
    } catch (TransferFailedException e) {
        verify(this.transferListenerSupport).fireTransferInitiated(new Resource("bar"), TransferEvent.REQUEST_PUT);
        verify(this.transferListenerSupport).fireTransferStarted(new Resource("bar"), TransferEvent.REQUEST_PUT);
        verify(this.transferListenerSupport).fireTransferError(new Resource("bar"), TransferEvent.REQUEST_PUT,
                exception);
    }
}
 
Example #9
Source File: MockWagon.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public void get( String s, File file )
    throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
    String sourceFile = getBasedir() + "/src/test/resources/" + s;

    try
    {
        FileUtils.copyFile( new File( sourceFile ), file );
        assert( file.exists() );
    }
    catch( IOException e )
    {
        throw new ResourceDoesNotExistException( e.getMessage() );            
    }
}
 
Example #10
Source File: GitWagon.java    From opoopress with Apache License 2.0 6 votes vote down vote up
@Override
public void get(String resourceName, File destination)
		throws TransferFailedException, ResourceDoesNotExistException,
		AuthorizationException {
	Resource resource = new Resource(resourceName);
	fireGetInitiated(resource, destination);
	fireGetStarted(resource, destination);

	try {
		File remote = new File(checkoutDirectory, resourceName);
		if (remote.exists()){
			transfer(resource, new FileInputStream(remote), new FileOutputStream(destination), TransferEvent.REQUEST_GET);
		}
	} catch (Exception e) {
		fireTransferError(resource, e, TransferEvent.REQUEST_GET);
		throw new TransferFailedException("Unable to get file", e);
	}

	fireGetCompleted(resource, destination);
}
 
Example #11
Source File: AbstractWagon.java    From lambadaframework with MIT License 6 votes vote down vote up
@Override
public final void put(File source, String destination) throws TransferFailedException,
        ResourceDoesNotExistException, AuthorizationException {
    Resource resource = new Resource(destination);
    this.transferListenerSupport.fireTransferInitiated(resource, TransferEvent.REQUEST_PUT);
    this.transferListenerSupport.fireTransferStarted(resource, TransferEvent.REQUEST_PUT);

    try {
        putResource(source, destination, new StandardTransferProgress(resource, TransferEvent.REQUEST_PUT,
                this.transferListenerSupport));
        this.transferListenerSupport.fireTransferCompleted(resource, TransferEvent.REQUEST_PUT);
    } catch (TransferFailedException | ResourceDoesNotExistException | AuthorizationException e) {
        this.transferListenerSupport.fireTransferError(resource, TransferEvent.REQUEST_PUT, e);
        throw e;
    }
}
 
Example #12
Source File: AbstractWagon.java    From lambadaframework with MIT License 6 votes vote down vote up
@Override
public final boolean getIfNewer(String resourceName, File destination, long timestamp)
        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    Resource resource = new Resource(resourceName);
    try {
        if (isRemoteResourceNewer(resourceName, timestamp)) {
            get(resourceName, destination);
            return true;
        }

        return false;
    } catch (TransferFailedException | ResourceDoesNotExistException | AuthorizationException e) {
        this.transferListenerSupport.fireTransferError(resource, TransferEvent.REQUEST_GET, e);
        throw e;
    }
}
 
Example #13
Source File: AbstractWagon.java    From lambadaframework with MIT License 6 votes vote down vote up
@Override
public final void get(String resourceName, File destination) throws TransferFailedException,
        ResourceDoesNotExistException, AuthorizationException {
    Resource resource = new Resource(resourceName);
    this.transferListenerSupport.fireTransferInitiated(resource, TransferEvent.REQUEST_GET);
    this.transferListenerSupport.fireTransferStarted(resource, TransferEvent.REQUEST_GET);

    try {
        getResource(resourceName, destination, new StandardTransferProgress(resource, TransferEvent.REQUEST_GET,
                this.transferListenerSupport));
        this.transferListenerSupport.fireTransferCompleted(resource, TransferEvent.REQUEST_GET);
    } catch (TransferFailedException | ResourceDoesNotExistException | AuthorizationException e) {
        this.transferListenerSupport.fireTransferError(resource, TransferEvent.REQUEST_GET, e);
        throw e;
    }
}
 
Example #14
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void getIfNewerResourceDoesNotExistException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    ResourceDoesNotExistException exception = new ResourceDoesNotExistException("");
    when(this.wagon.isRemoteResourceNewer("foo", 0)).thenThrow(exception);

    try {
        this.wagon.getIfNewer("foo", new File("bar"), 0);
        fail();
    } catch (ResourceDoesNotExistException e) {
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #15
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void put() throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    this.wagon.put(new File("foo"), "bar");

    verify(this.transferListenerSupport).fireTransferInitiated(new Resource("bar"), TransferEvent.REQUEST_PUT);
    verify(this.transferListenerSupport).fireTransferStarted(new Resource("bar"), TransferEvent.REQUEST_PUT);
    verify(this.wagon).putResource(eq(new File("foo")), eq("bar"), any(TransferProgress.class));
    verify(this.transferListenerSupport).fireTransferCompleted(new Resource("bar"), TransferEvent.REQUEST_PUT);
}
 
Example #16
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void getIfNewerAuthorizationException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    AuthorizationException exception = new AuthorizationException("");
    when(this.wagon.isRemoteResourceNewer("foo", 0)).thenThrow(exception);

    try {
        this.wagon.getIfNewer("foo", new File("bar"), 0);
        fail();
    } catch (AuthorizationException e) {
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #17
Source File: SimpleStorageServiceWagon.java    From lambadaframework with MIT License 5 votes vote down vote up
@Override
protected List<String> listDirectory(String directory) throws ResourceDoesNotExistException {
    List<String> directoryContents = new ArrayList<>();

    try {
        String prefix = getKey(directory);
        Pattern pattern = Pattern.compile(String.format(RESOURCE_FORMAT, prefix));

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest() //
                .withBucketName(this.bucketName) //
                .withPrefix(prefix) //
                .withDelimiter("/");

        ObjectListing objectListing;

        objectListing = this.amazonS3.listObjects(listObjectsRequest);
        directoryContents.addAll(getResourceNames(objectListing, pattern));

        while (objectListing.isTruncated()) {
            objectListing = this.amazonS3.listObjects(listObjectsRequest);
            directoryContents.addAll(getResourceNames(objectListing, pattern));
        }

        return directoryContents;
    } catch (AmazonServiceException e) {
        throw new ResourceDoesNotExistException(String.format("'%s' does not exist", directory), e);
    }
}
 
Example #18
Source File: DefaultVersionsHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Deprecated
private static RuleSet getRuleSet( Wagon wagon, String remoteURI )
    throws IOException, AuthorizationException, TransferFailedException, ResourceDoesNotExistException
{
    File tempFile = File.createTempFile( "ruleset", ".xml" );
    try
    {
        wagon.get( remoteURI, tempFile );
        InputStream is = new FileInputStream(tempFile );
        try
        {
            return readRulesFromStream(is);
        }
        finally
        {
            try
            {
                is.close();
            }
            catch ( IOException e )
            {
                // ignore
            }
        }
    }
    finally
    {
        if ( !tempFile.delete() )
        {
            // maybe we can delete this later
            tempFile.deleteOnExit();
        }
    }
}
 
Example #19
Source File: ManagedDefaultTransferTest.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetInSecondProxiedRepoFirstFails()
    throws Exception
{
    String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
    setupTestableManagedRepository( path );

    Path expectedFile = managedDefaultDir.resolve(path);

    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );

    Artifact artifact = layout.getArtifact( path );

    assertNotExistsInManagedDefaultRepo( expectedFile );

    // Configure Repository (usually done within archiva.xml configuration)
    saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "" +
        "http://bad.machine.com/repo/", "default" );

    wagonMock.get( EasyMock.eq( path), EasyMock.anyObject( File.class ) );
    EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "transfer failed" )  );
    wagonMockControl.replay();

    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector( ID_DEFAULT_MANAGED, "badproxied", false );
    saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );

    // Attempt the proxy fetch.
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );

    wagonMockControl.verify();

    Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
    assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File );
    assertNoTempFiles( expectedFile );
}
 
Example #20
Source File: WagonDelegate.java    From archiva with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings ("unchecked")
@Override
public List<String> getFileList( String destinationDirectory )
    throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
    return delegate.getFileList( destinationDirectory );
}
 
Example #21
Source File: WagonDelegate.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void get( String resourceName, File destination )
    throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
    log.debug( ".get({}, {})", resourceName, destination );
    delegate.get( resourceName, destination );
    create( destination.toPath() );
}
 
Example #22
Source File: WagonDelegate.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getIfNewer( String resourceName, File destination, long timestamp )
    throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
    log.info( ".getIfNewer({}, {}, {})", resourceName, destination, timestamp );

    boolean result = delegate.getIfNewer( resourceName, destination, timestamp );
    createIfMissing( destination.toPath() );
    return result;
}
 
Example #23
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void getIfNewerNewer() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    when(this.wagon.isRemoteResourceNewer("foo", 0)).thenReturn(true);

    assertTrue(this.wagon.getIfNewer("foo", new File("bar"), 0));
    verify(this.wagon).getResource(eq("foo"), eq(new File("bar")), any(TransferProgress.class));
}
 
Example #24
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void getFileListAuthorizationException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    AuthorizationException exception = new AuthorizationException("");
    when(this.wagon.listDirectory("foo")).thenThrow(exception);

    try {
        this.wagon.getFileList("foo");
        fail();
    } catch (AuthorizationException e) {
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #25
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void getFileResourceDoesNotExistException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    ResourceDoesNotExistException exception = new ResourceDoesNotExistException("");
    when(this.wagon.listDirectory("foo")).thenThrow(exception);

    try {
        this.wagon.getFileList("foo");
        fail();
    } catch (ResourceDoesNotExistException e) {
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #26
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void getFileListTransferFailedException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    TransferFailedException exception = new TransferFailedException("");
    when(this.wagon.listDirectory("foo")).thenThrow(exception);

    try {
        this.wagon.getFileList("foo");
        fail();
    } catch (TransferFailedException e) {
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #27
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void getIfNewerTransferFailedException() throws TransferFailedException, ResourceDoesNotExistException,
        AuthorizationException {
    TransferFailedException exception = new TransferFailedException("");
    when(this.wagon.isRemoteResourceNewer("foo", 0)).thenThrow(exception);

    try {
        this.wagon.getIfNewer("foo", new File("bar"), 0);
        fail();
    } catch (TransferFailedException e) {
        verify(this.transferListenerSupport).fireTransferError(new Resource("foo"), TransferEvent.REQUEST_GET,
                exception);
    }
}
 
Example #28
Source File: AbstractWagonTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
public void get() throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    this.wagon.get("foo", new File("bar"));

    verify(this.transferListenerSupport).fireTransferInitiated(new Resource("foo"), TransferEvent.REQUEST_GET);
    verify(this.transferListenerSupport).fireTransferStarted(new Resource("foo"), TransferEvent.REQUEST_GET);
    verify(this.wagon).getResource(eq("foo"), eq(new File("bar")), any(TransferProgress.class));
    verify(this.transferListenerSupport).fireTransferCompleted(new Resource("foo"), TransferEvent.REQUEST_GET);
}
 
Example #29
Source File: AbstractWagon.java    From lambadaframework with MIT License 5 votes vote down vote up
@Override
public final List<String> getFileList(String destinationDirectory) throws TransferFailedException,
        ResourceDoesNotExistException, AuthorizationException {
    try {
        return listDirectory(destinationDirectory);
    } catch (TransferFailedException | ResourceDoesNotExistException | AuthorizationException e) {
        this.transferListenerSupport.fireTransferError(new Resource(destinationDirectory),
                TransferEvent.REQUEST_GET, e);
        throw e;
    }
}
 
Example #30
Source File: AbstractWagon.java    From lambadaframework with MIT License 5 votes vote down vote up
@Override
public final void putDirectory(File sourceDirectory, String destinationDirectory) throws TransferFailedException,
        ResourceDoesNotExistException, AuthorizationException {
    File[] files = sourceDirectory.listFiles();
    if (files != null) {
        for (File f : files) {
            put(f, destinationDirectory + "/" + f.getName());
        }
    }
}