use of org.apache.karaf.features.internal.model.Bundle in project karaf by apache.
the class GenerateDescriptorMojo method checkChanges.
private void checkChanges(Features newFeatures, ObjectFactory objectFactory) throws Exception {
if (checkDependencyChange) {
//combine all the dependencies to one feature and strip out versions
Features features = objectFactory.createFeaturesRoot();
features.setName(newFeatures.getName());
Feature feature = objectFactory.createFeature();
features.getFeature().add(feature);
for (Feature f : newFeatures.getFeature()) {
for (Bundle b : f.getBundle()) {
Bundle bundle = objectFactory.createBundle();
bundle.setLocation(b.getLocation());
feature.getBundle().add(bundle);
}
for (Dependency d : f.getFeature()) {
Dependency dependency = objectFactory.createDependency();
dependency.setName(d.getName());
feature.getFeature().add(dependency);
}
}
feature.getBundle().sort(Comparator.comparing(Bundle::getLocation));
feature.getFeature().sort(Comparator.comparing(Dependency::getName));
if (dependencyCache.exists()) {
//filter dependencies file
filter(dependencyCache, filteredDependencyCache);
//read dependency types, convert to dependencies, compare.
Features oldfeatures = readFeaturesFile(filteredDependencyCache);
Feature oldFeature = oldfeatures.getFeature().get(0);
List<Bundle> addedBundles = new ArrayList<>(feature.getBundle());
List<Bundle> removedBundles = new ArrayList<>();
for (Bundle test : oldFeature.getBundle()) {
boolean t1 = addedBundles.contains(test);
int s1 = addedBundles.size();
boolean t2 = addedBundles.remove(test);
int s2 = addedBundles.size();
if (t1 != t2) {
getLog().warn("dependencies.contains: " + t1 + ", dependencies.remove(test): " + t2);
}
if (t1 == (s1 == s2)) {
getLog().warn("dependencies.contains: " + t1 + ", size before: " + s1 + ", size after: " + s2);
}
if (!t2) {
removedBundles.add(test);
}
}
List<Dependency> addedDependencys = new ArrayList<>(feature.getFeature());
List<Dependency> removedDependencys = new ArrayList<>();
for (Dependency test : oldFeature.getFeature()) {
boolean t1 = addedDependencys.contains(test);
int s1 = addedDependencys.size();
boolean t2 = addedDependencys.remove(test);
int s2 = addedDependencys.size();
if (t1 != t2) {
getLog().warn("dependencies.contains: " + t1 + ", dependencies.remove(test): " + t2);
}
if (t1 == (s1 == s2)) {
getLog().warn("dependencies.contains: " + t1 + ", size before: " + s1 + ", size after: " + s2);
}
if (!t2) {
removedDependencys.add(test);
}
}
if (!addedBundles.isEmpty() || !removedBundles.isEmpty() || !addedDependencys.isEmpty() || !removedDependencys.isEmpty()) {
saveDependencyChanges(addedBundles, removedBundles, addedDependencys, removedDependencys, objectFactory);
if (overwriteChangedDependencies) {
writeDependencies(features, dependencyCache);
}
} else {
getLog().info(saveTreeListing());
}
} else {
writeDependencies(features, dependencyCache);
}
}
}
use of org.apache.karaf.features.internal.model.Bundle in project karaf by apache.
the class AbstractFeatureMojo method resolveFeatures.
protected Set<Feature> resolveFeatures() throws MojoExecutionException {
Set<Feature> featuresSet = new HashSet<>();
try {
Set<String> artifactsToCopy = new HashSet<>();
Map<String, Feature> featuresMap = new HashMap<>();
for (String uri : descriptors) {
retrieveDescriptorsRecursively(uri, artifactsToCopy, featuresMap);
}
// no features specified, handle all of them
if (features == null) {
features = new ArrayList<>(featuresMap.keySet());
}
addFeatures(features, featuresSet, featuresMap, addTransitiveFeatures);
getLog().info("Using local repository at: " + localRepo.getUrl());
for (Feature feature : featuresSet) {
try {
for (Bundle bundle : feature.getBundle()) {
resolveArtifact(bundle.getLocation());
}
for (Conditional conditional : feature.getConditional()) {
for (BundleInfo bundle : conditional.getBundles()) {
if (ignoreDependencyFlag || (!ignoreDependencyFlag && !bundle.isDependency())) {
resolveArtifact(bundle.getLocation());
}
}
}
for (ConfigFile configfile : feature.getConfigfile()) {
resolveArtifact(configfile.getLocation());
}
} catch (RuntimeException e) {
throw new RuntimeException("Error resolving feature " + feature.getName() + "/" + feature.getVersion(), e);
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error populating repository", e);
}
return featuresSet;
}
use of org.apache.karaf.features.internal.model.Bundle in project karaf by apache.
the class ExportFeatureMetaDataMojo method mergeFeature.
private Feature mergeFeature(Set<Feature> featuresSet) throws MojoExecutionException {
Feature merged = new Feature("merged");
Set<String> bundleIds = new HashSet<>();
for (Feature feature : featuresSet) {
for (Bundle bundle : feature.getBundle()) {
String symbolicName = getBundleSymbolicName(bundle);
if (symbolicName == null) {
logIgnored(bundle);
continue;
}
String bundleId = symbolicName + ":" + getBundleVersion(bundle);
if (!bundleIds.contains(bundleId)) {
bundleIds.add(bundleId);
merged.getBundle().add(bundle);
}
}
}
return merged;
}
use of org.apache.karaf.features.internal.model.Bundle in project karaf by apache.
the class BlacklistTest method testBlacklistBundle.
@Test
public void testBlacklistBundle() {
URL url = getClass().getResource("f02.xml");
Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
List<String> blacklist = new ArrayList<>();
blacklist.add("mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt/1.7_1");
Blacklist.blacklist(features, blacklist);
for (Feature feature : features.getFeature()) {
for (Bundle bundle : feature.getBundle()) {
assertNotEquals("mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt/1.7_1", bundle.getLocation());
}
}
}
use of org.apache.karaf.features.internal.model.Bundle in project karaf by apache.
the class AddToRepositoryMojo method copyBundlesToDestRepository.
private void copyBundlesToDestRepository(List<? extends Bundle> artifactRefs) throws MojoExecutionException {
for (Bundle artifactRef : artifactRefs) {
Artifact artifact = resourceToArtifact(artifactRef.getLocation(), skipNonMavenProtocols);
// Avoid getting NPE on artifact.getFile in some cases
resolveArtifact(artifact, remoteRepos);
if (artifact != null) {
copy(artifact, repository);
}
}
}
Aggregations