Exemple #1
0
 /**
  * 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;
 }
  @Test
  public void suppliedManifestHasPrecedence() {
    // When
    final Archive<?> archive =
        ShrinkWrap.create(MavenImporter.class)
            .loadPomFromFile("src/it/jar-with-mf-sample/pom.xml")
            .importBuildOutput()
            .as(JavaArchive.class);

    // Then
    assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "User"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"));
  }
  @Test
  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testGetHeaders() throws Exception {
    Archive<?> assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1");
    Bundle bundle = installBundle(assembly);
    try {
      Dictionary expected = new Hashtable();
      expected.put(Constants.BUNDLE_NAME, "Simple1");
      expected.put(Constants.BUNDLE_SYMBOLICNAME, "simple1");
      expected.put(Constants.BUNDLE_MANIFESTVERSION, "2");
      expected.put(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
      expected.put(Attributes.Name.IMPLEMENTATION_TITLE.toString(), "JBoss OSGi tests");
      expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
      expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "test");

      Dictionary dictionary = bundle.getHeaders();
      assertEquals(expected, dictionary);
    } finally {
      bundle.uninstall();
    }
  }
public final class S_Manifest {
  // -------------------
  // PUBLIC STATIC FINAL

  public static final String f_s_strDirParentManifest = "META-INF";
  public static final String f_s_strPathRelManifest =
      S_Manifest.f_s_strDirParentManifest + "/MANIFEST.MF";

  public static final String f_s_strKeySpecVend = "Specification-Vendor";
  public static final String f_s_strKeySpecVers = "Specification-Version";
  public static final String f_s_strKeyImplVend = "Implementation-Vendor";
  public static final String f_s_strKeyImplVers = "Implementation-Version";
  public static final String f_s_strKeyImplVendId = "Implementation-Vendor-Id";

  // --------------------
  // PRIVATE STATIC FINAL

  private static final String _f_s_strClass =
      "com.google.code.p.keytooliui.share.util.jar.S_Manifest.";

  private static final String _f_s_strManifVersion = "1.0";

  private static final String[] _f_s_strsDefaultEntryManifVersion = {
    Attributes.Name.MANIFEST_VERSION.toString(), S_Manifest._f_s_strManifVersion
  };

  private static final String[] _f_s_strsDefaultEntryManifCreator = {
    // ----
    // arg #0
    "Created-By",

    // ----
    // arg #1
    System.getProperty("java.version") + " (" + System.getProperty("java.vendor") + ")"
  };

  // -------------
  // PUBLIC STATIC

  /* transform manifest in an array of byte
      if any code error, exit
      else if any error, show dialog, then return nil
  */
  public static byte[] s_toByteArray(Manifest man, Frame frmOwner) {
    String strMethod = _f_s_strClass + "s_toByteArray(...)";

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

    ByteArrayOutputStream baoBuffer = new ByteArrayOutputStream();

    try {
      man.write(baoBuffer);
      baoBuffer.flush();
      baoBuffer.close();
    } catch (IOException excIO) {
      excIO.printStackTrace();
      MySystem.s_printOutExit(strMethod, "excIO caught");

      String strBody = "Got IO exception";

      OPAbstract.s_showDialogError(frmOwner, strBody);

      return null;
    }

    return baoBuffer.toByteArray();
  }

  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;
  }

  public static Manifest s_create() {
    // create the manifest object
    Manifest man = new Manifest();

    S_Manifest.s_fill(man);

    return man;
  }

  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]);
  }
}
Exemple #5
0
 /**
  * Sets the default attributes to manifest. If one of those attributes already exists on
  * metaInfAttributes map, it will be replaced.
  *
  * @param metaInfAttributes
  */
 private void setDefaultAttributes(Map<String, String> metaInfAttributes) {
   metaInfAttributes.put(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
   metaInfAttributes.put(MANIFEST_BUILD_TIMESTAMP_PROPERTY, dateFormatter.format(new Date()));
 }