コード例 #1
0
  public static Manifest s_create(
      String strSpecVend,
      String strSpecVers,
      String strImplVend,
      String strImplVers,
      String strImplVendId) {

    // create the manifest object
    Manifest man = S_Manifest.s_create();

    Attributes attAttributes = man.getMainAttributes();

    if (strSpecVend != null) attAttributes.putValue(S_Manifest.f_s_strKeySpecVend, strSpecVend);

    if (strSpecVers != null) attAttributes.putValue(S_Manifest.f_s_strKeySpecVers, strSpecVers);

    if (strImplVend != null) attAttributes.putValue(S_Manifest.f_s_strKeyImplVend, strImplVend);

    if (strImplVers != null) attAttributes.putValue(S_Manifest.f_s_strKeyImplVers, strImplVers);

    if (strImplVendId != null)
      attAttributes.putValue(S_Manifest.f_s_strKeyImplVendId, strImplVendId);

    return man;
  }
コード例 #2
0
ファイル: ZipSigner.java プロジェクト: wangsongyan/zip-signer
  /** Add the SHA1 of every file to the manifest, creating it if necessary. */
  private Manifest addDigestsToManifest(Map<String, ZioEntry> entries)
      throws IOException, GeneralSecurityException {
    Manifest input = null;
    ZioEntry manifestEntry = entries.get(JarFile.MANIFEST_NAME);
    if (manifestEntry != null) {
      input = new Manifest();
      input.read(manifestEntry.getInputStream());
    }
    Manifest output = new Manifest();
    Attributes main = output.getMainAttributes();
    if (input != null) {
      main.putAll(input.getMainAttributes());
    } else {
      main.putValue("Manifest-Version", "1.0");
      main.putValue("Created-By", "1.0 (Android SignApk)");
    }

    // BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    byte[] buffer = new byte[512];
    int num;

    // We sort the input entries by name, and add them to the
    // output manifest in sorted order.  We expect that the output
    // map will be deterministic.

    TreeMap<String, ZioEntry> byName = new TreeMap<String, ZioEntry>();
    byName.putAll(entries);

    boolean debug = getLogger().isDebugEnabled();
    if (debug) getLogger().debug("Manifest entries:");
    for (ZioEntry entry : byName.values()) {
      if (canceled) break;
      String name = entry.getName();
      if (debug) getLogger().debug(name);
      if (!entry.isDirectory()
          && !name.equals(JarFile.MANIFEST_NAME)
          && !name.equals(CERT_SF_NAME)
          && !name.equals(CERT_RSA_NAME)
          && (stripPattern == null || !stripPattern.matcher(name).matches())) {

        progressHelper.progress(ProgressEvent.PRORITY_NORMAL, "Generating manifest");
        InputStream data = entry.getInputStream();
        while ((num = data.read(buffer)) > 0) {
          md.update(buffer, 0, num);
        }

        Attributes attr = null;
        if (input != null) {
          java.util.jar.Attributes inAttr = input.getAttributes(name);
          if (inAttr != null) attr = new Attributes(inAttr);
        }
        if (attr == null) attr = new Attributes();
        attr.putValue("SHA1-Digest", Base64.encode(md.digest()));
        output.getEntries().put(name, attr);
      }
    }

    return output;
  }
コード例 #3
0
 // TODO: includeRuntime should be not a flag but a path to runtime
 public static void writeToJar(
     ClassFileFactory factory,
     final OutputStream fos,
     @Nullable FqName mainClass,
     boolean includeRuntime) {
   try {
     Manifest manifest = new Manifest();
     final Attributes mainAttributes = manifest.getMainAttributes();
     mainAttributes.putValue("Manifest-Version", "1.0");
     mainAttributes.putValue("Created-By", "JetBrains Kotlin");
     if (mainClass != null) {
       mainAttributes.putValue("Main-Class", mainClass.getFqName());
     }
     JarOutputStream stream = new JarOutputStream(fos, manifest);
     for (String file : factory.files()) {
       stream.putNextEntry(new JarEntry(file));
       stream.write(factory.asBytes(file));
     }
     if (includeRuntime) {
       writeRuntimeToJar(stream);
     }
     stream.finish();
   } catch (IOException e) {
     throw new CompileEnvironmentException("Failed to generate jar file", e);
   }
 }
