use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList 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.BundleList in project sling by apache.
the class BundleListUtils method interpolateProperties.
public static void interpolateProperties(BundleList bundleList, MavenProject project, MavenSession mavenSession) throws MojoExecutionException {
Interpolator interpolator = createInterpolator(project, mavenSession);
for (final StartLevel sl : bundleList.getStartLevels()) {
for (final Bundle bndl : sl.getBundles()) {
try {
bndl.setArtifactId(interpolator.interpolate(bndl.getArtifactId()));
bndl.setGroupId(interpolator.interpolate(bndl.getGroupId()));
bndl.setVersion(interpolator.interpolate(bndl.getVersion()));
bndl.setClassifier(interpolator.interpolate(bndl.getClassifier()));
bndl.setType(interpolator.interpolate(bndl.getType()));
} catch (InterpolationException e) {
throw new MojoExecutionException("Unable to interpolate properties for bundle " + bndl.toString(), e);
}
}
}
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class BundleListContentProviderTest method parseBundleList.
@BeforeClass
public static void parseBundleList() throws Exception {
final BundleListXpp3Reader reader = new BundleListXpp3Reader();
final InputStream is = BundleListContentProviderTest.class.getClassLoader().getResourceAsStream(TEST_BUNDLE_LIST);
assertNotNull("Expecting " + TEST_BUNDLE_LIST + " to be found", is);
try {
bundleList = reader.read(is);
} finally {
is.close();
}
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class BundleListContentProviderTest method setupProvider.
@Before
public void setupProvider() {
final Log log = Mockito.mock(Log.class);
final Answer<Void> countWarningAnswers = new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Throwable {
logWarningsCount++;
return null;
}
};
Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(String.class));
Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(Throwable.class));
Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(String.class), Matchers.any(Throwable.class));
provider = new BundleListContentProvider(resourceProviderRoot) {
@Override
BundleList getInitializedBundleList() {
return bundleList;
}
@Override
File getConfigDirectory() {
return configDirectory;
}
@Override
Artifact getArtifact(ArtifactDefinition def) throws MojoExecutionException {
final Artifact a = Mockito.mock(Artifact.class);
final String fakeName = new StringBuilder().append("/FAKE_BUNDLE/").append(def.getArtifactId()).append("/").append(def.getStartLevel()).append("/").append(def.getRunModes()).toString();
Mockito.when(a.getFile()).thenReturn(new File(fakeName));
return a;
}
@Override
Log getLog() {
return log;
}
};
}
use of org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList in project sling by apache.
the class CreatePaxRunnerBundleProvisionFileMojo method executeWithArtifacts.
@Override
protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
FileWriter out = null;
try {
out = new FileWriter(outputFile);
BundleList bundleList = getInitializedBundleList();
for (StartLevel level : bundleList.getStartLevels()) {
for (Bundle bundle : level.getBundles()) {
String line = String.format("mvn:%s/%s/%s@%d\n", bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion(), level.getStartLevel());
out.write(line);
}
}
projectHelper.attachArtifact(project, TYPE, CLASSIFIER, outputFile);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write " + outputFile.getName(), e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}
Aggregations