Refine search
public String getName() { String name = resource.getName(); if ( name == null ) { name = ""; } else if ( name.startsWith( "/" ) ) { name = name.substring( 1 ); } return name; }
public long getContentLength() { return resource.getContentLength(); }
@Override public void transferStarted( TransferEvent transferEvent ) { log.debug( "transferStarted for resource {} on repository url {}", transferEvent.getResource().getName(), transferEvent.getWagon().getRepository().getUrl() ); }
/** * {@inheritDoc} */ public void fillInputData(InputData inputData) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { log.debug("Invoked fillInputData()"); Resource resource = inputData.getResource(); File file = new File(git.workDir, resource.getName()); if (!file.exists()) { throw new ResourceDoesNotExistException("File: " + file + " does not exist"); } try { InputStream in = new BufferedInputStream(new FileInputStream(file)); inputData.setInputStream(in); resource.setContentLength(file.length()); resource.setLastModified(file.lastModified()); } catch (FileNotFoundException e) { throw new TransferFailedException("Could not read from file: " + file.getAbsolutePath(), e); } }
public long getContentLength() { return source.getResource().getContentLength(); }
public void fillOutputData( OutputData outputData ) throws TransferFailedException { int directoryMode = getDirectoryMode( getRepository().getPermissions() ); Resource resource = outputData.getResource(); try { channel.cd( "/" ); String basedir = getRepository().getBasedir(); mkdirs( basedir + "/", directoryMode ); mkdirs( resource.getName(), directoryMode ); String filename = ScpHelper.getResourceFilename( resource.getName() ); outputData.setOutputStream( channel.put( filename ) ); } catch ( TransferFailedException e ) { fireTransferError( resource, e, TransferEvent.REQUEST_PUT ); throw e; } catch ( SftpException e ) { fireTransferError( resource, e, TransferEvent.REQUEST_PUT ); String msg = "Error occurred while deploying '" + resource.getName() + "' " + "to remote repository: " + getRepository().getUrl() + ": " + e.getMessage(); throw new TransferFailedException( msg, e ); } }
public void putFromStream( InputStream stream, String destination, long contentLength, long lastModified ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { Resource resource = new Resource( destination ); firePutInitiated( resource, null ); resource.setContentLength( contentLength ); resource.setLastModified( lastModified ); putFromStream( stream, resource ); }
private void handleIOException( Resource resource, IOException e ) throws TransferFailedException { if ( e.getMessage().contains( "set mode: Operation not permitted" ) ) { fireTransferDebug( e.getMessage() ); } else { fireTransferError( resource, e, TransferEvent.REQUEST_PUT ); String msg = "Error occurred while deploying '" + resource.getName() + "' to remote repository: " + getRepository().getUrl() + ": " + e.getMessage(); throw new TransferFailedException( msg, e ); } }
@Override public void transferCompleted( TransferEvent transferEvent ) { resourceName = transferEvent.getResource( ).getName( ); long endTime = System.currentTimeMillis( ); log.info( "end of transfer file {} {} kb: {}s", transferEvent.getResource( ).getName( ), this.totalLength / 1024, ( endTime - startTime ) / 1000 ); }
resource.getContentLength() == WagonConstants.UNKNOWN_LENGTH ? Long.MAX_VALUE : resource.getContentLength() ); String msg = "PUT request to: " + resource.getName() + " in " + repository.getName() + " failed"; throw new TransferFailedException( msg, e );
public void fillInputData( InputData inputData ) throws TransferFailedException, ResourceDoesNotExistException { Resource resource = inputData.getResource(); String filename = ScpHelper.getResourceFilename( resource.getName() ); String dir = ScpHelper.getResourceDirectory( resource.getName() ); // we already setuped the root directory. Ignore beginning / if ( dir.length() > 0 && dir.charAt( 0 ) == ScpHelper.PATH_SEPARATOR ) { dir = dir.substring( 1 ); } try { SftpATTRS attrs = changeToRepositoryDirectory( dir, filename ); long lastModified = attrs.getMTime() * MILLIS_PER_SEC; resource.setContentLength( attrs.getSize() ); resource.setLastModified( lastModified ); inputData.setInputStream( channel.get( filename ) ); } catch ( SftpException e ) { handleGetException( resource, e ); } }
/** * Builds a complete URL string from the repository URL and the relative path of the resource passed. * * @param resource the resource to extract the relative path from. * @return the complete URL */ private String buildUrl( Resource resource ) { return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() ); }
public void fillOutputData( OutputData outputData ) throws TransferFailedException { if ( getRepository().getBasedir() == null ) { throw new TransferFailedException( "Unable to operate with a null basedir." ); } Resource resource = outputData.getResource(); File file = new File( getRepository().getBasedir(), resource.getName() ); createParentDirectories( file ); OutputStream outputStream = new BufferedOutputStream( new LazyFileOutputStream( file ) ); outputData.setOutputStream( outputStream ); }
@Override public boolean resourceExists( String resourceName ) throws TransferFailedException, AuthorizationException { Resource resource = new Resource( resourceName ); try { ftpChangeDirectory( resource ); String filename = PathUtils.filename( resource.getName() ); int status = ftp.stat( filename ); return ( ( status == FTPReply.FILE_STATUS ) || ( status == FTPReply.DIRECTORY_STATUS ) || ( status == FTPReply.FILE_STATUS_OK ) // not in the RFC but used by some FTP servers || ( status == FTPReply.COMMAND_OK ) // not in the RFC but used by some FTP servers || ( status == FTPReply.SYSTEM_STATUS ) ); } catch ( IOException e ) { throw new TransferFailedException( "Error transferring file via FTP", e ); } catch ( ResourceDoesNotExistException e ) { return false; } }
@Override public void transferCompleted(final TransferEvent event) { final long length = event.getResource().getContentLength(); if (length != (long) WagonConstants.UNKNOWN_LENGTH) { this.log.info( String.format( "%s %s", event.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded", length >= KBYTE ? (length / KBYTE) + "K" : length + "b" ) ); } }
private void put(RetryableSource source, File file, Resource resource) throws TransferFailedException { firePutStarted( resource, file ); String url = buildUrl(resource.getName()); try(Response response = client.put(url, source)) { // TODO do I need to worry about response status? } catch (FileNotFoundException e) { fireTransferError(resource, e, TransferEvent.REQUEST_PUT); throw new TransferFailedException("Specified source file does not exist: " + source, e); } catch (IOException e) { fireTransferError(resource, e, TransferEvent.REQUEST_PUT); String msg = "PUT request to: " + resource.getName() + " in " + repository.getName() + " failed"; throw new TransferFailedException(msg, e); } firePutCompleted( resource, file ); }
public void get(String resourceName, File destination) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { Resource res = new Resource( resourceName ); try { fireGetInitiated( res, destination ); fireGetStarted( res, destination ); Map m = new HashMap(); destination.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(destination); try { queryRepo.getFile(combine(rootPath,resourceName),-1/*head*/,m, fos); } finally { fos.close(); } postProcessListeners( res, destination, TransferEvent.REQUEST_GET ); fireGetCompleted( res, destination ); } catch (SVNException e) { throw new ResourceDoesNotExistException("Unable to find "+resourceName+" in "+getRepository().getUrl(),e); } catch (IOException e) { throw new TransferFailedException("Unable to find "+resourceName+" in "+getRepository().getUrl(),e); } }
protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource ) { return new File( repository.getBasedir(), resource.getName() ).lastModified(); }
public final boolean getIfNewer(final String resourceName, final File destination, final long timestamp) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { Resource resource = new Resource(resourceName); try { if (isRemoteResourceNewer(resourceName, timestamp)) { get(resourceName, destination); return true; } else { return false; } } catch (TransferFailedException e) { throw e; } catch (ResourceDoesNotExistException e) { throw e; } catch (AuthorizationException e) { throw e; } catch (Exception e) { transferListeners.fireTransferError(resource, TransferEvent.REQUEST_GET, e); throw new TransferFailedException("Transfer of resource " + destination + "failed", e); } }
@Override public void transferStarted( TransferEvent transferEvent ) { this.totalLength = 0; resourceName = transferEvent.getResource().getName(); log.info("Transferring: {}, {}", transferEvent.getResource().getContentLength(), transferEvent.getLocalFile().toString()); log.info( "start transfer of {}", transferEvent.getResource().getName() ); }