use of org.eclipse.equinox.p2.publisher.eclipse.BundlesAction in project tycho by eclipse.
the class SourcesBundleDependencyMetadataGenerator method getPublisherActions.
@Override
protected List<IPublisherAction> getPublisherActions(IArtifactFacade artifact, List<TargetEnvironment> environments, OptionalResolutionAction optionalAction) {
ArrayList<IPublisherAction> actions = new ArrayList<>();
String id = artifact.getArtifactId();
String version = toCanonicalVersion(artifact.getVersion());
try {
// generated source bundle is not available at this point in filesystem yet, need to create
// in-memory BundleDescription instead
Dictionary<String, String> manifest = new Hashtable<>();
manifest.put("Manifest-Version", "1.0");
manifest.put("Bundle-ManifestVersion", "2");
String sourceBundleSymbolicName = id + ".source";
manifest.put("Bundle-SymbolicName", sourceBundleSymbolicName);
manifest.put("Bundle-Version", version);
manifest.put("Eclipse-SourceBundle", id + ";version=" + version + ";roots:=\".\"");
StateObjectFactory factory = StateObjectFactory.defaultFactory;
BundleDescription bundleDescription = factory.createBundleDescription(factory.createState(false), manifest, artifact.getLocation().getAbsolutePath(), createId(sourceBundleSymbolicName, version));
bundleDescription.setUserObject(manifest);
actions.add(new BundlesAction(new BundleDescription[] { bundleDescription }) {
@Override
protected void createAdviceFileAdvice(BundleDescription bundleDescription, IPublisherInfo publisherInfo) {
// 367255 p2.inf is not applicable to sources bundles
}
});
} catch (BundleException e) {
throw new RuntimeException(e);
}
return actions;
}
use of org.eclipse.equinox.p2.publisher.eclipse.BundlesAction in project tycho by eclipse.
the class P2GeneratorImpl method getPublisherActions.
@Override
protected List<IPublisherAction> getPublisherActions(IArtifactFacade artifact, List<TargetEnvironment> environments, OptionalResolutionAction optionalAction) {
if (!dependenciesOnly && optionalAction != null) {
throw new IllegalArgumentException();
}
List<IPublisherAction> actions = new ArrayList<>();
String packaging = artifact.getPackagingType();
File location = artifact.getLocation();
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging)) {
if (dependenciesOnly && optionalAction != null) {
actions.add(new BundleDependenciesAction(location, optionalAction));
} else {
actions.add(new BundlesAction(new File[] { location }));
}
} else if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(packaging)) {
Feature feature = new FeatureParser().parse(location);
feature.setLocation(location.getAbsolutePath());
if (dependenciesOnly) {
actions.add(new FeatureDependenciesAction(feature));
} else {
actions.add(new FeaturesAction(new Feature[] { feature }));
}
} else if (PackagingType.TYPE_ECLIPSE_APPLICATION.equals(packaging)) {
String product = new File(location, artifact.getArtifactId() + ".product").getAbsolutePath();
try {
IProductDescriptor productDescriptor = new ProductFile2(product);
if (dependenciesOnly) {
actions.add(new ProductDependenciesAction(productDescriptor));
} else {
actions.add(new ProductAction(product, productDescriptor, null, null));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else if (PackagingType.TYPE_ECLIPSE_UPDATE_SITE.equals(packaging)) {
if (dependenciesOnly) {
actions.add(new SiteDependenciesAction(location, artifact.getArtifactId(), artifact.getVersion()));
} else {
actions.add(new SiteXMLAction(location.toURI(), null));
}
} else if (PackagingType.TYPE_ECLIPSE_REPOSITORY.equals(packaging)) {
for (File productFile : getProductFiles(location)) {
String product = productFile.getAbsolutePath();
IProductDescriptor productDescriptor;
try {
productDescriptor = new ProductFile2(product);
} catch (Exception e) {
throw new RuntimeException("Unable to parse the product file " + product, e);
}
if (dependenciesOnly) {
actions.add(new ProductDependenciesAction(productDescriptor));
}
}
for (File categoryFile : getCategoryFiles(location)) {
CategoryParser cp = new CategoryParser(null);
FileInputStream ins = null;
try {
try {
ins = new FileInputStream(categoryFile);
SiteModel siteModel = cp.parse(ins);
actions.add(new CategoryDependenciesAction(siteModel, artifact.getArtifactId(), artifact.getVersion()));
} finally {
if (ins != null) {
ins.close();
}
}
} catch (Exception e) {
throw new RuntimeException("Unable to read category File", e);
}
}
} else if (PackagingType.TYPE_P2_IU.equals(packaging)) {
actions.add(new AuthoredIUAction(location));
} else if (location.isFile() && location.getName().endsWith(".jar")) {
actions.add(new BundlesAction(new File[] { location }));
} else {
throw new IllegalArgumentException("Unknown type of packaging " + packaging);
}
return actions;
}
use of org.eclipse.equinox.p2.publisher.eclipse.BundlesAction in project tycho by eclipse.
the class TargetPlatformBundlePublisher method attemptToPublishBundle.
/**
* Generate p2 data for an artifact, if the artifact is an OSGI bundle.
* <p>
* The p2 metadata produced by this method is only determined by the artifact, and the function
* used for this conversion must not change (significantly) even in future versions. This is
* required because the resulting metadata can be included in p2 repositories built by Tycho,
* and hence may be propagated into the p2 universe. Therefore the metadata generated by this
* method shall fulfill the basic assumption of p2 that ID+version uniquely identifies a
* unit/artifact. Assuming that distinct bundle artifacts specify unique ID+versions in their
* manifest (which should be mostly true), and the p2 BundlesAction used in the implementation
* doesn't change significantly (which can also be assumed), these conditions specified above a
* met.
* </p>
* <p>
* In slight deviation on the principles described in the previous paragraph, the implementation
* adds GAV properties to the generated IU. This is justified by the potential benefits of
* tracing the origin of artifact.
* </p>
*
* @param mavenArtifact
* An artifact in local file system.
* @return the p2 metadata of the artifact, or <code>null</code> if the artifact isn't a valid
* OSGi bundle.
*/
IInstallableUnit attemptToPublishBundle(IArtifactFacade mavenArtifact) {
if (!isAvailableAsLocalFile(mavenArtifact)) {
// this should have been ensured by the caller
throw new IllegalArgumentException("Not an artifact file: " + mavenArtifact.getLocation());
}
if (isCertainlyNoBundle(mavenArtifact)) {
return null;
}
PublisherRun publisherRun = new PublisherRun(mavenArtifact);
IStatus status = publisherRun.execute();
if (!status.isOK()) {
/**
* If publishing of a jar fails, it is simply not added to the resolution context. The
* BundlesAction already ignores non-bundle JARs silently, so an error status here
* indicates a caught exception that we at least want to see.
*/
logger.warn(StatusTool.collectProblems(status), status.getException());
}
IInstallableUnit publishedIU = publisherRun.getPublishedUnitIfExists();
if (publishedIU != null) {
IArtifactDescriptor publishedDescriptor = publisherRun.getPublishedArtifactDescriptor();
publishedArtifacts.addPublishedArtifact(publishedDescriptor, mavenArtifact);
}
return publishedIU;
}
Aggregations