| 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.util.ArrayList; |
| 19 |
import org.eclipse.core.runtime.*; |
| 20 |
import org.eclipse.equinox.internal.p2.core.helpers.Tracing; |
| 21 |
import org.eclipse.equinox.p2.publisher.*; |
| 22 |
import org.eclipse.osgi.util.NLS; |
| 23 |
|
| 24 |
/** |
| 25 |
* A publishing action that processes a remote (URL-based) update site and generates |
| 26 |
* metadata and artifacts for the features, bundles and site index (categories etc). The |
| 27 |
* IUs generated for the bundles are "partial" as the bundles themselves are not downloaded. |
| 28 |
*/ |
| 29 |
public class RemoteUpdateSiteAction implements IPublisherAction { |
| 30 |
private UpdateSite updateSite; |
| 31 |
private final String categoryQualifier; |
| 32 |
|
| 33 |
/** |
| 34 |
* Creates a local remote updatesite publisher action from an UpdateSite |
| 35 |
* @param updateSite The UpdateSite to use |
| 36 |
* @param categoryQualifier The qualifier to prepend to categories. This qualifier is used |
| 37 |
* to ensure that the category IDs are unique between update sites. If <b>null</b> a default |
| 38 |
* qualifier will be generated |
| 39 |
*/ |
| 40 |
public RemoteUpdateSiteAction(UpdateSite updateSite, String categoryQualifier) { |
| 41 |
this.updateSite = updateSite; |
| 42 |
this.categoryQualifier = categoryQualifier; |
| 43 |
} |
| 44 |
|
| 45 |
@Override |
| 46 |
public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) { |
| 47 |
if (Tracing.DEBUG_PUBLISHING) |
| 48 |
Tracing.debug("Generating metadata for update site: " + updateSite.getLocation()); //$NON-NLS-1$ |
| 49 |
IPublisherAction[] actions = createActions(); |
| 50 |
MultiStatus finalStatus = new MultiStatus(this.getClass().getName(), 0, NLS.bind(Messages.Error_Generation, updateSite != null ? updateSite.getLocation().toString() : "Unknown"), null); //$NON-NLS-1$ |
| 51 |
for (IPublisherAction action : actions) { |
| 52 |
if (monitor.isCanceled()) |
| 53 |
return Status.CANCEL_STATUS; |
| 54 |
finalStatus.merge(action.perform(info, results, monitor)); |
| 55 |
} |
| 56 |
if (Tracing.DEBUG_PUBLISHING) |
| 57 |
Tracing.debug("Generation for update site complete: " + updateSite.getLocation()); //$NON-NLS-1$ |
| 58 |
if (!finalStatus.isOK()) |
| 59 |
return finalStatus; |
| 60 |
return Status.OK_STATUS; |
| 61 |
} |
| 62 |
|
| 63 |
protected IPublisherAction[] createActions() { |
| 64 |
ArrayList<IPublisherAction> result = new ArrayList<>(); |
| 65 |
result.add(new RemoteFeaturesAction(updateSite)); |
| 66 |
result.add(createSiteXMLAction()); |
| 67 |
return result.toArray(new IPublisherAction[result.size()]); |
| 68 |
} |
| 69 |
|
| 70 |
private IPublisherAction createSiteXMLAction() { |
| 71 |
return new SiteXMLAction(updateSite, categoryQualifier); |
| 72 |
} |
| 73 |
} |