public static PackId createPackId(final String group, final String name, final String version) { if (group != null && group.length() > 1 && name != null && name.length() > 1) { PackageId _id = new PackageId(group, name, version != null ? version : ""); return new PackId(_id.getGroup(), _id.getName(), _id.getVersionString(), _id.getInstallationPath()); } else { return null; } }
/** * Sets the package Ids to the definition node * @param subPackageIds the package Ids * @throws RepositoryException if an error occurs */ void setSubPackages(Collection<PackageId> subPackageIds) throws RepositoryException { String[] subIds = new String[subPackageIds.size()]; int i =0; for (PackageId subId: subPackageIds) { subIds[i++] = subId.toString(); } defNode.setProperty(PN_SUB_PACKAGES, subIds); }
/** * Returns an array of package id from strings * @param str the strings * @return the array of package ids */ public static PackageId[] fromString(String ... str) { PackageId[] ret = new PackageId[str.length]; for (int i=0; i<str.length; i++) { ret[i] = PackageId.fromString(str[i]); } return ret; }
/** * Creates a new dependency to the specified package id * @param id package id. */ public Dependency(@Nonnull PackageId id) { this(id.getGroup(), id.getName(), new VersionRange(id.getVersion())); }
/** * Returns the snapshot id of this package. * @return the snapshot package id * @throws RepositoryException if an error occurs */ private PackageId getSnapshotId() throws RepositoryException { PackageId id = getDefinition().getId(); String group = id.getGroup(); if (group.length() == 0) { group = ".snapshot"; } else { group += "/.snapshot"; } return new PackageId( group, id.getName(), id.getVersion()); }
throw new PackageException("Package definition not unwrapped."); if (!PackageId.isValid(group, name, version)) { throw new RepositoryException("Unable to rename package. Illegal package name."); PackageId newId = new PackageId( group == null ? id.getGroup() : group, name == null ? id.getName() : name, version == null ? id.getVersion() : Version.create(version) ); String dstPath = getInstallationPath(newId) + ".zip"; if (id.equals(newId) && pack.getNode().getPath().equals(dstPath)) { log.debug("Package id not changed. won't rename."); return pack;
/** * Writes the properties derived from the package id to the content * @param id the package id * @param autoSave if {@code true} the changes are saved automatically. */ public void setId(PackageId id, boolean autoSave) { set(PN_GROUP, id.getGroup(), false); set(PN_NAME, id.getName(), false); set(PN_VERSION, id.getVersionString(), false); }
/** * Parses a options string as described above and returns a new SubPackageHandling instance. * @param str the string to parse * @return the configuration or {@code null} if the string is malformed. */ public static SubPackageHandling fromString(String str) { if (str == null || str.isEmpty()) { return SubPackageHandling.DEFAULT; } SubPackageHandling sp = new SubPackageHandling(); for (String instruction: Text.explode(str, ',')) { String[] opts = Text.explode(instruction.trim(), ';'); if (opts.length > 0) { PackageId id = PackageId.fromString(opts[0]); Option opt = Option.INSTALL; if (opts.length > 1) { try { opt = Option.valueOf(opts[1].toUpperCase()); } catch (IllegalArgumentException e) { // ignore } } sp.getEntries().add(new Entry(id.getGroup(), id.getName(), opt)); } } return sp; }
String pName = pId.getName(); Version pVersion = pId.getVersion(); List<JcrPackage> listPackages = pkgMgr.listPackages(pId.getGroup(), true); if (listedPackageId.equals(pId)) { continue; if (pName.equals(listedPackageId.getName()) && listedPackage.isValid() && listedPackage.isInstalled() && listedPackageId.getVersion().compareTo(pVersion) > 0) { newerPackageIdPerSubPackage.put(pId, listedPackageId); break;
/** * Creates a random package id for packages that lack one. * * @return a random package id. */ protected static PackageId createRandomPid() { return new PackageId("temporary", "pack_" + UUID.randomUUID().toString(), (String) null); }
/** * 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 option from the entries list that matches the package last. If no entry match, it returns * {@link org.apache.jackrabbit.vault.packaging.SubPackageHandling.Option#INSTALL} * @param id the package id to match * @return the option. */ public Option getOption(PackageId id) { Option opt = null; for (Entry e: entries) { if (!"*".equals(e.groupName) && !id.getGroup().equals(e.groupName)) { continue; } if (!"*".equals(e.packageName) && !id.getName().equals(e.packageName)) { continue; } opt = e.option; } return opt == null ? Option.INSTALL : opt; }
PackageId id = new PackageId(group, name, version); Set<String> rts = new HashSet<String>(); for (PathFilterSet p: filter.getFilterSets()) { addManifestAttribute(mf, MF_PACKAGE_ID, id.toString()); addManifestAttribute(mf, MF_PACKAGE_DESC, properties.getProperty(NAME_DESCRIPTION)); addManifestAttribute(mf, MF_PACKAGE_ROOTS, Text.implode(filterRoots, ","));
continue; } else if (!StringUtils.equals(name, jcrPackage.getDefinition().getId().getName())) { final Version packageVersion = jcrPackage.getDefinition().getId().getVersion();
/** * {@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()); } }
/** * Returns the properties (name, version, dependencies, etc.) for the provided VLT package file * * @throws IOException if it can't read the file * @see #packageId(File) */ public static String packageName(File packageFile) throws IOException { return packageId(packageFile).getName(); }
/** * {@inheritDoc} */ public JcrPackage create(String group, String name, String version) throws RepositoryException, IOException { // sanitize name String ext = Text.getName(name, '.'); if ("zip".equals(ext) || "jar".equals(ext)) { name = name.substring(0, name.length() - 4); } if (!PackageId.isValid(group, name, version)) { throw new RepositoryException("Unable to create package. Illegal package name."); } PackageId pid = new PackageId(group, name, version); Node folder = mkdir(Text.getRelativeParent(getInstallationPath(pid), 1), false); return createNew(folder, pid, null, true); }
/** * {@inheritDoc} */ @Override public PackageId resolve(Dependency dependency, boolean onlyInstalled) throws IOException { PackageId bestId = null; for (PackageId id : packages()) { if (!onlyInstalled || isInstalled(id)) { if (dependency.matches(id)) { if (bestId == null || id.getVersion().compareTo(bestId.getVersion()) > 0) { bestId = id; } } } } return bestId; }
void findOverlaps(final PackageId currentPackageId, final String path, final Violation.Severity severity) { // fast escape! no need to belabor the point. if (!reportAllOverlaps && reported.containsKey(currentPackageId) && !reported.get(currentPackageId).isLessSevereThan(severity)) { return; } // find any overlapping filters, looking forward. List<PackageId> overlapping = filters.entrySet().stream() .filter(entry -> !entry.getKey().equals(currentPackageId)) .filter(overlaps(path)) .map(Map.Entry::getKey) .collect(Collectors.toList()); if (!overlapping.isEmpty()) { if (!reportAllOverlaps) { reported.put(currentPackageId, severity); } reportViolation(severity, String.format("affected path %s overlaps %s", path, overlapping), currentPackageId); } }
/** * Checks if the given package id matches this dependency specification. * @param id the package id * @return {@code true} if matches */ public boolean matches(@Nonnull PackageId id) { return groupId.equals(id.getGroup()) && name.equals(id.getName()) && range.isInRange(id.getVersion()); }