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

The following examples show how to use org.codehaus.plexus.util.FileUtils#fileDelete() . 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: MoveFile.java    From butterfly with MIT License 6 votes vote down vote up
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
    File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext);
    File fileTo = getFileTo(transformedAppFolder, transformationContext);
    TOExecutionResult result;

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

    try {
        if (fileFrom.isDirectory()) {
            IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)");
            result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", ex));
        } else {
            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, new TransformationOperationException("File could not be moved", e));
    }

    return result;
}
 
Example 2
Source File: TransformMojoTest.java    From xml-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the it7 test project.
 * @throws Exception The test failed.
 */
public void testIt7()
    throws Exception
{
    final File dir = new File( "src/test/it7" );
    final File target = new File( dir, "target/generated-resources/xml/xslt/doc1.xml" );
    TransformMojo mojo = (TransformMojo) newMojo( dir.getPath() );
    FileUtils.fileDelete( target.getPath() );
    mojo.execute();
    String result = read( target );
    assertFalse( result.startsWith( "<?xml" ) );
    mojo = (TransformMojo) newMojo( "src/test/it7" );
    TransformationSet[] transformationSets =
        (TransformationSet[]) getVariableValueFromObject( mojo, "transformationSets" );
    transformationSets[0].getOutputProperties()[0].setValue( "no" );
    FileUtils.fileDelete( target.getPath() );
    mojo.execute();
    result = read( target );
    assertTrue( result.startsWith( "<?xml" ) );
}
 
Example 3
Source File: BuildFrontendMojoTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@After
public void teardown() throws IOException {
    if (FileUtils.fileExists(packageJson)) {
        FileUtils.fileDelete(packageJson);
    }
    if (FileUtils.fileExists(webpackConfig)) {
        FileUtils.fileDelete(webpackConfig);
    }
}
 
Example 4
Source File: AjcHelperTest.java    From aspectj-maven-plugin with MIT License 5 votes vote down vote up
/**
 * 
 * @throws Exception
 */
public void testBuildConfigFile()
{
    final File baseDir = new File(".");
    final String fileName = "test.lst";
    final String fileAbsolutePath = baseDir.getAbsolutePath() + File.separator + fileName;
    
    List args = new ArrayList();
    args.add("-classpath");
    args.add("a:b:c");
    args.add("-showWeaveInfo");
    args.add("/home/aspectj/AFile");
    args.add("/home/aspectj/AnotherFile");
    try
    {
        AjcHelper.writeBuildConfigToFile(args,fileName,baseDir);
        assertTrue("Config file not written to disk",FileUtils.fileExists(fileAbsolutePath));
        List readArgs = AjcHelper.readBuildConfigFile(fileName,baseDir);
        assertEquals(args,readArgs);
    } catch (Exception e)
    {
        fail("Unexpected exception: " + e.toString());
        if (FileUtils.fileExists(fileAbsolutePath))
        {
            FileUtils.fileDelete(fileAbsolutePath);
        }
    }
}
 
Example 5
Source File: AjcCompilerMojoTest.java    From aspectj-maven-plugin with MIT License 4 votes vote down vote up
/**
 * @throws Exception
 */
public void testModificationSet()
    throws Exception
{
        ajcMojo.aspectDirectory = "src/main/aspect";
        final String[] includes = new String[]{"org/codehaus/mojo/aspectj/OldStyleAspect.aj"};
        ajcMojo.setArgumentFileName("builddef.lst");
        FileUtils.fileDelete(project.getBuild().getDirectory() + ajcMojo.argumentFileName);

        ajcMojo.includes= new String[]{"org/codehaus/mojo/aspectj/OldStyleAspect.aj"};
        ajcMojo.assembleArguments();
        assertTrue("Build should be needed when no previous files are found",ajcMojo.isBuildNeeded());

        try
        {
            ajcMojo.ajcOptions.clear();
            ajcMojo.includes = includes;
            ajcMojo.execute();
        }
        catch ( CompilationFailedException cfe )
        {
            // we're only testing modifications, don't care if it won't compile
        }
        catch ( UnsupportedClassVersionError ucve )
        {
            // we're only testing modifications, don't care if it won't compile
        }

        ajcMojo.ajcOptions.clear();
        ajcMojo.includes = includes;
        ajcMojo.assembleArguments();
        assertFalse("A build has compleeted. No modifications done. no new build needed",ajcMojo.isBuildNeeded());

        ajcMojo.ajcOptions.clear();
        ajcMojo.includes = includes;
        ajcMojo.setShowWeaveInfo(true);
        ajcMojo.assembleArguments();
        assertTrue("One of the arguments has changed, a new build is needed",ajcMojo.isBuildNeeded());


        ajcMojo.ajcOptions.clear();
        ajcMojo.includes = includes;
        ajcMojo.assembleArguments();
        assertFalse("A build has compleeted. No modifications done. no new build needed",ajcMojo.isBuildNeeded());
        String currentDir = new File(".").getAbsolutePath();
        File aspect = new File(currentDir.substring(0,currentDir.length()-1)+"src/test/projects/test-project/src/main/aspect/org/codehaus/mojo/aspectj/OldStyleAspect.aj");
        long timeStamp = System.currentTimeMillis();
        assertTrue("Could not touch file: " + aspect.getAbsolutePath(), aspect.setLastModified(timeStamp));
        assertTrue("One of the included files has changed. a new build is needed",ajcMojo.isBuildNeeded());
}