當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。