Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsliebig2007-12-19 14:38:38 +0000
committersliebig2007-12-19 14:38:38 +0000
commitfe6cd37d700601f52c0ab373078697919fa28b99 (patch)
tree786c61c8e0fe39d49254b764dab906f1e6075842 /bundles/org.eclipse.equinox.p2.artifact.repository
parent2a78ee218afc91cb88d876d8df98a5f0fb9f77b3 (diff)
downloadrt.equinox.p2-fe6cd37d700601f52c0ab373078697919fa28b99.tar.gz
rt.equinox.p2-fe6cd37d700601f52c0ab373078697919fa28b99.tar.xz
rt.equinox.p2-fe6cd37d700601f52c0ab373078697919fa28b99.zip
support reading/writing of gzipped artifacts.xml
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository')
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java41
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java19
2 files changed, 47 insertions, 13 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 90aa2fcc6..ee4162f64 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,6 +12,7 @@ import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
+import java.util.zip.GZIPOutputStream;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.artifact.repository.*;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
@@ -35,6 +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 = ".gzip"; //$NON-NLS-1$
transient private Mapper mapper = new Mapper();
protected String[][] mappingRules = DEFAULT_MAPPING_RULES;
@@ -42,14 +44,19 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
private boolean signatureVerification = false;
private transient BlobStore blobStore;
- public static URL getActualLocation(URL base) {
+ public static URL getActualLocation(URL base, boolean gzip) {
+ return getActualLocation(base, gzip ? GZIP_EXTENSION : ""); //$NON-NLS-1$
+ }
+
+ private static URL getActualLocation(URL base, String extension) {
+ final String name = CONTENT_FILENAME + extension;
String spec = base.toExternalForm();
- if (spec.endsWith(CONTENT_FILENAME))
+ if (spec.endsWith(name))
return base;
if (spec.endsWith("/")) //$NON-NLS-1$
- spec += CONTENT_FILENAME;
+ spec += name;
else
- spec += "/" + CONTENT_FILENAME; //$NON-NLS-1$
+ spec += "/" + name; //$NON-NLS-1$
try {
return new URL(spec);
} catch (MalformedURLException e) {
@@ -402,11 +409,27 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
}
public void save() {
+ save(true);
+ }
+
+ public void save(boolean gzip) {
+ OutputStream os = null;
try {
- URL actualLocation = getActualLocation(location);
- FileOutputStream os = new FileOutputStream(actualLocation.getFile());
- new SimpleArtifactRepositoryIO().write(this, os);
+ try {
+ URL actualLocation = getActualLocation(location, gzip);
+ os = new FileOutputStream(actualLocation.getFile());
+ if (gzip)
+ os = new GZIPOutputStream(os);
+ new SimpleArtifactRepositoryIO().write(this, os);
+ } catch (IOException e) {
+ // TODO proper exception handling
+ e.printStackTrace();
+ } finally {
+ if (os != null)
+ os.close();
+ }
} catch (IOException e) {
+ // TODO proper exception handling
e.printStackTrace();
}
}
@@ -575,9 +598,9 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
}
public Object getAdapter(Class adapter) {
- // if we are adapting to file or writable repos then make sure we have a file location
+ // if we are adapting to file or writable repositories then make sure we have a file location
if (adapter == IFileArtifactRepository.class)
- if (!"file".equalsIgnoreCase(location.getProtocol()))
+ if (!"file".equalsIgnoreCase(location.getProtocol())) //$NON-NLS-1$
return null;
return super.getAdapter(adapter);
}
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 cc10fa454..ec37d1dff 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,6 +12,7 @@ package org.eclipse.equinox.internal.p2.artifact.repository.simple;
import java.io.*;
import java.net.URL;
+import java.util.zip.GZIPInputStream;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.artifact.repository.ECFTransport;
import org.eclipse.equinox.internal.p2.artifact.repository.Transport;
@@ -27,12 +28,20 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto
File temp = null;
try {
// TODO This temporary file stuff is not very elegant.
+ OutputStream artifacts = null;
temp = File.createTempFile("artifacts", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
- OutputStream artifacts = new BufferedOutputStream(new FileOutputStream(temp));
+ // try with gzip
+ boolean gzip = true;
try {
- IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location).toExternalForm(), artifacts, null);
- if (!status.isOK())
- return null;
+ artifacts = new BufferedOutputStream(new FileOutputStream(temp));
+ IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, gzip).toExternalForm(), artifacts, null);
+ if (!status.isOK()) {
+ // retry unzipped
+ gzip = false;
+ status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, gzip).toExternalForm(), artifacts, null);
+ if (!status.isOK())
+ return null;
+ }
} finally {
if (artifacts != null)
artifacts.close();
@@ -40,6 +49,8 @@ public class SimpleArtifactRepositoryFactory implements IArtifactRepositoryFacto
InputStream descriptorStream = null;
try {
descriptorStream = new BufferedInputStream(new FileInputStream(temp));
+ if (gzip)
+ descriptorStream = new GZIPInputStream(descriptorStream);
SimpleArtifactRepositoryIO io = new SimpleArtifactRepositoryIO();
SimpleArtifactRepository result = (SimpleArtifactRepository) io.read(descriptorStream);
result.initializeAfterLoad(location);

Back to the top