Sunday, August 5, 2012

Bundled PrimeFaces Themes

I have created a sub-project in PrimeFaces Extensions for everybody who would not like to confront with adding multiply theme JAR files and only needs one bundled JAR with all PrimeFaces themes. One JAR file would also reduce the scanning time during startup (JSF, CDI, ... look for marker XML files) in comparison to 35+ separate files.

Last release of the bundled themes can be found in the Maven Central repository. The release version is synchronized with the current release of PrimeFaces themes. Add this dependency to your pom.xml and you are done.
<dependencies>
    ...    
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>all-themes</artifactId>
        <version>1.0.6</version>
    </dependency>
    ...
</dependencies>
Non Maven users can download the JAR file direct from the Maven Central repository.

You can consider this as an "all-in-one" themes add-on. We don't modify themes, we only collect them by means of the Maven Assembly Plugin. A simple Maven project aggregates PrimeFaces themes and builds a single JAR file with all available themes. Here is a hint how it works. The Maven project with packaging pom is configured as follows:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
            <executions>
                <execution>
                    <id>package-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/all-themes.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.primefaces.themes</groupId>
        <artifactId>afterdark</artifactId>
        <version>${primefaces.theme.version}</version>
        <scope>runtime</scope>        
    </dependency>
    ...
    <dependency>
        <groupId>org.primefaces.themes</groupId>
        <artifactId>vader</artifactId>
        <version>${primefaces.theme.version}</version>
        <scope>runtime</scope>        
    </dependency>
</dependencies>

<properties>
    <primefaces.theme.version>1.0.6</primefaces.theme.version>    
</properties>
The Maven Assembly Plugin takes all dependencies and re-packs them as a single JAR. Repacking instructions are defined in the assembly descriptor all-themes.xml.
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="...">
    <id>all-themes</id>
    <formats>
        <format>jar</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <dependencySets>
        <dependencySet>
            <unpack>true</unpack>
            <useProjectArtifact>false</useProjectArtifact>
            <useTransitiveDependencies>false</useTransitiveDependencies>
        </dependencySet>
    </dependencySets>
</assembly>
That's all.