Package org.apache.sling.installer.api

Examples of org.apache.sling.installer.api.InstallableResource


        final List<InstallableResource> toRegister = new LinkedList<InstallableResource>();
        for(String resourceRef : resources) {
            final URL url = new URL(resourceRef);
            final InputStream stream = new AutoCloseInputStream(url.openStream());
            final String digest = resourceRef;
            toRegister.add(new InstallableResource(resourceRef, stream, null, digest, "file", 100));
        }
       
        if(toRegister.isEmpty()) {
            log.warn("No prepared resources found to register, use {} first", InstallerRegisterCommand.I_INSTALLER_REGISTER);
        } else {
View Full Code Here


    public void initialSet(final List<File> files) {
        logger.debug("Initial set for {}", this.scheme);
        final List<InstallableResource> resources = new ArrayList<InstallableResource>();
        for(final File f : files) {
            logger.debug("Initial file {}", f);
            final InstallableResource resource = this.createResource(f);
            if ( resource != null ) {
                resources.add(resource);
            }
        }
        this.installer.registerResources(this.scheme, resources.toArray(new InstallableResource[resources.size()]));
View Full Code Here

        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);
                    }
                }
            }
View Full Code Here

                } catch (NumberFormatException nfe) {
                    // ignore this
                }
            }
            dict.put(InstallableResource.RESOURCE_URI_HINT, file.toURI().toString());
            return new InstallableResource(file.getAbsolutePath(), is, dict, digest,
                null, null);
        } catch (IOException io) {
            logger.error("Unable to read file " + file, io);
        }
        return null;
View Full Code Here

        final NodeIterator it = folder.getNodes();
        while(it.hasNext()) {
            final Node n = it.nextNode();
            boolean processed = false;
            for (JcrInstaller.NodeConverter nc : converters) {
                final InstallableResource r = nc.convertNode(n, priority);
                if(r != null) {
                    processed = true;
                    resourcesSeen.add(r.getId());
                    final String oldDigest = digests.get(r.getId());
                    if(r.getDigest().equals(oldDigest)) {
                        log.debug("Digest didn't change, ignoring " + r);
                    } else {
                        result.toAdd.add(r);
                    }
                    break;
View Full Code Here

   *   if we don't know how to convert it.
   */
  public InstallableResource convertNode(final Node n,
          final int priority)
  throws RepositoryException {
    InstallableResource result = null;

    // We only consider CONFIG_NODE_TYPE nodes
    if(n.isNodeType(CONFIG_NODE_TYPE)) {
        final Dictionary<String, Object> dict = load(n);
      result = new InstallableResource(n.getPath(), null, dict, computeDigest(dict), null, priority);
      log.debug("Converted node {} to {}", n.getPath(), result);
    } else {
      log.debug("Node is not a {} node, ignored:{}", CONFIG_NODE_TYPE, n.getPath());
    }
    return result;
View Full Code Here

    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);
  }
View Full Code Here

    public void testOverrideConfig() throws Exception {
        final String pid = getClass().getSimpleName() + "." + System.currentTimeMillis();

        final Dictionary<String, Object> data = new Hashtable<String, Object>();
        data.put("foo", "a");
        final InstallableResource a = getInstallableResource("a/" + pid, data, InstallableResource.DEFAULT_PRIORITY - 1)[0];
        data.put("foo", "b");
        final InstallableResource b = getInstallableResource("b/" + pid, data, InstallableResource.DEFAULT_PRIORITY)[0];
        data.put("foo", "c");
        final InstallableResource c = getInstallableResource("c/" + pid, data, InstallableResource.DEFAULT_PRIORITY + 1)[0];

        // c has more priority than b which has more than a
        installer.updateResources(URL_SCHEME, new InstallableResource[] {b}, null);
        assertConfigValue(pid, "foo", "b", TIMEOUT);
        installer.updateResources(URL_SCHEME, new InstallableResource[] {c}, null);
        assertConfigValue(pid, "foo", "c", TIMEOUT);
        installer.updateResources(URL_SCHEME, new InstallableResource[] {a}, null);

        // highest prio should be active (c)
        assertConfigValue(pid, "foo", "c", TIMEOUT);

        // removing c, second highest prio should be active (b)
        installer.updateResources(URL_SCHEME, null, new String[] {c.getId()});
        assertConfigValue(pid, "foo", "b", TIMEOUT);

        // removing b, a should be active
        installer.updateResources(URL_SCHEME, null, new String[] {b.getId()});
        assertConfigValue(pid, "foo", "a", TIMEOUT);
View Full Code Here

        return InternalResource.create("test", is);
    }

    private String testDigestChanged(Dictionary<String, Object> d,
      String oldDigest, int step, boolean shouldChange) throws Exception {
    final String newDigest = create(new InstallableResource("a", null, d, null, null, null)).getDigest();
    if(shouldChange) {
      assertTrue("Digest (" + newDigest + ") should have changed at step " + step, !newDigest.equals(oldDigest));
    } else {
      assertTrue("Digest (" + newDigest + ") should NOT have changed at step " + step, newDigest.equals(oldDigest));
    }
View Full Code Here

    setTestData(d1);
    setTestData(d2);

    assertEquals(
        "Two dictionary with same values have the same key",
            create(new InstallableResource("a", null, d1, null, null, null)).getDigest(),
                create(new InstallableResource("a", null, d2, null, null, null)).getDigest()
    );
  }
View Full Code Here

TOP

Related Classes of org.apache.sling.installer.api.InstallableResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.