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

The following examples show how to use org.codehaus.plexus.util.FileUtils#forceMkdir() . 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: AjcHelper.java    From aspectj-maven-plugin with MIT License 6 votes vote down vote up
/**
 * Creates a file that can be used as input to the ajc compiler using the -argdfile flag.
 * Each line in these files should contain one option or filename.
 * Comments, as in Java, start with // and extend to the end of the line.
 *
 * @param arguments All arguments passed to ajc in this run
 * @param fileName the filename of the argfile
 * @param outputDir the build output area.
 * @throws IOException
 */
public static void writeBuildConfigToFile( List<String> arguments, String fileName, File outputDir )
    throws IOException
{
    FileUtils.forceMkdir( outputDir );
    File argFile = new File( outputDir, fileName );
    argFile.getParentFile().mkdirs();
    argFile.createNewFile();
    BufferedWriter writer = new BufferedWriter( new FileWriter( argFile ) );
    for ( String argument : arguments )
    {
        writer.write( argument );
        writer.newLine();
    }
    writer.flush();
    writer.close();
}
 
Example 2
Source File: EmbeddedGithubJsonToParquet.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private Path createDownloadDir(String workDir, String fileUrl) {
  Path downloadDirPath = Paths.get(workDir, DOWNLOAD_DIR);
  File downloadDirFile = downloadDirPath.toFile();
  try {
    Log.info(String.format("Creating download dir %s", downloadDirFile.toPath().toString()));
    FileUtils.forceMkdir(downloadDirFile);
  } catch (IOException e) {
    throw new RuntimeException(String
        .format("Unable to create download location for archive: %s at %s", fileUrl, downloadDirPath.toString()));
  }
  Log.info(String.format("Created download dir %s", downloadDirFile.toPath().toString()));
  return downloadDirPath;
}
 
Example 3
Source File: AbstractDependencyTest.java    From maven-native with MIT License 4 votes vote down vote up
protected void mkDir( String dirPath )
    throws IOException
{
    FileUtils.forceMkdir( new File( dirPath ) );
}
 
Example 4
Source File: BasicSupport.java    From ci.maven with Apache License 2.0 4 votes vote down vote up
protected void installFromFile() throws Exception {
    // Check if there is a different/newer archive or missing marker to trigger assembly install
    File installMarker = new File(installDirectory, ".installed");

    if (!refresh) {
        if (!installMarker.exists()) {
            refresh = true;
        } else if (assemblyArchive.lastModified() > installMarker.lastModified()) {
            log.debug(MessageFormat.format(messages.getString("debug.detect.assembly.archive"), ""));
            refresh = true;
        } else if(!assemblyArchive.getCanonicalPath().equals(FileUtils.fileRead(installMarker))) {
            refresh = true;
        }
    } else {
        log.debug(MessageFormat.format(messages.getString("debug.request.refresh"), ""));
    }

    String userDirectoryPath = userDirectory.getCanonicalPath();
    if (refresh && installDirectory.exists() && installDirectory.isDirectory()) {
        log.info(MessageFormat.format(messages.getString("info.uninstalling.server.home"), installDirectory));
        // Delete everything in the install directory except usr directory
        for(File f : installDirectory.listFiles()) {
            if(!(f.isDirectory() && f.getCanonicalPath().equals(userDirectoryPath))) {
                FileUtils.forceDelete(f);
            }
        }
    }

    // Install the assembly
    if (!installMarker.exists()) {
        log.info("Installing assembly...");

        FileUtils.forceMkdir(installDirectory);

        Expand unzip = (Expand) ant.createTask("unzip");

        unzip.setSrc(assemblyArchive);
        unzip.setDest(assemblyInstallDirectory.getCanonicalFile());
        unzip.execute();

        // Make scripts executable, since Java unzip ignores perms
        Chmod chmod = (Chmod) ant.createTask("chmod");
        chmod.setPerm("ugo+rx");
        chmod.setDir(installDirectory);
        chmod.setIncludes("bin/*");
        chmod.setExcludes("bin/*.bat");
        chmod.execute();

        // delete installMarker first in case it was packaged with the assembly
        installMarker.delete();
        installMarker.createNewFile();
        
        // Write the assembly archive path so we can determine whether to install a different assembly in future invocations
        FileUtils.fileWrite(installMarker, assemblyArchive.getCanonicalPath());
    } else {
        log.info(MessageFormat.format(messages.getString("info.reuse.installed.assembly"), ""));
    }
}
 
Example 5
Source File: AbstractDaemonGeneratorTest.java    From appassembler with MIT License 2 votes vote down vote up
public void runTest( String generatorId, String pom, String descriptor, String outputPath )
    throws Exception
{
    File outputDir = getTestFile( outputPath );

    DaemonGenerator generator = (DaemonGenerator) lookup( DaemonGenerator.ROLE, generatorId );

    // -----------------------------------------------------------------------
    // Build the MavenProject instance
    // -----------------------------------------------------------------------

    MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );

    MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) lookup( MavenSettingsBuilder.ROLE );
    Settings settings = settingsBuilder.buildSettings();

    ArtifactRepositoryFactory artifactRepositoryFactory =
        (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );

    String localRepoUrl = new File( settings.getLocalRepository() ).toURL().toExternalForm();

    ArtifactRepository localRepository =
        artifactRepositoryFactory.createDeploymentArtifactRepository( "local", localRepoUrl,
                                                                      new DefaultRepositoryLayout(), false );

    ProfileManager profileManager = new DefaultProfileManager( getContainer() );

    File tempPom = createFilteredFile( pom );

    MavenProject project = projectBuilder.buildWithDependencies( tempPom, localRepository, profileManager );

    // -----------------------------------------------------------------------
    // Clean the output directory
    // -----------------------------------------------------------------------

    FileUtils.deleteDirectory( outputDir );
    FileUtils.forceMkdir( outputDir );

    // -----------------------------------------------------------------------
    //
    // -----------------------------------------------------------------------

    DaemonGeneratorService daemonGeneratorService = (DaemonGeneratorService) lookup( DaemonGeneratorService.ROLE );

    Daemon model = daemonGeneratorService.loadModel( getTestFile( descriptor ) );

    generator.generate( new DaemonGenerationRequest( model, project, localRepository, outputDir, "bin" ) );
}