Hey Billerby,
nice question as well but more Maven than Alfresco related, and
touches a point where I'm very focused on.
See my answers interleaved:
> Hi Gabriele!
>
> Thank you very much for your very educative answers, they will help a
> lot. I have one other question (this one is not about "the bigger
> picture" though).
>
> I have now set up one extension project which I intend just to use
> just as it is without modifications. This extension project will have
> dependencies to the amps we will develop. When invoking jetty with mvn
> install -Prun, everything works well. However reading through the log-
> file raises one question:
>
> Shall I create the alfresco-global.properties to hold the paths to
> ImgMagick, pdf2swf and soffice? Could this file be created on the fly
> reading properties from settings.xml (Since every developer probably
> got different paths)? Maybe every developer just should create it and
> add it to the svn:ignore?
In my view, in any build process there are offer two sets of properties:
__ Build Time properties (build system dependent)
Environment dependent (e.g. developer dependent or depending on the
environment in general where the application is running). Typically
those properties are filtered in your project resources by the build
system.
Maven provides the <filters> tag in the POM to accomplish that
filtering all specified resources with the specified properties file
and with all POM properties (meaning POM + settings + any command line
property.
Specifically those properties which are developer dependent should be
*not* stored under the project root, but in external profiles
(possibly always active) stored in the per user (~/.m2/settings.xml)
or per system ($M2_HOME/conf/settings.xml) settings file so not to
taint the "independency" of the build. See [7].
Ant used to do so with the build.properties and project.properties file.
__RunTime or functional properties (webapp runtime dependent)
Properties which affect the functional behavior of the application and
are loaded (and possibly modified) by the application runtime but they
don't depend on the environment. These are heavily dependent on the
specific application runtime and often aggregated in a simple
java.lang.Properties file.
In standard Alfresco < 3.2 this used to be done by having a number of
*.properties files loaded by different Spring contexts, in Alfresco
3.2+ there's an alfresco-global.properties which gets loaded by
default providing the same functionalitiy.
In this sense in the Maven Alfresco Lifecycle, before Alfresco
introduced alfresco-global.properties, I added the concept of
application.properties (src/main/properties/<env>/
application.properties), a single runtime application properties file
gathering all properties that can be switched (per environment) by
just a -Denv=<yourEnv> property ( see[1] ).
ATM the latest 1.1.0 version of Maven Alfresco Lifecycle still has the
dicotomy application.prroperties / alfresco-global.properties (you can
decide to put your properties in either of the files) which needs very
few effort to be fixed (see [2])
Now customizing Alfresco, this distinction is not so strong (or better
there are no build time properties as all configuration can be loaded
at runtime). If you think at alf_data and the DB DSN you see how they
are both runtime properties but heavily environment dependent.
So to have a single configuration point there's an additional
(questionable as adds black magic) improvement I did: I configured
the default application.properties file to filter in (at build time)
some POM properties (see src/main/local/application.properties) so
that all more common properties (e.g alf_data and db name) could even
more simply be configured directly via POM properties (or settings as
described above).
Based on this considerations, there are a few options to achieve the
original goal of the post (how to manage environment dependent
properties):
1__
All developers keep on using the default env=local
application.properties file (which has $ placeholders in it) and
environment dependent properties are configured in an activeByDefault
profile [6] which filters in the environment dependent properties,.
E.g. each developer's ~/.m2/settings.xml (or $PROJECT_HOME/
profiles.xml with svn:ignore)
should contain something like:
<profiles>
...
<profile>
<id>alfresco-conf</id>
<properties>
<alfresco.data.location>./alf_data_jetty</alfresco.data.location>
<
alfresco.db.name>alf_jetty</
alfresco.db.name>
<alfresco.db.username>alfresco</alfresco.db.username>
<alfresco.db.password>alfresco</alfresco.db.password>
<alfresco.version>3.2r</alfresco.version>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
2__
Each developer uses his own application properties file (one folder
per developer under src/main/properties). These folders are added to
svn:ignore. In this case all properties gets directly configured in
the application.properties file (without any need for build time ->
runtime piping).
Drawback is that each developer will have then to run his build with a
specific command line (not really Maven friendly):
mvn install -Denv=<developerId>
3__
As a more definitive improvement to the approach, we tried to find a
neater way (than having $ placeholders in the properties files, which
is paranoid enough) to pipe build time -> run time properties: If you
look at Maven Calm [3], which is used by the 3.x branches [5] of our
archetype, it uses the maven-properties-plugin [4] to "write"
build time (POM) properties into a property file during the first
phases of the build, so that the very same property file can be used
(or better merged) with the application.properties/alfresco-
global.properties and later loaded at runtime. @Maoo: anything to add
here ? :)
I hope I could make something clear about this not so simple topic,
and I'd be really glad to have some feedback on which solution you
like best based on your specific requirement/use case.
Provided we stick as much as possible to Alfresco's approach, offering
super duper easy configurability is the 1st priority and added value
for a maven archetype IMHO.
WDYT?
HTH,
ciao!
Gab
[1]
http://maven.alfresco.com/nexus/content/repositories/alfresco-docs/maven-alfresco-lifecycle/maven-alfresco-archetypes/maven-alfresco-extension-archetype/profiles.html
[2]
http://code.google.com/p/maven-alfresco-archetypes/issues/detail?id=37
[3]
http://code.google.com/p/maven-calm
[4]
http://haroon.sis.utoronto.ca/zarar/properties-maven-plugin/
[5]
http://maven-alfresco-archetypes.googlecode.com/svn/branches/
[6]
http://maven.apache.org/settings.html#Profiles
[7]
http://maven.apache.org/guides/introduction/introduction-to-profiles.html