예제 #1
0
파일: Main.java 프로젝트: karianna/jdk8_tl
 /**
  * Expands list of files to process into full list of all files that can be found by recursively
  * descending directories.
  */
 void expand(File dir, String[] files, boolean isUpdate) {
   if (files == null) {
     return;
   }
   for (int i = 0; i < files.length; i++) {
     File f;
     if (dir == null) {
       f = new File(files[i]);
     } else {
       f = new File(dir, files[i]);
     }
     if (f.isFile()) {
       if (entries.add(f)) {
         if (isUpdate) entryMap.put(entryName(f.getPath()), f);
       }
     } else if (f.isDirectory()) {
       if (entries.add(f)) {
         if (isUpdate) {
           String dirPath = f.getPath();
           dirPath = (dirPath.endsWith(File.separator)) ? dirPath : (dirPath + File.separator);
           entryMap.put(entryName(dirPath), f);
         }
         expand(f, f.list(), isUpdate);
       }
     } else {
       error(formatMsg("error.nosuch.fileordir", String.valueOf(f)));
       ok = false;
     }
   }
 }
예제 #2
0
  /**
   * Read the version information from a file with a given file name. The file must be a jar
   * manifest file and all its entries are searched for package names and their specification
   * version information. All information is collected in a map for later lookup of package names
   * and their versions.
   *
   * @param versionFileName name of the jar file containing version information
   */
  public static String readVersionFromFile(String applicationName, String versionFileName) {
    try {
      FileInputStream fileInput = new FileInputStream(versionFileName);
      Manifest manifest = new Manifest();
      manifest.read(fileInput);

      Map entries = manifest.getEntries();
      // Now write out the pre-entry attributes
      Iterator entryIterator = entries.entrySet().iterator();
      while (entryIterator.hasNext()) {
        Map.Entry currentEntry = (Map.Entry) entryIterator.next();
        String packageName = currentEntry.getKey().toString();
        packageName = normalizePackageName(packageName);
        Attributes attributes = (Attributes) currentEntry.getValue();
        String packageSpecVersion = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
        packageSpecVersion = extractVersionInfo(packageSpecVersion);
        return packageSpecVersion;
      }
    } catch (IOException exception) {
      exception.printStackTrace();
    }

    // no version found
    return null;
  }
예제 #3
0
  /**
   * This is called when JPM runs in the background to start jobs
   *
   * @throws Exception
   */
  public void daemon() throws Exception {
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread("Daemon shutdown") {
              public void run() {

                for (Service service : startedByDaemon) {
                  try {
                    reporter.error("Stopping " + service);
                    service.stop();
                    reporter.error("Stopped " + service);
                  } catch (Exception e) {
                    // Ignore
                  }
                }
              }
            });
    List<ServiceData> services = getServices();
    Map<String, ServiceData> map = new HashMap<String, ServiceData>();
    for (ServiceData d : services) {
      map.put(d.name, d);
    }
    List<ServiceData> start = new ArrayList<ServiceData>();
    Set<ServiceData> set = new HashSet<ServiceData>();
    for (ServiceData sd : services) {
      checkStartup(map, start, sd, set);
    }

    if (start.isEmpty()) reporter.warning("No services to start");

    for (ServiceData sd : start) {
      try {
        Service service = getService(sd.name);
        reporter.trace("Starting " + service);
        String result = service.start();
        if (result != null) reporter.error("Started error " + result);
        else startedByDaemon.add(service);
        reporter.trace("Started " + service);
      } catch (Exception e) {
        reporter.error("Cannot start daemon %s, due to %s", sd.name, e);
      }
    }

    while (true) {
      for (Service sd : startedByDaemon) {
        try {
          if (!sd.isRunning()) {
            reporter.error("Starting due to failure " + sd);
            String result = sd.start();
            if (result != null) reporter.error("Started error " + result);
          }
        } catch (Exception e) {
          reporter.error("Cannot start daemon %s, due to %s", sd, e);
        }
      }
      Thread.sleep(10000);
    }
  }
 public Attributes getAttributes() throws IOException {
   if (URLJarFile.this.isSuperMan()) {
     Map e = URLJarFile.this.superEntries;
     if (e != null) {
       Attributes a = (Attributes) e.get(getName());
       if (a != null) return (Attributes) a.clone();
     }
   }
   return null;
 }
