Monday, October 19, 2009
Adding Jalopy to Maven and clean things up
Recently, I had the opportunity to work with web services and Apache Axis tools for generating java code from WSDL files to use UPS's Tradability web services. The generator created a lot of code that was poorly formatted. Given that I hate doing repetitive tasks, and I was already building in maven, I decided to see whose got a code formatter for maven. That way I could generate code and format code with just a few typed commnds.
Jalopy came to my rescue. To add their plugin, add the following to your pom.xml file:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jalopy-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<fileFormat>UNIX</fileFormat>
<convention>src/main/resources/jalopy/jalopy-settings.xml</convention>
</configuration>
</plugin>
Now, you don't have to use your own config file, but I recommend it if you want Sun coding conventions. This isn't perfect, I'm sure, but it's close enough for my needs:
<?xml version="1.0" encoding="UTF-8"?>
<jalopy>
<general>
<compliance>
<version>13</version>
</compliance>
<style>
<description>Java Style</description>
<name>Maven2</name>
</style>
</general>
<inspector>
<enable>false</enable>
<naming>
<classes>
<abstract>[A-Z][a-zA-Z0-9]+</abstract>
<general>[A-Z][a-zA-Z0-9]+</general>
</classes>
<fields>
<default>[a-z][\w]+</default>
<defaultStatic>[a-z][\w]+</defaultStatic>
<defaultStaticFinal>[a-zA-Z][\w]+</defaultStaticFinal>
<private>[a-z][\w]+</private>
<privateStatic>[a-z][\w]+</privateStatic>
<privateStaticFinal>[a-zA-Z][\w]+</privateStaticFinal>
<protected>[a-z][\w]+</protected>
<protectedStatic>[a-z][\w]+</protectedStatic>
<protectedStaticFinal>[a-zA-Z][\w]+</protectedStaticFinal>
<public>[a-z][\w]+</public>
<publicStatic>[a-z][\w]+</publicStatic>
<publicStaticFinal>[a-zA-Z][\w]+</publicStaticFinal>
</fields>
<interfaces>[A-Z][a-zA-Z0-9]+</interfaces>
<labels>\w+</labels>
<methods>
<default>[a-z][\w]+</default>
<defaultStatic>[a-z][\w]+</defaultStatic>
<defaultStaticFinal>[a-z][\w]+</defaultStaticFinal>
<private>[a-z][\w]+</private>
<privateStatic>[a-z][\w]+</privateStatic>
<privateStaticFinal>[a-z][\w]+</privateStaticFinal>
<protected>[a-z][\w]+</protected>
<protectedStatic>[a-z][\w]+</protectedStatic>
<protectedStaticFinal>[a-z][\w]+</protectedStaticFinal>
<public>[a-z][\w]+</public>
<publicStatic>[a-z][\w]+</publicStatic>
<publicStaticFinal>[a-z][\w]+</publicStaticFinal>
</methods>
<packages>[a-z]+(?:\.[a-z]+)*</packages>
<parameters>
<default>[a-z][\w]+</default>
<final>[a-z][\w]+</final>
</parameters>
<variables>[a-z][\w]*</variables>
</naming>
<tips>
<adhereToNamingConvention>false</adhereToNamingConvention>
<alwaysOverrideHashCode>false</alwaysOverrideHashCode>
<avoidThreadGroups>false</avoidThreadGroups>
<declareCollectionComment>false</declareCollectionComment>
<dontIgnoreExceptions>false</dontIgnoreExceptions>
<dontSubstituteObjectEquals>false</dontSubstituteObjectEquals>
<neverDeclareException>false</neverDeclareException>
<neverDeclareThrowable>false</neverDeclareThrowable>
<neverInvokeWaitOutsideLoop>false</neverInvokeWaitOutsideLoop>
<neverReturnZeroArrays>false</neverReturnZeroArrays>
<neverUseEmptyFinally>false</neverUseEmptyFinally>
<obeyContractEquals>false</obeyContractEquals>
<overrideToString>false</overrideToString>
<referToObjectsByInterface>false</referToObjectsByInterface>
<replaceStructureWithClass>false</replaceStructureWithClass>
<stringLiterallI18n>false</stringLiterallI18n>
<useInterfaceOnlyForTypes>false</useInterfaceOnlyForTypes>
<wrongCollectionComment>false</wrongCollectionComment>
</tips>
</inspector>
<internal>
<version>6</version>
</internal>
<messages>
<priority>
<general>30000</general>
<parser>30000</parser>
<parserJavadoc>30000</parserJavadoc>
<printer>30000</printer>
<printerJavadoc>30000</printerJavadoc>
<transform>30000</transform>
</priority>
<showErrorStackTrace>true</showErrorStackTrace>
</messages>
<misc>
<threadCount>2</threadCount>
</misc>
<printer>
<alignment>
<methodCallChain>false</methodCallChain>
<parameterMethodDeclaration>false</parameterMethodDeclaration>
<ternaryOperator>true</ternaryOperator>
<variableAssignment>false</variableAssignment>
<variableIdentifier>false</variableIdentifier>
</alignment>
<backup>
<directory>bak</directory>
<level>0</level>
</backup>
<blanklines>
<after>
<block>1</block>
<braceLeft>0</braceLeft>
<class>1</class>
<declaration>0</declaration>
<footer>1</footer>
<header>0</header>
<interface>1</interface>
<lastImport>1</lastImport>
<method>0</method>
<package>0</package>
</after>
<before>
<block>1</block>
<braceRight>0</braceRight>
<caseBlock>0</caseBlock>
<comment>
<javadoc>1</javadoc>
<multiline>1</multiline>
<singleline>1</singleline>
</comment>
<controlStatement>0</controlStatement>
<declaration>0</declaration>
<footer>0</footer>
<header>0</header>
</before>
<keepUpTo>1</keepUpTo>
</blanklines>
<braces>
<empty>
<cuddle>false</cuddle>
<insertStatement>false</insertStatement>
</empty>
<insert>
<dowhile>true</dowhile>
<for>true</for>
<ifelse>true</ifelse>
<while>true</while>
</insert>
<remove>
<block>true</block>
<dowhile>false</dowhile>
<for>false</for>
<ifelse>false</ifelse>
<while>false</while>
</remove>
<treatDifferent>
<methodClass>false</methodClass>
<methodClassIfWrapped>false</methodClassIfWrapped>
</treatDifferent>
</braces>
<chunks>
<blanklines>false</blanklines>
<comments>true</comments>
</chunks>
<comments>
<format>
<multiline>true</multiline>
</format>
<javadoc>
<check>
<innerclass>false</innerclass>
<tags>false</tags>
<throwsTags>true</throwsTags>
</check>
<fieldsShort>false</fieldsShort>
<generate>
<class>1</class>
<constructor>0</constructor>
<field>0</field>
<method>0</method>
</generate>
<parseComments>true</parseComments>
<tags>
<in-line />
<standard />
</tags>
<templates>
<class>/**| * DOCUMENT ME!| *| * @author $author$| * @version $Revision$| */</class>
<constructor>
<bottom> */</bottom>
<exception> * @throws $exceptionType$ DOCUMENT ME!</exception>
<param> * @param $paramType$ DOCUMENT ME!</param>
<top>/**| * Creates a new $objectType$ object.</top>
</constructor>
<interface>/**| * DOCUMENT ME!| *| * @author $author$| * @version $Revision$| */</interface>
<method>
<bottom> */</bottom>
<exception> * @throws $exceptionType$ DOCUMENT ME!</exception>
<param> * @param $paramType$ DOCUMENT ME!</param>
<return> * @return DOCUMENT ME!</return>
<top>/**| * DOCUMENT ME!</top>
</method>
</templates>
</javadoc>
<remove>
<javadoc>false</javadoc>
<multiline>false</multiline>
<singleline>false</singleline>
</remove>
<separator>
<fillCharacter>-</fillCharacter>
<insert>false</insert>
<insertRecursive>false</insertRecursive>
<text>
<class>Inner Classes</class>
<constructor>Constructors</constructor>
<field>Instance fields</field>
<initializer>Instance initializers</initializer>
<interface>Inner Interfaces</interface>
<method>Methods</method>
<static>Static fields/initializers</static>
</text>
</separator>
</comments>
<environment />
<footer>
<keys />
<smartMode>0</smartMode>
<use>false</use>
</footer>
<header>
<keys>Tha Apache Software License</keys>
<smartMode>5</smartMode>
<text>/*| * Copyright 2001-2004 The Apache Software Foundation.| *| * 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.| */</text>
<use>false</use>
</header>
<history>
<policy>disabled</policy>
</history>
<imports>
<grouping>
<defaultDepth>3</defaultDepth>
<packages>*:0|gnu:2|java:1|javax:1</packages>
</grouping>
<policy>disabled</policy>
<sort>true</sort>
</imports>
<indentation>
<caseFromSwitch>true</caseFromSwitch>
<continuation>
<block>false</block>
<operator>false</operator>
</continuation>
<firstColumnComments>false</firstColumnComments>
<label>false</label>
<policy>
<deep>true</deep>
</policy>
<sizes>
<braceCuddled>1</braceCuddled>
<braceLeft>1</braceLeft>
<braceRight>0</braceRight>
<braceRightAfter>1</braceRightAfter>
<continuation>4</continuation>
<deep>55</deep>
<extends>-1</extends>
<general>4</general>
<implements>-1</implements>
<leading>0</leading>
<tabs>8</tabs>
<throws>-1</throws>
<trailingComment>1</trailingComment>
</sizes>
<tabs>
<enable>false</enable>
<onlyLeading>false</onlyLeading>
</tabs>
</indentation>
<misc>
<arrayBracketsAfterIdent>false</arrayBracketsAfterIdent>
<forceFormatting>false</forceFormatting>
<insertExpressionParentheses>true</insertExpressionParentheses>
<insertLoggingConditional>false</insertLoggingConditional>
<insertTrailingNewline>true</insertTrailingNewline>
<insertUID>false</insertUID>
</misc>
<sorting>
<declaration>
<class>false</class>
<constructor>false</constructor>
<enable>false</enable>
<interface>false</interface>
<method>false</method>
<order>static|field|initializer|constructor|method|interface|class</order>
<variable>false</variable>
</declaration>
<modifier>
<enable>false</enable>
<order>public|protected|private|abstract|static|final|synchronized|transient|volatile|native|strictfp</order>
</modifier>
</sorting>
<whitespace>
<after>
<comma>true</comma>
<semicolon>true</semicolon>
<typeCast>true</typeCast>
</after>
<before>
<braces>false</braces>
<brackets>false</brackets>
<bracketsTypes>false</bracketsTypes>
<caseColon>false</caseColon>
<operator>
<not>true</not>
</operator>
<parentheses>
<methodCall>false</methodCall>
<methodDeclaration>false</methodDeclaration>
<statement>false</statement>
</parentheses>
</before>
<padding>
<braces>false</braces>
<brackets>false</brackets>
<operator>
<assignment>true</assignment>
<bitwise>true</bitwise>
<logical>true</logical>
<mathematical>true</mathematical>
<relational>true</relational>
<shift>true</shift>
</operator>
<parenthesis>false</parenthesis>
<typeCast>false</typeCast>
</padding>
</whitespace>
<wrapping>
<always>
<after>
<arrayElement>0</arrayElement>
<braceRight>false</braceRight>
<extendsTypes>false</extendsTypes>
<implementsTypes>false</implementsTypes>
<label>true</label>
<methodCallChained>false</methodCallChained>
<ternaryOperator>
<first>false</first>
<second>false</second>
</ternaryOperator>
<throwsTypes>false</throwsTypes>
</after>
<before>
<braceLeft>false</braceLeft>
<extends>true</extends>
<implements>true</implements>
<throws>true</throws>
</before>
<parameter>
<methodCall>false</methodCall>
<methodCallNested>true</methodCallNested>
<methodDeclaration>false</methodDeclaration>
</parameter>
</always>
<general>
<beforeOperator>false</beforeOperator>
<enable>true</enable>
<lineLength>140</lineLength>
</general>
<ondemand>
<after>
<assignment>true</assignment>
<leftParenthesis>false</leftParenthesis>
<parameter>true</parameter>
<types>
<extends>true</extends>
<implements>true</implements>
<throws>true</throws>
</types>
</after>
<before>
<rightParenthesis>false</rightParenthesis>
</before>
<groupingParentheses>true</groupingParentheses>
</ondemand>
</wrapping>
</printer>
</jalopy>
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2009
(21)
-
▼
October
(14)
- Slowing brute force hackers
- Generating a new CSR to get your shiny new SSL cer...
- Turning man pages to PDF files
- Regex pattern for stripping Javadocs
- XSLT outputing Carriage return/line feed
- Getting FTP to work through IP tables
- Yum repo for more up to date Dovecot
- JBoss and file handles on RedHat
- How to get more network stats
- How to find process IDs listening to port xxx
- Fun with SSL certs and Apache
- Adding Jalopy to Maven and clean things up
- Dealing with extended characters in bash
- Meta key in emacs on osx 10.6.1
-
▼
October
(14)
No comments:
Post a Comment