diff options
author | John Arthorne | 2008-01-10 20:19:37 +0000 |
---|---|---|
committer | John Arthorne | 2008-01-10 20:19:37 +0000 |
commit | 43014e3a84df2c6d062666c54ec284d7f3eb2551 (patch) | |
tree | 9ff7209dfad72a90b4ee1706329991fc52307362 /bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox | |
parent | 9d8a7a78ed908d1b4ca3eb03d156b8edfc930b4a (diff) | |
download | rt.equinox.p2-43014e3a84df2c6d062666c54ec284d7f3eb2551.tar.gz rt.equinox.p2-43014e3a84df2c6d062666c54ec284d7f3eb2551.tar.xz rt.equinox.p2-43014e3a84df2c6d062666c54ec284d7f3eb2551.zip |
Bug 214704 [prov] Consistency of repository index compressionv20080110-1605
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox')
2 files changed, 54 insertions, 23 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java index 420e962d7..752ed4da0 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java @@ -12,7 +12,8 @@ import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.util.*; -import java.util.zip.GZIPOutputStream; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.*; import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; @@ -25,7 +26,7 @@ import org.eclipse.equinox.spi.p2.artifact.repository.AbstractArtifactRepository public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository { static final private String BLOBSTORE = ".blobstore/"; //$NON-NLS-1$ - static final private String CONTENT_FILENAME = "artifacts.xml"; //$NON-NLS-1$ + static final private String CONTENT_FILENAME = "artifacts"; //$NON-NLS-1$ static final private String REPOSITORY_TYPE = "org.eclipse.equinox.p2.artifact.repository.simpleRepository"; //$NON-NLS-1$ static final private Integer REPOSITORY_VERSION = new Integer(1); static final public String[][] DEFAULT_MAPPING_RULES = { {"(& (namespace=eclipse) (classifier=plugin))", "${repoUrl}/plugins/${id}_${version}.jar"}, //$NON-NLS-1$//$NON-NLS-2$ @@ -35,7 +36,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme private static final String ARTIFACT_FOLDER = "artifact.folder"; //$NON-NLS-1$ private static final String ARTIFACT_REFERENCE = "artifact.reference"; //$NON-NLS-1$ private static final String JAR_EXTENSION = ".jar"; //$NON-NLS-1$ - private static final String GZIP_EXTENSION = ".gz"; //$NON-NLS-1$ + private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ transient private Mapper mapper = new Mapper(); protected String[][] mappingRules = DEFAULT_MAPPING_RULES; @@ -43,8 +44,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme private boolean signatureVerification = false; private transient BlobStore blobStore; - public static URL getActualLocation(URL base, boolean gzip) { - return getActualLocation(base, gzip ? GZIP_EXTENSION : ""); //$NON-NLS-1$ + public static URL getActualLocation(URL base, boolean compress) { + return getActualLocation(base, compress ? JAR_EXTENSION : XML_EXTENSION); } private static URL getActualLocation(URL base, String extension) { @@ -432,22 +433,39 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public void save() { - save(true); + boolean compress = "true".equalsIgnoreCase((String) properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ + save(compress); } - public void save(boolean gzip) { + public void save(boolean compress) { OutputStream os = null; try { try { - URL actualLocation = getActualLocation(location, gzip); + URL actualLocation = getActualLocation(location, false); File artifactsFile = new File(actualLocation.getPath()); - if (!artifactsFile.exists()) { - // create parent folders - artifactsFile.getParentFile().mkdirs(); + File jarFile = new File(getActualLocation(location, true).getPath()); + if (!compress) { + if (jarFile.exists()) { + jarFile.delete(); + } + if (!artifactsFile.exists()) { + // create parent folders + artifactsFile.getParentFile().mkdirs(); + } + os = new FileOutputStream(artifactsFile); + } else { + if (artifactsFile.exists()) { + artifactsFile.delete(); + } + if (!jarFile.exists()) { + if (!jarFile.getParentFile().exists()) + jarFile.getParentFile().mkdirs(); + jarFile.createNewFile(); + } + JarOutputStream jOs = new JarOutputStream(new FileOutputStream(jarFile)); + jOs.putNextEntry(new JarEntry(new Path(actualLocation.getFile()).lastSegment())); + os = jOs; } - os = new FileOutputStream(artifactsFile); - if (gzip) - os = new GZIPOutputStream(os); new SimpleArtifactRepositoryIO().write(this, os); } catch (IOException e) { // TODO proper exception handling diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java index ec37d1dff..fdf38b19c 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java @@ -12,8 +12,10 @@ package org.eclipse.equinox.internal.p2.artifact.repository.simple; import java.io.*; import java.net.URL; -import java.util.zip.GZIPInputStream; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.equinox.internal.p2.artifact.repository.ECFTransport; import org.eclipse.equinox.internal.p2.artifact.repository.Transport; import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository; @@ -30,15 +32,15 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto // TODO This temporary file stuff is not very elegant. OutputStream artifacts = null; temp = File.createTempFile("artifacts", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ - // try with gzip - boolean gzip = true; + // try with compressed + boolean compress = true; try { artifacts = new BufferedOutputStream(new FileOutputStream(temp)); - IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, gzip).toExternalForm(), artifacts, null); + IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, null); if (!status.isOK()) { - // retry unzipped - gzip = false; - status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, gzip).toExternalForm(), artifacts, null); + // retry uncompressed + compress = false; + status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, null); if (!status.isOK()) return null; } @@ -49,8 +51,19 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto InputStream descriptorStream = null; try { descriptorStream = new BufferedInputStream(new FileInputStream(temp)); - if (gzip) - descriptorStream = new GZIPInputStream(descriptorStream); + if (compress) { + URL actualFile = SimpleArtifactRepository.getActualLocation(location, false); + JarInputStream jInStream = new JarInputStream(descriptorStream); + JarEntry jarEntry = jInStream.getNextJarEntry(); + String filename = new Path(actualFile.getFile()).lastSegment(); + while (jarEntry != null && !(filename.equals(jarEntry.getName()))) { + jarEntry = jInStream.getNextJarEntry(); + } + if (jarEntry == null) { + throw new FileNotFoundException("Repository not found in " + actualFile.getPath()); //$NON-NLS-1$ + } + descriptorStream = jInStream; + } SimpleArtifactRepositoryIO io = new SimpleArtifactRepositoryIO(); SimpleArtifactRepository result = (SimpleArtifactRepository) io.read(descriptorStream); result.initializeAfterLoad(location); |