List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:com.centeractive.ws.builder.DefinitionSaveTest.java
public static File getGeneratedFolder(int serviceId) throws WSDLException, IOException { URL wsdlUrl = ServiceComplianceTest.getDefinitionUrl(serviceId); SoapBuilder builder = new SoapBuilder(wsdlUrl); File tempFolder = File.createTempFile("maven-temp", Long.toString(System.nanoTime())); if (!tempFolder.delete()) { throw new RuntimeException("cannot delete tmp file"); }//from w w w . ja va2 s .c om if (!tempFolder.mkdir()) { throw new RuntimeException("cannot create tmp folder"); } String fileName = FilenameUtils.getBaseName(wsdlUrl.toString()); builder.saveWsdl(fileName, tempFolder); tempFolder.deleteOnExit(); return tempFolder; }
From source file:edu.oregonstate.eecs.mcplan.abstraction.IrrelevanceExperiments.java
public static File createDirectory(final String[] args) { final File r = new File(args[0]); r.mkdir(); final File d = new File(r, "x" + args[1] + "_" + args[2]); d.mkdir();/*from ww w. jav a 2 s . co m*/ return d; }
From source file:it.geosolutions.tools.io.file.IOUtils.java
/** * Create a subDirectory having the actual date as name, within a specified * destination directory.//from w w w . j a va 2s .c om * * @param destDir * the destination directory where to build the "today" * directory. * @return the created directory. */ public static File createTodayDirectory(File destDir) { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd"); final String newPath = (new StringBuffer(destDir.getAbsolutePath().trim()).append(File.separatorChar) .append(sdf.format(new Date()))).toString(); File dir = new File(newPath); if (!dir.exists()) dir.mkdir(); return dir; }
From source file:at.ac.tuwien.big.testsuite.impl.task.UnzipTaskImpl.java
private static File createTempDirectory() throws IOException { final File temp = File.createTempFile("temp", Long.toString(System.currentTimeMillis())); if (!temp.delete()) { throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); }//from w w w . java2 s . c o m if (!temp.mkdir()) { throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); } return temp; }
From source file:com.hmiard.blackwater.projects.Builder.java
/** * Recursively copying a folder./*w ww.ja v a 2 s . com*/ * * @param src File * @param dest File * @throws IOException */ public static void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { if (!dest.exists()) dest.mkdir(); String files[] = src.list(); for (String file : files) copyFolder(new File(src, file), new File(dest, file)); } else { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0) out.write(buffer, 0, length); in.close(); out.close(); } }
From source file:com.qait.automation.samjbehavedemo.utils.FileHandler.java
public static void cleanStoryLocation() { File storiesDir = getFile(Constants.STORY_LOC); if (storiesDir.exists()) { try {/* w w w. ja v a 2 s. c o m*/ FileUtils.deleteDirectory(storiesDir); } catch (IOException ex) { Logger.getLogger(JiraStoryDownloader.class.getName()).log(Level.SEVERE, "UNABLE TO DELETE OLD STORIES", ex); ex.printStackTrace(); } } storiesDir.mkdir(); }
From source file:edu.odu.cs.cs350.yellow1.ui.cli.Main.java
/** * Main program function. Creates and runs mutants as well as logging and output files * /*from w w w . j a v a2 s .c o m*/ * @param srcFolder Source folder for project to be mutated * @param fileToBeMutated Source file for project to be mutated * @param testSuitePath Path for test suite * @param goldOutput Original version output file * @throws BuildFileNotFoundException * @throws IOException */ @SuppressWarnings("static-access") public static void mutate(String srcFolder, String fileToBeMutated, String testSuitePath, String goldOutput) throws BuildFileNotFoundException, IOException { //Step 1: Set up file directory paths for antRunner, jarExecutor, and fileMover logger = LogManager.getLogger(Main.class); mutLog = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs" + File.separator + "mutationsApplied.txt"); aliveLog = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs" + File.separator + "mutationsAlive.txt"); logFolder = new File(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs"); // ok because of the output on jenkins sanitize the logs directory if (logFolder.exists()) if (logFolder.isDirectory()) for (File f : logFolder.listFiles()) f.delete(); //give ant runer the project location ant = new AntRunner(srcFolder); ant.requiresInit(true); //call setup ant.setUp(); a = new JavaFile(); //give the jarUtil the directory where to expect the jar the directory where to put the jar jar = new JarUtil((srcFolder + File.separator + "bin"), (srcFolder + File.separator + "mutantDir")); //get a file object to the original file File goldFile = new File(fileToBeMutated); goldPath = goldFile.toPath(); //get the bytes from it for checking if applying mutation and restore works goldOrgContent = Files.readAllBytes(goldPath); File script = new File(srcFolder + File.separator + "compare.sh"); //build the JarExecutor using the JarExecutor jarExecutor = JarExecutorBuilder.pathToJarDirectory(srcFolder + File.separator + "mutantDir") .pathToCompareScript(script.getAbsolutePath()) .pathToLogDir(srcFolder + File.separator + "mutantDir" + File.separator + "logs") .pathToGold(goldOutput.toString()).withExecutionState(ExecutionState.multiFile) .withTestSuitePath(testSuitePath).create(); File tDir = new File(srcFolder + File.separator + "mutantDir"); if (!tDir.exists()) tDir.mkdir(); //Create a fileMover object give it the directory where mutations will be placed the directory of the original file location fMover = new FileMover(srcFolder + File.separator + "mutantDir", fileToBeMutated); fMover.setNoDelete(true); try { fMover.setUp(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } //Step2: Create and run mutants try { a.readFile(fileToBeMutated); } catch (IOException e) { e.printStackTrace(); } a.executeAll(); int mutantsCreated = a.getMutantCaseVector().getSize(); logger.info("Created " + mutantsCreated + " Mutants"); for (int i = 0; i < a.getMutantCaseVector().getSize(); i++) { a.getMutantCaseOperations(i).writeMutation(srcFolder + File.separator + "mutantDir" + File.separator + "Mutation" + Integer.toString(i + 1) + ".java"); } //get the files into the file mover object fMover.pullFiles(); //check to see if the filemover got all the files //assertEquals(fMover.getFileToBeMovedCount(),mutantsCreated); int moved = 0; int failed = 0; //move through each file moving them one by one while (fMover.hasMoreFiles()) { try { //move next file fMover.moveNextFile(); //build the new executable ant.build(); //move the created jar with correct number corresponding to the mutation created jar.moveJarToDestNumbered(); //clean the project ant.clean(); //check to see if the mutation was applied //assertThat(additionOrgContent, IsNot.not(IsEqual.equalTo(Files.readAllBytes(additionPath)))); } catch (FileMovingException | BuildException | TargetNotFoundException | IOException e) { //build failed if (e instanceof BuildException) { logger.error("Build exception " + e.getMessage()); //restore the file back since compilation was not successful fMover.restorTarget(); //try { // //check to see if the file was restored // assertArrayEquals(goldOrgContent, Files.readAllBytes(goldPath)); //} catch (IOException e1) { // //} //clean the project try { ant.clean(); } catch (BuildException e1) { } catch (TargetNotFoundException e1) { } //indicate compile failure ++failed; } //fail(); } //restore the file back to its original state fMover.restorTarget(); //check to see if the file was restored //try { // assertArrayEquals(goldOrgContent, Files.readAllBytes(goldPath)); //} catch (IOException e) { // //} //increment move count ++moved; //see if the file mover has the correct amount of mutatants still to be moved //assertEquals(fMover.getFileToBeMovedCount(), mutantsCreated - moved); } //set up for execution jarExecutor.setUp(); //start execution of jars jarExecutor.start(); //get the number of successful and failed runs int succesful = jarExecutor.getNumberOfMutantsKilled(); int failurs = jarExecutor.getNumberOfMutantsNotKilled(); int numTests = jarExecutor.getNumberOfTests(); int total = succesful + failurs; String aliveFile = null; String newLine = System.lineSeparator(); //Find any test jars that remain alive and write them to the log file List<ExecutionResults> testResults = jarExecutor.getMutationTestingResults(); for (ExecutionResults result : testResults) { if (!result.isKilled()) { aliveFile = result.getJarName(); FileUtils.writeStringToFile(aliveLog, aliveFile + newLine, true); } } //moved - failed = number of jars actually created moved = moved - failed; //see if the total number of executions equals the total amount of jars created //assertEquals(succesful+failurs,moved); logger.debug("Compilation failurs= " + failed + " total files moved= " + moved); logger.debug("Execution succesful=" + succesful + " Execution failurs= " + failurs); EOL eol = System.getProperty("os.name").toLowerCase().contains("windows") ? EOL.DOS : EOL.NIX; try { a.writeMutationsLog(srcFolder.toString() + File.separator + "mutantDir" + File.separator + "logs" + File.separator + "mutationsApplied.txt", eol); } catch (Exception e) { logger.error(e.getMessage()); } String finalOutput = "Number of tests: " + numTests + " " + "Number of mutants: " + total + " " + "Mutants killed: " + succesful; FileUtils.writeStringToFile(mutLog, newLine + finalOutput, true); System.out.println(finalOutput + "\n"); }
From source file:io.joynr.util.JoynrUtil.java
public static void copyDirectory(File sourceLocation, File targetLocation) throws IOException { if (sourceLocation.isDirectory()) { if (!targetLocation.exists()) { if (targetLocation.mkdir() == false) { logger.debug("Creating target directory " + targetLocation + " failed."); }/*from w ww . j a v a2 s.com*/ } String[] children = sourceLocation.list(); if (children == null) { return; } for (int i = 0; i < children.length; i++) { copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i])); } } else { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(sourceLocation); out = new FileOutputStream(targetLocation); copyStream(in, out); } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }
From source file:com.mirth.connect.server.launcher.MirthLauncher.java
private static void createAppdataDir(Properties mirthProperties) { File appDataDirFile = null; if (mirthProperties.getProperty(PROPERTY_APP_DATA_DIR) != null) { appDataDirFile = new File(mirthProperties.getProperty(PROPERTY_APP_DATA_DIR)); if (!appDataDirFile.exists()) { if (appDataDirFile.mkdir()) { logger.debug("created app data dir: " + appDataDirFile.getAbsolutePath()); } else { logger.error("error creating app data dir: " + appDataDirFile.getAbsolutePath()); }//from w w w . j a v a 2s . c om } } else { appDataDirFile = new File("."); } appDataDir = appDataDirFile.getAbsolutePath(); logger.debug("set app data dir: " + appDataDir); }
From source file:Main.java
public static void createFile(File file, boolean isFile) { if (!file.exists()) { if (!file.getParentFile().exists()) { createFile(file.getParentFile(), false); } else {//from ww w .j a va 2s .c om if (isFile) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else { file.mkdir(); } } } }