List of usage examples for org.apache.commons.io FileUtils deleteDirectory
public static void deleteDirectory(File directory) throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { File directory = new File("c:\\"); FileUtils.deleteDirectory(directory); }
From source file:edu.nju.cs.inform.jgit.CreateNewRepository.java
public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException { // prepare a new folder File localPath = File.createTempFile("TestGitRepository", ""); localPath.delete();//from www . ja v a 2s .c o m // create the directory try (Git git = Git.init().setDirectory(localPath).call()) { System.out.println("Having repository: " + git.getRepository().getDirectory()); } FileUtils.deleteDirectory(localPath); }
From source file:io.apiman.tools.jdbc.ApimanJdbcServer.java
public static void main(String[] args) { try {/*from w w w .j a v a 2 s.c o m*/ File dataDir = new File("target/h2"); String url = "jdbc:h2:tcp://localhost:9092/apiman"; if (dataDir.exists()) { FileUtils.deleteDirectory(dataDir); } dataDir.mkdirs(); Server.createTcpServer("-tcpPassword", "sa", "-baseDir", dataDir.getAbsolutePath(), "-tcpPort", "9092", "-tcpAllowOthers").start(); Class.forName("org.h2.Driver"); try (Connection connection = DriverManager.getConnection(url, "sa", "")) { System.out.println("Connection Established: " + connection.getMetaData().getDatabaseProductName() + "/" + connection.getCatalog()); executeUpdate(connection, "CREATE TABLE users ( username varchar(255) NOT NULL, password varchar(255) NOT NULL, PRIMARY KEY (username))"); executeUpdate(connection, "INSERT INTO users (username, password) VALUES ('bwayne', 'ae2efd698aefdf366736a4eda1bc5241f9fbfec7')"); executeUpdate(connection, "INSERT INTO users (username, password) VALUES ('ckent', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')"); executeUpdate(connection, "INSERT INTO users (username, password) VALUES ('ballen', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')"); executeUpdate(connection, "CREATE TABLE roles (rolename varchar(255) NOT NULL, username varchar(255) NOT NULL)"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('user', 'bwayne')"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('admin', 'bwayne')"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('ckent', 'user')"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('ballen', 'user')"); } System.out.println("======================================================"); System.out.println("JDBC (H2) server started successfully."); System.out.println(""); System.out.println(" Data: " + dataDir.getAbsolutePath()); System.out.println(" JDBC URL: " + url); System.out.println(" JDBC User: sa"); System.out.println(" JDBC Password: "); System.out.println( " Authentication Query: SELECT * FROM users u WHERE u.username = ? AND u.password = ?"); System.out.println(" Authorization Query: SELECT r.rolename FROM roles r WHERE r.username = ?"); System.out.println("======================================================"); System.out.println(""); System.out.println(""); System.out.println("Press Enter to stop the JDBC server."); new BufferedReader(new InputStreamReader(System.in)).readLine(); System.out.println("Shutting down the JDBC server..."); Server.shutdownTcpServer("tcp://localhost:9092", "", true, true); System.out.println("Done!"); } catch (Exception e) { e.printStackTrace(); } }
From source file:fr.dutra.tools.maven.deptree.extras.VelocityRendererMain.java
/** * Arguments list:/*from w w w . j a v a 2 s.c o m*/ * <ol> * <li>Full path of dependency tree file to parse;</li> * <li>Dependency tree file format; must be the (case-insensitive) name of a <code>{@link InputType}</code> enum;</li> * <li>Full path to the output directory where HTML files and static resources will be generated (<em>this directory will be erased</em>);</li> * <li>Renderer format; must be the (case-insensitive) name of a <code>{@link VelocityRenderType}</code> enum;</li> * </ol> * @param args * @throws ParseException * @throws IOException * @throws VisitException */ public static void main(String[] args) throws IOException, ParseException, VisitException { InputType format = InputType.valueOf(args[1].toUpperCase()); Parser parser = format.newParser(); Node tree = parser.parse(new FileReader(args[0])); File outputDir = new File(args[2]); FileUtils.deleteDirectory(outputDir); outputDir.mkdirs(); VelocityRenderer renderer = VelocityRenderType.valueOf(args[3].toUpperCase()).newRenderer(); renderer.setFileName("index.html"); renderer.setOutputDir(outputDir); renderer.visit(tree); }
From source file:com.ifeng.sorter.LogSortDriver.java
public static void main(String[] args) throws Exception { String input = "src/test/resources/data/nginx_report.txt"; String output = "src/test/resources/nginx/p1/"; FileUtils.deleteDirectory(new File(output)); args = new String[] { input, output }; int exitCode = ToolRunner.run(new LogSortDriver(), args); System.exit(exitCode);/*from w w w . j av a2s . com*/ }
From source file:fr.gael.dhus.database.util.RestoreDatabase.java
/** * @param args/*w w w .j a va 2s . co m*/ * @throws IllegalAccessException * @throws IOException */ public static void main(String[] args) throws IllegalAccessException, IOException { if (args.length != 2) { throw new IllegalArgumentException(RestoreDatabase.class.getCanonicalName() + ": Wrong arguments <source path> <destination path>."); } File dump = new File(args[0]); File db = new File(args[1]); logger.info("Restoring " + dump.getPath() + " into " + db.getPath() + "."); if (!db.exists()) throw new IllegalArgumentException(RestoreDatabase.class.getCanonicalName() + ": Input database path not found (\"" + db.getPath() + "\")."); if (!dump.exists()) throw new IllegalArgumentException(RestoreDatabase.class.getCanonicalName() + ": Input database dump path not found (\"" + db.getPath() + "\")."); FileUtils.deleteDirectory(db); FileUtils.copyDirectory(dump, db); logger.info("Dump properly restored, please restart system now."); }
From source file:ezbake.local.accumulo.LocalAccumulo.java
public static void main(String args[]) throws Exception { Logger logger = LoggerFactory.getLogger(LocalAccumulo.class); final File accumuloDirectory = Files.createTempDir(); int shutdownPort = 4445; MiniAccumuloConfig config = new MiniAccumuloConfig(accumuloDirectory, "strongpassword"); config.setZooKeeperPort(12181);//from ww w .jav a 2 s . co m final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(config); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { accumulo.stop(); FileUtils.deleteDirectory(accumuloDirectory); System.out.println("\nShut down gracefully on " + new Date()); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }); accumulo.start(); printInfo(accumulo, shutdownPort); if (args.length > 0) { logger.info("Adding the following authorizations: {}", Arrays.toString(args)); Authorizations auths = new Authorizations(args); Instance inst = new ZooKeeperInstance(accumulo.getConfig().getInstanceName(), accumulo.getZooKeepers()); Connector client = inst.getConnector("root", new PasswordToken(accumulo.getConfig().getRootPassword())); logger.info("Connected..."); client.securityOperations().changeUserAuthorizations("root", auths); logger.info("Auths updated"); } // start a socket on the shutdown port and block- anything connected to this port will activate the shutdown ServerSocket shutdownServer = new ServerSocket(shutdownPort); shutdownServer.accept(); System.exit(0); }
From source file:eu.qualimaster.easy.extension.debug.DebugProfile.java
/** * Executes the test./* www .j av a 2s .c o m*/ * * @param args the first argument shall be the model location * @throws ModelManagementException in case that obtaining the models fails * @throws IOException if file operations fail */ public static void main(String[] args) throws ModelManagementException, IOException { if (0 == args.length) { System.out.println("qualimaster.profile: <model location>"); System.exit(0); } else { Properties prop = new Properties(); prop.put(CoordinationConfiguration.PIPELINE_ELEMENTS_REPOSITORY, "https://projects.sse.uni-hildesheim.de/qm/maven/"); CoordinationConfiguration.configure(prop, false); File tmp = new File(FileUtils.getTempDirectory(), "qmDebugProfile"); FileUtils.deleteDirectory(tmp); tmp.mkdirs(); File modelLocation = new File(args[0]); if (!modelLocation.exists()) { System.out.println("model location " + modelLocation + " does not exist"); System.exit(0); } initialize(); ModelInitializer.registerLoader(ProgressObserver.NO_OBSERVER); ModelInitializer.addLocation(modelLocation, ProgressObserver.NO_OBSERVER); Project project = RepositoryHelper.obtainModel(VarModel.INSTANCE, "QM", null); // create descriptor before clearing the location - in infrastructure pass vil directly/resolve VIL Configuration monConfig = RepositoryHelper.createConfiguration(project, "MONITORING"); QmProjectDescriptor source = new QmProjectDescriptor(tmp); try { ProfileData data = AlgorithmProfileHelper.createProfilePipeline(monConfig, "ProfileTestPip", "fCorrelationFinancial", "TopoSoftwareCorrelationFinancial", source); // "fPreprocessor", "Preprocessor", source); System.out.println("Creation successful. " + data.getPipeline()); } catch (VilException e) { e.printStackTrace(); } ModelInitializer.removeLocation(modelLocation, ProgressObserver.NO_OBSERVER); } }
From source file:com.simpligility.maven.provisioner.MavenRepositoryProvisioner.java
public static void main(String[] args) { JCommander jcommander = null;/*from w w w .j ava 2 s . c o m*/ Boolean validConfig = false; logger.info("-----------------------------------"); logger.info(" Maven Repository Provisioner "); logger.info(" simpligility technologies inc. "); logger.info(" http://www.simpligility.com "); logger.info("-----------------------------------"); StringBuilder usage = new StringBuilder(); config = new Configuration(); try { jcommander = new JCommander(config); jcommander.usage(usage); jcommander.parse(args); validConfig = true; } catch (Exception error) { logger.info(usage.toString()); } if (validConfig) { if (config.getHelp()) { logger.info(usage.toString()); } else { logger.info("Provisioning: " + config.getArtifactCoordinate()); logger.info("Source: " + config.getSourceUrl()); logger.info("Target: " + config.getTargetUrl()); logger.info("Username: " + config.getUsername()); if (config.getPassword() != null) { logger.info("Password: " + config.getPassword().replaceAll(".", "***")); } logger.info("IncludeSources:" + config.getIncludeSources()); logger.info("IncludeJavadoc:" + config.getIncludeJavadoc()); logger.info("Local cache directory: " + config.getCacheDirectory()); cacheDirectory = new File(config.getCacheDirectory()); if (cacheDirectory.exists() && cacheDirectory.isDirectory()) { logger.info("Detected local cache directory '" + config.getCacheDirectory() + "' from prior execution."); try { FileUtils.deleteDirectory(cacheDirectory); logger.info(config.getCacheDirectory() + " deleted."); } catch (IOException e) { logger.info(config.getCacheDirectory() + " deletion failed"); } cacheDirectory = new File(config.getCacheDirectory()); } ArtifactRetriever retriever = new ArtifactRetriever(cacheDirectory); retriever.retrieve(config.getArtifactCoordinates(), config.getSourceUrl(), config.getIncludeSources(), config.getIncludeJavadoc()); logger.info("--------------------------------------------"); logger.info("Artifact retrieval completed."); logger.info("--------------------------------------------"); MavenRepositoryHelper helper = new MavenRepositoryHelper(cacheDirectory); helper.deployToRemote(config.getTargetUrl(), config.getUsername(), config.getPassword()); logger.info("--------------------------------------------"); logger.info("Artifact deployment completed."); logger.info("--------------------------------------------"); } } }
From source file:com.atlauncher.Bootstrap.java
public static void main(String[] args) { String json = null;/* w ww. j a v a2 s.co m*/ if (!Files.isDirectory(PATH)) { try { Files.createDirectories(PATH); } catch (IOException e) { e.printStackTrace(); } } try { json = IOUtils.toString(URI.create("http://download.nodecdn.net/containers/atl/v4/app.json")); } catch (IOException e) { e.printStackTrace(); System.exit(1); } Application application = GSON.fromJson(json, Application.class); Dependency currentDependency = null; if (Files.exists(PATH.resolve("nwjs.json"))) { try { currentDependency = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("nwjs.json").toFile()), Dependency.class); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } for (Dependency dependency : application.getDependencies()) { if (dependency.shouldInstall() && !dependency.matches(currentDependency)) { if (Files.isDirectory(PATH.resolve("nwjs/"))) { try { FileUtils.deleteDirectory(PATH.resolve("nwjs/").toFile()); } catch (IOException e) { e.printStackTrace(); } } try { File zipFile = PATH.resolve("nwjs/temp.zip").toFile(); FileUtils.copyURLToFile(dependency.getUrl(), zipFile); Utils.unzip(zipFile, PATH.resolve("nwjs/").toFile()); FileUtils.forceDelete(zipFile); currentDependency = dependency; FileUtils.writeStringToFile(PATH.resolve("nwjs.json").toFile(), GSON.toJson(dependency)); break; } catch (IOException e) { e.printStackTrace(); System.exit(1); } } } App currentApp = null; if (Files.exists(PATH.resolve("app.json"))) { try { currentApp = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("app.json").toFile()), App.class); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } if (!application.getApp().matches(currentApp) || (currentApp != null && !Files.exists(PATH.resolve(currentApp.getFilename())))) { if (currentApp != null && Files.exists(PATH.resolve(currentApp.getFilename()))) { try { FileUtils.forceDelete(PATH.resolve(currentApp.getFilename()).toFile()); } catch (IOException e) { e.printStackTrace(); } } try { FileUtils.copyURLToFile(application.getApp().getUrl(), PATH.resolve(application.getApp().getFilename()).toFile()); currentApp = application.getApp(); FileUtils.writeStringToFile(PATH.resolve("app.json").toFile(), GSON.toJson(application.getApp())); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } if (currentDependency == null || currentApp == null) { System.exit(1); } List<String> arguments = new ArrayList<>(); arguments.add(PATH.resolve("nwjs/").toAbsolutePath() + currentDependency.getStartup()); arguments.add(currentApp.getFilename()); ProcessBuilder processBuilder = new ProcessBuilder(arguments); processBuilder.directory(PATH.toFile()); try { processBuilder.start(); } catch (IOException e) { e.printStackTrace(); } }