コード例 #4
0
ファイル: JarTool.java プロジェクト: suping/jboss-aejb-1
  /** Jars a given directory or single file into a JarOutputStream. */
  public void jarDir(File dirOrFile2Jar, File destJar) throws IOException {

    if (dirOrFile2Jar == null || destJar == null) throw new IllegalArgumentException();

    mDestJarName = destJar.getCanonicalPath();
    FileOutputStream fout = new FileOutputStream(destJar);

    JarOutputStream jout;

    if (MAIN_CLASS != null) {
      Manifest manifest = new Manifest();
      Attributes attrs = manifest.getMainAttributes();
      attrs.putValue("Manifest-Version", "1.0");
      attrs.putValue("Class-Path", ".");
      attrs.putValue("Main-Class", MAIN_CLASS);
      /** Manifest-Version: 1.0 Class-Path: . Main-Class: test.JarTool */
      jout = new JarOutputStream(fout, manifest);
    } else {
      jout = new JarOutputStream(fout);
    }
    // jout.setLevel(0);
    try {
      jarDir(dirOrFile2Jar, jout, null);
    } catch (IOException ioe) {
      throw ioe;
    } finally {
      jout.close();
      fout.close();
    }
  }
コード例 #5
0
ファイル: Signer.java プロジェクト: jvlstudio/KApkSigner
  private static void writeSignatureFile(Manifest manifest, SignatureOutputStream out)
      throws IOException, GeneralSecurityException {
    Manifest sf = new Manifest();
    Attributes main = sf.getMainAttributes();
    main.putValue("Signature-Version", "1.0");
    main.putValue("Created-By", "1.0 (KApkSigner)");
    BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    PrintStream print =
        new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true, "UTF-8");
    manifest.write(print);
    print.flush();
    main.putValue("SHA1-Digest-Manifest", base64.encode(md.digest()));
    Map<String, Attributes> entries = manifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
      // Digest of the manifest stanza for this entry.
      print.print("Name: " + entry.getKey() + "\r\n");
      for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
        print.print(att.getKey() + ": " + att.getValue() + "\r\n");
      }
      print.print("\r\n");
      print.flush();

      Attributes sfAttr = new Attributes();
      sfAttr.putValue("SHA1-Digest", base64.encode(md.digest()));
      sf.getEntries().put(entry.getKey(), sfAttr);
    }
    sf.write(out);
    if (out.size() % 1024 == 0) {
      out.write('\r');
      out.write('\n');
    }
  }
コード例 #6
0
ファイル: PackageFile.java プロジェクト: paulcager/andmore
 /**
  * Create a new Manifest with the basic values and the created by string
  *
  * @param createdBy who is creating this manifest
  * @return a new Manifest with basic values and desired created by string
  */
 public Manifest createManifest(String createdBy) {
   Manifest newManifest = new Manifest();
   Attributes mainAttributes = newManifest.getMainAttributes();
   mainAttributes.putValue(
       Attributes.Name.MANIFEST_VERSION.toString(), CertificateManagerActivator.MANIFEST_VERSION);
   mainAttributes.putValue(CertificateManagerActivator.CREATED_BY_FIELD, createdBy);
   return newManifest;
 }
コード例 #7
0
ファイル: AttributesTest.java プロジェクト: dennis-xlc/ORDER
 @Override
 protected void setUp() {
   a = new Attributes();
   a.putValue("1", "one");
   a.putValue("2", "two");
   a.putValue("3", "three");
   a.putValue("4", "four");
 }
コード例 #8
0
ファイル: AttributesTest.java プロジェクト: dennis-xlc/ORDER
 /** @tests java.util.jar.Attributes#equals(java.lang.Object) */
 public void test_equalsLjava_lang_Object() {
   Attributes.Name n1 = new Attributes.Name("name"), n2 = new Attributes.Name("Name");
   assertEquals(n1, n2);
   Attributes a1 = new Attributes();
   a1.putValue("one", "1");
   a1.putValue("two", "2");
   Attributes a2 = new Attributes();
   a2.putValue("One", "1");
   a2.putValue("TWO", "2");
   assertEquals(a1, a2);
 }
コード例 #9
0
 /** @return */
 @Override
 protected Attributes getColumnMap() {
   Attributes map = new Attributes();
   map.putValue("post", "POST_ID");
   map.putValue("login_name", TurbineUser.LOGIN_NAME_PROPERTY);
   map.putValue("name_kana", TurbineUser.LAST_NAME_KANA_PROPERTY);
   map.putValue(
       "userposition",
       TurbineUser.EIP_MUSER_POSITION_PROPERTY
           + "."
           + EipMUserPosition.POSITION_PROPERTY); // ユーザの順番
   return map;
 }
