diff options
12 files changed, 227 insertions, 80 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF index 9a11085ed..73b1217ff 100644 --- a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF @@ -39,7 +39,8 @@ Export-Package: org.eclipse.equinox.internal.p2.core;x-internal:=true, org.eclipse.equinox.p2.updatechecker, org.eclipse.equinox.p2.updatechecker.app, org.eclipse.equinox.p2.garbagecollector, - org.eclipse.equinox.p2.console", + org.eclipse.equinox.p2.console, + org.eclipse.equinox.p2.updatesite", org.eclipse.equinox.internal.p2.persistence;x-friends:="org.eclipse.equinox.p2.artifact.repository,org.eclipse.equinox.p2.engine,org.eclipse.equinox.p2.metadata.repository", org.eclipse.equinox.p2.core, org.eclipse.equinox.p2.core.eventbus, diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.metadata.generator/META-INF/MANIFEST.MF index 0b4f08e1e..0d6e88859 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/META-INF/MANIFEST.MF @@ -20,7 +20,7 @@ Import-Package: javax.xml.parsers, org.xml.sax Bundle-Activator: org.eclipse.equinox.internal.p2.metadata.generator.Activator Export-Package: org.eclipse.equinox.internal.p2.metadata.generator;x-internal:=true, - org.eclipse.equinox.internal.p2.metadata.generator.features;x-internal:=true, + org.eclipse.equinox.internal.p2.metadata.generator.features;x-friends:="org.eclipse.equinox.p2.updatesite", org.eclipse.equinox.p2.metadata.generator Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4, diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/FeatureParser.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/FeatureParser.java index 3e5a83742..953b98f63 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/FeatureParser.java +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/FeatureParser.java @@ -73,43 +73,43 @@ public class FeatureParser extends DefaultHandler { characters = null; } - private Properties loadProperties(File location) { - if (location.isDirectory()) { - //skip directories that don't contain a feature.properties file - File file = new File(location, "feature.properties"); //$NON-NLS-1$ - if (!file.exists()) - return null; + private Properties loadProperties(File directory) { + //skip directories that don't contain a feature.properties file + File file = new File(directory, "feature.properties"); //$NON-NLS-1$ + if (!file.exists()) + return null; + try { + InputStream input = new BufferedInputStream(new FileInputStream(file)); try { - InputStream input = new BufferedInputStream(new FileInputStream(file)); - try { - Properties result = new Properties(); - result.load(input); - return result; - } finally { - if (input != null) - input.close(); - } - } catch (IOException e) { - e.printStackTrace(); + Properties result = new Properties(); + result.load(input); + return result; + } finally { + if (input != null) + input.close(); } - } else if (location.getName().endsWith(".jar")) { + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + private Properties loadProperties(JarFile jar) { + JarEntry entry = jar.getJarEntry("feature.properties"); + if (entry == null) + return null; + try { + InputStream input = new BufferedInputStream(jar.getInputStream(entry)); try { - JarFile jar = new JarFile(location); - JarEntry entry = jar.getJarEntry("feature.properties"); - if (entry == null) - return null; - InputStream input = new BufferedInputStream(jar.getInputStream(entry)); - try { - Properties result = new Properties(); - result.load(input); - return result; - } finally { - if (input != null) - input.close(); - } - } catch (IOException e) { - e.printStackTrace(); + Properties result = new Properties(); + result.load(input); + return result; + } finally { + if (input != null) + input.close(); } + } catch (IOException e) { + e.printStackTrace(); } return null; } @@ -147,10 +147,10 @@ public class FeatureParser extends DefaultHandler { } else if (location.getName().endsWith(".jar")) { try { JarFile jar = new JarFile(location); + Properties properties = loadProperties(jar); JarEntry entry = jar.getJarEntry("feature.xml"); if (entry == null) return null; - Properties properties = loadProperties(location); InputStream input = new BufferedInputStream(jar.getInputStream(entry)); return parse(input, properties); } catch (IOException e) { diff --git a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/SiteModel.java b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/SiteModel.java index 1c55e5e4e..9b0cbfd32 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/SiteModel.java +++ b/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/p2/metadata/generator/features/SiteModel.java @@ -31,7 +31,7 @@ public class SiteModel { /** * Map of String (feature id) -> SiteFeature */ - private Map features; + private List features; private URL locationURL; private String locationURLString; private List /* of URLEntry */mirrors; @@ -81,8 +81,8 @@ public class SiteModel { */ public void addFeature(SiteFeature featureReference) { if (this.features == null) - this.features = new HashMap(); - this.features.put(featureReference.getFeatureIdentifier(), featureReference); + this.features = new ArrayList(); + this.features.add(featureReference); } /** @@ -150,13 +150,6 @@ public class SiteModel { } /** - * Returns the feature with the given id, or <code>null</code> - */ - public SiteFeature getFeature(String id) { - return (SiteFeature) (features == null ? null : features.get(id)); - } - - /** * Returns an array of feature reference models on this site. * * @return an array of feature reference models, or an empty array. @@ -164,7 +157,7 @@ public class SiteModel { public SiteFeature[] getFeatures() { if (features == null || features.size() == 0) return new SiteFeature[0]; - return (SiteFeature[]) features.values().toArray(new SiteFeature[0]); + return (SiteFeature[]) features.toArray(new SiteFeature[0]); } /** diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java index 2ebdb8d17..05505b362 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java @@ -344,7 +344,7 @@ public class EclipseTouchpoint extends Touchpoint { return createError("The \"startLevel\" parameter was not set in the \"set start level\" action."); BundleInfo bundleInfo = new BundleInfo(); - Util.initFromManifest(Util.getManifest(iu.getTouchpointData()), bundleInfo); + Util.initFromManifest(Util.getManifest(iu.getTouchpointData(), null), bundleInfo); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (bundles[i].equals(bundleInfo)) { @@ -365,7 +365,7 @@ public class EclipseTouchpoint extends Touchpoint { IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU); BundleInfo bundleInfo = new BundleInfo(); - Util.initFromManifest(Util.getManifest(iu.getTouchpointData()), bundleInfo); + Util.initFromManifest(Util.getManifest(iu.getTouchpointData(), null), bundleInfo); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (bundles[i].equals(bundleInfo)) { @@ -390,7 +390,7 @@ public class EclipseTouchpoint extends Touchpoint { return createError("The \"started\" parameter was not set in the \"mark started\" action."); BundleInfo bundleInfo = new BundleInfo(); - Util.initFromManifest(Util.getManifest(iu.getTouchpointData()), bundleInfo); + Util.initFromManifest(Util.getManifest(iu.getTouchpointData(), null), bundleInfo); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (bundles[i].equals(bundleInfo)) { @@ -407,7 +407,7 @@ public class EclipseTouchpoint extends Touchpoint { IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU); BundleInfo bundleInfo = new BundleInfo(); - Util.initFromManifest(Util.getManifest(iu.getTouchpointData()), bundleInfo); + Util.initFromManifest(Util.getManifest(iu.getTouchpointData(), null), bundleInfo); BundleInfo[] bundles = manipulator.getConfigData().getBundles(); for (int i = 0; i < bundles.length; i++) { if (bundles[i].equals(bundleInfo)) { @@ -580,7 +580,7 @@ public class EclipseTouchpoint extends Touchpoint { return createError("The artifact " + artifactKey.toString() + " to install was not found."); // TODO: do we really need the manifest here or just the bsn and version? - String manifest = Util.getManifest(iu.getTouchpointData()); + String manifest = Util.getManifest(iu.getTouchpointData(), bundleFile); if (manifest == null) return createError("The manifest is missing for: " + iu.getTouchpointData()); @@ -620,7 +620,7 @@ public class EclipseTouchpoint extends Touchpoint { File bundleFile = Util.getBundleFile(artifactKey, profile); // TODO: do we really need the manifest here or just the bsn and version? - String manifest = Util.getManifest(iu.getTouchpointData()); + String manifest = Util.getManifest(iu.getTouchpointData(), bundleFile); if (manifest == null) return createError("The manifest is missing for: " + iu.getTouchpointData()); diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java index 7179239a1..fc1da0502 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/Util.java @@ -10,12 +10,14 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.touchpoint.eclipse; -import java.io.ByteArrayInputStream; -import java.io.File; +import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.util.HashSet; import java.util.Set; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.equinox.frameworkadmin.BundleInfo; @@ -155,13 +157,55 @@ public class Util { return "eclipse"; //$NON-NLS-1$ } - static String getManifest(TouchpointData[] data) { + static String getManifest(TouchpointData[] data, File bundleFile) { for (int i = 0; i < data.length; i++) { String manifest = data[i].getInstructions("manifest"); //$NON-NLS-1$ if (manifest != null) return manifest; } - return null; + if (bundleFile == null) + return null; + + if (bundleFile.isDirectory()) { + File manifestFile = new File(bundleFile, JarFile.MANIFEST_NAME); + byte[] buffer = new byte[(int) manifestFile.length()]; + InputStream fis = null; + try { + fis = new FileInputStream(manifestFile); + fis.read(buffer); + return new String(buffer); + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + if (fis != null) + try { + fis.close(); + } catch (IOException e) { + // ignore + } + } + } + + ZipFile bundleJar = null; + try { + bundleJar = new ZipFile(bundleFile); + ZipEntry manifestEntry = bundleJar.getEntry(JarFile.MANIFEST_NAME); + byte[] buffer = new byte[(int) manifestEntry.getSize()]; + bundleJar.getInputStream(manifestEntry).read(buffer); + return new String(buffer); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } finally { + if (bundleJar != null) + try { + bundleJar.close(); + } catch (IOException e) { + // ignore + } + } } public static void initFromManifest(String manifest, BundleInfo bInfo) { diff --git a/bundles/org.eclipse.equinox.p2.updatesite/.classpath b/bundles/org.eclipse.equinox.p2.updatesite/.classpath index 7cdeb7319..751c8f2e5 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/.classpath +++ b/bundles/org.eclipse.equinox.p2.updatesite/.classpath @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/bundles/org.eclipse.equinox.p2.updatesite/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.updatesite/.settings/org.eclipse.jdt.core.prefs index ed5b63b50..1f80709f3 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.equinox.p2.updatesite/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Mon Nov 05 17:01:21 EST 2007 +#Tue Jan 08 10:39:24 EST 2008 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -9,23 +9,19 @@ org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled org.eclipse.jdt.core.compiler.problem.discouragedReference=error org.eclipse.jdt.core.compiler.problem.emptyStatement=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled org.eclipse.jdt.core.compiler.problem.fieldHiding=warning @@ -74,7 +70,6 @@ org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled @@ -88,7 +83,6 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 diff --git a/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF index 34f1a5796..74b6ed5f6 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF @@ -3,19 +3,26 @@ Bundle-ManifestVersion: 2 Bundle-Name: Updatesite repository adapter bundle Bundle-SymbolicName: org.eclipse.equinox.p2.updatesite;singleton:=true Bundle-Version: 0.1.0.qualifier -Bundle-Activator: org.eclipse.equinox.p2.updatesite.Activator +Bundle-Activator: org.eclipse.equinox.internal.p2.updatesite.Activator Eclipse-LazyStart: true -Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, - J2SE-1.4 -Import-Package: org.eclipse.equinox.p2.artifact.repository, +Import-Package: org.eclipse.equinox.internal.p2.core.helpers, + org.eclipse.equinox.internal.p2.metadata.generator.features, + org.eclipse.equinox.p2.artifact.repository, org.eclipse.equinox.p2.core.repository, org.eclipse.equinox.p2.metadata, + org.eclipse.equinox.p2.metadata.generator, org.eclipse.equinox.p2.metadata.repository, org.eclipse.equinox.p2.query, org.eclipse.equinox.spi.p2.artifact.repository, org.eclipse.equinox.spi.p2.core.repository, org.eclipse.equinox.spi.p2.metadata.repository, - org.osgi.framework;version="1.3.0" + org.eclipse.osgi.service.resolver;version="1.2.0", + org.eclipse.osgi.util;version="1.1.0", + org.osgi.framework;version="1.3.0", + org.xml.sax, + org.xml.sax.helpers Require-Bundle: org.eclipse.equinox.common;bundle-version="3.4.0", org.eclipse.equinox.p2.metadata.repository;bundle-version="0.1.0", org.eclipse.equinox.p2.artifact.repository;bundle-version="0.1.0" +Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, + J2SE-1.4 diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/p2/updatesite/Activator.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/Activator.java index d7fdd9298..e44774298 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/p2/updatesite/Activator.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/Activator.java @@ -8,13 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.p2.updatesite; +package org.eclipse.equinox.internal.p2.updatesite; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public static String ID = "org.eclipse.equinox.internal.p2.updatesite"; private static BundleContext bundleContext; public void start(BundleContext context) throws Exception { diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepository.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepository.java index 692625f21..7bae80b19 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepository.java @@ -18,10 +18,10 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.updatesite.Activator; import org.eclipse.equinox.p2.artifact.repository.*; import org.eclipse.equinox.p2.core.repository.IRepository; import org.eclipse.equinox.p2.metadata.IArtifactKey; -import org.eclipse.equinox.p2.updatesite.Activator; import org.eclipse.equinox.spi.p2.core.repository.AbstractRepository; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -62,7 +62,7 @@ public class UpdateSiteArtifactRepository extends AbstractRepository implements repository = manager.loadRepository(stateDirURL, null); if (repository == null) { repository = manager.createRepository(stateDirURL, repositoryName, "org.eclipse.equinox.p2.artifact.repository.simpleRepository"); - repository.setProperty(IRepository.IMPLEMENTATION_ONLY_KEY, Boolean.TRUE.toString()); + repository.setProperty(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); } } finally { context.ungetService(reference); @@ -76,7 +76,7 @@ public class UpdateSiteArtifactRepository extends AbstractRepository implements public Map getProperties() { Map result = new HashMap(artifactRepository.getProperties()); - result.remove(IRepository.IMPLEMENTATION_ONLY_KEY); + result.remove(IRepository.PROP_SYSTEM); return result; } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java index bc3828192..d2ac88afa 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java @@ -10,22 +10,27 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.updatesite.metadata; -import java.io.File; +import java.io.*; import java.net.MalformedURLException; import java.net.URL; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; +import org.eclipse.equinox.internal.p2.metadata.generator.features.*; +import org.eclipse.equinox.internal.p2.updatesite.Activator; import org.eclipse.equinox.p2.core.repository.IRepository; +import org.eclipse.equinox.p2.metadata.IArtifactKey; import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.generator.*; import org.eclipse.equinox.p2.metadata.repository.IMetadataRepository; import org.eclipse.equinox.p2.metadata.repository.IMetadataRepositoryManager; import org.eclipse.equinox.p2.query.Collector; import org.eclipse.equinox.p2.query.Query; -import org.eclipse.equinox.p2.updatesite.Activator; import org.eclipse.equinox.spi.p2.core.repository.AbstractRepository; +import org.eclipse.osgi.service.resolver.*; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import org.xml.sax.SAXException; public class UpdateSiteMetadataRepository extends AbstractRepository implements IMetadataRepository { @@ -46,6 +51,91 @@ public class UpdateSiteMetadataRepository extends AbstractRepository implements e.printStackTrace(); } metadataRepository = initializeMetadataRepository(context, localRepositoryURL, "update site implementation - " + location.toExternalForm()); + + try { + + DefaultSiteParser siteParser = new DefaultSiteParser(); + long start = System.currentTimeMillis(); + InputStream is = new BufferedInputStream(location.openStream()); + SiteModel siteModel = siteParser.parse(is); + System.out.println("Time Fetching Site " + location + " was: " + (System.currentTimeMillis() - start) + " ms"); + Map categoryNameToFeatureIUs = new HashMap(); + SiteCategory[] siteCategories = siteModel.getCategories(); + for (int i = 0; i < siteCategories.length; i++) { + categoryNameToFeatureIUs.put(siteCategories[i].getName(), new HashSet()); + } + + Set allSiteIUs = new HashSet(); + SiteFeature[] siteFeatures = siteModel.getFeatures(); + + FeatureParser featureParser = new FeatureParser(); + BundleDescriptionFactory bundleDesciptionFactory = initializeBundleDescriptionFactory(Activator.getBundleContext()); + System.out.println("Retrieving " + siteFeatures.length + " features"); + for (int i = 0; i < siteFeatures.length; i++) { + SiteFeature siteFeature = siteFeatures[i]; + System.out.println(siteFeature.getFeatureIdentifier()); + URL featureURL = new URL(location, siteFeature.getURLString()); + Feature feature = parseFeature(featureParser, featureURL); + + FeatureEntry[] featureEntries = feature.getEntries(); + for (int j = 0; j < featureEntries.length; j++) { + FeatureEntry entry = featureEntries[j]; + if (entry.isPlugin()) { + Dictionary mockManifest = new Properties(); + mockManifest.put("Manifest-Version", "1.0"); + mockManifest.put("Bundle-ManifestVersion", "2"); + mockManifest.put("Bundle-SymbolicName", entry.getId()); + mockManifest.put("Bundle-Version", entry.getVersion()); + BundleDescription bundleDescription = bundleDesciptionFactory.getBundleDescription(mockManifest, null); + IArtifactKey key = MetadataGeneratorHelper.createBundleArtifactKey(entry.getId(), entry.getVersion()); + IInstallableUnit bundleIU = MetadataGeneratorHelper.createBundleIU(bundleDescription, null, entry.isUnpack(), key); + allSiteIUs.add(bundleIU); + } + } + + IInstallableUnit featureIU = MetadataGeneratorHelper.createFeatureIU(feature, false); + IInstallableUnit groupIU = MetadataGeneratorHelper.createGroupIU(feature, featureIU); + String[] categoryNames = siteFeature.getCategoryNames(); + for (int j = 0; j < categoryNames.length; j++) { + Set featureIUList = (Set) categoryNameToFeatureIUs.get(categoryNames[j]); + if (featureIUList != null) { + featureIUList.add(groupIU); + } + } + allSiteIUs.add(featureIU); + allSiteIUs.add(groupIU); + } + + for (int i = 0; i < siteCategories.length; i++) { + SiteCategory category = siteCategories[i]; + Set featureIUs = (Set) categoryNameToFeatureIUs.get(category.getName()); + IInstallableUnit categoryIU = MetadataGeneratorHelper.createCategoryIU(category, featureIUs, null); + allSiteIUs.add(categoryIU); + } + + IInstallableUnit[] ius = (IInstallableUnit[]) allSiteIUs.toArray(new IInstallableUnit[allSiteIUs.size()]); + metadataRepository.addInstallableUnits(ius); + System.out.println("Time Fetching Site and Features for " + location + " was: " + (System.currentTimeMillis() - start) + " ms"); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private Feature parseFeature(FeatureParser featureParser, URL featureURL) throws IOException, FileNotFoundException { + + File featureFile = File.createTempFile("feature", ".jar"); + try { + FileUtils.copyStream(featureURL.openStream(), false, new BufferedOutputStream(new FileOutputStream(featureFile)), true); + Feature feature = featureParser.parse(featureFile); + return feature; + } finally { + featureFile.delete(); + } } private IMetadataRepository initializeMetadataRepository(BundleContext context, URL stateDirURL, String repositoryName) { @@ -62,7 +152,7 @@ public class UpdateSiteMetadataRepository extends AbstractRepository implements repository = manager.loadRepository(stateDirURL, null); if (repository == null) { repository = manager.createRepository(stateDirURL, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY); - repository.setProperty(IRepository.IMPLEMENTATION_ONLY_KEY, Boolean.TRUE.toString()); + repository.setProperty(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); } } finally { context.ungetService(reference); @@ -74,9 +164,26 @@ public class UpdateSiteMetadataRepository extends AbstractRepository implements return repository; } + private BundleDescriptionFactory initializeBundleDescriptionFactory(BundleContext context) { + + ServiceReference reference = context.getServiceReference(PlatformAdmin.class.getName()); + if (reference == null) + throw new IllegalStateException("PlatformAdmin not registered."); + PlatformAdmin platformAdmin = (PlatformAdmin) context.getService(reference); + if (platformAdmin == null) + throw new IllegalStateException("PlatformAdmin not registered."); + + try { + StateObjectFactory stateObjectFactory = platformAdmin.getFactory(); + return new BundleDescriptionFactory(stateObjectFactory, null); + } finally { + context.ungetService(reference); + } + } + public Map getProperties() { Map result = new HashMap(metadataRepository.getProperties()); - result.remove(IRepository.IMPLEMENTATION_ONLY_KEY); + result.remove(IRepository.PROP_SYSTEM); return result; } |