Author: cziegeler
Date: Tue Mar 29 07:16:31 2011
New Revision: 1086501
URL: http://svn.apache.org/viewvc?rev=1086501&view=rev
Log:
SLING-2031 : Use bundle location to create path for persisting new
configurations
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/ResourceChangeListener.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/UpdateHandler.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/ResourceChangeListener.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/ResourceChangeListener.java?rev=1086501&r1=1086500&r2=1086501&view=diff
==============================================================================
---
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/ResourceChangeListener.java
(original)
+++
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/ResourceChangeListener.java
Tue Mar 29 07:16:31 2011
@@ -20,6 +20,7 @@ package org.apache.sling.installer.api;
import java.io.InputStream;
import java.util.Dictionary;
+import java.util.Map;
/**
@@ -44,7 +45,8 @@ public interface ResourceChangeListener
void resourceAddedOrUpdated(final String resourceType,
final String entityId,
final InputStream is,
- final Dictionary<String, Object> dict);
+ final Dictionary<String, Object> dict,
+ final Map<String, Object> attributes);
/**
* Inform the installer about a removed resource
Modified:
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/UpdateHandler.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/UpdateHandler.java?rev=1086501&r1=1086500&r2=1086501&view=diff
==============================================================================
---
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/UpdateHandler.java
(original)
+++
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/UpdateHandler.java
Tue Mar 29 07:16:31 2011
@@ -20,6 +20,7 @@ package org.apache.sling.installer.api;
import java.io.InputStream;
import java.util.Dictionary;
+import java.util.Map;
/**
@@ -38,12 +39,40 @@ public interface UpdateHandler {
String PROPERTY_SCHEMES = "handler.schemes";
/**
+ * Handle the remove of a resource
+ * @param resourceType The resource type
+ * @param id The resource id, e.g. symbolic name etc.
+ * @param url The url where an earlier version of this resource came from
+ * @return If the handler could handle/perist the resource an update
result is returned
+ * otherwise the handler should return <code>null</code>
+ */
+ UpdateResult handleRemoval(final String resourceType,
+ final String id,
+ final String url);
+
+ /**
+ * Handle the update of a resource
+ * @param resourceType The resource type
+ * @param id The resource id, e.g. symbolic name etc.
+ * @param url The url where an earlier version of this resource came from
(optional)
+ * @param dict Dictionary
+ * @param attributes Optional additional attributes.
+ * @return If the handler could handle/perist the resource an update
result is returned
+ * otherwise the handler should return <code>null</code>
+ */
+ UpdateResult handleUpdate(final String resourceType,
+ final String id,
+ final String url,
+ final Dictionary<String, Object> dict,
+ final Map<String, Object> attributes);
+
+ /**
* Handle the update of a resource
* @param resourceType The resource type
* @param id The resource id, e.g. symbolic name etc.
* @param url The url where an earlier version of this resource came from
(optional)
- * @param is Input stream to the contents of the resource (optional)
- * @param dict Dictionary (optional)
+ * @param is Input stream to the contents of the resource
+ * @param attributes Optional additional attributes.
* @return If the handler could handle/perist the resource an update
result is returned
* otherwise the handler should return <code>null</code>
*/
@@ -51,5 +80,5 @@ public interface UpdateHandler {
final String id,
final String url,
final InputStream is,
- final Dictionary<String, Object> dict);
+ final Map<String, Object> attributes);
}
\ No newline at end of file
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=1086501&r1=1086500&r2=1086501&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 Mar 29 07:16:31 2011
@@ -661,12 +661,13 @@ public class OsgiInstallerImpl
}
/**
- * @see
org.apache.sling.installer.api.ResourceChangeListener#resourceAddedOrUpdated(java.lang.String,
java.lang.String, java.io.InputStream, java.util.Dictionary)
+ * @see
org.apache.sling.installer.api.ResourceChangeListener#resourceAddedOrUpdated(java.lang.String,
java.lang.String, java.io.InputStream, java.util.Dictionary, Map)
*/
public void resourceAddedOrUpdated(final String resourceType,
String entityId,
final InputStream is,
- final Dictionary<String, Object> dict) {
+ final Dictionary<String, Object> dict,
+ final Map<String, Object> attributes) {
String key = resourceType + ':' + entityId;
try {
final ResourceData data = ResourceData.create(is, dict);
@@ -696,7 +697,8 @@ public class OsgiInstallerImpl
} else {
final InputStream localIS = data.getInputStream();
try {
- final UpdateResult result =
handler.handleUpdate(resourceType, entityId, tr.getURL(), localIS,
data.getDictionary());
+ final UpdateResult result = (localIS == null ?
handler.handleUpdate(resourceType, entityId, tr.getURL(), data.getDictionary(),
attributes)
+ :
handler.handleUpdate(resourceType, entityId, tr.getURL(), localIS, attributes));
if ( result != null ) {
if ( !result.getURL().equals(tr.getURL()) &&
!result.getResourceIsMoved() ) {
// resource has been added!
@@ -753,7 +755,8 @@ public class OsgiInstallerImpl
for(final UpdateHandler handler : handlerList) {
final InputStream localIS = data.getInputStream();
try {
- final UpdateResult result =
handler.handleUpdate(resourceType, entityId, null, localIS,
data.getDictionary());
+ final UpdateResult result = (localIS == null ?
handler.handleUpdate(resourceType, entityId, null, data.getDictionary(),
attributes)
+ :
handler.handleUpdate(resourceType, entityId, null, localIS, attributes));
if ( result != null ) {
final InternalResource internalResource = new
InternalResource(result.getScheme(),
result.getResourceId(),
@@ -831,7 +834,7 @@ public class OsgiInstallerImpl
logger.debug("No handler found to handle remove of
resource with scheme {}", tr.getScheme());
} else {
// we don't need to check the result, we just
check if a result is returned
- if ( handler.handleUpdate(resourceType,
resourceId, tr.getURL(), null, null) != null ) {
+ if ( handler.handleRemoval(resourceType,
resourceId, tr.getURL()) != null ) {
// We first set the state of the resource to
uninstall to make setFinishState work in all cases
((RegisteredResourceImpl)tr).setState(ResourceState.UNINSTALL);
erl.setFinishState(ResourceState.UNINSTALLED);
Modified:
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java?rev=1086501&r1=1086500&r2=1086501&view=diff
==============================================================================
---
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
(original)
+++
sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
Tue Mar 29 07:16:31 2011
@@ -103,7 +103,12 @@ public class ConfigTaskCreator
}
}
if ( persist ) {
-
this.changeListener.resourceAddedOrUpdated(InstallableResource.TYPE_CONFIG, id,
null, dict);
+ Map<String, Object> attrs = null;
+ if ( config.getBundleLocation() != null ) {
+ attrs = new HashMap<String, Object>();
+
attrs.put(InstallableResource.INSTALLATION_HINT, config.getBundleLocation());
+ }
+
this.changeListener.resourceAddedOrUpdated(InstallableResource.TYPE_CONFIG, id,
null, dict, attrs);
}
}
} catch ( final Exception ignore) {
Modified:
sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java?rev=1086501&r1=1086500&r2=1086501&view=diff
==============================================================================
---
sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
(original)
+++
sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
Tue Mar 29 07:16:31 2011
@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Dictionary;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
@@ -511,40 +512,84 @@ public class JcrInstaller implements Eve
}
/**
- * @see
org.apache.sling.installer.api.UpdateHandler#handleUpdate(java.lang.String,
java.lang.String, String, java.io.InputStream, java.util.Dictionary)
+ * @see
org.apache.sling.installer.api.UpdateHandler#handleRemoval(java.lang.String,
java.lang.String, java.lang.String)
+ */
+ public UpdateResult handleRemoval(final String resourceType,
+ final String id,
+ final String url) {
+ if ( !this.writeBack ) {
+ return null;
+ }
+ final int pos = url.indexOf(':');
+ final String path = url.substring(pos + 1);
+ // remove
+ logger.debug("Removal of {}", path);
+ Session session = null;
+ try {
+ session = this.repository.loginAdministrative(null);
+ if ( session.nodeExists(path) ) {
+ session.getNode(path).remove();
+ session.save();
+ }
+ } catch (final RepositoryException re) {
+ logger.error("Unable to remove resource from " + path, re);
+ return null;
+ } finally {
+ if ( session != null ) {
+ session.logout();
+ }
+ }
+ return new UpdateResult(url);
+ }
+
+ /**
+ * @see
org.apache.sling.installer.api.UpdateHandler#handleUpdate(java.lang.String,
java.lang.String, java.lang.String, java.util.Dictionary, Map)
+ */
+ public UpdateResult handleUpdate(final String resourceType,
+ final String id,
+ final String url,
+ final Dictionary<String, Object> dict,
+ final Map<String, Object> attributes) {
+ return this.handleUpdate(resourceType, id, url, null, dict,
attributes);
+ }
+
+ /**
+ * @see
org.apache.sling.installer.api.UpdateHandler#handleUpdate(java.lang.String,
java.lang.String, java.lang.String, java.io.InputStream, Map)
*/
public UpdateResult handleUpdate(final String resourceType,
final String id,
final String url,
final InputStream is,
- final Dictionary<String, Object> dict) {
+ final Map<String, Object> attributes) {
+ return this.handleUpdate(resourceType, id, url, is, null, attributes);
+ }
+
+ private String getPathWithHighestPrio(final String oldPath) {
+ final String path;
+ // check root path, we use the path with highest prio
+ final String rootPath = this.folderNameFilter.getRootPaths()[0] + '/';
+ if ( !oldPath.startsWith(rootPath) ) {
+ final int slashPos = oldPath.indexOf('/', 1);
+ path = rootPath + oldPath.substring(slashPos + 1);
+ } else {
+ path = oldPath;
+ }
+ return path;
+ }
+ /**
+ * Internal implementation of update handling
+ */
+ private UpdateResult handleUpdate(final String resourceType,
+ final String id,
+ final String url,
+ final InputStream is,
+ final Dictionary<String, Object> dict,
+ final Map<String, Object> attributes) {
if ( !this.writeBack ) {
return null;
}
- if ( is == null && dict == null ) {
- final int pos = url.indexOf(':');
- final String path = url.substring(pos + 1);
- // remove
- logger.debug("Removal of {}", path);
- Session session = null;
- try {
- session = this.repository.loginAdministrative(null);
- if ( session.nodeExists(path) ) {
- session.getNode(path).remove();
- session.save();
- }
- } catch (final RepositoryException re) {
- logger.error("Unable to remove resource from " + path, re);
- return null;
- } finally {
- if ( session != null ) {
- session.logout();
- }
- }
- return new UpdateResult(url);
- }
- // we only handle add and remove for configs for now
+ // we only handle add/update of configs for now
if ( !resourceType.equals(InstallableResource.TYPE_CONFIG) ) {
return null;
}
@@ -555,19 +600,32 @@ public class JcrInstaller implements Eve
// update
final int pos = url.indexOf(':');
final String oldPath = url.substring(pos + 1);
- // check root path, we use the path with highest prio
- final String rootPath = this.folderNameFilter.getRootPaths()[0] +
'/';
- if ( !oldPath.startsWith(rootPath) ) {
- final int slashPos = oldPath.indexOf('/', 1);
- path = rootPath + oldPath.substring(slashPos + 1);
- resourceIsMoved = false;
- } else {
- path = oldPath;
- }
+ path = getPathWithHighestPrio(oldPath);
+ resourceIsMoved = path.equals(oldPath);
logger.debug("Update of {} at {}", resourceType, path);
} else {
+ // check for path hint
+ String hint = null;
+ if ( attributes != null ) {
+ hint =
(String)attributes.get(InstallableResource.INSTALLATION_HINT);
+ if ( hint != null && hint.startsWith(URL_SCHEME + ':')) {
+ hint = hint.substring(URL_SCHEME.length() + 1);
+ final int lastSlash = hint.lastIndexOf('/');
+ if ( lastSlash < 1 ) {
+ hint = null;
+ } else {
+ int slashPos = hint.lastIndexOf('/', lastSlash - 1);
+ final String dirName = hint.substring(slashPos + 1,
lastSlash);
+ if ( "install".equals(dirName) ) {
+ hint =
this.getPathWithHighestPrio(hint.substring(0, slashPos + 1) + "config/");
+ } else {
+ hint = null;
+ }
+ }
+ }
+ }
// add
- path = this.newConfigPath + id;
+ path = (hint != null ? hint : this.newConfigPath) + id;
logger.debug("Add of {} at {}", resourceType, path);
}