Archive for March, 2012

Maven: Pom.xml and AspectJ

Monday, March 26th, 2012

In the Lib that has the aspect, add this to the pom.xml

<!-- AspecJ Compile -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <outxml>true</outxml>
    <showWeaveInfo>true</showWeaveInfo>
    <verbose>true</verbose>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>test-compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- /AspecJ Compile -->

.....


<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>1.6.7</version>
</dependency>

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.6.7</version>
</dependency>

Then, on the application that receive the aspect, need to have the failOnError:false to allow the mvn compiler to continue. Then, we weave the dependency “LibWithSomeAspects” in.

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <!-- Temporary fix for supporting aspectJ -->
    <failOnError>false</failOnError>
  </configuration>
</plugin>

<!-- AspecJ Compile -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <outxml>true</outxml>
    <showWeaveInfo>true</showWeaveInfo>
    <verbose>true</verbose>
    <weaveDependencies>
      <weaveDependency>
        <groupId>com.example</groupId>
        <artifactId>LibWithSomeAspects</artifactId>
      </weaveDependency>
    </weaveDependencies>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>test-compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- /AspecJ Compile -->

RegEx: Match filename with extension

Wednesday, March 7th, 2012

Checking if it is a image file

([^s]+(.(?i)(jpg|png|gif|bmp))$)

Very good explanation of this regex here