Skip to main content
summaryrefslogtreecommitdiffstats
blob: 582c01bcc166e278be2f97c569a9fed74919a65f (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
/*******************************************************************************
 * Copyright (c) 2009, 2017 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 - Initial API and implementation
 ******************************************************************************/
package org.eclipse.equinox.internal.p2.publisher.ant;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.Publisher;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;

public class FeaturesAndBundlesPublisherTask extends AbstractPublishTask {
	private final ArrayList<Object> features = new ArrayList<>();
	private final ArrayList<Object> bundles = new ArrayList<>();

	@Override
	public void execute() throws BuildException {
		try {
			initializeRepositories(getInfo());
		} catch (ProvisionException e) {
			throw new BuildException("Unable to configure repositories", e); //$NON-NLS-1$
		}

		File[] f = getLocations(features);
		File[] b = getLocations(bundles);

		ArrayList<IPublisherAction> actions = new ArrayList<>();
		if (f.length > 0)
			actions.add(new FeaturesAction(f));
		if (b.length > 0)
			actions.add(new BundlesAction(b));

		if (actions.size() > 0)
			new Publisher(getInfo()).publish(actions.toArray(new IPublisherAction[actions.size()]), new NullProgressMonitor());
	}

	private File[] getLocations(List<Object> collection) {
		ArrayList<Object> results = new ArrayList<>();
		for (Object obj : collection) {
			if (obj instanceof FileSet) {
				FileSet set = (FileSet) obj;

				DirectoryScanner scanner = set.getDirectoryScanner(getProject());
				String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
				for (int i = 0; i < 2; i++) {
					for (int j = 0; j < elements[i].length; j++) {
						results.add(new File(set.getDir(), elements[i][j]));
					}
				}
			} else if (obj instanceof File) {
				results.add(obj);
			}
		}
		return results.toArray(new File[results.size()]);
	}

	public FileSet createFeatures() {
		FileSet set = new FileSet();
		features.add(set);
		return set;
	}

	public FileSet createBundles() {
		FileSet set = new FileSet();
		bundles.add(set);
		return set;
	}

	public void setSource(String source) {
		super.source = source;
		features.add(new File(source, "features")); //$NON-NLS-1$
		bundles.add(new File(source, "plugins")); //$NON-NLS-1$
	}
}

Back to the top