Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fceaaf32a4f5eba477e308b9eb33c2d494e80f88 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*******************************************************************************
 * Copyright (c) 2009 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.p2.internal.repository.tools.tasks;

import java.io.File;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.artifact.repository.ant.AntMirrorLog;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.p2.internal.repository.tools.Messages;
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;

public class MirrorTask extends AbstractRepositoryTask {

	private File mirrorLog; // file to log mirror output to (optional)
	private ComparatorDescription comparator;

	public MirrorTask() {
		application = new MirrorApplication();
	}

	public void execute() throws BuildException {
		try {
			if (mirrorLog != null)
				((MirrorApplication) application).setLog(mirrorLog);
			else
				((MirrorApplication) application).setLog(new AntMirrorLog(this));

			if (comparator != null) {
				// Enable comparison
				((MirrorApplication) application).setCompare(true);
				// Set baseline location
				if (comparator.getBaseline() != null)
					((MirrorApplication) application).setBaseline(comparator.getBaseline().getDescriptor().getRepoLocation());
				// Set comparator to use
				if (comparator.getComparator() != null)
					((MirrorApplication) application).setComparatorID(comparator.getComparator());
				// Set comparator log
				if (comparator.getComparatorLog() != null)
					((MirrorApplication) application).setComparatorLog(comparator.getComparatorLog());
			}

			prepareSourceRepos();
			application.initializeRepos(null);
			List ius = prepareIUs();
			application.setSourceIUs(ius);
			IStatus result = application.run(null);
			if (result.matches(IStatus.ERROR))
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
		} catch (ProvisionException e) {
			throw new BuildException(e);
		} catch (NoSuchMethodException e) {
			// Should not occur
			throw new BuildException(e);
		}
	}

	public SlicingOption createSlicingOptions() {
		SlicingOption options = new SlicingOption();
		((MirrorApplication) application).setSlicingOptions(options.getOptions());
		return options;
	}

	/*
	 * Set the comparison information
	 */
	public ComparatorDescription createComparator() {
		if (comparator != null)
			throw new BuildException(Messages.exception_onlyOneComparator);
		comparator = new ComparatorDescription();
		return comparator;
	}

	/*
	 * Set the location of the mirror log
	 */
	public void setLog(String value) {
		mirrorLog = new File(value);
	}

	/*
	 * Set whether or not we should ignore errors when running the mirror application.
	 */
	public void setIgnoreErrors(boolean value) {
		((MirrorApplication) application).setIgnoreErrors(value);
	}

	/*
	 * Set whether or not the the artifacts are raw.
	 */
	public void setRaw(boolean value) {
		((MirrorApplication) application).setRaw(value);
	}

	/*
	 * Set whether or not the mirror application should be run in verbose mode.
	 */
	public void setVerbose(boolean value) {
		((MirrorApplication) application).setVerbose(value);
	}

	public void setValidate(boolean value) {
		((MirrorApplication) application).setValidate(value);
	}
}

Back to the top