Debian Codegraph @

bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/pde/internal/build/publisher/GatherBundleAction.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2008, 2015 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.Dictionary;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.equinox.p2.publisher.IPublisherInfo;
21 import org.eclipse.equinox.p2.publisher.IPublisherResult;
22 import org.eclipse.equinox.p2.publisher.eclipse.*;
23 import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
24 import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
25 import org.eclipse.osgi.service.resolver.BundleDescription;
26 import org.eclipse.pde.internal.publishing.Utils;
27
28 public class GatherBundleAction extends BundlesAction {
29 private GatheringComputer computer = null;
30 private String unpack = null;
31 private File manifestRoot = null;
32 private File bundleLocation = null;
33
34 /**
35 * @param location
36 */
37 public GatherBundleAction(File location, File manifestRoot) {
38 super(new File[] {location});
39 this.manifestRoot = manifestRoot;
40 this.bundleLocation = location;
41 }
42
43 @Override
44 public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor) {
45 return super.perform(publisherInfo, results, monitor);
46 }
47
48 @Override
49 protected void publishArtifact(IArtifactDescriptor descriptor, File base, File[] inclusions, IPublisherInfo publisherInfo) {
50 //ignore passed in inclusions, publish according to our computer
51 publishArtifact(descriptor, computer.getFiles(), null, publisherInfo, computer);
52 }
53
54 @Override
55 protected BundleDescription[] getBundleDescriptions(File[] bundleLocations, IProgressMonitor monitor) {
56 Dictionary<String, String> manifest = basicLoadManifestIgnoringExceptions(manifestRoot);
57 if (manifest == null)
58 return null;
59
60 BundleDescription bundle = createBundleDescription(manifest, bundleLocation);
61 createShapeAdvice(bundle);
62 return new BundleDescription[] {bundle};
63 }
64
65 protected void createShapeAdvice(BundleDescription bundle) {
66 @SuppressWarnings("unchecked")
67 Dictionary<String, String> manifest = (Dictionary<String, String>) bundle.getUserObject();
68 String shape = manifest.get(BUNDLE_SHAPE);
69 if (shape == null) {
70 if (unpack != null) {
71 shape = Boolean.parseBoolean(unpack) ? IBundleShapeAdvice.DIR : IBundleShapeAdvice.JAR;
72 } else {
73 shape = Utils.guessUnpack(bundle, Utils.getBundleClasspath(manifest)) ? IBundleShapeAdvice.DIR : IBundleShapeAdvice.JAR;
74 }
75 }
76 BundleShapeAdvice advice = new BundleShapeAdvice(bundle.getSymbolicName(), PublisherHelper.fromOSGiVersion(bundle.getVersion()), shape);
77 info.addAdvice(advice);
78 }
79
80 public void setComputer(GatheringComputer computer) {
81 this.computer = computer;
82 }
83
84 public void setUnpack(String unpack) {
85 this.unpack = unpack;
86 }
87 }