Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: faba5e08ea7c1706a6037c1b0444c1a721bac5c5 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*******************************************************************************
 * Copyright (c) 2007, 2017 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.publisher.ant;

import java.io.File;
import org.apache.tools.ant.BuildException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IVersionedId;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.publisher.*;
import org.eclipse.equinox.p2.publisher.eclipse.EclipseInstallAction;

/**
 * An Ant task to call the p2 publisher application.
 * 
 * @since 1.0
 */
public class PublisherTask extends AbstractPublishTask {

	protected boolean inplace = false;
	protected String[] configurations;
	protected String mode;
	private String flavor;
	private String operation;
	private String operationValue;
	private String root;
	private String rootVersion;
	private String versionAdvice;
	private String rootName;
	private String executableName;
	private IVersionedId[] topLevel;
	private boolean start;
	private String[] nonRootFiles;

	/* (non-Javadoc)
	 * @see org.apache.tools.ant.Task#execute()
	 */
	@Override
	public void execute() throws BuildException {
		try {
			initialize(getInfo());
		} catch (ProvisionException e) {
			throw new BuildException("Unable to configure repositories", e); //$NON-NLS-1$
		}
		createVersionAdvice();
		IPublisherAction[] actions = createActions();
		//TODO Do something with publisher result
		new Publisher(getInfo()).publish(actions, new NullProgressMonitor());
	}

	private IPublisherAction[] createActions() {
		if (operation == null)
			// TODO what to do in this case?
			return new IPublisherAction[] {};
		if (operation.equals("-update")) //$NON-NLS-1$
			// TODO fix this up.  watch for circularities
			//			return new IPublishingAction[] {new LocalUpdateSiteAction(operationValue)};
			return new IPublisherAction[] {};
		if (operation.equals("-source")) //$NON-NLS-1$
			// TODO what to do in this case?
			return new IPublisherAction[] {new EclipseInstallAction(operationValue, root, Version.parseVersion(rootVersion), rootName, executableName, flavor, topLevel, nonRootFiles, start)};
		// TODO what to do in this case?
		return new IPublisherAction[] {};
	}

	private void createVersionAdvice() {
		if (versionAdvice == null)
			return;
		// TODO read the version advice and add the IVersionAdvice
	}

	protected void initialize(PublisherInfo info) throws ProvisionException {
		if (inplace) {
			File sourceLocation = new File(source);
			if (metadataLocation == null)
				metadataLocation = sourceLocation.toURI();
			if (artifactLocation == null)
				artifactLocation = sourceLocation.toURI();
			info.setArtifactOptions(info.getArtifactOptions() | IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH);
		} else
			info.setArtifactOptions(info.getArtifactOptions() | IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH | IPublisherInfo.A_OVERWRITE);
		initializeRepositories(info);
	}

	public void setBase(String value) {
		source = value;
	}

	public void setBundles(String value) {
		//TODO Remove - currently exists for compatibility with generator task
	}

	public void setConfig(String value) {
		operation = "-config"; //$NON-NLS-1$
		operationValue = value;
	}

	public void setInplace(String value) {
		operation = "-inplace"; //$NON-NLS-1$
		operationValue = value;
	}

	public void setSource(String location) {
		super.source = location;
		operation = "-source"; //$NON-NLS-1$
		operationValue = location;
	}

	public void setUpdateSite(String value) {
		operation = "-update"; //$NON-NLS-1$
		operationValue = value;
	}

	/**
	 * @deprecated
	 */
	@Deprecated
	public void setExe(String value) {
		executableName = value;
	}

	public void setFeatures(String value) {
		//TODO Remove - currently exists for compatibility with generator task
	}

	public void setFlavor(String value) {
		flavor = value;
	}

	/**
	 * @deprecated
	 */
	@Deprecated
	public void setLauncherConfig(String value) {
		//TODO Remove - currently exists for compatibility with generator task
	}

	public void setNoDefaultIUs(String value) {
		//TODO Remove - currently exists for compatibility with generator task
	}

	/**
	 * @deprecated
	 */
	@Deprecated
	public void setP2OS(String value) {
		//TODO Remove - currently exists for compatibility with generator task
	}

	public void setProductFile(String file) {
		//TODO Remove - currently exists for compatibility with generator task
	}

	public void setPublishArtifactRepository(String value) {
		getInfo().setArtifactOptions(getInfo().getArtifactOptions() | IPublisherInfo.A_INDEX);
	}

	@Override
	public void setPublishArtifacts(String value) {
		getInfo().setArtifactOptions(getInfo().getArtifactOptions() | IPublisherInfo.A_PUBLISH);
	}

	public void setRoot(String value) {
		root = value;
	}

	public void setRootVersion(String value) {
		rootVersion = value;
	}

	public void setMode(String value) {
		mode = value;
	}

	public void setVersionAdvice(String value) {
		versionAdvice = value;
	}
}

Back to the top