Beispiel #1
0
  private void updateMarkedFeatures() throws Exception {
    for (String feature : feature2update) {
      logger.debug("FeatureUpdater.updateMarkedFeatures() UPDATE " + feature);
      File featureXMLFile = new File(bu.getFeatureXMLFile(feature));
      Document document = new SAXBuilder().build(featureXMLFile);
      Element root = document.getRootElement();

      // update version number
      String[] pattern = bu.getNumVersionPattern();
      String[] number = root.getAttributeValue("version").split("\\.");
      String newVersion = bu.update(number, pattern);
      root.setAttribute("version", newVersion);
      featuresNewsVersion.put(feature, newVersion);
      // update plugins version
      logger.debug("FeatureUpdater.updateMarkedFeatures() Update plugins Refs");
      List<?> listPlugins = root.getChildren("plugin");
      for (Object object : listPlugins) {
        Element courant = (Element) object;
        String pluginId = courant.getAttributeValue("id");
        if (bu.getProjects().contains(pluginId)) {
          String newVersionNumber = pu.getPluginVersion(pluginId);
          String oldVersionNumber = courant.getAttributeValue("version");
          if (!oldVersionNumber.equals(newVersionNumber)) {
            courant.setAttribute("version", newVersionNumber);
            // on indique que le numéro de feature doit changer
            logger.debug(
                "\t\tFeatureUpdater.updateMarkedFeatures() update plugin ref "
                    + pluginId
                    + ":"
                    + oldVersionNumber
                    + " -> "
                    + newVersionNumber);
          }
        } else {
          logger.debug("unable to check version plugin not managed :" + pluginId);
          logger.debug(
              "Mainly caused by feature that include binary plugins (com.bluexml.side.Integration.eclipse.dependencies.feature)");
        }
      }

      // update included features version
      logger.debug("FeatureUpdater.updateMarkedFeatures() Update features Refs");
      List<?> listIncludedFeatures = root.getChildren("includes");
      for (Object object : listIncludedFeatures) {
        Element currentNode = (Element) object;
        String oldVersionNumberRef = currentNode.getAttributeValue("version");
        String inculdedFeatureId = currentNode.getAttributeValue("id");
        if (featuresList.contains(inculdedFeatureId)) {

          String newVersionRef = null;
          String versionFromFS = getFeatureVersion(inculdedFeatureId);
          boolean changed = false;
          if (feature2update.contains(inculdedFeatureId)) {
            if (featureUpdated.contains(inculdedFeatureId)) {
              newVersionRef = versionFromFS;
            } else {
              // not yet updated (but marked)
              String[] numberRef = versionFromFS.split("\\.");
              newVersionRef = bu.update(numberRef, pattern);
            }
            changed = true;
          } else if (!oldVersionNumberRef.equals(versionFromFS)) {
            // not marked but could not have good version number
            // (mainly
            // if CRP Enterprise and reference to Core element)
            // bad version detected, so Fix it
            newVersionRef = versionFromFS;
            changed = true;
          }

          if (changed) {
            currentNode.setAttribute("version", newVersionRef);
            logger.debug(
                "\t\tFeatureUpdater.updateMarkedFeatures() update feature ref "
                    + inculdedFeatureId
                    + ":"
                    + oldVersionNumberRef
                    + " -> "
                    + newVersionRef);
          }

        } else {
          if (inculdedFeatureId.contains(ProjectVersionUpdater.bluexmlPackage)) {
            logger.warn(
                "Bad feature reference in " + feature + " ref to bad feature " + inculdedFeatureId);
          } else {
            logger.debug("included feature skipped :" + inculdedFeatureId);
          }
        }
      }
      // Enregistrement du fichier

      XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
      sortie.output(document, new FileOutputStream(featureXMLFile));

      featureUpdated.add(feature);
    }
  }