List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:io.ucoin.ucoinj.core.client.TestResource.java
protected void initI18n() throws IOException { Configuration config = Configuration.instance(); // --------------------------------------------------------------------// // init i18n/* w ww . jav a 2s .co m*/ // --------------------------------------------------------------------// File i18nDirectory = new File(config.getDataDirectory(), "i18n"); if (i18nDirectory.exists()) { // clean i18n cache FileUtils.cleanDirectory(i18nDirectory); } FileUtils.forceMkdir(i18nDirectory); if (log.isDebugEnabled()) { log.debug("I18N directory: " + i18nDirectory); } Locale i18nLocale = config.getI18nLocale(); if (log.isInfoEnabled()) { log.info(String.format("Starts i18n with locale [%s] at [%s]", i18nLocale, i18nDirectory)); } I18n.init(new UserI18nInitializer(i18nDirectory, new DefaultI18nInitializer(getI18nBundleName())), i18nLocale); }
From source file:edu.uci.ics.hyracks.hdfs.dataflow.DataflowTest.java
private void cleanupStores() throws IOException { FileUtils.forceMkdir(new File("teststore")); FileUtils.forceMkdir(new File("build")); FileUtils.cleanDirectory(new File("teststore")); FileUtils.cleanDirectory(new File("build")); }
From source file:hoot.services.controllers.info.ReportsResourceTest.java
@Test @Category(UnitTest.class) public void testGetReportsList() throws Exception { String storePath = _rps._homeFolder + "/" + _rps._rptStorePath; File f = new File(storePath); File fWks1 = new File(storePath + "/123_test1"); if (fWks1.exists()) { FileUtils.forceDelete(fWks1);/* www .j a va 2 s . co m*/ } File fWks2 = new File(storePath + "/123_test2"); if (fWks2.exists()) { FileUtils.forceDelete(fWks2); } File fWks3 = new File(storePath + "/123_test3"); if (fWks3.exists()) { FileUtils.forceDelete(fWks3); } FileUtils.forceMkdir(f); FileUtils.forceMkdir(fWks1); String currTime = "" + System.currentTimeMillis(); JSONObject metaData = new JSONObject(); metaData.put("name", "Test Report1"); metaData.put("description", "This is test report 1"); metaData.put("created", currTime); metaData.put("reportpath", storePath + "/123_test1/report.pdf"); File meta = new File(storePath + "/123_test1/meta.data"); FileUtils.write(meta, metaData.toJSONString()); FileUtils.forceMkdir(fWks2); currTime = "" + System.currentTimeMillis(); metaData = new JSONObject(); metaData.put("name", "Test Report2"); metaData.put("description", "This is test report 2"); metaData.put("created", currTime); metaData.put("reportpath", storePath + "/123_test2/report.pdf"); meta = new File(storePath + "/123_test2/meta.data"); FileUtils.write(meta, metaData.toJSONString()); FileUtils.forceMkdir(fWks3); currTime = "" + System.currentTimeMillis(); metaData = new JSONObject(); metaData.put("name", "Test Report3"); metaData.put("description", "This is test report 3"); metaData.put("created", currTime); metaData.put("reportpath", storePath + "/123_test3/report.pdf"); meta = new File(storePath + "/123_test3/meta.data"); FileUtils.write(meta, metaData.toJSONString()); JSONArray out = _rps._getReportsList(); int nCount1 = 0; int nCount2 = 0; int nCount3 = 0; for (Object o : out) { JSONObject jo = (JSONObject) o; if (jo.get("name").toString().equals("Test Report1")) { nCount1++; } if (jo.get("name").toString().equals("Test Report2")) { nCount2++; } if (jo.get("name").toString().equals("Test Report3")) { nCount3++; } } assertEquals(1, nCount1); assertEquals(1, nCount2); assertEquals(1, nCount3); FileUtils.forceDelete(fWks1); FileUtils.forceDelete(fWks2); FileUtils.forceDelete(fWks3); }
From source file:jp.co.tis.gsp.tools.dba.mojo.ImportSchemaMojo.java
@Override protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException { Dialect dialect = DialectFactory.getDialect(url, driver); dialect.createUser(user, password, adminUser, adminPassword); dialect.dropAll(user, password, adminUser, adminPassword, schema); Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, version, "jar"); ArtifactResolutionRequest schemaArtifactRequest = new ArtifactResolutionRequest() .setRemoteRepositories(project.getRemoteArtifactRepositories()).setArtifact(artifact); ArtifactResolutionResult schemaArtifactResult = repositorySystem.resolve(schemaArtifactRequest); if (schemaArtifactResult.hasExceptions()) { for (Exception e : schemaArtifactResult.getExceptions()) { getLog().error("?????????", e); }/*from ww w. j a va 2 s . c o m*/ } ImportParams params = createImportParams(); JarFile jarFile = JarFileUtil .create(new File(localRepository.getBasedir(), localRepository.pathOf(artifact))); try { if (!inputDirectory.exists()) { try { FileUtils.forceMkdir(inputDirectory); } catch (IOException e) { throw new MojoExecutionException("Can't create outputDirectory:" + inputDirectory); } } // jar?? extractJarAll(jarFile, inputDirectory.getAbsolutePath()); } catch (IOException e) { throw new MojoExecutionException("", e); } getLog().info("?????"); dialect.importSchema(params); getLog().info("??????"); }
From source file:de.uzk.hki.da.cb.ShortenFileNamesAction.java
@Override public void rollback() throws Exception { for (Event e : o.getLatestPackage().getEvents()) { if (!"CONVERT".equals(e.getType())) continue; DAFile daFile = e.getTarget_file(); File file = wa.toFile(daFile); String filePath = daFile.getRelative_path(); if (!map.containsKey(filePath)) continue; String oldFilePath = map.get(filePath); File oldFile = new File(file.getAbsolutePath().replaceAll(filePath + "$", oldFilePath)); daFile.setRelative_path(oldFilePath); FileUtils.forceMkdir(oldFile.getParentFile()); FileUtils.moveFile(file, oldFile); }/*from ww w . j a v a2 s . c om*/ logger.info("@Admin: You can safely roll back this job to status " + this.getStartStatus() + " now."); }
From source file:com.qcadoo.maven.plugins.jetty.JettyMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { setField("scanTargets", new File[] { jdbcDriver }); setField("project", _project); setField("webXml", _webXml); setField("classesDirectory", _classesDirectory); setField("webAppSourceDirectory", _webAppSourceDirectory); setField("pluginArtifacts", _pluginArtifacts); setField("reload", "automatic"); setField("contextPath", "/"); setField("tmpDirectory", _tmpDirectory); setField("scanIntervalSeconds", 0); try {// w w w . j a v a 2 s. c o m FileUtils.forceMkdir(logs); FileUtils.forceMkdir(temporaryPlugins); FileUtils.forceMkdir(plugins); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } SystemProperties systemProperties = new SystemProperties(); systemProperties.setSystemProperty(getSystemProperty("spring.profiles.default", profile)); systemProperties.setSystemProperty(getSystemProperty("QCADOO_CONF", configuration.getAbsolutePath())); systemProperties.setSystemProperty(getSystemProperty("QCADOO_LOG", logs.getAbsolutePath())); systemProperties.setSystemProperty( getSystemProperty("QCADOO_PLUGINS_TMP_PATH", temporaryPlugins.getAbsolutePath())); systemProperties.setSystemProperty(getSystemProperty("QCADOO_PLUGINS_PATH", plugins.getAbsolutePath())); systemProperties.setSystemProperty(getSystemProperty("QCADOO_WEBAPP_PATH", webapp.getAbsolutePath())); systemProperties.setSystemProperty(getSystemProperty("QCADOO_RESTART_CMD", restartCommand)); setSystemProperties(systemProperties); try { JettyWebAppContext webAppConfig = new JettyWebAppContext(); webAppConfig.setContextPath("/"); List<Resource> resources = new ArrayList<Resource>(); resources.add(Resource.newResource(webapp.getAbsolutePath())); resources.add(Resource.newResource("${basedir}/../../../qcadoo/qcadoo-view/src/main/resources")); resources.add(Resource .newResource("${basedir}/../../mes-plugins/mes-plugins-plugin-management/src/main/resources")); resources.add(Resource .newResource("${basedir}/../../mes-plugins/mes-plugins-technologies/src/main/resources")); webAppConfig.setBaseResource(new ResourceCollection(resources.toArray(new Resource[resources.size()]))); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } super.execute(); }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java
@Test public void testZipTwoFile() throws Exception { FileUtils.forceMkdir(new File("target/Z-testfiles/source")); FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"), new File("target/Z-testfiles/source/CP0-input.csv")); FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"), new File("target/Z-testfiles/source/CP1-input.csv")); String aTargetFilename = "target/Z1-input.zip"; ZipFilesTasklet aTasklet = new ZipFilesTasklet(); aTasklet.setSourceBaseDirectory(new FileSystemResource("target/Z-testfiles/source/")); FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory(); aSourceFactory.setPattern("file:target/Z-testfiles/source/*input*.csv"); aTasklet.setSourceFactory(aSourceFactory); ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory(); aDestinationFactory.setExpression(aTargetFilename); aTasklet.setDestinationFactory(aDestinationFactory); assertFalse(new File(aTargetFilename).exists()); StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); verify(aStepContribution, times(2)).incrementReadCount(); verify(aStepContribution, times(2)).incrementWriteCount(1); assertTrue(new File(aTargetFilename).exists()); ZipFile aZipFile = new ZipFile(new File(aTargetFilename)); Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries(); assertTrue(aEntries.hasMoreElements()); assertEquals("CP0-input.csv", aEntries.nextElement().getName()); assertTrue(aEntries.hasMoreElements()); assertEquals("CP1-input.csv", aEntries.nextElement().getName()); assertFalse(aEntries.hasMoreElements()); aZipFile.close();// w w w .j a va 2s .c om }
From source file:com.offbynull.coroutines.antplugin.InstrumentTask.java
@Override public void execute() throws BuildException { // Check classpath if (classpath == null) { throw new BuildException("Classpath not set"); }//ww w . ja v a 2s. c om // Check source directory if (sourceDirectory == null) { throw new BuildException("Source directory not set"); } if (!sourceDirectory.isDirectory()) { throw new BuildException("Source directory is not a directory: " + sourceDirectory.getAbsolutePath()); } // Check target directory if (targetDirectory == null) { throw new BuildException("Target directory not set"); } try { FileUtils.forceMkdir(targetDirectory); } catch (IOException ioe) { throw new BuildException("Unable to create target directory", ioe); } // Check JDK libs directory if (jdkLibsDirectory == null) { throw new BuildException("JDK libs directory not set"); } if (!jdkLibsDirectory.isDirectory()) { throw new BuildException( "JDK libs directory is not a directory: " + jdkLibsDirectory.getAbsolutePath()); } List<File> combinedClasspath; try { log("Getting compile classpath", Project.MSG_DEBUG); combinedClasspath = Arrays.stream(classpath.split(";")).map(x -> x.trim()).filter(x -> !x.isEmpty()) .map(x -> new File(x)).collect(Collectors.toList()); log("Getting bootstrap classpath", Project.MSG_DEBUG); combinedClasspath.addAll(FileUtils.listFiles(jdkLibsDirectory, new String[] { "jar" }, true)); log("Classpath for instrumentation is as follows: " + combinedClasspath, Project.MSG_INFO); } catch (Exception ex) { throw new BuildException("Unable to get compile classpath elements", ex); } Instrumenter instrumenter; try { log("Creating instrumenter...", Project.MSG_INFO); instrumenter = new Instrumenter(combinedClasspath); log("Processing " + sourceDirectory.getAbsolutePath() + " ... ", Project.MSG_INFO); instrumentPath(instrumenter); } catch (Exception ex) { throw new BuildException("Failed to instrument", ex); } }
From source file:edu.uci.ics.hyracks.hdfs2.dataflow.DataflowTest.java
@Override public void setUp() throws Exception { conf = new Job(); cleanupStores();// w w w . j a v a 2 s . c om HyracksUtils.init(); FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR)); FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR)); startHDFS(); }
From source file:com.alibaba.jstorm.cluster.StormConfig.java
public static String worker_root(Map conf) throws IOException { String ret = String.valueOf(conf.get(Config.STORM_LOCAL_DIR)) + FILE_SEPERATEOR + "workers"; FileUtils.forceMkdir(new File(ret)); return ret;/* w w w .java 2 s . co m*/ }