当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils类代码示例

本文整理汇总了Java中org.codehaus.plexus.util.FileUtils的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileUtils类属于org.codehaus.plexus.util包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execution

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
    File fileToBeModified = getAbsoluteFile(transformedAppFolder, transformationContext);

    if (!fileToBeModified.exists()) {
        // TODO Should this be done as pre-validation?
        FileNotFoundException ex = new FileNotFoundException("File to be modified has not been found");
        return TOExecutionResult.error(this, ex);
    }

    TOExecutionResult result = null;

    try {
        FileUtils.fileAppend(fileToBeModified.getAbsolutePath(), EolHelper.findEolDefaultToOs(fileToBeModified));
        FileUtils.fileAppend(fileToBeModified.getAbsolutePath(), newLine);
        String details =  "A new line has been added to file " + getRelativePath(transformedAppFolder, fileToBeModified);
        result = TOExecutionResult.success(this, details);
    } catch (IOException e) {
        result = TOExecutionResult.error(this, e);
    }

    return result;
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:24,代码来源:AddLine.java

示例2: checkGeneration

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
private void checkGeneration(String name) throws URISyntaxException, IOException, JAXBException {
    URL testfileUrl = getClass().getResource(name + ".groovy");
    URL testfileResultUrl = getClass().getResource(name + ".xml");
    URL testfileResultUrlYaml = getClass().getResource(name + ".yaml");

    File file = new File(testfileUrl.toURI());
    File resultFile = new File(testfileResultUrl.toURI());
    File resultFileYaml = new File(testfileResultUrlYaml.toURI());


    Node updateScriptNode = XmlGenerator.getUpdateScriptNode(getInterpretingClass(file));
    StringWriter writer = new StringWriter();

    getMarshaller().marshal(updateScriptNode, writer);
    final String xml = writer.toString();
    final String yaml = getYamlString(YamlGenerator.getUpdateYamlScript(getInterpretingClass(file)));

    String expectedContent = FileUtils.fileRead(resultFile);
    String expectedContentYaml = FileUtils.fileRead(resultFileYaml);
    assertEquals("failed xml parsing of " + name, expectedContent, xml);
    assertEquals("failed yaml parsing of " + name, expectedContentYaml, yaml);

}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:24,代码来源:TestUpdaterTransforming.java

示例3: storeThemeProperties

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
/**
 * Stores the given properties object in a file named <code>theme-derived.properties</code> within the
 * given theme directory
 *
 * @param themeDirectory directory the properties file should be created in
 * @param themeProperties properties that should be written to the properties file
 * @throws IOException
 */
public static void storeThemeProperties(String themeDirectory, Properties themeProperties) throws IOException {
    File propertiesFile = new File(themeDirectory, ThemeBuilderConstants.THEME_DERIVED_PROPERTIES_FILE);

    // need to remove file if already exists so the new properties will be written
    if (propertiesFile.exists()) {
        FileUtils.forceDelete(propertiesFile);
    }

    FileWriter fileWriter = null;

    try {
        fileWriter = new FileWriter(propertiesFile);

        themeProperties.store(fileWriter, null);
    } finally {
        if (fileWriter != null) {
            fileWriter.close();
        }
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:29,代码来源:ThemeBuilderUtils.java

示例4: copyFile

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
/**
 * Does the actual copy of the file and logging.
 *
 * @param artifact represents the file to copy.
 * @param destFile file name of destination file.
 *
 * @throws MojoExecutionException with a message if an
 *             error occurs.
 */
protected void copyFile ( File artifact, File destFile )
    throws MojoExecutionException
{
    Log theLog = this.getLog();
    try
    {
        theLog.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 );
    }
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:27,代码来源:AbstractDependencyMojo.java

示例5: addProperty

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
private TOExecutionResult addProperty(File transformedAppFolder, TransformationContext transformationContext) {
    File fileToBeChanged = getAbsoluteFile(transformedAppFolder, transformationContext);
    TOExecutionResult result;
    try {
        String[] propArray = {propertyName, propertyValue};
        String propertyKeyValue = "%s = %s";
        String propertyToBeAdded = String.format(propertyKeyValue, propArray);
        FileUtils.fileAppend(fileToBeChanged.getAbsolutePath(), EolHelper.findEolDefaultToOs(fileToBeChanged));
        FileUtils.fileAppend(fileToBeChanged.getAbsolutePath(), propertyToBeAdded);
        String details = String.format("Property '%s' has been added and set to '%s' at '%s'", propertyName, propertyValue, getRelativePath());
        result = TOExecutionResult.success(this, details);
    } catch (IOException e) {
        result = TOExecutionResult.error(this, e);
    }
    return result;
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:17,代码来源:AddProperty.java

示例6: execution

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
    File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext);
    File fileTo = getFileTo(transformedAppFolder, transformationContext);
    TOExecutionResult result = null;

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

    try {
        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, e);
    }

    return result;
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:21,代码来源:MoveFile.java

示例7: execution

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
    File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext);
    File fileTo = getFileTo(transformedAppFolder, transformationContext);
    TOExecutionResult result = null;

    try {
        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, e);
    }

    return result;
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:17,代码来源:CopyFile.java

