public BundleCompatibility invoke()

in versioning/versioning-checker/src/main/java/org/apache/aries/versioning/check/BundleCompatibility.java [128:224]


  public BundleCompatibility invoke() throws IOException {
    String reason = null;
    // open the manifest and scan the export package and find the package name and exported version
    // The tool assume the one particular package just exports under one version
    Map<String, PackageContent> currBundleExpPkgContents = getAllExportedPkgContents(currentBundle);
    Map<String, PackageContent> baseBundleExpPkgContents;
    boolean pkg_major_change = false;
    boolean pkg_minor_change = false;
    String fatal_package = null;
    if (!currBundleExpPkgContents.isEmpty()) {
      baseBundleExpPkgContents = getAllExportedPkgContents(baseBundle);
      // compare each class right now
      for (Map.Entry<String, PackageContent> pkg : baseBundleExpPkgContents.entrySet()) {
        String pkgName = pkg.getKey();
        Map<String, IFile> baseClazz = pkg.getValue().getClasses();
        Map<String, IFile> baseXsds = pkg.getValue().getXsds();
        PackageContent currPkgContents = currBundleExpPkgContents.get(pkgName);
        if (currPkgContents == null) {
          // The package is no longer exported any more. This should lead to bundle major version change.
          pkg_major_change = true;
          fatal_package = pkgName;
          _logger.debug("The package " + pkgName + " in the bundle of " + bundleSymbolicName + " is no longer to be exported. Major change.");
        } else {
          Map<String, IFile> curClazz = currPkgContents.getClasses();
          Map<String, IFile> curXsds = currPkgContents.getXsds();
          //check whether there should be major change/minor change/micro change in this package.
          //1. Use ASM to visit all classes in the package
          VersionChangeReason majorChange = new VersionChangeReason();
          VersionChangeReason minorChange = new VersionChangeReason();
          // check all classes to see whether there are minor or major changes
          visitPackage(pkgName, baseClazz, curClazz, majorChange, minorChange);
          // If there is no binary compatibility changes, check whether xsd files have been added, changed or deleted
          if (!majorChange.isChange()) {
            checkXsdChangesInPkg(pkgName, baseXsds, curXsds, majorChange);
            // If everything is ok with the existing classes. Need to find out whether there are more API (abstract classes) in the current bundle.
            // loop through curClazz and visit it and find out whether one of them is abstract.
            // check whether there are more xsd or abstract classes added
            if (!(majorChange.isChange() || minorChange.isChange())) {
              checkAdditionalClassOrXsds(pkgName, curClazz, curXsds, minorChange);
            }
          }
          // We have scanned the whole packages, report the result
          //                    if (majorChange.isChange() || minorChange.isChange()) {
          String oldVersion = pkg.getValue().getPackageVersion();
          String newVersion = currPkgContents.getPackageVersion();
          if (majorChange.isChange() && !ignoreChange(majorChange.getReason())) {
            packageChanges.put(pkgName, new VersionChange(VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion));
            pkg_major_change = true;
            fatal_package = pkgName;
            if (!isVersionCorrect(VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion)) {
              pkgElementsList.add(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion, majorChange.getReason(), majorChange.getChangeClass()));
            }
          } else if (minorChange.isChange() && !ignoreChange(minorChange.getReason())) {
            packageChanges.put(pkgName, new VersionChange(VERSION_CHANGE_TYPE.MINOR_CHANGE, oldVersion, newVersion));
            pkg_minor_change = true;
            if (fatal_package == null) fatal_package = pkgName;
            if (!isVersionCorrect(VERSION_CHANGE_TYPE.MINOR_CHANGE, oldVersion, newVersion)) {
              pkgElementsList.add(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.MINOR_CHANGE, pkg.getValue().getPackageVersion(), currPkgContents.getPackageVersion(), minorChange.getReason(), minorChange.getChangeClass()));
            }
          }  else {
            packageChanges.put(pkgName, new VersionChange(VERSION_CHANGE_TYPE.NO_CHANGE, oldVersion, newVersion));
            pkgElementsList.add(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.NO_CHANGE, pkg.getValue().getPackageVersion(), currPkgContents.getPackageVersion(), "", ""));
          }
      }
      }
      // If there is a package version change, the bundle version needs to be updated.
      // If there is a major change in one of the packages, the bundle major version needs to be increased.
      // If there is a minor change in one of the packages, the bundle minor version needs to be increased.
      String oldVersion = baseBundle.getBundleManifest().getVersion().toString();
      String newVersion = currentBundle.getBundleManifest().getVersion().toString();


      if (pkg_major_change || pkg_minor_change) {

        if (pkg_major_change) {
          // The bundle version's major value should be increased.
          bundleChange = new VersionChange(VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion);
          reason = "Some packages have major changes. For an instance, the package " + fatal_package + " has major version changes.";
          bundleElement = getBundleStatusText(currentBundle.getBundle().getName(), bundleSymbolicName, VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion, reason);
          bundleVersionCorrect = isVersionCorrect(VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion);
        } else if (pkg_minor_change) {
          bundleChange = new VersionChange(VERSION_CHANGE_TYPE.MINOR_CHANGE, oldVersion, newVersion);
          reason = "Some packages have minor changes. For an instance, the package " + fatal_package + " has minor version changes.";
          bundleElement = getBundleStatusText(currentBundle.getBundle().getName(), bundleSymbolicName, VERSION_CHANGE_TYPE.MINOR_CHANGE, oldVersion, newVersion, reason);
          bundleVersionCorrect = isVersionCorrect(VERSION_CHANGE_TYPE.MINOR_CHANGE, oldVersion, newVersion);
        }
      } else {
        bundleChange = new VersionChange(VERSION_CHANGE_TYPE.NO_CHANGE, oldVersion, newVersion);
        bundleVersionCorrect = isVersionCorrect(VERSION_CHANGE_TYPE.NO_CHANGE, oldVersion, newVersion);
        if (!bundleVersionCorrect) {
          reason = "The bundle has no version changes.";
          bundleElement = getBundleStatusText(currentBundle.getBundle().getName(), bundleSymbolicName, VERSION_CHANGE_TYPE.NO_CHANGE, oldVersion, newVersion, reason);
        }
      }
    }
    return this;
  }