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

The following examples show how to use org.codehaus.plexus.util.FileUtils#copyFile() . 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: EmoStartMojo.java    From emodb with Apache License 2.0 6 votes vote down vote up
private void copyEmoServiceArtifactToWorkingDirectory() throws MojoExecutionException, MojoFailureException {
    // NOTE: this emo service artifact is an "uberjar" created by the maven-shade-plugin
    final ArtifactItem emoServiceArtifact = new ArtifactItem();
    emoServiceArtifact.setGroupId("com.bazaarvoice.emodb");
    emoServiceArtifact.setArtifactId("emodb-web");
    emoServiceArtifact.setVersion(pluginVersion());

    resolveArtifactItems(asList(emoServiceArtifact));
    final File emoServiceJar = emoServiceArtifact.getResolvedArtifact().getArtifact().getFile();
    try {
        // copy to "emodb.jar" so that we always overwrite any prior
        FileUtils.copyFile(emoServiceJar, new File(emoProcessWorkingDirectory(), "emodb.jar"));
    } catch (IOException e) {
        throw new MojoFailureException("failed to copy: " + emoServiceArtifact, e);
    }
}
 
Example 2
Source File: NativeLinkMojo.java    From maven-native with MIT License 6 votes vote down vote up
private File getDependencyFile( Artifact artifact, boolean doCopy )
    throws MojoExecutionException
{

    File newLocation = new File( this.externalLibDirectory,
            artifact.getArtifactId() + "." + artifact.getArtifactHandler().getExtension() );

    try
    {
        if ( doCopy && !artifact.getFile().isDirectory()
                && ( !newLocation.exists() || newLocation.lastModified() <= artifact.getFile().lastModified() ) )
        {
            FileUtils.copyFile( artifact.getFile(), newLocation );
        }
    }
    catch ( IOException ioe )
    {
        throw new MojoExecutionException( "Unable to copy dependency to staging area.  Could not copy "
                + artifact.getFile() + " to " + newLocation, ioe );
    }

    return newLocation;
}
 
Example 3
Source File: RevertMojo.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
public void execute()
    throws MojoExecutionException, MojoFailureException
{
    File outFile = project.getFile();
    File backupFile = new File( outFile.getParentFile(), outFile.getName() + ".versionsBackup" );

    if ( backupFile.exists() )
    {
        getLog().info( "Restoring " + outFile + " from " + backupFile );
        try
        {
            FileUtils.copyFile( backupFile, outFile );
            FileUtils.forceDelete( backupFile );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException( e.getMessage(), e );
        }
    }
}
 
Example 4
Source File: DeployUtil.java    From Kylin with Apache License 2.0 6 votes vote down vote up
public static void deployJobJars() throws IOException {
    Pair<File, File> files = getJobJarFiles();
    File originalJobJar = files.getFirst();
    File originalCoprocessorJar = files.getSecond();

    String jobJarPath = config().getKylinJobJarPath();
    if (StringUtils.isEmpty(jobJarPath)) {
        throw new RuntimeException("deployJobJars cannot find job jar");
    }

    File targetJobJar = new File(jobJarPath);
    File jobJarRenamedAsTarget = new File(originalJobJar.getParentFile(), targetJobJar.getName());
    if (originalJobJar.equals(jobJarRenamedAsTarget) == false) {
        FileUtils.copyFile(originalJobJar, jobJarRenamedAsTarget);
    }

    File targetCoprocessorJar = new File(config().getCoprocessorLocalJar());
    File coprocessorJarRenamedAsTarget = new File(originalCoprocessorJar.getParentFile(), targetCoprocessorJar.getName());
    if (originalCoprocessorJar.equals(coprocessorJarRenamedAsTarget) == false) {
        FileUtils.copyFile(originalCoprocessorJar, coprocessorJarRenamedAsTarget);
    }

    CliCommandExecutor cmdExec = config().getCliCommandExecutor();
    cmdExec.copyFile(jobJarRenamedAsTarget.getAbsolutePath(), targetJobJar.getParent());
    cmdExec.copyFile(coprocessorJarRenamedAsTarget.getAbsolutePath(), targetCoprocessorJar.getParent());
}
 
