Java Code Examples for org.codehaus.plexus.util.FileUtils#copyFileToDirectory()

The following examples show how to use org.codehaus.plexus.util.FileUtils#copyFileToDirectory() . 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: MoveFile.java    From butterfly with MIT License 6 votes vote down vote up
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
    File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext);
    File fileTo = getFileTo(transformedAppFolder, transformationContext);
    TOExecutionResult result;

    // TODO
    // Check if it is really a file and if it exists!

    try {
        if (fileFrom.isDirectory()) {
            IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)");
            result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", ex));
        } else {
            String details = String.format("File '%s' has been moved to '%s'", getRelativePath(), getRelativePath(transformedAppFolder, fileTo));
            FileUtils.copyFileToDirectory(fileFrom, fileTo);
            FileUtils.fileDelete(fileFrom.getAbsolutePath());
            result = TOExecutionResult.success(this, details);
        }
    } catch (IOException e) {
        result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", e));
    }

    return result;
}
 
Example 2
Source File: CopyFile.java    From butterfly with MIT License 6 votes vote down vote up
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
    // TODO Validation must be done here!!!

    File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext);
    File fileTo = getFileTo(transformedAppFolder, transformationContext);
    TOExecutionResult result;

    try {
        if (fileFrom.isDirectory()) {
            IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)");
            result = TOExecutionResult.error(this, new TransformationOperationException("File could not be copied", ex));
        } else {
            String details = String.format("File '%s' has been copied to '%s'", getRelativePath(), getRelativePath(transformedAppFolder, fileTo));
            FileUtils.copyFileToDirectory(fileFrom, fileTo);
            result = TOExecutionResult.success(this, details);
        }
    } catch (IOException e) {
        result = TOExecutionResult.error(this, new TransformationOperationException("File could not be copied", e));
    }

    return result;
}
 
Example 3
Source File: JnlpReportMojo.java    From webstart with MIT License 5 votes vote down vote up
private void copyJnlpFiles()
        throws MavenReportException
{
    if ( !jnlpSourceDirectory.exists() )
    {
        throw new MavenReportException( "jnlpSourceDirectory does not exist" );
    }
    try
    {
        File destinationDirectory = new File( outputDirectory, siteJnlpDirectory );
        List<File> files = FileUtils.getFiles( jnlpSourceDirectory, "**/*", "" );
        for ( File file : files )
        {
            getLog().debug( "Copying " + file + " to " + destinationDirectory );
            String path = file.getAbsolutePath().substring( jnlpSourceDirectory.getAbsolutePath().length() + 1 );
            File destDir = new File( destinationDirectory, path );
            getLog().debug( "Copying " + file + " to " + destDir );
            if ( file.isDirectory() )
            {
                destDir.mkdirs();
            }
            else
            {
                FileUtils.copyFileToDirectory( file, destDir.getParentFile() );
            }
        }
    }
    catch ( IOException e )
    {
        throw new MavenReportException( "Failed to copy jnlp files", e );
    }
}
 
Example 4
Source File: DefaultIOUtil.java    From webstart with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean copyFileToDirectoryIfNecessary( File sourceFile, File targetDirectory )
        throws MojoExecutionException
{

    if ( sourceFile == null )
    {
        throw new IllegalArgumentException( "sourceFile is null" );
    }

    File targetFile = new File( targetDirectory, sourceFile.getName() );

    boolean shouldCopy = shouldCopyFile( sourceFile, targetFile );

    if ( shouldCopy )
    {
        try
        {
            FileUtils.copyFileToDirectory( sourceFile, targetDirectory );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException(
                    "Could not copy file " + sourceFile + " to directory " + targetDirectory, e );
        }
    }
    else
    {
        getLogger().debug(
                "Source file hasn't changed. Do not overwrite " + targetFile + " with " + sourceFile + "." );

    }

    return shouldCopy;
}
 
Example 5
Source File: Utils.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * Gets all dependency jars of the project specified by 'project' parameter from the local mirror and copies them
 * under targetFolder
 *
 * @param targetFolder The folder which the dependency jars will be copied to
 */
public static void copyArtifactsTo( MavenProject project, String targetFolder )
        throws MojoExecutionException {
    File targetFolderFile = new File( targetFolder );
    for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) {
        Artifact artifact = ( Artifact ) it.next();

        File f = artifact.getFile();

        LOG.info( "Artifact {} found.", f.getAbsolutePath() );

        if ( f == null ) {
            throw new MojoExecutionException( "Cannot locate artifact file of " + artifact.getArtifactId() );
        }

        // Check already existing artifacts and replace them if they are of a lower version
        try {

            List<String> existing =
                    FileUtils.getFileNames( targetFolderFile, artifact.getArtifactId() + "-*.jar", null, false );

            if ( existing.size() != 0 ) {
                String version =
                        existing.get( 0 ).split( "(" + artifact.getArtifactId() + "-)" )[1].split( "(.jar)" )[0];
                DefaultArtifactVersion existingVersion = new DefaultArtifactVersion( version );
                DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion( artifact.getVersion() );

                if ( existingVersion.compareTo( artifactVersion ) < 0 ) { // Remove existing version
                    FileUtils.forceDelete( targetFolder + existing.get( 0 ) );
                }
                else {
                    LOG.info( "Artifact " + artifact.getArtifactId() + " with the same or higher " +
                            "version already exists in lib folder, skipping copy" );
                    continue;
                }
            }

            LOG.info( "Copying {} to {}", f.getName(), targetFolder );
            FileUtils.copyFileToDirectory( f.getAbsolutePath(), targetFolder );
        }
        catch ( IOException e ) {
            throw new MojoExecutionException( "Error while copying artifact file of " + artifact.getArtifactId(),
                    e );
        }
    }
}