Maven plugin to test i18n properties - maven

does anybody know a maven plugin that tests all my language properties files? I want to test that every language in my project contains all keys.
Use cases:
Figure out if so. added a key to the default file and forgot to add to any of the other language files.
Figure out if so. dropped a key in one of the files and forgot to drop it in all the other files.
It is not that difficult to write my own small maven plugin, but I would prefer an already existing one. Haven't found one so far.
Or: How do you test your files? Manually / automated / not at all?
Eric

You should give a try to the i18n-maven-plugin. In the build (process-resources phase), all your Java classes, JSP will be parsed to find all the i18n keys in your project (according to your pom).
The plugin will add all the i18n keys that are missing in all you bundles. There is also a strict mode that remove all the i18n keys that are no longer found in your application from your bundles so you can be sure that 100% of the keys are both used in your app and translated in every language.
For a working, real-life example, feel free to check out this application:
svn checkout https://svn.codelutin.com/wao/tags/wao-4.0.4/
mvn clean process-resources -Di18n.verbose

Funny - I gave my project the same name a couple of years ago. https://github.com/hoereth/i18n-maven-plugin
This plugin serves me well on numerous projects. It turns around the concept of properties files 180 degrees. You maintain a well structured XMl file with your translations and the plugin will create all properties files for you during build time. No need for validation at his point. It can also create a Java class which holds all translation keys - thus enabling you to compile-check your translation calls.
Believe me - this takes away the pain of translating from a technical point of view. :)

Related

How to setup Maven to enable JSF2 resources versioning?

I have read the following essay:
Resources (library) in JSF 2.0
It's about versioning of web resources for JSF2 project.
May I know how could I do when my project is Maven-based? What need to be setup or added in the Maven setting?
Thanks a lot.
Effectively your question is a combination of three existing questions in Stackoverflow.
One is already superfluous since you already know how JSF versioning works, you just (unfortunately) referred an external site and not the existing question but from this question you need to 'remember' the format of the version number that needs to be used.
The second part should also not have been to difficult to come up with. JSF is a runtime framework and has no build/deploy time features. But you already use maven, so what is needed to build time copy(move?) the resources to a new location. The source folder can differ, it can be an additional resources folder e.g. src/main/myresources, that you don't treat as a resources (since it would end up in the classes folder then by default) or it can be a folder inside the webcontent and then you need to move (copy/delete). This is all for you to find out.
The third part is that the destination folder needs the version in the right format
1_0
1_1
1_2_3
Since this differs from the project version format, you need to search/replace this
which includes the project version in the right format. There are features for this as well in maven.
So you see, it all boils down to breaking a problem down into manageable parts...

Maven Archetype creation via Eclipse