Example 5
Source File: DependencyNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    File target = data.getJavadocFile();
    try {
        FileUtils.copyFile(source, target);
    } catch (IOException ex) {
        ex.printStackTrace();
        target.delete();
    }
    refreshNode();
}
 
Example 6
Source File: DependencyNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    File target = data.getSourceFile();
    try {
        FileUtils.copyFile(source, target);
    } catch (IOException ex) {
        ex.printStackTrace();
        target.delete();
    }
    refreshNode();
}
 
Example 7
Source File: EmoStartMojo.java    From emodb with Apache License 2.0 5 votes vote down vote up
private void copyEmoConfigurationFile() throws MojoExecutionException, IOException {
    if (StringUtils.isBlank(emoConfigurationFile)) {
        copyDefaultEmoConfigurationFile();
    } else {
        try {
            // copy configuration file to well-known emodb config directory and filename "config.yaml"
            FileUtils.copyFile(new File(emoConfigurationFile), new File(emoConfigurationDirectory(), "config.yaml"));
        } catch (Exception e) {
            throw new MojoExecutionException("failed to copy configuration file from " + emoConfigurationFile, e);
        }
    }
}
 
Example 8
Source File: EmoStartMojo.java    From emodb with Apache License 2.0 5 votes vote down vote up
private void copyDdlConfigurationFile() throws MojoExecutionException, IOException {
    if (StringUtils.isBlank(ddlConfigurationFile)) {
        copyDefaultDdlConfigurationFile();
    } else {
        try {
            // copy configuration file to well-known emodb DDL config directory and filename "config-ddl.yaml"
            FileUtils.copyFile(new File(ddlConfigurationFile), new File(emoConfigurationDirectory(), "config-ddl.yaml"));
        } catch (Exception e) {
            throw new MojoExecutionException("failed to copy configuration file from " + ddlConfigurationFile, e);
        }
    }
}
 
Example 9
Source File: JavaServiceWrapperDaemonGenerator.java    From appassembler with MIT License 5 votes vote down vote up
private void copyExternalFile( File from, File to )
    throws DaemonGeneratorException
{
    try
    {
        from.getParentFile().mkdirs();
        FileUtils.copyFile( from, to );
    }
    catch ( IOException e )
    {
        throw new DaemonGeneratorException( "Could not copy external file: " + from, e );
    }

}
 
Example 10
Source File: DefaultIOUtil.java    From webstart with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void copyFile( File sourceFile, File targetFile )
        throws MojoExecutionException
{
    makeDirectoryIfNecessary( targetFile.getParentFile() );
    try
    {
        FileUtils.copyFile( sourceFile, targetFile );
    }
    catch ( IOException e )
    {
        throw new MojoExecutionException( "Could not copy file " + sourceFile + " to " + targetFile, e );
    }
}
 
Example 11
Source File: SignToolTest.java    From webstart with MIT License 5 votes vote down vote up
protected void copyTestFile( File file, File target )
    throws IOException
{
    if ( target.exists() )
    {
        FileUtils.forceDelete( target );
    }

    FileUtils.copyFile( file, target );

}
 
Example 12
Source File: NarMojo.java    From nifi-maven with Apache License 2.0 5 votes vote down vote up
protected void copyFile(File artifact, File destFile) throws MojoExecutionException {
    try {
        getLog().info("Copying " + (this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName()) + " to " + destFile);
        FileUtils.copyFile(artifact, destFile);
    } catch (Exception e) {
        throw new MojoExecutionException("Error copying artifact from " + artifact + " to " + destFile, e);
    }
}
 