示例8: getInterpretingClassStrippingCode

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
public static ScriptClass getInterpretingClassStrippingCode(final File file) {
    groovyClassLoader.clearCache();
    String script;
    try {
        script = FileUtils.fileRead(file);

        String imports = getAnnotationClasses().stream()
                .map(clazz -> "import " + clazz.getCanonicalName() + ";")
                .collect(joining());

        String interpretCode =  imports + script.replaceAll("import .+\n", "")
                .replaceAll("package\\s.*\n", "")
                .replaceAll("extends\\s.*\\{[^\\u001a]*", "{}");

        interpretCode = scrubAnnotations(interpretCode);

        return new ScriptClass(file, groovyClassLoader.parseClass(interpretCode), script);
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:22,代码来源:ScriptClassFactory.java

示例9: generateHippoEcmExtensions

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
@Test
public void generateHippoEcmExtensions() throws URISyntaxException, IOException, JAXBException {
    URI resourceURI = getClass().getResource("").toURI();
    File root = new File(resourceURI);
    List<ScriptClass> scriptClasses = ScriptClassFactory.getScriptClasses(root);
    Node node = XmlGenerator.getEcmExtensionNode(root, new File(root, "target"), scriptClasses, "my-updater-prefix-");

    StringWriter writer = new StringWriter();

    getMarshaller().marshal(node, writer);
    final String xml = writer.toString();
    URL testfileResultUrl = getClass().getResource("resulting-hippoecm-extension.xml");
    File resultFile = new File(testfileResultUrl.toURI());

    String expectedContent = FileUtils.fileRead(resultFile);
    assertEquals(expectedContent, xml);
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:18,代码来源:TestUpdaterTransforming.java

示例10: generateNewHippoEcmExtensions

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
@Test
public void generateNewHippoEcmExtensions() throws URISyntaxException, IOException, JAXBException {
    URI resourceURI = getClass().getResource("sub").toURI();
    File root = new File(resourceURI);
    List<ScriptClass> scriptClasses = ScriptClassFactory.getScriptClasses(root);
    Node node = XmlGenerator.getEcmExtensionNode(root, new File(root, "target"), scriptClasses, "my-updater-prefix-");

    StringWriter writer = new StringWriter();

    getMarshaller().marshal(node, writer);
    final String xml = writer.toString();
    URL testfileResultUrl = getClass().getResource("sub-hippoecm-extension.xml");
    File resultFile = new File(testfileResultUrl.toURI());

    String expectedContent = FileUtils.fileRead(resultFile);
    assertEquals(expectedContent, xml);
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:18,代码来源:TestUpdaterTransforming.java

示例11: generateHcmActions

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
@Test
public void generateHcmActions() throws URISyntaxException, IOException {
    URI resourceURI = getClass().getResource("").toURI();
    File root = new File(resourceURI);
    List<File> groovyFiles = Generator.getGroovyFiles(root);

    //registry or unversioned scripts
    List<ScriptClass> scriptClassesToReload = groovyFiles.stream().map(ScriptClassFactory::getInterpretingClass)
            .filter(this::isRegistryOrUnversioned)
            .collect(toList());

    String yaml = YamlGenerator.getHcmActionsList(root, new File(root, "target"), scriptClassesToReload);

    URL testfileResultUrl = getClass().getResource("resulting-hcm-actions.yaml");
    File resultFile = new File(testfileResultUrl.toURI());
    String expectedContent = FileUtils.fileRead(resultFile);
    assertEquals(expectedContent, yaml);
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:19,代码来源:TestUpdaterTransforming.java

示例12: execute

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
/**
 * Called by the project to let the task do its work.
 * This will invoke PatternGenerator for each file in the nested FileSet(s).
 *
 * @throws MojoExecutionException if something goes wrong.
 */
public void execute() throws MojoExecutionException {
    PatternGenerator pg = null;
    try {
        File directory = new File(fileSet.getDirectory());
        String includes = StringUtils.join(fileSet.getIncludes(), ",");
        String excludes = StringUtils.join(fileSet.getExcludes(), ",");
        List<File> fileList = FileUtils.getFiles(directory, includes, excludes);
        for (File file : fileList) {
            pg = new PatternGenerator(file.toURI().toURL());
            pg.setData(fileList);
            pg.processPattern();
            pg.destroy();
            pg = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error in executing PatternGeneratorMojo: " + e.getMessage(), e);
    } finally {
        if (pg != null) {
            pg.destroy();
        }
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:30,代码来源:PatternGeneratorMojo.java

示例13: unpackOverlay

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
/**
 * Unpacks the specified overlay.
 * <p/>
 * Makes sure to skip the unpack process if the overlay has already been unpacked.
 *
 * @param context the packaging context
 * @param overlay the overlay
 * @return the directory containing the unpacked overlay
 * @throws MojoExecutionException if an error occurred while unpacking the overlay
 */
protected File unpackOverlay( WarPackagingContext context, Overlay overlay )
    throws MojoExecutionException
{
    final File tmpDir = getOverlayTempDirectory( context, overlay );

    // TODO: not sure it's good, we should reuse the markers of the dependency plugin
    if ( FileUtils.sizeOfDirectory( tmpDir ) == 0
        || overlay.getArtifact().getFile().lastModified() > tmpDir.lastModified() )
    {
        doUnpack( context, overlay.getArtifact().getFile(), tmpDir );
    }
    else
    {
        context.getLog().debug( "Overlay [" + overlay + "] was already unpacked" );
    }
    return tmpDir;
}
 
开发者ID:zhegexiaohuozi,项目名称:maven-seimicrawler-plugin,代码行数:28,代码来源:OverlayPackagingTask.java

示例14: testShellScriptGenerationWithFalseShowConsoleWindow

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
private void testShellScriptGenerationWithFalseShowConsoleWindow( Platform platform )
    throws Exception
{
    ScriptGenerator generator = (ScriptGenerator) lookup( ScriptGenerator.ROLE );

    Daemon daemon = new Daemon();

    daemon.setShowConsoleWindow( false );
    daemon.setId( "test" );
    daemon.setMainClass( "foo.Bar" );
    daemon.setJvmSettings( new JvmSettings() );
    daemon.getJvmSettings().setExtraArguments( Arrays.asList( new String[] { "Yo", "dude" } ) );
    daemon.setEnvironmentSetupFileName( "setup" );
    daemon.setRepositoryName( "repo" );
    File outputDirectory = getTestFile( "target/test-output/background-shell/" + platform.getName() );

    generator.createBinScript( platform.getName(), daemon, outputDirectory, "bin" );

    File expectedFile = getTestFile( PREFIX + "expected-false-showConsoleWindow-" + daemon.getId()
        + platform.getBinFileExtension() );
    File actualFile = new File( outputDirectory, "bin/" + daemon.getId() + platform.getBinFileExtension() );

    assertEquals( FileUtils.fileRead( expectedFile ), FileUtils.fileRead( actualFile ) );
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:25,代码来源:ScriptGeneratorBackgroundTest.java

示例15: testNormalShellScriptGeneration

import org.codehaus.plexus.util.FileUtils; //导入依赖的package包/类
private void testNormalShellScriptGeneration( Platform platform )
    throws Exception
{
    ScriptGenerator generator = (ScriptGenerator) lookup( ScriptGenerator.ROLE );

    Daemon daemon = new Daemon();

    daemon.setId( "test" );
    daemon.setMainClass( "foo.Bar" );
    daemon.setJvmSettings( new JvmSettings() );
    daemon.getJvmSettings().setExtraArguments( Arrays.asList( new String[] { "Yo", "dude" } ) );
    daemon.setEnvironmentSetupFileName( "setup" );
    daemon.setRepositoryName( "repo" );
    File outputDirectory = getTestFile( "target/test-output/normal-shell/" + platform.getName() );

    generator.createBinScript( platform.getName(), daemon, outputDirectory, "bin" );

    File expectedFile = getTestFile( PREFIX + "expected-" + daemon.getId() + platform.getBinFileExtension() );
    File actualFile = new File( outputDirectory, "bin/" + daemon.getId() + platform.getBinFileExtension() );

    assertEquals( FileUtils.fileRead( expectedFile ), FileUtils.fileRead( actualFile ) );
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:23,代码来源:ScriptGeneratorTest.java


注:本文中的org.codehaus.plexus.util.FileUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。