Search in sources :

Example 36 with InstallableResource

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

the class MockOsgiInstaller method registerResources.

/**
     * @see org.apache.sling.installer.api.OsgiInstaller#registerResources(java.lang.String, org.apache.sling.installer.api.InstallableResource[])
     */
public void registerResources(String urlScheme, final InstallableResource[] data) {
    // Sort the data to allow comparing the recorded calls reliably
    final List<InstallableResource> sorted = new LinkedList<InstallableResource>();
    for (final InstallableResource r : data) {
        sorted.add(r);
    }
    Collections.sort(sorted, new InstallableResourceComparator());
    for (InstallableResource r : sorted) {
        urls.add(urlScheme + ':' + r.getId());
        recordCall("register", urlScheme, r);
    }
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) LinkedList(java.util.LinkedList)

Example 37 with InstallableResource

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

the class Installer method updated.

/**
     * @see org.apache.sling.installer.provider.file.impl.FileChangesListener#updated(java.util.List, java.util.List, java.util.List)
     */
public void updated(List<File> added, List<File> changed, List<File> removed) {
    final List<InstallableResource> updated;
    if ((added != null && added.size() > 0) || (changed != null && changed.size() > 0)) {
        updated = new ArrayList<InstallableResource>();
        if (added != null) {
            for (final File f : added) {
                logger.debug("Added file {}", f);
                final InstallableResource resource = this.createResource(f);
                if (resource != null) {
                    updated.add(resource);
                }
            }
        }
        if (changed != null) {
            for (final File f : changed) {
                logger.debug("Changed file {}", f);
                final InstallableResource resource = this.createResource(f);
                if (resource != null) {
                    updated.add(resource);
                }
            }
        }
    } else {
        updated = null;
    }
    final String[] removedUrls;
    if (removed != null && removed.size() > 0) {
        removedUrls = new String[removed.size()];
        int index = 0;
        for (final File f : removed) {
            removedUrls[index] = f.getAbsolutePath();
            logger.debug("Removed file {}", removedUrls[index]);
            index++;
        }
    } else {
        removedUrls = null;
    }
    if (updated != null || removedUrls != null) {
        this.installer.updateResources(this.scheme, updated == null ? null : updated.toArray(new InstallableResource[updated.size()]), removedUrls);
    }
}
Also used : InstallableResource(org.apache.sling.installer.api.InstallableResource) File(java.io.File)

Example 38 with InstallableResource

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

the class FileNodeConverter method convert.

private InstallableResource convert(final Node n, final String path, final int priority) throws IOException, RepositoryException {
    final String digest = String.valueOf(n.getProperty(JCR_CONTENT_LAST_MODIFIED).getDate().getTimeInMillis());
    final InputStream is = n.getProperty(JCR_CONTENT_DATA).getStream();
    final Dictionary<String, Object> dict = new Hashtable<String, Object>();
    dict.put(InstallableResource.INSTALLATION_HINT, n.getParent().getName());
    return new InstallableResource(path, is, dict, digest, null, priority);
}
Also used : InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource)

Example 39 with InstallableResource

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

the class ConfigInstallTest method testInstallUpdateRemoveTemplateConfig.

@Test
public void testInstallUpdateRemoveTemplateConfig() throws Exception {
    final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
    cfgData.put("foo", "bar");
    cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
    final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
    // install config
    final InstallableResource rsrc = new InstallableResource("/configA/" + cfgPid, null, cfgData, null, InstallableResource.TYPE_PROPERTIES, 10);
    installer.updateResources(URL_SCHEME, new InstallableResource[] { rsrc }, null);
    // get config
    final Configuration cfg = waitForConfigValue("After installing", cfgPid, "foo", "bar");
    // update configuration
    final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
    secondData.put("foo", "bla");
    cfg.update(secondData);
    waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.IGNORED);
    // get updated config
    final Configuration secondCfg = waitForConfigValue("After updating", cfgPid, "foo", "bla");
    // remove config
    secondCfg.delete();
    // we have to wait here as no state change is happening
    sleep(200);
    waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.IGNORED);
    waitForConfiguration("After deleting", cfgPid, false);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource) Test(org.junit.Test)

Example 40 with InstallableResource

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

the class ConfigInstallTest method testDeferredConfigInstall.

@Test
public void testDeferredConfigInstall() throws Exception {
    // get config admin bundle and wait for service
    final Bundle configAdmin = this.getConfigAdminBundle();
    assertNotNull("ConfigAdmin bundle must be found", configAdmin);
    waitForConfigAdmin(true);
    // check that configuration is not available
    final String cfgPid = getClass().getSimpleName() + ".deferred." + uniqueID();
    assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
    // create new configuration object
    final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
    cfgData.put("foo", "bar");
    // Configuration installs must be deferred if ConfigAdmin service is stopped
    configAdmin.stop();
    waitForConfigAdmin(false);
    // add new configuration
    final InstallableResource[] rsrc = getInstallableResource(cfgPid, cfgData);
    installationEvents = 0;
    installer.updateResources(URL_SCHEME, rsrc, null);
    waitForInstallationEvents(2);
    configAdmin.start();
    waitForConfigAdmin(true);
    waitForConfiguration("Config must be installed once ConfigurationAdmin restarts", cfgPid, true);
    // Remove config and check
    installer.updateResources(URL_SCHEME, null, new String[] { rsrc[0].getId() });
    waitForConfiguration("Config must be removed once ConfigurationAdmin restarts", cfgPid, false);
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) InstallableResource(org.apache.sling.installer.api.InstallableResource) Test(org.junit.Test)

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