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