use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class AbstractUsingBundleListMojo method initBundleList.
private final void initBundleList() throws IOException, XmlPullParserException, MojoExecutionException {
initArtifactDefinitions();
if (BundleListUtils.isCurrentArtifact(project, defaultBundleList)) {
initializedBundleList = readBundleList(bundleListFile);
} else {
initializedBundleList = new BundleList();
if (includeDefaultBundles) {
Artifact defBndListArtifact = getArtifact(defaultBundleList.getGroupId(), defaultBundleList.getArtifactId(), defaultBundleList.getVersion(), defaultBundleList.getType(), defaultBundleList.getClassifier());
getLog().info("Using bundle list file from " + defBndListArtifact.getFile().getAbsolutePath());
initializedBundleList = readBundleList(defBndListArtifact.getFile());
}
if (bundleListFile.exists()) {
initializedBundleList.merge(readBundleList(bundleListFile));
}
}
// add additional bundles
if (additionalBundles != null) {
for (ArtifactDefinition def : additionalBundles) {
initializedBundleList.add(def.toBundleList());
}
}
interpolateProperties(initializedBundleList, project, mavenSession);
// check for partial bundle lists
final Set<Artifact> dependencies = project.getDependencyArtifacts();
for (Artifact artifact : dependencies) {
if (PARTIAL.equals(artifact.getType())) {
getLog().info(String.format("Merging partial bundle list %s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()));
initializedBundleList.merge(readBundleList(artifact.getFile()));
}
}
// handle exclusions
if (bundleExclusions != null) {
for (ArtifactDefinition def : bundleExclusions) {
initializedBundleList.remove(def.toBundleList(), false);
}
}
initBundleList(initializedBundleList);
interpolateProperties(initializedBundleList, project, mavenSession);
rewriteBundleList(initializedBundleList);
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class CheckBundleListForSnapshotsMojo method executeWithArtifacts.
@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
List<Bundle> snapshots = new ArrayList<Bundle>();
BundleList bundleList = getInitializedBundleList();
for (StartLevel level : bundleList.getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
if (isSnapshot(bundle)) {
snapshots.add(bundle);
}
}
}
if (!snapshots.isEmpty()) {
getLog().error("The following entries in the bundle list file are SNAPSHOTs:");
for (Bundle bundle : snapshots) {
getLog().error(String.format(" %s:%s:%s", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion()));
}
if (failOnSnapshot) {
throw new MojoFailureException("SNAPSHOTs were found in the bundle list. See log.");
}
}
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class CreateKarafFeatureDescriptorMojo method executeWithArtifacts.
@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
Document doc = new Document();
Element features = new Element("features");
doc.setRootElement(features);
features.setAttribute("name", featuresName);
Element feature = new Element("feature");
features.addContent(feature);
feature.setAttribute("name", featureName);
feature.setAttribute("version", featureVersion);
BundleList bundleList = getInitializedBundleList();
for (StartLevel level : bundleList.getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
String bundleRef = String.format("mvn:%s/%s/%s", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion());
feature.addContent(new Element("bundle").setText(bundleRef));
}
}
FileOutputStream out = null;
try {
out = new FileOutputStream(outputFile);
new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8")).output(doc, out);
projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write features.xml", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class BundleListContentProvider method handleResourcesRoot.
private Iterator<String> handleResourcesRoot() {
final Set<String> subDirs = new HashSet<String>();
subDirs.add(BUNDLE_PATH_PREFIX);
subDirs.add(CONFIG_PATH_PREFIX);
subDirs.add("resources/corebundles");
subDirs.add(INSTALL_PATH_PREFIX);
// Compute the set of run modes in our bundles
final Set<String> runModes = new HashSet<String>();
for (final StartLevel level : getInitializedBundleList().getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
final String modes = bundle.getRunModes();
if (modes != null && modes.length() > 0) {
for (String m : modes.split(",")) {
runModes.add("." + m);
}
}
}
}
// Add one install subdir per run mode
for (String m : runModes) {
subDirs.add(INSTALL_PATH_PREFIX + m);
}
return subDirs.iterator();
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class BundleListContentProvider method addBundles.
private void addBundles(Collection<String> bundles, int startLevel, String runMode) {
for (final StartLevel level : getInitializedBundleList().getStartLevels()) {
if (level.getStartLevel() == startLevel) {
for (final Bundle bundle : level.getBundles()) {
if (!runModeMatches(bundle, runMode)) {
continue;
}
final ArtifactDefinition d = new ArtifactDefinition(bundle, startLevel);
try {
final Artifact artifact = getArtifact(d);
bundles.add(artifact.getFile().toURI().toURL().toExternalForm());
} catch (Exception e) {
getLog().error("Unable to resolve artifact ", e);
}
}
}
}
}
Aggregations