Skip to main content
summaryrefslogtreecommitdiffstats
blob: f328f2d44ef333c0c207113a8356da6e93370872 (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
/*******************************************************************************
 * Copyright (c) 2008, 2011 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.pde.internal.build.publisher;

import java.io.File;
import java.util.Collection;
import org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.publisher.IPublisherInfo;
import org.eclipse.equinox.p2.publisher.eclipse.Feature;
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;

public class GatherFeatureAction extends FeaturesAction {
	private GatheringComputer computer;
	private String groupId = null;
	private FeatureRootAdvice rootAdvice;
	private final File featureRoot;

	public GatherFeatureAction(File location, File featureRoot) {
		super(new File[] {location});
		this.featureRoot = featureRoot;
	}

	public void setComputer(GatheringComputer computer) {
		this.computer = computer;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	@Override
	protected Feature[] getFeatures(File[] locations) {
		Feature feature = new FeatureParser().parse(featureRoot);
		if (feature != null) {
			feature.setLocation(locations[0].getAbsolutePath());
			rootAdvice.setFeatureId(feature.getId());
			rootAdvice.setFeatureVersion(Version.parseVersion(feature.getVersion()));
			return new Feature[] {feature};
		}
		return new Feature[0];
	}

	//	protected ArrayList generateRootFileIUs(Feature feature, IPublisherResult result, IPublisherInfo publisherInfo) {
	//		ArrayList ius = new ArrayList();
	//
	//		Collection collection = publisherInfo.getAdvice(null, false, null, null, FeatureRootAdvice.class);
	//		if (collection.size() == 0)
	//			return ius;
	//
	//		FeatureRootAdvice advice = (FeatureRootAdvice) collection.iterator().next();
	//		String[] configs = advice.getConfigs();
	//		for (int i = 0; i < configs.length; i++) {
	//			String config = configs[i];
	//
	//			GatheringComputer rootComputer = advice.getRootFileComputer(config);
	//
	//			if (rootComputer != null) {
	//				FileSetDescriptor descriptor = advice.getDescriptor(config);
	//				IInstallableUnit iu = (IInstallableUnit) createFeatureRootFileIU(feature.getId(), feature.getVersion(), null, descriptor)[0];
	//
	//				File[] files = rootComputer.getFiles();
	//				IArtifactKey artifactKey = iu.getArtifacts()[0];
	//				ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactKey);
	//				publishArtifact(artifactDescriptor, files, null, publisherInfo, rootComputer);
	//
	//				result.addIU(iu, IPublisherResult.NON_ROOT);
	//				ius.add(iu);
	//			}
	//		}
	//		return ius;
	//	}

	@Override
	protected String getGroupId(String featureId) {
		if (groupId != null)
			return groupId;
		return super.getGroupId(featureId);
	}

	@Override
	protected IInstallableUnit generateFeatureJarIU(Feature feature, IPublisherInfo publisherInfo) {
		if (computer == null)
			return null;
		return createFeatureJarIU(feature, publisherInfo);
	}

	@Override
	protected void publishFeatureArtifacts(Feature feature, IInstallableUnit featureIU, IPublisherInfo publisherInfo) {
		if (computer == null)
			return;

		// add all the artifacts associated with the feature
		Collection<IArtifactKey> artifacts = featureIU.getArtifacts();
		if (artifacts.size() > 1) {
			//boo!
		}

		ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(publisherInfo, artifacts.iterator().next(), null);
		processArtifactPropertiesAdvice(featureIU, ad, publisherInfo);
		ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);

		publishArtifact(ad, computer.getFiles(), null, publisherInfo, computer);
	}

	public void setRootAdvice(FeatureRootAdvice rootAdvice) {
		this.rootAdvice = rootAdvice;
	}
}

Back to the top