You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2017/03/09 17:31:23 UTC

svn commit: r1786207 - in /sling/trunk/tooling/maven/maven-sling-plugin: ./ src/main/java/org/apache/sling/maven/bundlesupport/ src/main/java/org/apache/sling/maven/bundlesupport/fsresource/

Author: sseifert
Date: Thu Mar  9 17:31:22 2017
New Revision: 1786207

URL: http://svn.apache.org/viewvc?rev=1786207&view=rev
Log:
SLING-6630 maven-sling-plugin: Support Mount FileVault XML for File System Resource Provider

Added:
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java   (with props)
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java   (with props)
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java   (with props)
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java   (with props)
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java   (with props)
Removed:
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountHelper.java
Modified:
    sling/trunk/tooling/maven/maven-sling-plugin/pom.xml
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractFsMountMojo.java
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsUnMountMojo.java
    sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java

Modified: sling/trunk/tooling/maven/maven-sling-plugin/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/pom.xml?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/pom.xml (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/pom.xml Thu Mar  9 17:31:22 2017
@@ -119,6 +119,17 @@
             <version>1.0-alpha-1</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit.vault</groupId>
+            <artifactId>org.apache.jackrabbit.vault</artifactId>
+            <version>3.1.18</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+            <scope>compile</scope>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.sling</groupId>

Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java Thu Mar  9 17:31:22 2017
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.maven.bundlesupport;
 
+import static org.apache.sling.maven.bundlesupport.JsonSupport.JSON_MIME_TYPE;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -37,12 +39,10 @@ import org.apache.commons.httpclient.met
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
+import org.apache.sling.maven.bundlesupport.fsresource.SlingInitialContentMounter;
 
 abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo {
 
-    /** Mime type for json response. */
-    public static final String JSON_MIME_TYPE = "application/json";
-
     /**
      * If a PUT via WebDAV should be used instead of the standard POST to the
      * Felix Web Console. In the <code>uninstall</code> goal, a HTTP DELETE will be
@@ -185,13 +185,12 @@ abstract class AbstractBundleInstallMojo
         }
 
         if ( mountByFS ) {
-            configure(targetURL, bundleFile);
+            configure(getConsoleTargetURL(), bundleFile);
         }
     }
     
     protected void configure(final String targetURL, final File file) throws MojoExecutionException {
-        FsMountHelper fsMountHelper = new FsMountHelper(getLog(), getHttpClient(), project);
-        fsMountHelper.configureInstall(targetURL, file);
+        new SlingInitialContentMounter(getLog(), getHttpClient(), project).mount(targetURL, file);
     }
 
     /**

Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundlePostMojo.java Thu Mar  9 17:31:22 2017
@@ -27,6 +27,7 @@ import org.apache.commons.httpclient.Cre
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugins.annotations.Parameter;
 
@@ -39,6 +40,13 @@ abstract class AbstractBundlePostMojo ex
     protected String slingUrl;
 
     /**
+     * The WebConsole URL of the running Sling instance. This is required for file system provider operations.
+     * If not configured the value of slingUrl is used.
+     */
+    @Parameter(property="sling.console.url")
+    protected String slingConsoleUrl;
+        
+    /**
      * An optional url suffix which will be appended to the <code>sling.url</code>
      * for use as the real target url. This allows to configure different target URLs
      * in each POM, while using the same common <code>sling.url</code> in a parent
@@ -132,14 +140,24 @@ abstract class AbstractBundlePostMojo ex
     }
 
     /**
-     * Returns the combination of <code>sling.url</code> and
-     * <code>sling.urlSuffix</code>.
+     * Returns the combination of <code>sling.url</code> and <code>sling.urlSuffix</code>.
      */
     protected String getTargetURL() {
         String targetURL = slingUrl;
         if (slingUrlSuffix != null) {
             targetURL += slingUrlSuffix;
         }
+        return targetURL;
+    }
+
+    /**
+     * Returns the combination of <code>sling.console.url</code> and <code>sling.urlSuffix</code>.
+     */
+    protected String getConsoleTargetURL() {
+        String targetURL = StringUtils.defaultString(slingConsoleUrl, slingUrl);
+        if (slingUrlSuffix != null) {
+            targetURL += slingUrlSuffix;
+        }
         return targetURL;
     }
 

Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractFsMountMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractFsMountMojo.java?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractFsMountMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractFsMountMojo.java Thu Mar  9 17:31:22 2017
@@ -18,7 +18,10 @@
 package org.apache.sling.maven.bundlesupport;
 
 import java.io.File;
+import java.util.List;
 
+import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
@@ -35,24 +38,101 @@ abstract class AbstractFsMountMojo exten
     private String bundleFileName;
 
     /**
+     * FileVault filesystem layout content root folder.
+     */
+    @Parameter(property = "sling.filevault.jcr_root.file")
+    private File fileVaultJcrRootFile;
+
+    /**
+     * Path to META-INF/vault/filter.xml when using FileVault XML filesystem
+     * layout.
+     */
+    @Parameter(property = "sling.filevault.filterxml.file")
+    private File fileVaultFilterXmlFile;
+
+    /**
      * The Maven project.
      */
     @Parameter(defaultValue = "${project}", required = true, readonly = true)
     protected MavenProject project;
-    
+
     @Override
     public void execute() throws MojoExecutionException {
+        String targetUrl = getConsoleTargetURL();
         
         // check for Sling-Initial-Content
-        File file = new File(bundleFileName);
-        if (file.exists()) {
-            configureSlingInitialContent(getTargetURL(), file);
+        File bundleFile = new File(bundleFileName);
+        if (bundleFile.exists()) {
+            configureSlingInitialContent(targetUrl, bundleFile);
+            return;
+        }
+        
+        // try to detect filevault layout
+        File jcrRootFile;
+        File filterXmlFile;
+        if (fileVaultJcrRootFile != null) {
+            jcrRootFile = fileVaultJcrRootFile;
+        }
+        else {
+            jcrRootFile = detectJcrRootFile();
+        }
+        if (fileVaultFilterXmlFile != null) {
+            filterXmlFile = fileVaultFilterXmlFile;
+        }
+        else {
+            filterXmlFile = detectFilterXmlFile();
+        }
+        if (jcrRootFile != null && jcrRootFile.exists() && filterXmlFile != null && filterXmlFile.exists()) {
+            configureFileVaultXml(targetUrl, jcrRootFile, filterXmlFile);
             return;
         }
         
-        getLog().info(file + " does not exist, skipping.");
+        getLog().info(bundleFile + " does not exist, skipping.");
+    }
+
+    @SuppressWarnings("unchecked")
+    private File detectJcrRootFile() {
+        List<Resource> resources = project.getResources();
+        if (resources != null) {
+            for (Resource resource : resources) {
+                File dir = new File(resource.getDirectory());
+                if (dir.exists() && dir.isDirectory() && StringUtils.equals(dir.getName(), "jcr_root")) {
+                    return dir;
+                }
+            }
+        }
+        return null;
     }
-    
-    protected abstract void configureSlingInitialContent(final String targetUrl, final File file) throws MojoExecutionException;
+
+    @SuppressWarnings("unchecked")
+    private File detectFilterXmlFile() {
+        List<Resource> resources = project.getResources();
+        if (resources != null) {
+            for (Resource resource : resources) {
+                File dir = new File(resource.getDirectory());
+                if (dir.exists() && dir.isDirectory() ) {
+                    if (StringUtils.equals(dir.getName(), "META-INF")) {
+                        File filterXml = new File(dir, "vault/filter.xml");
+                        if (filterXml.exists()) {
+                            return filterXml;
+                        }
+                    }
+                    else if (StringUtils.equals(dir.getName(), "vault")) {
+                        File filterXml = new File(dir, "filter.xml");
+                        if (filterXml.exists()) {
+                            return filterXml;
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    protected abstract void configureSlingInitialContent(final String targetUrl, final File bundleFile)
+            throws MojoExecutionException;
+
+    protected abstract void configureFileVaultXml(final String targetUrl, final File jcrRootFile, final File filterXmlFile)
+            throws MojoExecutionException;
 
 }
\ No newline at end of file

Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java Thu Mar  9 17:31:22 2017
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.maven.bundlesupport;
 
+import static org.apache.sling.maven.bundlesupport.JsonSupport.JSON_MIME_TYPE;
+
 import java.io.File;
 
 import org.apache.commons.httpclient.HttpStatus;
@@ -29,6 +31,7 @@ import org.apache.commons.httpclient.met
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.sling.maven.bundlesupport.fsresource.SlingInitialContentMounter;
 
 /**
  * Uninstall an OSGi bundle from a running Sling instance.
@@ -164,8 +167,7 @@ public class BundleUninstallMojo extends
 
     @Override
     protected void configure(final String targetURL, final File file) throws MojoExecutionException {
-        FsMountHelper fsMountHelper = new FsMountHelper(getLog(), getHttpClient(), project);
-        fsMountHelper.configureUninstall(targetURL, file);
+        new SlingInitialContentMounter(getLog(), getHttpClient(), project).unmount(targetURL, file);
     }
     
 }
\ No newline at end of file

Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsMountMojo.java Thu Mar  9 17:31:22 2017
@@ -21,6 +21,8 @@ import java.io.File;
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.sling.maven.bundlesupport.fsresource.FileVaultXmlMounter;
+import org.apache.sling.maven.bundlesupport.fsresource.SlingInitialContentMounter;
 
 /**
  * Creates OSGi configurations for File System Resource provider.
@@ -29,9 +31,13 @@ import org.apache.maven.plugins.annotati
 public class FsMountMojo extends AbstractFsMountMojo {
 
     @Override
-    protected void configureSlingInitialContent(final String targetUrl, final File file) throws MojoExecutionException {
-        FsMountHelper fsMountHelper = new FsMountHelper(getLog(), getHttpClient(), project);
-        fsMountHelper.configureInstall(targetUrl, file);
+    protected void configureSlingInitialContent(final String targetUrl, final File bundleFile) throws MojoExecutionException {
+        new SlingInitialContentMounter(getLog(), getHttpClient(), project).mount(targetUrl, bundleFile);
+    }
+
+    @Override
+    protected void configureFileVaultXml(String targetUrl, File jcrRootFile, File filterXmlFile) throws MojoExecutionException {
+        new FileVaultXmlMounter(getLog(), getHttpClient(), project).mount(targetUrl, jcrRootFile, filterXmlFile);
     }
 
 }
\ No newline at end of file

Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsUnMountMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsUnMountMojo.java?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsUnMountMojo.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/FsUnMountMojo.java Thu Mar  9 17:31:22 2017
@@ -21,6 +21,8 @@ import java.io.File;
 
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.sling.maven.bundlesupport.fsresource.FileVaultXmlMounter;
+import org.apache.sling.maven.bundlesupport.fsresource.SlingInitialContentMounter;
 
 /**
  * Removes OSGi configurations for File System Resource provider.
@@ -29,9 +31,13 @@ import org.apache.maven.plugins.annotati
 public class FsUnMountMojo extends AbstractFsMountMojo {
 
     @Override
-    protected void configureSlingInitialContent(final String targetUrl, final File file) throws MojoExecutionException {
-        FsMountHelper fsMountHelper = new FsMountHelper(getLog(), getHttpClient(), project);
-        fsMountHelper.configureUninstall(targetUrl, file);
+    protected void configureSlingInitialContent(final String targetUrl, final File bundleFile) throws MojoExecutionException {
+        new SlingInitialContentMounter(getLog(), getHttpClient(), project).unmount(targetUrl, bundleFile);
+    }
+
+    @Override
+    protected void configureFileVaultXml(String targetUrl, File jcrRootFile, File filterXmlFile) throws MojoExecutionException {
+        new FileVaultXmlMounter(getLog(), getHttpClient(), project).unmount(targetUrl, jcrRootFile, filterXmlFile);
     }
 
 }
\ No newline at end of file

Modified: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java?rev=1786207&r1=1786206&r2=1786207&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java (original)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/JsonSupport.java Thu Mar  9 17:31:22 2017
@@ -32,8 +32,11 @@ import javax.json.JsonObjectBuilder;
 import javax.json.JsonReader;
 import javax.json.JsonReaderFactory;
 
-final class JsonSupport {
+public final class JsonSupport {
 
+    /** Mime type for json response. */
+    public static final String JSON_MIME_TYPE = "application/json";
+    
     private static final JsonReaderFactory JSON_READER_FACTORY;
     static {
         // allow comments in JSON files

Added: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java?rev=1786207&view=auto
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java (added)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java Thu Mar  9 17:31:22 2017
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.maven.bundlesupport.fsresource;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Manages OSGi configurations for File System Resource Provider for File Vault XML.
+ */
+public final class FileVaultXmlMounter {
+    
+    private final Log log;
+    private final FsMountHelper helper;
+
+    public FileVaultXmlMounter(Log log, HttpClient httpClient, MavenProject project) {
+        this.log = log;
+        this.helper = new FsMountHelper(log, httpClient, project);
+    }
+
+    /**
+     * Add configurations to a running OSGi instance for FileVault XML
+     * @param targetUrl The web console base url
+     * @param file The artifact (bundle)
+     * @throws MojoExecutionException
+     */
+    public void mount(final String targetUrl, final File jcrRootFile, final File filterXmlFile) throws MojoExecutionException {
+        log.info("Trying to configure file system provider...");
+
+        // create config for each path defined in filter
+        final List<FsResourceConfiguration> cfgs = new ArrayList<>();
+        WorkspaceFilter workspaceFilter = getWorkspaceFilter(filterXmlFile);
+        for (PathFilterSet filterSet : workspaceFilter.getFilterSets()) {
+            cfgs.add(new FsResourceConfiguration()
+                    .fsMode(FsMode.FILEVAULT_XML)
+                    .contentRootDir(jcrRootFile.getAbsolutePath())
+                    .providerRootPath(filterSet.getRoot())
+                    .fileVaultFilterXml(filterXmlFile.getAbsolutePath()));
+        }
+     
+        if (!cfgs.isEmpty()) {
+            helper.addConfigurations(targetUrl, cfgs);
+        }
+    }
+    
+    /**
+     * Remove configurations to a running OSGi instance for FileVault XML
+     * @param targetUrl The web console base url
+     * @param file The artifact (bundle)
+     * @throws MojoExecutionException
+     */
+    public void unmount(final String targetUrl, final File jcrRootFile, final File filterXmlFile) throws MojoExecutionException {
+        log.info("Removing file system provider configurations...");
+
+        // remove all current configs for this project
+        final Map<String,FsResourceConfiguration> oldConfigs = helper.getCurrentConfigurations(targetUrl);
+        helper.removeConfigurations(targetUrl, oldConfigs);
+    }
+        
+    private WorkspaceFilter getWorkspaceFilter(final File filterXmlFile) throws MojoExecutionException {
+        try {
+            DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();
+            workspaceFilter.load(filterXmlFile);
+            return workspaceFilter;
+        }
+        catch (IOException | ConfigurationException ex) {
+            throw new MojoExecutionException("Unable to parse workspace filter: " + filterXmlFile.getPath(), ex);
+        }
+    }
+    
+}

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar  9 17:31:22 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FileVaultXmlMounter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java?rev=1786207&view=auto
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java (added)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java Thu Mar  9 17:31:22 2017
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.maven.bundlesupport.fsresource;
+
+/**
+ * Different modes for Filesystem provider support and filesystem layouts.
+ */
+enum FsMode {
+    
+    /**
+     * Sling-Initial-Content filesystem layout, with full support for JSON and jcr.xml content files.
+     */
+    INITIAL_CONTENT,
+    
+    /**
+     * Sling-Initial-Content filesystem layout, support only files and folders (classic mode).
+     */
+    INITIAL_CONTENT_FILES_FOLDERS,
+
+    /**
+     * FileVault XML format (expanded content package).
+     */
+    FILEVAULT_XML
+
+}

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar  9 17:31:22 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java?rev=1786207&view=auto
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java (added)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java Thu Mar  9 17:31:22 2017
@@ -0,0 +1,302 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.maven.bundlesupport.fsresource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.CharEncoding;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.sling.maven.bundlesupport.JsonSupport;
+
+/**
+ * Manages OSGi configurations for File System Resource Provider.
+ */
+final class FsMountHelper {
+    
+    /** The fs resource provider factory. */
+    private static final String FS_FACTORY = "org.apache.sling.fsprovider.internal.FsResourceProvider";
+    /** Http header for content type. */
+    private static final String HEADER_CONTENT_TYPE = "Content-Type";
+    
+    private static final String PROPERTY_FSMODE = "provider.fs.mode";
+    private static final String PROPERTY_ROOT = "provider.root";
+    private static final String PROPERTY_ROOTS = "provider.roots";
+    private static final String PROPERTY_PATH = "provider.file";
+    private static final String PROPERTY_INITIAL_CONTENT_IMPORT_OPTIONS = "provider.initial.content.import.options";
+    private static final String PROPERTY_FILEVAULT_FILTER_XML = "provider.filevault.filterxml.path";
+        
+    private final Log log;
+    private final HttpClient httpClient;
+    private final MavenProject project;
+
+    public FsMountHelper(Log log, HttpClient httpClient, MavenProject project) {
+        this.log = log;
+        this.httpClient = httpClient;
+        this.project = project;
+    }
+    
+    /**
+     * Adds as set of new configurations and removes old ones.
+     */
+    public void addConfigurations(final String targetUrl, Collection<FsResourceConfiguration> cfgs) throws MojoExecutionException {
+        final Map<String,FsResourceConfiguration> oldConfigs = getCurrentConfigurations(targetUrl);
+
+        for (FsResourceConfiguration cfg : cfgs) {
+            log.info("Mapping " + cfg.getContentRootDir() + " to " + cfg.getProviderRootPath());
+            
+            // check if this is already configured
+            boolean found = false;
+            final Iterator<Map.Entry<String,FsResourceConfiguration>> entryIterator = oldConfigs.entrySet().iterator();
+            while ( !found && entryIterator.hasNext() ) {
+                final Map.Entry<String,FsResourceConfiguration> current = entryIterator.next();
+                final FsResourceConfiguration oldcfg = current.getValue();
+                log.debug("Comparing " + oldcfg.getContentRootDir() + " with " + oldcfg);
+                if (StringUtils.equals(oldcfg.getContentRootDir(), oldcfg.getContentRootDir())) {
+                    if (cfg.equals(oldcfg)) {
+                        log.debug("Using existing configuration for " + cfg.getContentRootDir() + " and " + cfg.getProviderRootPath());
+                        found = true;
+                    }
+                    else {
+                        // remove old config
+                        log.debug("Removing old configuration for " + oldcfg);
+                        removeConfiguration(targetUrl, current.getKey());
+                    }
+                    entryIterator.remove();
+                }
+            }
+            if ( !found ) {
+                log.debug("Adding new configuration for " + cfg.getContentRootDir() + " and " + cfg.getProviderRootPath());
+                addConfiguration(targetUrl, cfg);
+            }
+        }
+        
+        // finally remove old configs
+        removeConfigurations(targetUrl, oldConfigs);
+    }
+    
+    /**
+     * Add a new configuration for the file system provider
+     */
+    private void addConfiguration(final String targetUrl, FsResourceConfiguration cfg) throws MojoExecutionException {
+        final String postUrl = targetUrl  + "/configMgr/" + FS_FACTORY;
+        final PostMethod post = new PostMethod(postUrl);
+        post.addParameter("apply", "true");
+        post.addParameter("factoryPid", FS_FACTORY);
+        post.addParameter("pid", "[Temporary PID replaced by real PID upon save]");
+        Map<String,String> props = toMap(cfg);
+        for (Map.Entry<String,String> entry : props.entrySet()) {
+            post.addParameter(entry.getKey(), entry.getValue());
+        }
+        post.addParameter("propertylist", StringUtils.join(props.keySet(), ","));
+        try {
+            final int status = httpClient.executeMethod(post);
+            // we get a moved temporarily back from the configMgr plugin
+            if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_OK) {
+                log.info("Configuration created.");
+            }
+            else {
+                log.error("Configuration on " + postUrl + " failed, cause: " + HttpStatus.getStatusText(status));
+            }
+        }
+        catch (HttpException ex) {
+            throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex);
+        }
+        catch (IOException ex) {
+            throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex);
+        }
+        finally {
+            post.releaseConnection();
+        }
+    }
+    
+    private Map<String,String> toMap(FsResourceConfiguration cfg) {
+        Map<String,String> props = new HashMap<>();
+        if (cfg.getFsMode() != null) {
+            props.put(PROPERTY_FSMODE, cfg.getFsMode().name());
+        }
+        if (cfg.getContentRootDir() != null) {
+            props.put(PROPERTY_PATH, cfg.getContentRootDir());
+        }
+        if (cfg.getProviderRootPath() != null) {
+            // save property value to both "provider.roots" and "provider.root" because the name has changed between fsresource 1.x and 2.x
+            props.put(PROPERTY_ROOT, cfg.getProviderRootPath());
+            props.put(PROPERTY_ROOTS, cfg.getProviderRootPath());
+        }
+        if (cfg.getInitialContentImportOptions() != null) {
+            props.put(PROPERTY_INITIAL_CONTENT_IMPORT_OPTIONS, cfg.getInitialContentImportOptions());
+        }
+        if (cfg.getStringVaultFilterXml() != null) {
+            props.put(PROPERTY_FILEVAULT_FILTER_XML, cfg.getStringVaultFilterXml());
+        }
+        return props;
+    }
+    
+    /**
+     * Remove all configurations contained in the given config map.
+     */
+    public void removeConfigurations(final String targetUrl, Map<String,FsResourceConfiguration> configs) throws MojoExecutionException {
+        for (Map.Entry<String,FsResourceConfiguration>  current : configs.entrySet()) {
+            log.debug("Removing configuration for " + current.getValue());
+            // remove old config
+            removeConfiguration(targetUrl, current.getKey());
+        }
+    }
+
+    /**
+     * Remove configuration.
+     */
+    private void removeConfiguration(final String targetUrl, final String pid) throws MojoExecutionException {
+        final String postUrl = targetUrl  + "/configMgr/" + pid;
+        final PostMethod post = new PostMethod(postUrl);
+        post.addParameter("apply", "true");
+        post.addParameter("delete", "true");
+        try {
+            final int status = httpClient.executeMethod(post);
+            // we get a moved temporarily back from the configMgr plugin
+            if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_OK) {
+                log.debug("Configuration removed.");
+            }
+            else {
+                log.error("Removing configuration failed, cause: "+ HttpStatus.getStatusText(status));
+            }
+        }
+        catch (HttpException ex) {
+            throw new MojoExecutionException("Removing configuration at " + postUrl
+                    + " failed, cause: " + ex.getMessage(), ex);
+        }
+        catch (IOException ex) {
+            throw new MojoExecutionException("Removing configuration at " + postUrl
+                    + " failed, cause: " + ex.getMessage(), ex);
+        }
+        finally {
+            post.releaseConnection();
+        }
+    }
+
+    /**
+     * Return all file provider configs for this project
+     * @param targetUrl The targetUrl of the webconsole
+     * @return A map (may be empty) with the pids as keys and the configurations as values
+     * @throws MojoExecutionException
+     */
+    public Map<String,FsResourceConfiguration> getCurrentConfigurations(final String targetUrl) throws MojoExecutionException {
+        log.debug("Getting current file provider configurations.");
+        final Map<String,FsResourceConfiguration> result = new HashMap<>();
+        final String getUrl = targetUrl  + "/configMgr/(service.factoryPid=" + FS_FACTORY + ").json";
+        final GetMethod get = new GetMethod(getUrl);
+
+        try {
+            final int status = httpClient.executeMethod(get);
+            if ( status == 200 ) {
+                String contentType = get.getResponseHeader(HEADER_CONTENT_TYPE).getValue();
+                int pos = contentType.indexOf(';');
+                if ( pos != -1 ) {
+                    contentType = contentType.substring(0, pos);
+                }
+                if ( !JsonSupport.JSON_MIME_TYPE.equals(contentType) ) {
+                    log.debug("Response type from web console is not JSON, but " + contentType);
+                    throw new MojoExecutionException("The Apache Felix Web Console is too old to mount " +
+                            "the initial content through file system provider configs. " +
+                            "Either upgrade the web console or disable this feature.");
+                }
+                final String jsonText;
+                try (InputStream jsonResponse = get.getResponseBodyAsStream()) {
+                    jsonText = IOUtils.toString(jsonResponse, CharEncoding.UTF_8);
+                }
+                try {
+                    JsonArray array = JsonSupport.parseArray(jsonText);
+                    for(int i=0; i<array.size(); i++) {
+                        final JsonObject obj = array.getJsonObject(i);
+                        final String pid = obj.getString("pid");
+                        final JsonObject properties = obj.getJsonObject("properties");
+                        final String fsmode = getConfigPropertyValue(properties, PROPERTY_FSMODE);
+                        final String path = getConfigPropertyValue(properties, PROPERTY_PATH);
+                        final String initialContentImportOptions = getConfigPropertyValue(properties, PROPERTY_INITIAL_CONTENT_IMPORT_OPTIONS);
+                        final String fileVaultFilterXml = getConfigPropertyValue(properties, PROPERTY_FILEVAULT_FILTER_XML);
+                        String root = getConfigPropertyValue(properties, PROPERTY_ROOTS);
+                        if (root == null) {
+                            root = getConfigPropertyValue(properties, PROPERTY_ROOT);
+                        }
+                        if (path != null && path.startsWith(this.project.getBasedir().getAbsolutePath()) && root != null) {
+                            FsResourceConfiguration cfg = new FsResourceConfiguration()
+                                    .fsMode(fsmode)
+                                    .providerRootPath(path)
+                                    .contentRootDir(root)
+                                    .initialContentImportOptions(initialContentImportOptions)
+                                    .fileVaultFilterXml(fileVaultFilterXml);
+                            log.debug("Found configuration with pid: " + pid + ", " + cfg);
+                            result.put(pid, cfg);
+                        }
+                    }
+                } catch (JsonException ex) {
+                    throw new MojoExecutionException("Reading configuration from " + getUrl
+                            + " failed, cause: " + ex.getMessage(), ex);
+                }
+            }
+        }
+        catch (HttpException ex) {
+            throw new MojoExecutionException("Reading configuration from " + getUrl
+                    + " failed, cause: " + ex.getMessage(), ex);
+        }
+        catch (IOException ex) {
+            throw new MojoExecutionException("Reading configuration from " + getUrl
+                    + " failed, cause: " + ex.getMessage(), ex);
+        }
+        finally {
+            get.releaseConnection();
+        }
+        return result;
+    }
+    
+    private String getConfigPropertyValue(JsonObject obj, String subKey) {
+        if (obj.containsKey(subKey)) {
+            JsonObject subObj = obj.getJsonObject(subKey);
+            if (subObj.containsKey("value")) {
+                return subObj.getString("value");
+            }
+            else if (subObj.containsKey("values")) {
+                JsonArray array = subObj.getJsonArray("values");
+                if (array.size() > 0) {
+                    // use only first property value from array
+                    return array.getString(0);
+                }
+            }
+        }
+        return null;
+    }
+
+}

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar  9 17:31:22 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java?rev=1786207&view=auto
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java (added)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java Thu Mar  9 17:31:22 2017
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.maven.bundlesupport.fsresource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+class FsResourceConfiguration {
+
+    private FsMode fsMode;
+    private String providerRootPath;
+    private String contentRootDir;
+    private String initialContentImportOptions;
+    private String fileVaultFilterXml;
+
+    public FsMode getFsMode() {
+        return fsMode;
+    }
+    public FsResourceConfiguration fsMode(FsMode value) {
+        this.fsMode = value;
+        return this;
+    }
+    public FsResourceConfiguration fsMode(String value) {
+        if (StringUtils.isBlank(value)) {
+            this.fsMode = null;
+        }
+        else {
+            this.fsMode = FsMode.valueOf(StringUtils.upperCase(value));
+        }
+        return this;
+    }
+
+    public String getProviderRootPath() {
+        return providerRootPath;
+    }
+    public FsResourceConfiguration providerRootPath(String value) {
+        this.providerRootPath = value;
+        return this;
+    }
+
+    public String getContentRootDir() {
+        return contentRootDir;
+    }
+    public FsResourceConfiguration contentRootDir(String value) {
+        this.contentRootDir = value;
+        return this;
+    }
+
+    public String getInitialContentImportOptions() {
+        return initialContentImportOptions;
+    }
+    public FsResourceConfiguration initialContentImportOptions(String value) {
+        this.initialContentImportOptions = value;
+        return this;
+    }
+
+    public String getStringVaultFilterXml() {
+        return fileVaultFilterXml;
+    }
+    public FsResourceConfiguration fileVaultFilterXml(String value) {
+        this.fileVaultFilterXml = value;
+        return this;
+    }
+    
+    @Override
+    public int hashCode() {
+        return HashCodeBuilder.reflectionHashCode(this);
+    }
+    @Override
+    public boolean equals(Object obj) {
+        return EqualsBuilder.reflectionEquals(this, obj);
+    }
+    @Override
+    public String toString() {
+        return ToStringBuilder.reflectionToString(this, ToStringStyle.NO_CLASS_NAME_STYLE);
+    }
+
+}

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar  9 17:31:22 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsResourceConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java?rev=1786207&view=auto
==============================================================================
--- sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java (added)
+++ sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java Thu Mar  9 17:31:22 2017
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.maven.bundlesupport.fsresource;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.commons.osgi.ManifestHeader.Entry;
+
+/**
+ * Manages OSGi configurations for File System Resource Provider for Sling-Initial-Content.
+ */
+public final class SlingInitialContentMounter {
+    
+    /** Header containing the sling initial content information. */
+    private static final String HEADER_INITIAL_CONTENT = "Sling-Initial-Content";
+    
+    private final Log log;
+    private final MavenProject project;
+    private final FsMountHelper helper;
+
+    public SlingInitialContentMounter(Log log, HttpClient httpClient, MavenProject project) {
+        this.log = log;
+        this.project = project;
+        this.helper = new FsMountHelper(log, httpClient, project);
+    }
+
+    /**
+     * Add configurations to a running OSGi instance for initial content.
+     * @param targetUrl The web console base url
+     * @param bundleFile The artifact (bundle)
+     * @throws MojoExecutionException
+     */
+    public void mount(final String targetUrl, final File bundleFile) throws MojoExecutionException {
+        // first, let's get the manifest and see if initial content is configured
+        ManifestHeader header = null;
+        try {
+            final Manifest mf = getManifest(bundleFile);
+            final String value = mf.getMainAttributes().getValue(HEADER_INITIAL_CONTENT);
+            if ( value == null ) {
+                log.debug("Bundle has no initial content - no file system provider config created.");
+                return;
+            }
+            header = ManifestHeader.parse(value);
+            if ( header == null || header.getEntries().length == 0 ) {
+                log.warn("Unable to parse header or header is empty: " + value);
+                return;
+            }
+        } catch (IOException ioe) {
+            throw new MojoExecutionException("Unable to read manifest from file " + bundleFile, ioe);
+        }
+
+        log.info("Trying to configure file system provider...");
+        // quick check if resources are configured
+        final List resources = project.getResources();
+        if ( resources == null || resources.size() == 0 ) {
+            throw new MojoExecutionException("No resources configured for this project.");
+        }
+
+        final List<FsResourceConfiguration> cfgs = new ArrayList<>();
+        final Entry[] entries = header.getEntries();
+        for (final Entry entry : entries) {
+            String path = entry.getValue();
+            if ( path != null && !path.endsWith("/") ) {
+                path += "/";
+            }
+            // check if we should ignore this
+            final String ignoreValue = entry.getDirectiveValue("maven:mount");
+            if ( ignoreValue != null && ignoreValue.equalsIgnoreCase("false") ) {
+                log.debug("Ignoring " + path);
+                continue;
+            }
+            String installPath = entry.getDirectiveValue("path");
+            if ( installPath == null ) {
+                installPath = "/";
+            }
+            // search the path in the resources (usually this should be the first resource
+            // entry but this might be reconfigured
+            File dir = null;
+            final Iterator i = resources.iterator();
+            while ( dir == null && i.hasNext() ) {
+                final Resource rsrc = (Resource)i.next();
+                String child = path;
+                // if resource mapping defines a target path: remove target path from checked resource path
+                String targetPath = rsrc.getTargetPath();
+                if ( targetPath != null && !targetPath.endsWith("/") ) {
+                    targetPath = targetPath + "/";
+                }
+                if ( targetPath != null && path.startsWith(targetPath) ) {
+                    child = child.substring(targetPath.length());
+                }
+                dir = new File(rsrc.getDirectory(), child);
+                if ( !dir.exists() ) {
+                    dir = null;
+                }
+            }
+            if ( dir == null ) {
+                throw new MojoExecutionException("No resource entry found containing " + path);
+            }
+            // check for root mapping - which we don't support atm
+            if ( "/".equals(installPath) ) {
+                throw new MojoExecutionException("Mapping to root path not supported by fs provider at the moment. Please adapt your initial content configuration.");
+            }
+            
+            // check further initial content directives
+            StringBuilder importOptions = new StringBuilder();
+            String overwriteValue = entry.getDirectiveValue("overwrite");
+            if (StringUtils.isNotBlank(overwriteValue)) {
+                importOptions.append("overwrite:=" + overwriteValue);
+            }
+            String ignoreImportProvidersValue = entry.getDirectiveValue("ignoreImportProviders");
+            if (StringUtils.isNotBlank(overwriteValue)) {
+                if (importOptions.length() > 0) {
+                    importOptions.append(";");
+                }
+                importOptions.append("ignoreImportProviders:=\"" + ignoreImportProvidersValue + "\"");
+            }
+            
+            cfgs.add(new FsResourceConfiguration()
+                    .fsMode(FsMode.INITIAL_CONTENT)
+                    .contentRootDir(dir.getAbsolutePath())
+                    .providerRootPath(installPath)
+                    .initialContentImportOptions(importOptions.toString()));
+        }
+
+        if (!cfgs.isEmpty()) {
+            helper.addConfigurations(targetUrl, cfgs);
+        }
+    }
+
+    /**
+     * Remove configurations from a running OSGi instance for initial content.
+     * @param targetUrl The web console base url
+     * @param bundleFile The artifact (bundle)
+     * @throws MojoExecutionException
+     */
+    public void unmount(final String targetUrl, final File bundleFile) throws MojoExecutionException {
+        log.info("Removing file system provider configurations...");
+
+        // remove all current configs for this project
+        final Map<String,FsResourceConfiguration> oldConfigs = helper.getCurrentConfigurations(targetUrl);
+        helper.removeConfigurations(targetUrl, oldConfigs);
+    }
+    
+    /**
+     * Get the manifest from the File.
+     * @param bundleFile The bundle jar
+     * @return The manifest.
+     * @throws IOException
+     */
+    private Manifest getManifest(final File bundleFile) throws IOException {
+        JarFile file = null;
+        try {
+            file = new JarFile(bundleFile);
+            return file.getManifest();
+        }
+        finally {
+            if (file != null) {
+                try {
+                    file.close();
+                }
+                catch (IOException ex) {
+                    // ignore
+                }
+            }
+        }
+    }
+
+}

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar  9 17:31:22 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/tooling/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain