Examples of JcrPackage


Examples of com.day.jcr.vault.packaging.JcrPackage

        contentPaths.add("/content/bar");

        final String packagePath = "/etc/packages/acs-commons/test.zip";
        final Resource packageResource = mock(Resource.class);
        final Node packageNode = mock(Node.class);
        final JcrPackage jcrPackage = mock(JcrPackage.class);
        final Node jcrPackageNode = mock(Node.class);
        final JcrPackageDefinition jcrPackageDefinition = mock(JcrPackageDefinition.class);
        final Resource jcrPackageJcrContent = mock(Resource.class);

        final Resource contentResource1 = mock(Resource.class);
        final Resource contentResource2 = mock(Resource.class);
        final Node contentNode1 = mock(Node.class);
        final Node contentNode2 = mock(Node.class);

        final String[] paths = new String[] { packagePath };

        final Map<String, Object> map = new HashMap<String, Object>();
        map.put("paths", paths);

        final Event event = new Event("MOCK", map);

        when(adminResourceResolver.getResource(packagePath)).thenReturn(packageResource);
        when(packageResource.adaptTo(Node.class)).thenReturn(packageNode);
        when(packaging.open(packageNode, false)).thenReturn(jcrPackage);
        when(packageHelper.getContents(jcrPackage)).thenReturn(contentPaths);
        when(jcrPackage.getDefinition()).thenReturn(jcrPackageDefinition);
        when(jcrPackageDefinition.getId()).thenReturn(mock(PackageId.class));
        when(jcrPackage.getNode()).thenReturn(jcrPackageNode);
        when(jcrPackageNode.getPath()).thenReturn(packagePath);
        when(packageResource.getChild("jcr:content")).thenReturn(jcrPackageJcrContent);

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(JcrConstants.JCR_LASTMODIFIED, calendar);
View Full Code Here

