/** * Add an artifact. If the exact artifact is already contained in the * collection, it is not added again. * * @param artifact The artifact * @return {@code true} if this collection changed as a result of the call */ @Override public boolean add(final Artifact artifact) { if (this.containsExact(artifact.getId())) { return false; } return super.add(artifact); }
/** * Checks whether the same artifact is available, neglecting the version * @param id The artifact id. * @return {@code true} if the artifact exists */ public boolean containsSame(final ArtifactId id) { for (final Artifact entry : this) { if ( entry.getId().isSame(id)) { return true; } } return false; } }
/** * Checks whether the exact artifact is available * @param id The artifact id. * @return {@code true} if the artifact exists */ public boolean containsExact(final ArtifactId id) { for (final Artifact entry : this) { if ( entry.getId().equals(id)) { return true; } } return false; }
/** * Get the artifact for the given id, neglecting the version * * @param id The artifact id * @return The artifact or {@code null} otherwise */ public Artifact getSame(final ArtifactId id) { for (final Artifact artifact : this) { if (artifact.getId().isSame(id)) { return artifact; } } return null; }
/** * Scan a bundle * * @param bundle The bundle artifact * @param startLevel The start level of the bundle * @return The bundle descriptor * @throws IOException If something goes wrong or the provided artifact is not a bundle. */ public BundleDescriptor scan(final Artifact bundle, final int startLevel) throws IOException { final File file = artifactProvider.provide(bundle.getId()); if ( file == null ) { throw new IOException("Unable to find file for " + bundle.getId()); } return new BundleDescriptorImpl(bundle, file, startLevel); }
/** * Obtain the alias or aliases for the artifact. * @param includeMain Whether to include the main ID in the result. * @return The aliases or an empty set if there are none. */ public Set<ArtifactId> getAliases(boolean includeMain) { Set<ArtifactId> artifactIds = new HashSet<>(); if (includeMain) artifactIds.add(getId()); String aliases = getMetadata().get(KEY_ALIAS); if (aliases != null) { for (String alias : aliases.split(",")) { alias = alias.trim(); if (alias.indexOf(':') == alias.lastIndexOf(':')) { // No version provided, set to version zero alias += ":0.0.0"; } artifactIds.add(ArtifactId.fromMvnId(alias)); } } return artifactIds; }
/** * Remove the exact artifact. The first one found is removed. * * @param id The artifact id * @return {@code true} if the artifact has been removed */ public boolean removeExact(final ArtifactId id) { for (final Artifact artifact : this) { if ( artifact.getId().equals(id)) { return this.remove(artifact); } } return false; }
/** * Remove the same artifact, neglecting the version. The first one found is * removed. * * @param id The artifact id * @return {@code true} if the artifact has been removed */ public boolean removeSame(final ArtifactId id) { for (final Artifact artifact : this) { if ( artifact.getId().isSame(id)) { return this.remove(artifact); } } return false; }
public Set<ContentPackageDescriptor> scan(final Artifact desc, final File file) throws IOException { if (!file.getName().endsWith(".zip") ) { throw new IOException("Artifact seems to be no content package (not a zip file): " + desc.getId().toMvnId()); } final Set<ContentPackageDescriptor> contentPackages = new HashSet<>(); final ContentPackageDescriptor cp = new ContentPackageDescriptor(); final int lastDot = file.getName().lastIndexOf("."); cp.setName(file.getName().substring(0, lastDot)); cp.setArtifact(desc); cp.setArtifactFile(file); extractContentPackage(cp, contentPackages, file); contentPackages.add(cp); cp.lock(); return contentPackages; }
static List<Artifact> selectArtifactOverride(Artifact a1, Artifact a2, List<String> artifactOverrides) { if (a1.getId().equals(a2.getId())) { return Arrays.asList(a1, a2); } else if (OVERRIDE_SELECT_HIGHEST.equals(rule)) { Version a1v = a1.getId().getOSGiVersion(); Version a2v = a2.getId().getOSGiVersion(); return a1v.compareTo(a2v) > 0 ? Collections.singletonList(a1) : Collections.singletonList(a2); } else if (OVERRIDE_SELECT_LATEST.equals(rule)) { if (a1.getId().getVersion().equals(rule)) { result.add(a1); } else if (a2.getId().getVersion().equals(rule)) { result.add(a2); } else {
cfg.getProperties().put(Configuration.PROP_PREFIX + "content-package", packageArtifact.getId().toMvnId());
protected void analyze() throws IOException { final String name = this.manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); if ( name != null ) { final String version = this.manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION); if ( version == null ) { throw new IOException("Unable to get bundle version from artifact " + getArtifact().getId().toMvnId()); } this.symbolicName = name; this.bundleVersion = version; final String newBundleName = this.getArtifact().getMetadata().get("bundle:rename-bsn"); if (newBundleName != null) { this.symbolicName = newBundleName; } this.getExportedPackages().addAll(extractExportedPackages(this.manifest)); this.getImportedPackages().addAll(extractImportedPackages(this.manifest)); this.getDynamicImportedPackages().addAll(extractDynamicImportedPackages(this.manifest)); try { ResourceImpl resource = ResourceBuilder.build(null, this.manifest.getMainAttributes().entrySet().stream() .collect(Collectors.toMap(entry -> entry.getKey().toString(), entry -> entry.getValue().toString()))); this.getCapabilities().addAll(resource.getCapabilities(null)); this.getRequirements().addAll(resource.getRequirements(null)); } catch (Exception ex) { throw new IOException(ex); } } else { throw new IOException("Unable to get bundle symbolic name from artifact " + getArtifact().getId().toMvnId()); } }
@Override public ContainerDescriptor scan(Feature feature, Extension extension, ArtifactProvider provider) throws IOException { FeatureDescriptor featureDescriptor = new FeatureDescriptorImpl(feature); for (Artifact artifact : feature.getBundles()) { File file = provider.provide(artifact.getId()); BundleDescriptor bundleDescriptor = new BundleDescriptorImpl(artifact, file, artifact.getStartOrder()); featureDescriptor.getBundleDescriptors().add(bundleDescriptor); } return featureDescriptor; }
ctx.reportError(String.format(format, info.getArtifact().getId().getArtifactId(), info.getArtifact().getId().getVersion(), requirement.toString(), entry.getKey(), "no artifact is providing a matching capability in this start level.")); ctx.reportWarning(String.format(format, info.getArtifact().getId().getArtifactId(), info.getArtifact().getId().getVersion(), requirement.toString(), entry.getKey(), "while the requirement is optional no artifact is providing a matching capability in this start level.")); ctx.reportWarning(String.format(format, info.getArtifact().getId().getArtifactId(), info.getArtifact().getId().getVersion(), requirement.toString(), entry.getKey(), "there is more than one matching capability in this start level."));
if ( newArtifact.getId().getType().equals("zip") ) { if ( cpExtension == null ) { cpExtension = new Extension(ExtensionType.ARTIFACTS,
String errorMessage = String.format( "Bundle '%s' (defined in feature '%s') declares '%s' in the '%s' header that is enlisted in both exporting '%s' and hiding '%s' APIs regions, please adjust Feature settings", bundleDescriptor.getArtifact().getId(), ctx.getFeature().getId(), exportedPackage, String errorMessage = String.format( "Bundle '%s' (defined in feature '%s') declares '%s' in the '%s' header, enlisted in the '%s' region, which uses '%s' package that is in the '%s' region", bundleDescriptor.getArtifact().getId(), ctx.getFeature().getId(), exportedPackage,
/** * Create a copy of the Extension * @return A copy of the Extension */ public Extension copy() { Extension c = new Extension(type, name, required); switch(type) { case TEXT: c.setText(text); break; case JSON: c.setJSON(text); break; case ARTIFACTS: if (artifacts != null) { for (Artifact a : artifacts) { c.getArtifacts().add(a.copy(a.getId())); } } break; } return c; }