You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2011/08/09 11:43:32 UTC
svn commit: r1155290 - in /sling/trunk:
installer/core/src/main/java/org/apache/sling/installer/api/
installer/core/src/main/java/org/apache/sling/installer/core/impl/
installer/providers/file/
installer/providers/file/src/main/java/org/apache/sling/in...
Author: cziegeler
Date: Tue Aug 9 09:43:31 2011
New Revision: 1155290
URL: http://svn.apache.org/viewvc?rev=1155290&view=rev
Log:
SLING-2171 : Don't copy resources if they are always available (like from the file system)
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
sling/trunk/installer/providers/file/pom.xml
sling/trunk/installer/providers/file/src/main/java/org/apache/sling/installer/provider/file/impl/Installer.java
sling/trunk/launchpad/builder/src/main/bundles/list.xml
sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java Tue Aug 9 09:43:31 2011
@@ -95,6 +95,20 @@ public class InstallableResource {
*/
public static final String INSTALLATION_HINT = "installation.hint";
+ /**
+ * Optional parameter in the dictionary if a resource (not a dict) is installed.
+ * If this parameter is specified, the installer uses the URI to get the input
+ * stream of the resource! Usually the installer copies the resource into the
+ * file system and uses this copy. To optimize this, if the URI of the resource
+ * is always available (like a file URI), this property can be used to avoid
+ * copying the resource.
+ * It is only evaluated if the resource type is either unknown (null) or
+ * {@link #TYPE_FILE} and a digest for the resource is delivered.
+ * The value of this property is a string.
+ * @since 3.2.2
+ */
+ public static final String RESOURCE_URI_HINT = "resource.uri.hint";
+
/** Default resource priority */
public static final int DEFAULT_PRIORITY = 100;
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java Tue Aug 9 09:43:31 2011
@@ -54,14 +54,22 @@ public class InternalResource extends In
// an input stream or a dictionary
InputStream is = resource.getInputStream();
Dictionary<String, Object> dict = resource.getDictionary();
- String type = resource.getType();
+
// Handle deprecated types and map them to new types
+ String type = resource.getType();
if ( InstallableResource.TYPE_BUNDLE.equals(type) ) {
type = InstallableResource.TYPE_FILE;
} else if ( InstallableResource.TYPE_CONFIG.equals(type) ) {
type = InstallableResource.TYPE_PROPERTIES;
}
+ // check for optional uri (only if type is file and digest is available)
+ final String resourceUri = (dict != null
+ && (type == null || InstallableResource.TYPE_FILE.equals(type))
+ && resource.getDigest() != null
+ && resource.getDigest().length() > 0) ?
+ (String)dict.get(InstallableResource.RESOURCE_URI_HINT) : null;
+
if ( is != null &&
(InstallableResource.TYPE_PROPERTIES.equals(type) ||
((type == null || InstallableResource.TYPE_FILE.equals(type)) && isConfigExtension(resource.getId())))) {
@@ -80,18 +88,22 @@ public class InternalResource extends In
// we always compute a digest
digest = FileDataStore.computeDigest(dict);
} else {
- final String url = scheme + ':' + resource.getId();
- // if input stream is not null, file is expected!
- dataFile = FileDataStore.SHARED.createNewDataFile(is,
- url,
- resource.getDigest(),
- resource.getType());
- type = (type != null ? type : InstallableResource.TYPE_FILE);
- if (resource.getDigest() != null && resource.getDigest().length() > 0) {
+ if ( resourceUri != null ) {
digest = resource.getDigest();
} else {
- digest = FileDataStore.computeDigest(dataFile);
- FileDataStore.SHARED.updateDigestCache(url, digest);
+ final String url = scheme + ':' + resource.getId();
+ // if input stream is not null, file is expected!
+ dataFile = FileDataStore.SHARED.createNewDataFile(is,
+ url,
+ resource.getDigest(),
+ resource.getType());
+ type = (type != null ? type : InstallableResource.TYPE_FILE);
+ if (resource.getDigest() != null && resource.getDigest().length() > 0) {
+ digest = resource.getDigest();
+ } else {
+ digest = FileDataStore.computeDigest(dataFile);
+ FileDataStore.SHARED.updateDigestCache(url, digest);
+ }
}
}
return new InternalResource(scheme,
@@ -101,14 +113,18 @@ public class InternalResource extends In
type,
digest,
resource.getPriority(),
- dataFile);
+ dataFile,
+ resourceUri);
}
/** The unique resource url. */
private final String url;
/** The data file (if copied) */
- private File dataFile;
+ private final File dataFile;
+
+ /** The resource uri */
+ private final String resourceUri;
public InternalResource(
final String scheme,
@@ -118,10 +134,12 @@ public class InternalResource extends In
final String type,
final String digest,
final Integer priority,
- final File dataFile) {
+ final File dataFile,
+ final String resourceUri) {
super(id, is, dict, digest, type, priority);
this.url = scheme + ':' + id;
this.dataFile = dataFile;
+ this.resourceUri = resourceUri;
}
/** The unique url of the resource. */
@@ -155,6 +173,13 @@ public class InternalResource extends In
}
/**
+ * Return the resource uri (or null)
+ */
+ public String getResourceUri() {
+ return this.resourceUri;
+ }
+
+ /**
* Read dictionary from an input stream.
* We use the same logic as Apache Felix FileInstall here:
* - *.cfg files are treated as property files
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java Tue Aug 9 09:43:31 2011
@@ -705,7 +705,8 @@ public class OsgiInstallerImpl
(data.getDictionary() != null ? InstallableResource.TYPE_PROPERTIES : InstallableResource.TYPE_FILE),
data.getDigest(result.getURL(), result.getDigest()),
result.getPriority(),
- data.getDataFile());
+ data.getDataFile(),
+ null);
final RegisteredResource rr = this.persistentList.addOrUpdate(internalResource);
final TransformationResult transRes = new TransformationResult();
transRes.setId(entityId);
@@ -764,7 +765,8 @@ public class OsgiInstallerImpl
(data.getDictionary() != null ? InstallableResource.TYPE_PROPERTIES : InstallableResource.TYPE_FILE),
data.getDigest(result.getURL(), result.getDigest()),
result.getPriority(),
- data.getDataFile());
+ data.getDataFile(),
+ null);
final RegisteredResource rr = this.persistentList.addOrUpdate(internalResource);
final TransformationResult transRes = new TransformationResult();
transRes.setId(entityId);
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java Tue Aug 9 09:43:31 2011
@@ -116,22 +116,14 @@ public class PersistentResourceList {
private void updateCache() {
for(final EntityResourceList group : this.data.values()) {
for(final RegisteredResource rr : group.getResources()) {
- try {
- if ( rr.getInputStream() != null ) {
- FileDataStore.SHARED.updateDigestCache(rr.getURL(), rr.getDigest());
- }
- } catch (final IOException ioe) {
- // we just ignore this
+ if ( ((RegisteredResourceImpl)rr).hasDataFile() ) {
+ FileDataStore.SHARED.updateDigestCache(rr.getURL(), rr.getDigest());
}
}
}
for(final RegisteredResource rr : this.untransformedResources ) {
- try {
- if ( rr.getInputStream() != null ) {
- FileDataStore.SHARED.updateDigestCache(rr.getURL(), rr.getDigest());
- }
- } catch (final IOException ioe) {
- // we just ignore this
+ if ( ((RegisteredResourceImpl)rr).hasDataFile() ) {
+ FileDataStore.SHARED.updateDigestCache(rr.getURL(), rr.getDigest());
}
}
}
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java Tue Aug 9 09:43:31 2011
@@ -24,6 +24,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
@@ -47,7 +49,7 @@ public class RegisteredResourceImpl
private static final long serialVersionUID = 6L;
/** Serialization version. */
- private static final int VERSION = 2;
+ private static final int VERSION = 3;
/** The resource url. */
private String url;
@@ -67,6 +69,8 @@ public class RegisteredResourceImpl
/** Additional attributes. */
private final Map<String, Object> attributes = new HashMap<String, Object>();
+ private String dataUri;
+
private File dataFile;
private int priority;
@@ -105,6 +109,7 @@ public class RegisteredResourceImpl
out.writeInt(priority);
out.writeObject(state.toString());
out.writeLong(this.lastChange);
+ out.writeObject(this.dataUri);
}
/**
@@ -133,6 +138,9 @@ public class RegisteredResourceImpl
} else {
this.lastChange = 0;
}
+ if ( version > 2 ) {
+ this.dataUri = (String)in.readObject();
+ }
}
/**
@@ -143,6 +151,7 @@ public class RegisteredResourceImpl
throws IOException {
final int schemePos = input.getURL().indexOf(':');
return new RegisteredResourceImpl(input.getId(),
+ input.getResourceUri(),
input.getPrivateCopyOfFile(),
input.getPrivateCopyOfDictionary(),
input.getType(),
@@ -158,6 +167,7 @@ public class RegisteredResourceImpl
* The only exception is the digest!
*/
private RegisteredResourceImpl(final String id,
+ final String resourceUri,
final File file,
final Dictionary<String, Object> dict,
final String type,
@@ -165,6 +175,7 @@ public class RegisteredResourceImpl
final int priority,
final String scheme) {
this.url = scheme + ':' + id;
+ this.dataUri = resourceUri;
this.dataFile = file;
this.dictionary = dict;
this.resourceType = type;
@@ -210,6 +221,10 @@ public class RegisteredResourceImpl
return sb.toString();
}
+ public boolean hasDataFile() {
+ return this.dataFile != null;
+ }
+
/**
* Remove the data file
*/
@@ -217,6 +232,7 @@ public class RegisteredResourceImpl
if ( this.dataFile != null && this.dataFile.exists() ) {
dataFile.delete();
}
+ this.dataUri = null;
}
/**
@@ -241,6 +257,14 @@ public class RegisteredResourceImpl
* @see org.apache.sling.installer.api.tasks.RegisteredResource#getInputStream()
*/
public InputStream getInputStream() throws IOException {
+ if ( this.dataUri != null ) {
+ try {
+ final URI uri = new URI(this.dataUri);
+ return uri.toURL().openStream();
+ } catch (final URISyntaxException use) {
+ throw (IOException)new IOException().initCause(use);
+ }
+ }
if (this.dataFile != null && this.dataFile.exists() ) {
return new BufferedInputStream(new FileInputStream(this.dataFile));
}
@@ -492,6 +516,7 @@ public class RegisteredResourceImpl
final int schemePos = this.url.indexOf(':');
final RegisteredResourceImpl rr = new RegisteredResourceImpl(
this.url.substring(schemePos + 1),
+ this.dataUri,
this.dataFile,
this.dictionary,
this.resourceType,
Modified: sling/trunk/installer/providers/file/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/file/pom.xml?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/installer/providers/file/pom.xml (original)
+++ sling/trunk/installer/providers/file/pom.xml Tue Aug 9 09:43:31 2011
@@ -82,7 +82,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.installer.core</artifactId>
- <version>3.2.0</version>
+ <version>3.2.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- We use a class from the config admin implementation to read config files -->
Modified: sling/trunk/installer/providers/file/src/main/java/org/apache/sling/installer/provider/file/impl/Installer.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/file/src/main/java/org/apache/sling/installer/provider/file/impl/Installer.java?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/installer/providers/file/src/main/java/org/apache/sling/installer/provider/file/impl/Installer.java (original)
+++ sling/trunk/installer/providers/file/src/main/java/org/apache/sling/installer/provider/file/impl/Installer.java Tue Aug 9 09:43:31 2011
@@ -129,19 +129,19 @@ public class Installer
final InputStream is = new FileInputStream(file);
final String digest = String.valueOf(file.lastModified());
// if this is a bundle check for start level directory!
- Dictionary<String, Object> dict = null;
+ final Dictionary<String, Object> dict = new Hashtable<String, Object>();
if ( file.getName().endsWith(".jar") || file.getName().endsWith(".war") ) {
final String parentName = file.getParentFile().getName();
try {
final int startLevel = Integer.valueOf(parentName);
if ( startLevel > 0 ) {
- dict = new Hashtable<String, Object>();
dict.put(InstallableResource.BUNDLE_START_LEVEL, startLevel);
}
} catch (NumberFormatException nfe) {
// ignore this
}
}
+ dict.put(InstallableResource.RESOURCE_URI_HINT, file.toURI().toString());
return new InstallableResource(file.getAbsolutePath(), is, dict, digest,
null, null);
} catch (IOException io) {
Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Tue Aug 9 09:43:31 2011
@@ -213,7 +213,7 @@
<bundle>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.launchpad.installer</artifactId>
- <version>1.0.2</version>
+ <version>1.0.3-SNAPSHOT</version>
</bundle>
<bundle>
<groupId>org.apache.sling</groupId>
Modified: sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java?rev=1155290&r1=1155289&r2=1155290&view=diff
==============================================================================
--- sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java (original)
+++ sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java Tue Aug 9 09:43:31 2011
@@ -16,7 +16,10 @@
*/
package org.apache.sling.launchpad.installer.impl;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashSet;
@@ -62,13 +65,26 @@ public class LaunchpadConfigInstaller {
}
if ( !checkPath(resourceProvider, installables, path, resourceType) ) {
logger.info("Launchpad {} will be installed: {}", resourceType, path);
+ final URL url = resourceProvider.getResource(path);
Dictionary<String, Object> dict = null;
if ( InstallableResource.TYPE_FILE.equals(resourceType) ) {
dict = new Hashtable<String, Object>();
dict.put(InstallableResource.INSTALLATION_HINT, hint);
+ try {
+ dict.put(InstallableResource.RESOURCE_URI_HINT, url.toURI().toString());
+ } catch (final URISyntaxException e) {
+ // we just ignore this
+ }
}
+ long lastModified = -1;
+ try {
+ lastModified = url.openConnection().getLastModified();
+ } catch (final IOException e) {
+ // we ignore this
+ }
+ final String digest = (lastModified > 0 ? String.valueOf(lastModified) : null);
final InputStream stream = resourceProvider.getResourceAsStream(path);
- installables.add(new InstallableResource(path, stream, dict, null, resourceType, null));
+ installables.add(new InstallableResource(path, stream, dict, digest, resourceType, null));
count++;
}
}