in src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java [263:343]
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);
}
}