Examples of com.day.jcr.vault.packaging.JcrPackage

        final List<JcrPackage> packages = new ArrayList<JcrPackage>();

        for (final String path : paths) {
            final Resource eventResource = this.adminResourceResolver.getResource(path);

            JcrPackage jcrPackage;

            try {
                jcrPackage = packaging.open(eventResource.adaptTo(Node.class), false);
                if (jcrPackage != null) {
                    packages.add(jcrPackage);
View Full Code Here

Examples of com.day.jcr.vault.packaging.JcrPackage

            boolean configVersionEligible = true;

            while (children.hasNext()) {
                final Node child = children.nextNode();

                final JcrPackage jcrPackage = jcrPackageManager.open(child, true);
                if (jcrPackage == null
                        || jcrPackage.getDefinition() == null
                        || jcrPackage.getDefinition().getId() == null) {

                    log.warn("Could not covert node [ {} ] into a proper JCR Package, moving to next node",
                            child.getPath());
                    continue;

                } else if (!StringUtils.equals(name, jcrPackage.getDefinition().getId().getName())) {
                    // Name mismatch - so just skip
                    continue;
                }

                final Version packageVersion = jcrPackage.getDefinition().getId().getVersion();

                log.debug(packageVersion.toString() + " compareTo " + latestVersion.toString()
                        + " = " + packageVersion.compareTo(latestVersion));

                if (packageVersion.compareTo(latestVersion) >= 1) {
View Full Code Here

Examples of com.day.jcr.vault.packaging.JcrPackage

     */
    public void removePackage(final JcrPackageManager jcrPackageManager,
                              final String groupName, final String name,
                              final String version) throws RepositoryException {
        final PackageId packageId = new PackageId(groupName, name, version);
        final JcrPackage jcrPackage = jcrPackageManager.open(packageId);

        if (jcrPackage != null && jcrPackage.getNode() != null) {
            jcrPackage.getNode().remove();
            jcrPackage.getNode().getSession().save();
        } else {
            log.debug("Nothing to remove at: ", packageId.getInstallationPath());
        }
    }
View Full Code Here

Examples of com.day.jcr.vault.packaging.JcrPackage

            this.removePackage(jcrPackageManager, groupName, name, version);
        } else if (ConflictResolution.IncrementVersion.equals(conflictResolution)) {
            version = this.getNextVersion(jcrPackageManager, groupName, name, version).toString();
        }

        final JcrPackage jcrPackage = jcrPackageManager.create(groupName, name, version);
        final JcrPackageDefinition jcrPackageDefinition = jcrPackage.getDefinition();
        final DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();

        for (final PathFilterSet pathFilterSet : pathFilterSets) {
            workspaceFilter.add(pathFilterSet);
        }
View Full Code Here

Examples of com.day.jcr.vault.packaging.JcrPackage

                // Do not create empty packages; This will only clutter up CRX Package Manager
                response.getWriter().print(packageHelper.getErrorJSON("Refusing to create a package with no filter "
                        + "set rules."));
            } else {
                // Create JCR Package; Defaults should always be passed in via Request Parameters, but just in case
                final JcrPackage jcrPackage = packageHelper.createPackageFromPathFilterSets(packageResources,
                        request.getResourceResolver().adaptTo(Session.class),
                        properties.get(PACKAGE_GROUP_NAME, DEFAULT_PACKAGE_GROUP_NAME),
                        properties.get(PACKAGE_NAME, DEFAULT_PACKAGE_NAME),
                        properties.get(PACKAGE_VERSION, DEFAULT_PACKAGE_VERSION),
                        PackageHelper.ConflictResolution.valueOf(properties.get(CONFLICT_RESOLUTION,
View Full Code Here

Examples of com.day.jcr.vault.packaging.JcrPackage

                // Do not create empty packages; This will only clutter up CRX Package Manager
                response.getWriter().print(packageHelper.getErrorJSON("Refusing to create a package with no filter "
                        + "set rules."));
            } else {
                // Create JCR Package; Defaults should always be passed in via Request Parameters, but just in case
                final JcrPackage jcrPackage = packageHelper.createPackage(packageResources,
                        request.getResourceResolver().adaptTo(Session.class),
                        properties.get(PACKAGE_GROUP_NAME, DEFAULT_PACKAGE_GROUP_NAME),
                        properties.get(PACKAGE_NAME, DEFAULT_PACKAGE_NAME),
                        properties.get(PACKAGE_VERSION, DEFAULT_PACKAGE_VERSION),
                        PackageHelper.ConflictResolution.valueOf(properties.get(CONFLICT_RESOLUTION,
View Full Code Here

Examples of org.apache.jackrabbit.vault.packaging.JcrPackage

        if (this.getDefinition().getBoolean(JcrPackageDefinition.PN_DISABLE_INTERMEDIATE_SAVE) ) {
            // MAX_VALUE disables saving completely, therefore we have to use a lower value!
            opts.setAutoSaveThreshold(Integer.MAX_VALUE - 1);
        }
        InstallContextImpl ctx = pack.prepareExtract(node.getSession(), opts);
        JcrPackage snap = null;
        if (!opts.isDryRun() && createSnapshot) {
            ExportOptions eOpts = new ExportOptions();
            eOpts.setListener(opts.getListener());
            snap = snapshot(eOpts, replaceSnapshot, opts.getAccessControlHandling());
        }
        List<String> subPackages = new ArrayList<String>();
        pack.extract(ctx, subPackages);
        getDefinition();
        if (def != null && !opts.isDryRun()) {
            def.touchLastUnpacked(null, true);
        }

        // process sub packages
        Session s = node.getSession();
        List<JcrPackageImpl> subPacks = new LinkedList<JcrPackageImpl>();
        for (String path: subPackages) {
            if (s.nodeExists(path)) {
                JcrPackageImpl p = new JcrPackageImpl(s.getNode(path));
                if (!p.isValid()) {
                    // check if package was included as pure .zip or .jar
                    try {
                        p.tryUnwrap();
                    } catch (Exception e) {
                        log.info("Sub package {} not valid: " + e, path);
                    }
                }
                if (p.isValid()) {
                    subPacks.add(p);
                }
            }
        }

        // don't extract sub packages if not recursive
        if (!opts.isNonRecursive() && !subPacks.isEmpty()) {
            try {
                DependencyUtil.sortPackages(subPacks);
            } catch (CyclicDependencyException e) {
                if (opts.isStrict()) {
                    throw e;
                }
            }
            List<String> subIds = new LinkedList<String>();
            SubPackageHandling sb = pack.getSubPackageHandling();
            for (JcrPackageImpl p: subPacks) {
                boolean skip = false;
                PackageId id = p.getPackage().getId();
                SubPackageHandling.Option option = sb.getOption(id);
                String msg;
                if (option == SubPackageHandling.Option.ADD || option == SubPackageHandling.Option.IGNORE) {
                    msg = "skipping installation of subpackage " + id + " due to option " + option;
                    skip = true;
                } else if (option == SubPackageHandling.Option.INSTALL) {
                    msg = "Starting installation of subpackage " + id;
                } else {
                    msg = "Starting extraction of subpackage " + id;
                }
                if (options.isDryRun()) {
                    msg = "Dry run: " + msg;
                }
                if (options.getListener() != null) {
                    options.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, msg, "");
                } else {
                    log.info(msg);
                }
                if (!skip) {
                    if (createSnapshot && option == SubPackageHandling.Option.INSTALL) {
                        p.extract(options, true, true);
                        subIds.add(id.toString());
                    } else {
                        p.extract(options, false, true);
                    }
                }
                p.close();
            }
            // register sub packages in snapshot for uninstall
            if (snap != null) {
                snap.getDefinition().getNode().setProperty(JcrPackageDefinition.PN_SUB_PACKAGES, subIds.toArray(new String[subIds.size()]));
                snap.getDefinition().getNode().save();
            }
        }
    }
View Full Code Here

Examples of org.apache.jackrabbit.vault.packaging.JcrPackage

        log.info("Creating snapshot for {}.", id);
        JcrPackageManagerImpl packMgr = new JcrPackageManagerImpl(node.getSession());
        String path = id.getInstallationPath();
        String parentPath = Text.getRelativeParent(path, 1);
        Node folder = packMgr.mkdir(parentPath, true);
        JcrPackage snap = JcrPackageImpl.createNew(folder, id, null, true);
        JcrPackageDefinitionImpl snapDef = (JcrPackageDefinitionImpl) snap.getDefinition();
        JcrPackageDefinitionImpl myDef = (JcrPackageDefinitionImpl) getDefinition();
        snapDef.setId(id, false);
        snapDef.setFilter(myDef.getMetaInf().getFilter(), false);
        snapDef.set(JcrPackageDefinition.PN_DESCRIPTION, "Snapshot of package " + myDef.getId().toString(), false);
        if (acHandling == null) {
            snapDef.set(JcrPackageDefinition.PN_AC_HANDLING, myDef.get(JcrPackageDefinition.PN_AC_HANDLING), false);
        } else {
            snapDef.set(JcrPackageDefinition.PN_AC_HANDLING, acHandling.name(), false);
        }
        if (opts.getListener() != null) {
            opts.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, "Creating snapshot for package " + myDef.getId(), "");
        }
        packMgr.assemble(snap.getNode(), snapDef, opts.getListener());
        log.info("Creating snapshot for {} completed.", id);
        return snap;
    }
View Full Code Here

Examples of org.apache.jackrabbit.vault.packaging.JcrPackage

    /**
     * {@inheritDoc}
     */
    public void uninstall(ImportOptions opts) throws RepositoryException, PackageException, IOException {
        JcrPackage snap = getSnapshot();
        if (snap == null) {
            throw new PackageException("Unable to uninstall package. No snapshot present.");
        }
        if (opts.getListener() != null) {
            opts.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, "Uninstalling package from snapshot " + snap.getDefinition().getId(), "");
        }
        Session s = getNode().getSession();
        // check for recursive unininstall
        if (!opts.isNonRecursive()) {
            Node defNode = snap.getDefNode();
            LinkedList<PackageId> subPackages = new LinkedList<PackageId>();
            if (defNode.hasProperty(JcrPackageDefinition.PN_SUB_PACKAGES)) {
                Value[] subIds = defNode.getProperty(JcrPackageDefinition.PN_SUB_PACKAGES).getValues();
                for (Value v: subIds) {
                    // reverse installation order
                    subPackages.addLast(PackageId.fromString(v.getString()));
                }
            }
            if (subPackages.size() > 0) {
                JcrPackageManagerImpl packMgr = new JcrPackageManagerImpl(s);
                for (PackageId id: subPackages) {
                    JcrPackage pack = packMgr.open(id);
                    if (pack != null) {
                        pack.uninstall(opts);
                    }
                }

            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.