package com.x.base.core.project.tools;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

import org.apache.commons.lang3.StringUtils;

public class PathTools {

	public static final String WEB_INF = "WEB-INF";
	public static final String WEB_INF_WEB_XML = "WEB-INF/web.xml";
	public static final String WEB_INF_CLASSES = "WEB-INF/classes";
	public static final String WEB_INF_CLASSES_LANGUAGE = "WEB-INF/classes/language";
	public static final String WEB_INF_LASTMODIFIED = "WEB-INF/lastModified";
	public static final String META_INF = "META";
	public static final String DOT_WAR = ".war";
	public static final String DOT_JAR = ".jar";
	public static final String DOT_ZIP = ".zip";
	public static final String DOT_BAT = ".bat";
	public static final String DOT_SH = ".sh";

	public static boolean shOrBat(Path path) {
		if (Files.exists(path) && (!Files.isDirectory(path))) {
			return StringUtils.endsWithAny(path.getFileName().toString().toLowerCase(), DOT_BAT, DOT_SH);
		}
		return false;
	}

	public static boolean jarOrZip(Path path) {
		if (Files.exists(path) && (!Files.isDirectory(path))) {
			return StringUtils.endsWithAny(path.getFileName().toString().toLowerCase(), DOT_JAR, DOT_ZIP);
		}
		return false;
	}

	public static boolean jar(Path path) {
		if (Files.exists(path) && (!Files.isDirectory(path))) {
			return StringUtils.endsWith(path.getFileName().toString().toLowerCase(), DOT_JAR);
		}
		return false;
	}

	public static boolean war(Path path) {
		if (Files.exists(path) && (!Files.isDirectory(path))) {
			return StringUtils.endsWith(path.getFileName().toString().toLowerCase(), DOT_WAR);
		}
		return false;
	}

	public static void copyDirectory(Path sourcePath, Path targetPath) throws IOException {
		Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs)
					throws IOException {
				Files.createDirectories(targetPath.resolve(sourcePath.relativize(dir)));
				return FileVisitResult.CONTINUE;
			}

			@Override
			public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
				Files.copy(file, targetPath.resolve(sourcePath.relativize(file)));
				return FileVisitResult.CONTINUE;
			}
		});
	}

}

@@ -2473,10 +2473,503 @@
 %7D);%0A%09%7D%0A%0A
+%09public static void deleteDirectory(Path directory) throws IOException %7B%0A%09%09Files.walkFileTree(directory, new SimpleFileVisitor%3CPath%3E() %7B%0A%09%09%09@Override%0A%09%09%09public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException %7B%0A%09%09%09%09Files.delete(file);%0A%09%09%09%09return FileVisitResult.CONTINUE;%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException %7B%0A%09%09%09%09Files.delete(dir);%0A%09%09%09%09return FileVisitResult.CONTINUE;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D%0A%0A
 %7D%0A

update PathTools