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

The following examples show how to use org.codehaus.plexus.util.FileUtils#copyDirectoryStructure() . 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: DefaultIOUtil.java    From webstart with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void copyDirectoryStructure( File sourceDirectory, File targetDirectory )
        throws MojoExecutionException
{

    makeDirectoryIfNecessary( targetDirectory );

    // hopefully available from FileUtils 1.0.5-SNAPSHOT
    try
    {
        FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
    }
    catch ( IOException e )
    {
        throw new MojoExecutionException(
                "Could not copy directory structure from " + sourceDirectory + " to " + targetDirectory, e );
    }
}
 
Example 2
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
@Test
public void basicItTest()
    throws Exception
{
    Assume.assumeTrue( isSvn18() );

    File projDir = resources.getBasedir( "basic-it" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File testDir = result.getBasedir();
    FileUtils.copyDirectoryStructure( new File( testDir, "dotSvnDir" ), new File( testDir, ".svn" ) );
    result = mavenExec.execute( "clean", "verify" );
    result.assertLogText( "Storing buildNumber: 14069" );
    result.assertLogText( "Storing buildScmBranch: trunk" );

    File artifact = new File( testDir, "target/buildnumber-maven-plugin-basic-it-1.0-SNAPSHOT.jar" );
    JarFile jarFile = new JarFile( artifact );
    Attributes manifest = jarFile.getManifest().getMainAttributes();
    jarFile.close();
    String scmRev = manifest.getValue( "SCM-Revision" );
    Assert.assertEquals( "14069", scmRev );
}
 
Example 3
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
@Test
public void basicItGitTest()
    throws Exception
{
    File projDir = resources.getBasedir( "basic-it-git" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File testDir = result.getBasedir();
    FileUtils.copyDirectoryStructure( new File( testDir, "dotGitDir" ), new File( testDir, ".git" ) );
    result = mavenExec.execute( "clean", "verify" );
    result.assertLogText( "Storing buildNumber: 6d36c746e82f00c5913954f9178f40224497b2f3" );
    result.assertLogText( "Storing buildScmBranch: master" );

    File artifact = new File( testDir, "target/buildnumber-maven-plugin-basic-it-1.0-SNAPSHOT.jar" );
    JarFile jarFile = new JarFile( artifact );
    Attributes manifest = jarFile.getManifest().getMainAttributes();
    jarFile.close();
    String scmRev = manifest.getValue( "SCM-Revision" );
    Assert.assertEquals( "6d36c746e82f00c5913954f9178f40224497b2f3", scmRev );
}
 
Example 4
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
@Test
public void basicItNoDevScmTest()
    throws Exception
{
    Assume.assumeTrue( isSvn18() );

    File projDir = resources.getBasedir( "basic-it-no-devscm" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File testDir = result.getBasedir();
    FileUtils.copyDirectoryStructure( new File( testDir, "dotSvnDir" ), new File( testDir, ".svn" ) );
    result = mavenExec.execute( "clean", "verify" );
    result.assertLogText( "Storing buildNumber: 14069" );
    result.assertLogText( "Storing buildScmBranch: trunk" );

    File artifact = new File( testDir, "target/buildnumber-maven-plugin-basic-it-no-devscm-1.0-SNAPSHOT.jar" );
    JarFile jarFile = new JarFile( artifact );
    Attributes manifest = jarFile.getManifest().getMainAttributes();
    jarFile.close();
    String scmRev = manifest.getValue( "SCM-Revision" );
    Assert.assertEquals( "14069", scmRev );
}
 
Example 5
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
@Test
public void basicItSvnJavaTest()
    throws Exception
{
    Assume.assumeTrue( isSvn18() );

    File projDir = resources.getBasedir( "basic-it-svnjava" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File testDir = result.getBasedir();
    FileUtils.copyDirectoryStructure( new File( testDir, "dotSvnDir" ), new File( testDir, ".svn" ) );
    result = mavenExec.execute( "clean", "verify" );
    result.assertLogText( "Storing buildNumber: 19665" );
    result.assertLogText( "Storing buildScmBranch: trunk" );

    File artifact = new File( testDir, "target/buildnumber-maven-plugin-basic-it-svnjava-1.0-SNAPSHOT.jar" );
    JarFile jarFile = new JarFile( artifact );
    Attributes manifest = jarFile.getManifest().getMainAttributes();
    jarFile.close();
    String scmRev = manifest.getValue( "SCM-Revision" );
    Assert.assertEquals( "19665", scmRev );
}
 
Example 6
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
@Test
public void failLocalChangeItTest()
    throws Exception
{
    File projDir = resources.getBasedir( "failed-local-change" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File basedir = result.getBasedir();
    File foo = new File( basedir, "foo.txt" );
    FileUtils.fileWrite( foo, "hello" );
    FileUtils.copyDirectoryStructure( new File( basedir, "dotSvnDir" ), new File( basedir, ".svn" ) );
    result = mavenExec.execute( "verify" );
    result.assertLogText( "BUILD FAILURE" );
    result.assertLogText( "because you have local modifications" );
}
 
Example 7
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
@Test
public void gitBasicItMBUILDNUM66Test()
    throws Exception
{
    File projDir = resources.getBasedir( "git-basic-it-MBUILDNUM-66" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File basedir = result.getBasedir();
    File foo = new File( basedir, "foo.txt" );
    FileUtils.fileWrite( foo, "hello" );
    FileUtils.copyDirectoryStructure( new File( basedir, "dotGitDir" ), new File( basedir, ".git" ) );
    result = mavenExec.execute( "verify" );
    result.assertLogText( "Storing buildScmBranch: master" );
    File testDir = result.getBasedir();
    File artifact = new File( testDir, "target/buildnumber-maven-plugin-basic-it-1.0-SNAPSHOT.jar" );
    JarFile jarFile = new JarFile( artifact );
    Attributes manifest = jarFile.getManifest().getMainAttributes();
    jarFile.close();
    String scmRev = manifest.getValue( "SCM-Revision" );
    Assert.assertEquals( "ee58acb27b6636a497c1185f80cd15f76134113f", scmRev );

}
 
Example 8
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
@Test
public void Mojo1668Test()
    throws Exception
{
    Assume.assumeTrue( isSvn18() );

    File projDir = resources.getBasedir( "MOJO-1668" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File testDir = result.getBasedir();
    FileUtils.copyDirectoryStructure( new File( testDir, "dotSvnDir" ), new File( testDir, ".svn" ) );
    result = mavenExec.execute( "clean", "verify" );

    File artifact = new File( testDir, "target/buildnumber-maven-plugin-MOJO-1668-1.0-SNAPSHOT.jar" );
    JarFile jarFile = new JarFile( artifact );
    Attributes manifest = jarFile.getManifest().getMainAttributes();
    jarFile.close();
    String buildDate = manifest.getValue( "Build-Date" );
    Assert.assertTrue( buildDate.length() > 0 );
}
 
Example 9
Source File: CLIEmbedUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void copyServerBaseDir(final File root, final String baseDirName, final String newbaseDirName, boolean force) throws IOException {
    // copy the base server directory (standalone etc to a new name to test changing jboss.server.base.dir etc)
    final File baseDir = new File(root + File.separator + baseDirName);
    assertTrue(baseDir.exists());
    final File newBaseDir = new File(root + File.separator + newbaseDirName);
    assertFalse(!force && newBaseDir.exists());
    FileUtils.copyDirectoryStructure(baseDir, newBaseDir);
    assertTrue(newBaseDir.exists());

    // remove anything we'll auto-create on startup
    final String[] cleanDirs = {"content", "data", "deployments", "log", "tmp"};
    for (final String dir : cleanDirs) {
        FileUtils.deleteDirectory(root + File.separator + newbaseDirName + File.separator + dir);
    }
}
 
Example 10
Source File: ThemeBuilderUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Copies all the contents from the directory given by the source path to the directory given by the
 * target path
 *
 * <p>
 * If source directory does not exist nothing is performed. The target directory will be created if it
 * does not exist. Any hidden directories (directory names that start with ".") will be deleted from the
 * target directory
 * </p>
 *
 * @param sourceDirectoryPath absolute path to the source directory
 * @param targetDirectoryPath absolute path to the target directory
 * @throws IOException
 */
public static void copyDirectory(String sourceDirectoryPath, String targetDirectoryPath)
        throws IOException {
    File sourceDir = new File(sourceDirectoryPath);

    if (!sourceDir.exists()) {
        return;
    }

    File targetDir = new File(targetDirectoryPath);
    if (targetDir.exists()) {
        // force removal so the copy starts clean
        FileUtils.forceDelete(targetDir);
    }

    targetDir.mkdir();

    FileUtils.copyDirectoryStructure(sourceDir, targetDir);

    // remove hidden directories from the target
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(targetDir);

    scanner.scan();

    for (String includedDirectory : scanner.getIncludedDirectories()) {
        File subdirectory = new File(targetDir, includedDirectory);

        if (subdirectory.exists() && subdirectory.isDirectory()) {
            if (subdirectory.getName().startsWith(".")) {
                FileUtils.forceDelete(subdirectory);
            }
        }
    }
}
 
Example 11
Source File: GitWagon.java    From opoopress with Apache License 2.0 4 votes vote down vote up
public void putDirectory(File sourceDirectory, String destinationDirectory) 
		throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
	if (!sourceDirectory.isDirectory()) {
		throw new IllegalArgumentException("Source is not a directory: " + sourceDirectory);
	}
	String resourceName = FilenameUtils.separatorsToUnix(destinationDirectory);
	Resource resource = new Resource(resourceName);
	firePutInitiated(resource, sourceDirectory);
	firePutStarted(resource, sourceDirectory);
	
	Repository repo = getRepository();
	String url = repo.getUrl();

	if (url.endsWith("/")){
		url = url.substring(0, url.length() - 1);
	}

	String remote = url.substring(4);
	String branch = repo.getParameter("branch");
	String message = repo.getParameter("message");

	if(remote.startsWith("default://")){
		remote = remote.substring(10);
	}
	
	if(branch == null){
		branch = "master";
	}
	
	try {
		Git git = new Git(checkoutDirectory, remote, branch);
		
		if(message != null){
			git.setMessage(message);
		}
		
		if(safeCheckout){//not cache, clone every time
			git.cloneAll();
		}else{
			git.pullAll();
		}
		
		FileUtils.copyDirectoryStructure(sourceDirectory, new File(checkoutDirectory, destinationDirectory));
		
		git.pushAll();
	} catch (Exception e) {
		fireTransferError(resource, e, TransferEvent.REQUEST_PUT);
		throw new TransferFailedException("Unable to put file", e);
	}

	firePutCompleted(resource, sourceDirectory);
}
 
Example 12
Source File: JCasGenMojoTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void test(String projectName, String... types) throws Exception {

    File projectSourceDirectory = getTestFile("src/test/resources/" + projectName);
    File projectDirectory = getTestFile("target/project-" + projectName + "-test");

    // Stage project to target folder
    FileUtils.copyDirectoryStructure(projectSourceDirectory, projectDirectory);
    
    File pomFile = new File(projectDirectory, "/pom.xml");
    assertNotNull(pomFile);
    assertTrue(pomFile.exists());

    // create the MavenProject from the pom.xml file
    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
    MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
    assertNotNull(project);

    // copy resources
    File source = new File(projectDirectory, "src/main/resources");
    if (source.exists()) {
      FileUtils.copyDirectoryStructure(source, new File(project.getBuild().getOutputDirectory()));
    }
    
    // load the Mojo
    JCasGenMojo generate = (JCasGenMojo) this.lookupConfiguredMojo(project, "generate");
    assertNotNull(generate);

    // set the MavenProject on the Mojo (AbstractMojoTestCase does not do this by default)
    setVariableValueToObject(generate, "project", project);

    // execute the Mojo
    generate.execute();

    // check that the Java files have been generated
    File jCasGenDirectory = new File(project.getBasedir(), "target/generated-sources/jcasgen");
    
    // Record all the files that were generated
    DirectoryScanner ds = new DirectoryScanner();
    ds.setBasedir(jCasGenDirectory);
    ds.setIncludes(new String[] { "**/*.java" });
    ds.scan();
    List<File> files = new ArrayList<>();
    for (String scannedFile : ds.getIncludedFiles()) {
      files.add(new File(ds.getBasedir(), scannedFile));
    }
    
    for (String type : types) {
      File wrapperFile = new File(jCasGenDirectory + "/" + type.replace('.', '/') + ".java");
      // no _type files in v3
//      File typeFile = new File(jCasGenDirectory + "/" + type.replace('.', '/') + "_Type.java");
      
      Assert.assertTrue(files.contains(wrapperFile));
      // no _type files in v3
//      Assert.assertTrue(files.contains(typeFile));
      
      files.remove(wrapperFile);
//      files.remove(typeFile);
    }
    
    // check that no extra files were generated
    Assert.assertTrue(files.isEmpty());

    // check that the generated sources are on the compile path
    Assert.assertTrue(project.getCompileSourceRoots().contains(jCasGenDirectory.getAbsolutePath()));
  }