diff options
author | John Arthorne | 2007-09-30 18:11:02 +0000 |
---|---|---|
committer | John Arthorne | 2007-09-30 18:11:02 +0000 |
commit | 2ccb446cc885495686cc9eb430c4a98031b3cfc5 (patch) | |
tree | 207e30d5f61856ece926ed3548297aa3958132c9 /bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator | |
parent | c4f6662ccd02bb75cba95a6ae56a2da38c6cadde (diff) | |
download | rt.equinox.p2-2ccb446cc885495686cc9eb430c4a98031b3cfc5.tar.gz rt.equinox.p2-2ccb446cc885495686cc9eb430c4a98031b3cfc5.tar.xz rt.equinox.p2-2ccb446cc885495686cc9eb430c4a98031b3cfc5.zip |
Renamed prov bundles to p2
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator')
10 files changed, 2043 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/BundleDescriptionFactory.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/BundleDescriptionFactory.java new file mode 100644 index 000000000..0f0c07611 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/BundleDescriptionFactory.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import org.eclipse.core.runtime.Path; +import org.eclipse.osgi.service.resolver.*; +import org.eclipse.osgi.util.ManifestElement; +import org.osgi.framework.BundleException; + +public class BundleDescriptionFactory { + static final String DIR = "dir"; + static final String JAR = "jar"; + static String BUNDLE_FILE_KEY = "eclipse.prov.bundle.format"; + + StateObjectFactory factory; + State state; + + public BundleDescriptionFactory(StateObjectFactory factory, State state) { + this.factory = factory; + this.state = state; + //TODO find a state and a factory when not provided + } + + public BundleDescription getBundleDescription(File bundleLocation) { + Dictionary manifest = loadManifest(bundleLocation); + if (manifest == null) + return null; + return getBundleDescription(manifest, bundleLocation); + } + + public BundleDescription getBundleDescription(InputStream manifestStream, File bundleLocation) { + Hashtable entries = new Hashtable(); + try { + ManifestElement.parseBundleManifest(manifestStream, entries); + return getBundleDescription(entries, bundleLocation); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (BundleException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + public Dictionary loadManifest(File bundleLocation) { + InputStream manifestStream = null; + ZipFile jarFile = null; + try { + if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && bundleLocation.isFile()) { //$NON-NLS-1$ + jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ); + ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME); + if (manifestEntry != null) { + manifestStream = jarFile.getInputStream(manifestEntry); + } + } else { + manifestStream = new BufferedInputStream(new FileInputStream(new File(bundleLocation, JarFile.MANIFEST_NAME))); + } + } catch (IOException e) { + //ignore + } + + if (manifestStream == null) + return null; + try { + Dictionary manifest = manifestToProperties(new Manifest(manifestStream).getMainAttributes()); + // remember the format of the bundle as we found it + manifest.put(BUNDLE_FILE_KEY, bundleLocation.isDirectory() ? DIR : JAR); + return manifest; + } catch (IOException ioe) { + return null; + } finally { + try { + manifestStream.close(); + } catch (IOException e1) { + //Ignore + } + try { + if (jarFile != null) + jarFile.close(); + } catch (IOException e2) { + //Ignore + } + } + } + + private Properties manifestToProperties(Attributes attributes) { + Properties result = new Properties(); + for (Iterator i = attributes.keySet().iterator(); i.hasNext();) { + Attributes.Name key = (Attributes.Name) i.next(); + result.put(key.toString(), attributes.get(key)); + } + return result; + } + + public BundleDescription getBundleDescription(Dictionary enhancedManifest, File bundleLocation) { + try { + BundleDescription descriptor = factory.createBundleDescription(state, enhancedManifest, bundleLocation != null ? bundleLocation.getAbsolutePath() : null, 1); //TODO Do we need to have a real bundle id + descriptor.setUserObject(enhancedManifest); + return descriptor; + } catch (BundleException e) { + // IStatus status = new Status(IStatus.WARNING, IPDEBuildConstants.PI_PDEBUILD, EXCEPTION_STATE_PROBLEM, NLS.bind(Messages.exception_stateAddition, enhancedManifest.get(Constants.BUNDLE_NAME)), e); + // BundleHelper.getDefault().getLog().log(status); + System.err.println("An error has occured while adding the bundle" + bundleLocation != null ? bundleLocation.getAbsoluteFile() : null); + return null; + } + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/EclipseInstallGeneratorInfoProvider.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/EclipseInstallGeneratorInfoProvider.java new file mode 100644 index 000000000..4117eeda1 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/EclipseInstallGeneratorInfoProvider.java @@ -0,0 +1,358 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +import java.io.File; +import java.io.IOException; +import java.util.*; +import org.eclipse.equinox.frameworkadmin.*; +import org.eclipse.equinox.internal.prov.metadata.generator.Activator; +import org.eclipse.equinox.prov.artifact.repository.IWritableArtifactRepository; +import org.eclipse.equinox.prov.core.helpers.ServiceHelper; +import org.eclipse.equinox.prov.metadata.IInstallableUnit; +import org.eclipse.equinox.prov.metadata.InstallableUnit; +import org.eclipse.equinox.prov.metadata.repository.IWritableMetadataRepository; +import org.eclipse.osgi.service.environment.EnvironmentInfo; +import org.osgi.framework.*; +import org.osgi.util.tracker.ServiceTracker; + +public class EclipseInstallGeneratorInfoProvider implements IGeneratorInfo { + private static final String ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR = "org.eclipse.equinox.simpleconfigurator"; + + private final static String FILTER_OBJECTCLASS = "(" + Constants.OBJECTCLASS + "=" + FrameworkAdmin.class.getName() + ")"; + private final static String filterFwName = "(" + FrameworkAdmin.SERVICE_PROP_KEY_FW_NAME + "=Equinox)"; + //String filterFwVersion = "(" + FrameworkAdmin.SERVICE_PROP_KEY_FW_VERSION + "=" + props.getProperty("equinox.fw.version") + ")"; + private final static String filterLauncherName = "(" + FrameworkAdmin.SERVICE_PROP_KEY_LAUNCHER_NAME + "=Eclipse.exe)"; + //String filterLauncherVersion = "(" + FrameworkAdmin.SERVICE_PROP_KEY_LAUNCHER_VERSION + "=" + props.getProperty("equinox.launcher.version") + ")"; + private final static String frameworkAdminFillter = "(&" + FILTER_OBJECTCLASS + filterFwName + filterLauncherName + ")"; + + private ServiceTracker frameworkAdminTracker; + private Manipulator manipulator; + private ArrayList defaultIUs; + + private File baseLocation; + private File[] bundleLocations; + private File featuresLocation; + private File configLocation; + private File executableLocation; + private String flavor; + private String rootId; + private String rootVersion; + private boolean publishArtifacts = false; + private boolean publishArtifactRepo = false; + private boolean append = false; + private String[][] mappingRules; + private boolean addDefaultIUs = true; + private IWritableMetadataRepository metadataRepository; + private IWritableArtifactRepository artifactRepository; + private static String os; + + public EclipseInstallGeneratorInfoProvider() { + super(); + } + + /** + * Returns a default name for the executable. + */ + public static String getDefaultExecutableName() { + String theOS = os; + if (theOS == null) { + EnvironmentInfo info = (EnvironmentInfo) ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName()); + theOS = info.getOS(); + } + if (theOS.equalsIgnoreCase("win32")) //$NON-NLS-1$ + return "eclipse.exe"; //$NON-NLS-1$ + //FIXME Is this a reasonable default for all non-Windows platforms? + return "eclipse"; //$NON-NLS-1$ + } + + public void initialize(File base) { + initialize(base, new File(base, "configuration"), new File(base, getDefaultExecutableName()), new File[] {new File(base, "plugins")}, new File(base, "features")); + } + + public void initialize(File base, File config, File executable, File[] bundleLocations, File features) { + // TODO + if (base == null || !base.exists()) + throw new RuntimeException("Source directory is invalid: " + base.getAbsolutePath()); + this.baseLocation = base; + if (config == null || config.exists()) + this.configLocation = config; + if (executable == null || executable.exists()) + this.executableLocation = executable; + this.bundleLocations = bundleLocations; + this.featuresLocation = features; + + expandBundleLocations(); + + // if the config or exe are not set then we cannot be generating any data related to the config so + // don't bother setting up the manipulator. In fact, the manipulator will likely be invalid without + // these locations. + if (configLocation == null || executableLocation == null) + return; + + createFrameworkManipulator(); + + LauncherData launcherData = manipulator.getLauncherData(); + launcherData.setFwPersistentDataLocation(configLocation, true); + launcherData.setLauncher(executableLocation); + try { + manipulator.load(); + } catch (IllegalStateException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } catch (FrameworkAdminRuntimeException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + } + + private void expandBundleLocations() { + ArrayList result = new ArrayList(); + for (int i = 0; i < bundleLocations.length; i++) { + File location = bundleLocations[i]; + if (location.isDirectory()) { + File[] list = location.listFiles(); + for (int j = 0; j < list.length; j++) + result.add(list[j]); + } else { + result.add(location); + } + } + bundleLocations = (File[]) result.toArray(new File[result.size()]); + } + + public ArrayList getDefaultIUs(Set ius) { + if (defaultIUs != null) + return defaultIUs; + defaultIUs = new ArrayList(5); + if (addDefaultIUs) { + defaultIUs.addAll(createLauncherBundleInfo(ius)); + defaultIUs.add(createLauncher()); + defaultIUs.add(createSimpleConfigurator()); + // defaultIUs.add(createDefaultConfigurationBundleInfo()); + // defaultIUs.add(createDefaultUnconfigurationBundleInfo()); + } + return defaultIUs; + } + + protected GeneratorBundleInfo createDefaultConfigurationBundleInfo() { + GeneratorBundleInfo result = new GeneratorBundleInfo(); + result.setSymbolicName("defaultConfigure"); + result.setVersion("1.0.0"); + result.setStartLevel(4); + result.setSpecialConfigCommands("manipulator.getConfigData().addBundle(bundleToInstall);"); + return result; + } + + protected GeneratorBundleInfo createDefaultUnconfigurationBundleInfo() { + GeneratorBundleInfo result = new GeneratorBundleInfo(); + result.setSymbolicName("defaultUnconfigure"); + result.setVersion("1.0.0"); + result.setSpecialConfigCommands("manipulator.getConfigData().removeBundle(bundleToRemove);"); + return result; + } + + /** + * Obtains the framework manipulator instance. Throws an exception + * if it could not be created. + */ + private void createFrameworkManipulator() { + FrameworkAdmin admin = getFrameworkAdmin(); + if (admin == null) + throw new RuntimeException("Framework admin service not found"); //$NON-NLS-1$ + manipulator = admin.getManipulator(); + if (manipulator == null) + throw new RuntimeException("Framework manipulator not found"); //$NON-NLS-1$ + } + + private FrameworkAdmin getFrameworkAdmin() { + if (frameworkAdminTracker == null) { + try { + Filter filter = Activator.getContext().createFilter(frameworkAdminFillter); + frameworkAdminTracker = new ServiceTracker(Activator.getContext(), filter, null); + frameworkAdminTracker.open(); + } catch (InvalidSyntaxException e) { + // never happens + e.printStackTrace(); + } + } + // try { + // frameworkAdminTracker.waitForService(500); + // } catch (InterruptedException e) { + // // ignore + // } + return (FrameworkAdmin) frameworkAdminTracker.getService(); + } + + public ConfigData getConfigData() { + return manipulator == null ? null : manipulator.getConfigData(); + } + + public LauncherData getLauncherData() { + return manipulator == null ? null : manipulator.getLauncherData(); + } + + private Collection createLauncherBundleInfo(Set ius) { + Collection result = new HashSet(); + Collection launchers = getIUs(ius, "org.eclipse.equinox.launcher."); + for (Iterator iterator = launchers.iterator(); iterator.hasNext();) { + InstallableUnit object = (InstallableUnit) iterator.next(); + GeneratorBundleInfo temp = new GeneratorBundleInfo(); + temp.setSymbolicName(object.getId()); + temp.setVersion(object.getVersion().toString()); + temp.setSpecialConfigCommands("manipulator.getLauncherData().addProgramArg('--launcher.library');manipulator.getLauncherData().addProgramArg(artifact);"); + result.add(temp); + } + return result; + } + + private Collection getIUs(Set ius, String prefix) { + Set result = new HashSet(); + for (Iterator iterator = ius.iterator(); iterator.hasNext();) { + IInstallableUnit tmp = (IInstallableUnit) iterator.next(); + if (tmp.getId().startsWith(prefix)) + result.add(tmp); + } + return result; + } + + private GeneratorBundleInfo createLauncher() { + GeneratorBundleInfo result = new GeneratorBundleInfo(); + result.setSymbolicName("org.eclipse.equinox.launcher"); + result.setVersion("0.0.0"); + //result.setSpecialConfigCommands("manipulator.addProgramArgument('-startup'); manipulator.addProgramArgument(artifact);"); + result.setSpecialConfigCommands("manipulator.getLauncherData().addProgramArg('-startup');manipulator.getLauncherData().addProgramArg(artifact);"); + return result; + } + + private GeneratorBundleInfo createSimpleConfigurator() { + GeneratorBundleInfo result = new GeneratorBundleInfo(); + result.setSymbolicName(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR); + result.setVersion("0.0.0"); + result.setStartLevel(1); + result.setMarkedAsStarted(true); + result.setSpecialConfigCommands("manipulator.getLauncherData().addJvmArg('-Dorg.eclipse.equinox.simpleconfigurator.useReference=true');"); + return result; + } + + public File getBaseLocation() { + return baseLocation; + } + + public File[] getBundleLocations() { + return bundleLocations; + } + + public File getFeaturesLocation() { + return featuresLocation; + } + + public File getConfigurationLocation() { + return configLocation; + } + + public File getExecutableLocation() { + return executableLocation; + } + + public boolean publishArtifacts() { + return publishArtifacts; + } + + public boolean addDefaultIUs() { + return addDefaultIUs; + } + + public boolean publishArtifactRepository() { + return publishArtifactRepo; + } + + public String getRootId() { + return rootId; + } + + public String getRootVersion() { + if (rootVersion == null) + return "0.0.0"; //$NON-NLS-1$ + return rootVersion; + } + + public String getFlavor() { + return flavor; + } + + public void setMetadataRepository(IWritableMetadataRepository value) { + metadataRepository = value; + } + + public void setArtifactRepository(IWritableArtifactRepository value) { + artifactRepository = value; + } + + public void setFlavor(String value) { + flavor = value; + } + + public void setRootId(String value) { + rootId = value; + } + + public void setRootVersion(String value) { + rootVersion = value; + } + + public void setPublishArtifacts(boolean value) { + publishArtifacts = value; + } + + public void setPublishArtifactRepository(boolean value) { + publishArtifactRepo = value; + } + + public boolean append() { + return append; + } + + public String[][] getMappingRules() { + return mappingRules; + } + + public void setMappingRules(String[][] value) { + mappingRules = value; + } + + public void setExecutableLocation(String value) { + executableLocation = new File(value); + } + + public void setAppend(boolean value) { + append = value; + } + + public void setAddDefaultIUs(boolean value) { + addDefaultIUs = value; + } + + public IWritableArtifactRepository getArtifactRepository() { + return artifactRepository; + } + + public IWritableMetadataRepository getMetadataRepository() { + return metadataRepository; + } + + public void setOS(String os) { + this.os = os; + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/Feature.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/Feature.java new file mode 100644 index 000000000..289e1243c --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/Feature.java @@ -0,0 +1,271 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +import java.util.ArrayList; + +/** + * + * Feature information + */ +public class Feature implements IPlatformEntry { + + private String id; + private String version; + private String label; + private String image; + + private URLEntry description; + private URLEntry license; + private URLEntry copyright; + + private String installHandler; + private String installHandlerURL; + private String installHandlerLibrary; + + private URLEntry updateSite; + private ArrayList discoverySites; + + private ArrayList entries; + private String name; + private String providerName; + private String os; + private String ws; + private String arch; + private String nl; + + public Feature(String id, String version) { + if (id == null) + throw new IllegalArgumentException(); + this.id = id; + this.version = version; + } + + public void addEntry(FeatureEntry plugin) { + if (entries == null) + entries = new ArrayList(); + entries.add(plugin); + } + + public FeatureEntry[] getEntries() { + return (FeatureEntry[]) entries.toArray(new FeatureEntry[entries.size()]); + } + + public void setLabel(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + + public void setDescription(String description) { + if (this.description == null) + this.description = new URLEntry(); + this.description.setAnnotation(description); + } + + public String getDescription() { + if (description != null) + return description.getAnnotation(); + return null; + } + + public String getDescriptionURL() { + if (description != null) + return description.getURL(); + return null; + } + + public void setDescriptionURL(String descriptionURL) { + if (this.description == null) + this.description = new URLEntry(); + this.description.setURL(descriptionURL); + } + + public String getName() { + return name; + } + + public String getProviderName() { + return providerName; + } + + public void setProviderName(String value) { + providerName = value; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getId() { + return id; + } + + public void setLicenseURL(String licenseURL) { + if (this.license == null) + this.license = new URLEntry(); + this.license.setURL(licenseURL); + } + + public String getLicenseURL() { + if (license != null) + return license.getURL(); + return null; + } + + public void setLicense(String license) { + if (this.license == null) + this.license = new URLEntry(); + this.license.setAnnotation(license); + } + + public String getLicense() { + if (license != null) + return license.getAnnotation(); + return null; + } + + public void setCopyright(String copyright) { + if (this.copyright == null) + this.copyright = new URLEntry(); + this.copyright.setAnnotation(copyright); + } + + public void setCopyrightURL(String copyrightURL) { + if (this.copyright == null) + this.copyright = new URLEntry(); + this.copyright.setURL(copyrightURL); + } + + public String getCopyright() { + if (copyright != null) + return copyright.getAnnotation(); + return null; + } + + public String getCopyrightURL() { + if (copyright != null) + return copyright.getURL(); + return null; + } + + public void setInstallHandler(String installHandler) { + this.installHandler = installHandler; + } + + public void setInstallHandlerLibrary(String installHandlerLibrary) { + this.installHandlerLibrary = installHandlerLibrary; + } + + public void setInstallHandlerURL(String installHandlerURL) { + this.installHandlerURL = installHandlerURL; + } + + public String getInstallHandler() { + return installHandler; + } + + public String getInstallHandlerLibrary() { + return installHandlerLibrary; + } + + public String getInstallHandlerURL() { + return installHandlerURL; + } + + public void setUpdateSiteLabel(String updateSiteLabel) { + if (this.updateSite == null) + this.updateSite = new URLEntry(); + this.updateSite.setAnnotation(updateSiteLabel); + } + + public void setUpdateSiteURL(String updateSiteURL) { + if (this.updateSite == null) + this.updateSite = new URLEntry(); + this.updateSite.setURL(updateSiteURL); + } + + public String getUpdateSiteLabel() { + if (updateSite != null) + return updateSite.getAnnotation(); + return null; + } + + public String getUpdateSiteURL() { + if (updateSite != null) + return updateSite.getURL(); + return null; + } + + public void addDiscoverySite(String label, String url) { + if (label == null && url == null) + return; + + if (this.discoverySites == null) + this.discoverySites = new ArrayList(); + + URLEntry entry = new URLEntry(url, label); + this.discoverySites.add(entry); + } + + public URLEntry[] getDiscoverySites() { + if (discoverySites == null) + return new URLEntry[0]; + return (URLEntry[]) discoverySites.toArray(new URLEntry[discoverySites.size()]); + } + + public void setEnvironment(String os, String ws, String arch, String nl) { + this.os = os; + this.ws = ws; + this.arch = arch; + this.nl = nl; + } + + public String getOS() { + return os; + } + + public String getWS() { + return ws; + } + + public String getArch() { + return arch; + } + + public String getNL() { + return nl; + } + + public void setURL(String value) { + } + + /** + * For debugging purposes only. + */ + public String toString() { + return "Feature " + id + " version: " + version; //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/FeatureEntry.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/FeatureEntry.java new file mode 100644 index 000000000..b7bdfd373 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/FeatureEntry.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +/** + */ +public class FeatureEntry implements IPlatformEntry { + private String id; + private String version; + private String url; + private String os; + private String ws; + private String arch; + private String nl; + private String match; + private boolean isPlugin; + private boolean isFragment = false; + private boolean isRequires = false; + private boolean unpack = true; + private boolean optional = false; + + /** + * Temporary field to add provisioning filters to features + */ + private String filter; + + public static FeatureEntry createRequires(String id, String version, String match, String filter, boolean isPlugin) { + FeatureEntry result = new FeatureEntry(id, version, isPlugin); + result.match = match; + result.isRequires = true; + if (filter != null) + result.setFilter(filter); + return result; + } + + public FeatureEntry(String id, String version, boolean isPlugin) { + this.id = id; + this.version = version; + this.isPlugin = isPlugin; + } + + public String getURL() { + return url; + } + + public void setURL(String value) { + url = value; + } + + public String getId() { + return id; + } + + public String getVersion() { + return version; + } + + public boolean isPlugin() { + return isPlugin; + } + + public boolean isRequires() { + return isRequires; + } + + public boolean isFragment() { + return isFragment; + } + + public String toString() { + StringBuffer result = new StringBuffer(); + + result.append(isPlugin ? "Plugin: " : "Feature: "); //$NON-NLS-1$ + result.append(id != null ? id.toString() : ""); //$NON-NLS-1$ + result.append(version != null ? " " + version.toString() : ""); //$NON-NLS-1$ //$NON-NLS-2$ + return result.toString(); + } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final FeatureEntry other = (FeatureEntry) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + public void setEnvironment(String os, String ws, String arch, String nl) { + this.os = os; + this.ws = ws; + this.arch = arch; + this.nl = nl; + } + + public void setFragment(boolean value) { + isFragment = value; + } + + public void setUnpack(boolean value) { + unpack = value; + } + + public boolean isUnpack() { + return unpack; + } + + public void setOptional(boolean value) { + optional = value; + } + + /** + * Temporary method to add provisioning filters to features + */ + public void setFilter(String filter) { + this.filter = filter; + + } + + /** + * Temporary method to add provisioning filters to features + */ + public String getFilter() { + return filter; + } + + public String getMatch() { + return match; + } + + public boolean isOptional() { + return optional; + } + + public String getOS() { + return os; + } + + public String getWS() { + return ws; + } + + public String getArch() { + return arch; + } + + public String getNL() { + return nl; + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/Generator.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/Generator.java new file mode 100644 index 000000000..b2f85fe99 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/Generator.java @@ -0,0 +1,338 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +import java.io.*; +import java.net.MalformedURLException; +import java.util.*; +import java.util.Map.Entry; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.frameworkadmin.*; +import org.eclipse.equinox.internal.prov.metadata.generator.Activator; +import org.eclipse.equinox.internal.prov.metadata.generator.features.FeatureParser; +import org.eclipse.equinox.prov.artifact.repository.IArtifactDescriptor; +import org.eclipse.equinox.prov.artifact.repository.IWritableArtifactRepository; +import org.eclipse.equinox.prov.core.helpers.FileUtils; +import org.eclipse.equinox.prov.core.helpers.ServiceHelper; +import org.eclipse.equinox.prov.metadata.*; +import org.eclipse.osgi.service.resolver.*; +import org.osgi.framework.Version; + +public class Generator { + + private static final Version ECLIPSE_TOUCHPOINT_VERSION = new Version(1, 0, 0); + private static final String ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR = "org.eclipse.equinox.simpleconfigurator"; + private static final String ORG_ECLIPSE_UPDATE_CONFIGURATOR = "org.eclipse.update.configurator"; + // private static String[][] defaultMappingRules = new String[][] { {"(& (namespace=eclipse) (classifier=feature))", "${repoUrl}/feature/${id}_${version}"}, {"(& (namespace=eclipse) (classifier=plugin))", "${repoUrl}/plugin/${id}_${version}"}, {"(& (namespace=eclipse) (classifier=native))", "${repoUrl}/native/${id}_${version}"}}; + + private StateObjectFactory stateObjectFactory; + private IGeneratorInfo info; + + public Generator(IGeneratorInfo infoProvider) { + this.info = infoProvider; + // TODO need to figure a better way of configuring the generator... + PlatformAdmin platformAdmin = (PlatformAdmin) ServiceHelper.getService(Activator.getContext(), PlatformAdmin.class.getName()); + if (platformAdmin != null) { + stateObjectFactory = platformAdmin.getFactory(); + } + } + + public IStatus generate() { + Set ius = new HashSet(); + + Feature[] features = getFeatures(info.getFeaturesLocation()); + generateFeatureIUs(features, ius); + + BundleDescription[] bundles = getBundleDescriptions(info.getBundleLocations()); + generateBundleIUs(bundles, ius, info.getArtifactRepository()); + + generateNativeIUs(info.getExecutableLocation(), ius, info.getArtifactRepository()); + + generateConfigIUs(info.getConfigData() == null ? null : info.getConfigData().getBundles(), ius); + + if (info.addDefaultIUs()) + generateDefaultConfigIU(ius, info); + + generateRootIU(ius, info.getRootId(), info.getRootVersion()); + + // persistence.setMappingRules(info.getMappingRules() == null ? defaultMappingRules : info.getMappingRules()); + // if (info.publishArtifacts() || info.publishArtifactRepository()) { + // persistence.saveArtifactRepository(); + // } + info.getMetadataRepository().addInstallableUnits((InstallableUnit[]) ius.toArray(new InstallableUnit[ius.size()])); + + return Status.OK_STATUS; + } + + private void generateDefaultConfigIU(Set ius, IGeneratorInfo info) { + // TODO this is a bit of a hack. We need to have the default IU fragment generated with code that configures + // and unconfigures. the Generator should be decoupled from any particular provider but it is not clear + // that we should add the create* methods to IGeneratorInfo... + // MockBundleDescription bd1 = new MockBundleDescription("defaultConfigure"); + // MockBundleDescription bd2 = new MockBundleDescription("defaultUnconfigure"); + EclipseInstallGeneratorInfoProvider provider = (EclipseInstallGeneratorInfoProvider) info; + ius.add(MetadataGeneratorHelper.createEclipseDefaultConfigurationUnit(provider.createDefaultConfigurationBundleInfo(), provider.createDefaultUnconfigurationBundleInfo(), info.getFlavor())); + } + + private Feature[] getFeatures(File folder) { + if (folder == null || !folder.exists()) + return new Feature[0]; + File[] locations = folder.listFiles(); + ArrayList result = new ArrayList(locations.length); + for (int i = 0; i < locations.length; i++) { + FeatureParser parser = new FeatureParser(); + try { + result.add(parser.parse(new File(locations[i], "feature.xml").toURL())); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + return (Feature[]) result.toArray(new Feature[result.size()]); + } + + protected void generateFeatureIUs(Feature[] features, Set resultantIUs) { + for (int i = 0; i < features.length; i++) { + Feature feature = features[i]; + resultantIUs.add(MetadataGeneratorHelper.createGroupIU(feature)); + } + } + + protected BundleDescription[] getBundleDescriptions(File[] bundleLocations) { + boolean addSimpleConfigurator = false; + for (int i = 0; i < bundleLocations.length; i++) { + addSimpleConfigurator = bundleLocations[i].toString().indexOf(ORG_ECLIPSE_UPDATE_CONFIGURATOR) > 0; + if (addSimpleConfigurator) + break; + } + BundleDescription[] result = new BundleDescription[bundleLocations.length + (addSimpleConfigurator ? 1 : 0)]; + BundleDescriptionFactory factory = getBundleFactory(); + for (int i = 0; i < bundleLocations.length; i++) + result[i] = factory.getBundleDescription(bundleLocations[i]); + if (addSimpleConfigurator) { + //Add simple configurator to the list of bundles + try { + File location = new File(FileLocator.toFileURL(Activator.getContext().getBundle().getEntry(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR + ".jar")).getFile()); + result[result.length - 1] = factory.getBundleDescription(location); + } catch (IOException e) { + e.printStackTrace(); + } + } + return result; + } + + protected BundleDescriptionFactory getBundleFactory() { + BundleDescriptionFactory factory = new BundleDescriptionFactory(stateObjectFactory, null); + return factory; + } + + protected void generateRootIU(Set resultantIUs, String rootIUId, String rootIUVersion) { + if (rootIUId == null) + return; + resultantIUs.add(createTopLevelIU(resultantIUs, rootIUId, rootIUVersion)); + } + + protected void generateNativeIUs(File executableLocation, Set resultantIUs, IWritableArtifactRepository destination) { + if (executableLocation == null) + return; + HashSet newArtifacts = new HashSet(); + + //generate data for JRE + File jreLocation = new File(executableLocation.getParentFile(), "jre"); + MetadataGeneratorHelper.createJREData(jreLocation, resultantIUs, newArtifacts); + publishArtifact(jreLocation, newArtifacts); + newArtifacts.clear(); + + //generate data for executable launcher + MetadataGeneratorHelper.createLauncherData(executableLocation, info.getFlavor(), resultantIUs, newArtifacts); + publishArtifact(executableLocation, newArtifacts); + } + + private void publishArtifact(File location, Set artifacts) { + if (!info.publishArtifacts() || artifacts.isEmpty()) + return; + for (Iterator i = artifacts.iterator(); i.hasNext();) { + IArtifactDescriptor descriptor = (IArtifactDescriptor) i.next(); + publishArtifact(descriptor, location, info.getArtifactRepository(), false, true); + } + } + + protected void generateConfigIUs(BundleInfo[] infos, Set resultantIUs) { + if (infos == null) + return; + for (int i = 0; i < infos.length; i++) { + GeneratorBundleInfo bundle = new GeneratorBundleInfo(infos[i]); + if (bundle.getSymbolicName().equals(ORG_ECLIPSE_UPDATE_CONFIGURATOR)) { + bundle.setStartLevel(BundleInfo.NO_LEVEL); + bundle.setMarkedAsStarted(false); + bundle.setSpecialConfigCommands("manipulator.getLauncherData().addJvmArg('-Dorg.eclipse.update.reconcile=false');"); + } + if (bundle.getSymbolicName().equals(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR)) { + bundle.setSpecialConfigCommands("manipulator.getLauncherData().addJvmArg('-Dorg.eclipse.equinox.simpleconfigurator.useReference=true');"); + } + IInstallableUnit cu = MetadataGeneratorHelper.createEclipseConfigurationUnit(bundle.getSymbolicName(), new Version(bundle.getVersion()), false, bundle, info.getFlavor()); + if (cu != null) + resultantIUs.add(cu); + } + + if (info.addDefaultIUs()) { + for (Iterator iterator = info.getDefaultIUs(resultantIUs).iterator(); iterator.hasNext();) { + GeneratorBundleInfo bundle = (GeneratorBundleInfo) iterator.next(); + InstallableUnit configuredIU = getIU(resultantIUs, bundle.getSymbolicName()); + if (configuredIU != null) + bundle.setVersion(configuredIU.getVersion().toString()); + IInstallableUnit cu = MetadataGeneratorHelper.createEclipseConfigurationUnit(bundle.getSymbolicName(), new Version(bundle.getVersion()), false, bundle, info.getFlavor()); + if (cu != null) + resultantIUs.add(cu); + } + } + } + + private InstallableUnit getIU(Set ius, String id) { + for (Iterator iterator = ius.iterator(); iterator.hasNext();) { + InstallableUnit tmp = (InstallableUnit) iterator.next(); + if (tmp.getId().equals(id)) + return tmp; + } + return null; + } + + protected void generateBundleIUs(BundleDescription[] bundles, Set resultantIUs, IWritableArtifactRepository destination) { + for (int i = 0; i < bundles.length; i++) { + BundleDescription bd = bundles[i]; + // A bundle may be null if the associated plug-in does not have a manifest file - + // for example, org.eclipse.jdt.launching.j9 + if (bd != null) { + String format = (String) ((Dictionary) bd.getUserObject()).get(BundleDescriptionFactory.BUNDLE_FILE_KEY); + boolean isDir = format.equals(BundleDescriptionFactory.DIR) ? true : false; + IArtifactKey key = MetadataGeneratorHelper.createEclipseArtifactKey(bd.getSymbolicName(), bd.getVersion().toString()); + IArtifactDescriptor ad = MetadataGeneratorHelper.createArtifactDescriptor(key, new File(bd.getLocation()), true, false); + if (info.publishArtifacts()) + // publishArtifact(info.getArtifactRepoLocation().getParentFile(), new File(bd.getLocation()), key.getClassifier(), key.getId() + "_" + key.getVersion().toString(), !isDir, true); + publishArtifact(ad, new File(bd.getLocation()), destination, !isDir, true); + else + destination.addDescriptor(ad); + + IInstallableUnit iu = MetadataGeneratorHelper.createEclipseIU(bd, (Map) bd.getUserObject(), isDir, key); + resultantIUs.add(iu); + } + } + } + + protected InstallableUnit createTopLevelIU(Set resultantIUs, String configurationIdentification, String configurationVersion) { + InstallableUnit iu = new InstallableUnit(); + iu.setSingleton(true); + iu.setId(configurationIdentification); + iu.setVersion(new Version(configurationVersion)); + + ArrayList reqsConfigurationUnits = new ArrayList(resultantIUs.size()); + for (Iterator iterator = resultantIUs.iterator(); iterator.hasNext();) { + InstallableUnit tmp = (InstallableUnit) iterator.next(); + reqsConfigurationUnits.add(RequiredCapability.createRequiredCapabilityForName(tmp.getId(), new VersionRange(tmp.getVersion(), true, tmp.getVersion(), true), false)); + } + iu.setRequiredCapabilities((RequiredCapability[]) reqsConfigurationUnits.toArray(new RequiredCapability[reqsConfigurationUnits.size()])); + iu.setApplicabilityFilter(""); + iu.setArtifacts(new IArtifactKey[0]); + + iu.setProperty("lineUp", "true"); + iu.setProperty(IInstallableUnitConstants.UPDATE_FROM, configurationIdentification); + iu.setProperty(IInstallableUnitConstants.UPDATE_RANGE, VersionRange.emptyRange.toString()); + ProvidedCapability groupCapability = new ProvidedCapability(IInstallableUnit.IU_KIND_NAMESPACE, "group", new Version("1.0.0")); + iu.setCapabilities(new ProvidedCapability[] {groupCapability}); + iu.setTouchpointType(new TouchpointType("eclipse", ECLIPSE_TOUCHPOINT_VERSION)); + Map touchpointData = new HashMap(); + + String configurationData = ""; + + ConfigData configData = info.getConfigData(); + if (configData != null) { + for (Iterator iterator = configData.getFwDependentProps().entrySet().iterator(); iterator.hasNext();) { + Entry aProperty = (Entry) iterator.next(); + String key = ((String) aProperty.getKey()); + if (key.equals("osgi.frameworkClassPath") || key.equals("osgi.framework") || key.equals("osgi.bundles") || key.equals("eof")) + continue; + configurationData += "manipulator.getConfigData().setFwDependentProp('" + key + "', '" + ((String) aProperty.getValue()) + "');"; + } + for (Iterator iterator = configData.getFwIndependentProps().entrySet().iterator(); iterator.hasNext();) { + Entry aProperty = (Entry) iterator.next(); + String key = ((String) aProperty.getKey()); + if (key.equals("osgi.frameworkClassPath") || key.equals("osgi.framework") || key.equals("osgi.bundles") || key.equals("eof")) + continue; + configurationData += "manipulator.getConfigData().setFwIndependentProp('" + key + "', '" + ((String) aProperty.getValue()) + "');"; + } + } + + LauncherData launcherData = info.getLauncherData(); + if (launcherData != null) { + final String[] jvmArgs = launcherData.getJvmArgs(); + for (int i = 0; i < jvmArgs.length; i++) + configurationData += "manipulator.getLauncherData().addJvmArg('" + jvmArgs[i] + "');"; + + final String[] programArgs = launcherData.getProgramArgs(); + for (int i = 0; i < programArgs.length; i++) { + String programArg = programArgs[i]; + if (programArg.equals("--launcher.library") || programArg.equals("-startup") || programArg.equals("-configuration")) + i++; + configurationData += "manipulator.getLauncherData().addProgramArg('" + programArg + "');"; + } + } + touchpointData.put("configurationData", configurationData); + iu.setImmutableTouchpointData(new TouchpointData(touchpointData)); + return iu; + } + + // Put the artifact on the server + protected void publishArtifact(IArtifactDescriptor descriptor, File bundlePath, IWritableArtifactRepository destination, boolean asIs, boolean recurse) { + // key.getClassifier(), key.getId() + '_' + key.getVersion().toString() + if (asIs) { + try { + if (!destination.contains(descriptor)) { + OutputStream output = destination.getOutputStream(descriptor); + if (output == null) + throw new IOException("unable to open output stream for " + descriptor); + FileUtils.copyStream(new BufferedInputStream(new FileInputStream(bundlePath)), true, new BufferedOutputStream(output), true); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + File tempFile = null; + try { + tempFile = File.createTempFile("work", ""); + if (recurse) + FileUtils.zip(new File[] {bundlePath}, tempFile); + else + FileUtils.zip(bundlePath.listFiles(new FileFilter() { + public boolean accept(File pathname) { + if (pathname.isFile()) + return true; + return false; + } + }), tempFile); + if (!destination.contains(descriptor)) { + OutputStream output = destination.getOutputStream(descriptor); + if (output == null) + throw new IOException("unable to open output stream for " + descriptor); + FileUtils.copyStream(new BufferedInputStream(new FileInputStream(tempFile)), true, new BufferedOutputStream(output), true); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (tempFile != null) + tempFile.delete(); + } + } + } + + protected IGeneratorInfo getGeneratorInfo() { + return info; + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/GeneratorBundleInfo.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/GeneratorBundleInfo.java new file mode 100644 index 000000000..11009c567 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/GeneratorBundleInfo.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +import java.io.ByteArrayInputStream; +import org.eclipse.equinox.frameworkadmin.BundleInfo; +import org.eclipse.equinox.prov.core.helpers.Headers; +import org.eclipse.osgi.util.ManifestElement; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; + +public class GeneratorBundleInfo extends BundleInfo { + // public static final int NO_LEVEL = -1; + + // private String symbolicName; + // private String version; + // private String location; + // private int expectedState; + // private int startLevel = NO_LEVEL; + // private String manifest; + + private String specialConfigCommands; + + public GeneratorBundleInfo(BundleInfo bInfo) { + super.setBundleId(bInfo.getBundleId()); + super.setLocation(bInfo.getLocation()); + super.setManifest(bInfo.getManifest()); + super.setMarkedAsStarted(bInfo.isMarkedAsStarted()); + super.setResolved(bInfo.isResolved()); + super.setStartLevel(bInfo.getStartLevel()); + super.setSymbolicName(bInfo.getSymbolicName()); + super.setVersion(bInfo.getVersion()); + } + + public GeneratorBundleInfo() { + // TODO Auto-generated constructor stub + } + + // /* (non-Javadoc) + // * @see java.lang.Object#hashCode() + // */ + // public int hashCode() { + // int result = symbolicName == null ? 0 : symbolicName.hashCode(); + // result = result + (version == null ? 0 : version.hashCode()); + // result = result + (location == null ? 0 : location.hashCode()); + // return result; + // } + // + // public String getSymbolicName() { + // return symbolicName; + // } + // + // public String getVersion() { + // return version; + // } + // + // public int expectedState() { + // return expectedState; + // } + // + // public int getStartLevel() { + // return startLevel; + // } + // + // public String getLocation() { + // return location; + // } + // + // public void setSymbolicName(String id) { + // symbolicName = id; + // } + // + // public void setVersion(String version) { + // this.version = version; + // } + // + // public void setExpectedState(int state) { + // expectedState = state; + // } + // + // public void setStartLevel(int level) { + // this.startLevel = level; + // } + // + // public void setLocation(String location) { + // this.location = location; + // } + // + // public void setManifest(String manifest) { + // this.manifest = manifest; + // } + // + // public String getManifest() { + // return manifest; + // } + // + public String getSpecialConfigCommands() { + return specialConfigCommands; + } + + public void setSpecialConfigCommands(String specialConfigCommands) { + this.specialConfigCommands = specialConfigCommands; + } + + // /* (non-Javadoc) + // * @see java.lang.Object#equals(java.lang.Object) + // */ + // public boolean equals(Object toCompare) { + // if (toCompare instanceof GeneratorBundleInfo) { + // GeneratorBundleInfo info = (GeneratorBundleInfo) toCompare; + // if (info.symbolicName.equals(symbolicName) && info.version.equals(version) && (info.location == null || location == null ? true : info.location.equals(location))) + // return true; + // } + // return false; + // } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer buffer = new StringBuffer(); + String superSt = super.toString(); + buffer.append(superSt.substring(superSt.length() - 1)); + buffer.append(", this.specialConfigCommands="); //$NON-NLS-1$ + buffer.append(this.specialConfigCommands); + buffer.append(')'); + return buffer.toString(); + } + + public void initFromManifest(String manifest) { + try { + super.setManifest(manifest); + Headers headers = Headers.parseManifest(new ByteArrayInputStream(manifest.getBytes())); + ManifestElement[] element = ManifestElement.parseHeader("bsn", (String) headers.get(Constants.BUNDLE_SYMBOLICNAME)); + super.setSymbolicName(element[0].getValue()); + super.setVersion((String) headers.get(Constants.BUNDLE_VERSION)); + } catch (BundleException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/IGeneratorInfo.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/IGeneratorInfo.java new file mode 100644 index 000000000..72af1ead7 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/IGeneratorInfo.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +import java.io.File; +import java.util.ArrayList; +import java.util.Set; +import org.eclipse.equinox.frameworkadmin.ConfigData; +import org.eclipse.equinox.frameworkadmin.LauncherData; +import org.eclipse.equinox.prov.artifact.repository.IWritableArtifactRepository; +import org.eclipse.equinox.prov.metadata.repository.IWritableMetadataRepository; + +public interface IGeneratorInfo { + public boolean addDefaultIUs(); + + public boolean append(); + + public IWritableArtifactRepository getArtifactRepository(); + + public File[] getBundleLocations(); + + public ConfigData getConfigData(); + + public File getConfigurationLocation(); + + public ArrayList getDefaultIUs(Set ius); + + public File getExecutableLocation(); + + public File getFeaturesLocation(); + + public String getFlavor(); + + public LauncherData getLauncherData(); + + public String[][] getMappingRules(); + + public IWritableMetadataRepository getMetadataRepository(); + + public String getRootId(); + + public String getRootVersion(); + + public boolean publishArtifactRepository(); + + public boolean publishArtifacts(); + + public void setArtifactRepository(IWritableArtifactRepository value); + + public void setFlavor(String value); + + public void setMetadataRepository(IWritableMetadataRepository value); + + public void setPublishArtifacts(boolean value); + + public void setRootId(String value); +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/IPlatformEntry.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/IPlatformEntry.java new file mode 100644 index 000000000..132eecca3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/IPlatformEntry.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.prov.metadata.generator; + +public interface IPlatformEntry { + public String getOS(); + + public String getWS(); + + public String getArch(); + + public String getNL(); +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/MetadataGeneratorHelper.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/MetadataGeneratorHelper.java new file mode 100644 index 000000000..e315d5ba5 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/MetadataGeneratorHelper.java @@ -0,0 +1,504 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.prov.metadata.generator; + +import java.io.*; +import java.util.*; +import org.eclipse.equinox.frameworkadmin.BundleInfo; +import org.eclipse.equinox.internal.prov.metadata.ArtifactKey; +import org.eclipse.equinox.internal.prov.metadata.generator.Activator; +import org.eclipse.equinox.prov.artifact.repository.ArtifactDescriptor; +import org.eclipse.equinox.prov.artifact.repository.IArtifactDescriptor; +import org.eclipse.equinox.prov.core.helpers.ServiceHelper; +import org.eclipse.equinox.prov.metadata.*; +import org.eclipse.osgi.service.environment.EnvironmentInfo; +import org.eclipse.osgi.service.resolver.*; +import org.eclipse.osgi.util.ManifestElement; +import org.osgi.framework.*; + +public class MetadataGeneratorHelper { + private static final String ECLIPSE_EXTENSIBLE_API = "Eclipse-ExtensibleAPI"; //$NON-NLS-1$ + + private static final String CAPABILITY_TYPE_OSGI_PACKAGES = "osgi.packages"; //$NON-NLS-1$ + + private static final Version versionMax = new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + + private static final String ECLIPSE_TOUCHPOINT = "eclipse"; //$NON-NLS-1$ + private static final Version ECLIPSE_TOUCHPOINT_VERSION = new Version(1, 0, 0); + + private static final String NATIVE_TOUCHPOINT = "native"; //$NON-NLS-1$ + private static final Version NATIVE_TOUCHPOINT_VERSION = new Version(1, 0, 0); + + private static final String ECLIPSE_ARTIFACT_NAMESPACE = "eclipse"; //$NON-NLS-1$ + private static final String ECLIPSE_ARTIFACT_CLASSIFIER = "plugin"; //$NON-NLS-1$ + + private static final String ORG_ECLIPSE_EXECUTABLE = "org.eclipse.executable"; //$NON-NLS-1$ + private static final Version ORG_ECLIPSE_EXECUTABLE_VERSION = new Version(1, 0, 0); + private static final String IU_NAMESPACE = IInstallableUnit.IU_NAMESPACE; + + private static final String[] BUNDLE_IU_PROPERTY_MAP = {Constants.BUNDLE_NAME, IInstallableUnitConstants.NAME, Constants.BUNDLE_DESCRIPTION, IInstallableUnitConstants.DESCRIPTION, Constants.BUNDLE_VENDOR, IInstallableUnitConstants.PROVIDER, Constants.BUNDLE_CONTACTADDRESS, IInstallableUnitConstants.CONTACT, Constants.BUNDLE_COPYRIGHT, IInstallableUnitConstants.COPYRIGHT, Constants.BUNDLE_DOCURL, IInstallableUnitConstants.DOC_URL, Constants.BUNDLE_UPDATELOCATION, IInstallableUnitConstants.UPDATE_SITE}; + + private static final Version DEFAULT_JRE_VERSION = new Version("1.5"); //$NON-NLS-1$ + + /** + * Creates IUs and artifact descriptors for the JRE, and adds them to the given sets. + * if the jreLocation is <code>null</code>, default information is generated. + */ + public static void createJREData(File jreLocation, Set resultantIUs, Set resultantArtifactDescriptors) { + InstallableUnit iu = new InstallableUnit(); + iu.setSingleton(false); + iu.setId("a.jre"); //$NON-NLS-1$ + iu.setTouchpointType(new TouchpointType(NATIVE_TOUCHPOINT, NATIVE_TOUCHPOINT_VERSION)); + if (jreLocation == null || !jreLocation.exists()) { + //set some reasonable defaults + iu.setVersion(DEFAULT_JRE_VERSION); + iu.setCapabilities(generateJRECapability(null)); + resultantIUs.add(iu); + return; + } + generateJREIUData(iu, jreLocation); + + //Generate artifact for JRE + IArtifactKey key = new ArtifactKey(ECLIPSE_ARTIFACT_NAMESPACE, NATIVE_TOUCHPOINT, iu.getId(), iu.getVersion()); + iu.setArtifacts(new IArtifactKey[] {key}); + iu.setTouchpointType(new TouchpointType(NATIVE_TOUCHPOINT, new Version(1, 0, 0))); + resultantIUs.add(iu); + + //Create the CU + InstallableUnitFragment cu = new InstallableUnitFragment(); + cu.setId("config." + iu.getId()); //$NON-NLS-1$ + cu.setVersion(iu.getVersion()); + cu.setHost(iu.getId(), new VersionRange(iu.getVersion(), true, versionMax, true)); + + cu.setTouchpointType(new TouchpointType(NATIVE_TOUCHPOINT, NATIVE_TOUCHPOINT_VERSION)); + Map touchpointData = new HashMap(); + String configurationData = "Zip.unzip(artifact, currentDir, null);"; + EnvironmentInfo info = (EnvironmentInfo) ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName()); + touchpointData.put("configurationData", configurationData); + cu.setImmutableTouchpointData(new TouchpointData(touchpointData)); + resultantIUs.add(cu); + + //Create the artifact descriptor + IArtifactDescriptor descriptor = createArtifactDescriptor(key, jreLocation, false, true); + resultantArtifactDescriptors.add(descriptor); + } + + private static void generateJREIUData(InstallableUnit iu, File jreLocation) { + //Look for a JRE profile file to set version and capabilities + File[] profiles = jreLocation.listFiles(new FileFilter() { + public boolean accept(File pathname) { + return pathname.getAbsolutePath().endsWith(".profile"); //$NON-NLS-1$ + } + }); + if (profiles.length != 1) { + iu.setVersion(DEFAULT_JRE_VERSION); + iu.setCapabilities(generateJRECapability(null)); + return; + } + String profileName = profiles[0].getAbsolutePath().substring(profiles[0].getAbsolutePath().lastIndexOf('/')); + Version version = DEFAULT_JRE_VERSION; + //TODO Find a better way to determine JRE version + if (profileName.indexOf("1.5") > 0) { //$NON-NLS-1$ + version = new Version("1.5"); //$NON-NLS-1$ + } else if (profileName.indexOf("1.4") > 0) { //$NON-NLS-1$ + version = new Version("1.4"); //$NON-NLS-1$ + } + iu.setVersion(version); + try { + iu.setCapabilities(generateJRECapability(new FileInputStream(profiles[0]))); + } catch (FileNotFoundException e) { + //Shouldn't happen, but ignore and fall through to use default + } + } + + /** + * Creates IUs and artifacts for the Eclipse executable, and adds them to the given + * sets. + */ + public static void createLauncherData(File launcher, String configurationFlavor, Set resultantIUs, Set resultantArtifactDescriptors) { + if (launcher == null || !launcher.exists()) + return; + + //Create the IU + InstallableUnit iu = new InstallableUnit(); + iu.setSingleton(true); + iu.setId(ORG_ECLIPSE_EXECUTABLE); + iu.setVersion(ORG_ECLIPSE_EXECUTABLE_VERSION); + + IArtifactKey key = new ArtifactKey(ECLIPSE_ARTIFACT_NAMESPACE, NATIVE_TOUCHPOINT, ORG_ECLIPSE_EXECUTABLE, ORG_ECLIPSE_EXECUTABLE_VERSION); + iu.setArtifacts(new IArtifactKey[] {key}); + iu.setTouchpointType(new TouchpointType(NATIVE_TOUCHPOINT, new Version(1, 0, 0))); + resultantIUs.add(iu); + + //Create the CU + InstallableUnitFragment cu = new InstallableUnitFragment(); + cu.setId(configurationFlavor + iu.getId()); + cu.setVersion(iu.getVersion()); + cu.setHost(iu.getId(), new VersionRange(iu.getVersion(), true, versionMax, true)); + + cu.setTouchpointType(new TouchpointType(NATIVE_TOUCHPOINT, NATIVE_TOUCHPOINT_VERSION)); + Map touchpointData = new HashMap(); + String configurationData = "Zip.unzip(artifact, currentDir, null);"; + EnvironmentInfo info = (EnvironmentInfo) ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName()); + if (!info.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32)) + // FIXME: is this correct? do all non-Windows platforms need execute permissions on the launcher? + configurationData += " Permissions.chmod(currentDir, \"" + launcher.getName() + "\", 755);"; + touchpointData.put("configurationData", configurationData); + cu.setImmutableTouchpointData(new TouchpointData(touchpointData)); + resultantIUs.add(cu); + + //Create the artifact descriptor + IArtifactDescriptor descriptor = createArtifactDescriptor(new ArtifactKey(ECLIPSE_ARTIFACT_NAMESPACE, NATIVE_TOUCHPOINT, ORG_ECLIPSE_EXECUTABLE, ORG_ECLIPSE_EXECUTABLE_VERSION), launcher, false, true); + resultantArtifactDescriptors.add(descriptor); + } + + private static ProvidedCapability[] generateJRECapability(InputStream profileStream) { + if (profileStream == null) { + //use the 1.5 profile stored in the generator bundle + try { + profileStream = Activator.getContext().getBundle().getEntry("J2SE-1.5.profile").openStream(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + Properties p = new Properties(); + try { + p.load(profileStream); + ManifestElement[] jrePackages = ManifestElement.parseHeader("org.osgi.framework.system.packages", (String) p.get("org.osgi.framework.system.packages")); + ProvidedCapability[] exportedPackageAsCapabilities = new ProvidedCapability[jrePackages.length]; + for (int i = 0; i < jrePackages.length; i++) { + exportedPackageAsCapabilities[i] = new ProvidedCapability("osgi.packages", jrePackages[i].getValue(), null); + } + return exportedPackageAsCapabilities; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (BundleException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (profileStream != null) { + try { + profileStream.close(); + } catch (IOException e) { + //ignore secondary failure + } + } + } + return new ProvidedCapability[0]; + } + + public static IInstallableUnit createEclipseConfigurationUnit(String iuId, Version iuVersion, boolean isBundleFragment, GeneratorBundleInfo configInfo, String configurationFlavor) { + if (configInfo == null) + return null; + + InstallableUnitFragment cu = new InstallableUnitFragment(); + cu.setId(configurationFlavor + iuId); + cu.setVersion(iuVersion); + + //Indicate the IU to which this CU apply + cu.setHost(iuId, new VersionRange(iuVersion, true, versionMax, true)); + + //Add a capability describing the flavor supported + cu.setCapabilities(new ProvidedCapability[] {new ProvidedCapability(IInstallableUnit.FLAVOR_NAMESPACE, configurationFlavor, Version.emptyVersion)}); + + cu.setTouchpointType(new TouchpointType(ECLIPSE_TOUCHPOINT, ECLIPSE_TOUCHPOINT_VERSION)); //TODO Is this necessary? I think we get that from the IU + + Map touchpointData = new HashMap(); + touchpointData.put("configurationData", createConfigScript(configInfo, isBundleFragment)); + touchpointData.put("unconfigurationData", createUnconfigScript(configInfo, isBundleFragment)); + cu.setImmutableTouchpointData(new TouchpointData(touchpointData)); + + return cu; + } + + public static IInstallableUnit createEclipseDefaultConfigurationUnit(GeneratorBundleInfo configInfo, GeneratorBundleInfo unconfigInfo, String configurationFlavor) { + InstallableUnitFragment cu = new InstallableUnitFragment(); + cu.setId(configurationFlavor + "default"); + cu.setVersion(new Version(1, 0, 0)); + + //Add a capability describing the flavor supported + cu.setCapabilities(new ProvidedCapability[] {new ProvidedCapability(IInstallableUnit.FLAVOR_NAMESPACE, configurationFlavor, Version.emptyVersion)}); + + //Create a capability on bundles + RequiredCapability[] reqs = new RequiredCapability[] {new RequiredCapability(IInstallableUnit.CAPABILITY_ECLIPSE_TYPES, IInstallableUnit.CAPABILITY_ECLIPSE_BUNDLE, VersionRange.emptyRange, null, false, true)}; + cu.setRequiredCapabilities(reqs); + cu.setTouchpointType(new TouchpointType(ECLIPSE_TOUCHPOINT, ECLIPSE_TOUCHPOINT_VERSION)); //TODO Is this necessary? I think we get that from the IU + Map touchpointData = new HashMap(); + + touchpointData.put("configurationData", createDefaultConfigScript(configInfo)); + touchpointData.put("unconfigurationData", createDefaultUnconfigScript(unconfigInfo)); + + cu.setImmutableTouchpointData(new TouchpointData(touchpointData)); + return cu; + } + + private static String createDefaultConfigScript(GeneratorBundleInfo configInfo) { + String configScript = "";//$NON-NLS-1$ + if (configInfo != null) { + if (configInfo.getStartLevel() != BundleInfo.NO_LEVEL) { + configScript += "bundleToInstall.setStartLevel(" + configInfo.getStartLevel() + ");"; + } + if (configInfo.isMarkedAsStarted()) { + configScript += "bundleToInstall.setMarkedAsStarted(true);"; + } + if (configInfo.getSpecialConfigCommands() != null) { + configScript += configInfo.getSpecialConfigCommands(); + } + } + return configScript; + } + + private static String createDefaultUnconfigScript(GeneratorBundleInfo unconfigInfo) { + String unconfigScript = ""; //$NON-NLS-1$ + if (unconfigInfo != null) { + if (unconfigInfo.getSpecialConfigCommands() != null) { + unconfigScript += unconfigInfo.getSpecialConfigCommands(); + } + } + return unconfigScript; + } + + private static String createConfigScript(GeneratorBundleInfo configInfo, boolean isBundleFragment) { + String configScript = "manipulator.getConfigData().addBundle(bundleToInstall);"; + if (configInfo != null) { + if (!isBundleFragment && configInfo.getStartLevel() != BundleInfo.NO_LEVEL) { + configScript += "bundleToInstall.setStartLevel(" + configInfo.getStartLevel() + ");"; + } + if (!isBundleFragment && configInfo.isMarkedAsStarted()) { + configScript += "bundleToInstall.setMarkedAsStarted(true);"; + } + if (configInfo.getSpecialConfigCommands() != null) { + configScript += configInfo.getSpecialConfigCommands(); + } + } + return configScript; + } + + private static String createUnconfigScript(GeneratorBundleInfo configInfo, boolean isBundleFragment) { + String unconfigScript = ""; + if (configInfo != null) { + if (!isBundleFragment && configInfo.getStartLevel() != BundleInfo.NO_LEVEL) { + unconfigScript += "bundleToRemove.setStartLevel(" + BundleInfo.NO_LEVEL + ");"; + } + if (!isBundleFragment && configInfo.isMarkedAsStarted()) { + unconfigScript += "bundleToRemove.setMarkedAsStarted(false);"; + } + if (configInfo.getSpecialConfigCommands() != null) { + // TODO: how should special config commands be removed + // unconfigScript += "foobar.remove(" + configInfo.getSpecialConfigCommands() + ");"; + } + } + unconfigScript += "manipulator.getConfigData().removeBundle(bundleToRemove);"; + return unconfigScript; + } + + private static boolean requireAFragment(BundleDescription bd, Map manifest) { + if (manifest == null) + return false; + if (manifest.get(ECLIPSE_EXTENSIBLE_API) == null) + return false; + if (bd.getSymbolicName().equals("org.eclipse.osgi")) //Special case for OSGi + return false; + String classpath = (String) ((Map) bd.getUserObject()).get(Constants.BUNDLE_CLASSPATH); + if (classpath == null) + return true; + ManifestElement[] classpathEntries; + try { + classpathEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, classpath); + if (classpathEntries.length != 0 && classpathEntries[0].getValue().equals(".")) + return true; + } catch (BundleException e) { + //If we are here, it is that we have already parsed the bundle manifest and it contains no error + } + return false; + } + + public static IInstallableUnit createEclipseIU(BundleDescription bd, Map manifest, boolean isFolderPlugin, IArtifactKey key) { + InstallableUnit iu = new InstallableUnit(); + iu.setSingleton(bd.isSingleton()); + iu.setId(bd.getSymbolicName()); + iu.setVersion(bd.getVersion()); + iu.setFilter(bd.getPlatformFilter()); + iu.setProperty(IInstallableUnitConstants.UPDATE_FROM, bd.getSymbolicName()); + iu.setProperty(IInstallableUnitConstants.UPDATE_RANGE, VersionRange.emptyRange.toString()); + + boolean isFragment = bd.getHost() != null; + boolean requiresAFragment = isFragment ? false : requireAFragment(bd, manifest); + + //Process the required bundles + BundleSpecification requiredBundles[] = bd.getRequiredBundles(); + ArrayList reqsDeps = new ArrayList(); + if (requiresAFragment) + reqsDeps.add(new RequiredCapability("fragment", iu.getId(), VersionRange.emptyRange, null, false, false)); + if (isFragment) + reqsDeps.add(RequiredCapability.createRequiredCapabilityForName(bd.getHost().getName(), bd.getHost().getVersionRange(), false)); + for (int j = 0; j < requiredBundles.length; j++) + reqsDeps.add(RequiredCapability.createRequiredCapabilityForName(requiredBundles[j].getName(), requiredBundles[j].getVersionRange() == VersionRange.emptyRange ? null : requiredBundles[j].getVersionRange(), requiredBundles[j].isOptional())); + + //Process the import package + ImportPackageSpecification osgiImports[] = bd.getImportPackages(); + for (int i = 0; i < osgiImports.length; i++) { + // TODO we need to sort out how we want to handle wild-carded dynamic imports - for now we ignore them + ImportPackageSpecification importSpec = osgiImports[i]; + String importPackageName = importSpec.getName(); + if (importPackageName.indexOf('*') != -1) + continue; + + VersionRange versionRange = importSpec.getVersionRange() == VersionRange.emptyRange ? null : importSpec.getVersionRange(); + + //TODO this needs to be refined to take into account all the attribute handled by imports + reqsDeps.add(new RequiredCapability(CAPABILITY_TYPE_OSGI_PACKAGES, importPackageName, versionRange, null, isOptional(importSpec), false)); + } + iu.setRequiredCapabilities((RequiredCapability[]) reqsDeps.toArray(new RequiredCapability[reqsDeps.size()])); + + //Process the export package + ExportPackageDescription exports[] = bd.getExportPackages(); + ProvidedCapability[] exportedPackageAsCapabilities = new ProvidedCapability[exports.length + 1 + (isFragment ? 1 : 0)]; + exportedPackageAsCapabilities[exports.length] = new ProvidedCapability(IInstallableUnit.CAPABILITY_ECLIPSE_TYPES, IInstallableUnit.CAPABILITY_ECLIPSE_BUNDLE, new Version(1, 0, 0)); //Here we add a bundle capability to identify bundles + for (int i = 0; i < exports.length; i++) { + exportedPackageAsCapabilities[i] = new ProvidedCapability(CAPABILITY_TYPE_OSGI_PACKAGES, exports[i].getName(), exports[i].getVersion() == Version.emptyVersion ? null : exports[i].getVersion()); //TODO make sure that we support all the refinement on the exports + } + if (isFragment) + exportedPackageAsCapabilities[exportedPackageAsCapabilities.length - 1] = new ProvidedCapability("fragment", bd.getHost().getName(), bd.getVersion()); + iu.setCapabilities(exportedPackageAsCapabilities); + iu.setApplicabilityFilter(""); + + iu.setArtifacts(new IArtifactKey[] {key}); + + iu.setTouchpointType(new TouchpointType(ECLIPSE_TOUCHPOINT, ECLIPSE_TOUCHPOINT_VERSION)); + + // Set IU properties from the manifest header attributes + // TODO The values of the attributes may be localized. Metadata generation + // should construct property files for the IU based on the bundle/plug-in + // property files in whatever locales are provided. + if (manifest != null) { + int i = 0; + while (i < BUNDLE_IU_PROPERTY_MAP.length) { + if (manifest.containsKey(BUNDLE_IU_PROPERTY_MAP[i])) { + String value = (String) manifest.get(BUNDLE_IU_PROPERTY_MAP[i]); + if (value != null) { + iu.setProperty(BUNDLE_IU_PROPERTY_MAP[i + 1], value); + } + } + i += 2; + } + } + + //Define the immutable metadata for this IU. In this case immutable means that this is something that will not impact the configuration + Map touchpointData = new HashMap(); + if (isFolderPlugin) + touchpointData.put("zipped", "true"); + touchpointData.put("manifest", toManifestString(manifest)); + iu.setImmutableTouchpointData(new TouchpointData(touchpointData)); + return iu; + } + + public static VersionRange getVersionRange(FeatureEntry entry) { + String versionSpec = entry.getVersion(); + if (versionSpec == null) + // TODO should really be returning VersionRange.emptyRange here... + return null; + Version version = new Version(versionSpec); + if (!entry.isRequires()) + return new VersionRange(version, true, version, true); + String match = entry.getMatch(); + if (match == null) + // TODO should really be returning VersionRange.emptyRange here... + return null; + if (match.equals("perfect")) + return new VersionRange(version, true, version, true); + if (match.equals("equivalent")) { + Version upper = new Version(version.getMajor(), version.getMinor() + 1, 0); + return new VersionRange(version, true, upper, false); + } + if (match.equals("compatible")) { + Version upper = new Version(version.getMajor() + 1, 0, 0); + return new VersionRange(version, true, upper, false); + } + if (match.equals("greaterOrEqual")) + return new VersionRange(version, true, new VersionRange(null).getMaximum(), true); + return null; + } + + private static String getTransformedId(String original, boolean isPlugin) { + return isPlugin ? original : original + ".featureIU"; + } + + public static IInstallableUnit createGroupIU(Feature feature) { + InstallableUnit iu = new InstallableUnit(); + iu.setId(getTransformedId(feature.getId(), false)); + iu.setVersion(new Version(feature.getVersion())); + iu.setProperty(IInstallableUnitConstants.UPDATE_FROM, iu.getId()); + iu.setProperty(IInstallableUnitConstants.UPDATE_RANGE, VersionRange.emptyRange.toString()); + + FeatureEntry entries[] = feature.getEntries(); + RequiredCapability[] required = new RequiredCapability[entries.length]; + for (int i = 0; i < entries.length; i++) { + VersionRange range = getVersionRange(entries[i]); + required[i] = new RequiredCapability(IU_NAMESPACE, getTransformedId(entries[i].getId(), entries[i].isPlugin()), range, getFilter(entries[i]), entries[i].isOptional(), false); + } + iu.setRequiredCapabilities(required); + iu.setTouchpointType(TouchpointType.NONE); + ProvidedCapability groupCapability = new ProvidedCapability(IInstallableUnit.IU_KIND_NAMESPACE, "group", new Version("1.0.0")); + iu.setCapabilities(new ProvidedCapability[] {groupCapability}); + return iu; + } + + public static String getFilter(FeatureEntry entry) { + StringBuffer result = new StringBuffer(); + result.append("(&"); //$NON-NLS-1$ + if (entry.getFilter() != null) + result.append(entry.getFilter()); + if (entry.getOS() != null) + result.append("(osgi.os=" + entry.getOS() + ')');//$NON-NLS-1$ + if (entry.getWS() != null) + result.append("(osgi.ws=" + entry.getWS() + ')');//$NON-NLS-1$ + if (entry.getArch() != null) + result.append("(osgi.arch=" + entry.getArch() + ')');//$NON-NLS-1$ + if (entry.getNL() != null) + result.append("(osgi.nl=" + entry.getNL() + ')');//$NON-NLS-1$ + if (result.length() == 2) + return null; + result.append(')'); + return result.toString(); + } + + private static boolean isOptional(ImportPackageSpecification importedPackage) { + if (importedPackage.getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_DYNAMIC) || importedPackage.getDirective(Constants.RESOLUTION_DIRECTIVE).equals(ImportPackageSpecification.RESOLUTION_OPTIONAL)) + return true; + return false; + } + + private static String toManifestString(Map p) { + if (p == null) + return null; + Collection properties = p.entrySet(); + StringBuffer result = new StringBuffer(); + for (Iterator iterator = properties.iterator(); iterator.hasNext();) { + Map.Entry aProperty = (Map.Entry) iterator.next(); + result.append(aProperty.getKey()).append(": ").append(aProperty.getValue()).append('\n'); + } + return result.toString(); + } + + public static IArtifactKey createEclipseArtifactKey(String bsn, String version) { + return new ArtifactKey(ECLIPSE_ARTIFACT_NAMESPACE, ECLIPSE_ARTIFACT_CLASSIFIER, bsn, new Version(version)); + } + + public static IArtifactDescriptor createArtifactDescriptor(IArtifactKey key, File pathOnDisk, boolean asIs, boolean recurse) { + //TODO this size calculation is bogus + ArtifactDescriptor result = new ArtifactDescriptor(key); + if (pathOnDisk != null) + result.setProperty(IArtifactDescriptor.ARTIFACT_SIZE, Long.toString(pathOnDisk.length())); + return result; + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/URLEntry.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/URLEntry.java new file mode 100644 index 000000000..fb628f82d --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/prov/metadata/generator/URLEntry.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.equinox.prov.metadata.generator; + +public class URLEntry { + private String annotation; + private String url; + + public URLEntry() { + } + + public URLEntry(String url, String annotation) { + this.url = url; + this.annotation = annotation; + } + + public void setAnnotation(String annotation) { + this.annotation = annotation; + } + + public String getAnnotation() { + return annotation; + } + + public void setURL(String url) { + this.url = url; + } + + public String getURL() { + return url; + } +} |