예제 #5
0
 /** Test export annotation. */
 public static void testExportAnnotation() throws Exception {
   Builder a = new Builder();
   a.addClasspath(new File("bin"));
   a.setProperty("build", "xyz");
   a.setProperty("Export-Package", "test.versionpolicy.api");
   a.build();
   Map<String, String> attrs = a.getExports().getByFQN("test.versionpolicy.api");
   assertEquals("1.2.0.xyz", attrs.get("version"));
   assertEquals("PrivateImpl", attrs.get("exclude:"));
   assertEquals("a", attrs.get("mandatory:"));
 }
예제 #6
0
  /** Test default package versions. */
  public static void testDefaultPackageVersion() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setProperty("Bundle-Version", "1.2.3");
    a.setProperty("Export-Package", "test.refer");
    Jar jar = a.build();

    Manifest m = jar.getManifest();
    Parameters exports =
        Processor.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE), null);
    Map<String, String> attrs = exports.get("test.refer");
    assertNotNull(attrs);
    assertEquals("1.2.3", attrs.get("version"));
  }
예제 #7
0
  /** Test import provide:. */
  public static void testExportProvided() throws Exception {
    Builder a = new Builder();
    a.addClasspath(IO.getFile("jar/osgi.jar"));
    a.addClasspath(new File("bin"));
    a.setProperty("Private-Package", "test.refer");
    a.setProperty("Export-Package", "org.osgi.service.http;provide:=true");
    Jar jar = a.build();
    Map<String, String> event = a.getImports().getByFQN("org.osgi.service.event");
    assertEquals("[1.0,2)", event.get("version"));
    Map<String, String> http = a.getImports().getByFQN("org.osgi.service.http");
    assertEquals("[1.2,1.3)", http.get("version"));

    Manifest m = jar.getManifest();
    String imports = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    assertFalse(imports.contains(Constants.PROVIDE_DIRECTIVE));
  }
예제 #8
0
  private void checkStartup(
      Map<String, ServiceData> map,
      List<ServiceData> start,
      ServiceData sd,
      Set<ServiceData> cyclic) {
    if (sd.after.isEmpty() || start.contains(sd)) return;

    if (cyclic.contains(sd)) {
      reporter.error("Cyclic dependency for " + sd.name);
      return;
    }

    cyclic.add(sd);

    for (String dependsOn : sd.after) {
      if (dependsOn.equals("boot")) continue;

      ServiceData deps = map.get(dependsOn);
      if (deps == null) {
        reporter.error("No such service " + dependsOn + " but " + sd.name + " depends on it");
      } else {
        checkStartup(map, start, deps, cyclic);
      }
    }
    start.add(sd);
  }
예제 #9
0
  @Override
  public boolean loadLibrary(String libname, boolean ignoreError, ClassLoader cl) {
    try {
      for (Entry<String, String> nativeEntry : platformNativeIndex.entrySet()) {
        if (nativeEntry.getKey().contains(libname)) {
          if (log.isDebugEnabled()) {
            log.debug(
                "Loading mapped entry: [{}] [{}] [{}]",
                libname,
                nativeEntry.getKey(),
                nativeEntry.getValue());
          }
          File nativeLibCopy =
              extractJarEntry(
                  nativeEntry.getValue(),
                  nativeEntry.getKey(),
                  System.getProperty(JAVA_TMP_DIR),
                  String.format("%s.jni", libname));
          System.load(nativeLibCopy.getAbsolutePath());
          return true;
        }
      }
    } catch (Exception e) {
      log.error("Unable to load native library [{}] - {}", libname, e);
    }

    if (log.isDebugEnabled()) {
      log.debug("No mapped library match for [{}]", libname);
    }
    return false;
  }
예제 #10
0
  /**
   * @param data
   * @param target
   * @throws Exception
   * @throws IOException
   */
  public String createCommand(CommandData data, boolean force) throws Exception, IOException {

    // TODO
    // if (Data.validate(data) != null)
    // return "Invalid command data: " + Data.validate(data);

    Map<String, String> map = null;
    if (data.trace) {
      map = new HashMap<String, String>();
      map.put("java.security.manager", "aQute.jpm.service.TraceSecurityManager");
      reporter.trace("tracing");
    }
    String s = platform.createCommand(data, map, force, service.getAbsolutePath());
    if (s == null) storeData(new File(commandDir, data.name), data);
    return s;
  }
