Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2013-05-06 06:48:56 -0400
committerPascal Rapicault2013-05-07 10:28:16 -0400
commit56334fddd10d26ce57003359dfcce3e7504f0008 (patch)
tree1690ed21e07efe06c87b87764dacfb6c3b9efa45 /bundles/org.eclipse.equinox.p2.updatesite
parent5ba5f8ffad90e03da07bce45e2cac84f32b5f3cf (diff)
downloadrt.equinox.p2-56334fddd10d26ce57003359dfcce3e7504f0008.tar.gz
rt.equinox.p2-56334fddd10d26ce57003359dfcce3e7504f0008.tar.xz
rt.equinox.p2-56334fddd10d26ce57003359dfcce3e7504f0008.zip
+ Fix Comparator to work with multiple levels of nested categories + Test + Updated copyright
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.updatesite')
-rw-r--r--bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java39
3 files changed, 33 insertions, 10 deletions
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java
index fa06c7322..88801dbfd 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Red Hat Inc. - 383795 (bundle element), 406902 (nested categories)
*******************************************************************************/
package org.eclipse.equinox.internal.p2.updatesite;
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java
index a98529bdc..cc56b4cec 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Red Hat Inc. - 406902 (nested categories)
*******************************************************************************/
package org.eclipse.equinox.internal.p2.updatesite;
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java
index 1a06342e4..71336f1e6 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java
@@ -8,6 +8,7 @@
* Code 9 - initial API and implementation
* IBM - ongoing development
* Sonatype, Inc. - transport split
+ * Red Hat Inc. - 383795 (bundle element)
******************************************************************************/
package org.eclipse.equinox.internal.p2.updatesite;
@@ -425,7 +426,7 @@ public class SiteXMLAction extends AbstractPublisherAction {
for (SiteCategory category : this.updateSite.getSite().getCategories()) {
nameToCategory.put(category.getName(), category);
}
- Map<SiteCategory, Set<SiteCategory>> categoryToNestedCategories = new HashMap<SiteCategory, Set<SiteCategory>>();
+ final Map<SiteCategory, Set<SiteCategory>> categoryToNestedCategories = new HashMap<SiteCategory, Set<SiteCategory>>();
for (SiteCategory category : this.updateSite.getSite().getCategories()) {
for (String parentCategoryName : category.getCategoryNames()) {
SiteCategory parentCategory = nameToCategory.get(parentCategoryName);
@@ -436,22 +437,42 @@ public class SiteXMLAction extends AbstractPublisherAction {
}
}
+ List<SiteCategory> categories = new ArrayList<SiteCategory>(Arrays.asList(this.updateSite.getSite().getCategories()));
+ categories.add(this.defaultCategory);
// sort category so they are processed in reverse order of dependency
- // category2 is nested in category1 => category2 < category1
+ // (Nested categories go first)
Comparator<SiteCategory> isNestedCategoryComparator = new Comparator<SiteCategory>() {
public int compare(SiteCategory category1, SiteCategory category2) {
- if (Arrays.asList(category1.getCategoryNames()).contains(category2.getName())) {
- // category2 is nested in category1
- return -1;
- } else if (Arrays.asList(category2.getCategoryNames()).contains(category1.getName())) {
- // category1 is nested in category2
+ Set<SiteCategory> childrenOfCategory1 = categoryToNestedCategories.get(category1);
+ Set<SiteCategory> childrenOfCategory2 = categoryToNestedCategories.get(category2);
+ if (childrenOfCategory1 != null && childrenOfCategory1.contains(category2)) {
+ // category2 nested in category1 => category2 < category1
return +1;
}
+ if (childrenOfCategory2 != null && childrenOfCategory2.contains(category1)) {
+ // category1 nested in category2 => category1 < category2
+ return -1;
+ }
+ // Then recurse in childrenCategories for transitivity
+ if (childrenOfCategory1 != null) {
+ for (SiteCategory childOfCategory1 : childrenOfCategory1) {
+ int res = this.compare(childOfCategory1, category2);
+ if (res != 0) {
+ return res;
+ }
+ }
+ }
+ if (childrenOfCategory2 != null) {
+ for (SiteCategory childOfCategory2 : childrenOfCategory2) {
+ int res = this.compare(category1, childOfCategory2);
+ if (res != 0) {
+ return res;
+ }
+ }
+ }
return 0;
}
};
- List<SiteCategory> categories = new ArrayList<SiteCategory>(Arrays.asList(this.updateSite.getSite().getCategories()));
- categories.add(this.defaultCategory);
Collections.sort(categories, isNestedCategoryComparator);
// Then create categories in the right order

Back to the top