This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag slingstart-maven-plugin-1.0.0 in repository https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git
commit 42e2fe7e4eb6f0ae67f6ed14998579632188e383 Author: Carsten Ziegeler <[email protected]> AuthorDate: Fri Sep 26 16:05:42 2014 +0000 Implement txt format for reading and writing git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/slingstart-maven-plugin@1627819 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/slingstart/AttachSlingStartModel.java | 8 +-- .../sling/maven/slingstart/BuildConstants.java | 8 +-- .../slingstart/DependencyLifecycleParticipant.java | 23 +++---- .../apache/sling/maven/slingstart/ModelUtils.java | 54 ++++++++-------- .../sling/maven/slingstart/PreparePackageMojo.java | 71 ++++++++++++---------- src/main/resources/META-INF/plexus/components.xml | 4 +- 6 files changed, 90 insertions(+), 78 deletions(-) diff --git a/src/main/java/org/apache/sling/maven/slingstart/AttachSlingStartModel.java b/src/main/java/org/apache/sling/maven/slingstart/AttachSlingStartModel.java index f634942..97f4dc6 100644 --- a/src/main/java/org/apache/sling/maven/slingstart/AttachSlingStartModel.java +++ b/src/main/java/org/apache/sling/maven/slingstart/AttachSlingStartModel.java @@ -28,7 +28,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.sling.slingstart.model.SSMDeliverable; -import org.apache.sling.slingstart.model.xml.XMLSSMModelWriter; +import org.apache.sling.slingstart.model.txt.TXTSSMModelWriter; /** * Attaches the subsystem as a project artifact. @@ -46,12 +46,12 @@ public class AttachSlingStartModel extends AbstractSlingStartMojo { public void execute() throws MojoExecutionException, MojoFailureException { final SSMDeliverable model = this.readModel(); - final File outputFile = new File(this.project.getBuild().getDirectory() + File.separatorChar + "slingstart.xml"); + final File outputFile = new File(this.project.getBuild().getDirectory() + File.separatorChar + "slingstart.txt"); outputFile.getParentFile().mkdirs(); Writer writer = null; try { writer = new FileWriter(outputFile); - XMLSSMModelWriter.write(writer, model); + TXTSSMModelWriter.write(writer, model); } catch (IOException e) { throw new MojoExecutionException("Unable to write model to " + outputFile, e); } finally { @@ -63,7 +63,7 @@ public class AttachSlingStartModel extends AbstractSlingStartMojo { project.getArtifact().setFile(outputFile); } else { // otherwise attach it as an additional artifact - projectHelper.attachArtifact(project, BuildConstants.TYPE_XML, BuildConstants.CLASSIFIER_PARTIAL_SYSTEM, outputFile); + projectHelper.attachArtifact(project, BuildConstants.TYPE_TXT, BuildConstants.CLASSIFIER_PARTIAL_SYSTEM, outputFile); } } } diff --git a/src/main/java/org/apache/sling/maven/slingstart/BuildConstants.java b/src/main/java/org/apache/sling/maven/slingstart/BuildConstants.java index 01f2238..265aea5 100644 --- a/src/main/java/org/apache/sling/maven/slingstart/BuildConstants.java +++ b/src/main/java/org/apache/sling/maven/slingstart/BuildConstants.java @@ -19,14 +19,14 @@ package org.apache.sling.maven.slingstart; import java.util.ArrayList; import java.util.List; -import org.apache.sling.slingstart.model.SSMFeature; +import org.apache.sling.slingstart.model.SSMConstants; public abstract class BuildConstants { // CONTEXTS public static final String CONTEXT_GLOBAL = "slingstart:global"; - public static final String CONTEXT_STANDALONE = "slingstart" + SSMFeature.RUN_MODE_STANDALONE; - public static final String CONTEXT_WEBAPP = "slingstart" + SSMFeature.RUN_MODE_WEBAPP; + public static final String CONTEXT_STANDALONE = "slingstart" + SSMConstants.RUN_MODE_STANDALONE; + public static final String CONTEXT_WEBAPP = "slingstart" + SSMConstants.RUN_MODE_WEBAPP; // Types @@ -37,7 +37,7 @@ public abstract class BuildConstants { public static final String TYPE_POM = "pom"; - public static final String TYPE_XML = "xml"; + public static final String TYPE_TXT = "txt"; public static final String PACKAGING_PARTIAL_SYSTEM = "slingsubsystem"; diff --git a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java index 4b3d973..cca358c 100644 --- a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java +++ b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java @@ -37,6 +37,7 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.project.MavenProject; import org.apache.sling.slingstart.model.SSMArtifact; +import org.apache.sling.slingstart.model.SSMConstants; import org.apache.sling.slingstart.model.SSMDeliverable; import org.apache.sling.slingstart.model.SSMFeature; import org.apache.sling.slingstart.model.SSMStartLevel; @@ -120,10 +121,10 @@ public class DependencyLifecycleParticipant extends AbstractMavenLifecyclePartic final String[] classifiers = new String[] {null, BuildConstants.CLASSIFIER_APP, BuildConstants.CLASSIFIER_WEBAPP}; for(final String c : classifiers) { final Dependency dep = new Dependency(); - dep.setGroupId(base.groupId); - dep.setArtifactId(base.artifactId); - dep.setVersion(model.getValue(base.version)); - dep.setType(base.type); + dep.setGroupId(base.getGroupId()); + dep.setArtifactId(base.getArtifactId()); + dep.setVersion(model.getValue(base.getVersion())); + dep.setType(base.getType()); dep.setClassifier(c); if ( BuildConstants.CLASSIFIER_WEBAPP.equals(c) ) { dep.setType(BuildConstants.TYPE_WAR); @@ -140,17 +141,17 @@ public class DependencyLifecycleParticipant extends AbstractMavenLifecyclePartic private static void addDependencies(final SSMDeliverable model, final Logger log, final MavenProject project) { for(final SSMFeature feature : model.getFeatures()) { // skip base - if ( feature.isRunMode(SSMFeature.RUN_MODE_BASE) ) { + if ( feature.isRunMode(SSMConstants.RUN_MODE_BASE) ) { continue; } for(final SSMStartLevel sl : feature.getStartLevels()) { - for(final SSMArtifact a : sl.artifacts) { + for(final SSMArtifact a : sl.getArtifacts()) { final Dependency dep = new Dependency(); - dep.setGroupId(a.groupId); - dep.setArtifactId(a.artifactId); - dep.setVersion(model.getValue(a.version)); - dep.setType(a.type); - dep.setClassifier(a.classifier); + dep.setGroupId(a.getGroupId()); + dep.setArtifactId(a.getArtifactId()); + dep.setVersion(model.getValue(a.getVersion())); + dep.setType(a.getType()); + dep.setClassifier(a.getClassifier()); dep.setScope(PROVIDED); log.debug("- adding dependency " + dep); diff --git a/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java b/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java index 6895e23..ab3c0f0 100644 --- a/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java +++ b/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.commons.io.IOUtils; @@ -30,8 +31,12 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.sling.slingstart.model.SSMArtifact; +import org.apache.sling.slingstart.model.SSMConstants; import org.apache.sling.slingstart.model.SSMDeliverable; import org.apache.sling.slingstart.model.SSMFeature; +import org.apache.sling.slingstart.model.SSMTraceable; +import org.apache.sling.slingstart.model.SSMValidator; +import org.apache.sling.slingstart.model.txt.TXTSSMModelReader; import org.apache.sling.slingstart.model.xml.XMLSSMModelReader; import org.codehaus.plexus.logging.Logger; @@ -47,7 +52,7 @@ public abstract class ModelUtils { final List<String> candidates = new ArrayList<String>(); if ( systemsDirectory != null && systemsDirectory.exists() ) { for(final File f : systemsDirectory.listFiles() ) { - if ( f.isFile() && f.getName().endsWith(".xml") && !f.getName().startsWith(".") ) { + if ( f.isFile() && f.getName().endsWith(".txt") && !f.getName().startsWith(".") ) { candidates.add(f.getName()); } } @@ -59,13 +64,13 @@ public abstract class ModelUtils { for(final String name : candidates) { logger.debug("Reading model " + name + " in project " + project.getId()); try { - final FileReader reader = new FileReader(new File(systemsDirectory, name)); + final File f = new File(systemsDirectory, name); + final FileReader reader = new FileReader(f); try { - final SSMDeliverable current = XMLSSMModelReader.read(reader); - try { - current.validate(); - } catch ( final IllegalStateException ise) { - throw new MojoExecutionException("Invalid model at " + name, ise); + final SSMDeliverable current = TXTSSMModelReader.read(reader, f.getAbsolutePath()); + final Map<SSMTraceable, String> errors = new SSMValidator().validate(current); + if (errors != null ) { + throw new MojoExecutionException("Invalid model at " + name + " : " + errors); } result.merge(current); } finally { @@ -76,10 +81,9 @@ public abstract class ModelUtils { } } - try { - result.validate(); - } catch ( final IllegalStateException ise) { - throw new MojoExecutionException("Invalid assembled model", ise); + final Map<SSMTraceable, String> errors = new SSMValidator().validate(result); + if (errors != null ) { + throw new MojoExecutionException("Invalid assembled model : " + errors); } return result; @@ -107,10 +111,9 @@ public abstract class ModelUtils { depModel = new SSMDeliverable(); } final SSMDeliverable readModel = XMLSSMModelReader.read(r); - try { - readModel.validate(); - } catch ( final IllegalStateException ise) { - throw new MojoExecutionException("Invalid model " + file, ise); + final Map<SSMTraceable, String> errors = new SSMValidator().validate(readModel); + if (errors != null ) { + throw new MojoExecutionException("Invalid model at " + file + " : " + errors); } depModel.merge(readModel); } finally { @@ -119,13 +122,16 @@ public abstract class ModelUtils { } final SSMDeliverable result; if ( depModel != null ) { - try { - depModel.validate(); - depModel.merge(localModel); - depModel.validate(); - } catch ( final IllegalStateException ise) { - throw new MojoExecutionException("Invalid model.", ise); + Map<SSMTraceable, String> errors = new SSMValidator().validate(depModel); + if (errors != null ) { + throw new MojoExecutionException("Invalid model : " + errors); } + depModel.merge(localModel); + errors = new SSMValidator().validate(depModel); + if (errors != null ) { + throw new MojoExecutionException("Invalid model : " + errors); + } + result = depModel; } else { result = localModel; @@ -138,7 +144,7 @@ public abstract class ModelUtils { public static SSMArtifact getBaseArtifact(final SSMDeliverable model) throws MojoExecutionException { // get base run mode - final SSMFeature base = model.getRunMode(SSMFeature.RUN_MODE_BASE); + final SSMFeature base = model.getRunMode(SSMConstants.RUN_MODE_BASE); if ( base == null ) { throw new MojoExecutionException("No base run mode found."); } @@ -148,11 +154,11 @@ public abstract class ModelUtils { if ( base.getStartLevels().size() > 1 ) { throw new MojoExecutionException("Base run mode should only have a single start level."); } - if ( base.getStartLevels().get(0).artifacts.size() != 1 ) { + if ( base.getStartLevels().get(0).getArtifacts().size() != 1 ) { throw new MojoExecutionException("Base run mode should contain exactly one artifact."); } - return base.getStartLevels().get(0).artifacts.get(0); + return base.getStartLevels().get(0).getArtifacts().get(0); } /** diff --git a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java index f066ad0..9d13ef3 100644 --- a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java +++ b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java @@ -18,12 +18,15 @@ package org.apache.sling.maven.slingstart; import java.io.File; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.TreeSet; +import org.apache.commons.io.IOUtils; import org.apache.felix.cm.file.ConfigurationHandler; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; @@ -101,11 +104,11 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { // unpack base artifact and create settings final File outputDir = new File(this.project.getBuild().getOutputDirectory()); - unpackBaseArtifact(model, outputDir, SSMFeature.RUN_MODE_STANDALONE); - this.buildSettings(model, SSMFeature.RUN_MODE_STANDALONE, outputDir); - this.buildBootstrapFile(model, SSMFeature.RUN_MODE_STANDALONE, outputDir); + unpackBaseArtifact(model, outputDir, SSMConstants.RUN_MODE_STANDALONE); + this.buildSettings(model, SSMConstants.RUN_MODE_STANDALONE, outputDir); + this.buildBootstrapFile(model, SSMConstants.RUN_MODE_STANDALONE, outputDir); - this.buildContentsMap(model, SSMFeature.RUN_MODE_STANDALONE, contentsMap); + this.buildContentsMap(model, SSMConstants.RUN_MODE_STANDALONE, contentsMap); } /** @@ -119,10 +122,10 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { // 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, SSMFeature.RUN_MODE_WEBAPP); + unpackBaseArtifact(model, outputDir, SSMConstants.RUN_MODE_WEBAPP); // check for web.xml - final SSMFeature webappRM = model.getRunMode(SSMFeature.RUN_MODE_WEBAPP); + final SSMFeature webappRM = model.getRunMode(SSMConstants.RUN_MODE_WEBAPP); if ( webappRM != null ) { final SSMConfiguration webConfig = webappRM.getConfiguration(SSMConstants.CFG_WEB_XML); if ( webConfig != null ) { @@ -134,10 +137,10 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { } } } - this.buildSettings(model, SSMFeature.RUN_MODE_WEBAPP, webappDir); - this.buildBootstrapFile(model, SSMFeature.RUN_MODE_WEBAPP, outputDir); + this.buildSettings(model, SSMConstants.RUN_MODE_WEBAPP, webappDir); + this.buildBootstrapFile(model, SSMConstants.RUN_MODE_WEBAPP, outputDir); - this.buildContentsMap(model, SSMFeature.RUN_MODE_WEBAPP, contentsMap); + this.buildContentsMap(model, SSMConstants.RUN_MODE_WEBAPP, contentsMap); } } @@ -154,7 +157,7 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { for(final SSMFeature feature : model.getFeatures()) { if ( packageRunMode == null ) { if ( feature.isSpecial() - && !feature.isRunMode(SSMFeature.RUN_MODE_BOOT)) { + && !feature.isRunMode(SSMConstants.RUN_MODE_BOOT)) { continue; } this.buildContentsMap(model, feature, contentsMap); @@ -172,8 +175,8 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { private void buildContentsMap(final SSMDeliverable model, final SSMFeature runMode, final Map<String, File> contentsMap) throws MojoExecutionException{ for(final SSMStartLevel sl : runMode.getStartLevels()) { - for(final SSMArtifact a : sl.artifacts) { - final Artifact artifact = ModelUtils.getArtifact(this.project, a.groupId, a.artifactId, model.getValue(a.version), a.type, a.classifier); + for(final SSMArtifact a : sl.getArtifacts()) { + final Artifact artifact = ModelUtils.getArtifact(this.project, a.getGroupId(), a.getArtifactId(), model.getValue(a.getVersion()), a.getType(), a.getClassifier()); final File artifactFile = artifact.getFile(); contentsMap.put(getPathForArtifact(sl.getLevel(), artifactFile.getName(), runMode), artifactFile); } @@ -212,29 +215,31 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { */ private void buildSettings(final SSMDeliverable model, final String packageRunMode, final File outputDir) throws MojoExecutionException { - String settings = null; - final SSMFeature baseRM = model.getRunMode(SSMFeature.RUN_MODE_BASE); - if ( baseRM != null && baseRM.getSettings() != null ) { - settings = baseRM.getSettings().properties + "\n"; - } else { - settings = ""; + final Properties settings = new Properties(); + final SSMFeature baseRM = model.getRunMode(SSMConstants.RUN_MODE_BASE); + if ( baseRM != null ) { + settings.putAll(baseRM.getSettings()); } - final SSMFeature bootRM = model.getRunMode(SSMFeature.RUN_MODE_BOOT); - if ( bootRM != null && bootRM.getSettings() != null ) { - settings = settings + bootRM.getSettings().properties + "\n"; + final SSMFeature bootRM = model.getRunMode(SSMConstants.RUN_MODE_BOOT); + if ( bootRM != null ) { + settings.putAll(bootRM.getSettings()); } final SSMFeature packageRM = model.getRunMode(packageRunMode); - if ( packageRM != null && packageRM.getSettings() != null ) { - settings = settings + packageRM.getSettings().properties; + if ( packageRM != null ) { + settings.putAll(packageRM.getSettings()); } - if ( settings != null ) { + if ( settings.size() > 0 ) { final File settingsFile = new File(outputDir, PROPERTIES_FILE); getLog().debug(String.format("Creating settings at %s", settingsFile.getPath())); + FileWriter writer = null; try { - FileUtils.fileWrite(settingsFile, settings); + writer = new FileWriter(settingsFile); + settings.store(writer, null); } catch ( final IOException ioe ) { throw new MojoExecutionException("Unable to write properties file.", ioe); + } finally { + IOUtils.closeQuietly(writer); } } } @@ -245,7 +250,7 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { private void buildBootstrapFile(final SSMDeliverable model, final String packageRunMode, final File outputDir) throws MojoExecutionException { final StringBuilder sb = new StringBuilder(); - final SSMFeature baseRM = model.getRunMode(SSMFeature.RUN_MODE_BASE); + final SSMFeature baseRM = model.getRunMode(SSMConstants.RUN_MODE_BASE); if ( baseRM != null ) { final SSMConfiguration c = baseRM.getConfiguration(SSMConstants.CFG_BOOTSTRAP); if ( c != null ) { @@ -253,7 +258,7 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { sb.append('\n'); } } - final SSMFeature bootRM = model.getRunMode(SSMFeature.RUN_MODE_BOOT); + final SSMFeature bootRM = model.getRunMode(SSMConstants.RUN_MODE_BOOT); if ( bootRM != null ) { final SSMConfiguration c = bootRM.getConfiguration(SSMConstants.CFG_BOOTSTRAP); if ( c != null ) { @@ -287,15 +292,15 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { private Artifact getBaseArtifact(final SSMDeliverable model, final String classifier, final String type) throws MojoExecutionException { final SSMArtifact baseArtifact = ModelUtils.getBaseArtifact(model); - final Artifact a = ModelUtils.getArtifact(this.project, baseArtifact.groupId, - baseArtifact.artifactId, - model.getValue(baseArtifact.version), + final Artifact a = ModelUtils.getArtifact(this.project, baseArtifact.getGroupId(), + baseArtifact.getArtifactId(), + model.getValue(baseArtifact.getVersion()), type, classifier); if (a == null) { throw new MojoExecutionException( String.format("Project doesn't have a base dependency of groupId %s and artifactId %s", - baseArtifact.groupId, baseArtifact.artifactId)); + baseArtifact.getGroupId(), baseArtifact.getArtifactId())); } return a; } @@ -307,7 +312,7 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { throws MojoExecutionException { final String classifier; final String type; - if ( SSMFeature.RUN_MODE_STANDALONE.equals(packageRunMode) ) { + if ( SSMConstants.RUN_MODE_STANDALONE.equals(packageRunMode) ) { classifier = BuildConstants.CLASSIFIER_APP; type = BuildConstants.TYPE_JAR; } else { @@ -362,7 +367,7 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { runModeExt = sb.toString(); } - if ( rm.isRunMode(SSMFeature.RUN_MODE_BOOT) ) { + if ( rm.isRunMode(SSMConstants.RUN_MODE_BOOT) ) { return String.format("%s/%s/1/%s", BASE_DESTINATION, BOOT_DIRECTORY, artifactName); } diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml index 8896896..29d8eaa 100644 --- a/src/main/resources/META-INF/plexus/components.xml +++ b/src/main/resources/META-INF/plexus/components.xml @@ -74,8 +74,8 @@ <configuration> <type>slingsubsystem</type> <includesDependencies>false</includesDependencies> - <language>xml</language> - <extension>xml</extension> + <language>txt</language> + <extension>txt</extension> <addedToClasspath>false</addedToClasspath> </configuration> </component> -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
