From 7551c043f37ed14252ed6c5e7adbaa44ed889f1e Mon Sep 17 00:00:00 2001 From: ltheussl Date: Sat, 29 Apr 2006 06:05:18 +0000 Subject: [PATCH] PR: MPJALOPY-10 Complete rewrite of the plugin so it doesn't use the jalopy ant task anymore. Using a jellybean instead, copied and adapted from the m2 jalopy plugin at mojo. Added new properties maven.jalopy.inspect, maven.jalopy.backup and maven.jalopy.force. Removed properties maven.jalopy.logLevel and maven.jalopy.nbThread. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@398096 13f79535-47bb-0310-9956-ffa450edef68 --- jalopy/README | 13 - jalopy/plugin.jelly | 67 +-- jalopy/plugin.properties | 7 +- jalopy/project.xml | 65 +- .../org/apache/maven/jalopy/JalopyBean.java | 564 ++++++++++++++++++ .../java/org/apache/maven/jalopy/package.html | 11 + jalopy/src/plugin-resources/jalopy.xml | 385 ++++++++++++ jalopy/src/plugin-resources/jalopy_maven.xml | 254 -------- .../apache/maven/jalopy/JalopyBeanTest.java | 312 ++++++++++ .../java/org/apache/maven/jalopy/package.html | 11 + .../src/test/resources/input-bak/Circle.java | 32 + .../src/test/resources/input-bak/Point.java | 24 + .../test/resources/input-bak/Rectangle.java | 53 ++ jalopy/src/test/resources/jalopy.xml | 385 ++++++++++++ .../src/test/resources/validator/Circle.java | 42 ++ .../src/test/resources/validator/Point.java | 27 + .../test/resources/validator/Rectangle.java | 57 ++ jalopy/xdocs/changes.xml | 2 + jalopy/xdocs/properties.xml | 41 +- 19 files changed, 1991 insertions(+), 361 deletions(-) delete mode 100644 jalopy/README create mode 100644 jalopy/src/main/java/org/apache/maven/jalopy/JalopyBean.java create mode 100644 jalopy/src/main/java/org/apache/maven/jalopy/package.html create mode 100644 jalopy/src/plugin-resources/jalopy.xml delete mode 100644 jalopy/src/plugin-resources/jalopy_maven.xml create mode 100644 jalopy/src/test/java/org/apache/maven/jalopy/JalopyBeanTest.java create mode 100644 jalopy/src/test/java/org/apache/maven/jalopy/package.html create mode 100644 jalopy/src/test/resources/input-bak/Circle.java create mode 100644 jalopy/src/test/resources/input-bak/Point.java create mode 100644 jalopy/src/test/resources/input-bak/Rectangle.java create mode 100644 jalopy/src/test/resources/jalopy.xml create mode 100644 jalopy/src/test/resources/validator/Circle.java create mode 100644 jalopy/src/test/resources/validator/Point.java create mode 100644 jalopy/src/test/resources/validator/Rectangle.java diff --git a/jalopy/README b/jalopy/README deleted file mode 100644 index ba892c76..00000000 --- a/jalopy/README +++ /dev/null @@ -1,13 +0,0 @@ -A simple plugin to make jalopy available to you. - -Your maven.xml might look something like this: - - - - - - - - diff --git a/jalopy/plugin.jelly b/jalopy/plugin.jelly index d55b2ef0..fe56646f 100644 --- a/jalopy/plugin.jelly +++ b/jalopy/plugin.jelly @@ -20,59 +20,44 @@ + + + + + - - - - - - - - - - - - - - + description="Format all sources with code convention conformance"> + + - - - - - - - - - - - - - diff --git a/jalopy/plugin.properties b/jalopy/plugin.properties index 1419f2f9..e8930f1d 100644 --- a/jalopy/plugin.properties +++ b/jalopy/plugin.properties @@ -19,11 +19,12 @@ # ------------------------------------------------------------------- maven.jalopy.fileFormat=auto -maven.jalopy.style=${plugin.resources}/jalopy_maven.xml +maven.jalopy.style=${plugin.resources}/jalopy.xml maven.jalopy.history=none -maven.jalopy.logLevel=info -maven.jalopy.nbThread=1 maven.jalopy.failOnError=true +maven.jalopy.inspect=false +maven.jalopy.backup=false +maven.jalopy.force=false maven.jalopy.filesetInclude=**/*.java maven.jalopy.filesetExclude= diff --git a/jalopy/project.xml b/jalopy/project.xml index a8aa0724..9719032d 100644 --- a/jalopy/project.xml +++ b/jalopy/project.xml @@ -87,37 +87,20 @@ jalopy jalopy 1.5b5 - - root - - jalopy - jalopy-ant - 0.1-1.5b5 - - root - + plexus + plexus-utils + 1.0.0 - aelfred - aelfred - 1.2 - - - xml-apis - xml-apis - 1.3.03 - http://xml.apache.org/commons/ + commons-logging + commons-logging + 1.0.4 This library is already loaded by maven's core. Be careful to use the same version number as in the core. - - jdom - jdom - 1.0 - log4j log4j @@ -126,15 +109,31 @@ This library is already loaded by maven's core. Be careful to use the same version number as in the core. - - oro - oro - 2.0.8 - - - textarea - textarea - 2.2.3 - + + src/main/java + src/test/java + + + + input-bak + src/test/resources/input-bak + + *.java + + + + validator + src/test/resources/validator + + *.java + + + + + **/*Test.java + + + + diff --git a/jalopy/src/main/java/org/apache/maven/jalopy/JalopyBean.java b/jalopy/src/main/java/org/apache/maven/jalopy/JalopyBean.java new file mode 100644 index 00000000..6da49821 --- /dev/null +++ b/jalopy/src/main/java/org/apache/maven/jalopy/JalopyBean.java @@ -0,0 +1,564 @@ +package org.apache.maven.jalopy; + +/* ==================================================================== + * Copyright 2006 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. + * ==================================================================== + */ + +import de.hunsicker.jalopy.Jalopy; +import de.hunsicker.jalopy.storage.Convention; +import de.hunsicker.jalopy.storage.History; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.StringUtils; + + +/** + * A bean to format all source files according to code conventions. + * + * @author jruiz@exist.com + * @author Emmanuel Venisse + * @author Lukas Theussl + * @version $Id$ + */ + +public class JalopyBean +{ + /** Log. */ + private static final Log LOG = LogFactory.getLog( JalopyBean.class ); + + /** + * Sets the file format of the output files. + * The file format controls what end of line character is used. + * Either one of "UNIX", "DOS", "MAC", "DEFAULT" or "AUTO" can be used. + */ + private String fileFormat; + + /** + * Specifies the history policy to use. + * Either one of "COMMENT", "FILE" or "NONE" can be used. + */ + private String historyPolicy; + + /** + * Indicates whether a run should be held if errors occured. + */ + private boolean failOnError; + + /** + * Indicates whether to enable the code inspector. + */ + private boolean inspect; + + /** + * Indicates whether keep backups of formatted source files. + */ + private boolean backup; + + /** + * Indicates whether to force formatting of source files. + */ + private boolean force; + + /** + * The source directory. + */ + private File sourceDirectory; + + /** + * The test source directory. + */ + private File testSourceDirectory; + + /** + * Sets the preferences file to use - given either relative to + * the project's basedir or as an absolute local path or internet address. + * If omitted, the current preferences are used, if available. + * Otherwise the Jalopy build-in defaults will be used. + */ + private File convention; + + /** + * For Source Directory. Specifies a fileset source file to format. + * This is a comma- or space-separated list of patterns of files. + */ + private String srcIncludesPattern; + + /** + * For Source Directory. Source files excluded from format. + * This is a comma- or space-separated list of patterns of files. + */ + private String srcExcludesPattern; + + /** + * For Test Directory. Specifies a fileset source file to format. + * This is a comma- or space-separated list of patterns of files. + */ + private String testIncludesPattern; + + /** + * For Test Directory. Source files excluded from format. + * This is a comma- or space-separated list of patterns of files. + */ + private String testExcludesPattern; + + /** + * The main method: starts formatting of source files. + * + * @throws Exception Exception + */ + public void execute() throws Exception + { + + LOG.info("[jalopy] Jalopy Java Source Code Formatter " + Jalopy.getVersion()); + + try + { + if ( getSourceDirectory().exists() ) + { + String[] filesToFormat = getIncludedFiles( getSourceDirectory(), getSrcIncludesPattern(), + getSrcExcludesPattern() ); + + LOG.info( "[jalopy] Format " + filesToFormat.length + " source files in " + getSourceDirectory().toString() ); + formatFiles( getSourceDirectory(), filesToFormat ); + LOG.info( "[jalopy] " + filesToFormat.length + " source files formatted" ); + } + + if ( getTestSourceDirectory().exists() ) + { + String[] filesToFormat = getIncludedFiles( getTestSourceDirectory(), getTestIncludesPattern(), + getTestExcludesPattern() ); + + LOG.info( "[jalopy] Format " + filesToFormat.length + " source files in " + getTestSourceDirectory().toString() ); + formatFiles( getTestSourceDirectory(), filesToFormat ); + LOG.info( "[jalopy] " + filesToFormat.length + " source files formatted" ); + } + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + + /** + * Returns a string array of files to format. + * + * @param directory The base directory + * @param includes The includes pattern + * @param excludes The excludes pattern + * @return String[] + */ + private String[] getIncludedFiles( File directory, String includes, String excludes ) + { + DirectoryScanner scanner = new DirectoryScanner(); + + scanner.setBasedir( directory ); + + scanner.setIncludes( StringUtils.split( includes, "," ) ); + + scanner.setExcludes( StringUtils.split( excludes, "," ) ); + + scanner.scan(); + + String[] filesToFormat = scanner.getIncludedFiles(); + + return filesToFormat; + } + + /** + * Formats the source files. + * + * @param directory The base directory + * @param filesToFormat A string array of files to format + * @throws FileNotFoundException FileNotFoundException + * @throws Exception Exception + */ + private void formatFiles( File directory, String[] filesToFormat ) + throws FileNotFoundException, Exception + { + Jalopy jalopy = createJalopy(); + + for ( int i = 0; i < filesToFormat.length; i++ ) + { + File currentFile = new File( directory, filesToFormat[i] ); + + jalopy.setInput( currentFile ); + + jalopy.setOutput( currentFile ); + + if ( isBackup() ) + { + jalopy.setBackupDirectory( currentFile.getParentFile() ); + } + + jalopy.format(); + + logMessage( jalopy, currentFile ); + } + } + + /** + * Logs a message depending on the jalopy exit status. + * + * @param jalopy The jalopy instance + * @param currentFile The file whose status is to be logged + * @throws Exception Exception + */ + private void logMessage( Jalopy jalopy, File currentFile ) + throws Exception + { + + if ( jalopy.getState() == Jalopy.State.OK ) + { + LOG.debug( "[jalopy] " + currentFile + " formatted correctly." ); + } + else if ( jalopy.getState() == Jalopy.State.WARN ) + { + LOG.warn( "[jalopy] " + currentFile + " formatted with warnings." ); + } + else if ( jalopy.getState() == Jalopy.State.ERROR ) + { + LOG.error( "[jalopy] " + currentFile + " could not be formatted." ); + + if ( isFailOnError() ) + { + throw new Exception( currentFile + " could not be formatted." ); + } + } + else + { + LOG.warn( "[jalopy] " + currentFile + " formatted with unknown state." ); + } + } + + /** + * Creates a new instance of a Jalopy formatter with all bean variables being set. + * + * @return Jalopy + */ + private Jalopy createJalopy() + { + Jalopy jalopy = new Jalopy(); + + try + { + if ( ( convention != null ) && convention.exists() ) + { + LOG.debug( "[jalopy] Using convention file : " + convention.getAbsoluteFile() ); + Jalopy.setConvention( convention ); + } + else + { + LOG.warn( "[jalopy] Convention file does not exist: " + convention.getAbsoluteFile() ); + LOG.warn( "[jalopy] Using default convention : jalopy.xml"); + InputStream in = this.getClass().getClassLoader().getResourceAsStream( "plugin-resources/jalopy.xml" ); + Convention.importSettings( in, Convention.EXTENSION_XML ); + } + } + catch ( IOException ex ) + { + ex.printStackTrace(); + } + + jalopy.setFileFormat( getFileFormat() ); + + jalopy.setInspect( isInspect() ); + + if ( !getHistoryPolicy().equalsIgnoreCase( "none" ) ) + { + jalopy.setHistoryPolicy( History.Policy.valueOf( getHistoryPolicy() ) ); + } + + // TODO: what are the allowed values for historyMethod? + //Convention settings = Convention.getInstance(); + //History.Method historyMethod = History.Method.valueOf( settings.get( ConventionKeys.HISTORY_METHOD, + // ConventionDefaults.HISTORY_METHOD ) ); + //jalopy.setHistoryMethod( historyMethod ); + + jalopy.setBackup( isBackup() ); + + jalopy.setForce( isForce() ); + + return jalopy; + } + + /** + * Returns the fileFormat property. + * + * @return String + */ + public String getFileFormat() + { + return fileFormat; + } + + /** + * Sets the fileFormat property. + * + * @param newfileFormat The new property + */ + public void setFileFormat( String newfileFormat ) + { + this.fileFormat = newfileFormat; + } + + /** + * Returns the failOnError property. + * + * @return boolean + */ + public boolean isFailOnError() + { + return failOnError; + } + + /** + * Sets the failOnError property. + * + * @param newfailOnError The new property + */ + public void setFailOnError( boolean newfailOnError ) + { + this.failOnError = newfailOnError; + } + + /** + * Returns the inspect property. + * + * @return boolean + */ + public boolean isInspect() + { + return inspect; + } + + /** + * Sets the inspect property. + * + * @param newinspect The new property + */ + public void setInspect( boolean newinspect ) + { + this.inspect = newinspect; + } + + /** + * Returns the backup property. + * + * @return boolean + */ + public boolean isBackup() + { + return backup; + } + + /** + * Sets the backup property. + * + * @param newbackup The new property + */ + public void setBackup( boolean newbackup ) + { + this.backup = newbackup; + } + + /** + * Returns the force property. + * + * @return boolean + */ + public boolean isForce() + { + return force; + } + + /** + * Sets the force property. + * + * @param newforce The new property + */ + public void setForce( boolean newforce ) + { + this.force = newforce; + } + + /** + * Returns the sourceDirectory property. + * + * @return File + */ + public File getSourceDirectory() + { + return sourceDirectory; + } + + /** + * Sets the sourceDirectory property. + * + * @param newsourceDirectory The new property + */ + public void setSourceDirectory( File newsourceDirectory ) + { + this.sourceDirectory = newsourceDirectory; + } + + /** + * Returns the srcIncludesPattern property. + * + * @return String + */ + public String getSrcIncludesPattern() + { + return srcIncludesPattern; + } + + /** + * Sets the srcIncludesPattern property. + * + * @param newsrcIncludesPattern The new property + */ + public void setSrcIncludesPattern( String newsrcIncludesPattern ) + { + this.srcIncludesPattern = newsrcIncludesPattern; + } + + /** + * Returns the srcExcludesPattern property. + * + * @return String + */ + public String getSrcExcludesPattern() + { + return srcExcludesPattern; + } + + /** + * Sets the srcExcludesPattern property. + * + * @param newsrcExcludesPattern The new property + */ + public void setSrcExcludesPattern( String newsrcExcludesPattern ) + { + this.srcExcludesPattern = newsrcExcludesPattern; + } + + /** + * Returns the historyPolicy property. + * + * @return String + */ + public String getHistoryPolicy() + { + return historyPolicy; + } + + /** + * Sets the historyPolicy property. + * + * @param newhistoryPolicy The new property + */ + public void setHistoryPolicy( String newhistoryPolicy ) + { + this.historyPolicy = newhistoryPolicy; + } + + /** + * Returns the convention property. + * + * @return File + */ + public File getConvention() + { + return convention; + } + + /** + * Sets the convention property. + * + * @param newconvention The new property + */ + public void setConvention( File newconvention ) + { + this.convention = newconvention; + } + + /** + * Returns the testSourceDirectory property. + * + * @return File + */ + public File getTestSourceDirectory() + { + return testSourceDirectory; + } + + /** + * Sets the testSourceDirectory property. + * + * @param newtestSourceDirectory The new property + */ + public void setTestSourceDirectory( File newtestSourceDirectory ) + { + this.testSourceDirectory = newtestSourceDirectory; + } + + /** + * Returns the testIncludesPattern property. + * + * @return String + */ + public String getTestIncludesPattern() + { + return testIncludesPattern; + } + + /** + * Sets the testIncludesPattern property. + * + * @param newtestIncludesPattern The new property + */ + public void setTestIncludesPattern( String newtestIncludesPattern ) + { + this.testIncludesPattern = newtestIncludesPattern; + } + + /** + * Returns the testExcludesPattern property. + * + * @return String + */ + public String getTestExcludesPattern() + { + return testExcludesPattern; + } + + /** + * Sets the testExcludesPattern property. + * + * @param newtestExcludesPattern The new property + */ + public void setTestExcludesPattern( String newtestExcludesPattern ) + { + this.testExcludesPattern = newtestExcludesPattern; + } +} diff --git a/jalopy/src/main/java/org/apache/maven/jalopy/package.html b/jalopy/src/main/java/org/apache/maven/jalopy/package.html new file mode 100644 index 00000000..f50fafd3 --- /dev/null +++ b/jalopy/src/main/java/org/apache/maven/jalopy/package.html @@ -0,0 +1,11 @@ + + + + org.apache.maven.jalopy + + +

+ Contains classes to format java source files with jalopy. +

+ + diff --git a/jalopy/src/plugin-resources/jalopy.xml b/jalopy/src/plugin-resources/jalopy.xml new file mode 100644 index 00000000..fbadb142 --- /dev/null +++ b/jalopy/src/plugin-resources/jalopy.xml @@ -0,0 +1,385 @@ + + + + + 13 + + + + + false + + + [A-Z][a-zA-Z0-9]+ + [A-Z][a-zA-Z0-9]+ + + + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + + [A-Z][a-zA-Z0-9]+ + \w+ + + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + + [a-z]+(?:\.[a-z]+)* + + [a-z][\w]+ + [a-z][\w]+ + + [a-z][\w]* + + + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + + + + 6 + + + + 30000 + 30000 + 30000 + 30000 + 30000 + 30000 + + true + + + 2 + + + + true + false + true + false + false + + + bak + 0 + + + + 1 + 0 + 1 + 0 +
1
+
0
+ 1 + 1 + 1 + 1 +
+ + 1 + 0 + 1 + + 1 + 1 + 1 + + 1 + 1 +
0
+
2
+
+ 1 +
+ + + false + false + + + true + true + true + true + + + true + false + false + false + false + + + true + true + + + + true + true + + + + false + + + + false + false + true + + false + + 0 + 0 + 0 + 0 + + false + + + + + + /**| * DOCUMENT ME!| *| * @author $author$| * @version $Revision: 120 $| */ + + */ + * @throws $exceptionType$ DOCUMENT ME! + * @param $paramType$ DOCUMENT ME! + /**| * Creates a new $objectType$ object. + + /**| * DOCUMENT ME!| *| * @author $author$| * @version $Revision: 120 $| */ + + */ + * @throws $exceptionType$ DOCUMENT ME! + * @param $paramType$ DOCUMENT ME! + * @return DOCUMENT ME! + /**| * DOCUMENT ME! + + + + + false + false + false + + + - + false + false + + Inner Classes + Constructors + Instance fields + Instance initializers + Inner Interfaces + Methods + Static fields/initializers + + + + +
+ + 0 + false +
+
+ Tha Apache Software License + 5 + /*| * 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.| */ + false +
+ + disabled + + + + 3 + *:0|gnu:2|java:1|javax:1 + + disabled + true + + + true + + true + false + + false + + + true + + + 1 + 0 + 0 + 1 + 4 + 55 + -1 + 4 + -1 + 0 + 8 + -1 + 1 + + + false + false + + + + false + false + true + false + true + false + + + + false + false + false + false + false + static|field|initializer|constructor|method|interface|class + false + + + false + public|protected|private|abstract|static|final|synchronized|transient|volatile|native|strictfp + + + + + true + true + true + + + true + false + false + false + + true + + + false + false + true + + + + true + false + + true + true + true + true + true + true + + true + false + + + + + + 0 + false + false + false + + false + + false + false + + false + + + true + true + true + true + + + false + true + false + + + + false + true + 120 + + + + true + false + true + + true + true + true + + + + false + + true + + +
+
+ diff --git a/jalopy/src/plugin-resources/jalopy_maven.xml b/jalopy/src/plugin-resources/jalopy_maven.xml deleted file mode 100644 index 7a0aed8f..00000000 --- a/jalopy/src/plugin-resources/jalopy_maven.xml +++ /dev/null @@ -1,254 +0,0 @@ - - - - - - false - false - false - false - false - - - false - false - - false - - false - Static Variables/Initializers,Instance Variables,Instance Initializers,Constructors,Methods,Interfaces,Classes - true - false - public,protected,private,abstract,static,final,synchronized,transient,volatile,native,strictfp - false - - - 0 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 0 - 1 - 0 - -
- /* - * 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. - */ - 5 - The Apache Software License - false -
- - true - false - false - true - true - true - false - false - true - true - true - true - false - true - true - false - true - false - false - true - false - - - - 0 - -1 - -1 - 0 - false - -1 - 4 - 1 - true - false - - 4 - false - - false - -1 - 1 - 30 - 0 - false - 4 - 1 - - - - 0 - false - - - * @return DOCUMENT ME! - * @throws $exceptionType$ DOCUMENT ME! - /**| * DOCUMENT ME! - */ - * @param $paramType$ DOCUMENT ME! - - - - - - - 0 - false - 0 - 0 - false - false - - - Methods - Static variables/initializers - Constructors - · - Interfaces - Instance initializers - Instance variables - Classes - - false - false - false - false - false - -
- - - false - 0 -
- - 0 - false - false - false - false - false - false - 80 - false - true - false - false - false - true - true - - - true - false - false - true - false - true - false - true - false - false - true - false - false - true - - - History.Policy [disabled] - - - - true - true - -
- - - ImportPolicy [expand] - 1 - javax:2|java:2 - true - - - false - false - true - - - - Sun - Sun Java Coding Convention - 0 - bak - 1 - 13 - false - - - 30000 - 30000 - 30000 - 30000 - 30000 - true - 30000 - - - 4 - -
\ No newline at end of file diff --git a/jalopy/src/test/java/org/apache/maven/jalopy/JalopyBeanTest.java b/jalopy/src/test/java/org/apache/maven/jalopy/JalopyBeanTest.java new file mode 100644 index 00000000..6758b149 --- /dev/null +++ b/jalopy/src/test/java/org/apache/maven/jalopy/JalopyBeanTest.java @@ -0,0 +1,312 @@ +package org.apache.maven.jalopy; + +/* ==================================================================== + * Copyright 2006 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. + * ==================================================================== + */ + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.StringTokenizer; + +/** + * Test case for JalopyBean.java + * + * @author Johnny R. Ruiz III + * @author Lukas Theussl + * @version $Id$ + */ +public class JalopyBeanTest extends TestCase +{ + /** An instance of a JalopyBean. */ + private JalopyBean jalopy; + + /** The basedir system property. */ + private String baseDir = System.getProperty( "basedir" ); + + /** + * Constructor. + * + * @param testName The name of the test. + */ + public JalopyBeanTest( String testName ) + { + super( testName ); + } + + /** JUnit setUp. + * @throws Exception Exception + */ + protected void setUp() throws Exception + { + jalopy = new JalopyBean(); + } + + /** JUnit tearDown. + * @throws Exception Exception + */ + protected void tearDown() throws Exception + { + } + + /** + * Rus the test suite. + * + * @return Test + */ + public static Test suite() + { + TestSuite suite = new TestSuite( JalopyBeanTest.class ); + + return suite; + } + + /** Tests equality of not yet formatted files. + * @throws IOException IOException + */ + public void testIfInputFilesIsNotYetJalopyFormatted() + throws IOException + { + recopyInputFiles(); + + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/test/Circle.java" ), + new File( baseDir, "target/test-classes/input-bak/Circle.java" ) ) ); + + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/src/Rectangle.java" ), + new File( baseDir, "target/test-classes/input-bak/Rectangle.java" ) ) ); + + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/test/Point.java" ), + new File( baseDir, "target/test-classes/input-bak/Point.java" ) ) ); + + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/src/Point.java" ), + new File( baseDir, "target/test-classes/input-bak/Point.java" ) ) ); + } + + /** Tests not-equality of formatted files. */ + public void testExecute() + { + jalopy.setFailOnError( true ); + + jalopy.setFileFormat( "auto" ); + + jalopy.setConvention( new File( baseDir, "src/test/resources/jalopy.xml" ) ); + + jalopy.setSourceDirectory( new File( baseDir, "target/test-classes/input/src" ) ); + + jalopy.setSrcExcludesPattern( "Point.java" ); + + jalopy.setSrcIncludesPattern( "Rectangle.java" ); + + jalopy.setTestSourceDirectory( new File( baseDir, "target/test-classes/input/test" ) ); + + jalopy.setTestExcludesPattern( "" ); + + jalopy.setTestIncludesPattern( "*.java" ); + + jalopy.setHistoryPolicy( "none" ); + + jalopy.setInspect( false ); + + jalopy.setForce( false ); + + jalopy.setBackup( false ); + + try + { + jalopy.execute(); + + assertFalse( compareTextFiles( new File( baseDir, "target/test-classes/input/test/Circle.java" ), + new File( baseDir, "target/test-classes/input-bak/Circle.java" ) ) ); + + assertFalse( compareTextFiles( new File( baseDir, "target/test-classes/input/src/Rectangle.java" ), + new File( baseDir, "target/test-classes/input-bak/Rectangle.java" ) ) ); + + assertFalse( compareTextFiles( new File( baseDir, "target/test-classes/input/test/Point.java" ), + new File( baseDir, "target/test-classes/input-bak/Point.java" ) ) ); + + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/src/Point.java" ), + new File( baseDir, "target/test-classes/input-bak/Point.java" ) ) ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + + /** Test source input files. + * @throws IOException IOException + */ + public void testIfSourceInputFilesWasFormatted() + throws IOException + { + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/src/Rectangle.java" ), + new File( baseDir, "target/test-classes/validator/Rectangle.java" ) ) ); + } + + /** Test excludes pattern. + * @throws IOException IOException + */ + public void testIfExcludedFilesNotFormatted() + throws IOException + { + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/src/Point.java" ), + new File( baseDir, "target/test-classes/input-bak/Point.java" ) ) ); + } + + /** Test that all source input files are formatted. + * @throws IOException IOException + */ + public void testIfTestInputFilesAllFormatted() + throws IOException + { + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/test/Circle.java" ), + new File( baseDir, "target/test-classes/validator/Circle.java" ) ) ); + + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/test/Point.java" ), + new File( baseDir, "target/test-classes/validator/Point.java" ) ) ); + + assertTrue( compareTextFiles( new File( baseDir, "target/test-classes/input/test/Rectangle.java" ), + new File( baseDir, "target/test-classes/validator/Rectangle.java" ) ) ); + + } + + /** Test fileFormat. */ + public void testSetGetFileFormat() + { + jalopy.setFileFormat( "fileFormat" ); + + assertEquals( "fileFormat", jalopy.getFileFormat() ); + } + + /** Test FailOnError. */ + public void testSetIsFailOnError() + { + jalopy.setFailOnError( true ); + + assertEquals( true, jalopy.isFailOnError() ); + } + + /** Test SourceDirectory. */ + public void testSetGetSourceDirectory() + { + jalopy.setSourceDirectory( new File( "src/test" ) ); + + assertEquals( new File( "src/test" ), jalopy.getSourceDirectory() ); + } + + /** Test SrcIncludesPattern. */ + public void testSetGetSrcIncludesPattern() + { + jalopy.setSrcIncludesPattern( "**.*" ); + + assertEquals( "**.*", jalopy.getSrcIncludesPattern() ); + } + + /** Test SrcExcludesPattern. */ + public void testSetGetSrcExcludesPattern() + { + jalopy.setSrcExcludesPattern( "**.pro" ); + + assertEquals( "**.pro", jalopy.getSrcExcludesPattern() ); + } + + /** Test HistoryPolicy. */ + public void testSetGetHistory() + { + jalopy.setHistoryPolicy( "history" ); + + assertEquals( "history", jalopy.getHistoryPolicy() ); + } + + /** + * Compares two text files for equality. + * + * @param f1 The first file + * @param f2 The second file + * @return True if the files are equal + * @throws FileNotFoundException FileNotFoundException + * @throws IOException IOException + */ + private boolean compareTextFiles( File f1, File f2 ) + throws FileNotFoundException, IOException + { + String text1 = getTextContents( f1 ); + + String text2 = getTextContents( f2 ); + + StringTokenizer tokenizer1 = new StringTokenizer( text1, "\n" ); + + StringTokenizer tokenizer2 = new StringTokenizer( text2, "\n" ); + + if ( tokenizer1.countTokens() != tokenizer2.countTokens() ) + { + return false; + } + + while ( tokenizer1.hasMoreTokens() ) + { + if ( !tokenizer1.nextToken().equalsIgnoreCase( tokenizer2.nextToken() ) ) + { + return false; + } + } + + return true; + } + + /** + * Returns the text content of a file. + * + * @param f The file + * @return The file as a String + * @throws FileNotFoundException FileNotFoundException + * @throws IOException IOException + */ + private String getTextContents( File f ) + throws FileNotFoundException, IOException + { + FileInputStream fIn = new FileInputStream( f ); + + byte[] fBytes = new byte[fIn.available()]; + + fIn.read( fBytes ); + + fIn.close(); + + return new String( fBytes ); + } + + /** Make a copy of input files so they can be compared several times. + * @throws IOException IOException + */ + private void recopyInputFiles() + throws IOException + { + FileUtils.copyDirectory( new File( baseDir, "src/test/resources/input-bak/" ), + new File( baseDir, "target/test-classes/input/src" ) ); + + FileUtils.copyDirectory( new File( baseDir, "src/test/resources/input-bak/" ), + new File( baseDir, "target/test-classes/input/test" ) ); + } + +} diff --git a/jalopy/src/test/java/org/apache/maven/jalopy/package.html b/jalopy/src/test/java/org/apache/maven/jalopy/package.html new file mode 100644 index 00000000..539bf42e --- /dev/null +++ b/jalopy/src/test/java/org/apache/maven/jalopy/package.html @@ -0,0 +1,11 @@ + + + + org.apache.maven.jalopy + + +

