/** * <b>If wrappers is null or empty, the file will be copy only if {@code to.lastModified() < from.lastModified()}</b> * * @param from the file to copy * @param to the destination file * @param encoding the file output encoding (only if wrappers is not empty) * @param wrappers array of {@link FilterWrapper} * @throws IOException if an IO error occurs during copying or filtering */ public static void copyFile( File from, File to, String encoding, FilterWrapper[] wrappers ) throws IOException { copyFile( from, to, encoding, wrappers, false ); }
/** * Recursively delete a directory. * * @param directory a directory * @throws IOException if any */ public static void deleteDirectory( final String directory ) throws IOException { deleteDirectory( new File( directory ) ); }
/** * Writes data to a file. The file will be created if it does not exist. Note: the data is written with platform * encoding * * @param fileName The path of the file to write. * @param data The content to write to the file. * @throws IOException if any */ public static void fileWrite( String fileName, String data ) throws IOException { fileWrite( fileName, null, data ); }
/** * Copy file from source to destination only if source timestamp is later than the destination timestamp. The * directories up to <code>destination</code> will be created if they don't already exist. <code>destination</code> * will be overwritten if it already exists. * * @param source An existing non-directory <code>File</code> to copy bytes from. * @param destination A non-directory <code>File</code> to write bytes to (possibly overwriting). * @return true if no problem occured * @throws IOException if <code>source</code> does not exist, <code>destination</code> cannot be written to, or an * IO error occurs during copying. */ public static boolean copyFileIfModified( final File source, final File destination ) throws IOException { if ( isSourceNewerThanDestination( source, destination ) ) { copyFile( source, destination ); return true; } return false; }
/** * Copy a directory to an other one. * * @param sourceDirectory the source dir * @param destinationDirectory the target dir * @param includes include pattern * @param excludes exclude pattern * @throws IOException if any * @see #getFiles(File, String, String) */ public static void copyDirectory( File sourceDirectory, File destinationDirectory, String includes, String excludes ) throws IOException { if ( !sourceDirectory.exists() ) { return; } List<File> files = getFiles( sourceDirectory, includes, excludes ); for ( File file : files ) { copyFileToDirectory( file, destinationDirectory ); } }
/** * Delete a file. If file is directory delete it and all sub-directories. * * @param file a file * @throws IOException if any */ public static void forceDelete( final File file ) throws IOException { if ( file.isDirectory() ) { deleteDirectory( file ); } else { /* * NOTE: Always try to delete the file even if it appears to be non-existent. This will ensure that a * symlink whose target does not exist is deleted, too. */ boolean filePresent = file.getCanonicalFile().exists(); if ( !deleteFile( file ) && filePresent ) { final String message = "File " + file + " unable to be deleted."; throw new IOException( message ); } } }
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 ); } } } }
public void execute() throws MojoExecutionException { if (skip) return; // capture the attached artifacts to sign before we start attaching our own stuff List<Artifact> attached = new ArrayList<Artifact>((List<Artifact>)project.getAttachedArtifacts()); PGPSecretKey secretKey = loadSecretKey(); Signer signer = new Signer(secretKey,loadPassPhrase(secretKey).toCharArray()); if ( !"pom".equals( project.getPackaging() ) ) sign(signer,project.getArtifact()); {// sign POM File pomToSign = new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom" ); try { FileUtils.copyFile(project.getFile(), pomToSign); } catch ( IOException e ) { throw new MojoExecutionException( "Error copying POM for signing.", e ); } getLog().debug( "Generating signature for " + pomToSign ); // fake just enough Artifact for the sign method DefaultArtifact a = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), VersionRange.createFromVersion(project.getVersion()), null, "pom", null, new DefaultArtifactHandler("pom")); a.setFile(pomToSign); sign(signer,a); } for (Artifact a : attached) sign(signer,a); }
public void deploy(Log log, Artifact artifact) throws MojoExecutionException { StringBuilder buffer = new StringBuilder(artifact.getArtifactId()); if (!stripVersion) { buffer.append("-"); buffer.append(artifact.getBaseVersion()); } buffer.append("."); buffer.append(artifact.getType()); String destFileName = buffer.toString(); log.info("Adding " + destFileName); try { FileUtils.copyFile(artifact.getFile(), new File(directory, destFileName)); } catch (IOException ex) { throw new MojoExecutionException("Error copying " + destFileName + ": " + ex.getMessage(), ex); } files.add(destFileName); }
throws MojoExecutionException { File targetFolderFile = new File( targetFolder ); for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) { Artifact artifact = ( Artifact ) it.next(); File f = artifact.getFile(); throw new MojoExecutionException( "Cannot locate artifact file of " + artifact.getArtifactId() ); FileUtils.getFileNames( targetFolderFile, artifact.getArtifactId() + "-*.jar", null, false ); FileUtils.forceDelete( targetFolder + existing.get( 0 ) ); FileUtils.copyFileToDirectory( f.getAbsolutePath(), targetFolder ); throw new MojoExecutionException( "Error while copying artifact file of " + artifact.getArtifactId(), e );
public void execute() throws MojoExecutionException, MojoFailureException { for (Artifact dependency : dependencies) { try { String filename = dependency.getArtifactId() + "." + dependency.getArtifactHandler().getExtension(); File targetFile = new File(binDir, filename); if (!targetFile.exists()) { getLog().debug("NPANDAY-000-0001: copy dependency: typeof:" + dependency.getClass()); getLog().debug("NPANDAY-000-0001: copy dependency: " + dependency); getLog().debug("NPANDAY-000-0002: copying " + dependency.getFile().getAbsolutePath() + " to " + targetFile); File sourceFile = PathUtil.getGACFile4Artifact(dependency); FileUtils.copyFile(sourceFile, targetFile); } } catch (IOException ioe) { throw new MojoExecutionException("NPANDAY-000-00002: Error copying dependency " + dependency, ioe); } } }
protected void removeDirectory( File directory ) throws MojoExecutionException { if ( directory.exists() ) { try { this.getLog().info( "Removing " + directory ); FileUtils.deleteDirectory( directory ); } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } }
/** * Creates the archive from data in the staging directory. * * @return The archive file. * @throws Exception Unspecified exception. */ private File createArchive() throws Exception { getLog().info("Creating archive."); Artifact artifact = mavenProject.getArtifact(); String clsfr = noclassifier ? "" : ("-" + classifier); String archiveName = artifact.getArtifactId() + "-" + artifact.getVersion() + clsfr + ".jar"; File jarFile = new File(mavenProject.getBuild().getDirectory(), archiveName); MavenArchiver archiver = new MavenArchiver(); jarArchiver.addDirectory(stagingDirectory); archiver.setArchiver(jarArchiver); archiver.setOutputFile(jarFile); archiver.createArchive(mavenSession, mavenProject, archiveConfig); if (noclassifier) { artifact.setFile(jarFile); } else { projectHelper.attachArtifact(mavenProject, jarFile, classifier); } FileUtils.deleteDirectory(stagingDirectory); return jarFile; }
private void updateMavenLib( Artifact artifact ) throws MojoExecutionException { try { File mavenLibDir = new File( System.getProperty( "maven.home" ), "lib/ext" ); artifactResolver.resolve( artifact, remoteRepositories, localRepository ); this.getLog().info( "Copy " + artifact.getFile() + " to " + mavenLibDir ); FileUtils.copyFileToDirectory( artifact.getFile(), mavenLibDir ); } catch ( Exception e ) { throw new MojoExecutionException( "Unable to download artifact", e ); } } }
if (!collect.exists()) { if (!collect.mkdir()) { throw new MojoExecutionException( "Failed to create target directory: " + collect.getAbsolutePath()); if (!collect.exists()) { if (!collect.mkdir()) { throw new MojoExecutionException("Failed to create binaries directory."); FileUtils.copyFileToDirectory(jarFile, collect); Set<Artifact> dependencies = project.getDependencyArtifacts(); if (dependencies != null) { for (final Artifact artifact : dependencies) { System.out.println("+++++++++++++++++++++++ DEP: " + artifact.getDependencyTrail()); final String scope = artifact.getScope(); if (scope != null final File file = artifact.getFile(); if (!artifact.getGroupId().startsWith("org.geotools")) { final File copy = new File(collect, file.getName()); FileUtils.copyFileToDirectory(file, collect);
+ "failIfCommitNecessary parameter as false in your plugin configuration field inside the pom.xml"; throw new MojoExecutionException( failMsg ); if ( FileUtils.fileExists( extractedRunnerPath ) ) { FileUtils.cleanDirectory( extractedRunnerPath ); FileUtils.mkdir( extractedRunnerPath ); if ( ! FileUtils.fileExists( projectTestOutputJar ) ) { throw new MojoExecutionException( "Project Test Jar could not be found. Make sure you use 'test-jar'" + " goal of the 'maven-jar-plugin' in your project's pom" ); FileUtils.copyFileToDirectory( new File( getProjectOutputJarPath() ), libPathFile ); FileUtils.copyFileToDirectory( new File( projectTestOutputJar ), libPathFile ); Properties prop = new Properties(); String configPropertiesFilePath = extractedRunnerPath + "project.properties"; if ( FileUtils.fileExists( configPropertiesFilePath ) ) { FileUtils.mkdir( configPropertiesFilePath.substring( 0, configPropertiesFilePath.lastIndexOf( '/' ) ) ); FileWriter writer = new FileWriter( configPropertiesFilePath ); prop.store( writer, "Generated with chop:runner" ); throw new MojoExecutionException( "There is no resource folder inside the project" );
this.getLog().info( "Removing " + this.exportDirectory ); FileUtils.deleteDirectory( this.exportDirectory ); throw new MojoExecutionException( "Cannot remove " + getExportDirectory() ); throw new MojoExecutionException( "Cannot create " + this.exportDirectory ); new ScmFileSet( this.exportDirectory.getAbsoluteFile() ), getScmVersion( scmVersionType, scmVersion ) ); throw new MojoExecutionException( "Cannot run export command : ", e );
protected void copy(File file, int startLevel, String runModes, File outputDirectory) throws MojoExecutionException { File destination = new File(outputDirectory, getPathForArtifact(startLevel, file.getName().replace('/', File.separatorChar), runModes)); if (shouldCopy(file, destination)) { getLog().info(String.format("Copying bundle from %s to %s", file.getPath(), destination.getPath())); try { FileUtils.copyFile(file, destination); } catch (IOException e) { throw new MojoExecutionException("Unable to copy bundle from " + file.getPath(), e); } } }
@SuppressWarnings( "unchecked" ) protected Artifact getGlobalArtifact() { Artifact global = getDependency(GLOBAL_MATCHER); if ( global == null ) { throw new IllegalArgumentException( "Global artifact is not available. Make sure to add " + "'playerglobal' or 'airglobal' to this project."); } File source = global.getFile(); File dest = new File( source.getParentFile(), global.getArtifactId() + "." + SWC ); global.setFile( dest ); try { if ( !dest.exists() ) { dest.getParentFile().mkdirs(); getLog().debug( "Striping global artifact, source: " + source + ", dest: " + dest ); FileUtils.copyFile( source, dest ); } } catch ( IOException e ) { throw new IllegalStateException( "Error renaming '" + global.getArtifactId() + "'.", e ); } return global; }
public void copy(File output, String groupId, String artifactId, String version, String exclusion) throws MojoExecutionException { output.mkdirs(); for(Artifact artifact: resolve(groupId, artifactId, version, exclusion)) { try { FileUtils.copyFile(artifact.getFile(), new File(output, artifact.getFile().getName())); } catch (IOException e) { throw new MojoExecutionException("could not copy: " + artifact, e); } } }