use of org.eclipse.equinox.p2.publisher.IPublisherInfo in project tycho by eclipse.
the class PublisherActionRunner method newPublisherInfo.
private IPublisherInfo newPublisherInfo(IMetadataRepository metadataOutput, IArtifactRepository artifactsOutput) {
final PublisherInfo publisherInfo = new PublisherInfo();
publisherInfo.setMetadataRepository(metadataOutput);
publisherInfo.setArtifactRepository(artifactsOutput);
publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH);
// TODO publishers only need an IQueryable<IInstallableUnit> -> changing this in p2 would simplify things for us
publisherInfo.setContextMetadataRepository(contextIUs);
// no (known) publisher action needs context artifact repositories
setTargetEnvironments(publisherInfo);
return publisherInfo;
}
use of org.eclipse.equinox.p2.publisher.IPublisherInfo in project tycho by eclipse.
the class AuthoredIUAction method perform.
@Override
@SuppressWarnings("deprecation")
public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) {
File iuFile = new File(iuProject, "p2iu.xml");
if (!iuFile.exists())
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not find the p2iu.xml file in folder " + iuProject);
try {
FileInputStream is = new FileInputStream(iuFile);
InstallableUnitDescription iuDescriptions = new MetadataIO().readOneIU(is);
tweakIU(iuDescriptions);
Set<IInstallableUnit> ius = toIUs(iuDescriptions);
results.addIUs(ius, IPublisherResult.ROOT);
IArtifactRepository repo = info.getArtifactRepository();
boolean artifactReferenced = false;
if (repo != null) {
for (IInstallableUnit iu : ius) {
Collection<IArtifactKey> associatedKeys = iu.getArtifacts();
for (IArtifactKey key : associatedKeys) {
ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, key, null);
processArtifactPropertiesAdvice(iu, ad, info);
ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
ad.setProperty(RepositoryLayoutHelper.PROP_EXTENSION, "zip");
repo.addDescriptor(ad);
artifactReferenced = true;
}
}
}
// and fails in many places. I tried to change the code where the failures were occurring but did not succeed.
if (!artifactReferenced && repo != null) {
IInstallableUnit iu = ((IInstallableUnit) ius.iterator().next());
ArtifactDescriptor ad = (ArtifactDescriptor) PublisherHelper.createArtifactDescriptor(info, new ArtifactKey("binary", "generated_" + iu.getId(), iu.getVersion()), null);
processArtifactPropertiesAdvice(iu, ad, info);
ad.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, IArtifactDescriptor.TYPE_ZIP);
repo.addDescriptor(ad);
artifactReferenced = true;
}
return Status.OK_STATUS;
} catch (IOException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while reading " + iuFile, e);
}
}
use of org.eclipse.equinox.p2.publisher.IPublisherInfo in project tycho by eclipse.
the class BundleDependenciesAction method createAdviceFileAdvice.
@Override
protected void createAdviceFileAdvice(BundleDescription bundleDescription, IPublisherInfo publisherInfo) {
String location = bundleDescription.getLocation();
if (location == null)
return;
File adviceFile = new File(location, AdviceFileAdvice.BUNDLE_ADVICE_FILE.toString());
if (!adviceFile.canRead()) {
return;
}
Map<String, String> advice = new LinkedHashMap<>();
try {
InputStream is = new BufferedInputStream(new FileInputStream(adviceFile));
try {
Properties props = new Properties();
props.load(is);
for (Map.Entry<Object, Object> p : props.entrySet()) {
advice.put((String) p.getKey(), (String) p.getValue());
}
} finally {
try {
is.close();
} catch (IOException secondary) {
// secondary exception
}
}
} catch (IOException e) {
// TODO log
return;
}
final String symbolicName = bundleDescription.getSymbolicName();
final Version bundleVersion = PublisherHelper.fromOSGiVersion(bundleDescription.getVersion());
AdviceFileParser parser = new AdviceFileParser(symbolicName, bundleVersion, advice) {
@Override
protected IRequirement createRequirement(String namespace, String name, VersionRange range, String filter, boolean optional, boolean multiple, boolean greedy) {
if (optionalAction == OptionalResolutionAction.OPTIONAL) {
return super.createRequirement(namespace, name, range, filter, optional, multiple, greedy);
}
return BundleDependenciesAction.this.createRequirement(namespace, name, range, filter, optional, multiple, greedy);
}
};
try {
parser.parse();
} catch (Exception e) {
// TODO log
return;
}
final IProvidedCapability[] provided = parser.getProvidedCapabilities();
final IRequirement[] required = parser.getRequiredCapabilities();
if (provided == null && required == null) {
return;
}
publisherInfo.addAdvice(new ICapabilityAdvice() {
@Override
public boolean isApplicable(String configSpec, boolean includeDefault, String id, Version version) {
return symbolicName.equals(id) && bundleVersion.equals(version);
}
@Override
public IRequirement[] getRequiredCapabilities(InstallableUnitDescription iu) {
return required;
}
@Override
public IProvidedCapability[] getProvidedCapabilities(InstallableUnitDescription iu) {
return provided;
}
@Override
public IRequirement[] getMetaRequiredCapabilities(InstallableUnitDescription iu) {
return null;
}
});
}
use of org.eclipse.equinox.p2.publisher.IPublisherInfo in project tycho by eclipse.
the class SiteDependenciesAction method perform.
@Override
public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor) {
try {
// don't need transport to read local site.xml
Transport transport = null;
updateSite = UpdateSite.load(location.toURI(), transport, monitor);
} catch (ProvisionException e) {
return new Status(IStatus.ERROR, Activator.ID, "Error generating site xml action.", e);
}
return super.perform(publisherInfo, results, monitor);
}
use of org.eclipse.equinox.p2.publisher.IPublisherInfo 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;
}
Aggregations