+ Test classes for org.apache.maven.jalopy. +

+ + diff --git a/jalopy/src/test/resources/input-bak/Circle.java b/jalopy/src/test/resources/input-bak/Circle.java new file mode 100644 index 00000000..d91e081f --- /dev/null +++ b/jalopy/src/test/resources/input-bak/Circle.java @@ -0,0 +1,32 @@ +package com.shape; + +import java.io.File; +import java.lang.Math; + +public class Circle extends Point +{ + public final float PI = 3.1415926535897932385f; + public float Circumference; public int Diameter; + private int Radius; + + public float getCircumference( ) { + Circumference = 2 * ( Radius * PI ); + + return Circumference; } + + public int getDiameter( ) { + Diameter = Radius * 2; + + return Diameter; } + + public void setRadius( int intRadius ) + { + this.Radius = intRadius; } + + public int getRadius( ) + { return this.Radius; + } + + public static void main( String[] args ) { + System.out.println( "Main Program for Junit Sample triggered!" ); } +} diff --git a/jalopy/src/test/resources/input-bak/Point.java b/jalopy/src/test/resources/input-bak/Point.java new file mode 100644 index 00000000..256d39c0 --- /dev/null +++ b/jalopy/src/test/resources/input-bak/Point.java @@ -0,0 +1,24 @@ +package com.shape; + + +public class Point +{ + private int x; + private int y; + public void setX( int xValue ) + { + x = xValue; + } + public int getX( ) { + return this.x; + } + + public void setY( int yValue ) { + y = yValue; + } + + + public int getY( ) { + return this.y; + } +} diff --git a/jalopy/src/test/resources/input-bak/Rectangle.java b/jalopy/src/test/resources/input-bak/Rectangle.java new file mode 100644 index 00000000..4ec35549 --- /dev/null +++ b/jalopy/src/test/resources/input-bak/Rectangle.java @@ -0,0 +1,53 @@ + +package com.shape; + + +public class Rectangle +{ + private float Hypotenuse; + private int Area; + private int Height; + private int Perimeter; + private int Width; + + + public int getArea( ) + { + this.Area = this.Width * this.Height; return this.Area; } + + + public void setHeight( int height ) + { + Height = height; } + + + public int getHeight( ) { + return this.Height; + } + + + public float getHypotenuse( ) { + this.Hypotenuse = (float) Math.sqrt( Math.pow( this.Height, 2.0 ) + Math.pow( this.Width, 2.0 ) ); + + return this.Hypotenuse; + } + + + public int getPerimeter( ) + { + this.Perimeter = ( 2 * this.Width ) + ( 2 * this.Height ); + + return this.Perimeter; } + + public void setWidth( int width ) { + Width = width; } + + public int getWidth( ) { + return this.Width; + } + public void setWidthHeight( int width, int height ) + { + setWidth( width ); + setHeight( height ); + } +} diff --git a/jalopy/src/test/resources/jalopy.xml b/jalopy/src/test/resources/jalopy.xml new file mode 100644 index 00000000..fbadb142 --- /dev/null +++ b/jalopy/src/test/resources/jalopy.xml @@ -0,0 +1,385 @@ + + + + + 13 + + + + + false + + + [A-Z][a-zA-Z0-9]+ + [A-Z][a-zA-Z0-9]+ + + + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-zA-Z][\w]+ + + [A-Z][a-zA-Z0-9]+ + \w+ + + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + [a-z][\w]+ + + [a-z]+(?:\.[a-z]+)* + + [a-z][\w]+ + [a-z][\w]+ + + [a-z][\w]* + + + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + false + + + + 6 + + + + 30000 + 30000 + 30000 + 30000 + 30000 + 30000 + + true + + + 2 + + + + true + false + true + false + false + + + bak + 0 + + + + 1 + 0 + 1 + 0 +
1
+
0
+ 1 + 1 + 1 + 1 +
+ + 1 + 0 + 1 + + 1 + 1 + 1 + + 1 + 1 +
0
+
2
+
+ 1 +
+ + + false + false + + + true + true + true + true + + + true + false + false + false + false + + + true + true + + + + true + true + + + + false + + + + false + false + true + + false + + 0 + 0 + 0 + 0 + + false + + + + + + /**| * DOCUMENT ME!| *| * @author $author$| * @version $Revision: 120 $| */ + + */ + * @throws $exceptionType$ DOCUMENT ME! + * @param $paramType$ DOCUMENT ME! + /**| * Creates a new $objectType$ object. + + /**| * DOCUMENT ME!| *| * @author $author$| * @version $Revision: 120 $| */ + + */ + * @throws $exceptionType$ DOCUMENT ME! + * @param $paramType$ DOCUMENT ME! + * @return DOCUMENT ME! + /**| * DOCUMENT ME! + + + + + false + false + false + + + - + false + false + + Inner Classes + Constructors + Instance fields + Instance initializers + Inner Interfaces + Methods + Static fields/initializers + + + + +
+ + 0 + false +
+
+ Tha Apache Software License + 5 + /*| * 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.| */ + false +
+ + disabled + + + + 3 + *:0|gnu:2|java:1|javax:1 + + disabled + true + + + true + + true + false + + false + + + true + + + 1 + 0 + 0 + 1 + 4 + 55 + -1 + 4 + -1 + 0 + 8 + -1 + 1 + + + false + false + + + + false + false + true + false + true + false + + + + false + false + false + false + false + static|field|initializer|constructor|method|interface|class + false + + + false + public|protected|private|abstract|static|final|synchronized|transient|volatile|native|strictfp + + + + + true + true + true + + + true + false + false + false + + true + + + false + false + true + + + + true + false + + true + true + true + true + true + true + + true + false + + + + + + 0 + false + false + false + + false + + false + false + + false + + + true + true + true + true + + + false + true + false + + + + false + true + 120 + + + + true + false + true + + true + true + true + + + + false + + true + + +
+
+ diff --git a/jalopy/src/test/resources/validator/Circle.java b/jalopy/src/test/resources/validator/Circle.java new file mode 100644 index 00000000..2afcd188 --- /dev/null +++ b/jalopy/src/test/resources/validator/Circle.java @@ -0,0 +1,42 @@ +package com.shape; + +import java.io.File; +import java.lang.Math; + +public class Circle + extends Point +{ + public final float PI = 3.1415926535897932385f; + public float Circumference; + public int Diameter; + private int Radius; + + public float getCircumference( ) + { + Circumference = 2 * ( Radius * PI ); + + return Circumference; + } + + public int getDiameter( ) + { + Diameter = Radius * 2; + + return Diameter; + } + + public void setRadius( int intRadius ) + { + this.Radius = intRadius; + } + + public int getRadius( ) + { + return this.Radius; + } + + public static void main( String[] args ) + { + System.out.println( "Main Program for Junit Sample triggered!" ); + } +} diff --git a/jalopy/src/test/resources/validator/Point.java b/jalopy/src/test/resources/validator/Point.java new file mode 100644 index 00000000..392a6e6e --- /dev/null +++ b/jalopy/src/test/resources/validator/Point.java @@ -0,0 +1,27 @@ +package com.shape; + +public class Point +{ + private int x; + private int y; + + public void setX( int xValue ) + { + x = xValue; + } + + public int getX( ) + { + return this.x; + } + + public void setY( int yValue ) + { + y = yValue; + } + + public int getY( ) + { + return this.y; + } +} diff --git a/jalopy/src/test/resources/validator/Rectangle.java b/jalopy/src/test/resources/validator/Rectangle.java new file mode 100644 index 00000000..7595eee7 --- /dev/null +++ b/jalopy/src/test/resources/validator/Rectangle.java @@ -0,0 +1,57 @@ +package com.shape; + +public class Rectangle +{ + private float Hypotenuse; + private int Area; + private int Height; + private int Perimeter; + private int Width; + + public int getArea( ) + { + this.Area = this.Width * this.Height; + + return this.Area; + } + + public void setHeight( int height ) + { + Height = height; + } + + public int getHeight( ) + { + return this.Height; + } + + public float getHypotenuse( ) + { + this.Hypotenuse = (float) Math.sqrt( Math.pow( this.Height, 2.0 ) + Math.pow( this.Width, 2.0 ) ); + + return this.Hypotenuse; + } + + public int getPerimeter( ) + { + this.Perimeter = ( 2 * this.Width ) + ( 2 * this.Height ); + + return this.Perimeter; + } + + public void setWidth( int width ) + { + Width = width; + } + + public int getWidth( ) + { + return this.Width; + } + + public void setWidthHeight( int width, int height ) + { + setWidth( width ); + setHeight( height ); + } +} diff --git a/jalopy/xdocs/changes.xml b/jalopy/xdocs/changes.xml index f17e4d20..28449f11 100644 --- a/jalopy/xdocs/changes.xml +++ b/jalopy/xdocs/changes.xml @@ -24,6 +24,8 @@ + Rewrite the plugin so it doesn't use the jalopy ant task anymore. + New properties maven.jalopy.inspect, maven.jalopy.backup and maven.jalopy.force. Removed properties maven.jalopy.logLevel and maven.jalopy.nbThread. Upgrade to log4j 1.2.13. Jalopy classes aren't found. Replace the deprecated xmlParserAPIs by xml-apis 1.3.03. diff --git a/jalopy/xdocs/properties.xml b/jalopy/xdocs/properties.xml index 8c207ef1..9eff5286 100644 --- a/jalopy/xdocs/properties.xml +++ b/jalopy/xdocs/properties.xml @@ -57,23 +57,6 @@ "FILE" or "NONE" can be used. Defaults to "none". - - maven.jalopy.logLevel - Yes - - Specifies the logging level for message output. Either one of - "ERROR", "WARN", "INFO" or "DEBUG" can be used. - Defaults to "info". - - - - maven.jalopy.nbThread - Yes - - Specifies the number of processing threads to use. Integer between 1 - 8. - Defaults to "2". - - maven.jalopy.failOnError Yes @@ -81,6 +64,30 @@ Indicates whether a run should be held if errors occured. Defaults to "true". + + maven.jalopy.inspect + Yes + + Indicates whether source files should be inspected during a format. + Defaults to "false". + + + + maven.jalopy.backup + Yes + + Indicates whether to keep backup copies of formatted files. + Defaults to "false". + + + + maven.jalopy.force + Yes + + Indicates whether to force the formatting. + Defaults to "false". + + maven.jalopy.filesetInclude Yes