Exemple #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$
  }
Exemple #2
0
  protected void generateMetadataTarget() {
    if (configScriptGenerator.haveP2Bundles()) {
      script.printTargetDeclaration(TARGET_P2_METADATA, null, TARGET_P2_METADATA, null, null);

      ProductFile product = configScriptGenerator.getProductFile();
      String productPath = null;
      if (product != null) {
        File productFile = new File(product.getLocation());
        String modLocation = getProductDir() + productFile.getName();
        script.printAvailableTask(PROPERTY_P2_PRODUCT_MOD, modLocation, modLocation);
        script.printProperty(PROPERTY_P2_PRODUCT_MOD, product.getLocation());
        productPath = Utils.getPropertyFormat(PROPERTY_P2_PRODUCT_MOD);
      }

      script.printProperty(PROPERTY_P2_APPEND, "true"); // $NON-NLS-1$
      script.printProperty(PROPERTY_P2_COMPRESS, "false"); // $NON-NLS-1$
      script.printProperty(PROPERTY_P2_METADATA_REPO_NAME, ""); // $NON-NLS-1$
      script.printProperty(PROPERTY_P2_ARTIFACT_REPO_NAME, ""); // $NON-NLS-1$

      String versionAdvice = null;
      if (versionsList && product != null) {
        if (product.useFeatures())
          versionAdvice =
              getWorkingDirectory()
                  + '/'
                  + DEFAULT_FEATURE_VERSION_FILENAME_PREFIX
                  + PROPERTIES_FILE_SUFFIX;
        else
          versionAdvice =
              getWorkingDirectory()
                  + '/'
                  + DEFAULT_PLUGIN_VERSION_FILENAME_PREFIX
                  + PROPERTIES_FILE_SUFFIX;
      }
      generateP2FinalCall(script, productPath, versionAdvice);
      script.printTargetEnd();
    }
  }