Search This Blog

Wednesday, May 23, 2012

mac: no acceptable C compiler found in $PATH

If you get the following error on mac:
configure: error: no acceptable C compiler found in $PATH
Here is the step to fix it:

1. download Xcode from https://developer.apple.com/downloads/index.action
2. install Xcode
3. Open Xcode, go to Preferences --> Downloads --> install "Command Line Tools"
4. relaunch terminal

Saturday, May 19, 2012

Enable Spring Jdbc Transaction with Annotation

Spring 3.1 introduced a new annotation @EnableTransactionManagement.  With it, all xml configuration can be got rid of now.  Here is the example on how to use it:

@Configuration
@EnableTransactionManagement
public class JdbcConfig {

    @Bean
    public DataSource dataSource() {
    //config datasource      
    }

    @Bean
    public PlatformTransactionManager txManager() {
        return new DataSourceTransactionManager(dataSource());
    }

    @Bean
    public MyDao myDao() {
        MyDaoJdbc dao = new MyDaoJdbc();
        dao.setDataSource(dataSource());
        return dao;
    }
}
Next you need to annote your dao with @Transactional.  The source code can be found at github:

https://github.com/zhentao/spring-jdbc-transaction-example

cobertura-maven-plugin

Recently I created a parent pom for my team to use.  All my team's projects need to inherit this parent pom.  This parent pom is rather simple:

  <properties>
    <default.encoding>UTF-8</default.encoding>
    <default.jdk>1.6</default.jdk>
    <line.coverage.target>90</line.coverage.target>
    <branch.coverage.target>90</branch.coverage.target>
  </properties>

  <build>
    <defaultGoal>install</defaultGoal>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.2</version>
          <configuration>
            <source>${default.jdk}</source>
            <target>${default.jdk}</target>
            <encoding>${default.encoding}</encoding>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <version>2.1.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.5</version>
          <configuration>
            <encoding>${default.encoding}</encoding>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>2.8</version>
          <configuration>
            <encoding>${default.encoding}</encoding>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.2.2</version>
        </plugin>

        <!-- Sonar uses these versions, below -->
        <plugin>
          <artifactId>maven-pmd-plugin</artifactId>
          <version>2.7.1</version>
          <configuration>
            <targetJdk>${default.jdk}</targetJdk>
            <encoding>${default.encoding}</encoding>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <version>2.9.1</version>
          <configuration>
            <encoding>${default.encoding}</encoding>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>cobertura-maven-plugin</artifactId>
          <version>2.5.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.12</version>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <configuration>
          <check>
            <!-- Per-class thresholds -->
            <branchRate>${branch.coverage.target}</branchRate>
            <lineRate>${line.coverage.target}</lineRate>
            <!-- Project-wide thresholds -->
            <totalLineRate>${line.coverage.target}</totalLineRate>
            <totalBranchRate>${branch.coverage.target}</totalBranchRate>
          </check>
          <formats>
            <format>html</format>
          </formats>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>clean</goal>
              <goal>cobertura</goal>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
      </plugin>
      <plugin>
        <!-- Ensure that source code is packaged and deployed for inclusion into IDEs -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
We are targeting a pretty high unit test coverage, 90% for both line and branch coverage.  However, some classes don't need unit test or don't need high coverage.  Then each individual project can include the following to its project pom:
    <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <configuration>
          <instrumentation>
            <ignores>
              <ignore>org.slf4j.*</ignore>
            </ignores>
            <excludes>
              <exclude>com/zhentao/Some.class</exclude>
              <exclude>com/zhentao/other.class</exclude>
            </excludes>
          </instrumentation>
        </configuration>
      </plugin>
    </plugins>
  </build>
 <ignore>org.slf4j.*</ignore> ignores all log statement in the code since we don't need to test logs.
<exclude>com/zhentao/Some.class</exclude> excludes Some.class from the cobertura report.

However, this flexibility can be abused by some developers.  I got an build failed notification today:
11:52:52  Archiving artifacts
11:52:52  [htmlpublisher] Archiving HTML reports...
11:52:52  [htmlpublisher] Archiving at PROJECT level /target/site/cobertura to /htmlreports/Cobertura_Report
11:52:52  ERROR: Specified HTML directory '/target/site/cobertura' does not exist.
11:52:52  Build step 'Publish HTML reports' changed build result to FAILURE
 One developer excluded all classes from testing.  What a developer!

Friday, May 4, 2012

Yahoo hadoop tutorials

This is the link from yahoo for hadoop tutorials:

http://developer.yahoo.com/hadoop/tutorial/index.html

Monday, January 16, 2012

"someCommand > /dev/null 2>&1" means

someCommand > /dev/null 2>&1

When I saw it, I don't understand what it means since I am not good at shell script.  Today, I searched online and got the answer from the following link:

http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/

Below is my summary from the above blog:

Greater than (>) is for redirect, and the number 1 stands for STDOUT and 2 for STDERR, and 0 for STDIN.  By default, if no number provided, it is for STDOUT (number 1).  So the above script means STDOUT is redirected to /dev/null (called bit-bucket), and STDERR then is redirected to STDOUT which in turn is redirected to /dev/null.  It means both STDERR and STDOUT are redirected to /dev/null eventually.




Wednesday, December 7, 2011

Create a maven archetype from an existing project

In your project's root directory, run the following command:

mvn archetype:create-from-project

The generated archetype is in directory target/generated-sources/archetype

Move above folder to different folder, say: /path/to/myarchetypeOpen pom to change <name> tag, and groupId and artifactId. To add additional required field, open archetype-metadata.xml file (src/main/resources/META-INF/maven) and add one required property, using <requiredProperties> tag.

To install archetype into local catalog:
mvn clean install

To generate a new project from the installed archetype:

mvn archetype:generate -DarchetypeCatalog=local

Thursday, October 6, 2011

Show hidden characters in vi

In vi, type the following to show hidden characters:
:set list
Turn it off
:set nolist