Example usage for org.apache.commons.io FileUtils cleanDirectory

List of usage examples for org.apache.commons.io FileUtils cleanDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils cleanDirectory.

Prototype

public static void cleanDirectory(File directory) throws IOException 

Source Link

Document

Cleans a directory without deleting it.

Usage

From source file:de.tarent.maven.plugins.pkg.packager.IzPackPackager.java

/**
 * Creates the temporary and package base directory.
 * /* w  w  w . j  a v  a  2s  .  co m*/
 * @param l
 * @param basePkgDir
 * @throws MojoExecutionException
 */
private void prepareDirectories(Log l, File tempRoot, File izPackEmbeddedRoot, File srcDir,
        File tempDescriptorRoot, File libraryRoot) throws MojoExecutionException {
    l.info("creating temporary directory: " + tempRoot.getAbsolutePath());

    if (!tempRoot.exists() && !tempRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create temporary directory.");
    }
    l.info("cleaning the temporary directory");
    try {
        FileUtils.cleanDirectory(tempRoot);
    } catch (IOException ioe) {
        throw new MojoExecutionException("Exception while cleaning temporary directory.", ioe);
    }

    l.info("creating IzPack base directory: " + izPackEmbeddedRoot.getAbsolutePath());
    if (!izPackEmbeddedRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create directory for the embedded IzPack installation.");
    }
    if (!tempDescriptorRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create base directory for the IzPack descriptor.");
    }
    l.info("copying IzPack descriptor data");
    try {
        FileUtils.copyDirectory(srcDir, tempDescriptorRoot, Utils.FILTER);
    } catch (IOException ioe) {
        throw new MojoExecutionException("IOException while copying IzPack descriptor data.", ioe);
    }

    l.info("creating directory for dependencies: " + libraryRoot.getAbsolutePath());
    if (!libraryRoot.mkdirs()) {
        throw new MojoExecutionException("Could not create directory for the dependencies.");
    }
}

From source file:com.igormaznitsa.jcp.JCPreprocessor.java

private void createDestinationDirectory() throws IOException {
    final File destination = context.getDestinationDirectoryAsFile();

    final boolean destinationExistsAndDirectory = destination.exists() && destination.isDirectory();

    if (context.doesClearDestinationDirBefore() && destinationExistsAndDirectory) {
        try {/*from w ww  .  j a va 2 s .co  m*/
            FileUtils.cleanDirectory(destination);
        } catch (IOException ex) {
            throw new IOException("I can't clean the destination directory ["
                    + PreprocessorUtils.getFilePath(destination) + ']', ex);
        }
    }

    if (!destinationExistsAndDirectory && !destination.mkdirs()) {
        throw new IOException(
                "I can't make the destination directory [" + PreprocessorUtils.getFilePath(destination) + ']');
    }
}

From source file:io.hops.hopsworks.common.security.CertificateMaterializer.java

