1 /******************************************************************************
2 * Copyright (c) 2012 GitHub Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License 2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-2.0/
8 * SPDX-License-Identifier: EPL-2.0
11 * Kevin Sawicki (GitHub Inc.) - initial API and implementation
12 * Stephan Hackstedt <stephan.hackstedt@googlemail.com> - Bug 477695
13 *****************************************************************************/
14 package org
.eclipse
.egit
.core
.op
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Collection
;
19 import org
.eclipse
.core
.runtime
.CoreException
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.SubMonitor
;
22 import org
.eclipse
.jgit
.lib
.Repository
;
25 * Base operation that supports adding pre/post tasks
27 abstract class BaseOperation
implements IEGitOperation
{
29 protected final Repository repository
;
31 protected Collection
<PreExecuteTask
> preTasks
;
33 protected Collection
<PostExecuteTask
> postTasks
;
35 BaseOperation(final Repository repository
) {
36 this.repository
= repository
;
40 * Invoke all pre-execute tasks
43 * @throws CoreException
45 protected void preExecute(IProgressMonitor monitor
) throws CoreException
{
47 if (preTasks
!= null) {
48 SubMonitor progress
= SubMonitor
.convert(monitor
,
50 for (PreExecuteTask task
: preTasks
)
51 task
.preExecute(repository
, progress
.newChild(1));
57 * Invoke all post-execute tasks
60 * @throws CoreException
62 protected void postExecute(IProgressMonitor monitor
) throws CoreException
{
64 if (postTasks
!= null) {
65 SubMonitor progress
= SubMonitor
.convert(monitor
,
67 for (PostExecuteTask task
: postTasks
)
68 task
.postExecute(repository
, progress
.newChild(1));
75 * to be performed before execution
77 public synchronized void addPreExecuteTask(final PreExecuteTask task
) {
79 preTasks
= new ArrayList
<PreExecuteTask
>();
85 * to be performed after execution
87 public synchronized void addPostExecuteTask(PostExecuteTask task
) {
88 if (postTasks
== null)
89 postTasks
= new ArrayList
<PostExecuteTask
>();