use of org.apache.sling.provisioning.model.Configuration in project sling by apache.
the class PreparePackageMojo method buildContentsMap.
/**
* Build a list of all artifacts from this run mode
*/
private void buildContentsMap(final Model model, final RunMode runMode, final Map<String, File> contentsMap, final boolean isBoot) throws MojoExecutionException {
for (final ArtifactGroup group : runMode.getArtifactGroups()) {
for (final org.apache.sling.provisioning.model.Artifact a : group) {
Artifact artifact = null;
if (a.getGroupId().equals(this.project.getGroupId()) && a.getArtifactId().equals(this.project.getArtifactId()) && a.getVersion().equals(this.project.getVersion())) {
for (final Artifact projectArtifact : this.project.getAttachedArtifacts()) {
if (projectArtifact.getClassifier().equals(a.getClassifier())) {
artifact = projectArtifact;
break;
}
}
// check if the artifact is bound already?
if (project.getArtifact().getFile().exists()) {
if (a.getClassifier() != null) {
if (a.getClassifier().equals(project.getArtifact().getClassifier())) {
artifact = project.getArtifact();
} else {
throw new MojoExecutionException("Unable to find artifact from same project with the given classifier: " + a.toMvnUrl());
}
} else {
if (project.getArtifact().getClassifier() == null) {
artifact = project.getArtifact();
} else {
throw new MojoExecutionException("Unable to find artifact with no classifier from same project, because the main artifact is bound to classifier " + project.getArtifact().getClassifier());
}
}
} else {
throw new MojoExecutionException("You must not reference artifact " + a.toMvnUrl() + " from the model which is not yet available in the phase '" + mojoExecution.getLifecyclePhase() + ". Make sure to execute this goal after phase 'package'");
}
} else {
artifact = ModelUtils.getArtifact(this.project, this.mavenSession, this.artifactHandlerManager, this.resolver, a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getType(), a.getClassifier());
}
File artifactFile = artifact.getFile();
String newBSN = a.getMetadata().get("bundle:rename-bsn");
if (newBSN != null) {
try {
getTmpDir().mkdirs();
artifactFile = new BSNRenamer(artifactFile, getTmpDir(), newBSN).process();
} catch (IOException e) {
throw new MojoExecutionException("Unable to rename bundle BSN to " + newBSN + " for " + artifactFile, e);
}
}
contentsMap.put(getPathForArtifact(group.getStartLevel(), artifactFile.getName(), runMode, isBoot), artifactFile);
}
}
final File rootConfDir = new File(this.getTmpDir(), "global-config");
boolean hasConfig = false;
for (final Configuration config : runMode.getConfigurations()) {
// skip special configurations
if (config.isSpecial()) {
continue;
}
final String configPath = getPathForConfiguration(config, runMode);
final File configFile = new File(rootConfDir, configPath);
getLog().debug(String.format("Creating configuration at %s", configFile.getPath()));
configFile.getParentFile().mkdirs();
try {
final FileOutputStream os = new FileOutputStream(configFile);
try {
ConfigurationHandler.write(os, config.getProperties());
} finally {
os.close();
}
} catch (final IOException e) {
throw new MojoExecutionException("Unable to write configuration to " + configFile, e);
}
hasConfig = true;
}
if (hasConfig) {
contentsMap.put(BASE_DESTINATION, rootConfDir);
}
}
use of org.apache.sling.provisioning.model.Configuration in project sling by apache.
the class PreparePackageMojo method buildBootstrapFile.
/**
* Build the bootstrap file for the given packaging run mode
*/
private void buildBootstrapFile(final Model model, final String packageRunMode, final File outputDir) throws MojoExecutionException {
final StringBuilder sb = new StringBuilder();
final Feature launchpadFeature = model.getFeature(ModelConstants.FEATURE_LAUNCHPAD);
if (launchpadFeature != null) {
final RunMode launchpadRunMode = launchpadFeature.getRunMode();
if (launchpadRunMode != null) {
final Configuration c = launchpadRunMode.getConfiguration(ModelConstants.CFG_LAUNCHPAD_BOOTSTRAP);
if (c != null) {
sb.append(c.getProperties().get(c.getPid()));
sb.append('\n');
}
}
final RunMode packageRM = launchpadFeature.getRunMode(new String[] { packageRunMode });
if (packageRM != null) {
final Configuration c = packageRM.getConfiguration(ModelConstants.CFG_LAUNCHPAD_BOOTSTRAP);
if (c != null) {
sb.append(c.getProperties().get(c.getPid()));
sb.append('\n');
}
}
}
if (sb.length() > 0) {
final File file = new File(outputDir, BOOTSTRAP_FILE);
getLog().debug(String.format("Creating bootstrap file at %s", file.getPath()));
try {
FileUtils.fileWrite(file, sb.toString());
} catch (final IOException ioe) {
throw new MojoExecutionException("Unable to write bootstrap file.", ioe);
}
}
}
Aggregations