Monday 14 October 2013

JetBrains IntelliJ IDEA > Features > Code/Context Highlighting and Code Folding

No one have ever understood the problems and challenges faced by Developers, better than JetBrains. The day, I was introduced to this amazingly genius IDE, back in 2004, I fell for it. And, with every passing day, or should I say every passing release, JetBrains keep on raising the bar to a level where no one can possibly reach it.

So impressed with this IDE, I though about writing each of those intelligent features that saves me from a lot of stress and waste of time and efforts. But, honestly, every time I failed to figure out where to start and which ones to blog first. So, now, just 2 minutes ago, while I was coding Bootstrap prototype interface for one of the projects that I’m working on, I was amazed to see how intelligently it is aiding and assisting me to do my work efficiently with as least stress as possible.

The Bootstrap prototype file I’m working on is a Plain HTML file, and there are around ~300 lines of code. See the snapshot below, shows how efficiently IntelliJ IDEA has highlighted the area where I’m working at:

JetBrains IntelliJ IDEA IDE (Click to open enlarge image in a new window)

  1. Notice breadcrumbs at the top of editor window
  2. Notice a thin stripe at the left hand side buffer of editor window
  3. Notice the highlighted line of code within the editor where my caret is
  4. Notice the highlighted tags hierarchy within the editor
  5. And finally notice, how all of the above are synced with beautiful colors to track each item of current context individually

Wow!

Well, that’s not all. This file you are looking at is a ~300 line file, notice how I saved my self from additional stress of looking at un-related code, by (6) folding/collapsing literally any part of the code I wished to.

Genius! isn’t it?

And finally Winking smile, for those who are thinking that I’ve spent a fortune to have that jewel under my belt, have a look at this:

JetBrains IntelliJ IDEA Community Edition

Happy Coding Smile

Saturday 5 October 2013

Apache Maven Tips: Add/Append Copyright and License Header to your Project’s Source Code Artifacts using Maven License Plugin

apache-mavenEvery project requires proper copyrights and license information header to be added/appended at the top of each of the project’s source code artifacts. There is a very useful plugin for Apache Maven, called Maven License Plugin that helps you easily add/append such copyrights and license information.

First create a copyrights and license header file, for example:

${project}

Copyright (c) ${year}, ${founder}

This project includes software developed by ${founder}
${website}

Licensed under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

Note the highlighted “parameters” enclosed within special notation “${ }”. We will define the values for these parameters when we will configure Maven License Plugin in our project’s POM file, as show below:

<plugin>
    <groupId>com.mycila.maven-license-plugin</groupId>
    <artifactId>maven-license-plugin</artifactId>
    <version>1.10.b1</version>
    <configuration>
        <header>src/license/LicenseHeader.txt</header>
        <properties>
            <project>${project.name}</project>
            <founder>${project.organization.name}</founder>
            <year>${project.inceptionYear}</year>
            <website>${founder-website}</website>

        </properties>
        <includes>
            <include>src/main/java/**</include>
            <include>src/test/java/**</include>

        </includes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>format</goal>
            </goals>
            <phase>process-sources</phase>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.mycila</groupId>
            <artifactId>licenses</artifactId>
            <version>1</version>
        </dependency>
    </dependencies>
</plugin>

  1. Under the configuration tag, notice the <header/> element where we’ve mentioned the path to our copyrights and license header file.
  2. Similarly, the <properties/> element under <header/> is the place where you can define parameters and their values to be replaced by the parameter place holders as show in the header file above.
  3. The <includes/> element is the place where you can configure which files should the plugin attempt to add/append the copyright and license information. You can use wild cards as shown above.

Following is an example of Source Code file after processed by Maven License Plugin:

Thursday 3 October 2013

Apache Maven Tips: Customizing Maven Site generation via Site Descriptor (Site.xml), Maven Site Plugin and Velocity Template

apache-mavenThere are two kind of customizations you can do with Maven Site generation:

(1) Configuring the Site Descriptor (Simple) – This is a higher level customization, where you can change or configure certain sections/areas of the site layout including the navigation/menu. Read more on Maven website.

(2) Custom Velocity Template (Complex) – This is a low level customization, where you have full control over the generated html content. However it is more complex than the first one because you need to have an understanding of Apache Velocity templating language.

To begin with, add Maven Site Plugin configuration under the <build/> tag of your POM:

<plugin>
    <artifactId>maven-site-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <templateFile>${basedir}/src/site/maven-site-template.vm</templateFile>
    </configuration>

</plugin>

Recommended way to develop/design a custom maven site template, is to start with the default template provided by maven itself, and then change it to your desired layout.

Tuesday 1 October 2013

Apache Maven Tips: How to add/include or remove/exclude files as Resources and Test Resources

apache-mavenApache Maven’s Standard Directory Layout contains specific folders for application wide Resources and TestResources, they are:

src/main/resources
src/test/resources

What if you want to add or include more files as Resources or TestResources? a typical example is the use of standard README, LICENSE and NOTICE files, which by convention should reside at the very root of the project, like this:

./README
./LICENSE
./NOTICE
./src/...

In such situations, you can add or include files by adding a configuration similar to the following, under the <build/> section of your POM:

<build>
    <resources>
        <resource>
            <directory>${project.basedir}</directory>
            <includes>
                <include>README*</include>
                <include>LICENSE*</include>
                <include>NOTICE*</include>
            </includes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>${project.basedir}</directory>
            <includes>
                <include>README*</include>
                <include>LICENSE*</include>
                <include>NOTICE*</include>
            </includes>
        </testResource>
    </testResources>

Similarly, you can remove or exclude files by adding a configuration similar to the following, under the <build/> section of your POM:

<build>
    <resources>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <excludes>
                <exclude>SomeFile.toExclude</exclude>
            </excludes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>${project.basedir}/src/test/resources</directory>
            <excludes>
                <exclude>SomeFile.toExclude</exclude>
            </excludes>
        </testResource>
    </testResources>