@Override protected Properties getPropertiesMap() { try { return pkg.getPackage().getMetaInf().getProperties(); } catch (RepositoryException|IOException e) { throw new IllegalStateException(e); } }
@Override public PackageProperties getPackageProperties() throws IOException { return getPackage().getProperties(); } }
/** * Sorts the packages by the dependency order * @param packages packages to sort * @param <T> Type of the collection. * @throws CyclicDependencyException if a cyclic dependency is detected */ public static <T extends VaultPackage> void sort(Collection<T> packages) throws CyclicDependencyException { Map<PackageId, Dependency[]> list = new LinkedHashMap<PackageId, Dependency[]>(); Map<PackageId, VaultPackage> byId = new LinkedHashMap<PackageId, VaultPackage>(); for (VaultPackage pack: packages) { list.put(pack.getId(), pack.getDependencies()); byId.put(pack.getId(), pack); } packages.clear(); for (PackageId id: resolve(list)) { packages.add((T) byId.remove(id)); } }
/** * {@inheritDoc} */ public void unwrap(VaultPackage pack, boolean force, boolean autoSave) throws RepositoryException, IOException { if (!force && isUnwrapped()) { return; } log.debug("unwrapping package {}", pack == null ? "(unknown)" : pack.getId()); long now = System.currentTimeMillis(); unwrap(pack == null ? null : pack.getArchive(), autoSave); if (log.isDebugEnabled()) { log.debug("unwrapping package {} completed in {}ms", getId(), System.currentTimeMillis() - now); } }
private void processPackage(Session admin, JcrPackageManager manager, JcrPackage jcrPackage, final boolean preInstall) throws IOException, PackageException, RepositoryException { final PackageId packageId = jcrPackage.getPackage().getId(); final Session inspectSession = SessionFacade.findBestWrapper(admin, false); final ProgressTrackerListener tracker = if (!vaultPackage.isValid()) { throw new PackageException("Package is not valid: " + packageId); try { handler.beforeExtract(packageId, inspectSession, vaultPackage.getProperties(), vaultPackage.getMetaInf(), subpacks); } catch (final RepositoryException e) { getErrorListener().onListenerException(e, handler, packageId);
PackageId id = pack.getId(); InputStream in; try { in = FileUtils.openInputStream(pack.getFile()); } catch (IOException e) { throw new PackageException(e); contentNode.setProperty(JcrConstants.JCR_MIMETYPE, JcrPackage.MIME_TYPE); packNode.getSession().save(); pack.close(); dispatch(PackageEvent.Type.ASSEMBLE, id, null);
pack = manager.open(file, true); if (!pack.isValid()) { return new ValidationResult(Reason.INVALID_META_INF); pack.getMetaInf().getFilter()); } finally { if (pack != null) { pack.close();
@Nonnull @Override public PackageId getId() { return vltPkg.getId(); }
@Override public void close() { if (vltPkg != null) { vltPkg.close(); vltPkg = 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); } } }
/** * {@inheritDoc} */ @Override public void installPackage(@Nonnull Session session, @Nonnull RegisteredPackage pkg, @Nonnull ImportOptions opts, boolean extract) throws IOException, PackageException { // For now FS based persistence only supports extraction but no reversible installation if (!extract) { String msg = "Only extraction supported by FS based registry"; log.error(msg); throw new PackageException(msg); } try (VaultPackage vltPkg = pkg.getPackage()) { vltPkg.extract(session, opts); dispatch(PackageEvent.Type.EXTRACT, pkg.getId(), null); updateInstallState(vltPkg.getId(), FSPackageStatus.EXTRACTED); } catch (RepositoryException e) { throw new IOException(e); } }
/** * Get a JSONObject from the JCR package configured for the Angular model. * * @param jcrPackage The JCR Package to retrieve data from. * @return the JSON Object configured for the Angular model. * @throws JSONException * @throws RepositoryException * @throws IOException */ private JSONObject getJsonFromJcrPackage(final JcrPackage jcrPackage) throws JSONException, RepositoryException, IOException { final JSONObject json = new JSONObject(); final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); json.put(JSON_SIZE_PROPERTY, getSize(jcrPackage.getPackage().getSize())); json.put(JSON_DATE_PROPERTY, dateFormat.format(jcrPackage.getPackage().getCreated().getTime())); json.put(JSON_NAME_PROPERTY, jcrPackage.getDefinition().getId().getName()); json.put(JSON_PATH_PROPERTY, jcrPackage.getNode().getPath()); json.put(JSON_ID_PROPERTY, jcrPackage.getDefinition().getId().toString()); return json; }
/** * Gets the last build time of the package. * * @param jcrPackage the package obj * @return the package's last build time or null if none can be found * @throws RepositoryException */ private Calendar getJcrPackageLastModified(final JcrPackage jcrPackage) throws RepositoryException, IOException { if (ReplicatedAt.CURRENT_TIME.equals(this.replicatedAt)) { return Calendar.getInstance(); } else { return jcrPackage.getPackage().getCreated(); } }
Map<PackageId, SubPackageHandling.Option> subpackages = new HashMap<>(); Archive.Entry packagesRoot = pkg.getArchive().getEntry(ARCHIVE_PACKAGE_ROOT_PATH); if (packagesRoot != null) { for (PathFilterSet root : pkg.getArchive().getMetaInf().getFilter().getFilterSets()) { pkg.getId()); hasOwnContent = true; Dependency autoDependency = hasOwnContent ? new Dependency(pkg.getId()) : null; registerSubPackages(pkg, packagesRoot, DEFAULT_PACKAGE_ROOT_PATH, replace, subpackages, autoDependency); dispatch(Type.EXTRACT_SUB_PACKAGES, pkg.getId(), subpackages.keySet().toArray(new PackageId[subpackages.size()]));
@Nonnull @Override public PackageId register(@Nonnull InputStream in, boolean replace) throws IOException, PackageExistsException { try (JcrPackage pkg = upload(in, replace)){ //noinspection resource return pkg.getPackage().getId(); } catch (RepositoryException e) { throw new IOException(e); } }
@Override public void close() { vltPkg.close(); vltPkg = null; pkg.close(); pkg = null; }
private void extractSubpackages(@Nonnull ImportOptions opts, @Nonnull Set<PackageId> processed) throws RepositoryException, PackageException, IOException { final VaultPackage pack = getPackage(); final PackageId pId = pack.getId(); Archive a = pack.getArchive(); Archive.Entry packages = a.getEntry(ARCHIVE_PACKAGE_ROOT_PATH); if (packages == null) {