コード例 #10
0
ファイル: NoteClientSelectData.java プロジェクト: ntamvl/aipo
 /** @return */
 @Override
 protected Attributes getColumnMap() {
   Attributes map = new Attributes();
   map.putValue(
       "client_name", EipTNoteMap.EIP_TNOTE_PROPERTY + "." + EipTNote.CLIENT_NAME_PROPERTY);
   map.putValue(
       "subject_type", EipTNoteMap.EIP_TNOTE_PROPERTY + "." + EipTNote.SUBJECT_TYPE_PROPERTY);
   map.putValue(
       "create_date", EipTNoteMap.EIP_TNOTE_PROPERTY + "." + EipTNote.CREATE_DATE_PROPERTY);
   map.putValue(
       "accept_date", EipTNoteMap.EIP_TNOTE_PROPERTY + "." + EipTNote.ACCEPT_DATE_PROPERTY);
   map.putValue("note_stat", EipTNoteMap.NOTE_STAT_PROPERTY);
   return map;
 }
コード例 #11
0
  /** @return */
  @Override
  protected Attributes getColumnMap() {
    Attributes map = new Attributes();

    map.putValue(
        "corp_group",
        TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY
            + "."
            + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY
            + "."
            + TurbineGroup.GROUP_NAME_COLUMN);
    map.putValue("name_kana", TurbineUser.LAST_NAME_KANA_PROPERTY);

    return map;
  }
コード例 #12
0
ファイル: Signer.java プロジェクト: jvlstudio/KApkSigner
  private static Manifest addDigestsToManifest(JarFile jar)
      throws IOException, GeneralSecurityException {
    Manifest input = jar.getManifest();
    Manifest output = new Manifest();
    Attributes main = output.getMainAttributes();
    if (input != null) {
      main.putAll(input.getMainAttributes());
    } else {
      main.putValue("Manifest-Version", "1.0");
      main.putValue("Created-By", "1.0 (KApkSigner)");
    }

    BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    byte[] buffer = new byte[4096];
    int num;

    TreeMap<String, JarEntry> byName = new TreeMap<String, JarEntry>();

    for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ) {
      JarEntry entry = e.nextElement();
      byName.put(entry.getName(), entry);
    }

    for (JarEntry entry : byName.values()) {
      String name = entry.getName();
      if (!entry.isDirectory()
          && !name.equals(JarFile.MANIFEST_NAME)
          && !name.equals(Signer.CERT_SF_NAME)
          && !name.equals(Signer.CERT_RSA_NAME)
          && (Signer.stripPattern == null || !Signer.stripPattern.matcher(name).matches())) {
        InputStream data = jar.getInputStream(entry);
        while ((num = data.read(buffer)) > 0) {
          md.update(buffer, 0, num);
        }

        Attributes attr = null;
        if (input != null) {
          attr = input.getAttributes(name);
        }
        attr = attr != null ? new Attributes(attr) : new Attributes();
        attr.putValue("SHA1-Digest", base64.encode(md.digest()));
        output.getEntries().put(name, attr);
      }
    }

    return output;
  }
コード例 #13
0
  public static void s_fill(Manifest man) {
    String strMethod = _f_s_strClass + "s_fill(man)";

    if (man == null) {
      MySystem.s_printOutExit(strMethod, "nil man");
    }

    Attributes attAttributes = man.getMainAttributes();

    attAttributes.putValue(
        S_Manifest._f_s_strsDefaultEntryManifVersion[0],
        S_Manifest._f_s_strsDefaultEntryManifVersion[1]);

    attAttributes.putValue(
        S_Manifest._f_s_strsDefaultEntryManifCreator[0],
        S_Manifest._f_s_strsDefaultEntryManifCreator[1]);
  }
コード例 #14
0
  protected void redefineFoo() throws Exception {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    Attributes mainAttrs = manifest.getMainAttributes();
    mainAttrs.putValue("Agent-Class", FooAgent.class.getName());
    mainAttrs.putValue("Can-Redefine-Classes", "true");
    mainAttrs.putValue("Can-Retransform-Classes", "true");

    Path jar = Files.createTempFile("myagent", ".jar");
    try {
      JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(jar.toFile()), manifest);
      add(jarStream, FooAgent.class);
      add(jarStream, FooTransformer.class);
      jarStream.close();

      loadAgent(jar);
    } finally {
      Files.deleteIfExists(jar);
    }
  }