I am willing to create an archetype which will be useful to create a lot of projects sharing the same architecture. I followed the maven guide and read some bloggers guides but even with these informations I am struggling.
I have some constraints for my projects :
All the project code is in a package which must be something like com.ei.app.project (app and project are vars I would like to set during the project generation)
I have dependencies I would like to be present in my POM when the project is generated
I have some scripts file with data (paths, app name...) and I would like to set them according to the project parameters, and if it is possible add additional parameters.
We don't use the official maven repo but set up another online repo. We have a strict security policy an whenever we have to add a lib into the repo it takes a lot of time for verifications.
How can I achieve this ? I tried several solutions but encountered a lot of errors. If you have a complete step-by-step guide in english or french that would be fantastic, but I would also like to understand how it works.
Many thanks for your help
Let me answer parts of your question.
From an example project, you can create an archetype by using archetype:create-from-project (https://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html).
You can supply a property file that will be used to replace actual values (like 1.0.0-SNAPSHOT) with references (like $version). All filtered files will be treated as velocity templates so that you can use $-type replacement.
Your repository restriction may be problem because you probably need dozens of artifacts to make the archetype plugin run.
I finally created a "base" project with all I need inside (libraries, main Vert.x class...), and developed a script to replace a template value (i.e __projectName__ ) in dir / file names and inside configuration / pom.
It's close enough to what we need and provide a cool replacement tool for my company, which will be used for multiple purposes.

How to easily copy/rename/remove files with Maven (as in Ant)

I am working on a project and using Maven to build it. The project is a quite big Java web application and it is supposed to work with both Mysql and Oracle databases.
The problem is that there are some specific annotations related to either of the two databases in the source code, plus some other differences, so that I am forced to manually comment/uncomment part of the code before building the application for one of the two databases.
Basically what I would like to achieve is to have my build script, maybe via a Maven profile, to automatically switch the source classes before building depending on the database I want my war to work against.
Putting it simply, the idea is to have MyClass.oracle and MyClass.mysql, and depending on my build profile I should move one of the two in the source dir, rename it MyClass and build. This should be done for some packages, classes, and also configuration files.
Is there any way I can achieve it via "pure" Maven? The only solution I came across till now is to use an antrun plugin and reference an Ant build.xml inside of it.
Thank you,
Mattia
A pure maven solution would be to develop your own maven plugin. Depending on your requirements this can be an overkill, however it is not hard at all, you can see how to achieve this here.
This is a limitation of Maven. One of Maven's purposes is to not have a build script. You should simply use the plugins as available, and setup your project the right way, and magically, everything will build!
There is one solution: Use Ant. Well, not to redo your whole project with Ant, but with the antrun plugin, you can run a few Ant tasks at various phases of your Maven build life cycle.
It's been a long, long time since I've used this, so I am not going to try to write a test pom.xml, but I don't remember it being very difficult to use.
Of course, the correct Maven solution is to divide your project up into "common core" code, and then a separate Oracle and MySql client that uses the "common core". By the way, I hope you're not patching source code. Instead, you're using a properties file to do this for you.

Exclude Reading/Replacing specific files in Maven Build

We are using maven for building the project. It's legacy and huge one.
We newly added few .keystore files to it's resources folder.
The problem is, once the build is done, the .keystore files are getting tampered [may be maven is trying to replace/search for some placeholders]. Since it's legacy one, the project structure is so much messed up and we don't have separate distributions or no other choice but to go with plain build.
What I want is, tell maven to copy these sort of files without touching them and keeping the build as usual like before.
Between, there's no explicit is mentioned in pom.xml, tried to doing with that as per this http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html but it's messing up the project build.
I don't want to tamper the build, since it's legacy and huge one. We are using Ant plugin
Just switch off filtering for the respective <resource/> or add an <exclude/> for it.
After going through lot of sources, Found the solution http://maven.apache.org/plugins/maven-resources-plugin/examples/binaries-filtering.html
Thanks :)

Maven copy resources in multi module project

My need is pretty basic but I could not find any clean answer to it: I simply need to be able to distribute a resource in a multi-module project.
Let us consider for example the LICENSE file, which I hereby assume to be the same for all modules. I prefer not to manually copy it into each and every module because the file could change over time. I also prefer not to statically link to resources (even if using relative paths) outside the project folder, because the modular structure can possibly change too.
Is there any plugin that can be used to robustly guarantee that each module is given the required file? It would be equally acceptable for such copy to be obtained by exploiting the POM of the parent project or directly performed by the super project in the modular hierarchy.
you could use the assembly and the dependency plugins.. did you stumble over that link?
http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/
it describes that option ..its from 2008, but maven is around for quite some time.. so I guess its more or less up to date
edit regarding comment
Another option is the maven-remote-resources-plugin.
For a more detailed example see:
http://maven.apache.org/plugins/maven-remote-resources-plugin/examples/sharing-resources.html
Since their intro speaks actually for itself, I quote (maven.apache.org)
This plugin is used to retrieve JARs of resources from remote repositories, process those resources, and incorporate them into JARs you build with Maven. A very common use-case is the need to package certain resources in a consistent way across your organization: at Apache it is required that every JAR produced contains a copy of the Apache license and a notice file that references all used software in a given project.

Resources