Wednesday, October 22, 2014

How to use snapshot checkstyle version in maven plugin

Base on knowledge from http://maven.apache.org/plugins/maven-checkstyle-plugin/examples/custom-developed-checkstyle.html#Configure_the_Checkstyle_Plugin_to_use_your_custom_checks

you can easily force to maven checkstyle plugin to use custom/snapshot version of Checkstyle library.
It is very useful for testing of new Checks and generating HTML report on big sources.

<project>
...
  </build>
    </pluginManagement>
      </plugins>
....
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-checkstyle-plugin</artifactId>
     <version>2.13</version>
     <dependencies>
       <dependency>
   <groupId>com.puppycrawl.tools</groupId>
         <artifactId>checkstyle</artifactId>
          <version>6.0-SNAPSHOT</version>
       </dependency>
     </dependencies>
   </plugin>        
.....
      </plugins>
    </pluginManagement>
  </build>
......
  <reporting>
    <plugins>
     <!-- that plugin is required to link violation with source code-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <version>2.3</version>

      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.13</version>
        <configuration>
          <configLocation>checkstyle.xml</configLocation>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
....
</project>

Build HTML report by "mvn site" command.

to have different HTML reports (for each tested Check) over the same sources - just save index.html as index-MyCheck.html, and do report generation for each Check separately.

Tuesday, October 14, 2014

Sevntu Checkstyle release 1.12.0

new release of Checkstyle extension (Sevntu.Checkstyle) 1.12.0, with new checks:
DiamondOperatorForVariableDefinitionCheck,
PublicReferenceToPrivateTypeCheck,
TernaryPerExpressionCountCheck

Updates in:
RedundantReturnCheck
CustomDeclarationOrderCheck
LineLengthCheck
ForbidThrowAnonymousExceptionsCheck,

Details:
http://daniilyar.blogspot.com/2014/10/sevntu-checkstyle-release-112-checks.html

Wednesday, October 1, 2014

How to copy static site to SourceForge hosting

Sources of wisdom:
http://sourceforge.net/p/forge/documentation/Shell%20Service/
http://sourceforge.net/p/forge/documentation/File%20Management/#access-paths


~ $ ssh romanivanov,checkstyle@web.sourceforge.net

Welcome!

        This is a restricted Shell Account.
                                           You can only copy files to/from here.

                                                                                PTY allocation request failed
Shared connection to web.sourceforge.net closed.

~/ $ ssh -t romanivanov,checkstyle@shell.sourceforge.net create
Password:

Requesting a new shell for "romanivanov" and waiting for it to start.
creating... starting...

This is an interactive shell created for user romanivanov,checkstyle.
Use the "timeleft" command to see how much time remains before shutdown.
Use the "shutdown" command to destroy the shell before the time limit.
For path information and login help, type "sf-help".

[romanivanov@shell-22008 ~]$ uname -a
Linux shell-22008 2.6.18-308.8.2.el5.028stab101.1 #1 SMP Sun Jun 24 20:25:35 MSD 2012 x86_64 x86_64 x86_64 GNU/Linux
[romanivanov@shell-22008 ~]$ ls -la
total 32
drwx------ 3 romanivanov users 4096 Feb  1  2011 .
drwxr-xr-x 3 root        root  4096 Sep  9 04:27 ..
-rw-r--r-- 1 romanivanov users   33 Jan 22  2009 .bash_logout
-rw-r--r-- 1 romanivanov users  176 Jan 22  2009 .bash_profile
-rw-r--r-- 1 romanivanov users  124 Jan 22  2009 .bashrc
-rw-r--r-- 1 romanivanov users  515 Jun 15  2008 .emacs
drwxr-xr-x 4 romanivanov users 4096 Dec  9  2010 .mozilla
-rw-r--r-- 1 romanivanov users  633 Jun 13  2009 .zshrc
lrwxrwxrwx 1 root        root    30 Apr 26  2012 userweb -> /home/userweb/r/ro/romanivanov

[romanivanov@shell-22008 ~]$ cd /home/project-web/checkstyle/htdocs/

========================

copy big files from local PC:

~/ $ scp report-openjdk8.tar.gz  romanivanov,checkstyle@web.sourceforge.net:

Friday, August 29, 2014

Examine Apache configuration locations on server

-root@centos-server ~]# which httpd
/usr/sbin/httpd


[root@centos-server ~]# /usr/sbin/httpd -V | egrep ROOT\|SERVER_CONFIG
-D HTTPD_ROOT="/etc/httpd"
-D SERVER_CONFIG_FILE="conf/httpd.conf"


[root@centos-server ~]# grep  "^[iI]nclude" /etc/httpd/conf/httpd.conf
Include conf.d/*.conf

[root@centos-server ~]# ls -la /etc/httpd/conf.d/
total 16
drwxr-xr-x. 2 root root 4096 Aug 14 21:06 .
drwxr-xr-x. 4 root root 4096 Aug 14 21:06 ..
-rw-r--r--. 1 root root  392 Jul 23 14:18 README
-rw-r--r--. 1 root root  299 Jul 18 06:27 welcome.conf
...... here will be your other confs that are included

[root@centos-server ~]#  less /etc/httpd/conf.d/welcome.conf 
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /error/noindex.html
</LocationMatch>


Wednesday, July 2, 2014

false negatives and false positives


Result of validation could be false negatives (no issue reported) or false positives (incorrect issues reported).

Friday, June 27, 2014

Google Java Style - mandatory braces rules

During development of Checkstyle configuration for Google Java Style,  we found two rules that are looks like conflicting . 

In 4.1.1 Google say:
Braces are used with if, else, for, do and while statements, even when the body is empty or contains only a single statement.

in 4.1.3 Google say:
An empty block or block-like construct may be closed immediately after it is opened, with no characters or line break in between ({}), unless it is part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else or try/catch/finally).

So in 4.1.1 IF-ELSE could be {}, but in 4.1.3 there is unclear "unless" that either conflict with 4.1.1 or mean smth else that it not described.

After long discussion with friends and investigation :

Rule 4.1.1 tell us to always use braces for statements that use blocks

// BAD
if () {
  ...
} else
  i++;

It must be
// GOOD
if () {
  ...
} else {
  i++;
}

// it is OK, old fashioned but ok
int index = 0;
for (; index < s.length() && s[index] != 'x'; index++) {}

// OK, side effect in condition expression is bad design , but it is not matter of style/formatting 
while ((r = in.read()) != 0) {}

So ELSE is just another structure that could have braces so it have to have braces no matter what.


Rule 4.1.3 extend 4.1.1 and demand that braces should not be empty in multi-block statements, small wording conflict in ELSE case is not intentional and if apply rules in sequence 4.1.1 and then 4.1.3 all will be fine:

// BAD
try {
  doX();
} catch (Exception e) {}

// BETTER
try {
  doX();
} catch (Exception e) {
  // Here's why I'm swallowing this exception
}

// BAD
if (expr) {} else {
  doSomething();
}

// BETTER
if (expr) {
  // Here's why I'm not doing anything here....
} else {
  doSomething();
}