コード例 #15
0
  private InputStream createBundleStream(
      String name, String symbolicName, String version, List<String> imports) throws IOException {
    Manifest bundleManifest = new Manifest();
    Attributes attributes = bundleManifest.getMainAttributes();
    attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attributes.putValue("Bundle-ManifestVersion", "2");
    attributes.putValue("Bundle-Name", name);
    attributes.putValue("Bundle-SymbolicName", symbolicName);
    attributes.putValue("Bundle-Version", version);

    if (!imports.isEmpty()) {
      attributes.putValue("Import-Package", String.join(",", imports));
    }

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try (JarOutputStream target = new JarOutputStream(outputStream, bundleManifest)) {
      // you need at least one java class file for osgi bundle
      addJarEntry(DUMMY_CLASS_NAME, dummyBundleClassByteCodes, target);
    }
    return new ByteArrayInputStream(outputStream.toByteArray());
  }
コード例 #16
0
  public Manifest getManifest() throws MojoExecutionException {
    Manifest m = new Manifest();

    Attributes attributes = m.getMainAttributes();

    attributes.put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.0");

    attributes.putValue("Bundle-ManifestVersion", "2");
    Artifact artifact = project.getArtifact();
    attributes.putValue("Bundle-Version", getBundleVersion(artifact, true));
    attributes.putValue("Bundle-Name", project.getName());

    String symbolicName = (String) manifestAttributes.get("Bundle-SymbolicName");
    if (symbolicName == null) {
      symbolicName =
          getBundleSymbolicName(artifact.getGroupId(), artifact.getArtifactId())
              + ";singleton:=true";
    }
    attributes.putValue("Bundle-SymbolicName", symbolicName);

    if (organization != null) {
      attributes.putValue("Bundle-Vendor", organization);
    }

    attributes.putValue("Bundle-ClassPath", getBundleClasspath());

    String exportedPackages = getExportedPackages();
    if (exportedPackages != null) {
      attributes.putValue("Export-Package", exportedPackages);
    }

    String requiredBundles = getRequiredBundles();
    if (requiredBundles != null) {
      attributes.putValue("Require-Bundle", requiredBundles);
    }

    if (manifestAttributes != null) {
      for (Iterator i = manifestAttributes.entrySet().iterator(); i.hasNext(); ) {
        Entry e = (Entry) i.next();
        attributes.putValue((String) e.getKey(), (String) e.getValue());
      }
    }

    return m;
  }
コード例 #17
0
ファイル: WARDeployer.java プロジェクト: eclipse/virgo.web
  private final Manifest toManifest(Dictionary<String, String> headers) {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    Enumeration<String> names = headers.keys();

    while (names.hasMoreElements()) {
      String name = names.nextElement();
      String value = headers.get(name);

      attributes.putValue(name, value);
    }
    return manifest;
  }
コード例 #18
0
  private boolean expandVersion(Manifest mf) {
    Attributes attributes = mf.getMainAttributes();

    String version = attributes.getValue("Bundle-Version");
    if (version.endsWith(".qualifier")) {
      version = version.substring(0, version.lastIndexOf('.') + 1);
      version = version + df.format(new Date());
      attributes.putValue("Bundle-Version", version);

      return true;
    }

    return false;
  }
