use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class AbstractFeatureMojo method retrieveDescriptorsRecursively.
protected void retrieveDescriptorsRecursively(String uri, Set<String> bundles, Map<String, Feature> featuresMap) {
// let's ensure a mvn: based url is sitting in the local repo before we try reading it
Artifact descriptor;
try {
descriptor = resourceToArtifact(uri, true);
} catch (MojoExecutionException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (descriptor != null) {
resolveArtifact(descriptor, remoteRepos);
descriptorArtifacts.add(descriptor);
}
if (includeMvnBasedDescriptors) {
bundles.add(uri);
}
String uriToUse = descriptor != null ? descriptor.getFile().toURI().toString() : translateFromMaven(uri);
Features repo = JaxbUtil.unmarshal(uriToUse, true);
for (Feature f : repo.getFeature()) {
featuresMap.put(f.getId(), f);
}
if (resolveDefinedRepositoriesRecursively) {
for (String r : repo.getRepository()) {
retrieveDescriptorsRecursively(r, bundles, featuresMap);
}
}
}
use of org.apache.karaf.features.internal.model.Features 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.Features in project karaf by apache.
the class BlacklistTest method testBlacklistFeatureWithRange.
@Test
public void testBlacklistFeatureWithRange() {
URL url = getClass().getResource("f02.xml");
Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
List<String> blacklist = new ArrayList<>();
blacklist.add("spring;range=\"[2,3)\"");
Blacklist.blacklist(features, blacklist);
for (Feature feature : features.getFeature()) {
assertNotEquals("spring/2.5.6.SEC02", feature.getId());
}
}
use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class FeaturesValidationTest method testNs13Unmarshall.
@Test
public void testNs13Unmarshall() throws Exception {
URL url = getClass().getResource("f07.xml");
Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
assertNotNull(features);
assertEquals("2.5.6.SEC02", features.getFeature().get(0).getVersion());
assertTrue(features.getFeature().get(1).isHidden());
assertNotNull(features.getFeature().get(1).getLibraries());
assertEquals(1, features.getFeature().get(0).getLibraries().size());
assertEquals("my-library", features.getFeature().get(0).getLibraries().get(0).getLocation());
assertEquals(Library.TYPE_ENDORSED, features.getFeature().get(0).getLibraries().get(0).getType());
assertFalse(features.getFeature().get(0).getLibraries().get(0).isExport());
assertTrue(features.getFeature().get(0).getLibraries().get(0).isDelegate());
}
use of org.apache.karaf.features.internal.model.Features in project karaf by apache.
the class FeaturesValidationTest method testNs10NoNameUnmarshall.
@Test
public void testNs10NoNameUnmarshall() throws Exception {
URL url = getClass().getResource("f03.xml");
Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
assertNotNull(features);
}
Aggregations