diff --git a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java index f7e5ba2ec4..aa19c4cc55 100644 --- a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java +++ b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java @@ -556,6 +556,50 @@ public final class GerritLauncher { } } + /** + * Locate the path of the {@code buck-out} directory in a source tree. + * + * @throws FileNotFoundException if the directory cannot be found. + */ + public static File getDeveloperBuckOut() throws FileNotFoundException { + // Find ourselves in the CLASSPATH, we should be a loose class file. + Class self = GerritLauncher.class; + URL u = self.getResource(self.getSimpleName() + ".class"); + if (u == null) { + throw new FileNotFoundException("Cannot find class " + self.getName()); + } else if (!"file".equals(u.getProtocol())) { + throw new FileNotFoundException("Cannot find extract path from " + u); + } + + // Pop up to the top level classes folder that contains us. + File dir = new File(u.getPath()); + String myName = self.getName(); + for (;;) { + int dot = myName.lastIndexOf('.'); + if (dot < 0) { + dir = dir.getParentFile(); + break; + } + myName = myName.substring(0, dot); + dir = dir.getParentFile(); + } + + dir = popdir(u, dir, "classes"); + dir = popdir(u, dir, "eclipse"); + if ("buck-out".equals(dir.getName())) { + return dir; + } + throw new FileNotFoundException("Cannot find buck-out from " + u); + } + + private static File popdir(URL u, File dir, String name) + throws FileNotFoundException { + if (dir.getName().equals(name)) { + return dir.getParentFile(); + } + throw new FileNotFoundException("Cannot find buck-out from " + u); + } + private GerritLauncher() { } } diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java index 3d284e98d5..a57733712a 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java @@ -77,7 +77,6 @@ import java.io.PrintWriter; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.ArrayList; import java.util.EnumSet; import java.util.Enumeration; @@ -452,7 +451,7 @@ public class JettyServer { try { baseResource = unpackWar(GerritLauncher.getDistributionArchive()); } catch (FileNotFoundException err) { - if (err.getMessage() == GerritLauncher.NOT_ARCHIVED) { + if (GerritLauncher.NOT_ARCHIVED.equals(err.getMessage())) { baseResource = useDeveloperBuild(app); } else { throw err; @@ -537,39 +536,7 @@ public class JettyServer { private Resource useDeveloperBuild(ServletContextHandler app) throws IOException { - // Find ourselves in the CLASSPATH. We should be a loose class file. - // - URL u = getClass().getResource(getClass().getSimpleName() + ".class"); - if (u == null) { - throw new FileNotFoundException("Cannot find web application root"); - } - if (!"file".equals(u.getProtocol())) { - throw new FileNotFoundException("Cannot find web root from " + u); - } - - // Pop up to the top level classes folder that contains us. - // - File dir = new File(u.getPath()); - String myName = getClass().getName(); - for (;;) { - int dot = myName.lastIndexOf('.'); - if (dot < 0) { - dir = dir.getParentFile(); - break; - } - myName = myName.substring(0, dot); - dir = dir.getParentFile(); - } - - if (!dir.getName().equals("classes")) { - throw new FileNotFoundException("Cannot find web root from " + u); - } - dir = dir.getParentFile(); // pop classes - - if (!"buck-out".equals(dir.getName())) { - throw new FileNotFoundException("Cannot find web root from " + u); - } - + final File dir = GerritLauncher.getDeveloperBuckOut(); final File gen = new File(dir, "gen"); final File root = dir.getParentFile(); final File dstwar = makeWarTempDir(); diff --git a/tools/eclipse/project.py b/tools/eclipse/project.py index 6e02c35a11..50644ebe2d 100755 --- a/tools/eclipse/project.py +++ b/tools/eclipse/project.py @@ -72,12 +72,14 @@ def gen_classpath(): impl = minidom.getDOMImplementation() return impl.createDocument(None, 'classpath', None) - def classpathentry(kind, path, src=None): + def classpathentry(kind, path, src=None, out=None): e = doc.createElement('classpathentry') e.setAttribute('kind', kind) e.setAttribute('path', path) if src: e.setAttribute('sourcepath', src) + if out: + e.setAttribute('output', out) doc.documentElement.appendChild(e) doc = make_classpath() @@ -112,16 +114,29 @@ def gen_classpath(): gwt_src.add(m.group(1)) for s in sorted(src): + out = None + + if s.startswith('lib/'): + out = 'buck-out/eclipse/lib' + elif s.startswith('plugins/'): + out = 'buck-out/eclipse/' + s + p = path.join(s, 'java') if path.exists(p): - classpathentry('src', p) + classpathentry('src', p, out=out) continue for env in ['main', 'test']: + o = None + if out: + o = out + '/' + env + elif env == 'test': + o = 'buck-out/eclipse/test' + for srctype in ['java', 'resources']: p = path.join(s, 'src', env, srctype) if path.exists(p): - classpathentry('src', p) + classpathentry('src', p, out=o) for libs in [lib, gwt_lib]: for j in sorted(libs): @@ -133,14 +148,15 @@ def gen_classpath(): classpathentry('lib', j, s) for s in sorted(gwt_src): - classpathentry('lib', path.join(ROOT, s, 'src', 'main', 'java')) + p = path.join(ROOT, s, 'src', 'main', 'java') + classpathentry('lib', p, out='buck-out/eclipse/gwtsrc') classpathentry('con', JRE) - classpathentry('output', 'buck-out/classes') + classpathentry('output', 'buck-out/eclipse/classes') p = path.join(ROOT, '.classpath') with open(p, 'w') as fd: - doc.writexml(fd, addindent=' ', newl='\n', encoding='UTF-8') + doc.writexml(fd, addindent='\t', newl='\n', encoding='UTF-8') try: if args.src: