public void mount()

in src/main/java/org/apache/sling/maven/bundlesupport/fsresource/SlingInitialContentMounter.java [66:164]


    public void mount(final URI consoleTargetUrl, 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.warn("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 for Sling initial content...");
        // quick check if resources are configured
        final List<Resource> resources = project.getResources();
        if (resources == null || resources.isEmpty()) {
            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<Resource> i = resources.iterator();
            while (dir == null && i.hasNext()) {
                final Resource rsrc = 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 + "/";
                }
                log.debug("Checking if project resource '" + rsrc.getDirectory() + "' with target path '" + targetPath
                        + "' is a potential mount point for " + path + " ...");
                if (targetPath != null && path != 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)
                    .fsRootPath(dir.getAbsoluteFile())
                    .resourceRootPath(installPath)
                    .initialContentImportOptions(importOptions.toString()));
            log.info("Created new configuration for resource path " + installPath);
        }

        if (!cfgs.isEmpty()) {
            helper.addConfigurations(consoleTargetUrl, cfgs);
        }
    }