Debian Codegraph @

bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2008, 2017 Code 9 and others.
3 *
4 * This
5 * program and the accompanying materials are made available under the terms of
6 * the Eclipse Public License 2.0 which accompanies this distribution, and is
7 * available at
8 * https://www.eclipse.org/legal/epl-2.0/
9 *
10 * SPDX-License-Identifier: EPL-2.0
11 *
12 * Contributors:
13 * Code 9 - initial API and implementation
14 * IBM - ongoing development
15 ******************************************************************************/
16 package org.eclipse.equinox.internal.p2.updatesite;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import org.eclipse.core.runtime.*;
21 import org.eclipse.equinox.p2.publisher.*;
22 import org.eclipse.equinox.p2.publisher.actions.MergeResultsAction;
23 import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
24 import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
25 import org.eclipse.osgi.util.NLS;
26
27 /**
28 * A publishing action that processes a local (File-based) update site and generates
29 * metadata and artifacts for the features, bundles and site index (categories etc).
30 */
31 public class LocalUpdateSiteAction implements IPublisherAction {
32 protected String source;
33 private UpdateSite updateSite;
34 private String categoryQualifier;
35 private String categoryVersion;
36
37 protected LocalUpdateSiteAction() {
38 // empty
39 }
40
41 /**
42 * Creates a local updatesite publisher action from a source location
43 * @param source The location of the directory that contains the site.xml file
44 * @param categoryQualifier The qualifier to prepend to categories. This qualifier is used
45 * to ensure that the category IDs are unique between update sites. If <b>null</b> a default
46 * qualifier will be generated
47 */
48 public LocalUpdateSiteAction(String source, String categoryQualifier) {
49 this.source = source;
50 this.categoryQualifier = categoryQualifier;
51 }
52
53 /**
54 * Creates a local updatesite publisher action from an UpdateSite
55 * @param updateSite The updatesite to use
56 * @param categoryQualifier The qualifier to prepend to categories. This qualifier is used
57 * to ensure that the category IDs are unique between update sites. If <b>null</b> a default
58 * qualifier will be generated
59 */
60 public LocalUpdateSiteAction(UpdateSite updateSite, String categoryQualifier) {
61 this.updateSite = updateSite;
62 this.categoryQualifier = categoryQualifier;
63 }
64
65 public void setCategoryVersion(String version) {
66 categoryVersion = version;
67 }
68
69 @Override
70 public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) {
71 IPublisherAction[] actions = createActions();
72 MultiStatus finalStatus = new MultiStatus(LocalUpdateSiteAction.class.getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toString() : "Unknown")), null); //$NON-NLS-1$
73 for (IPublisherAction action : actions) {
74 if (monitor.isCanceled())
75 return Status.CANCEL_STATUS;
76 finalStatus.merge(action.perform(info, results, monitor));
77 }
78 if (!finalStatus.isOK())
79 return finalStatus;
80 return Status.OK_STATUS;
81 }
82
83 protected IPublisherAction[] createActions() {
84 createAdvice();
85 ArrayList<IPublisherAction> result = new ArrayList<>();
86 // create an action that just publishes the raw bundles and features
87 IPublisherAction action = new MergeResultsAction(new IPublisherAction[] {createFeaturesAction(), createBundlesAction()}, IPublisherResult.MERGE_ALL_NON_ROOT);
88 result.add(action);
89 result.add(createSiteXMLAction());
90 return result.toArray(new IPublisherAction[result.size()]);
91 }
92
93 private IPublisherAction createSiteXMLAction() {
94 SiteXMLAction action = null;
95 if (updateSite != null)
96 action = new SiteXMLAction(updateSite, categoryQualifier);
97 else if (source != null) {
98 action = new SiteXMLAction(new File(source, "site.xml").toURI(), categoryQualifier); //$NON-NLS-1$
99 }
100 if (action != null && categoryVersion != null)
101 action.setCategoryVersion(categoryVersion);
102 return action;
103 }
104
105 private void createAdvice() {
106 // empty
107 }
108
109 protected IPublisherAction createFeaturesAction() {
110 return new FeaturesAction(new File[] {new File(source, "features")}); //$NON-NLS-1$
111 }
112
113 protected IPublisherAction createBundlesAction() {
114 return new BundlesAction(new File[] {new File(source, "plugins")}); //$NON-NLS-1$
115 }
116
117 }