コード例 #19
0
 public void addExportedPackage(
     final IJavaProject pluginProject, final String... exportedPackages) {
   try {
     IProject _project = pluginProject.getProject();
     final IFile manifestFile = _project.getFile("META-INF/MANIFEST.MF");
     final InputStream manifestContent = manifestFile.getContents();
     Manifest _xtrycatchfinallyexpression = null;
     try {
       _xtrycatchfinallyexpression = new Manifest(manifestContent);
     } finally {
       manifestContent.close();
     }
     final Manifest manifest = _xtrycatchfinallyexpression;
     final Attributes attrs = manifest.getMainAttributes();
     boolean _containsKey = attrs.containsKey("Export-Package");
     if (_containsKey) {
       Object _get = attrs.get("Export-Package");
       String _plus = (_get + ",");
       String _join =
           IterableExtensions.join(((Iterable<?>) Conversions.doWrapArray(exportedPackages)), ",");
       String _plus_1 = (_plus + _join);
       attrs.putValue("Export-Package", _plus_1);
     } else {
       String _join_1 =
           IterableExtensions.join(((Iterable<?>) Conversions.doWrapArray(exportedPackages)), ",");
       attrs.putValue("Export-Package", _join_1);
     }
     final ByteArrayOutputStream out = new ByteArrayOutputStream();
     manifest.write(out);
     byte[] _byteArray = out.toByteArray();
     final ByteArrayInputStream in = new ByteArrayInputStream(_byteArray);
     BufferedInputStream _bufferedInputStream = new BufferedInputStream(in);
     manifestFile.setContents(_bufferedInputStream, true, true, null);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
コード例 #20
0
ファイル: AttributesTest.java プロジェクト: dennis-xlc/ORDER
 /** @tests java.util.jar.Attributes#putAll(java.util.Map) */
 public void test_putAllLjava_util_Map() {
   Attributes b = new Attributes();
   b.putValue("3", "san");
   b.putValue("4", "shi");
   b.putValue("5", "go");
   b.putValue("6", "roku");
   a.putAll(b);
   assertEquals("Should not have been replaced", "one", a.getValue("1"));
   assertEquals("Should have been replaced", "san", a.getValue("3"));
   assertEquals("Should have been added", "go", a.getValue("5"));
   Attributes atts = new Attributes();
   assertNull("Assert 0: ", atts.put(Attributes.Name.CLASS_PATH, "tools.jar"));
   assertNull("Assert 1: ", atts.put(Attributes.Name.MANIFEST_VERSION, "1"));
   Attributes atts2 = new Attributes();
   atts2.putAll(atts);
   assertEquals("Assert 2:", "tools.jar", atts2.get(Attributes.Name.CLASS_PATH));
   assertEquals("Assert 3: ", "1", atts2.get(Attributes.Name.MANIFEST_VERSION));
   try {
     atts.putAll(Collections.EMPTY_MAP);
     fail("Assert 4: no class cast from attrib parameter");
   } catch (ClassCastException e) {
     // Expected
   }
 }
  /**
   * Creates the default manifest in case none if found on the disk. By default, the imports are
   * synthetised based on the test class bytecode.
   *
   * @return default manifest for the jar created on the fly
   */
  protected Manifest createDefaultManifest() {
    Manifest manifest = new Manifest();
    Attributes attrs = manifest.getMainAttributes();

    // manifest versions
    attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attrs.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");

    String description = getName() + "-" + getClass().getName();
    // name/description
    attrs.putValue(Constants.BUNDLE_NAME, "TestBundle-" + description);
    attrs.putValue(Constants.BUNDLE_SYMBOLICNAME, "TestBundle-" + description);
    attrs.putValue(Constants.BUNDLE_DESCRIPTION, "on-the-fly test bundle");

    // activator
    attrs.putValue(Constants.BUNDLE_ACTIVATOR, JUnitTestActivator.class.getName());

    // add Import-Package entry
    addImportPackage(manifest);

    if (logger.isDebugEnabled())
      logger.debug("Created manifest:" + manifest.getMainAttributes().entrySet());
    return manifest;
  }
コード例 #22
0
  public void perform() {
    File dropinsFolder = new File(Utils.getCarbonComponentRepo(), "dropins");

    File dir = Utils.getBundleDirectory(EXTENSIONS_DIR);
    File[] files = dir.listFiles(new Utils.JarFileFilter());
    if (files != null) {
      for (File file : files) {
        try {
          Manifest mf = new Manifest();
          Attributes attribs = mf.getMainAttributes();
          attribs.putValue(LauncherConstants.FRAGMENT_HOST, "system.bundle; extension:=framework");
          Utils.createBundle(file, dropinsFolder, mf, EXTENSION_PREFIX);
        } catch (IOException e) {
          System.err.println(
              "Cannot create framework extension bundle from jar file " + file.getAbsolutePath());
          e.printStackTrace();
        }
      }
    }
  }
コード例 #23
0
  public static void setManifestEntries(final File manifestFile, final Map<String, String> entries)
      throws IOException {

    final Manifest manifest = new Manifest();

    if (manifestFile.exists()) {
      final InputStream in = new FileInputStream(manifestFile);

      try {
        manifest.read(new BufferedInputStream(in));
      } finally {
        try {
          in.close();
        } catch (IOException e) {
        }
      }
    }

    final Attributes mainAttributes = manifest.getMainAttributes();

    for (Map.Entry<String, String> entry : entries.entrySet()) {
      mainAttributes.putValue(entry.getKey(), entry.getValue());
    }

    final OutputStream out = new FileOutputStream(manifestFile);

    try {
      final BufferedOutputStream bout = new BufferedOutputStream(out);
      manifest.write(bout);
      bout.flush();
    } finally {
      try {
        out.close();
      } catch (IOException e) {
      }
    }
  }
コード例 #24
0
ファイル: ProjectLauncherImpl.java プロジェクト: hemantgp/bnd
  /**
   * Create a standalone executable. All entries on the runpath are rolled out into the JAR and the
   * runbundles are copied to a directory in the jar. The launcher will see that it starts in
   * embedded mode and will automatically detect that it should load the bundles from inside. This
   * is drive by the launcher.embedded flag.
   *
   * @throws Exception
   */
  @Override
  public Jar executable() throws Exception {

    // TODO use constants in the future
    Parameters packageHeader = OSGiHeader.parseHeader(project.getProperty("-package"));
    boolean useShas = packageHeader.containsKey("jpm");
    project.trace("Useshas %s %s", useShas, packageHeader);

    Jar jar = new Jar(project.getName());

    Builder b = new Builder();
    project.addClose(b);

    if (!project.getIncludeResource().isEmpty()) {
      b.setIncludeResource(project.getIncludeResource().toString());
      b.setProperty(Constants.RESOURCEONLY, "true");
      b.build();
      if (b.isOk()) {
        jar.addAll(b.getJar());
      }
      project.getInfo(b);
    }

    List<String> runpath = getRunpath();

    Set<String> runpathShas = new LinkedHashSet<String>();
    Set<String> runbundleShas = new LinkedHashSet<String>();
    List<String> classpath = new ArrayList<String>();

    for (String path : runpath) {
      project.trace("embedding runpath %s", path);
      File file = new File(path);
      if (file.isFile()) {
        if (useShas) {
          String sha = SHA1.digest(file).asHex();
          runpathShas.add(sha + ";name=\"" + file.getName() + "\"");
        } else {
          String newPath = "jar/" + file.getName();
          jar.putResource(newPath, new FileResource(file));
          classpath.add(newPath);
        }
      }
    }

    // Copy the bundles to the JAR

    List<String> runbundles = (List<String>) getRunBundles();
    List<String> actualPaths = new ArrayList<String>();

    for (String path : runbundles) {
      project.trace("embedding run bundles %s", path);
      File file = new File(path);
      if (!file.isFile()) project.error("Invalid entry in -runbundles %s", file);
      else {
        if (useShas) {
          String sha = SHA1.digest(file).asHex();
          runbundleShas.add(sha + ";name=\"" + file.getName() + "\"");
          actualPaths.add("${JPMREPO}/" + sha);
        } else {
          String newPath = "jar/" + file.getName();
          jar.putResource(newPath, new FileResource(file));
          actualPaths.add(newPath);
        }
      }
    }

    LauncherConstants lc = getConstants(actualPaths, true);
    lc.embedded = !useShas;
    lc.storageDir = null; // cannot use local info

    final Properties p = lc.getProperties(new UTF8Properties());

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p.store(bout, "");
    jar.putResource(
        LauncherConstants.DEFAULT_LAUNCHER_PROPERTIES,
        new EmbeddedResource(bout.toByteArray(), 0L));

    Manifest m = new Manifest();
    Attributes main = m.getMainAttributes();

    for (Entry<Object, Object> e : project.getFlattenedProperties().entrySet()) {
      String key = (String) e.getKey();
      if (key.length() > 0 && Character.isUpperCase(key.charAt(0)))
        main.putValue(key, (String) e.getValue());
    }

    Instructions instructions = new Instructions(project.getProperty(Constants.REMOVEHEADERS));
    Collection<Object> result = instructions.select(main.keySet(), false);
    main.keySet().removeAll(result);

    if (useShas) {
      project.trace("Use JPM launcher");
      m.getMainAttributes().putValue("Main-Class", JPM_LAUNCHER_FQN);
      m.getMainAttributes().putValue("JPM-Classpath", Processor.join(runpathShas));
      m.getMainAttributes().putValue("JPM-Runbundles", Processor.join(runbundleShas));
      URLResource jpmLauncher = new URLResource(this.getClass().getResource("/" + JPM_LAUNCHER));
      jar.putResource(JPM_LAUNCHER, jpmLauncher);
      doStart(jar, JPM_LAUNCHER_FQN);
    } else {
      project.trace("Use Embedded launcher");
      m.getMainAttributes().putValue("Main-Class", EMBEDDED_LAUNCHER_FQN);
      m.getMainAttributes().putValue(EmbeddedLauncher.EMBEDDED_RUNPATH, Processor.join(classpath));
      URLResource embeddedLauncher =
          new URLResource(this.getClass().getResource("/" + EMBEDDED_LAUNCHER));
      jar.putResource(EMBEDDED_LAUNCHER, embeddedLauncher);
      doStart(jar, EMBEDDED_LAUNCHER_FQN);
    }
    if (project.getProperty(Constants.DIGESTS) != null)
      jar.setDigestAlgorithms(project.getProperty(Constants.DIGESTS).trim().split("\\s*,\\s*"));
    else jar.setDigestAlgorithms(new String[] {"SHA-1", "MD-5"});
    jar.setManifest(m);
    return jar;
  }
コード例 #25
0
 /** @return */
 @Override
 protected Attributes getColumnMap() {
   Attributes map = new Attributes();
   map.putValue("name", EipTCommonCategory.NAME_PROPERTY);
   return map;
 }
コード例 #26
0
ファイル: AttributesTest.java プロジェクト: dennis-xlc/ORDER
 /** @tests java.util.jar.Attributes#clone() */
 public void test_clone() {
   Attributes a2 = (Attributes) a.clone();
   assertEquals(a, a2);
   a.putValue("1", "one(1)");
   assertTrue("equal", !a.equals(a2));
 }
コード例 #27
0
ファイル: AttributesTest.java プロジェクト: dennis-xlc/ORDER
 /** @tests java.util.jar.Attributes#Attributes(java.util.jar.Attributes) */
 public void test_ConstructorLjava_util_jar_Attributes() {
   Attributes a2 = new Attributes(a);
   assertEquals(a, a2);
   a.putValue("1", "one(1)");
   assertTrue("equal", !a.equals(a2));
 }
コード例 #28
0
 @Override
 protected Attributes getColumnMap() {
   Attributes map = new Attributes();
   map.putValue("group", VEipTScheduleList.USER_ID_PROPERTY);
   return map;
 }
コード例 #29
0
ファイル: MakeNBM.java プロジェクト: JSansalone/NetBeansIDE
 private Attributes getModuleAttributesForLocale(String locale) throws BuildException {
   if (locale == null) {
     throw new BuildException("Unknown locale: null", getLocation());
   }
   log("Processing module attributes for locale '" + locale + "'", Project.MSG_VERBOSE);
   Attributes attr;
   if ((!locale.equals("")) && (englishAttr != null)) {
     attr = new Attributes(englishAttr);
     attr.putValue("locale", locale);
     log(
         "Copying English module attributes to localized attributes in locale " + locale,
         Project.MSG_VERBOSE);
     String om = attr.getValue("OpenIDE-Module");
     String omn = attr.getValue("OpenIDE-Module-Name");
     String omdc = attr.getValue("OpenIDE-Module-Display-Category");
     String omsd = attr.getValue("OpenIDE-Module-Short-Description");
     String omld = attr.getValue("OpenIDE-Module-Long-Description");
     if (om != null)
       log(
           "OpenIDE-Module" + (locale.equals("") ? "" : "_" + locale) + " is " + om,
           Project.MSG_DEBUG);
     if (omn != null)
       log(
           "OpenIDE-Module-Name" + (locale.equals("") ? "" : "_" + locale) + " is " + omn,
           Project.MSG_DEBUG);
     if (omdc != null)
       log(
           "OpenIDE-Module-Display-Category"
               + (locale.equals("") ? "" : "_" + locale)
               + " is "
               + omdc,
           Project.MSG_DEBUG);
     if (omsd != null)
       log(
           "OpenIDE-Module-Short-Description"
               + (locale.equals("") ? "" : "_" + locale)
               + " is "
               + omsd,
           Project.MSG_DEBUG);
     if (omld != null)
       log(
           "OpenIDE-Module-Long-Description"
               + (locale.equals("") ? "" : "_" + locale)
               + " is "
               + omld,
           Project.MSG_DEBUG);
   } else {
     attr = new Attributes();
     attr.putValue("locale", locale);
   }
   moduleName = moduleName.replace(File.separatorChar, '/');
   String jarName = moduleName;
   String filename;
   String fname;
   String fext;
   if (!locale.equals("")) {
     // update file name for current locale
     filename = moduleName.substring(moduleName.lastIndexOf('/') + 1);
     fname = filename.substring(0, filename.lastIndexOf('.'));
     fext = filename.substring(filename.lastIndexOf('.'));
     jarName =
         moduleName.substring(0, moduleName.lastIndexOf('/'))
             + "/locale/"
             + fname
             + "_"
             + locale
             + fext;
   }
   log("Going to open jarfile " + jarName, Project.MSG_VERBOSE);
   File mfile = new File(productDir, jarName);
   if (!mfile.exists()) {
     // localizing jarfile does not exist, try to return english data
     if (englishAttr != null) {
       Attributes xattr = new Attributes(englishAttr);
       xattr.putValue("locale", locale);
       return xattr;
     } else {
       throw new BuildException(
           "Unable to find English/localized data about module (locale is '" + locale + "')",
           getLocation());
     }
   }
   try {
     JarFile mjar = new JarFile(mfile);
     try {
       if (mjar.getManifest().getMainAttributes().getValue("Bundle-SymbolicName") != null) {
         // #181025: treat bundles specially.
         return null;
       }
       if (attr.getValue("OpenIDE-Module") == null) {
         attr = mjar.getManifest().getMainAttributes();
         attr.putValue("locale", locale);
       }
       String bundlename =
           mjar.getManifest().getMainAttributes().getValue("OpenIDE-Module-Localizing-Bundle");
       if ((bundlename == null) && (englishAttr != null)) {
         String bname = englishAttr.getValue("OpenIDE-Module-Localizing-Bundle");
         String bfname;
         String bfext;
         if (bname != null) {
           bname = bname.replace(File.separatorChar, '/');
           bfname = bname.substring(0, bname.lastIndexOf('.'));
           bfext = bname.substring(bname.lastIndexOf('.'));
           bundlename = bfname + "_" + locale + bfext;
           log(
               "Determined (" + locale + ") localizing bundle name: " + bundlename,
               Project.MSG_VERBOSE);
         }
       }
       if (bundlename != null) {
         Properties p = new Properties();
         ZipEntry bundleentry = mjar.getEntry(bundlename);
         if (bundleentry != null) {
           InputStream is = mjar.getInputStream(bundleentry);
           try {
             p.load(is);
           } finally {
             is.close();
           }
           // Now pick up attributes from the bundle.
           Iterator it = p.entrySet().iterator();
           while (it.hasNext()) {
             Map.Entry entry = (Map.Entry) it.next();
             String name = (String) entry.getKey();
             if (!name.startsWith("OpenIDE-Module-")) continue;
             attr.putValue(name, (String) entry.getValue());
           }
         }
       }
     } finally {
       mjar.close();
     }
   } catch (IOException ioe) {
     throw new BuildException("exception while reading " + mfile.getName(), ioe, getLocation());
   }
   if (locale.equals("") && (englishAttr == null)) {
     log("Populating English module attributes", Project.MSG_VERBOSE);
     englishAttr = new Attributes(attr);
   }
   String om = attr.getValue("OpenIDE-Module");
   String omn = attr.getValue("OpenIDE-Module-Name");
   String omdc = attr.getValue("OpenIDE-Module-Display-Category");
   String omsd = attr.getValue("OpenIDE-Module-Short-Description");
   String omld = attr.getValue("OpenIDE-Module-Long-Description");
   if (om != null)
     log(
         "OpenIDE-Module" + (locale.equals("") ? "" : "_" + locale) + " is " + om,
         Project.MSG_VERBOSE);
   if (omn != null)
     log(
         "OpenIDE-Module-Name" + (locale.equals("") ? "" : "_" + locale) + " is " + omn,
         Project.MSG_VERBOSE);
   if (omdc != null)
     log(
         "OpenIDE-Module-Display-Category"
             + (locale.equals("") ? "" : "_" + locale)
             + " is "
             + omdc,
         Project.MSG_VERBOSE);
   if (omsd != null)
     log(
         "OpenIDE-Module-Short-Description"
             + (locale.equals("") ? "" : "_" + locale)
             + " is "
             + omsd,
         Project.MSG_VERBOSE);
   if (omld != null)
     log(
         "OpenIDE-Module-Long-Description"
             + (locale.equals("") ? "" : "_" + locale)
             + " is "
             + omld,
         Project.MSG_VERBOSE);
   return attr;
 }