Skip to main content
summaryrefslogtreecommitdiffstats
blob: 19729096f096eae039eaaf7d869579d534f9cb13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************************************
 * Copyright (c) 2007 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
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.prov.engine;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.prov.engine.Messages;
import org.eclipse.equinox.prov.core.helpers.MultiStatus;
import org.eclipse.osgi.util.NLS;

public abstract class Phase {
	protected final String phaseId;
	protected final int weight;
	protected final String phaseName;

	protected Phase(String phaseId, int weight, String phaseName) {
		if (phaseId == null || phaseId.length() == 0) {
			throw new IllegalArgumentException("Phase id must be set.");
		}

		if (weight <= 0) {
			throw new IllegalArgumentException("Phase weight must be positive.");
		}

		if (phaseName == null || phaseName.length() == 0) {
			throw new IllegalArgumentException("Phase name must be set.");
		}

		this.weight = weight;
		this.phaseName = phaseName;
		this.phaseId = phaseId;
	}

	public String toString() {
		return "Phase: " + this.phaseName + " - " + this.weight; //$NON-NLS-1$ //$NON-NLS-2$
	}

	protected MultiStatus perform(EngineSession session, Profile profile, Operand[] deltas, IProgressMonitor monitor) {
		MultiStatus status = new MultiStatus();
		//			log.start(log.info(Messages2.Engine_Performing_Phase, this.phaseName));
		perform(status, session, profile, deltas, monitor);
		//			log.stop();
		if (status.matches(IStatus.CANCEL)) {
			status.setMessage(Messages.Engine_Operation_Canceled_By_User);
		} else if (status.matches(IStatus.ERROR)) {
			status.setMessage(NLS.bind(Messages.Engine_Error_During_Phase, this.phaseName));
		}
		return status;
	}

	protected abstract void perform(MultiStatus status, EngineSession session, Profile profile, Operand[] deltas, IProgressMonitor monitor);

}

Back to the top