Apache VFS Files Cache implemented using Guava CacheBuilder

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
 
import java.util.concurrent.TimeUnit;
 
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.cache.AbstractFilesCache;
 
class GuavaFilesCache extends AbstractFilesCache
{
   static class CacheOfFilesystem
   {
      private final Cache<FileName, FileObject> files = CacheBuilder.newBuilder()
               .concurrencyLevel(4)
               .maximumSize(10000)
               .expireAfterWrite(10, TimeUnit.MINUTES)
               .build();
 
      public FileObject getFile(final FileName name)
      {
         return files.getIfPresent(name);
      }
 
      public void putFile(final FileObject file)
      {
         files.put(file.getName(), file);
      }
 
      public boolean putFileIfAbsent(final FileObject file)
      {
         return files.asMap().putIfAbsent(file.getName(), file) == null;
      }
 
      public void removeFile(final FileName name)
      {
         files.invalidate(name);
      }
   }
 
   private final LoadingCache<FileSystem, CacheOfFilesystem> filesystems = CacheBuilder.newBuilder()
         .concurrencyLevel(4)
         .maximumSize(10000)
         .expireAfterWrite(10, TimeUnit.MINUTES)
         .build(new CacheLoader<FileSystem, CacheOfFilesystem>(){
            @Override
            public CacheOfFilesystem load(@SuppressWarnings("unused") final FileSystem key) throws Exception
            {
               return new CacheOfFilesystem();
            }});
 
   @Override
   public void putFile(final FileObject file)
   {
      filesystems.getUnchecked(file.getFileSystem()).putFile(file);
   }
 
   @Override
   public boolean putFileIfAbsent(final FileObject file)
   {
      return filesystems.getUnchecked(file.getFileSystem()).putFileIfAbsent(file);
   }
 
   @Override
   public FileObject getFile(final FileSystem filesystem, final FileName name)
   {
      return filesystems.getUnchecked(filesystem).getFile(name);
   }
 
   @Override
   public void clear(final FileSystem filesystem)
   {
      filesystems.invalidate(filesystem);
   }
 
   @Override
   public void removeFile(final FileSystem filesystem, final FileName name)
   {
      filesystems.getUnchecked(filesystem).removeFile(name);
   }
}

Creating a Glassfish domain and run it as a Windows service

So, my on-going saga of ways to run glassfish as a service progresses to glassfish 3.1.1.

Here are the ant snippets I am using to create the glassfish domain and set it up to run as a windows service:

<exec executable="${glassfish.home}/bin/asadmin.bat" 
      failonerror="true" 
      output="${glassfish.home}/glassfish-create-domain.log"
      inputstring="AS_ADMIN_PASSWORD=${glassfish.admin.password}">   
   <arg value="--user"/>
   <arg value="${glassfish.admin.username}"/>
   <arg value="--passwordfile"/>
   <arg value="-"/>
   <arg value="create-domain"/>
   <arg value="--savelogin"/>
   <arg value="--checkports=false"/>
   <arg value="--adminport"/>
   <arg value="${glassfish.admin.port}"/>
   <arg value="--instanceport"/>
   <arg value="${glassfish.http.port}"/>
   <arg value="--domainproperties=jms.port=7676:domain.jmxPort=8686:orb.listener.port=3700:http.ssl.port=8181:orb.ssl.port=3820:orb.mutualauth.port=3920"/>
   <arg value="myDomain"/>
</exec>
<exec executable="${glassfish.home}/bin/asadmin.bat" 
      failonerror="true"
      output="${glassfish.home}/glassfish-create-service.log">
   <arg value="create-service"/>
   <arg value="--name"/>
   <arg value="MyServiceName"/>
   <arg value="myDomain"/>
</exec>

Github Maven Plugins

Anyone hosting projects built with maven on Github will probably be interested in the Github Maven plugins

At the moment there are two plugins, one for uploading artifacts to the download section of your Github project, and another for uploading your maven site to the gh-pages branch of your repository.

You need to put something like this, or a bit cleverer, in your maven settings.xml:

<profiles>
    <profile>
      <id>github-properties</id>
      <properties>
        <github.global.userName>myusername</github.global.userName>
        <github.global.password>mypassword</github.global.password>
      </properties>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>github-properties</activeProfile>
  </activeProfiles>

site plugin

Then configure the plugins in your project. For the site plugin you need something like this, which will upload to github each tiem you run the site goal in maven.

<build>
   <plugins>
      <plugin>
         <groupId>com.github.github</groupId>
         <artifactId>site-maven-plugin</artifactId>
         <version>0.5</version>
         <executions>
            <execution>
               <goals>
                  <goal>site</goal>
               </goals>
               <phase>site</phase>
               <configuration>
                  <message>Creating site for ${project.version}</message>
               </configuration>
            </execution>
         </executions>
      </plugin>

multi-module projects

I’m not clear on how the multi-module support is supposed to work. The way I have got it to work is by using `path` and `merge` in the modules:

<configuration>
    <path>modulename</path>
    <merge>true</merge>
    ...
</configuration>

my theory is that if you build `site` in your parent project, then it will be uploaded first, clearing the whole site. Then each of the sub modules will be built merging each site into the parent site in the correct subdirectory. This seems to work, but the top level project run with `merge=false` wipes out you site for a while until the child modules complete. So if your project takes a while to build (or fails!) visitors might get disappointed. The only alternative to this seems to be to have `merge=true` on all the projects, but that will leave anything that doesn’t get overwritten unaffected. YMMV.

download plugin

You can have each of your releases uploaded to github for other people to download. I use a profile to only sign and upload my release builds and not every snapshot.

<profile>
    <id>release-sign-artifacts</id>
    <activation>
        <property>
            <name>performRelease</name>
            <value>true</value>
        </property>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
               <groupId>com.github.github</groupId>
               <artifactId>downloads-maven-plugin</artifactId>
               <version>0.4</version>
               <executions>
                  <execution>
                     <goals>
                        <goal>upload</goal>
                     </goals>
                     <phase>install</phase>
                     <configuration>
                        <description>${project.version} release of ${project.name}</       description>
                        <override>true</override>
                        <includeAttached>true</includeAttached>
                     </configuration>
                  </execution>
               </executions>
           </plugin>
        </plugins>
    </build>
</profile>

The more I use maven and github for Open Source development the better it gets, and this github integration is super-smooth. I have pretty much single click global publishing of my whole project source, documentation and artifacts. Combined with the super easy and free nexus and maven central access provided by sonatype OSS and the jenkins CI server instance provied by cloudbees this is as close to as good a dev environment as you can get – and all for no money. Oh yeah, and I forgot about the eclipse maven integration. We’ve come along way.