Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

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>

Saturday, 15 December 2012

JDBC URL String Part One

 

Please click here to read the introduction of the series of posts and the format being used.

  1. 4D – 4D – 4D
    1. com.fourd.jdbc.DriverImpl
    2. jdbc:4d:ip-address
    3. jdbc:4d:127.0.0.1
  2. Software AG – Adabas D – Adabas D
    1. de.sag.jdbc.adabasd.ADriver
    2. jdbc:adabasd://server-node[:port]/server-db
    3. jdbc:adabasd://localhost/mydb
  3. Apache – Derby – Derby
    1. org.apache.derby.jdbc.EmbeddedDriver
    2. jdbc:derby:[subsubprotocol:][databaseName][;attribute=value]*
    3. jdbc:derby:sample
  4. Teradata – Aster nCluster – Aster nCluster
    1. com.asterdata.ncluster.Driver
    2. jdbc:ncluster://{ip or name of server}:2406/{database name}
    3. jdbc:ncluster://localhost:2406/mydb
    4. 2406
  5. Altibase – Altibase – Altibase
    1. Altibase.jdbc.driver.AltibaseDriver
    2. jdbc:Altibase://server_ip:server_port/dbname
    3. jdbc:Altibase://127.0.0.1:20300/mydb
  6. CSQL – CSQL – CSQL
    1. csql.jdbc.JdbcSqlDriver
    2. JDBC URLs
      1. jdbc:csql
        Connect to database without network.
      2. jdbc: adapter
        Connect to database through adapter without network for any operation in target database
      3. jdbc:gateway
        Connect to database through gateway without network
      4. jdbc:csql://<Host Name>:<Port>/csql
        Connect to database with network
      5. jdbc:adapter://<Host Name>:<port>/csql
        Connect to database through adapter with network for any operation on target database
      6. jdbc:gateway://<Host Name>:<port>/csql
        Connect to database through gateway with network
  7. CUBRID – CUBRID – CUBRID
    1. cubrid.jdbc.driver.CUBRIDDriver
    2. jdbc:cubrid:<host>:<port>:<db-name>:[user-id]:[password]:[?<property> [& <property>]]
    3. jdbc:CUBRID:192.168.0.1:33000:db1:::
    4. 33000
  8. Daffodil – Daffodil DB – Daffodil DB
    1. Drivers
      1. in.co.daffodil.db.rmi.RmiDaffodilDBDriver
      2. in.co.daffodil.db.jdbc.DaffodilDBDriver
    2. JDBC URLs
      1. Server - jdbc:daffodilDB://<server>[:<port>]/<databaseName>
      2. Embedded - jdbc:daffodilDB_embedded:<databaseName>
    3. Examples
      1. Server – jdbc:daffodilDB://localhost:3456/mydb
      2. Embedded – jdbc:daffodilDB_embedded:mydb
    4. 3456