--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Fri Aug 30 16:16:28 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Fri Aug 30 16:27:08 2013 -0700
@@ -383,35 +383,44 @@
DocErrorReporter reporter);
private void initProfiles() throws IOException {
+ if (profilespath.isEmpty())
+ return;
+
profiles = Profiles.read(new File(profilespath));
- // Generate profiles documentation only is profilespath is set and if
- // profiles is not null and profiles count is 1 or more.
- showProfiles = (!profilespath.isEmpty() && profiles != null &&
- profiles.getProfileCount() > 0);
- }
- private void initProfilePackages() throws IOException {
- profilePackages = new HashMap<String,PackageDoc[]>();
- ArrayList<PackageDoc> results;
- Map<String,PackageDoc> packageIndex = new HashMap<String,PackageDoc>();
- for (int i = 0; i < packages.length; i++) {
- PackageDoc pkg = packages[i];
- packageIndex.put(pkg.name(), pkg);
+ // Group the packages to be documented by the lowest profile (if any)
+ // in which each appears
+ Map<Profile, List<PackageDoc>> interimResults =
+ new EnumMap<Profile, List<PackageDoc>>(Profile.class);
+ for (Profile p: Profile.values())
+ interimResults.put(p, new ArrayList<PackageDoc>());
+
+ for (PackageDoc pkg: packages) {
+ // the getProfile method takes a type name, not a package name,
+ // but isn't particularly fussy about the simple name -- so just use *
+ int i = profiles.getProfile(pkg.name().replace(".", "/") + "/*");
+ Profile p = Profile.lookup(i);
+ if (p != null) {
+ List<PackageDoc> pkgs = interimResults.get(p);
+ pkgs.add(pkg);
+ }
}
- for (int i = 1; i < profiles.getProfileCount(); i++) {
- Set<String> profPkgs = profiles.getPackages(i);
- results = new ArrayList<PackageDoc>();
- for (String packageName : profPkgs) {
- packageName = packageName.replace("/", ".");
- PackageDoc profPkg = packageIndex.get(packageName);
- if (profPkg != null) {
- results.add(profPkg);
- }
- }
- Collections.sort(results);
- PackageDoc[] profilePkgs = results.toArray(new PackageDoc[]{});
- profilePackages.put(Profile.lookup(i).name, profilePkgs);
+
+ // Build the profilePackages structure used by the doclet
+ profilePackages = new HashMap<String,PackageDoc[]>();
+ List<PackageDoc> prev = Collections.<PackageDoc>emptyList();
+ for (Map.Entry<Profile,List<PackageDoc>> e: interimResults.entrySet()) {
+ Profile p = e.getKey();
+ List<PackageDoc> pkgs = e.getValue();
+ pkgs.addAll(prev); // each profile contains all lower profiles
+ Collections.sort(pkgs);
+ profilePackages.put(p.name, pkgs.toArray(new PackageDoc[pkgs.size()]));
+ prev = pkgs;
}
+
+ // Generate profiles documentation if any profile contains any
+ // of the packages to be documented.
+ showProfiles = !prev.isEmpty();
}
private void initPackageArray() {
@@ -534,13 +543,10 @@
public void setOptions() throws Fault {
initPackageArray();
setOptions(root.options());
- if (!profilespath.isEmpty()) {
- try {
- initProfiles();
- initProfilePackages();
- } catch (Exception e) {
- throw new DocletAbortException(e);
- }
+ try {
+ initProfiles();
+ } catch (Exception e) {
+ throw new DocletAbortException(e);
}
setSpecificDocletOptions(root.options());
}