@PostConstruct
public void init() {
    File tmpDir = new File(settings.getHopsworksTmpCertDir());
    if (!tmpDir.exists()) {
        throw new IllegalStateException(
                "Transient certificates directory <" + tmpDir.getAbsolutePath() + "> does NOT exist!");
    }//from ww  w . j  a va2  s.  com

    try {
        PosixFileAttributeView fileView = Files.getFileAttributeView(tmpDir.toPath(),
                PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
        Set<PosixFilePermission> permissions = fileView.readAttributes().permissions();
        boolean ownerRead = permissions.contains(PosixFilePermission.OWNER_READ);
        boolean ownerWrite = permissions.contains(PosixFilePermission.OWNER_WRITE);
        boolean ownerExecute = permissions.contains(PosixFilePermission.OWNER_EXECUTE);

        boolean groupRead = permissions.contains(PosixFilePermission.GROUP_READ);
        boolean groupWrite = permissions.contains(PosixFilePermission.GROUP_WRITE);
        boolean groupExecute = permissions.contains(PosixFilePermission.GROUP_EXECUTE);

        boolean othersRead = permissions.contains(PosixFilePermission.OTHERS_READ);
        boolean othersWrite = permissions.contains(PosixFilePermission.OTHERS_WRITE);
        boolean othersExecute = permissions.contains(PosixFilePermission.OTHERS_EXECUTE);

        // Permissions should be 750
        if ((ownerRead && ownerWrite && ownerExecute) && (groupRead && !groupWrite && groupExecute)
                && (!othersRead && !othersWrite & !othersExecute)) {
            String owner = fileView.readAttributes().owner().getName();
            String group = fileView.readAttributes().group().getName();
            String permStr = PosixFilePermissions.toString(permissions);
            LOG.log(Level.INFO, "Passed permissions check for " + tmpDir.getAbsolutePath() + ". Owner: " + owner
                    + " Group: " + group + " permissions: " + permStr);
        } else {
            throw new IllegalStateException(
                    "Wrong permissions for " + tmpDir.getAbsolutePath() + ", it should be 0750");
        }
    } catch (UnsupportedOperationException ex) {
        LOG.log(Level.WARNING,
                "Associated filesystem is not POSIX compliant. "
                        + "Continue without checking the permissions of " + tmpDir.getAbsolutePath()
                        + " This might be a security problem.");
    } catch (IOException ex) {
        throw new IllegalStateException(
                "Error while getting filesystem " + "permissions of " + tmpDir.getAbsolutePath(), ex);
    }

    try {
        FileUtils.cleanDirectory(tmpDir);
    } catch (IOException ex) {
        LOG.log(Level.WARNING, "Could not clean directory " + tmpDir.getAbsolutePath()
                + " during startup, there might be stale " + "certificates", ex);
    }
    transientDir = tmpDir.getAbsolutePath();
    String delayRaw = settings.getCertificateMaterializerDelay();
    DELAY_VALUE = settings.getConfTimeValue(delayRaw);
    DELAY_TIMEUNIT = settings.getConfTimeTimeUnit(delayRaw);

    try {
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        long threadId = Thread.currentThread().getId();
        String lock_identifier = hostAddress + "_" + threadId;
        lock_id = lock_identifier.length() <= 30 ? lock_identifier : lock_identifier.substring(0, 30);
    } catch (UnknownHostException ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:com.vsquaresystem.safedeals.rawmarketprice.RawMarketPriceService.java

public boolean saveExcelToDatabase() throws IOException {

    Vector dataHolder = read();//  w ww. j  a v a2  s  .  c  o  m
    rawMarketPriceDAL.truncateAll();
    dataHolder.remove(0);

    RawMarketPrice rawMarketPrice = new RawMarketPrice();
    String id = "";
    String cityId = "";
    String locationName = "";
    String year = "";
    String month = "";
    String mpAgriLandLowest = "";
    String mpAgriLandHighest = "";
    String mpPlotLowest = "";
    String mpPlotHighest = "";
    String mpResidentialLowest = "";
    String mpResidentialHighest = "";
    String mpCommercialLowest = "";
    String mpCommercialHighest = "";
    String sdZoneId = "";
    String locationTypeId = "";
    String locationCategories = "";
    String description = "";
    String majorApproachRoad = "";
    String sourceOfWater = "";
    String publicTransport = "";
    String advantage = "";
    String disadvantage = "";
    String population = "";
    String migrationRate = "";
    String isCommercialCenter = "";
    System.out.println(dataHolder);
    DataFormatter formatter = new DataFormatter();
    for (Iterator iterator = dataHolder.iterator(); iterator.hasNext();) {
        List list = (List) iterator.next();
        logger.info("list", list);
        cityId = list.get(1).toString();
        locationName = list.get(2).toString();
        year = list.get(3).toString();
        month = list.get(4).toString();
        mpAgriLandLowest = list.get(5).toString();
        mpAgriLandHighest = list.get(6).toString();
        mpPlotLowest = list.get(7).toString();
        mpPlotHighest = list.get(8).toString();
        mpResidentialLowest = list.get(9).toString();
        mpResidentialHighest = list.get(10).toString();
        mpCommercialLowest = list.get(11).toString();
        mpCommercialHighest = list.get(12).toString();
        sdZoneId = list.get(13).toString();
        locationTypeId = list.get(14).toString();
        locationCategories = list.get(15).toString();
        description = list.get(16).toString();
        majorApproachRoad = list.get(17).toString();
        sourceOfWater = list.get(18).toString();
        publicTransport = list.get(19).toString();
        advantage = list.get(20).toString();
        disadvantage = list.get(21).toString();
        population = list.get(22).toString();
        migrationRate = list.get(23).toString();
        isCommercialCenter = list.get(24).toString();
        List<String> strList = new ArrayList<String>(Arrays.asList(locationCategories.split(",")));
        List<Integer> numberList = new ArrayList<Integer>();
        for (String number : strList) {
            numberList.add(Integer.parseInt(number));
        }

        try {
            rawMarketPrice.setCityId(Integer.parseInt(cityId));
            rawMarketPrice.setLocationName(locationName);
            rawMarketPrice.setYear(Integer.parseInt(year));
            rawMarketPrice.setMonth(Integer.parseInt(month));
            rawMarketPrice.setMpAgriLandLowest(Double.parseDouble(mpAgriLandLowest));
            rawMarketPrice.setMpAgriLandHighest(Double.parseDouble(mpAgriLandHighest));
            rawMarketPrice.setMpPlotLowest(Double.parseDouble(mpPlotLowest));
            rawMarketPrice.setMpPlotHighest(Double.parseDouble(mpPlotHighest));
            rawMarketPrice.setMpResidentialLowest(Double.parseDouble(mpResidentialLowest));
            rawMarketPrice.setMpResidentialHighest(Double.parseDouble(mpResidentialHighest));
            rawMarketPrice.setMpCommercialLowest(Double.parseDouble(mpCommercialLowest));
            rawMarketPrice.setMpCommercialHighest(Double.parseDouble(mpCommercialHighest));
            rawMarketPrice.setSafedealZoneId(Integer.parseInt(sdZoneId));
            rawMarketPrice.setLocationTypeId(Integer.parseInt(locationTypeId));
            rawMarketPrice.setLocationCategories(numberList);
            rawMarketPrice.setDescription(description);
            rawMarketPrice.setMajorApproachRoad(majorApproachRoad);
            rawMarketPrice.setSourceOfWater(sourceOfWater);
            rawMarketPrice.setPublicTransport(publicTransport);
            rawMarketPrice.setAdvantage(advantage);
            rawMarketPrice.setDisadvantage(disadvantage);
            rawMarketPrice.setPopulation(Integer.parseInt(population));
            rawMarketPrice.setMigrationRate(Integer.parseInt(migrationRate));
            rawMarketPrice.setIsCommercialCenter((Boolean.parseBoolean(isCommercialCenter)));
            rawMarketPriceDAL.insert(rawMarketPrice);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    File excelFile = attachmentUtils
            .getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.RAW_MARKET_PRICE);
    FileUtils.cleanDirectory(excelFile);
    return true;

}

From source file:ddf.test.itests.platform.TestConfiguration.java

public void resetInitialState() throws Exception {

    FileUtils.deleteQuietly(getDefaultExportDirectory().toFile());
    FileUtils.deleteQuietly(new File(TEST_FILE));
    FileUtils.deleteQuietly(symbolicLink.toFile());

    FileUtils.cleanDirectory(getPathToProcessedDirectory().toFile());
    FileUtils.cleanDirectory(getPathToFailedDirectory().toFile());

    restoreBackup(SYSTEM_PROPERTIES_COPY, SYSTEM_PROPERTIES);
    restoreBackup(USERS_PROPERTIES_COPY, USERS_PROPERTIES);
    restoreBackup(WS_SECURITY_COPY, WS_SECURITY);
    restoreBackup(PDP_COPY, PDP);/*ww w .  j  a v  a  2  s. c om*/

    System.setProperty(KEYSTORE_PROPERTY,
            "etc" + File.separator + "keystores" + File.separator + "serverKeystore.jks");

    disableCrls();
    console.runCommand(CATALOG_REMOVE_ALL_COMMAND, new RolePrincipal("admin"));
}

From source file:gov.nih.nci.caintegrator.application.study.AbstractDeployStudyTestIntegration.java

private void clearStudyDirectory(Study study) throws IOException {
    File studyDirectory = fileManager.getStudyDirectory(study);
    if (studyDirectory.exists()) {
        FileUtils.cleanDirectory(studyDirectory);
    }//w ww .j ava  2 s  .co  m
}

From source file:com.ecofactor.qa.automation.platform.ops.impl.AbstractDriverOperations.java

/**
 * Clean up screen shots./*from ww  w  . j ava 2 s.c om*/
 */
private void cleanUpScreenShots() {

    try {
        final File srcFile = new File("target/screenshots");
        if (srcFile.exists()) {
            FileUtils.cleanDirectory(srcFile);
        }
    } catch (final IOException e) {
        LOGGER.error("Error in deleting screenshots");
    }
}

From source file:com.zotoh.maedr.etc.CmdAppOps.java

protected void genEclipseProj(String lang) throws Exception {
    File out, ec, cwd = getCwd(), home = getMaedrDir();
    ec = new File(cwd, ECPPROJ);
    ec.mkdirs();/*from w  ww  .  ja v a 2  s.  c  om*/
    FileUtils.cleanDirectory(ec);
    String app = cwd.getName();
    StringBuilder sb;
    String str = rc2Str("com/zotoh/maedr/eclipse/" + lang + "/project.txt", "utf-8");
    str = strstr(str, "${APP.NAME}", app);
    str = strstr(str, "${" + lang.toUpperCase() + ".SRC}", niceFPath(new File(cwd, "src/main/" + lang)));
    str = strstr(str, "${TEST.SRC}", niceFPath(new File(cwd, "src/main/test")));
    out = new File(ec, ".project");
    writeFile(out, str, "utf-8");
    str = rc2Str("com/zotoh/maedr/eclipse/" + lang + "/classpath.txt", "utf-8");
    sb = new StringBuilder(512);
    scanJars(new File(home, "lib"), sb);
    scanJars(new File(home, "thirdparty"), sb);
    scanJars(new File(home, "dist"), sb);
    scanJars(new File(cwd, "lib"), sb);
    scanJars(new File(cwd, "thirdparty"), sb);
    scanJars(new File(cwd, "dist"), sb);
    str = strstr(str, "${CLASS.PATH.ENTRIES}", sb.toString());
    out = new File(ec, ".classpath");
    writeFile(out, str, "utf-8");
}

From source file:com.yifanlu.PSXperiaTool.PSXperiaTool.java

private void generateOutput() throws IOException, InterruptedException, GeneralSecurityException,
        SignedJarBuilder.IZipEntryFilter.ZipAbortException {
    nextStep("Done processing, generating output.");
    String titleId = mProperties.getProperty("KEY_TITLE_ID");
    if (!mOutputDir.exists())
        mOutputDir.mkdir();//  ww w.  j  a v a 2  s  .  c o m
    File outDataDir = new File(mOutputDir, "/data/com.sony.playstation." + titleId + "/files/content");
    if (!outDataDir.exists())
        outDataDir.mkdirs();
    Logger.debug("Moving files around.");
    FileUtils.cleanDirectory(outDataDir);
    FileUtils.moveFileToDirectory(new File(mTempDir, "/" + titleId + ".zpak"), outDataDir, false);
    FileUtils.moveFileToDirectory(new File(mTempDir, "/image_ps_toc.bin"), outDataDir, false);
    Logger.verbose("Deleting config from temp directory.");
    FileUtils.deleteDirectory(new File(mTempDir, "/config"));
    File outApk = new File(mOutputDir, "/com.sony.playstation." + titleId + ".apk");

    ApkBuilder build = new ApkBuilder(mTempDir, outApk);
    build.buildApk();

    Logger.info("Done.");
    Logger.info("APK file: %s", outApk.getPath());
    Logger.info("Data dir: %s", outDataDir.getPath());

}

From source file:com.goodformobile.build.mobile.RIMPackageMojoTest.java

@Test
public void testExecuteOnProguardPreverifiedClasses() throws Exception {

    File projectDirectory = getRelativeFile("projects/maven-test-app-preverified-with-proguard/pom.xml")
            .getParentFile();//from www  .ja  va  2 s. c  om

    File workProjectDirectory = new File(getBasedir(), "target/temp/project");
    if (workProjectDirectory.exists()) {
        FileUtils.cleanDirectory(workProjectDirectory);
    }
    FileUtils.copyDirectory(projectDirectory, workProjectDirectory);

    RIMPackageMojo mojo = setupMojo();

    MavenProject project = getProject(mojo);

    setupProject(workProjectDirectory, project);

    mojo.execute();

    // Ensure a jad is generated.
    File targetDirectory = new File(workProjectDirectory, "target");
    File expectedJad = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables"
            + File.separator + "maven_test_app.jad");
    assertTrue("Unable to find generated jad: " + expectedJad.getAbsolutePath(), expectedJad.exists());

    // Ensure a cod file is generated.
    File expectedCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables"
            + File.separator + "maven_test_app.cod");
    assertTrue("Unable to find generated cod: " + expectedCod.getAbsolutePath(), expectedCod.exists());

}