@Override public void fillInputData(InputData inputData) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { Resource resource = inputData.getResource(); try { if (proxy != Proxy.NO_PROXY) { warn("proxy support is not implemented - ignoring proxy settings"); } URLConnection urlConnection = newConnection(resource.getName()); InputStream is = urlConnection.getInputStream(); inputData.setInputStream(is); resource.setLastModified(urlConnection.getLastModified()); resource.setContentLength(urlConnection.getContentLength()); } catch (MalformedURLException e) { throw new TransferFailedException("Invalid repository URL: " + e.getMessage(), e); } catch (FileNotFoundException e) { throw new ResourceDoesNotExistException("Unable to locate resource in repository", e); } catch (IOException e) { throw new TransferFailedException("Error transferring file: " + e.getMessage(), e); } }
/** * @see org.apache.maven.wagon.StreamWagon#putFromStream(java.io.InputStream, java.lang.String, * long, long) */ @Override public void putFromStream( InputStream stream, String destination, long contentLength, long lastModified) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { Resource resource = new Resource(destination); resource.setContentLength(contentLength); resource.setLastModified(lastModified); putCommon(resource, null, stream); }
/** @see org.apache.maven.wagon.StreamWagon#put(java.io.File, java.lang.String) */ @Override public void put(File source, String resourceName) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { InputStream resourceInputStream = null; try { resourceInputStream = new FileInputStream(source); } catch (FileNotFoundException e) { throw new TransferFailedException(e.getMessage()); } Resource resource = new Resource(resourceName); resource.setContentLength(source.length()); resource.setLastModified(source.lastModified()); putCommon(resource, source, resourceInputStream); }
protected ProgressAnswer replayMockForPut(String resourceName, String content, Wagon wagon) { Resource resource = new Resource(resourceName); mockTransferListener.transferInitiated( createTransferEvent( wagon, resource, TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_PUT, sourceFile)); resource = new Resource(resourceName); resource.setContentLength(content.length()); resource.setLastModified(sourceFile.lastModified()); mockTransferListener.transferStarted( createTransferEvent( wagon, resource, TransferEvent.TRANSFER_STARTED, TransferEvent.REQUEST_PUT, sourceFile)); mockTransferListener.transferProgress( eq( createTransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT, sourceFile)), anyObject(byte[].class), anyInt()); ProgressAnswer progressAnswer = new ProgressAnswer(); expectLastCall().andStubAnswer(progressAnswer); mockTransferListener.debug(anyString()); expectLastCall().anyTimes(); mockTransferListener.transferCompleted( createTransferEvent( wagon, resource, TransferEvent.TRANSFER_COMPLETED, TransferEvent.REQUEST_PUT, sourceFile)); replay(mockTransferListener); return progressAnswer; }
protected ProgressAnswer replaceMockForGet(Wagon wagon, int expectedSize) { Resource resource = new Resource(this.resource); mockTransferListener.transferInitiated( createTransferEvent( wagon, resource, TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET, destFile)); resource = new Resource(this.resource); resource.setContentLength(getExpectedContentLengthOnGet(expectedSize)); resource.setLastModified(getExpectedLastModifiedOnGet(testRepository, resource)); TransferEvent te = createTransferEvent( wagon, resource, TransferEvent.TRANSFER_STARTED, TransferEvent.REQUEST_GET, null); mockTransferListener.transferStarted(te); mockTransferListener.transferProgress( eq( new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_GET)), anyObject(byte[].class), anyInt()); ProgressAnswer progressAnswer = new ProgressAnswer(); if (assertOnTransferProgress()) { expectLastCall().andAnswer(progressAnswer); } else { expectLastCall().andAnswer(progressAnswer); expectLastCall().anyTimes(); } mockTransferListener.debug(anyString()); expectLastCall().anyTimes(); mockTransferListener.transferCompleted( createTransferEvent( wagon, resource, TransferEvent.TRANSFER_COMPLETED, TransferEvent.REQUEST_GET, destFile)); replay(mockTransferListener); return progressAnswer; }
/** * Common put implementation. Handles firing events and ultimately sending the data via the s-ramp * client. * * @param resource * @param source * @param content * @throws TransferFailedException * @throws ResourceDoesNotExistException * @throws AuthorizationException */ private void putCommon(Resource resource, File source, InputStream content) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { logger.info(Messages.i18n.format("UPLOADING_TO_SRAMP", resource.getName())); // $NON-NLS-1$ firePutInitiated(resource, source); firePutStarted(resource, source); if (resource.getName().contains("maven-metadata.xml")) { // $NON-NLS-1$ logger.info(Messages.i18n.format("SKIPPING_ARTY", resource.getName())); // $NON-NLS-1$ try { transfer(resource, content, new DevNullOutputStream(), TransferEvent.REQUEST_PUT); } catch (IOException e) { throw new TransferFailedException(e.getMessage(), e); } } else { doPut(resource, content); } firePutCompleted(resource, source); }
private void replaceMockForSkippedGetIfNewer(Wagon wagon, int expectedSize) { Resource resource = new Resource(this.resource); mockTransferListener.transferInitiated( createTransferEvent( wagon, resource, TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET, destFile)); resource = new Resource(this.resource); resource.setContentLength(getExpectedContentLengthOnGet(expectedSize)); resource.setLastModified(getExpectedLastModifiedOnGet(testRepository, resource)); // TODO: transfer skipped event? // mockTransferListener.transferSkipped( createTransferEvent( wagon, resource, // TransferEvent.TRANSFER_STARTED, // TransferEvent.REQUEST_GET, destFile ) ); mockTransferListener.debug(anyString()); expectLastCall().anyTimes(); replay(mockTransferListener); }