Example 13
Source File: ExportHBaseData.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public void downloadToLocal() throws IOException {
    String localArchive = "../examples/test_case_data/minicluster/hbase-export.tar.gz";

    if (kylinConfig.getRunAsRemoteCommand()) {
        SSHClient ssh = new SSHClient(kylinConfig.getRemoteHadoopCliHostname(), kylinConfig.getRemoteHadoopCliUsername(), kylinConfig.getRemoteHadoopCliPassword());
        try {
            ssh.scpFileToLocal(backupArchive, localArchive);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        FileUtils.copyFile(new File(backupArchive), new File(localArchive));
    }
}
 
Example 14
Source File: CopyMojo.java    From copy-rename-maven-plugin with MIT License 5 votes vote down vote up
private void copy(File srcFile,File destFile) throws MojoExecutionException{

		if(!srcFile.exists()){
			if(ignoreFileNotFoundOnIncremental && buildContext.isIncremental()){
				getLog().warn("sourceFile "+srcFile.getAbsolutePath()+ " not found during incremental build");
			} else {
				getLog().error("sourceFile "+srcFile.getAbsolutePath()+ " does not exist");
			}
		} else if(srcFile.isDirectory()){
			getLog().error("sourceFile "+srcFile.getAbsolutePath()+ " is not a file");
		} else if(destFile == null){
			getLog().error("destinationFile not specified");
		} else if(destFile.exists() && destFile.isFile() && !overWrite){
			getLog().error(destFile.getAbsolutePath()+" already exists and overWrite not set");
		} else{
			try {
				if(buildContext.isIncremental() && destFile.exists() && !buildContext.hasDelta(srcFile) && FileUtils.contentEquals(srcFile, destFile)){
					getLog().info("No changes detected in "+srcFile.getAbsolutePath());
					return;
				}
				FileUtils.copyFile(srcFile, destFile);
				getLog().info("Copied "+ srcFile.getAbsolutePath()+ " to "+ destFile.getAbsolutePath());
				buildContext.refresh(destFile);
			} catch (IOException e) {
				throw new MojoExecutionException("could not copy "+srcFile.getAbsolutePath()+" to "+destFile.getAbsolutePath());
			}
		}


	}
 
Example 15
Source File: ThemeBuilderUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Copies all content (files and directories) from the source directory to the target directory, except content
 * that already exists in the target directory (same name and path), in other words it does not override any
 * existing content
 *
 * <p>
 * Files from the source directory can be excluded from the copying by setting one or more patterns in the
 * source excludes list
 * </p>
 *
 * @param sourceDirectory directory to copy content from
 * @param targetDirectory directory to copy content to
 * @param sourceExcludes list of patterns to match on for source exclusions
 * @throws IOException
 */
public static void copyMissingContent(File sourceDirectory, File targetDirectory, List<String> sourceExcludes)
        throws IOException {
    String[] copyExcludes = null;

    if ((sourceExcludes != null) && !sourceExcludes.isEmpty()) {
        copyExcludes = new String[sourceExcludes.size()];

        copyExcludes = sourceExcludes.toArray(copyExcludes);
    }

    List<String> sourceDirectoryContents = getDirectoryContents(sourceDirectory, null, copyExcludes);
    List<String> targetDirectoryContents = getDirectoryContents(targetDirectory, null, null);

    for (String sourceContent : sourceDirectoryContents) {
        if (targetDirectoryContents.contains(sourceContent)) {
            continue;
        }

        // copy file to target
        File sourceFile = new File(sourceDirectory, sourceContent);
        File targetFile = new File(targetDirectory, sourceContent);

        if (sourceFile.isDirectory()) {
            targetFile.mkdir();
        } else {
            FileUtils.copyFile(sourceFile, targetFile);
        }
    }
}
 
Example 16
Source File: SampleCubeSetupTest.java    From Kylin with Apache License 2.0 4 votes vote down vote up
private void deployJobConfToEtc() throws IOException {
    File src = new File(SANDBOX_TEST_DATA, JobEngineConfig.HADOOP_JOB_CONF_FILENAME + ".xml");
    File dst = new File("/etc/kylin", src.getName());
    FileUtils.copyFile(src, dst);
}