use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class DisplayBundleUpdatesMojo method execute.
@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException, MojoFailureException {
try {
BundleList bundleList = readBundleList(bundleListFile);
Set<Dependency> bundlesAsDependencies = new HashSet<Dependency>();
for (StartLevel startLevel : bundleList.getStartLevels()) {
for (Bundle bundle : startLevel.getBundles()) {
bundlesAsDependencies.add(asDependency(bundle));
}
}
logUpdates(getHelper().lookupDependenciesUpdates(bundlesAsDependencies, false));
} catch (Exception e) {
throw new MojoExecutionException("Unable to read bundle list.", e);
}
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class AttachPartialBundleListMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
final BundleList initializedBundleList;
if (bundleListFile.exists()) {
try {
initializedBundleList = readBundleList(bundleListFile);
} catch (IOException e) {
throw new MojoExecutionException("Unable to read bundle list file", e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Unable to read bundle list file", e);
}
} else {
throw new MojoFailureException(String.format("Bundle list file %s does not exist.", bundleListFile.getAbsolutePath()));
}
interpolateProperties(initializedBundleList, this.project, this.mavenSession);
final BundleListXpp3Writer writer = new BundleListXpp3Writer();
try {
this.bundleListOutput.getParentFile().mkdirs();
writer.write(new FileWriter(bundleListOutput), initializedBundleList);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write bundle list", e);
}
// if this project is a partial bundle list, it's the main artifact
if (project.getPackaging().equals(PARTIAL)) {
project.getArtifact().setFile(bundleListOutput);
} else {
// otherwise attach it as an additional artifact
projectHelper.attachArtifact(project, TYPE, CLASSIFIER, bundleListOutput);
}
this.getLog().info("Attaching bundle list configuration");
try {
this.attachConfigurations();
} catch (final IOException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
} catch (final ArchiverException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
}
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class CreateBundleJarMojo method addBundles.
private void addBundles() throws MojoExecutionException {
BundleList bundles = getInitializedBundleList();
for (StartLevel level : bundles.getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
Artifact artifact = getArtifact(new ArtifactDefinition(bundle, level.getStartLevel()));
final String destFileName = getPathForArtifact(level.getStartLevel(), bundle.getRunModes(), artifact.getFile().getName());
try {
jarArchiver.addFile(artifact.getFile(), destFileName);
} catch (ArchiverException e) {
throw new MojoExecutionException("Unable to add file to bundle jar file: " + artifact.getFile().getAbsolutePath(), e);
}
}
}
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class SlingPaxOptions method slingBundleList.
public static CompositeOption slingBundleList(String groupId, String artifactId, String version, String type, String classifier) {
final DefaultCompositeOption result = new DefaultCompositeOption();
final String paxUrl = new StringBuilder().append("mvn:").append(groupId).append("/").append(artifactId).append("/").append(version == null ? "" : version).append("/").append(type == null ? "" : type).append("/").append(classifier == null ? "" : classifier).toString();
// TODO BundleList should take an InputStream - for now copy to a tmp file for parsing
log.info("Getting bundle list {}", paxUrl);
File tmp = null;
final Collection<String> testRunModes = getTestRunModes();
try {
tmp = dumpMvnUrlToTmpFile(paxUrl);
final BundleList list = BundleListUtils.readBundleList(tmp);
int counter = 0;
int ignored = 0;
for (StartLevel s : list.getStartLevels()) {
// Start level < 0 means bootstrap in our bundle lists
final int startLevel = s.getStartLevel() < 0 ? 1 : s.getStartLevel();
for (Bundle b : s.getBundles()) {
if (ignore(b)) {
log.info("Bundle ignored due to setIgnoredBundles: {}", b);
ignored++;
continue;
}
counter++;
// TODO need better fragment detection
// (but pax exam should really detect that by itself?)
final List<String> KNOWN_FRAGMENTS = new ArrayList<String>();
KNOWN_FRAGMENTS.add("org.apache.sling.extensions.webconsolebranding");
final boolean isFragment = b.getArtifactId().contains("fragment") || KNOWN_FRAGMENTS.contains(b.getArtifactId());
// Ignore bundles with run modes that do not match ours
final String bundleRunModes = b.getRunModes();
if (bundleRunModes != null && bundleRunModes.length() > 0) {
boolean active = false;
for (String m : bundleRunModes.split(",")) {
if (testRunModes.contains(m)) {
active = true;
break;
}
}
if (!active) {
log.info("Ignoring bundle {} as none of its run modes [{}] are active in this test run {}", new Object[] { b.getArtifactId(), bundleRunModes, testRunModes });
continue;
}
}
if (isFragment) {
result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).noStart());
} else if (startLevel == 0) {
result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()));
} else {
result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).startLevel(startLevel));
}
log.info("Bundle added: {}/{}/{}", new Object[] { b.getGroupId(), b.getArtifactId(), b.getVersion() });
}
}
log.info("Got {} bundles ({} ignored) from {}", new Object[] { counter, ignored, paxUrl });
} catch (Exception e) {
throw new RuntimeException("Error getting bundle list " + paxUrl, e);
} finally {
if (tmp != null) {
tmp.delete();
}
}
return result;
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle in project sling by apache.
the class ArtifactDefinition method toBundleList.
public List<Bundle> toBundleList() {
ArrayList<Bundle> bundleList = new ArrayList<Bundle>();
if (bundles == null) {
Bundle bnd = new Bundle();
bnd.setArtifactId(artifactId);
bnd.setGroupId(groupId);
bnd.setVersion(version);
if (type != null) {
bnd.setType(type);
}
bnd.setClassifier(classifier);
bnd.setStartLevel(startLevel);
bundleList.add(bnd);
} else {
for (ArtifactDefinition bundle : bundles) {
bundleList.addAll(bundle.toBundleList());
}
}
return bundleList;
}
Aggregations