summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2013-05-06 06:48:56 (EDT)
committer Pascal Rapicault2013-05-07 10:28:16 (EDT)
commit56334fddd10d26ce57003359dfcce3e7504f0008 (patch)
tree1690ed21e07efe06c87b87764dacfb6c3b9efa45
parent5ba5f8ffad90e03da07bce45e2cac84f32b5f3cf (diff)
downloadrt.equinox.p2-56334fddd10d26ce57003359dfcce3e7504f0008.zip
rt.equinox.p2-56334fddd10d26ce57003359dfcce3e7504f0008.tar.gz
rt.equinox.p2-56334fddd10d26ce57003359dfcce3e7504f0008.tar.bz2
+ Fix Comparator to work with multiple levels of nested categories + Test + Updated copyright
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/CategoryXMLActionTest.java54
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/testData/updatesite/CategoryXMLActionTest/3-depth-category.xml18
-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
5 files changed, 98 insertions, 17 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/CategoryXMLActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/CategoryXMLActionTest.java
index 0cd7405..1b06905 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/CategoryXMLActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/CategoryXMLActionTest.java
@@ -1,11 +1,12 @@
/*******************************************************************************
-* Copyright (c) 2009, 2010 EclipseSource and others. All rights reserved. This
+* Copyright (c) 2009, 2013 EclipseSource 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 http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* EclipseSource - initial API and implementation
+* Red Hat Inc. - 383795 (bundle element), 406902 (nested categories)
******************************************************************************/
package org.eclipse.equinox.p2.tests.updatesite;
@@ -169,12 +170,7 @@ public class CategoryXMLActionTest extends AbstractProvisioningTest {
}
assertNotNull("1.1", rootCategoryIu);
- IQuery<IInstallableUnit> rootCategoryMembersQuery = QueryUtil.createIUCategoryMemberQuery(rootCategoryIu);
- IQueryResult<IInstallableUnit> rootCategoryMembers = actionResult.query(rootCategoryMembersQuery, new NullProgressMonitor());
- Set<IInstallableUnit> rootCategoryMembersSet = rootCategoryMembers.toUnmodifiableSet();
- assertEquals("2.0", 1, rootCategoryMembersSet.size());
- IInstallableUnit nestedCategory = rootCategoryMembersSet.iterator().next();
- assertTrue("2.1", nestedCategory.getId().endsWith("Nested Category"));
+ IInstallableUnit nestedCategory = assertContainsAndGetIU(rootCategoryIu, "Nested Category");
IQuery<IInstallableUnit> nestedCategoryMemberQuery = QueryUtil.createIUCategoryMemberQuery(nestedCategory);
IQueryResult<IInstallableUnit> nestedCategoryMembers = actionResult.query(nestedCategoryMemberQuery, new NullProgressMonitor());
@@ -182,4 +178,48 @@ public class CategoryXMLActionTest extends AbstractProvisioningTest {
assertEquals("3.0", 1, nestedCategoryMembersSet.size());
assertEquals("3.1", "test.bundle", nestedCategoryMembersSet.iterator().next().getId());
}
+
+ public void testMultiDepthNestedInCategory() throws Exception {
+ PublisherInfo info = new PublisherInfo();
+
+ info.setMetadataRepository(metadataRepository);
+ siteLocation = TestData.getFile("updatesite", "CategoryXMLActionTest/3-depth-category.xml").toURI();
+ FeaturesAction featuresAction = new FeaturesAction(new File[] {TestData.getFile("updatesite", "CategoryXMLActionTest")});
+ BundlesAction bundlesAction = new BundlesAction(new File[] {TestData.getFile("updatesite", "CategoryXMLActionTest")});
+ MergeResultsAction publishAction = new MergeResultsAction(new IPublisherAction[] {featuresAction, bundlesAction}, IPublisherResult.MERGE_ALL_NON_ROOT);
+ publishAction.perform(info, actionResult, new NullProgressMonitor());
+
+ CategoryXMLAction action = new CategoryXMLAction(siteLocation, null);
+ action.perform(info, actionResult, getMonitor());
+
+ IQueryResult result = actionResult.query(QueryUtil.createIUCategoryQuery(), new NullProgressMonitor());
+ assertEquals("1.0", 4, queryResultSize(result));
+ IInstallableUnit rootCategoryIu = null;
+ for (Object item : result) {
+ if (((IInstallableUnit) item).getId().endsWith("Root Category")) {
+ rootCategoryIu = (IInstallableUnit) item;
+ }
+ }
+ assertNotNull("1.1", rootCategoryIu);
+
+ IInstallableUnit nestedCategoryIu = assertContainsAndGetIU(rootCategoryIu, "Nested Category");
+ IInstallableUnit nestedNestedCategoryIu = assertContainsAndGetIU(nestedCategoryIu, "Nested Nested Category");
+ IInstallableUnit nestedNestedNestedCategoryIu = assertContainsAndGetIU(nestedNestedCategoryIu, "Nested Nested Nested Category");
+
+ IQuery<IInstallableUnit> nestedNestedNestedCategoryMemberQuery = QueryUtil.createIUCategoryMemberQuery(nestedNestedNestedCategoryIu);
+ IQueryResult<IInstallableUnit> nestedNestedNestedCategoryMembers = actionResult.query(nestedNestedNestedCategoryMemberQuery, new NullProgressMonitor());
+ Set<IInstallableUnit> nestedCategoryMembersSet = nestedNestedNestedCategoryMembers.toUnmodifiableSet();
+ assertEquals("3.0", 1, nestedCategoryMembersSet.size());
+ assertEquals("3.1", "test.feature.feature.group", nestedCategoryMembersSet.iterator().next().getId());
+ }
+
+ private IInstallableUnit assertContainsAndGetIU(IInstallableUnit parentCategoryIu, String iuId) {
+ IQuery<IInstallableUnit> rootCategoryMembersQuery = QueryUtil.createIUCategoryMemberQuery(parentCategoryIu);
+ IQueryResult<IInstallableUnit> rootCategoryMembers = actionResult.query(rootCategoryMembersQuery, new NullProgressMonitor());
+ Set<IInstallableUnit> rootCategoryMembersSet = rootCategoryMembers.toUnmodifiableSet();
+ assertEquals("Unexpected multiple items under category", 1, rootCategoryMembersSet.size());
+ IInstallableUnit nestedCategoryIu = rootCategoryMembersSet.iterator().next();
+ assertTrue("Could not find IU '" + iuId + "'", nestedCategoryIu.getId().endsWith(iuId));
+ return nestedCategoryIu;
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/CategoryXMLActionTest/3-depth-category.xml b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/CategoryXMLActionTest/3-depth-category.xml
new file mode 100644
index 0000000..263cf04
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/testData/updatesite/CategoryXMLActionTest/3-depth-category.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<site
+ mirrorsURL="http://www.eclipse.org/downloads/download.php?file=/eclipse/updates/3.4&amp;format=xml"
+ associateSitesURL="associateSites.xml">
+ <feature url="features/test.feature_1.0.0.jar" id="test.feature" version="1.0.0">>
+ <category name="Nested Nested Nested Category"/>
+ </feature>
+ <category-def name="Root Category" label="Root Category"/>
+ <category-def name="Nested Category" label="Nested Category">
+ <category name="Root Category"/>
+ </category-def>
+ <category-def name="Nested Nested Category" label="Nested Nested Category">
+ <category name="Nested Category"/>
+ </category-def>
+ <category-def name="Nested Nested Nested Category" label="Nested Nested Nested Category">
+ <category name="Nested Nested Category"/>
+ </category-def>
+</site>
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 fa06c73..88801db 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 a98529b..cc56b4c 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 1a06342..71336f1 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