launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java
changeset 1809 72a0dbfa2ae8
parent 1808 68c0229e193e
child 1942 f8cc2a015ece
     1.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Tue Mar 10 20:35:20 2015 +0100
     1.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Wed Mar 11 08:50:51 2015 +0100
     1.3 @@ -97,21 +97,14 @@
     1.4              if (u == null) {
     1.5                  throw new IOException("Cannot find InterruptedException class on classpath: " + System.getProperty("java.class.path"));
     1.6              }
     1.7 -            final URLConnection conn = u.openConnection();
     1.8 -            if (conn instanceof JarURLConnection) {
     1.9 -                JarURLConnection juc = (JarURLConnection)conn;
    1.10 -                rt = Bck2BrwsrJars.configureFrom(null, new File(juc.getJarFileURL().toURI()));
    1.11 -            } else {
    1.12 -                throw new FileNotFoundException("Not a JAR URL: " + u);
    1.13 -            }
    1.14 +            rt = configureFrom(u, null, 3);
    1.15          } catch (URISyntaxException ex) {
    1.16              throw new IOException(ex);
    1.17          }
    1.18          final Bck2Brwsr all;
    1.19          try {
    1.20              URL u = r.get(Bck2Brwsr.class.getName().replace('.', '/') + ".class", 0);
    1.21 -            JarURLConnection juc = (JarURLConnection)u.openConnection();
    1.22 -            all = Bck2BrwsrJars.configureFrom(rt, new File(juc.getJarFileURL().toURI()));
    1.23 +            all = configureFrom(u, rt, 4);
    1.24          } catch (URISyntaxException ex) {
    1.25              throw new IOException(ex);
    1.26          }
    1.27 @@ -127,4 +120,21 @@
    1.28                  }
    1.29              }).generate(sb);
    1.30      }
    1.31 +
    1.32 +    static Bck2Brwsr configureFrom(URL u, Bck2Brwsr rt, int parents) throws IOException, URISyntaxException {
    1.33 +        final URLConnection conn = u.openConnection();
    1.34 +        if (conn instanceof JarURLConnection) {
    1.35 +            JarURLConnection juc = (JarURLConnection)conn;
    1.36 +            rt = Bck2BrwsrJars.configureFrom(null, new File(juc.getJarFileURL().toURI()));
    1.37 +        } else if (u.getProtocol().equals("file")) {
    1.38 +            File dir = new File(u.toURI());
    1.39 +            while (parents-- > 0) {
    1.40 +                dir = dir.getParentFile();
    1.41 +            }
    1.42 +            rt = Bck2BrwsrJars.configureFrom(null, dir);
    1.43 +        } else {
    1.44 +            throw new FileNotFoundException("Not a JAR or file URL: " + u);
    1.45 +        }
    1.46 +        return rt;
    1.47 +    }
    1.48  }