JettyServer: Use java.nio.file.Path
Change-Id: Ib92f88e86727053fca5367b81a171085057c47b2
This commit is contained in:
parent
fda7f712b3
commit
057e94530c
@ -29,6 +29,8 @@ import java.net.JarURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
@ -540,7 +542,7 @@ public final class GerritLauncher {
|
||||
*
|
||||
* @throws FileNotFoundException if the directory cannot be found.
|
||||
*/
|
||||
public static File getDeveloperBuckOut() throws FileNotFoundException {
|
||||
public static Path getDeveloperBuckOut() throws FileNotFoundException {
|
||||
// Find ourselves in the CLASSPATH, we should be a loose class file.
|
||||
Class<GerritLauncher> self = GerritLauncher.class;
|
||||
URL u = self.getResource(self.getSimpleName() + ".class");
|
||||
@ -551,39 +553,43 @@ public final class GerritLauncher {
|
||||
}
|
||||
|
||||
// Pop up to the top level classes folder that contains us.
|
||||
File dir = new File(u.getPath());
|
||||
Path dir = Paths.get(u.getPath());
|
||||
String myName = self.getName();
|
||||
for (;;) {
|
||||
int dot = myName.lastIndexOf('.');
|
||||
if (dot < 0) {
|
||||
dir = dir.getParentFile();
|
||||
dir = dir.getParent();
|
||||
break;
|
||||
}
|
||||
myName = myName.substring(0, dot);
|
||||
dir = dir.getParentFile();
|
||||
dir = dir.getParent();
|
||||
}
|
||||
|
||||
dir = popdir(u, dir, "classes");
|
||||
dir = popdir(u, dir, "eclipse");
|
||||
if ("buck-out".equals(dir.getName())) {
|
||||
if (last(dir).equals("buck-out")) {
|
||||
return dir;
|
||||
}
|
||||
throw new FileNotFoundException("Cannot find buck-out from " + u);
|
||||
}
|
||||
|
||||
private static File popdir(URL u, File dir, String name)
|
||||
private static String last(Path dir) {
|
||||
return dir.getName(dir.getNameCount() - 1).toString();
|
||||
}
|
||||
|
||||
private static Path popdir(URL u, Path dir, String name)
|
||||
throws FileNotFoundException {
|
||||
if (dir.getName().equals(name)) {
|
||||
return dir.getParentFile();
|
||||
if (last(dir).equals(name)) {
|
||||
return dir.getParent();
|
||||
}
|
||||
throw new FileNotFoundException("Cannot find buck-out from " + u);
|
||||
}
|
||||
|
||||
private static ClassLoader useDevClasspath()
|
||||
throws MalformedURLException, FileNotFoundException {
|
||||
File out = getDeveloperBuckOut();
|
||||
Path out = getDeveloperBuckOut();
|
||||
List<URL> dirs = new ArrayList<>();
|
||||
dirs.add(new File(new File(out, "eclipse"), "classes").toURI().toURL());
|
||||
dirs.add(out.resolve("eclipse").resolve("classes").toUri().toURL());
|
||||
ClassLoader cl = GerritLauncher.class.getClassLoader();
|
||||
for (URL u : ((URLClassLoader) cl).getURLs()) {
|
||||
if (includeJar(u)) {
|
||||
|
@ -83,6 +83,7 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Enumeration;
|
||||
@ -562,9 +563,9 @@ public class JettyServer {
|
||||
|
||||
private Resource useDeveloperBuild(ServletContextHandler app)
|
||||
throws IOException {
|
||||
final File dir = GerritLauncher.getDeveloperBuckOut();
|
||||
final File gen = new File(dir, "gen");
|
||||
final File root = dir.getParentFile();
|
||||
final Path dir = GerritLauncher.getDeveloperBuckOut();
|
||||
final Path gen = dir.resolve("gen");
|
||||
final Path root = dir.getParent();
|
||||
final File dstwar = makeWarTempDir();
|
||||
File ui = new File(dstwar, "gerrit_ui");
|
||||
File p = new File(ui, "permutations");
|
||||
@ -593,7 +594,7 @@ public class JettyServer {
|
||||
// $ buck targets --show_output //gerrit-gwtui:ui_safari \
|
||||
// | awk '{print $2}'
|
||||
String child = String.format("%s/__gwt_binary_%s__", pkg, target);
|
||||
File zip = new File(new File(gen, child), target + ".zip");
|
||||
File zip = gen.resolve(child).resolve(target + ".zip").toFile();
|
||||
|
||||
synchronized (this) {
|
||||
try {
|
||||
@ -643,13 +644,13 @@ public class JettyServer {
|
||||
return Resource.newResource(dstwar.toURI());
|
||||
}
|
||||
|
||||
private static void build(File root, File gen, String target)
|
||||
private static void build(Path root, Path gen, String target)
|
||||
throws IOException, BuildFailureException {
|
||||
log.info("buck build " + target);
|
||||
Properties properties = loadBuckProperties(gen);
|
||||
String buck = MoreObjects.firstNonNull(properties.getProperty("buck"), "buck");
|
||||
ProcessBuilder proc = new ProcessBuilder(buck, "build", target)
|
||||
.directory(root)
|
||||
.directory(root.toFile())
|
||||
.redirectErrorStream(true);
|
||||
if (properties.containsKey("PATH")) {
|
||||
proc.environment().put("PATH", properties.getProperty("PATH"));
|
||||
@ -677,11 +678,11 @@ public class JettyServer {
|
||||
log.info(String.format("UPDATED %s in %.3fs", target, time / 1000.0));
|
||||
}
|
||||
|
||||
private static Properties loadBuckProperties(File gen)
|
||||
private static Properties loadBuckProperties(Path gen)
|
||||
throws FileNotFoundException, IOException {
|
||||
Properties properties = new Properties();
|
||||
try (InputStream in = new FileInputStream(
|
||||
new File(new File(gen, "tools"), "buck.properties"))) {
|
||||
gen.resolve(Paths.get("tools/buck.properties")).toFile())) {
|
||||
properties.load(in);
|
||||
}
|
||||
return properties;
|
||||
|
Loading…
Reference in New Issue
Block a user