示例#1
0
 private void checkManifestConnection(URL url) throws Exception {
   final URLConnection urlConnection = url.openConnection();
   final JarURLConnection jarURLConnection = (JarURLConnection) urlConnection;
   final Manifest manifest = jarURLConnection.getManifest();
   Assert.assertEquals("1.0", ManifestU.getAttribute(manifest, "Manifest-Version"));
   Assert.assertNotNull(ManifestU.getImplementationBuild(manifest));
 }
  /** @param url The url with a war scheme */
  @Override
  public URLConnection openConnection(URL url) throws IOException {
    // remove the war scheme.
    URL actual = new URL(url.toString().substring("war:".length()));

    // let's do some basic tests: see if this is a folder or not.
    // if it is a folder. we will try to support it.
    if (actual.getProtocol().equals("file")) {
      File file = new File(URIUtil.encodePath(actual.getPath()));
      if (file.exists()) {
        if (file.isDirectory()) {
          // TODO (not mandatory for rfc66 though)
        }
      }
    }

    // if (actual.toString().startsWith("file:/") && ! actual.to)
    URLConnection ori = (URLConnection) actual.openConnection();
    ori.setDefaultUseCaches(Resource.getDefaultUseCaches());
    JarURLConnection jarOri = null;
    try {
      if (ori instanceof JarURLConnection) {
        jarOri = (JarURLConnection) ori;
      } else {
        jarOri = (JarURLConnection) new URL("jar:" + actual.toString() + "!/").openConnection();
        jarOri.setDefaultUseCaches(Resource.getDefaultUseCaches());
      }
      Manifest mf =
          WarBundleManifestGenerator.createBundleManifest(
              jarOri.getManifest(), url, jarOri.getJarFile());
      try {
        jarOri.getJarFile().close();
        jarOri = null;
      } catch (Throwable t) {
      }
      return new WarURLConnection(actual, mf);
    } finally {
      if (jarOri != null)
        try {
          jarOri.getJarFile().close();
        } catch (Throwable t) {
        }
    }
  }
示例#3
0
  private BuildVersion() {
    try {
      URL url = this.getClass().getResource(REFERENCE_FILE);
      JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
      Manifest manifest = jarConnection.getManifest();

      version = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
      revision = manifest.getMainAttributes().getValue(Attributes.Name.SPECIFICATION_VERSION);
      buildDate = manifest.getMainAttributes().getValue("Compile-Timestamp");
      buildUser = manifest.getMainAttributes().getValue("Compile-User");
    } catch (Throwable e) {
      // System.out.println("Unable to read version information from manifest : not running from jar
      // files (Igored)");

      version = Const.VERSION;
      revision = "";
      buildDate = XMLHandler.date2string(new Date());
      buildUser = "";
    }
  }
  private static String getRegistrationClasses() {
    CentralRegistrationClass c = new CentralRegistrationClass();
    String name = c.getClass().getCanonicalName().replace('.', '/').concat(".class");
    try {
      Enumeration<URL> urlEnum = c.getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
      while (urlEnum.hasMoreElements()) {
        URL url = urlEnum.nextElement();
        String file = url.getFile();
        JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
        Manifest mf = jarConnection.getManifest();

        Attributes attrs = (Attributes) mf.getAttributes(name);
        if (attrs != null) {
          String classes = attrs.getValue("RegistrationClasses");
          return classes;
        }
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    return "";
  }