use of org.apache.maven.plugins.clean.CleanMojo in project maven-plugins by apache.
the class CleanMojoTest method testCleanLockedFile.
/**
* Test the removal of a locked file on Windows systems.
* <br/>
* Note: Unix systems doesn't lock any files.
*
* @throws Exception
*/
public void testCleanLockedFile() throws Exception {
if (!System.getProperty("os.name").toLowerCase().contains("windows")) {
assertTrue("Ignored this test on none Windows based systems", true);
return;
}
String pluginPom = getBasedir() + "/src/test/resources/unit/locked-file-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/locked-file-test"), new File(getBasedir(), "target/test-classes/unit/locked-file-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupMojo("clean", pluginPom);
assertNotNull(mojo);
File f = new File(getBasedir(), "target/test-classes/unit/locked-file-test/buildDirectory/file.txt");
FileChannel channel = null;
FileLock lock = null;
try {
channel = new RandomAccessFile(f, "rw").getChannel();
lock = channel.lock();
mojo.execute();
fail("Should fail to delete a file that is locked");
} catch (MojoExecutionException expected) {
assertTrue(true);
} finally {
if (lock != null) {
lock.release();
}
if (channel != null) {
channel.close();
}
}
}
use of org.apache.maven.plugins.clean.CleanMojo in project maven-plugins by apache.
the class CleanMojoTest method testMissingDirectory.
/**
* Tests the removal of a missing directory
*
* @throws Exception
*/
public void testMissingDirectory() throws Exception {
String pluginPom = getBasedir() + "/src/test/resources/unit/missing-directory-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/missing-directory-test"), new File(getBasedir(), "target/test-classes/unit/missing-directory-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupMojo("clean", pluginPom);
assertNotNull(mojo);
mojo.execute();
assertFalse(checkExists(getBasedir() + "/target/test-classes/unit/missing-directory-test/does-not-exist"));
}
use of org.apache.maven.plugins.clean.CleanMojo in project maven-plugins by apache.
the class CleanMojoTest method testCleanLockedFileWithNoError.
/**
* Test the removal of a locked file on Windows systems.
* <br/>
* Note: Unix systems doesn't lock any files.
*
* @throws Exception
*/
public void testCleanLockedFileWithNoError() throws Exception {
if (!System.getProperty("os.name").toLowerCase().contains("windows")) {
assertTrue("Ignored this test on none Windows based systems", true);
return;
}
String pluginPom = getBasedir() + "/src/test/resources/unit/locked-file-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/locked-file-test"), new File(getBasedir(), "target/test-classes/unit/locked-file-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupMojo("clean", pluginPom);
setVariableValueToObject(mojo, "failOnError", Boolean.FALSE);
assertNotNull(mojo);
File f = new File(getBasedir(), "target/test-classes/unit/locked-file-test/buildDirectory/file.txt");
FileChannel channel = null;
FileLock lock = null;
try {
channel = new RandomAccessFile(f, "rw").getChannel();
lock = channel.lock();
mojo.execute();
assertTrue(true);
} catch (MojoExecutionException expected) {
fail("Should display a warning when deleting a file that is locked");
} finally {
if (lock != null) {
lock.release();
}
if (channel != null) {
channel.close();
}
}
}
use of org.apache.maven.plugins.clean.CleanMojo in project maven-clean-plugin by apache.
the class CleanMojoTest method testFilesetsClean.
/**
* Tests the removal of files using fileset
*
* @throws Exception in case of an error.
*/
public void testFilesetsClean() throws Exception {
String pluginPom = getBasedir() + "/src/test/resources/unit/fileset-clean-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/fileset-clean-test"), new File(getBasedir(), "target/test-classes/unit/fileset-clean-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupMojo("clean", pluginPom);
assertNotNull(mojo);
mojo.execute();
// fileset 1
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target"));
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target/classes"));
assertFalse(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target/test-classes"));
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target/subdir"));
assertFalse(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target/classes/file.txt"));
assertTrue(checkEmpty(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target/classes"));
assertFalse(checkEmpty(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target/subdir"));
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/target/subdir/file.txt"));
// fileset 2
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/" + "buildOutputDirectory"));
assertFalse(checkExists(getBasedir() + "/target/test-classes/unit/fileset-clean-test/" + "buildOutputDirectory/file.txt"));
}
use of org.apache.maven.plugins.clean.CleanMojo in project maven-clean-plugin by apache.
the class CleanMojoTest method testCleanEmptyDirectories.
/**
* Tests that no exception is thrown when all internal variables are empty and that it doesn't
* just remove whats there
*
* @throws Exception in case of an error.
*/
public void testCleanEmptyDirectories() throws Exception {
String pluginPom = getBasedir() + "/src/test/resources/unit/empty-clean-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/empty-clean-test"), new File(getBasedir(), "target/test-classes/unit/empty-clean-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupEmptyMojo("clean", pluginPom);
assertNotNull(mojo);
mojo.execute();
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/empty-clean-test/testDirectoryStructure"));
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/empty-clean-test/" + "testDirectoryStructure/file.txt"));
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/empty-clean-test/" + "testDirectoryStructure/outputDirectory"));
assertTrue(checkExists(getBasedir() + "/target/test-classes/unit/empty-clean-test/" + "testDirectoryStructure/outputDirectory/file.txt"));
}
Aggregations