You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:16:07 UTC
[sling-maven-launchpad-plugin] 30/34: SLING-2207 : Support
different properties and bootstrap commands for standalone and webapp
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag maven-launchpad-plugin-2.1.0
in repository https://gitbox.apache.org/repos/asf/sling-maven-launchpad-plugin.git
commit 02a8aea9e2d2e5fe735e9061d5089c7091512dff
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Sep 5 15:31:41 2011 +0000
SLING-2207 : Support different properties and bootstrap commands for standalone and webapp
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/maven/maven-launchpad-plugin@1165337 13f79535-47bb-0310-9956-ffa450edef68
---
.../projectsupport/AbstractBundleListMojo.java | 24 +++++
.../AbstractUsingBundleListMojo.java | 105 ++++++++++++++++-----
.../AttachPartialBundleListMojo.java | 33 +++++++
.../maven/projectsupport/PreparePackageMojo.java | 4 +-
4 files changed, 143 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
index e248d2b..912fa3d 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractBundleListMojo.java
@@ -66,6 +66,30 @@ public abstract class AbstractBundleListMojo extends AbstractMojo {
*/
protected File commonSlingBootstrap;
+ /**
+ * @parameter expression="${webappSlingProps}"
+ * default-value="src/main/sling/webapp.properties"
+ */
+ protected File webappSlingProps;
+
+ /**
+ * @parameter expression="${webappSlingBootstrap}"
+ * default-value="src/main/sling/webapp.bootstrap.txt"
+ */
+ protected File webappSlingBootstrap;
+
+ /**
+ * @parameter expression="${standaloneSlingProps}"
+ * default-value="src/main/sling/standalone.properties"
+ */
+ protected File standaloneSlingProps;
+
+ /**
+ * @parameter expression="${standaloneSlingBootstrap}"
+ * default-value="src/main/sling/standalone.bootstrap.txt"
+ */
+ protected File standaloneSlingBootstrap;
+
protected File getConfigDirectory() {
return this.configDirectory;
}
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
index f058a34..34270d5 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/AbstractUsingBundleListMojo.java
@@ -177,8 +177,16 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
private Properties slingProperties;
+ private Properties slingWebappProperties;
+
+ private Properties slingStandaloneProperties;
+
private String slingBootstrapCommand;
+ private String slingWebappBootstrapCommand;
+
+ private String slingStandaloneBootstrapCommand;
+
/**
* @parameter default-value="${project.build.directory}/tmpBundleListconfig"
*/
@@ -380,8 +388,12 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
zipUnarchiver.extract();
final File slingDir = new File(this.tmpOutputDir, "sling");
- this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_PROPS));
- this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_BOOTSTRAP));
+ this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_PROPS), 0);
+ this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_PROPS), 1);
+ this.readSlingProperties(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_PROPS), 2);
+ this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_COMMON_BOOTSTRAP), 0);
+ this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_WEBAPP_BOOTSTRAP), 1);
+ this.readSlingBootstrap(new File(slingDir, AttachPartialBundleListMojo.SLING_STANDALONE_BOOTSTRAP), 2);
// and now configurations
if ( this.overlayConfigDir == null ) {
@@ -458,7 +470,15 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
}
}
- private void readSlingProperties(final File propsFile) throws MojoExecutionException {
+ private void copyProperties(final Properties source, final Properties dest) {
+ final Enumeration<Object> keys = source.keys();
+ while ( keys.hasMoreElements() ) {
+ final Object key = keys.nextElement();
+ dest.put(key, source.get(key));
+ }
+ }
+
+ private void readSlingProperties(final File propsFile, final int mode) throws MojoExecutionException {
if (propsFile.exists()) {
File tmp = null;
try {
@@ -466,13 +486,23 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
mavenFileFilter.copyFile(propsFile, tmp, true, project, null, true,
System.getProperty("file.encoding"), mavenSession);
final Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null);
- if ( this.slingProperties == null ) {
- this.slingProperties = loadedProps;
+ if ( mode == 0 ) {
+ if ( this.slingProperties == null ) {
+ this.slingProperties = loadedProps;
+ } else {
+ this.copyProperties(loadedProps, this.slingProperties);
+ }
+ } else if ( mode == 1 ) {
+ if ( this.slingWebappProperties == null ) {
+ this.slingWebappProperties = loadedProps;
+ } else {
+ this.copyProperties(loadedProps, this.slingWebappProperties);
+ }
} else {
- final Enumeration<Object> keys = loadedProps.keys();
- while ( keys.hasMoreElements() ) {
- final Object key = keys.nextElement();
- this.slingProperties.put(key, loadedProps.get(key));
+ if ( this.slingStandaloneProperties == null ) {
+ this.slingStandaloneProperties = loadedProps;
+ } else {
+ this.copyProperties(loadedProps, this.slingStandaloneProperties);
}
}
} catch (IOException e) {
@@ -487,8 +517,18 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
}
}
- protected Properties getSlingProperties() throws MojoExecutionException {
- readSlingProperties(this.commonSlingProps);
+ protected Properties getSlingProperties(final boolean standalone) throws MojoExecutionException {
+ readSlingProperties(this.commonSlingProps, 0);
+ final Properties additionalProps = (standalone ? this.slingStandaloneProperties : this.slingWebappProperties);
+ if ( this.slingProperties == null) {
+ return additionalProps;
+ }
+ if ( additionalProps != null ) {
+ final Properties combinedProps = new Properties();
+ this.copyProperties(this.slingProperties, combinedProps);
+ this.copyProperties(additionalProps, combinedProps);
+ return combinedProps;
+ }
return this.slingProperties;
}
@@ -497,7 +537,7 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
* The filter is copied to a tmp location to apply filtering.
* @throws MojoExecutionException
*/
- private void readSlingBootstrap(final File bootstrapFile) throws MojoExecutionException {
+ private void readSlingBootstrap(final File bootstrapFile, final int mode) throws MojoExecutionException {
if (bootstrapFile.exists()) {
File tmp = null;
Reader reader = null;
@@ -507,19 +547,34 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
System.getProperty("file.encoding"), mavenSession);
reader = new FileReader(tmp);
final StringBuilder sb = new StringBuilder();
- if ( this.slingBootstrapCommand != null ) {
- sb.append(this.slingBootstrapCommand);
+ if ( mode == 0 ) {
+ if ( this.slingBootstrapCommand != null ) {
+ sb.append(this.slingBootstrapCommand);
+ }
+ } else if ( mode == 1 ) {
+ if ( this.slingWebappBootstrapCommand != null ) {
+ sb.append(this.slingWebappBootstrapCommand);
+ }
+ } else {
+ if ( this.slingStandaloneBootstrapCommand != null ) {
+ sb.append(this.slingStandaloneBootstrapCommand);
+ }
}
final char[] buffer = new char[2048];
int l;
while ( (l = reader.read(buffer, 0, buffer.length) ) != -1 ) {
sb.append(buffer, 0, l);
}
-
- this.slingBootstrapCommand = sb.toString();
- } catch (IOException e) {
+ if ( mode == 0 ) {
+ this.slingBootstrapCommand = sb.toString();
+ } else if ( mode == 1 ) {
+ this.slingWebappBootstrapCommand = sb.toString();
+ } else {
+ this.slingStandaloneBootstrapCommand = sb.toString();
+ }
+ } catch (final IOException e) {
throw new MojoExecutionException("Unable to create filtered bootstrap file", e);
- } catch (MavenFilteringException e) {
+ } catch (final MavenFilteringException e) {
throw new MojoExecutionException("Unable to create filtered bootstrap file", e);
} finally {
if (tmp != null) {
@@ -540,9 +595,17 @@ public abstract class AbstractUsingBundleListMojo extends AbstractBundleListMojo
* @return The contents are <code>null</code>
* @throws MojoExecutionException
*/
- protected String getSlingBootstrap() throws MojoExecutionException {
- this.readSlingBootstrap(this.commonSlingBootstrap);
-
+ protected String getSlingBootstrap(final boolean standalone) throws MojoExecutionException {
+ this.readSlingBootstrap(this.commonSlingBootstrap, 0);
+ final String addCmds = (standalone ? this.slingStandaloneBootstrapCommand : this.slingWebappBootstrapCommand);
+ if ( this.slingBootstrapCommand == null ) {
+ return addCmds;
+ }
+ if ( addCmds != null ) {
+ final StringBuilder builder = new StringBuilder(this.slingBootstrapCommand);
+ builder.append(addCmds);
+ return builder.toString();
+ }
return this.slingBootstrapCommand;
}
}
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
index e602d1c..40f5732 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/AttachPartialBundleListMojo.java
@@ -42,6 +42,14 @@ public class AttachPartialBundleListMojo extends AbstractBundleListMojo {
public static final String SLING_COMMON_BOOTSTRAP = "common.bootstrap.txt";
+ public static final String SLING_WEBAPP_PROPS = "webapp.properties";
+
+ public static final String SLING_WEBAPP_BOOTSTRAP = "webapp.bootstrap.txt";
+
+ public static final String SLING_STANDALONE_PROPS = "standalone.properties";
+
+ public static final String SLING_STANDALONE_BOOTSTRAP = "standalone.bootstrap.txt";
+
/**
* @parameter default-value="${project.build.directory}/bundleListconfig"
*/
@@ -75,6 +83,7 @@ public class AttachPartialBundleListMojo extends AbstractBundleListMojo {
private boolean checkFile(final File f) {
return f != null && f.exists();
}
+
private void attachConfigurations() throws MojoExecutionException, IOException, ArchiverException {
if ( this.ignoreBundleListConfig ) {
this.getLog().debug("ignoreBundleListConfig is set to true, therefore not attaching configurations.");
@@ -84,6 +93,10 @@ public class AttachPartialBundleListMojo extends AbstractBundleListMojo {
boolean hasConfigs = this.checkFile(this.getConfigDirectory());
hasConfigs |= this.checkFile(this.commonSlingBootstrap);
hasConfigs |= this.checkFile(this.commonSlingProps);
+ hasConfigs |= this.checkFile(this.webappSlingBootstrap);
+ hasConfigs |= this.checkFile(this.webappSlingProps);
+ hasConfigs |= this.checkFile(this.standaloneSlingBootstrap);
+ hasConfigs |= this.checkFile(this.standaloneSlingProps);
if ( !hasConfigs ) {
this.getLog().debug("No configurations to attach.");
@@ -101,6 +114,26 @@ public class AttachPartialBundleListMojo extends AbstractBundleListMojo {
slingDir.mkdirs();
FileUtils.copyFile(this.commonSlingProps, new File(slingDir, SLING_COMMON_PROPS));
}
+ if ( this.checkFile(this.webappSlingBootstrap) ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.copyFile(this.webappSlingBootstrap, new File(slingDir, SLING_WEBAPP_BOOTSTRAP));
+ }
+ if ( this.checkFile(this.webappSlingProps) ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.copyFile(this.webappSlingProps, new File(slingDir, SLING_WEBAPP_PROPS));
+ }
+ if ( this.checkFile(this.standaloneSlingBootstrap) ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.copyFile(this.standaloneSlingBootstrap, new File(slingDir, SLING_STANDALONE_BOOTSTRAP));
+ }
+ if ( this.checkFile(this.standaloneSlingProps) ) {
+ final File slingDir = new File(this.configOutputDir, "sling");
+ slingDir.mkdirs();
+ FileUtils.copyFile(this.standaloneSlingProps, new File(slingDir, SLING_STANDALONE_PROPS));
+ }
if ( this.checkFile(this.getConfigDirectory()) ) {
final File configDir = new File(this.configOutputDir, "config");
configDir.mkdirs();
diff --git a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
index 7506118..abc2f03 100644
--- a/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
+++ b/src/main/java/org/apache/sling/maven/projectsupport/PreparePackageMojo.java
@@ -222,8 +222,8 @@ public class PreparePackageMojo extends AbstractLaunchpadFrameworkMojo {
+ "." + artifact.getArtifactHandler().getExtension());
// check if custom sling.properties file or bootstrap command exists
- final Properties additionalProps = this.getSlingProperties();
- final String bootstrapCmd = this.getSlingBootstrap();
+ final Properties additionalProps = this.getSlingProperties(JAR.equals(this.packaging));
+ final String bootstrapCmd = this.getSlingBootstrap(JAR.equals(this.packaging));
if ( additionalProps != null || bootstrapCmd != null ) {
// unpack to a temp destination
final File dest = new File(this.tempDirectory, "basejar");
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.