本文整理了Java中org.codehaus.plexus.util.FileUtils
类的一些代码示例,展示了FileUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils
类的具体详情如下:
包路径:org.codehaus.plexus.util.FileUtils
类名称:FileUtils
[英]This class provides basic facilities for manipulating files and file paths.
Methods exist to retrieve the components of a typical file path. For example /www/hosted/mysite/index.html
, can be broken into:
/www/hosted/mysite/
-- retrievable through #getPathindex.html
-- retrievable through #removePath/www/hosted/mysite/index
-- retrievable through #removeExtensionhtml
-- retrievable through #getExtensionThere are methods to create a #toFile, copy a #copyFileToDirectory, copy a #copyFile, copy a #copyURLToFile, as well as methods to #deleteDirectory(File) and #cleanDirectory(File) a directory.
Common java.io.File manipulation routines.
Taken from the commons-utils repo. Also code from Alexandria's FileUtils. And from Avalon Excalibur's IO. And from Ant.
[中]此类提供了操作文件和文件路径的基本工具。
####路径相关方法
存在检索典型文件路径的组件的方法。例如/www/hosted/mysite/index.html
,可以分为:
*[$1$]--可通过#getPath检索
*[$2$]--可通过#removePath检索
*[$3$]--可通过#removeExtension检索
*[$4$]--可通过#getExtension检索
还有一些方法可以#catPath、#resolveFile和#规范化路径。
####文件相关方法
有创建#toFile、将#copyFileToDirectory、复制#copyFile、复制#copyURLToFile的方法,也有删除目录(File)和清除目录(File)的方法。
通用java。木卫一。文件操作例程。
摘自《公用事业报告》。还有来自亚历山大的FileUtils的代码。还有阿瓦隆·埃克斯卡利伯的木卫一。还有蚂蚁。
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* <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 );
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* 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 ) );
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* 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 );
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* 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;
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* 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 );
}
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
/**
* 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 );
}
}
}
代码示例来源:origin: org.codehaus.mojo/versions-maven-plugin
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 );
}
}
}
}
代码示例来源:origin: org.kohsuke/pgp-maven-plugin
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);
}
代码示例来源:origin: apache/axis2-java
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);
}
代码示例来源:origin: apache/usergrid
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 );
代码示例来源:origin: org.apache.npanday.plugins/maven-aspx-plugin
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);
}
}
}
代码示例来源:origin: org.codehaus.mojo/appassembler-maven-plugin
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 );
}
}
}
代码示例来源:origin: org.carewebframework/org.carewebframework.mvn.plugin.core
/**
* 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;
}
代码示例来源:origin: org.codehaus.mojo/wagon-maven-plugin
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 );
}
}
}
代码示例来源:origin: geotools/geotools
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);
代码示例来源:origin: apache/usergrid
+ "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" );
代码示例来源:origin: apache/maven-scm
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 );
代码示例来源:origin: org.apache.sling/maven-launchpad-plugin
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);
}
}
}
代码示例来源:origin: net.flexmojos.oss/flexmojos-maven-plugin
@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;
}
代码示例来源:origin: de.saumya.mojo/jruby9-common
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);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!