summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2011-04-08 12:26:26 (EDT)
committer Ryan D. Brooks2011-04-08 12:26:26 (EDT)
commit57a38c0cb2afaaf6f0defb30599ccb2e9106234f (patch)
treeccf05a32626944f9cf02b116d22e87eb13760388
parent22d8d7ca6eb8fa01acca19461d1c48bbc8250e60 (diff)
downloadorg.eclipse.osee-57a38c0cb2afaaf6f0defb30599ccb2e9106234f.zip
org.eclipse.osee-57a38c0cb2afaaf6f0defb30599ccb2e9106234f.tar.gz
org.eclipse.osee-57a38c0cb2afaaf6f0defb30599ccb2e9106234f.tar.bz2
refactor[bgz_342607]: Remove PurgeDeletedBranches and create generic BranchOperation
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/META-INF/MANIFEST.MF11
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchOperationFactory.java41
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java89
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/BranchOperationTest.java101
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java48
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/PurgeTestSuite.java4
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java42
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/TestPurgeBranchRecursive.java66
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/internal/OseeBranchService.java11
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/BranchOperation.java83
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java40
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchOperationFactory.java21
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchesProvider.java22
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperation.java8
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperationFactory.java38
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchRecursive.java55
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeDeletedBranches.java55
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/RecursiveBranchProvider.java41
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/SingleBranchProvider.java31
-rw-r--r--plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/mocks/MockOperation.java16
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java2
-rw-r--r--plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/BranchManagementCommandProvider.java18
-rw-r--r--plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/branch/BranchCommands.java41
23 files changed, 680 insertions, 204 deletions
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.branch.management.test/META-INF/MANIFEST.MF
index 3e2c622..fa27144 100644
--- a/plugins/org.eclipse.osee.framework.branch.management.test/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/META-INF/MANIFEST.MF
@@ -4,13 +4,10 @@ Bundle-Name: Branch Management Test
Bundle-SymbolicName: org.eclipse.osee.framework.branch.management.test;singleton:=true
Bundle-Version: 0.9.9.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
-Fragment-Host: org.eclipse.osee.framework.branch.management;bundle-version="0.4.0"
+Fragment-Host: org.eclipse.osee.framework.branch.management
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.junit
-Import-Package: org.eclipse.osee.framework.core.message.test.mocks,
- org.eclipse.osee.framework.core.test.mocks,
- org.eclipse.osee.framework.skynet.core,
- org.eclipse.osee.framework.skynet.core.artifact,
- org.eclipse.osee.framework.skynet.core.transaction,
- org.eclipse.osee.support.test.util
Export-Package: org.eclipse.osee.framework.branch.management.test
+Import-Package: org.eclipse.osee.framework.core.message.test.mocks,
+ org.eclipse.osee.framework.core.model.test.mocks,
+ org.eclipse.osee.framework.core.test.mocks
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchOperationFactory.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchOperationFactory.java
new file mode 100644
index 0000000..e020c8a
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchOperationFactory.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.mocks;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.framework.branch.management.purge.IBranchOperationFactory;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.operation.IOperation;
+import org.eclipse.osee.framework.core.test.mocks.MockOperation;
+
+/**
+ * @author John Misinco
+ */
+public final class MockBranchOperationFactory implements IBranchOperationFactory {
+
+ private final MockOperation mockOp = new MockOperation();
+ private final List<Branch> calledBranches = new ArrayList<Branch>();
+
+ public boolean getCalled() {
+ return mockOp.getCalled();
+ }
+
+ public List<Branch> getCallOrder() {
+ return calledBranches;
+ }
+
+ @Override
+ public IOperation createOperation(Branch branch) {
+ calledBranches.add(branch);
+ return mockOp;
+ }
+} \ 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/mocks/MockBranchProvider.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java
new file mode 100644
index 0000000..a9050b7
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/mocks/MockBranchProvider.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.mocks;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.eclipse.osee.framework.branch.management.purge.IBranchesProvider;
+import org.eclipse.osee.framework.core.enums.BranchState;
+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.jdk.core.util.GUID;
+
+/**
+ * @author John Misinco
+ */
+public final class MockBranchProvider implements IBranchesProvider {
+
+ private Branch root;
+ private final Collection<Branch> branches = new ArrayList<Branch>();
+
+ public MockBranchProvider() throws OseeCoreException {
+ initializeData();
+ }
+
+ private void initializeData() throws OseeCoreException {
+ //create a root branch
+ root = new Branch(GUID.create(), "root", BranchType.SYSTEM_ROOT, BranchState.COMMITTED, false);
+
+ //add a child to root (parent)
+ Branch parent = new Branch(GUID.create(), "parent", BranchType.SYSTEM_ROOT, BranchState.CREATED, false);
+ parent.setParentBranch(root);
+
+ //add children branches to parent
+ Branch child1 = new Branch(GUID.create(), "child1", BranchType.SYSTEM_ROOT, BranchState.MODIFIED, false);
+ child1.setParentBranch(parent);
+ child1.setArchived(true);
+ child1.setBranchState(BranchState.DELETED);
+
+ //this branch should get deleted
+ Branch child2 = new Branch(GUID.create(), "child2", BranchType.WORKING, BranchState.DELETED, true);
+ child2.setParentBranch(parent);
+
+ Branch child3 = new Branch(GUID.create(), "child3", BranchType.SYSTEM_ROOT, BranchState.CREATED, false);
+ //make one a merge branch
+ child3.setBranchType(BranchType.MERGE);
+ child3.setParentBranch(parent);
+
+ Branch grandChild1 = new Branch(GUID.create(), "grandChild1", BranchType.MERGE, BranchState.UNKNOWN, false);
+ grandChild1.setBranchState(BranchState.DELETED);
+ grandChild1.setArchived(true);
+ grandChild1.setParentBranch(child1);
+
+ Branch grandChild2 =
+ new Branch(GUID.create(), "grandChild2", BranchType.SYSTEM_ROOT, BranchState.MODIFIED, false);
+ grandChild2.setParentBranch(child1);
+
+ //this branch should get deleted
+ Branch grandChild3 = new Branch(GUID.create(), "grandChild3", BranchType.WORKING, BranchState.DELETED, true);
+ grandChild3.setParentBranch(child2);
+
+ //add branches in a random order
+ branches.add(child2);
+ branches.add(grandChild2);
+ branches.add(grandChild3);
+ branches.add(child1);
+ branches.add(root);
+ branches.add(child3);
+ branches.add(grandChild1);
+ branches.add(parent);
+ }
+
+ public Branch getRootBranch() {
+ return root;
+ }
+
+ @Override
+ public Collection<Branch> getBranches() {
+ return branches;
+ }
+} \ 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/BranchOperationTest.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/BranchOperationTest.java
new file mode 100644
index 0000000..4415b63
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/BranchOperationTest.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.List;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osee.framework.branch.management.purge.BranchOperation;
+import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchOperationFactory;
+import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchProvider;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.operation.NullOperationLogger;
+import org.eclipse.osee.framework.core.operation.OperationLogger;
+import org.eclipse.osee.framework.core.operation.Operations;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public final class BranchOperationTest {
+
+ private void runTest(boolean nullFactory, boolean nullProvider, boolean nullLogger, boolean expectedResult) throws OseeCoreException {
+ OperationLogger logger = NullOperationLogger.getSingleton();
+
+ MockBranchOperationFactory mbo = new MockBranchOperationFactory();
+ MockBranchProvider mbp = new MockBranchProvider();
+
+ if (nullFactory) {
+ mbo = null;
+ }
+ if (nullProvider) {
+ mbp = null;
+ }
+ if (nullLogger) {
+ logger = null;
+ }
+
+ BranchOperation bo = new BranchOperation(logger, mbo, mbp);
+ IStatus status = Operations.executeWork(bo);
+
+ if (expectedResult) {
+ Assert.assertEquals(Status.OK_STATUS, status);
+ Assert.assertTrue(mbo.getCalled() == expectedResult);
+ Assert.assertTrue(verifyCallOrder(mbo.getCallOrder()));
+ } else {
+ Assert.assertFalse(Status.OK_STATUS == status);
+ }
+
+ }
+
+ private boolean verifyCallOrder(List<Branch> callOrder) throws OseeCoreException {
+ boolean result = true;
+ for (Branch cur : callOrder) {
+ int idxCur = callOrder.indexOf(cur);
+ Branch parent = cur.getParentBranch();
+ if (parent != null) {
+ int idxParent = callOrder.indexOf(parent);
+ if (idxCur > idxParent) {
+ result = false;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ @Test
+ public void testBranchOperation() throws OseeCoreException {
+ runTest(false, false, false, true);
+ }
+
+ @Test
+ public void testBranchOperationException__nullFactory() throws OseeCoreException {
+ runTest(true, false, false, false);
+ }
+
+ @Test
+ public void testBranchOperationException__nullProvider() throws OseeCoreException {
+ runTest(false, true, false, false);
+ }
+
+ @Test
+ public void testBranchOperationException__nullLogger() throws OseeCoreException {
+ runTest(false, false, true, false);
+ }
+
+ @Test
+ public void testBranchOperationException__allNull() throws OseeCoreException {
+ runTest(true, true, true, false);
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java
new file mode 100644
index 0000000..2bee8e9
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/DeletedBranchProviderTest.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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 junit.framework.Assert;
+import org.eclipse.osee.framework.branch.management.purge.DeletedBranchProvider;
+import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchProvider;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.cache.BranchCache;
+import org.eclipse.osee.framework.core.model.test.mocks.MockOseeDataAccessor;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public final class DeletedBranchProviderTest {
+
+ @Test
+ public void testGetBranches() throws OseeCoreException {
+ Collection<Branch> branches;
+
+ MockBranchProvider mbp = new MockBranchProvider();
+ BranchCache mockCache = new BranchCache(new MockOseeDataAccessor<Branch>());
+
+ branches = mbp.getBranches();
+ mockCache.cache(branches.toArray(new Branch[branches.size()]));
+
+ DeletedBranchProvider provider = new DeletedBranchProvider(mockCache);
+ int numBranches = provider.getBranches().size();
+ Assert.assertEquals(2, numBranches);
+ }
+
+ @Test(expected = OseeCoreException.class)
+ public void testGetBranchesException() throws OseeCoreException {
+ DeletedBranchProvider provider = new DeletedBranchProvider(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 5632ca1..9834c7b 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,10 +14,10 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses({TestPurgeBranchRecursive.class})
+@Suite.SuiteClasses({BranchOperationTest.class, DeletedBranchProviderTest.class, RecursiveBranchProviderTest.class})
/**
* @author John Misinco
*/
public class PurgeTestSuite {
- // test provided above
+ // tests provided above
} \ 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/RecursiveBranchProviderTest.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java
new file mode 100644
index 0000000..7d9237d
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/RecursiveBranchProviderTest.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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 {
+
+ @Test
+ public void testGetBranches() throws OseeCoreException {
+ MockBranchProvider mbp = new MockBranchProvider();
+ BranchFilter filter = new BranchFilter();
+ filter.setNegatedBranchTypes(BranchType.BASELINE);
+
+ RecursiveBranchProvider provider = new RecursiveBranchProvider(mbp.getRootBranch(), filter);
+ int numBranches = provider.getBranches().size();
+ Assert.assertEquals(numBranches, 8);
+ }
+
+ @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.test/src/org/eclipse/osee/framework/branch/management/test/purge/TestPurgeBranchRecursive.java b/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/TestPurgeBranchRecursive.java
deleted file mode 100644
index 323fe2c..0000000
--- a/plugins/org.eclipse.osee.framework.branch.management.test/src/org/eclipse/osee/framework/branch/management/test/purge/TestPurgeBranchRecursive.java
+++ /dev/null
@@ -1,66 +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 static org.junit.Assert.assertFalse;
-import junit.framework.Assert;
-import org.eclipse.osee.framework.branch.management.purge.PurgeBranchRecursive;
-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.operation.OperationLogger;
-import org.eclipse.osee.framework.skynet.core.UserManager;
-import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
-import org.eclipse.osee.support.test.util.TestUtil;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestPurgeBranchRecursive {
-
- @Before
- public void checkTestDb() throws OseeCoreException {
- assertFalse(TestUtil.isProductionDb());
- }
-
- @Test
- public void testPurgeBranchRecursive() throws OseeCoreException {
- //create a root branch
- Branch root = BranchManager.createTopLevelBranch("root");
- //add a child to root (parent)
- Branch parent = BranchManager.createWorkingBranch(root, "parent", UserManager.getUser());
-
- //add children branches to parent
- Branch child1 = BranchManager.createWorkingBranch(parent, "child1", UserManager.getUser());
- Branch child2 = BranchManager.createWorkingBranch(parent, "child2", UserManager.getUser());
- Branch child3 = BranchManager.createWorkingBranch(parent, "child3", UserManager.getUser());
- //make one a merge branch
- child3.setBranchType(BranchType.MERGE);
-
- Branch grandChild1 = BranchManager.createWorkingBranch(child1, "grandChild1", UserManager.getUser());
- grandChild1.setBranchType(BranchType.MERGE);
- Branch grandChild2 = BranchManager.createWorkingBranch(child2, "grandChild1", UserManager.getUser());
- Branch grandChild3 = BranchManager.createWorkingBranch(child3, "grandChild1", UserManager.getUser());
-
- //count how many children of root there are
- Assert.assertEquals(7, root.getAllChildBranches(true).size());
- //call purgeBranch recursive
- OperationLogger ol = new OperationLogger() {
- @Override
- public void log(String... row) {
- //do nothing
- }
- };
-
- PurgeBranchRecursive purge = new PurgeBranchRecursive(ol, parent, null, null);
- //count how many children branches are in root (should be 0)
- Assert.assertEquals(7, root.getAllChildBranches(true).size());
- }
-}
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 f75d291..2381775 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
@@ -19,7 +19,9 @@ import org.eclipse.osee.framework.branch.management.change.LoadDeltasBetweenBran
import org.eclipse.osee.framework.branch.management.change.LoadDeltasBetweenTxsOnTheSameBranch;
import org.eclipse.osee.framework.branch.management.commit.CommitDbOperation;
import org.eclipse.osee.framework.branch.management.creation.CreateBranchOperation;
-import org.eclipse.osee.framework.branch.management.purge.PurgeBranchOperation;
+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.PurgeBranchOperationFactory;
import org.eclipse.osee.framework.core.enums.BranchArchivedState;
import org.eclipse.osee.framework.core.enums.BranchState;
import org.eclipse.osee.framework.core.enums.BranchType;
@@ -147,8 +149,11 @@ public class OseeBranchService implements IOseeBranchService {
@Override
public IOperation purge(IProgressMonitor monitor, PurgeBranchRequest request, OperationLogger logger) throws OseeCoreException {
BranchCache branchCache = cachingService.getOseeCachingService().getBranchCache();
- return new PurgeBranchOperation(logger, branchCache.getById(request.getBranchId()),
- cachingService.getOseeCachingService(), oseeDatabaseProvider.getOseeDatabaseService());
+ Branch branch = branchCache.getById(request.getBranchId());
+ IBranchOperationFactory factory =
+ new PurgeBranchOperationFactory(logger, branchCache, oseeDatabaseProvider.getOseeDatabaseService());
+
+ return new BranchOperation(logger, factory, branch);
}
@Override
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/BranchOperation.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/BranchOperation.java
new file mode 100644
index 0000000..80bb48f
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/BranchOperation.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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.purge;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.osee.framework.branch.management.internal.Activator;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.operation.AbstractOperation;
+import org.eclipse.osee.framework.core.operation.IOperation;
+import org.eclipse.osee.framework.core.operation.OperationLogger;
+import org.eclipse.osee.framework.core.util.Conditions;
+
+/**
+ * @author John Misinco
+ */
+public final class BranchOperation extends AbstractOperation {
+
+ private final IBranchOperationFactory operationFactory;
+ private final IBranchesProvider branchProvider;
+
+ public BranchOperation(OperationLogger logger, IBranchOperationFactory operationFactory, IBranchesProvider branchProvider) {
+ super("Branches", Activator.PLUGIN_ID, logger);
+ this.operationFactory = operationFactory;
+ this.branchProvider = branchProvider;
+ }
+
+ public BranchOperation(OperationLogger logger, IBranchOperationFactory operationFactory, Branch branch) {
+ this(logger, operationFactory, new SingleBranchProvider(branch));
+ }
+
+ @Override
+ protected void doWork(IProgressMonitor monitor) throws OseeCoreException {
+ Conditions.checkNotNull(operationFactory, "operationFactory");
+ Conditions.checkNotNull(branchProvider, "branchProvider");
+ Collection<Branch> branches = branchProvider.getBranches();
+ Conditions.checkNotNull(branches, "branches");
+
+ logf("Branch Operation Starting for %d branch(es).", branches.size());
+ for (Branch branch : order(branches)) {
+ AbstractOperation.checkForCancelledStatus(monitor);
+ IOperation subOp = operationFactory.createOperation(branch);
+ log(subOp.getName());
+ doSubWork(subOp, monitor, 0);
+ }
+ }
+
+ private List<Branch> order(Collection<Branch> branches) throws OseeCoreException {
+ List<Branch> list = new ArrayList<Branch>(branches);
+ for (int i = 0; i < list.size(); i++) {
+ Branch cur = list.get(i);
+ Branch parent = cur.getParentBranch();
+
+ //this is the last element in the list
+ if (parent == null || !list.contains(parent)) {
+ Branch last = list.get(list.size() - 1);
+ list.set(i, last);
+ list.set(list.size() - 1, cur);
+ } else {
+ int parentIdx = list.indexOf(parent);
+ //need to swap
+ if (parentIdx < i) {
+ list.set(i, parent);
+ list.set(parentIdx, cur);
+ //reset i
+ i--;
+ }
+ }
+ }
+ return list;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java
new file mode 100644
index 0000000..5b4b4bf
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/DeletedBranchProvider.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.purge;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.enums.BranchArchivedState;
+import org.eclipse.osee.framework.core.enums.BranchState;
+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.BranchCache;
+import org.eclipse.osee.framework.core.model.cache.BranchFilter;
+import org.eclipse.osee.framework.core.util.Conditions;
+
+/**
+ * @author John Misinco
+ */
+public final class DeletedBranchProvider implements IBranchesProvider {
+ private final BranchCache branchCache;
+
+ public DeletedBranchProvider(BranchCache branchCache) {
+ this.branchCache = branchCache;
+ }
+
+ @Override
+ public Collection<Branch> getBranches() throws OseeCoreException {
+ Conditions.checkNotNull(branchCache, "branchCache");
+ BranchFilter branchFilter = new BranchFilter(BranchArchivedState.ARCHIVED, BranchType.WORKING);
+ branchFilter.setBranchStates(BranchState.DELETED);
+ return branchCache.getBranches(branchFilter);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchOperationFactory.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchOperationFactory.java
new file mode 100644
index 0000000..9bf2869
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchOperationFactory.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * 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.purge;
+
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.operation.IOperation;
+
+/**
+ * @author John Misinco
+ */
+public interface IBranchOperationFactory {
+ public IOperation createOperation(Branch branch);
+}
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchesProvider.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchesProvider.java
new file mode 100644
index 0000000..d8e8204
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/IBranchesProvider.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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.purge;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+
+/**
+ * @author John Misinco
+ */
+public interface IBranchesProvider {
+ Collection<Branch> getBranches() throws OseeCoreException;
+}
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperation.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperation.java
index 9a41e9a..3c0c79d 100644
--- a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperation.java
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperation.java
@@ -22,7 +22,6 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.cache.BranchCache;
import org.eclipse.osee.framework.core.operation.OperationLogger;
-import org.eclipse.osee.framework.core.services.IOseeCachingService;
import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.database.core.AbstractDbTxOperation;
import org.eclipse.osee.framework.database.core.IOseeStatement;
@@ -57,15 +56,15 @@ public class PurgeBranchOperation extends AbstractDbTxOperation {
private OseeConnection connection;
private IProgressMonitor monitor;
private final String sourceTableName;
- private final IOseeCachingService cachingService;
+ private final BranchCache branchCache;
private final IOseeDatabaseService databaseService;
- public PurgeBranchOperation(OperationLogger logger, Branch branch, IOseeCachingService cachingService, IOseeDatabaseService databaseService) {
+ public PurgeBranchOperation(OperationLogger logger, Branch branch, BranchCache branchCache, IOseeDatabaseService databaseService) {
super(databaseService, String.format("Purge Branch: [(%s)-%s]", branch.getId(), branch.getShortName()),
Activator.PLUGIN_ID, logger);
this.branch = branch;
this.sourceTableName = branch.getArchiveState().isArchived() ? "osee_txs_archived" : "osee_txs";
- this.cachingService = cachingService;
+ this.branchCache = branchCache;
this.databaseService = databaseService;
}
@@ -94,7 +93,6 @@ public class PurgeBranchOperation extends AbstractDbTxOperation {
purgeFromTable("Merge", DELETE_FROM_MERGE, 0.01, branch.getId(), branch.getParentBranch().getId());
purgeFromTable("Branch", DELETE_FROM_BRANCH_TABLE, 0.01, branch.getId());
- BranchCache branchCache = cachingService.getBranchCache();
branch.setStorageState(StorageState.PURGED);
branchCache.storeItems(branch);
branch.internalRemovePurgedBranchFromParent();
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperationFactory.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperationFactory.java
new file mode 100644
index 0000000..cf30ea8
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchOperationFactory.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.purge;
+
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.cache.BranchCache;
+import org.eclipse.osee.framework.core.operation.IOperation;
+import org.eclipse.osee.framework.core.operation.OperationLogger;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+
+/**
+ * @author John Misinco
+ */
+public final class PurgeBranchOperationFactory implements IBranchOperationFactory {
+
+ private final BranchCache branchCache;
+ private final IOseeDatabaseService databaseService;
+ private final OperationLogger logger;
+
+ public PurgeBranchOperationFactory(OperationLogger logger, BranchCache branchCache, IOseeDatabaseService databaseService) {
+ this.branchCache = branchCache;
+ this.databaseService = databaseService;
+ this.logger = logger;
+ }
+
+ @Override
+ public IOperation createOperation(Branch branch) {
+ return new PurgeBranchOperation(logger, branch, branchCache, databaseService);
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchRecursive.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchRecursive.java
deleted file mode 100644
index 0d8da87..0000000
--- a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeBranchRecursive.java
+++ /dev/null
@@ -1,55 +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.purge;
-
-import java.util.Collection;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.osee.framework.branch.management.internal.Activator;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.model.Branch;
-import org.eclipse.osee.framework.core.operation.AbstractOperation;
-import org.eclipse.osee.framework.core.operation.OperationLogger;
-import org.eclipse.osee.framework.core.services.IOseeCachingService;
-import org.eclipse.osee.framework.database.IOseeDatabaseService;
-
-/**
- * @author John Misinco
- */
-
-public class PurgeBranchRecursive extends AbstractOperation {
-
- private final IOseeCachingService cachingService;
- private final IOseeDatabaseService databaseService;
- private final Branch toDelete;
-
- public PurgeBranchRecursive(OperationLogger logger, Branch toDelete, IOseeCachingService cachingService, IOseeDatabaseService databaseService) {
- super("Purge Branch Recursive", Activator.PLUGIN_ID, logger);
- this.cachingService = cachingService;
- this.databaseService = databaseService;
- this.toDelete = toDelete;
- }
-
- @Override
- protected void doWork(IProgressMonitor monitor) throws OseeCoreException {
- Collection<Branch> children = toDelete.getAllChildBranches(true);
- //add parent so it gets deleted last
- children.add(toDelete);
- logf("Found %s branches to purge.", children.size());
- for (Branch branch : children) {
- logf("Purging %s.", branch);
- try {
- doSubWork(new PurgeBranchOperation(getLogger(), branch, cachingService, databaseService), monitor, 0);
- } catch (OseeCoreException ex) {
- log(ex);
- }
- }
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeDeletedBranches.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeDeletedBranches.java
deleted file mode 100644
index d433efa..0000000
--- a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/PurgeDeletedBranches.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 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.purge;
-
-import java.util.List;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.osee.framework.branch.management.internal.Activator;
-import org.eclipse.osee.framework.core.enums.BranchArchivedState;
-import org.eclipse.osee.framework.core.enums.BranchState;
-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.BranchCache;
-import org.eclipse.osee.framework.core.model.cache.BranchFilter;
-import org.eclipse.osee.framework.core.operation.AbstractOperation;
-import org.eclipse.osee.framework.core.operation.OperationLogger;
-import org.eclipse.osee.framework.core.services.IOseeCachingService;
-import org.eclipse.osee.framework.database.IOseeDatabaseService;
-
-public class PurgeDeletedBranches extends AbstractOperation {
- private final IOseeCachingService cachingService;
- private final IOseeDatabaseService databaseService;
-
- public PurgeDeletedBranches(OperationLogger logger, IOseeCachingService cachingService, IOseeDatabaseService databaseService) {
- super("Purge Deleted Branches", Activator.PLUGIN_ID, logger);
- this.cachingService = cachingService;
- this.databaseService = databaseService;
- }
-
- @Override
- protected void doWork(IProgressMonitor monitor) throws OseeCoreException {
- BranchFilter branchFilter = new BranchFilter(BranchArchivedState.ARCHIVED, BranchType.WORKING);
- branchFilter.setBranchStates(BranchState.DELETED);
- BranchCache branchCache = cachingService.getBranchCache();
-
- List<Branch> branches = branchCache.getBranches(branchFilter);
- logf("Found %s branches to purge.", branches.size());
- for (Branch branch : branches) {
- logf("Purging %s.", branch);
- try {
- doSubWork(new PurgeBranchOperation(getLogger(), branch, cachingService, databaseService), monitor, 0);
- } catch (OseeCoreException ex) {
- log(ex);
- }
- }
- }
-} \ No newline at end of file
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/RecursiveBranchProvider.java
new file mode 100644
index 0000000..bcc6a63
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/RecursiveBranchProvider.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.purge;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+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.eclipse.osee.framework.core.util.Conditions;
+
+/**
+ * @author John Misinco
+ */
+public final class RecursiveBranchProvider implements IBranchesProvider {
+ private final Branch parentBranch;
+ private final BranchFilter filter;
+
+ public RecursiveBranchProvider(Branch parentBranch, BranchFilter filter) {
+ this.parentBranch = parentBranch;
+ this.filter = filter;
+ }
+
+ @Override
+ public Collection<Branch> getBranches() throws OseeCoreException {
+ Conditions.checkNotNull(parentBranch, "seed");
+ Set<Branch> children = new HashSet<Branch>();
+ parentBranch.getChildBranches(children, true, filter);
+ children.add(parentBranch);
+ return children;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/SingleBranchProvider.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/SingleBranchProvider.java
new file mode 100644
index 0000000..c709ee1
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/purge/SingleBranchProvider.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.purge;
+
+import java.util.Collection;
+import java.util.Collections;
+import org.eclipse.osee.framework.core.model.Branch;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class SingleBranchProvider implements IBranchesProvider {
+ private final Branch branch;
+
+ public SingleBranchProvider(Branch branch) {
+ this.branch = branch;
+ }
+
+ @Override
+ public Collection<Branch> getBranches() {
+ return Collections.singleton(branch);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/mocks/MockOperation.java b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/mocks/MockOperation.java
index fd26569..79165bc 100644
--- a/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/mocks/MockOperation.java
+++ b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/mocks/MockOperation.java
@@ -11,6 +11,7 @@
package org.eclipse.osee.framework.core.test.mocks;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osee.framework.core.operation.IOperation;
@@ -19,8 +20,14 @@ import org.eclipse.osee.framework.core.operation.IOperation;
*/
public class MockOperation implements IOperation {
private final IStatus status;
+ private boolean called;
+
+ public MockOperation() {
+ this(Status.OK_STATUS);
+ }
public MockOperation(IStatus status) {
+ setCalled(false);
this.status = status;
}
@@ -31,6 +38,15 @@ public class MockOperation implements IOperation {
@Override
public IStatus run(SubMonitor subMonitor) {
+ setCalled(true);
return status;
}
+
+ public boolean getCalled() {
+ return called;
+ }
+
+ public void setCalled(boolean called) {
+ this.called = called;
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java
index 3218a42..d0b7bf9 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/operation/AbstractOperation.java
@@ -119,7 +119,7 @@ public abstract class AbstractOperation implements IOperation {
* throws OperationCanceledException if the user cancelled the operation via the monitor , otherwise it simply
* returns
*/
- protected static final void checkForCancelledStatus(IProgressMonitor monitor) throws OperationCanceledException {
+ public static final void checkForCancelledStatus(IProgressMonitor monitor) throws OperationCanceledException {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
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 97b4d33..5984ed3 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,6 +11,7 @@
package org.eclipse.osee.framework.server.admin;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.server.admin.branch.BranchCommands;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
@@ -54,16 +55,21 @@ public class BranchManagementCommandProvider implements CommandProvider {
return branchCmds.purgeDeletedBranches(ci);
}
+ public Job _purge_branch_recursive(CommandInterpreter ci) throws OseeCoreException {
+ return branchCmds.purgeBranchRecursive(ci);
+ }
+
@Override
public String getHelp() {
StringBuilder sb = new StringBuilder();
sb.append("\n---OSEE Branch Commands---\n");
- sb.append(" export_branch <exchangeFileName> [-compress] [-minTx <value>] [-maxTx <value>] [-exclude_baseline_txs] [-includeArchivedBranches] -excludeBranchIds [<branchId>]+ - export a specific set of branches into an exchange zip file.\n");
- sb.append(" export_branch_stop - stop branch export\n");
- sb.append(" import_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(" check_exchange <exchangeFileName> - checks an exchange file to ensure data integrity\n");
- sb.append(" check_exchange_stop - stop exchange integrity check\n");
- sb.append(" purge_deleted_branches - permenatly remove all branches that are both archived and deleted \n");
+ sb.append("\texport_branch <exchangeFileName> [-compress] [-minTx <value>] [-maxTx <value>] [-exclude_baseline_txs] [-includeArchivedBranches] -excludeBranchIds [<branchId>]+ - export a specific set of branches into an exchange zip file.\n");
+ sb.append("\texport_branch_stop - stop branch export\n");
+ 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("\tcheck_exchange_stop - stop exchange integrity check\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");
return sb.toString();
}
diff --git a/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/branch/BranchCommands.java b/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/branch/BranchCommands.java
index 4874f8c..6506530 100644
--- a/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/branch/BranchCommands.java
+++ b/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/branch/BranchCommands.java
@@ -11,11 +11,22 @@
package org.eclipse.osee.framework.server.admin.branch;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.osee.framework.branch.management.purge.PurgeDeletedBranches;
+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.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.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.cache.BranchCache;
+import org.eclipse.osee.framework.core.model.cache.BranchFilter;
import org.eclipse.osee.framework.core.operation.CommandInterpreterLogger;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.core.operation.OperationLogger;
import org.eclipse.osee.framework.core.operation.Operations;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.server.admin.internal.Activator;
import org.eclipse.osgi.framework.console.CommandInterpreter;
@@ -122,8 +133,30 @@ public class BranchCommands {
public Job purgeDeletedBranches(CommandInterpreter ci) {
OperationLogger logger = new CommandInterpreterLogger(ci);
- IOperation operation =
- new PurgeDeletedBranches(logger, Activator.getOseeCachingService(), Activator.getOseeDatabaseService());
+ BranchCache branchCache = Activator.getOseeCachingService().getBranchCache();
+ IBranchesProvider provider = new DeletedBranchProvider(branchCache);
+
+ return internalPurgeBranch(logger, branchCache, provider);
+ }
+
+ public Job purgeBranchRecursive(CommandInterpreter ci) throws OseeCoreException {
+ OperationLogger logger = new CommandInterpreterLogger(ci);
+ String branchGuid = ci.nextArgument();
+ BranchCache branchCache = Activator.getOseeCachingService().getBranchCache();
+ Branch seed = branchCache.getByGuid(branchGuid);
+
+ BranchFilter filter = new BranchFilter();
+ filter.setNegatedBranchTypes(BranchType.BASELINE);
+
+ IBranchesProvider provider = new RecursiveBranchProvider(seed, filter);
+ return internalPurgeBranch(logger, branchCache, provider);
+ }
+
+ private Job internalPurgeBranch(OperationLogger logger, BranchCache branchCache, IBranchesProvider provider) {
+ IOseeDatabaseService databaseService = Activator.getOseeDatabaseService();
+ IBranchOperationFactory factory = new PurgeBranchOperationFactory(logger, branchCache, databaseService);
+
+ IOperation operation = new BranchOperation(logger, factory, provider);
return Operations.executeAsJob(operation, false);
}
-}
+} \ No newline at end of file