/** * {@inheritDoc} */ public JcrPackage open(Node node, boolean allowInvalid) throws RepositoryException { JcrPackageManager pMgr = getPackageManager(node.getSession()); return pMgr.open(node, allowInvalid); } }
public void excute() throws RepositoryException, PackageException, IOException, ReplicationException { boolean succeeded = false; try (ResourceResolver resolver = ConfigurationUpdateListener.getResourceResolver(resolverFactory)){ Session session = resolver.adaptTo(Session.class); JcrPackageManager pkgMgr = PackagingService.getPackageManager(session); PackageId packageId = new PackageId(packagePath); // check if the package exists JcrPackage jcrPackage = pkgMgr.open(packageId); if (jcrPackage == null || jcrPackage.getNode() == null) { log.warn("Package at path " + packagePath + " does not exist"); throw new IllegalArgumentException("Package at path " + packagePath + " does not exist"); } log.debug("Assembling package {}", packagePath); pkgMgr.assemble(jcrPackage, null); log.debug("Replicating package {}", packagePath); replicator.replicate(session, ReplicationActionType.ACTIVATE, jcrPackage.getNode().getPath()); log.debug("Package {} replicated successfully!", packagePath); fireEvent(OSGI_EVENT_REPLICATED_TOPIC); succeeded = true; } finally { if(!succeeded){ fireEvent(OSGI_EVENT_FAILED_TOPIC); } } }
/** * Get the list of all packages in order of newest to oldest. * * @param request The Sling HTTP servlet request * @return List of all JCR Packages */ public List<JcrPackage> getPackageList(final SlingHttpServletRequest request) { Session session = request.getResourceResolver().adaptTo(Session.class); JcrPackageManager packageManager = packaging.getPackageManager(session); List<JcrPackage> packages = null; try { packages = packageManager.listPackages(); } catch (RepositoryException e) { LOGGER.error("Could not get package list", e); } return packages; }
/** * Delete package from the JCR. * * @param request The current request. * @param groupName The name of the package group to install * @param packageName The name of the package to install * @param version The version of the package to install * @return true if package was installed successfully */ public boolean deletePackage(final SlingHttpServletRequest request, final String groupName, final String packageName, final String version) { Session session = request.getResourceResolver().adaptTo(Session.class); boolean result; final JcrPackageManager packageManager = packaging.getPackageManager(session); final PackageId packageId = new PackageId(groupName, packageName, version); try { final JcrPackage jcrPackage = packageManager.open(packageId); packageManager.remove(jcrPackage); result = true; } catch (RepositoryException e) { LOGGER.error("Could not remove package", e); result = false; } return result; }
/** * computes configured package based on expression configuration (either existing or creating it) * @throws IOException problem with binary * @throws RepositoryException problem with package persistence * @throws IOException problem with package build * @throws ScriptException problem with some expression/path compute */ protected void init() throws IOException, RepositoryException, ScriptException { if (jcrPackage == null){ String packagePath = getExpr(); if (StringUtils.isNotBlank(packagePath)) { JcrPackageManager mgr = PackagingService.getPackageManager(resolver.adaptTo(Session.class)); Resource packageResource = resolver.getResource(packagePath); if (packageResource != null) { jcrPackage = mgr.open(packageResource.adaptTo(Node.class)); } else { String parent = Text.getRelativeParent(packagePath, 1); Resource folderResource = resolver.getResource(parent); if (folderResource == null) { LOGGER.error("folder of configured path should exists"); } else { String name = Text.getName(packagePath); jcrPackage = mgr.create(folderResource.adaptTo(Node.class), name); } } } else { LOGGER.error("expression should not be blank as it's supposed to hold package path"); } } }
final String groupName, final String name, final String version) throws RepositoryException { final Node packageRoot = jcrPackageManager.getPackageRoot(false); final Version configVersion = Version.create(version); final Node child = children.nextNode(); final JcrPackage jcrPackage = jcrPackageManager.open(child, true); if (jcrPackage == null || jcrPackage.getDefinition() == null
/** * Create package in the JCR under /etc/packages/group_name. * {@link org.apache.sling.distribution.serialization.impl.vlt.JcrVaultDistributionPackageBuilder#uploadPackage} * * @param session The current session * @param pack the Vault Package to upload * @return the JCR Package from the uploaded file * @throws IOException * @throws RepositoryException */ private JcrPackage uploadPackage(Session session, VaultPackage pack) throws IOException, RepositoryException { JcrPackageManager packageManager = packaging.getPackageManager(session); InputStream in = FileUtils.openInputStream(pack.getFile()); try { JcrPackage jcrPackage = packageManager.upload(in, true); return jcrPackage; } finally { IOUtils.closeQuietly(in); } } }
@Override public void after() throws Exception { super.after(); if (assemble) { JcrPackageManager mgr = PackagingService.getPackageManager(resolver.adaptTo(Session.class)); mgr.assemble(jcrPackage, null); } } }
/** * {@inheritDoc} */ public JcrPackage createPackageFromPathFilterSets(final Collection<PathFilterSet> pathFilterSets, final Session session, final String groupName, final String name, String version, final ConflictResolution conflictResolution, final Map<String, String> packageDefinitionProperties) throws IOException, RepositoryException { final JcrPackageManager jcrPackageManager = packaging.getPackageManager(session); if (ConflictResolution.Replace.equals(conflictResolution)) { 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); } jcrPackageDefinition.setFilter(workspaceFilter, true); for (final Map.Entry<String, String> entry : packageDefinitionProperties.entrySet()) { jcrPackageDefinition.set(entry.getKey(), entry.getValue(), false); } session.save(); return jcrPackage; }
/** * Upload a package. * * @param request The current Sling HTTP servlet request * @return The uploaded JCR Package */ public JcrPackage uploadBackupPackage(final SlingHttpServletRequest request) { final RequestParameterMap params = request.getRequestParameterMap(); Session session = null; JcrPackage jcrPackage = null; for (final Map.Entry<String, RequestParameter[]> pairs : params.entrySet()) { final RequestParameter[] pArr = pairs.getValue(); final RequestParameter param = pArr[0]; if (!param.isFormField()) { try { session = request.getResourceResolver().adaptTo(Session.class); final JcrPackageManager packageManager = packaging.getPackageManager(session); final InputStream stream = param.getInputStream(); jcrPackage = packageManager.upload(stream, true); } catch (java.io.IOException e) { LOGGER.error("Could not get image input stream", e); } catch (RepositoryException e) { LOGGER.error("Could not upload package to repository", e); } } } return jcrPackage; }
jcrPackageManager.assemble(jcrPackage, listener);
/** * Opens a package that is based on the given node. If {@code allowInvalid} * is {@code true} also invalid packages are returned, but only if the * node is file like (i.e. is nt:hierarchyNode and has a * jcr:content/jcr:data property). * * This is a shortcut version of {@link JcrPackageManager#open(Node, boolean)} * which does not create a package manager instance. * * @param node the underlying node * @param allowInvalid if {@code true} invalid packages are openend, too. * @return the new package or {@code null} it the package is not * valid unless {@code allowInvalid} is {@code true}. * @throws RepositoryException if an error occurs * * @since 2.3.0 */ public static JcrPackage open(Node node, boolean allowInvalid) throws RepositoryException { JcrPackageManager pMgr = getPackageManager(node.getSession()); return pMgr.open(node, allowInvalid); } }
for (JcrPackage pkg: pkgMgr.listPackages()) { try { Object[] values = {
private void processPackageFile(Session admin, JcrPackageManager manager, final File file, final boolean preInstall) throws AbortedScanException { JcrPackage jcrPackage = null; try { jcrPackage = manager.upload(file, false, true, null, true); final PackageId packageId = jcrPackage.getPackage().getId(); if (!preInstall) { progressChecks.forEach(handler -> { try { handler.identifyPackage(packageId, file); } catch (Exception e) { getErrorListener().onListenerException(e, handler, packageId); } }); } processPackage(admin, manager, jcrPackage, preInstall); } catch (IOException | PackageException | RepositoryException e) { throw new AbortedScanException(e, file); } finally { if (jcrPackage != null) { jcrPackage.close(); } } }
/** * {@inheritDoc} */ 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()); } }
List<JcrPackage> listPackages = pkgMgr.listPackages(pId.getGroup(), true);
private void processSubpackage(Session admin, JcrPackageManager manager, PackageId packageId, PackageId parentId, final boolean preInstall) { JcrPackage jcrPackage = null; try { jcrPackage = manager.open(packageId); if (!preInstall) { progressChecks.forEach(handler -> handler.identifySubpackage(packageId, parentId)); } processPackage(admin, manager, jcrPackage, preInstall); } catch (IOException | PackageException | RepositoryException e) { getErrorListener().onSubpackageException(e, packageId); } finally { if (jcrPackage != null) { jcrPackage.close(); } } }
final JcrPackage jcrPackage = packageManager.open(packageId); final ImportOptions opts = VltUtils.getImportOptions(aclHandling, importMode);