예제 #11
0
  public GLBootstrap() throws Exception {

    System.setProperty("jogamp.gluegen.UseTempJarCache", "false");

    log.info(
        "Initializing native JOGL jar dependencies for platform [{}]. Temp jar cache disabled.",
        PlatformPropsImpl.os_and_arch);

    String nativeJarName = String.format("%s-%s", NATIVES, PlatformPropsImpl.os_and_arch);
    String[] classpathEntries =
        System.getProperty(JAVA_CLASSPATH).split(System.getProperty(JAVA_SEPARATOR));

    for (String jarPath : classpathEntries) {

      if (jarPath.contains(nativeJarName)) {

        if (log.isDebugEnabled()) {
          log.debug("Applicable platform jar: [{}]", jarPath);
        }

        JarFile jf = new JarFile(jarPath);

        try {
          Enumeration<JarEntry> jarEntries = jf.entries();

          while (jarEntries.hasMoreElements()) {

            JarEntry je = jarEntries.nextElement();

            if (!je.isDirectory() && !je.getName().contains(JAVA_META_INF)) {
              if (log.isDebugEnabled()) {
                log.debug("Mapping jar entry [{}] -> [{}]", je.getName(), jarPath);
              }
              if (log.isDebugEnabled() && platformNativeIndex.containsKey(je.getName())) {
                log.debug("Duplicate jar entry: [{}]", je.getName());
                log.debug("Mapped at: [{}]", platformNativeIndex.get(je.getName()));
                log.debug("Also at: [{}]", jarPath);
              }
              platformNativeIndex.put(je.getName(), jarPath);
            }
          }
        } finally {
          closeJar(jf);
        }
      }
    }
  }
예제 #12
0
  public Map<String, Revision> latest(Collection<Revision> list) {
    Map<String, Revision> programs = new HashMap<String, Library.Revision>();

    for (Revision r : list) {
      String coordinates = r.groupId + ":" + r.artifactId;
      if (r.classifier != null) coordinates += ":" + r.classifier;

      if (r.groupId.equals(Library.SHA_GROUP)) continue;

      Revision current = programs.get(coordinates);
      if (current == null) programs.put(coordinates, r);
      else {
        // who is better?
        if (compare(r, current) >= 0) programs.put(coordinates, r);
      }
    }
    return programs;
  }
예제 #13
0
 private static String getVersionString() {
   String findContainingJar = JarManager.findContainingJar(Main.class);
   try {
     StringBuffer buffer = new StringBuffer();
     JarFile jar = new JarFile(findContainingJar);
     final Manifest manifest = jar.getManifest();
     final Map<String, Attributes> attrs = manifest.getEntries();
     Attributes attr = attrs.get("org/apache/pig");
     String version = (String) attr.getValue("Implementation-Version");
     String svnRevision = (String) attr.getValue("Svn-Revision");
     String buildTime = (String) attr.getValue("Build-TimeStamp");
     // we use a version string similar to svn
     // svn, version 1.4.4 (r25188)
     // compiled Sep 23 2007, 22:32:34
     return "Apache Pig version " + version + " (r" + svnRevision + ") \ncompiled " + buildTime;
   } catch (Exception e) {
     throw new RuntimeException("unable to read pigs manifest file", e);
   }
 }
예제 #14
0
  /**
   * Writes the index file out to <code>jos</code>. <code>oldEntries</code> gives the names of the
   * files that were removed, <code>movedMap</code> maps from the new name to the old name.
   */
  private static void createIndex(JarOutputStream jos, List oldEntries, Map movedMap)
      throws IOException {
    StringWriter writer = new StringWriter();

    writer.write(VERSION_HEADER);
    writer.write("\r\n");

    // Write out entries that have been removed
    for (int counter = 0; counter < oldEntries.size(); counter++) {
      String name = (String) oldEntries.get(counter);

      writer.write(REMOVE_COMMAND);
      writer.write(" ");
      writeEscapedString(writer, name);
      writer.write("\r\n");
    }

    // And those that have moved
    Iterator names = movedMap.keySet().iterator();

    if (names != null) {
      while (names.hasNext()) {
        String newName = (String) names.next();
        String oldName = (String) movedMap.get(newName);

        writer.write(MOVE_COMMAND);
        writer.write(" ");
        writeEscapedString(writer, oldName);
        writer.write(" ");
        writeEscapedString(writer, newName);
        writer.write("\r\n");
      }
    }

    JarEntry je = new JarEntry(INDEX_NAME);
    byte[] bytes = writer.toString().getBytes("UTF-8");

    writer.close();
    jos.putNextEntry(je);
    jos.write(bytes, 0, bytes.length);
  }
