List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:com.netflix.imfutility.AbstractFormatBuilder.java
private void cleanWorkingDir() throws IOException { logger.debug("Cleaning working directory..."); if (isCleanWorkingDir()) { FileUtils.cleanDirectory(inputParameters.getWorkingDirFile()); logger.info("Cleaned working directory: OK\n"); } else {//from w ww . j ava 2 s.co m logger.info("Cleaning working directory is DISABLED in config.xml\n"); } }
From source file:com.edgenius.core.util.FileUtil.java
/** * Delete all files and sub-directories and given directory itself. * @param dir/* ww w . j ava2 s . c o m*/ * @throws IOException * @throws IOException */ public static void deleteDir(String dir) throws IOException { try { FileUtils.cleanDirectory(new File(dir)); if (!new File(dir).delete()) new File(dir).deleteOnExit(); } catch (Exception e) { throw new IOException("Delete directory failed in " + e.toString()); } }
From source file:com.litt.core.security.license.gui.CustomerPanel.java
public CustomerPanel() { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; setLayout(gridBagLayout);//from w ww.j a v a 2s .c om JLabel lblProduct = new JLabel("\u4EA7\u54C1\uFF1A"); GridBagConstraints gbc_lblProduct = new GridBagConstraints(); gbc_lblProduct.insets = new Insets(0, 0, 5, 5); gbc_lblProduct.anchor = GridBagConstraints.EAST; gbc_lblProduct.gridx = 0; gbc_lblProduct.gridy = 0; add(lblProduct, gbc_lblProduct); comboBoxProduct = new JComboBox(); GridBagConstraints gbc_comboBoxProduct = new GridBagConstraints(); gbc_comboBoxProduct.insets = new Insets(0, 0, 5, 5); gbc_comboBoxProduct.fill = GridBagConstraints.HORIZONTAL; gbc_comboBoxProduct.gridx = 1; gbc_comboBoxProduct.gridy = 0; add(comboBoxProduct, gbc_comboBoxProduct); JButton btnRefresh = new JButton(""); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { initProduct(); } }); btnRefresh.setIcon(new ImageIcon(CustomerPanel.class.getResource("/images/icon_refresh.png"))); GridBagConstraints gbc_btnRefresh = new GridBagConstraints(); gbc_btnRefresh.insets = new Insets(0, 0, 5, 0); gbc_btnRefresh.gridx = 2; gbc_btnRefresh.gridy = 0; add(btnRefresh, gbc_btnRefresh); JLabel lblProductVersion = new JLabel("\u4EA7\u54C1\u7248\u672C\uFF1A"); GridBagConstraints gbc_lblProductVersion = new GridBagConstraints(); gbc_lblProductVersion.anchor = GridBagConstraints.EAST; gbc_lblProductVersion.insets = new Insets(0, 0, 5, 5); gbc_lblProductVersion.gridx = 0; gbc_lblProductVersion.gridy = 1; add(lblProductVersion, gbc_lblProductVersion); textFieldProductVersion = new VersionTextField(); textFieldProductVersion.setColumns(10); GridBagConstraints gbc_textFieldProductVersion = new GridBagConstraints(); gbc_textFieldProductVersion.anchor = GridBagConstraints.WEST; gbc_textFieldProductVersion.insets = new Insets(0, 0, 5, 5); gbc_textFieldProductVersion.gridx = 1; gbc_textFieldProductVersion.gridy = 1; add(textFieldProductVersion, gbc_textFieldProductVersion); JLabel lblCompanyName = new JLabel("\u516C\u53F8\u540D\u79F0\uFF1A"); GridBagConstraints gbc_lblCompanyName = new GridBagConstraints(); gbc_lblCompanyName.anchor = GridBagConstraints.EAST; gbc_lblCompanyName.insets = new Insets(0, 0, 5, 5); gbc_lblCompanyName.gridx = 0; gbc_lblCompanyName.gridy = 2; add(lblCompanyName, gbc_lblCompanyName); textFieldCompanyName = new JTextField(); GridBagConstraints gbc_textFieldCompanyName = new GridBagConstraints(); gbc_textFieldCompanyName.insets = new Insets(0, 0, 5, 5); gbc_textFieldCompanyName.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldCompanyName.gridx = 1; gbc_textFieldCompanyName.gridy = 2; add(textFieldCompanyName, gbc_textFieldCompanyName); textFieldCompanyName.setColumns(10); JLabel lblCustomerCode = new JLabel("\u5BA2\u6237\u7F16\u53F7\uFF1A"); GridBagConstraints gbc_lblCustomerCode = new GridBagConstraints(); gbc_lblCustomerCode.anchor = GridBagConstraints.EAST; gbc_lblCustomerCode.insets = new Insets(0, 0, 5, 5); gbc_lblCustomerCode.gridx = 0; gbc_lblCustomerCode.gridy = 3; add(lblCustomerCode, gbc_lblCustomerCode); textFieldCustomerCode = new JTextField(); GridBagConstraints gbc_textFieldCustomerCode = new GridBagConstraints(); gbc_textFieldCustomerCode.insets = new Insets(0, 0, 5, 5); gbc_textFieldCustomerCode.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldCustomerCode.gridx = 1; gbc_textFieldCustomerCode.gridy = 3; add(textFieldCustomerCode, gbc_textFieldCustomerCode); textFieldCustomerCode.setColumns(10); JLabel lblCustomerName = new JLabel("\u5BA2\u6237\u540D\u79F0\uFF1A"); GridBagConstraints gbc_lblCustomerName = new GridBagConstraints(); gbc_lblCustomerName.anchor = GridBagConstraints.EAST; gbc_lblCustomerName.insets = new Insets(0, 0, 5, 5); gbc_lblCustomerName.gridx = 0; gbc_lblCustomerName.gridy = 4; add(lblCustomerName, gbc_lblCustomerName); textFieldCustomerName = new JTextField(); GridBagConstraints gbc_textFieldCustomerName = new GridBagConstraints(); gbc_textFieldCustomerName.insets = new Insets(0, 0, 5, 5); gbc_textFieldCustomerName.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldCustomerName.gridx = 1; gbc_textFieldCustomerName.gridy = 4; add(textFieldCustomerName, gbc_textFieldCustomerName); textFieldCustomerName.setColumns(10); JLabel lblLicenseType = new JLabel("\u8BC1\u4E66\u7C7B\u578B\uFF1A"); GridBagConstraints gbc_lblLicenseType = new GridBagConstraints(); gbc_lblLicenseType.anchor = GridBagConstraints.EAST; gbc_lblLicenseType.insets = new Insets(0, 0, 5, 5); gbc_lblLicenseType.gridx = 0; gbc_lblLicenseType.gridy = 5; add(lblLicenseType, gbc_lblLicenseType); comboBoxLicenseType = new JComboBox(); GridBagConstraints gbc_comboBoxLicenseType = new GridBagConstraints(); gbc_comboBoxLicenseType.insets = new Insets(0, 0, 5, 5); gbc_comboBoxLicenseType.fill = GridBagConstraints.HORIZONTAL; gbc_comboBoxLicenseType.gridx = 1; gbc_comboBoxLicenseType.gridy = 5; add(comboBoxLicenseType, gbc_comboBoxLicenseType); JLabel lblExpiredDate = new JLabel("\u8FC7\u671F\u65F6\u95F4\uFF1A"); GridBagConstraints gbc_lblExpiredDate = new GridBagConstraints(); gbc_lblExpiredDate.insets = new Insets(0, 0, 5, 5); gbc_lblExpiredDate.gridx = 0; gbc_lblExpiredDate.gridy = 6; add(lblExpiredDate, gbc_lblExpiredDate); datePickerExpiredDate = new DatePicker(new Date(), "yyyy-MM-dd", null, null); GridBagConstraints gbc_datePicker = new GridBagConstraints(); gbc_datePicker.anchor = GridBagConstraints.WEST; gbc_datePicker.insets = new Insets(0, 0, 5, 5); gbc_datePicker.gridx = 1; gbc_datePicker.gridy = 6; add(datePickerExpiredDate, gbc_datePicker); JButton btnSave = new JButton("\u4FDD\u5B58"); btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { //???????? if (comboBoxProduct.getSelectedIndex() <= 0) { JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "??"); return; } String[] array = StringUtils.split(comboBoxProduct.getSelectedItem().toString(), '-'); String productCode = array[0]; String productName = array[1]; String customerCode = textFieldCustomerCode.getText(); //?? File configFile = ResourceUtils.getFile(Gui.HOME_PATH + File.separator + "config.xml"); Document document = XmlUtils.readXml(configFile); Element customerNode = (Element) document.selectSingleNode( "//product[@code='" + productCode + "']/customer[@code='" + customerCode + "']"); if (customerNode != null) { JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "???"); return; } String licenseId = new RandomGUID().toString(); String licenseType = Utility.splitStringAll(comboBoxLicenseType.getSelectedItem().toString(), " - ")[0]; String companyName = textFieldCompanyName.getText(); String customerName = textFieldCustomerName.getText(); String version = textFieldProductVersion.getText(); Date expiredDate = Utility.parseDate(datePickerExpiredDate.getText()); License license = new License(); license.setLicenseId(licenseId); license.setLicenseType(licenseType); license.setProductName(productName); license.setCompanyName(companyName); license.setCustomerName(customerName); license.setVersion(Version.parseVersion(version)); license.setCreateDate(new Date()); license.setExpiredDate(expiredDate); LicenseService service = new LicenseService(); String productPath = Gui.HOME_PATH + File.separator + productCode; File licenseDir = new File(productPath, customerCode); if (!licenseDir.exists()) { licenseDir.mkdir(); //? FileUtils.copyFileToDirectory(new File(productPath, "license.key"), licenseDir); } File priKeyFile = new File(Gui.HOME_PATH + File.separator + productCode, "private.key"); File licenseFile = new File(licenseDir, "license.xml"); service.save(Gui.HOME_PATH, productCode, customerCode, license, priKeyFile, licenseFile); //??zip? File customerPath = licenseFile.getParentFile(); //???license????? File licensePath = new File(customerPath.getParent(), "license"); if (!licensePath.exists() && !licensePath.isDirectory()) { licensePath.mkdir(); } else { FileUtils.cleanDirectory(licensePath); } //? FileUtils.copyDirectory(customerPath, licensePath); String currentTime = FormatDateTime.formatDateTimeNum(new Date()); ZipUtils.zip(licensePath, new File(licensePath.getParentFile(), customerCode + "-" + currentTime + ".zip")); //license FileUtils.deleteDirectory(licensePath); JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "??"); } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), e1.getMessage()); } } }); GridBagConstraints gbc_btnSave = new GridBagConstraints(); gbc_btnSave.insets = new Insets(0, 0, 5, 5); gbc_btnSave.gridx = 1; gbc_btnSave.gridy = 7; add(btnSave, gbc_btnSave); //?? initData(); }
From source file:com.taobao.android.builder.tools.proguard.BundleProguarder.java
public static void execute(AppVariantContext appVariantContext, Input input) throws Exception { if (input.proguardOutputDir != null && input.proguardOutputDir.exists()) { FileUtils.cleanDirectory(input.proguardOutputDir); }// w w w. j av a 2 s. co m if (!appVariantContext.getAtlasExtension().getTBuildConfig().isProguardCacheEnabled()) { doProguard(appVariantContext, input); return; } String md5 = input.getMd5(); Result result = loadProguardFromCache(appVariantContext, input); String bundleName = input.getAwbBundles().get(0).getAwbBundle().getName(); if (result.success) { fileLogger.log(bundleName + " hit cache " + result.cacheDir.getAbsolutePath()); return; } fileLogger.log(bundleName + " miss cache " + result.cacheDir.getAbsolutePath()); long startTime = System.currentTimeMillis(); doProguard(appVariantContext, input); double during = (System.currentTimeMillis() - startTime) / 1000.0; fileLogger.log(bundleName + "proguard consume (s) " + during); //cache if (null != result.cacheDir) { try { cacheProguard(appVariantContext, input, result); } catch (Throwable e) { logger.error(e.getMessage(), e); } } }
From source file:de.teamgrit.grit.entities.Exercise.java
/** * After the deadline, all submissions are processed as follows: * <ol>/*from www . j a va 2 s. com*/ * <li>The submissions are downloaded from the specified source.</li> * <li>The submissions are checked for plausibility.</li> * <li>The submissions are compiled.</li> * <li>The submissions are tested with the supplied test.</li> * <li>A scorecard is generated from the results of compiling and testing * for each submissions.</li> * <li>The scorecards are merged into one report file for easy printing, * which is put into the output directory.</li> * <li>A notification email is sent to the administrator when the * processing is done and the report is ready for download.</li> * </ol> */ private void postDeadlineProcessing() { /* Local variables for the metadata */ Path tempPdfPath = context.getTempPdfPath(); Path binpath = context.getBinPath(); Path targetDirectory = context.getFetchPath(); String courseName = context.getCourseName(); String exerciseName = context.getExerciseName(); Connection connection = m_controller.getConnection(context.getConnectionId()); String fileRegex = context.getFileRegex(); String archiveRegex = context.getArchiveRegex(); Date startTime = context.getStartTime().getTime(); Date endTime = context.getDeadline().getTime(); /* download the submissions from the source and tokonize them. */ status = "fetching submissions"; PreprocessingResult result = null; try { result = Preprocessors.preprocess(connection, startTime, endTime, targetDirectory, courseName, exerciseName, fileRegex, archiveRegex); } catch (SubmissionFetchingException e) { context.logError(e.getMessage()); status = "error while fetching submissions"; m_taskPool.shutdownNow(); return; } Map<Student, Submission> submissions = result.getStudentSubmissions(); m_submissions = submissions; List<Student> studentsWithoutSubmission = result.getStudentsWithoutSubmission(); /* check plausibility of the submission. */ status = "processing submissions"; for (Submission submission : m_submissions.values()) { try { checkPlausibility(submission); if (submission.isPlausible()) { /* compile */ LOGGER.info("compiling submission"); CompilerOutput compileResult = compileSubmission(submission); /* test */ LOGGER.info("testing submission"); TestOutput testResult = testSubmission(binpath, compileResult); /* create checking result */ submission.setCheckingResult(new CheckingResult(compileResult, testResult)); /* score card creation */ LOGGER.info("generate scorecard"); ReportGenerator.generateReport(submission, tempPdfPath, courseName, exerciseName, ReportGenerator.ReportType.PDF); try { FileUtils.cleanDirectory(binpath.toFile()); } catch (IOException e) { LOGGER.severe("Could not delete output directory (binpath)"); } } } catch (BadCompilerSpecifiedException | BadFlagException | CompilerOutputFolderExistsException | IOException e) { LOGGER.severe("Error during processing a submission, " + "it was skipped. " + e.getMessage()); } } /* merge the single scorecard files into a large one. */ try { ReportGenerator.concatenatePdfReports(context.getTempPdfPath(), context.getOutputPath(), context.getExerciseName(), studentsWithoutSubmission); } catch (IOException e) { context.logError("error while merging scorecards: " + e.getMessage()); status = "error while generating pdf for printout"; m_taskPool.shutdownNow(); return; } /* delete all temporary files. */ cleanup(); status = "ready for download"; notifyAdmin(); /* all done! */ m_taskPool.shutdownNow(); }
From source file:es.uvigo.ei.sing.adops.datatypes.ProjectExperiment.java
@Override public void clear() { final FileFilter filter = new FileFilter() { @Override/* w w w . ja v a2 s.com*/ public boolean accept(File pathname) { if (pathname.equals(ProjectExperiment.this.getNotesFile()) || pathname.equals(ProjectExperiment.this.getPropertiesFile()) || pathname.equals(ProjectExperiment.this.getFastaFile()) || pathname.equals(ProjectExperiment.this.getNamesFile()) || pathname.equals(ProjectExperiment.this.getFilesFolder())) { return false; } return true; } }; for (File file : this.getFolder().listFiles(filter)) { if (file.isFile()) file.delete(); else if (file.isDirectory()) try { FileUtils.deleteDirectory(file); } catch (IOException e) { } } try { FileUtils.cleanDirectory(this.getFilesFolder()); } catch (IOException e) { } new File(this.getFilesFolder(), TCoffeeOutput.OUTPUT_FOLDER_NAME).mkdirs(); new File(this.getFilesFolder(), MrBayesOutput.OUTPUT_FOLDER_NAME).mkdirs(); new File(this.getFilesFolder(), CodeMLOutput.OUTPUT_FOLDER_NAME).mkdirs(); this.result = null; this.setChanged(); this.notifyObservers(); }
From source file:cl.uai.webcursos.emarking.desktop.QRextractor.java
/** * @param tempdir the tempdir to set//from w w w .j a v a 2 s . co m * @throws IOException */ public void setTempdir(File tmpdir) throws IOException { if (tmpdir == null) { File tempdir = File.createTempFile("emarking", Long.toString(System.nanoTime())); if (!tempdir.delete()) { logger.error("Could not delete temp dir"); System.exit(1); } if (!tempdir.mkdir()) { logger.error("Could not create temp dir"); System.exit(1); } tmpdir = tempdir; } if (!tmpdir.exists() || !tmpdir.isDirectory()) { logger.error("Invalid temp dirextory " + tmpdir.getAbsolutePath()); System.exit(1); } if (tmpdir.listFiles().length != 0) { logger.debug("Temp folder is not empty, cleaning."); FileUtils.cleanDirectory(tmpdir); } if (this.tempdir != null) { this.tempdir.delete(); } this.tempdir = tmpdir; }
From source file:com.github.os72.protocjar.maven.ProtocJarMojo.java
private void preprocessTarget(OutputTarget target) throws MojoExecutionException { if (target.pluginArtifact != null && target.pluginArtifact.length() > 0) { target.pluginPath = resolveArtifact(target.pluginArtifact).getAbsolutePath(); }/* www.j a va2 s . c om*/ File f = target.outputDirectory; if (!f.exists()) { getLog().info(f + " does not exist. Creating..."); f.mkdirs(); } if (target.cleanOutputFolder) { try { getLog().info("Cleaning " + f); FileUtils.cleanDirectory(f); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.edgenius.wiki.rss.RSSServiceImpl.java
public void cleanAllRss() { try {//from w w w .java2 s. c o m FileUtils.cleanDirectory(rssRoot.getFile()); } catch (IOException e) { log.error("Unable to clean RSS directory", e); } }
From source file:com.taobao.android.apatch.FastBuild.java
public File dopatch() throws IOException, RecognitionException, CertificateException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableEntryException, PatchException { File dexFile = new File(out, "diff.dex"); if (dexFile.exists() && !dexFile.delete()) { throw new RuntimeException("diff.dex can't be removed."); }/*from w w w . ja v a 2s. c o m*/ File outFile = new File(out, "diff" + SUFFIX); if (outFile.exists() && !outFile.delete()) { throw new RuntimeException("diff" + SUFFIX + " can't be removed."); } currentTimeStamp = System.currentTimeMillis(); File smaliDir = new File(out, "smali"); if (smaliDir.exists()) { FileUtils.cleanDirectory(smaliDir); } smaliDir.mkdirs(); classes = SmaliDiffUtils.buildCode(smaliDir, dexFile, dexDiffInfo); if (null == classes || classes.size() <= 0) { return null; } if (null != diffFile && null != diffJsonFile) { dexDiffInfo.writeToFile(name, diffFile, diffJsonFile); } DexDiffInfo.release(); build(outFile, dexFile); File file = release(out, dexFile, outFile); release(); return file; }