use of org.apache.sling.provisioning.model.RunMode in project sling by apache.
the class PreparePackageMojo method prepareWebapp.
/**
* Prepare the web application.
*/
private void prepareWebapp(final Model model) throws MojoExecutionException {
if (this.createWebapp) {
final Map<String, File> contentsMap = new HashMap<String, File>();
this.project.setContextValue(BuildConstants.CONTEXT_WEBAPP, contentsMap);
// unpack base artifact and create settings
final File outputDir = new File(this.project.getBuild().getDirectory(), BuildConstants.WEBAPP_OUTDIR);
final File webappDir = new File(outputDir, "WEB-INF");
unpackBaseArtifact(model, outputDir, ModelConstants.RUN_MODE_WEBAPP);
// check for web.xml
final Feature webappF = model.getFeature(ModelConstants.FEATURE_LAUNCHPAD);
if (webappF != null) {
final RunMode webappRM = webappF.getRunMode();
if (webappRM != null) {
final Configuration webConfig = webappRM.getConfiguration(ModelConstants.CFG_LAUNCHPAD_WEB_XML);
if (webConfig != null) {
final File webXML = new File(webappDir, "web.xml");
try {
FileUtils.fileWrite(webXML, webConfig.getProperties().get(ModelConstants.CFG_LAUNCHPAD_WEB_XML).toString());
} catch (final IOException e) {
throw new MojoExecutionException("Unable to write configuration to " + webXML, e);
}
}
}
}
this.buildSettings(model, ModelConstants.RUN_MODE_WEBAPP, webappDir);
this.buildBootstrapFile(model, ModelConstants.RUN_MODE_WEBAPP, webappDir);
this.embedModel(model, webappDir);
this.buildContentsMap(model, ModelConstants.RUN_MODE_WEBAPP, contentsMap);
}
}
use of org.apache.sling.provisioning.model.RunMode in project sling by apache.
the class PreparePackageMojo method getRunModesManifest.
private Manifest getRunModesManifest(Feature feature) throws MojoExecutionException {
Map<String, StringBuilder> runModes = new HashMap<>();
for (RunMode rm : feature.getRunModes()) {
for (ArtifactGroup ag : rm.getArtifactGroups()) {
// For subsystems the start level on the artifact group is used as start order.
int startOrder = ag.getStartLevel();
for (org.apache.sling.provisioning.model.Artifact a : ag) {
Artifact 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 entryName = getEntryName(artifactFile, startOrder);
String[] runModeNames = rm.getNames();
if (runModeNames == null)
runModeNames = new String[] { ALL_RUNMODES_KEY };
for (String runModeName : runModeNames) {
StringBuilder sb = runModes.get(runModeName);
if (sb == null) {
sb = new StringBuilder();
runModes.put(runModeName, sb);
} else {
sb.append('|');
}
sb.append(entryName);
}
}
}
}
Manifest mf = new Manifest();
Attributes attrs = mf.getMainAttributes();
// Manifest does not work without this value
attrs.putValue("Manifest-Version", "1.0");
attrs.putValue("About-This-Manifest", "This is not a real manifest, it is used as information when this archive is transformed into a real subsystem .esa file");
for (Map.Entry<String, StringBuilder> entry : runModes.entrySet()) {
attrs.putValue(entry.getKey().replace(':', '_'), entry.getValue().toString());
}
return mf;
}
use of org.apache.sling.provisioning.model.RunMode in project sling by apache.
the class PreparePackageMojo method createSubsystemBaseFile.
private File createSubsystemBaseFile(Feature feature, AtomicInteger startLevelHolder) throws MojoExecutionException {
File subsystemFile = new File(getTmpDir(), feature.getName() + ".subsystem-base");
if (subsystemFile.exists()) {
// TODO is there a better way to avoid calling this multiple times?
return null;
}
startLevelHolder.set(-1);
// The runmodes information has to be the first item in the archive so that we always have it available when the
// archive is being processed. For this reason a Jar file is used here as it's guaranteed to store the manifest
// first.
Manifest runModesManifest = getRunModesManifest(feature);
getLog().info("Creating subsystem base file: " + subsystemFile.getName());
boolean created = subsystemFile.getParentFile().mkdirs();
if (!created) {
throw new MojoExecutionException("Failed creating " + subsystemFile.getParentFile().getAbsolutePath());
}
try (JarOutputStream os = new JarOutputStream(new FileOutputStream(subsystemFile), runModesManifest)) {
Map<String, Integer> bsnStartOrderMap = new HashMap<>();
for (RunMode rm : feature.getRunModes()) {
for (ArtifactGroup ag : rm.getArtifactGroups()) {
// For subsystems the start level on the artifact group is used as start order.
int startOrder = ag.getStartLevel();
for (org.apache.sling.provisioning.model.Artifact a : ag) {
Artifact 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 entryName = getEntryName(artifactFile, startOrder);
ZipEntry ze = new ZipEntry(entryName);
try {
os.putNextEntry(ze);
Files.copy(artifactFile.toPath(), os);
} finally {
os.closeEntry();
}
}
}
}
int sl = createSubsystemManifest(feature, bsnStartOrderMap, os);
if (sl != -1)
startLevelHolder.set(sl);
addReadme(os);
} catch (IOException ioe) {
throw new MojoExecutionException("Problem creating subsystem .esa file " + subsystemFile, ioe);
}
return subsystemFile;
}
use of org.apache.sling.provisioning.model.RunMode in project sling by apache.
the class ModelPreprocessor method processAttachments.
private void processAttachments(final Environment env, final ProjectInfo info) throws MavenExecutionException {
final Xpp3Dom config = info.plugin == null ? null : (Xpp3Dom) info.plugin.getConfiguration();
final Xpp3Dom[] nodes = (config == null ? null : config.getChildren("attach"));
if (nodes != null) {
for (final Xpp3Dom node : nodes) {
final String type = nodeValue(node, "type", null);
if (type == null) {
throw new MavenExecutionException("Attachment for provisioning model has no type.", (File) null);
}
final String classifier = nodeValue(node, "classifier", null);
final String featureName = nodeValue(node, "feature", null);
int startLevel = 0;
final String level = nodeValue(node, "startLevel", null);
if (level != null) {
startLevel = Integer.valueOf(level);
}
final Feature f;
if (featureName != null) {
f = info.localModel.getFeature(featureName);
} else if (info.localModel.getFeatures().isEmpty()) {
f = null;
} else {
f = info.localModel.getFeatures().get(0);
}
if (f == null) {
if (featureName == null) {
throw new MavenExecutionException("No feature found in provisioning model for attachment.", (File) null);
}
throw new MavenExecutionException("Feature with name '" + featureName + "' not found in provisioning model for attachment.", (File) null);
}
final RunMode runMode = f.getOrCreateRunMode(null);
final ArtifactGroup group = runMode.getOrCreateArtifactGroup(startLevel);
final org.apache.sling.provisioning.model.Artifact artifact = new org.apache.sling.provisioning.model.Artifact(info.project.getGroupId(), info.project.getArtifactId(), info.project.getVersion(), classifier, type);
env.logger.debug("Attaching " + artifact + " to feature " + f.getName());
group.add(artifact);
}
}
}
use of org.apache.sling.provisioning.model.RunMode in project sling by apache.
the class PreparePackageMojo method buildContentsMap.
/**
* Build a list of all artifacts.
*/
private void buildContentsMap(final Model model, final String packageRunMode, final Map<String, File> contentsMap) throws MojoExecutionException {
if (packageRunMode == null) {
// add base jar
final Artifact artifact = getBaseArtifact(model, null, BuildConstants.TYPE_JAR);
contentsMap.put(BASE_DESTINATION + "/" + artifact.getArtifactId() + "." + artifact.getArtifactHandler().getExtension(), artifact.getFile());
}
for (final Feature feature : model.getFeatures()) {
if (feature.isSpecial() && !feature.getName().equals(ModelConstants.FEATURE_BOOT)) {
continue;
} else if (FeatureTypes.SUBSYSTEM_APPLICATION.equals(feature.getType()) || FeatureTypes.SUBSYSTEM_COMPOSITE.equals(feature.getType()) || FeatureTypes.SUBSYSTEM_FEATURE.equals(feature.getType())) {
buildSubsystemBase(contentsMap, feature);
} else {
for (final RunMode runMode : feature.getRunModes()) {
if (packageRunMode == null) {
if (runMode.isSpecial()) {
continue;
}
this.buildContentsMap(model, runMode, contentsMap, feature.getName().equals(ModelConstants.FEATURE_BOOT));
} else {
if (runMode.isRunMode(packageRunMode)) {
this.buildContentsMap(model, runMode, contentsMap, feature.getName().equals(ModelConstants.FEATURE_BOOT));
}
}
}
}
}
}
Aggregations