예제 #15
0
 /*
  * Verify that the provider JAR files are signed properly, which
  * means the signer's certificate can be traced back to a
  * JCE trusted CA.
  * Return null if ok, failure Exception if verification failed.
  */
 static synchronized Exception getVerificationResult(Provider p) {
   Object o = verificationResults.get(p);
   if (o == PROVIDER_VERIFIED) {
     return null;
   } else if (o != null) {
     return (Exception) o;
   }
   if (verifyingProviders.get(p) != null) {
     // this method is static synchronized, must be recursion
     // return failure now but do not save the result
     return new NoSuchProviderException("Recursion during verification");
   }
   try {
     verifyingProviders.put(p, Boolean.FALSE);
     URL providerURL = getCodeBase(p.getClass());
     verifyProviderJar(providerURL);
     // Verified ok, cache result
     verificationResults.put(p, PROVIDER_VERIFIED);
     return null;
   } catch (Exception e) {
     verificationResults.put(p, e);
     return e;
   } finally {
     verifyingProviders.remove(p);
   }
 }
  public Manifest getManifest() throws IOException {

    if (!isSuperMan()) {
      return null;
    }

    Manifest man = new Manifest();
    Attributes attr = man.getMainAttributes();
    attr.putAll((Map) superAttr.clone());

    // now deep copy the manifest entries
    if (superEntries != null) {
      Map entries = man.getEntries();
      Iterator it = superEntries.keySet().iterator();
      while (it.hasNext()) {
        Object key = it.next();
        Attributes at = (Attributes) superEntries.get(key);
        entries.put(key, at.clone());
      }
    }

    return man;
  }
예제 #17
0
파일: Main.java 프로젝트: karianna/jdk8_tl
  /** Updates an existing jar file. */
  boolean update(InputStream in, OutputStream out, InputStream newManifest, JarIndex jarIndex)
      throws IOException {
    ZipInputStream zis = new ZipInputStream(in);
    ZipOutputStream zos = new JarOutputStream(out);
    ZipEntry e = null;
    boolean foundManifest = false;
    boolean updateOk = true;

    if (jarIndex != null) {
      addIndex(jarIndex, zos);
    }

    // put the old entries first, replace if necessary
    while ((e = zis.getNextEntry()) != null) {
      String name = e.getName();

      boolean isManifestEntry = equalsIgnoreCase(name, MANIFEST_NAME);

      if ((jarIndex != null && equalsIgnoreCase(name, INDEX_NAME)) || (Mflag && isManifestEntry)) {
        continue;
      } else if (isManifestEntry && ((newManifest != null) || (ename != null) || (pname != null))) {
        foundManifest = true;
        if (newManifest != null) {
          // Don't read from the newManifest InputStream, as we
          // might need it below, and we can't re-read the same data
          // twice.
          FileInputStream fis = new FileInputStream(mname);
          boolean ambiguous = isAmbiguousMainClass(new Manifest(fis));
          fis.close();
          if (ambiguous) {
            return false;
          }
        }

        // Update the manifest.
        Manifest old = new Manifest(zis);
        if (newManifest != null) {
          old.read(newManifest);
        }
        if (!updateManifest(old, zos)) {
          return false;
        }
      } else {
        if (!entryMap.containsKey(name)) { // copy the old stuff
          // do our own compression
          ZipEntry e2 = new ZipEntry(name);
          e2.setMethod(e.getMethod());
          e2.setTime(e.getTime());
          e2.setComment(e.getComment());
          e2.setExtra(e.getExtra());
          if (e.getMethod() == ZipEntry.STORED) {
            e2.setSize(e.getSize());
            e2.setCrc(e.getCrc());
          }
          zos.putNextEntry(e2);
          copy(zis, zos);
        } else { // replace with the new files
          File f = entryMap.get(name);
          addFile(zos, f);
          entryMap.remove(name);
          entries.remove(f);
        }
      }
    }

    // add the remaining new files
    for (File f : entries) {
      addFile(zos, f);
    }
    if (!foundManifest) {
      if (newManifest != null) {
        Manifest m = new Manifest(newManifest);
        updateOk = !isAmbiguousMainClass(m);
        if (updateOk) {
          if (!updateManifest(m, zos)) {
            updateOk = false;
          }
        }
      } else if (ename != null || pname != null) {
        if (!updateManifest(new Manifest(), zos)) {
          updateOk = false;
        }
      }
    }
    zis.close();
    zos.close();
    return updateOk;
  }