forked from eclipse-tycho/tycho
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-tycho#114 Create a 'maven-p2-site' plugin
- add a PublisherApplication - add first version of mojo Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
- Loading branch information
Showing
5 changed files
with
411 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?eclipse version="3.4"?> | ||
<plugin> | ||
<extension | ||
id="org.eclipse.tycho.p2.tools.publisher.TychoFeaturesAndBundlesPublisher" | ||
point="org.eclipse.core.runtime.applications"> | ||
<application | ||
cardinality="1" | ||
thread="any" | ||
visible="true"> | ||
<run | ||
class="org.eclipse.tycho.p2.tools.publisher.TychoFeaturesAndBundlesPublisherApplication"> | ||
</run> | ||
</application> | ||
</extension> | ||
</plugin> |
172 changes: 172 additions & 0 deletions
172
...ava/org/eclipse/tycho/p2/tools/publisher/TychoFeaturesAndBundlesPublisherApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.p2.tools.publisher; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.core.runtime.URIUtil; | ||
import org.eclipse.equinox.internal.p2.updatesite.CategoryXMLAction; | ||
import org.eclipse.equinox.p2.metadata.IInstallableUnit; | ||
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription; | ||
import org.eclipse.equinox.p2.publisher.AbstractPublisherAction; | ||
import org.eclipse.equinox.p2.publisher.AbstractPublisherApplication; | ||
import org.eclipse.equinox.p2.publisher.AdviceFileAdvice; | ||
import org.eclipse.equinox.p2.publisher.IPublisherAction; | ||
import org.eclipse.equinox.p2.publisher.IPublisherInfo; | ||
import org.eclipse.equinox.p2.publisher.IPublisherResult; | ||
import org.eclipse.equinox.p2.publisher.PublisherInfo; | ||
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction; | ||
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; | ||
import org.eclipse.osgi.service.resolver.BundleDescription; | ||
import org.osgi.framework.BundleException; | ||
|
||
@SuppressWarnings("restriction") | ||
public class TychoFeaturesAndBundlesPublisherApplication extends AbstractPublisherApplication { | ||
|
||
private static final String MAVEN_PREFIX = "maven-"; | ||
private BundleDescription[] bundles; | ||
private File[] advices; | ||
private URI categoryDefinition; | ||
|
||
@Override | ||
protected void processParameter(String arg, String parameter, PublisherInfo publisherInfo) | ||
throws URISyntaxException { | ||
super.processParameter(arg, parameter, publisherInfo); | ||
if (arg.equalsIgnoreCase("-bundles")) { | ||
bundles = Arrays.stream(AbstractPublisherAction.getArrayFromString(parameter, ",")).map(File::new) | ||
.map(t -> { | ||
try { | ||
return BundlesAction.createBundleDescription(t); | ||
} catch (IOException | BundleException e) { | ||
//ignoring files that are "not bundles" they will be skipped on the later steps | ||
return null; | ||
} | ||
}).toArray(BundleDescription[]::new); | ||
} | ||
if (arg.equalsIgnoreCase("-advices")) { | ||
advices = Arrays.stream(AbstractPublisherAction.getArrayFromString(parameter, ",")) | ||
.map(str -> str.isBlank() ? null : new File(str)).toArray(File[]::new); | ||
} | ||
if (arg.equalsIgnoreCase("-categoryDefinition")) { | ||
categoryDefinition = URIUtil.fromString(parameter); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected IPublisherAction[] createActions() { | ||
List<IPublisherAction> result = new ArrayList<>(); | ||
if (advices != null) { | ||
List<AdviceFileAdvice> advicesList = new ArrayList<>(); | ||
for (int i = 0; i < advices.length; i++) { | ||
File adviceFile = advices[i]; | ||
BundleDescription bundleDescription; | ||
if (i >= bundles.length - 1 || (bundleDescription = bundles[i]) == null) { | ||
continue; | ||
} | ||
String symbolicName = bundleDescription.getSymbolicName(); | ||
if (symbolicName == null) { | ||
//not a bundle... no advice... | ||
continue; | ||
} | ||
advicesList.add(new AdviceFileAdvice(symbolicName, | ||
PublisherHelper.fromOSGiVersion(bundleDescription.getVersion()), | ||
new Path(adviceFile.getParentFile().getAbsolutePath()), new Path(adviceFile.getName())) { | ||
|
||
@Override | ||
public Map<String, String> getArtifactProperties(IInstallableUnit iu, | ||
IArtifactDescriptor descriptor) { | ||
|
||
// workaround Bug 539672 | ||
Map<String, String> properties = super.getInstallableUnitProperties(null); | ||
if (properties != null) { | ||
if (descriptor instanceof ArtifactDescriptor) { | ||
ArtifactDescriptor artifactDescriptor = (ArtifactDescriptor) descriptor; | ||
for (Map.Entry<String, String> entry : properties.entrySet()) { | ||
String key = entry.getKey(); | ||
String value = entry.getValue(); | ||
if (key.startsWith(MAVEN_PREFIX)) { | ||
String key2 = "maven." + key.substring(MAVEN_PREFIX.length()); | ||
artifactDescriptor.setProperty(key2, value); | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getInstallableUnitProperties(InstallableUnitDescription iu) { | ||
Map<String, String> properties = super.getInstallableUnitProperties(iu); | ||
if (properties == null) { | ||
return null; | ||
} | ||
Map<String, String> installableUnitProperties = new LinkedHashMap<>(properties); | ||
Set<String> keySet = installableUnitProperties.keySet(); | ||
for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) { | ||
String string = iterator.next(); | ||
if (string.startsWith(MAVEN_PREFIX)) { | ||
iterator.remove(); | ||
} | ||
} | ||
return installableUnitProperties.isEmpty() ? null : installableUnitProperties; | ||
} | ||
|
||
}); | ||
result.add(new AdviceFilePublisherAction(advicesList)); | ||
} | ||
} | ||
if (bundles != null) { | ||
result.add(new BundlesAction(bundles)); | ||
} | ||
if (categoryDefinition != null) { | ||
result.add(new CategoryXMLAction(categoryDefinition, "category")); | ||
} | ||
return result.toArray(IPublisherAction[]::new); | ||
} | ||
|
||
private static final class AdviceFilePublisherAction extends AbstractPublisherAction { | ||
|
||
private List<AdviceFileAdvice> advicesList; | ||
|
||
public AdviceFilePublisherAction(List<AdviceFileAdvice> advicesList) { | ||
this.advicesList = advicesList; | ||
} | ||
|
||
@Override | ||
public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor) { | ||
for (AdviceFileAdvice advice : advicesList) { | ||
publisherInfo.addAdvice(advice); | ||
} | ||
return Status.OK_STATUS; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.