Example #1
0
  private void analyze() {
    if (activator == ACTIVATOR_AUTO || packageAnalysis != PACKAGE_ANALYSIS_NONE) {
      addZipGroups();
      addImplicitFileset();

      for (final FileSet fileset : srcFilesets) {
        for (@SuppressWarnings("unchecked") final Iterator<Resource> fsIt = fileset.iterator();
            fsIt.hasNext(); ) {
          final Resource res = fsIt.next();
          analyze(res);
        }
      }
      // Scan done
      bpInfo.toJavaNames();

      final Set<String> publicPackages = exportPackage.keySet();

      if (packageAnalysis != PACKAGE_ANALYSIS_NONE) {
        for (final String packageName : publicPackages) {
          if (!bpInfo.providesPackage(packageName)) {
            log("Exported package not provided by bundle: " + packageName, Project.MSG_WARN);
          }
          // The Version from the packageinfo-file or null
          final Version piVersion = bpInfo.getProvidedPackageVersion(packageName);
          if (null != piVersion) {
            final String epVersionS = exportPackage.get(packageName);
            if (null == epVersionS) {
              // Use the version form the packageinfo-file
              exportPackage.put(packageName, piVersion.toString());
            } else {
              // Check that the versions match, if not trigger a build error
              try {
                final Version epVersion = Version.parseVersion(epVersionS);
                if (0 != epVersion.compareTo(piVersion)) {
                  final String msg =
                      "Multiple versions found for export of "
                          + "the package '"
                          + packageName
                          + "'. The packageinfo file ("
                          + bpInfo.getProvidedPackageVersionSource(packageName)
                          + ") states '"
                          + piVersion.toString()
                          + "' but the <exportpackage> element says '"
                          + epVersion.toString()
                          + "'.";
                  log(msg, Project.MSG_ERR);
                  throw new BuildException(msg);
                }
              } catch (final IllegalArgumentException iae) {
                final String msg =
                    "Invalid version '"
                        + epVersionS
                        + "' in <exportpackage name=\""
                        + packageName
                        + "\" ...>: "
                        + iae.getMessage();
                log(msg, Project.MSG_ERR);
                throw new BuildException(msg, iae);
              }
            }
          }
        }
      }

      final SortedSet<String> privatePackages = bpInfo.getProvidedPackages();
      privatePackages.removeAll(publicPackages);

      final SortedSet<String> referencedPackages = bpInfo.getReferencedPackages();
      referencedPackages.removeAll(privatePackages);
      for (final Object element : referencedPackages) {
        final String packageName = (String) element;
        if (!isStandardPackage(packageName) && !importPackage.containsKey(packageName)) {
          if (packageAnalysis == PACKAGE_ANALYSIS_AUTO) {
            final String version = exportPackage.get(packageName);
            try {
              importPackage.put(packageName, toImportRange(version));
            } catch (final IllegalArgumentException iae) {
              final String msg =
                  "Invalid version value, '"
                      + version
                      + "' for exported package \""
                      + packageName
                      + "\" can not derive version range for auto-import. "
                      + iae.getMessage();
              log(msg, Project.MSG_ERR);
              throw new BuildException(msg, iae);
            }
          } else if (packageAnalysis == PACKAGE_ANALYSIS_WARN) {
            log(
                "Referenced package not found in bundle or imports: " + packageName,
                Project.MSG_WARN);
          }
        }
      }
    }
  }