@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);
    }
  }
예제 #2
0
파일: SrampWagon.java 프로젝트: rnc/s-ramp
 /**
  * @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);
 }
예제 #3
0
파일: SrampWagon.java 프로젝트: rnc/s-ramp
  /** @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);
  }
예제 #4
0
  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;
  }
예제 #5
0
  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;
  }
예제 #6
0
파일: SrampWagon.java 프로젝트: rnc/s-ramp
  /**
   * 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);
  }
예제 #7
0
  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);
  }