Beispiel #1
0
  /**
   * Generate an ant script that can be run to generate final p2 metadata for a product. Returns
   * null if p2 bundles aren't available.
   *
   * <p>If no product file is given, the generated p2 call generates final metadata for a
   * ${p2.root.name}_${p2.root.version} IU.
   *
   * <p>versionAdvice is a properties file with bsn=3.2.1.xyz entries
   *
   * @param workingDir - the directory in which to generate the script
   * @param productFileLocation - the location of a .product file (can be null)
   * @param versionAdvice - version advice (can be null)
   * @return The location of the generated script, or null
   * @throws CoreException
   */
  public static String generateP2ProductScript(
      String workingDir, String productFileLocation, Properties versionAdvice)
      throws CoreException {
    if (!loadP2Class()) return null;

    File working = new File(workingDir);
    working.mkdirs();

    File adviceFile = null;
    if (versionAdvice != null) {
      adviceFile = new File(working, "versionAdvice.properties"); // $NON-NLS-1$
      try {
        OutputStream os = new BufferedOutputStream(new FileOutputStream(adviceFile));
        try {
          versionAdvice.store(os, null);
        } finally {
          os.close();
        }
      } catch (IOException e) {
        String message = NLS.bind(Messages.exception_writingFile, adviceFile.toString());
        throw new CoreException(
            new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e));
      }
    }

    AntScript p2Script = null;
    try {
      p2Script = newAntScript(workingDir, "p2product.xml"); // $NON-NLS-1$
      p2Script.printProjectDeclaration(
          "P2 Product IU Generation", "main", "."); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      p2Script.println();
      p2Script.printProperty(PROPERTY_P2_APPEND, "true"); // $NON-NLS-1$
      p2Script.printProperty(PROPERTY_P2_COMPRESS, "false"); // $NON-NLS-1$
      p2Script.printProperty(PROPERTY_P2_METADATA_REPO_NAME, ""); // $NON-NLS-1$
      p2Script.printProperty(PROPERTY_P2_ARTIFACT_REPO_NAME, ""); // $NON-NLS-1$
      p2Script.printTargetDeclaration(
          "main",
          null,
          TARGET_P2_METADATA,
          null,
          "Generate the final Product IU"); //$NON-NLS-1$//$NON-NLS-2$
      generateP2FinalCall(
          p2Script, productFileLocation, adviceFile != null ? adviceFile.getAbsolutePath() : null);
      p2Script.printTargetEnd();
      p2Script.printProjectEnd();
    } finally {
      if (p2Script != null) p2Script.close();
    }
    return workingDir + "/p2product.xml"; // $NON-NLS-1$
  }
Beispiel #2
0
  private static void generateP2FinalCall(
      AntScript script, String productFileLocation, String versionAdvice) {
    script.printTab();
    script.print("<p2.generator "); // $NON-NLS-1$
    script.printAttribute(
        "append", Utils.getPropertyFormat(PROPERTY_P2_APPEND), true); // $NON-NLS-1$
    script.printAttribute(
        "flavor", Utils.getPropertyFormat(PROPERTY_P2_FLAVOR), true); // $NON-NLS-1$
    script.printAttribute(
        "compress", Utils.getPropertyFormat(PROPERTY_P2_COMPRESS), true); // $NON-NLS-1$
    script.printAttribute(
        "metadataRepository",
        Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO),
        true); //$NON-NLS-1$
    script.printAttribute(
        "artifactRepository",
        Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO),
        true); //$NON-NLS-1$
    script.printAttribute(
        "metadataRepositoryName",
        Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO_NAME),
        true); //$NON-NLS-1$
    script.printAttribute(
        "artifactRepositoryName",
        Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO_NAME),
        true); //$NON-NLS-1$
    script.printAttribute(
        "publishArtifacts",
        Utils.getPropertyFormat(PROPERTY_P2_PUBLISH_ARTIFACTS),
        true); //$NON-NLS-1$
    script.printAttribute("mode", "final", true); // $NON-NLS-1$ //$NON-NLS-2$

    if (productFileLocation != null) {
      script.printAttribute("productFile", productFileLocation, true); // $NON-NLS-1$
      if (versionAdvice != null)
        script.printAttribute("versionAdvice", versionAdvice, true); // $NON-NLS-1$
    } else {
      script.printAttribute(
          "root", Utils.getPropertyFormat(PROPERTY_P2_ROOT_NAME), true); // $NON-NLS-1$
      script.printAttribute(
          "rootVersion", Utils.getPropertyFormat(PROPERTY_P2_ROOT_VERSION), true); // $NON-NLS-1$
    }

    script.println("/>"); // $NON-NLS-1$
  }