summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2011-06-20 16:31:31 (EDT)
committer Ryan D. Brooks2011-06-20 16:31:31 (EDT)
commit3f1e3da1d487f062ed470aef975c09253edfa29e (patch)
tree3f50631729a649a4f306be16a2ad18915fed74da
parent0150e261ca7b0e465ebeb80ee5cb1c783c0b2ce6 (diff)
downloadorg.eclipse.osee-3f1e3da1d487f062ed470aef975c09253edfa29e.zip
org.eclipse.osee-3f1e3da1d487f062ed470aef975c09253edfa29e.tar.gz
org.eclipse.osee-3f1e3da1d487f062ed470aef975c09253edfa29e.tar.bz2
refinement[bgz_349970]: Replace RecursiveBranchProvider with MultiBranchProvider
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java4
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/MultiBranchProviderTest.java72
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/PurgeTestSuite.java2
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java45
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/internal/OseeBranchService.java5
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/MultiBranchProvider.java (renamed from plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/RecursiveBranchProvider.java)37
-rw-r--r--plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/BranchManagementCommandProvider.java29
7 files changed, 127 insertions, 67 deletions
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java
index bc45b31..b1820ef 100644
--- a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java
@@ -76,8 +76,8 @@ public final class MockBranchProvider implements IBranchesProvider {
return branches;
}
- public static Branch getRootBranch() throws OseeCoreException {
- for (Branch branch : MockBranchProvider.createTestBranches()) {
+ public static Branch getRootBranch(Collection<Branch> branches) throws OseeCoreException {
+ for (Branch branch : branches) {
if (branch.getName().equals(ROOT_BRANCH_NAME)) {
return branch;
}
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/MultiBranchProviderTest.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/MultiBranchProviderTest.java
new file mode 100644
index 0000000..8ec7c2c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/MultiBranchProviderTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.branch.management.test.purge;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.branch.management.purge.MultiBranchProvider;
+import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchProvider;
+import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.cache.BranchFilter;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class MultiBranchProviderTest {
+
+ @Test
+ public void testGetBranchesRecursive() throws OseeCoreException {
+ BranchFilter filter = new BranchFilter();
+ filter.setNegatedBranchTypes(BranchType.BASELINE);
+ Set<Branch> branchRoots = new HashSet<Branch>();
+
+ Collection<Branch> testBranchesA = MockBranchProvider.createTestBranches();
+ Collection<Branch> testBranchesB = MockBranchProvider.createTestBranches();
+
+ branchRoots.add(MockBranchProvider.getRootBranch(testBranchesA));
+ branchRoots.add(MockBranchProvider.getRootBranch(testBranchesB));
+
+ MultiBranchProvider provider = new MultiBranchProvider(true, branchRoots, filter);
+ int numBranches = provider.getBranches().size();
+ int expectedSize = testBranchesA.size() + testBranchesB.size();
+ Assert.assertEquals(expectedSize, numBranches);
+ }
+
+ @Test
+ public void testGetBranchesNonRecursive() throws OseeCoreException {
+ BranchFilter filter = new BranchFilter();
+ filter.setNegatedBranchTypes(BranchType.BASELINE);
+
+ Collection<Branch> testBranches = MockBranchProvider.createTestBranches();
+
+ MultiBranchProvider provider1 =
+ new MultiBranchProvider(false, Collections.singleton(MockBranchProvider.getRootBranch(testBranches)), filter);
+ int numBranches = provider1.getBranches().size();
+ Assert.assertEquals(1, numBranches);
+
+ Set<Branch> branches = new HashSet<Branch>(MockBranchProvider.createTestBranches());
+ MultiBranchProvider provider2 = new MultiBranchProvider(false, branches, filter);
+ numBranches = provider2.getBranches().size();
+ Assert.assertEquals(branches.size(), numBranches);
+ }
+
+ @Test(expected = OseeCoreException.class)
+ public void testGetBranchesException() throws OseeCoreException {
+ MultiBranchProvider provider = new MultiBranchProvider(true, null, null);
+ provider.getBranches().size();
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/PurgeTestSuite.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/PurgeTestSuite.java
index 9834c7b..1ac8f6b 100644
--- a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/PurgeTestSuite.java
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/PurgeTestSuite.java
@@ -14,7 +14,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses({BranchOperationTest.class, DeletedBranchProviderTest.class, RecursiveBranchProviderTest.class})
+@Suite.SuiteClasses({BranchOperationTest.class, DeletedBranchProviderTest.class, MultiBranchProviderTest.class})
/**
* @author John Misinco
*/
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java
deleted file mode 100644
index d6eefe3..0000000
--- a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Boeing.
- * 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:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.branch.management.test.purge;
-
-import junit.framework.Assert;
-import org.eclipse.osee.framework.branch.management.purge.RecursiveBranchProvider;
-import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchProvider;
-import org.eclipse.osee.framework.core.enums.BranchType;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.model.cache.BranchFilter;
-import org.junit.Test;
-
-/**
- * @author John Misinco
- */
-public class RecursiveBranchProviderTest {
-
- private int getExpectedNumberOfBranches() throws OseeCoreException {
- return MockBranchProvider.createTestBranches().size();
- }
-
- @Test
- public void testGetBranches() throws OseeCoreException {
- BranchFilter filter = new BranchFilter();
- filter.setNegatedBranchTypes(BranchType.BASELINE);
-
- RecursiveBranchProvider provider = new RecursiveBranchProvider(MockBranchProvider.getRootBranch(), filter);
- int numBranches = provider.getBranches().size();
- Assert.assertEquals(getExpectedNumberOfBranches(), numBranches);
- }
-
- @Test(expected = OseeCoreException.class)
- public void testGetBranchesException() throws OseeCoreException {
- RecursiveBranchProvider provider = new RecursiveBranchProvider(null, null);
- provider.getBranches().size();
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/internal/OseeBranchService.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/internal/OseeBranchService.java
index 7cd28cd..25370b9 100644
--- a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/internal/OseeBranchService.java
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/internal/OseeBranchService.java
@@ -11,6 +11,7 @@
package org.eclipse.osee.framework.branch.management.internal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.branch.management.IOseeBranchService;
@@ -22,8 +23,8 @@ import org.eclipse.osee.framework.branch.management.creation.CreateBranchOperati
import org.eclipse.osee.framework.branch.management.purge.BranchOperation;
import org.eclipse.osee.framework.branch.management.purge.IBranchOperationFactory;
import org.eclipse.osee.framework.branch.management.purge.IBranchesProvider;
+import org.eclipse.osee.framework.branch.management.purge.MultiBranchProvider;
import org.eclipse.osee.framework.branch.management.purge.PurgeBranchOperationFactory;
-import org.eclipse.osee.framework.branch.management.purge.RecursiveBranchProvider;
import org.eclipse.osee.framework.branch.management.purge.SingleBranchProvider;
import org.eclipse.osee.framework.core.enums.BranchArchivedState;
import org.eclipse.osee.framework.core.enums.BranchState;
@@ -158,7 +159,7 @@ public class OseeBranchService implements IOseeBranchService {
IBranchesProvider provider;
if (request.isRecursive()) {
- provider = new RecursiveBranchProvider(branch, new BranchFilter());
+ provider = new MultiBranchProvider(true, Collections.singleton(branch), new BranchFilter());
} else {
provider = new SingleBranchProvider(branch);
}
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/RecursiveBranchProvider.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/MultiBranchProvider.java
index 41308ca..8892474 100644
--- a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/RecursiveBranchProvider.java
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/MultiBranchProvider.java
@@ -21,24 +21,39 @@ import org.eclipse.osee.framework.core.util.Conditions;
/**
* @author John Misinco
*/
-public final class RecursiveBranchProvider implements IBranchesProvider {
- private final Branch parentBranch;
+public class MultiBranchProvider implements IBranchesProvider {
+
+ private final boolean recursive;
+ private final Set<Branch> branches;
private final BranchFilter filter;
- public RecursiveBranchProvider(Branch parentBranch, BranchFilter filter) {
- this.parentBranch = parentBranch;
+ public MultiBranchProvider(boolean recursive, Set<Branch> branches, BranchFilter filter) {
+ this.recursive = recursive;
+ this.branches = branches;
this.filter = filter;
}
- @Override
- public Collection<Branch> getBranches() throws OseeCoreException {
- Conditions.checkNotNull(parentBranch, "seed");
+ private Collection<Branch> getChildBranches(Branch branch) throws OseeCoreException {
Set<Branch> children = new HashSet<Branch>();
- parentBranch.getChildBranches(children, true, filter);
- if (filter.matches(parentBranch)) {
- children.add(parentBranch);
+ branch.getChildBranches(children, true, filter);
+ if (filter.matches(branch)) {
+ children.add(branch);
}
return children;
}
-} \ No newline at end of file
+
+ @Override
+ public Collection<Branch> getBranches() throws OseeCoreException {
+ Conditions.checkNotNull(branches, "seeds");
+ Set<Branch> result = branches;
+ if (recursive) {
+ result = new HashSet<Branch>(branches);
+ for (Branch b : branches) {
+ result.addAll(getChildBranches(b));
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/BranchManagementCommandProvider.java b/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/BranchManagementCommandProvider.java
index 2603908..56e760a 100644
--- a/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/BranchManagementCommandProvider.java
+++ b/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/BranchManagementCommandProvider.java
@@ -11,7 +11,9 @@
package org.eclipse.osee.framework.server.admin;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osee.framework.branch.management.ExportOptions;
@@ -20,8 +22,8 @@ import org.eclipse.osee.framework.branch.management.purge.BranchOperation;
import org.eclipse.osee.framework.branch.management.purge.DeletedBranchProvider;
import org.eclipse.osee.framework.branch.management.purge.IBranchOperationFactory;
import org.eclipse.osee.framework.branch.management.purge.IBranchesProvider;
+import org.eclipse.osee.framework.branch.management.purge.MultiBranchProvider;
import org.eclipse.osee.framework.branch.management.purge.PurgeBranchOperationFactory;
-import org.eclipse.osee.framework.branch.management.purge.RecursiveBranchProvider;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
@@ -157,16 +159,31 @@ public class BranchManagementCommandProvider implements CommandProvider {
return internalPurgeBranch(logger, branchCache, provider);
}
- public Job _purge_branch_recursive(CommandInterpreter ci) throws OseeCoreException {
+ public Job _purge_branch(CommandInterpreter ci) throws OseeCoreException {
OperationLogger logger = new CommandInterpreterLogger(ci);
- String branchGuid = ci.nextArgument();
+ String arg = ci.nextArgument();
+ boolean recursive = false;
+ Set<String> guids = new HashSet<String>();
+
+ while (Strings.isValid(arg)) {
+ if (arg.equals("-recursive")) {
+ recursive = true;
+ } else {
+ guids.add(arg);
+ }
+ arg = ci.nextArgument();
+ }
+
+ Set<Branch> branches = new HashSet<Branch>();
BranchCache branchCache = Activator.getOseeCachingService().getBranchCache();
- Branch seed = branchCache.getByGuid(branchGuid);
+ for (String guid : guids) {
+ branches.add(branchCache.getByGuid(guid));
+ }
BranchFilter filter = new BranchFilter();
filter.setNegatedBranchTypes(BranchType.BASELINE);
- IBranchesProvider provider = new RecursiveBranchProvider(seed, filter);
+ IBranchesProvider provider = new MultiBranchProvider(recursive, branches, filter);
return internalPurgeBranch(logger, branchCache, provider);
}
@@ -186,7 +203,7 @@ public class BranchManagementCommandProvider implements CommandProvider {
sb.append("\timport_branch <exchangeFileName> [-exclude_baseline_txs] [-allAsRootBranches] [-minTx <value>] [-maxTx <value>] [-clean] [<branchId>]+ - import a specific set of branches from an exchange zip file.\n");
sb.append("\tcheck_exchange <exchangeFileName> - checks an exchange file to ensure data integrity\n");
sb.append("\tpurge_deleted_branches - permenatly remove all branches that are both archived and deleted \n");
- sb.append("\tpurge_branch_recursive <guid> - removes the branch defined by guid and all its children excluding baseline branches\n");
+ sb.append("\tpurge_branch <guids...> [-recursive] - removes branches defined by guids, if recursive all its children excluding baseline branches are removed\n");
return sb.toString();
}
} \ No newline at end of file