diff options
author | John Arthorne | 2009-08-10 14:34:39 +0000 |
---|---|---|
committer | John Arthorne | 2009-08-10 14:34:39 +0000 |
commit | 09509ad60e6b3ef0f61967887c194e5dcec41169 (patch) | |
tree | 7372704b48b5de117280014d56bf380ad13ec108 | |
parent | 32d359cd48bb6a1b105fdc7768810892219c7e67 (diff) | |
download | rt.equinox.p2-09509ad60e6b3ef0f61967887c194e5dcec41169.tar.gz rt.equinox.p2-09509ad60e6b3ef0f61967887c194e5dcec41169.tar.xz rt.equinox.p2-09509ad60e6b3ef0f61967887c194e5dcec41169.zip |
Bug 286047 GZipped profile format not understood by 3.5.0
2 files changed, 93 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java index 21cf171b6..5bd4df26d 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java @@ -20,8 +20,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.equinox.internal.p2.core.helpers.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.core.Version; +import org.eclipse.equinox.internal.provisional.p2.core.*; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; import org.eclipse.equinox.internal.provisional.p2.engine.*; @@ -428,7 +427,8 @@ public class SimpleProfileRegistry implements IProfileRegistry { long currentTimestamp = System.currentTimeMillis(); if (currentTimestamp <= previousTimestamp) currentTimestamp = previousTimestamp + 1; - File profileFile = new File(profileDirectory, Long.toString(currentTimestamp) + PROFILE_GZ_EXT); + boolean shouldGzipFile = shouldGzipFile(profile); + File profileFile = new File(profileDirectory, Long.toString(currentTimestamp) + (shouldGzipFile ? PROFILE_GZ_EXT : PROFILE_EXT)); // Log a stack trace to see who is writing the profile. if (DebugHelper.DEBUG_PROFILE_REGISTRY) @@ -438,7 +438,10 @@ public class SimpleProfileRegistry implements IProfileRegistry { profile.setChanged(false); OutputStream os = null; try { - os = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(profileFile))); + if (shouldGzipFile) + os = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(profileFile))); + else + os = new BufferedOutputStream(new FileOutputStream(profileFile)); Writer writer = new Writer(os); writer.writeProfile(profile); } catch (IOException e) { @@ -455,6 +458,14 @@ public class SimpleProfileRegistry implements IProfileRegistry { } } + /** + * Returns whether the profile file for the given profile should be written in gzip format. + */ + private boolean shouldGzipFile(Profile profile) { + //check whether the profile contains the p2 engine from 3.5.0 or earlier + return profile.available(new InstallableUnitQuery("org.eclipse.equinox.p2.engine", new VersionRange("[0.0.0, 1.0.101)")), new Collector(), null).isEmpty(); //$NON-NLS-1$//$NON-NLS-2$ + } + private void deleteProfile(String profileId) { File profileDirectory = new File(store, escape(profileId) + PROFILE_EXT); FileUtils.deleteAll(profileDirectory); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java index 8784ca39e..9d95c8a73 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java @@ -10,8 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.p2.tests.engine; -import java.io.File; -import java.io.IOException; +import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Properties; import org.eclipse.core.runtime.FileLocator; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; @@ -19,10 +20,12 @@ import org.eclipse.equinox.internal.p2.engine.Profile; import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.equinox.internal.provisional.p2.core.Version; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener; import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; +import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; import org.eclipse.equinox.internal.provisional.p2.query.Collector; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; @@ -541,4 +544,77 @@ public class ProfileRegistryTest extends AbstractProvisioningTest { // } // } // } + + public void testPersistenceFormatNotGzipped() { + //in a profile with an engine version from 3.5.0 or earlier, we must not gzip the profile registry + IInstallableUnit engineIU = createEclipseIU("org.eclipse.equinox.p2.engine", Version.create("1.0.100.v20090605")); + File folder = getTempFolder(); + folder.mkdirs(); + SimpleProfileRegistry profileRegistry = new SimpleProfileRegistry(folder, null, false); + Profile profile = new Profile(getName(), null, null); + profile.addInstallableUnit(engineIU); + Method saveMethod; + try { + saveMethod = registry.getClass().getDeclaredMethod("saveProfile", new Class[] {Profile.class}); + saveMethod.setAccessible(true); + saveMethod.invoke(profileRegistry, new Object[] {profile}); + } catch (SecurityException e) { + fail(); + } catch (NoSuchMethodException e) { + fail(); + } catch (IllegalArgumentException e) { + fail(); + } catch (IllegalAccessException e) { + fail(); + } catch (InvocationTargetException e) { + fail(); + } + File profileFolder = new File(folder, getName() + ".profile"); + File[] filesFound = profileFolder.listFiles(new FileFilter() { + public boolean accept(File pathname) { + return pathname.getName().endsWith(".profile"); + } + }); + assertEquals(1, filesFound.length); + filesFound = profileFolder.listFiles(new FileFilter() { + public boolean accept(File pathname) { + return pathname.getName().endsWith(".profile.gz"); + } + }); + assertEquals(0, filesFound.length); + } + + public void testPersistenceFormatGzipped() { + //in a profile with an engine version from 3.5.1 or later, we gzip the profile registry + IInstallableUnit engineIU = createEclipseIU("org.eclipse.equinox.p2.engine", Version.create("1.0.101")); + File folder = getTempFolder(); + folder.mkdirs(); + SimpleProfileRegistry profileRegistry = new SimpleProfileRegistry(folder, null, false); + Profile profile = new Profile(getName(), null, null); + profile.addInstallableUnit(engineIU); + Method saveMethod; + try { + saveMethod = registry.getClass().getDeclaredMethod("saveProfile", new Class[] {Profile.class}); + saveMethod.setAccessible(true); + saveMethod.invoke(profileRegistry, new Object[] {profile}); + } catch (SecurityException e) { + fail(); + } catch (NoSuchMethodException e) { + fail(); + } catch (IllegalArgumentException e) { + fail(); + } catch (IllegalAccessException e) { + fail(); + } catch (InvocationTargetException e) { + fail(); + } + File profileFolder = new File(folder, getName() + ".profile"); + File[] filesFound = profileFolder.listFiles(new FileFilter() { + + public boolean accept(File pathname) { + return pathname.getName().endsWith(".profile.gz"); + } + }); + assertEquals(1, filesFound.length); + } } |