use of org.apache.maven.plugins.clean.CleanMojo in project maven-clean-plugin by apache.
the class CleanMojoTest method testCleanInvalidDirectory.
/**
* Tests the removal of a directory as file
*
* @throws Exception in case of an error.
*/
public void testCleanInvalidDirectory() throws Exception {
String pluginPom = getBasedir() + "/src/test/resources/unit/invalid-directory-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/invalid-directory-test"), new File(getBasedir(), "target/test-classes/unit/invalid-directory-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupMojo("clean", pluginPom);
assertNotNull(mojo);
try {
mojo.execute();
fail("Should fail to delete a file treated as a directory");
} catch (MojoExecutionException expected) {
assertTrue(true);
}
}
use of org.apache.maven.plugins.clean.CleanMojo in project maven-clean-plugin by apache.
the class CleanMojoTest method testCleanLockedFile.
/**
* Test the removal of a locked file on Windows systems.
* <p>
* Note: Unix systems doesn't lock any files.
* </p>
*
* @throws Exception in case of an error.
*/
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-clean-plugin by apache.
the class CleanMojoTest method testCleanNestedStructure.
/**
* Tests the removal of files and nested directories
*
* @throws Exception in case of an error.
*/
public void testCleanNestedStructure() throws Exception {
String pluginPom = getBasedir() + "/src/test/resources/unit/nested-clean-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/nested-clean-test"), new File(getBasedir(), "target/test-classes/unit/nested-clean-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupMojo("clean", pluginPom);
assertNotNull(mojo);
mojo.execute();
assertFalse(checkExists(getBasedir() + "/target/test-classes/unit/nested-clean-test/target"));
assertFalse(checkExists(getBasedir() + "/target/test-classes/unit/nested-clean-test/target/classes"));
assertFalse(checkExists(getBasedir() + "/target/test-classes/unit/nested-clean-test/target/test-classes"));
}
use of org.apache.maven.plugins.clean.CleanMojo in project maven-clean-plugin by apache.
the class CleanMojoTest method testMissingDirectory.
/**
* Tests the removal of a missing directory
*
* @throws Exception in case of an error.
*/
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-clean-plugin by apache.
the class CleanMojoTest method testBasicClean.
/**
* Tests the simple removal of directories
*
* @throws Exception in case of an error.
*/
public void testBasicClean() throws Exception {
String pluginPom = getBasedir() + "/src/test/resources/unit/basic-clean-test/plugin-pom.xml";
// safety
FileUtils.copyDirectory(new File(getBasedir(), "src/test/resources/unit/basic-clean-test"), new File(getBasedir(), "target/test-classes/unit/basic-clean-test"), null, "**/.svn,**/.svn/**");
CleanMojo mojo = (CleanMojo) lookupMojo("clean", pluginPom);
assertNotNull(mojo);
mojo.execute();
assertFalse("Directory exists", checkExists(getBasedir() + "/target/test-classes/unit/" + "basic-clean-test/buildDirectory"));
assertFalse("Directory exists", checkExists(getBasedir() + "/target/test-classes/unit/basic-clean-test/" + "buildOutputDirectory"));
assertFalse("Directory exists", checkExists(getBasedir() + "/target/test-classes/unit/basic-clean-test/" + "buildTestDirectory"));
}
Aggregations