| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2011 IBM Corporation and others. |
| 3 |
* |
| 4 |
* This program and the accompanying materials |
| 5 |
* are made available under the terms of the Eclipse Public License 2.0 |
| 6 |
* which accompanies this distribution, and is available at |
| 7 |
* https://www.eclipse.org/legal/epl-2.0/ |
| 8 |
* |
| 9 |
* SPDX-License-Identifier: EPL-2.0 |
| 10 |
* |
| 11 |
* Contributors: |
| 12 |
* IBM Corporation - initial API and implementation |
| 13 |
*******************************************************************************/ |
| 14 |
package org.eclipse.pde.internal.build.publisher; |
| 15 |
|
| 16 |
import java.io.File; |
| 17 |
import java.util.Collection; |
| 18 |
import org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser; |
| 19 |
import org.eclipse.equinox.p2.metadata.IArtifactKey; |
| 20 |
import org.eclipse.equinox.p2.metadata.IInstallableUnit; |
| 21 |
import org.eclipse.equinox.p2.metadata.Version; |
| 22 |
import org.eclipse.equinox.p2.publisher.IPublisherInfo; |
| 23 |
import org.eclipse.equinox.p2.publisher.eclipse.Feature; |
| 24 |
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction; |
| 25 |
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; |
| 26 |
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; |
| 27 |
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; |
| 28 |
|
| 29 |
public class GatherFeatureAction extends FeaturesAction { |
| 30 |
private GatheringComputer computer; |
| 31 |
private String groupId = null; |
| 32 |
private FeatureRootAdvice rootAdvice; |
| 33 |
private final File featureRoot; |
| 34 |
|
| 35 |
public GatherFeatureAction(File location, File featureRoot) { |
| 36 |
super(new File[] {location}); |
| 37 |
this.featureRoot = featureRoot; |
| 38 |
} |
| 39 |
|
| 40 |
public void setComputer(GatheringComputer computer) { |
| 41 |
this.computer = computer; |
| 42 |
} |
| 43 |
|
| 44 |
public void setGroupId(String groupId) { |
| 45 |
this.groupId = groupId; |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
protected Feature[] getFeatures(File[] locations) { |
| 50 |
Feature feature = new FeatureParser().parse(featureRoot); |
| 51 |
if (feature != null) { |
| 52 |
feature.setLocation(locations[0].getAbsolutePath()); |
| 53 |
rootAdvice.setFeatureId(feature.getId()); |
| 54 |
rootAdvice.setFeatureVersion(Version.parseVersion(feature.getVersion())); |
| 55 |
return new Feature[] {feature}; |
| 56 |
} |
| 57 |
return new Feature[0]; |
| 58 |
} |
| 59 |
|
| 60 |
// protected ArrayList generateRootFileIUs(Feature feature, IPublisherResult result, IPublisherInfo publisherInfo) { |
| 61 |
// ArrayList ius = new ArrayList(); |
| 62 |
// |
| 63 |
// Collection collection = publisherInfo.getAdvice(null, false, null, null, FeatureRootAdvice.class); |
| 64 |
// if (collection.size() == 0) |
| 65 |
// return ius; |
| 66 |
// |
| 67 |
// FeatureRootAdvice advice = (FeatureRootAdvice) collection.iterator().next(); |
| 68 |
// String[] configs = advice.getConfigs(); |
| 69 |
// for (int i = 0; i < configs.length; i++) { |
| 70 |
// String config = configs[i]; |
| 71 |
// |
| 72 |
// GatheringComputer rootComputer = advice.getRootFileComputer(config); |
| 73 |
// |
| 74 |
// if (rootComputer != null) { |
| 75 |
// FileSetDescriptor descriptor = advice.getDescriptor(config); |
| 76 |
// IInstallableUnit iu = (IInstallableUnit) createFeatureRootFileIU(feature.getId(), feature.getVersion(), null, descriptor)[0]; |
| 77 |
// |
| 78 |
// File[] files = rootComputer.getFiles(); |
| 79 |
// IArtifactKey artifactKey = iu.getArtifacts()[0]; |
| 80 |
// ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactKey); |
| 81 |
// publishArtifact(artifactDescriptor, files, null, publisherInfo, rootComputer); |
| 82 |
// |
| 83 |
// result.addIU(iu, IPublisherResult.NON_ROOT); |
| 84 |
// ius.add(iu); |
| 85 |
// } |
| 86 |
// } |
| 87 |
// return ius; |
| 88 |
// } |
| 89 |
|
| 90 |
@Override |
| 91 |
protected String getGroupId(String featureId) { |
| 92 |
if (groupId != null) |
| 93 |
return groupId; |
| 94 |
return super.getGroupId(featureId); |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
protected IInstallableUnit generateFeatureJarIU(Feature feature, IPublisherInfo publisherInfo) { |
| 99 |
if (computer == null) |
| 100 |
return null; |
| 101 |
return createFeatureJarIU(feature, publisherInfo); |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
protected void publishFeatureArtifacts(Feature feature, IInstallableUnit featureIU, IPublisherInfo publisherInfo) { |
| 106 |
if (computer == null) |
| 107 |
return; |
| 108 |
|
| 109 |
// add all the artifacts associated with the feature |
| 110 |
Collection<IArtifactKey> artifacts = featureIU.getArtifacts(); |
| 111 |
if (artifacts.size() > 1) { |
| 112 |
//boo! |
| 113 |
} |
| 114 |
|
| 115 |
ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(publisherInfo, artifacts.iterator().next(), null); |
| 116 |
processArtifactPropertiesAdvice(featureIU, ad, publisherInfo); |
| 117 |
ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP); |
| 118 |
|
| 119 |
publishArtifact(ad, computer.getFiles(), null, publisherInfo, computer); |
| 120 |
} |
| 121 |
|
| 122 |
public void setRootAdvice(FeatureRootAdvice rootAdvice) { |
| 123 |
this.rootAdvice = rootAdvice; |
| 124 |
} |
| 125 |
} |