Search in sources :

Example 46 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project stanbol by apache.

the class BundleInstaller method storeConfig.

/**
     * Used to stores/overrides the ids of installed resource for a bundle.
     * @param bundle
     * @param resources
     * @throws IOException
     */
private void storeConfig(Bundle bundle, Collection<InstallableResource> resources) throws IOException {
    synchronized (configDir) {
        File config = new File(configDir, bundle.getBundleId() + ".resources");
        if (config.exists()) {
            config.delete();
        }
        FileOutputStream out = new FileOutputStream(config);
        List<String> ids = new ArrayList<String>(resources.size());
        for (InstallableResource resource : resources) {
            ids.add(resource.getId());
        }
        try {
            IOUtils.writeLines(ids, null, out, "UTF-8");
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) File(java.io.File)

Example 47 with InstallableResource

use of org.apache.sling.installer.api.InstallableResource in project stanbol by apache.

the class BundleInstaller method createInstallableResource.

/**
     * Creates an {@link InstallableResource} for {@link URL}s of files within
     * the parsed bundle.
     *
     * @param bundle the bundle containing the parsed resource
     * @param bundleResource a resource within the bundle that need to be installed
     *
     * @return the installable resource or <code>null</code> in case of an error
     */
private InstallableResource createInstallableResource(Bundle bundle, String path, URL bundleResource) {
    //define the id
    String relPath = getInstallableResourceId(path, bundleResource);
    String name = FilenameUtils.getName(relPath);
    if (name == null || name.isEmpty()) {
        //ignore directories!
        return null;
    }
    InstallableResource resource;
    try {
        /*
             * Notes:
             *  - use <relativepath> as id
             *  - parse null as type to enable autodetection for configs as
             *    implemented by InternalReseouce.create(..)
             *  - we use the symbolic name and the modification date of the bundle as digest
             *  - the Dictionary will be ignored if an input stream is present
             *    so it is best to parse null
             *  - No idea how the priority is used by the Sling Installer. For
             *    now parse null than the default priority is used.
             */
        resource = new InstallableResource(relPath, bundleResource.openStream(), null, String.valueOf(bundle.getSymbolicName() + bundle.getLastModified()), null, null);
        log.info(" ... found installable resource " + bundleResource);
    } catch (IOException e) {
        log.error(String.format("Unable to process configuration File %s from Bundle %s", bundleResource, bundle.getSymbolicName()), e);
        return null;
    }
    return resource;
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) IOException(java.io.IOException)

Aggregations

InstallableResource (org.apache.sling.installer.api.InstallableResource)47 Hashtable (java.util.Hashtable)23 Test (org.junit.Test)21 File (java.io.File)8 IOException (java.io.IOException)8 InputStream (java.io.InputStream)7 Configuration (org.osgi.service.cm.Configuration)6 FileInputStream (java.io.FileInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 TaskResource (org.apache.sling.installer.api.tasks.TaskResource)3 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)3 FileOutputStream (java.io.FileOutputStream)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 Node (javax.jcr.Node)2 OsgiInstaller (org.apache.sling.installer.api.OsgiInstaller)2 ModelArchiveReader (org.apache.sling.provisioning.model.io.ModelArchiveReader)2