You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2008/12/20 17:48:08 UTC
svn commit: r728296 - in /incubator/click/trunk/tools/standalone: ./
dev-tasks/src/org/ dev-tasks/src/org/apache/
dev-tasks/src/org/apache/click/ dev-tasks/src/org/apache/click/tools/
dev-tasks/src/org/apache/click/tools/devtasks/
Author: sabob
Date: Sat Dec 20 08:48:07 2008
New Revision: 728296
URL: http://svn.apache.org/viewvc?rev=728296&view=rev
Log:
Useful Ant tasks for Click build time
Added:
incubator/click/trunk/tools/standalone/LICENSE.txt
incubator/click/trunk/tools/standalone/NOTICE.txt
incubator/click/trunk/tools/standalone/dev-tasks/src/org/
incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/
incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/
incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/
incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/
incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/LineTrimTask.java
incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/MakeTestCaseTask.java
incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/ReplaceTabsTask.java
Modified:
incubator/click/trunk/tools/standalone/build.xml
Added: incubator/click/trunk/tools/standalone/LICENSE.txt
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/standalone/LICENSE.txt?rev=728296&view=auto
==============================================================================
--- incubator/click/trunk/tools/standalone/LICENSE.txt (added)
+++ incubator/click/trunk/tools/standalone/LICENSE.txt Sat Dec 20 08:48:07 2008
@@ -0,0 +1,176 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
\ No newline at end of file
Added: incubator/click/trunk/tools/standalone/NOTICE.txt
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/standalone/NOTICE.txt?rev=728296&view=auto
==============================================================================
--- incubator/click/trunk/tools/standalone/NOTICE.txt (added)
+++ incubator/click/trunk/tools/standalone/NOTICE.txt Sat Dec 20 08:48:07 2008
@@ -0,0 +1,5 @@
+Apache Click
+Copyright 2008 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
Modified: incubator/click/trunk/tools/standalone/build.xml
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/standalone/build.xml?rev=728296&r1=728295&r2=728296&view=diff
==============================================================================
--- incubator/click/trunk/tools/standalone/build.xml (original)
+++ incubator/click/trunk/tools/standalone/build.xml Sat Dec 20 08:48:07 2008
@@ -1,36 +1,29 @@
<project name="Standalone Tools for Click" default="help" basedir=".">
<!--
- Project Properties
+ Project Properties
-->
- <property file="./../../click/build/build.properties"/>
- <property name="jar.original" value="click-${version}.jar"/>
+ <property name="version" value="1.0"/>
<!--
- Macro Definitions
- -->
- <macrodef name="digestMacro">
- <attribute name="file"/>
- <sequential>
- <checksum file="@{file}" forceOverwrite="true" />
- <checksum file="@{file}" forceOverwrite="true" algorithm="SHA1" />
- </sequential>
- </macrodef>
- <!--
Path Definitions
-->
<path id="classpath.dev-tasks">
- <pathelement location="build/${jar.original}"/>
- </path>
-
- <path id="classpath.examples">
- <pathelement location="build/${jar.original}"/>
</path>
<!--
- Target Definitions
+ Target Definitions
-->
- <target name="build-dev-tasks" description="build the dev-tasks">
+ <target name="build" description="build the dev-tasks" depends="clean, init">
+
+ <copy todir="dev-tasks/classes">
+ <fileset dir="dev-tasks/src">
+ <exclude name="**/package.html"/>
+ </fileset>
+ </copy>
+ <copy file="LICENSE.txt" todir="dev-tasks/classes/META-INF"/>
+ <copy file="NOTICE.txt" todir="dev-tasks/classes/META-INF"/>
+
<!-- 1. Compile the tasks -->
<javac srcdir="dev-tasks/src"
destdir="dev-tasks/classes"
@@ -38,7 +31,7 @@
excludes="**/Test*"
encoding="ISO-8859-1"
source="1.4">
- <classpath refid="classpath.dev-tasks"/>
+ <classpath refid="classpath.dev-tasks"/>
</javac>
<!-- 2. package the tasks into a JAR -->
@@ -48,75 +41,38 @@
<jar destfile="dist/click-dev-tasks-${version}.jar">
<manifest>
- <attribute name="Click-Version" value="${version}"/>
- <attribute name="Package" value="net.sf.click.tools.devtasks"/>
- <attribute name="Built-By" value="${user.name}"/>
+ <attribute name="Click-Version" value="${version}"/>
+ <attribute name="Package" value="org.apache.click.tools.devtasks"/>
+ <attribute name="Built-By" value="${user.name}"/>
</manifest>
<fileset dir="dev-tasks/classes"/>
</jar>
- <digestMacro file="dist/click-dev-tasks-${version}.jar"/>
- </target>
-
- <target name="build-examples" depends="build-dev-tasks" description="build examples">
- <fail message="This task is not implemented yet!"/>
- </target>
-
- <target name="build-all" depends="build-dev-tasks"
- description="build all tools, and examples"/>
-
- <target name="build-distribution" description="build distribution ZIP file">
- <fail message="This task is not implemented yet!"/>
</target>
- <target name="build-sources" description="build source ZIP files for use with IDEs">
- <!-- zip the dev tasks without the dependencies -->
- <zip destfile="dist/click-dev-tasks-${version}-src.zip">
- <fileset dir="dev-tasks/src">
- <exclude name="**/*.html"/>
- </fileset>
- </zip>
-
- </target>
-
<target name="init" depends="clean">
<!-- 1. copy the Original JAR from the original dist directory -->
<mkdir dir="dist"/>
- <mkdir dir="build"/>
- <available file="./../../click/dist/${jar.original}" property="isJarAvail"/>
- <fail message="Ensure that you have build Click first (to be able here to copy the core jar)!">
- <condition>
- <or><isfalse value="${isJarAvail}"/></or>
- </condition>
- </fail>
- <copy file="./../../click/dist/${jar.original}" todir="build"/>
-
<!-- 2. Cleanup the old classes -->
- <delete dir="dev-tasks/classes" quiet="false"/>
<mkdir dir="dev-tasks/classes"/>
</target>
-
- <target name="clean">
- <delete dir="dist" quiet="false"/>
- <delete dir="build" quiet="false"/>
- </target>
-
- <target name="get-deps" description="download JAR dependencies">
- <fail message="This task is not implemented yet!"/>
- </target>
-
- <target name="help" description="display the Help message">
- <echo>Standalone Tools for Click ${version} web application framework
+
+ <target name="clean">
+ <delete dir="dist" quiet="false"/>
+ <delete dir="dev-tasks/classes" quiet="false"/>
+ </target>
+
+ <target name="get-deps" description="download JAR dependencies">
+ <fail message="This task is not implemented yet!"/>
+ </target>
+
+ <target name="help" description="display the Help message">
+ <echo>Standalone Tools for Click ${version} web application framework
==============================================================
Main targets:
- build-all build all tools, and examples
- build-distribution build distribution ZIP file
- build-dev-tasks build the dev-tasks
- build-examples build examples
- build-sources build source ZIP files for use with IDEs
-
- get-deps download JAR dependencies
+ build build the dev-tasks
+ get-deps download JAR dependencies
help display the Help message
Environment:
@@ -124,6 +80,7 @@
java.home = ${java.home}
ant.home = ${ant.home}
-Please ensure you have configured build.properties</echo>
- </target>
+Please ensure you have configured build.properties
+ </echo>
+ </target>
</project>
Added: incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/LineTrimTask.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/LineTrimTask.java?rev=728296&view=auto
==============================================================================
--- incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/LineTrimTask.java (added)
+++ incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/LineTrimTask.java Sat Dec 20 08:48:07 2008
@@ -0,0 +1,115 @@
+package org.apache.click.tools.devtasks;
+
+import java.io.*;
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.types.FileSet;
+
+public class LineTrimTask extends Task {
+
+ private File mSrcDir;
+ protected FileSet mFileSet;
+
+ public LineTrimTask() {
+ mFileSet = new FileSet();
+ }
+
+ public void setSrcdir(File aSrcDir) {
+ mSrcDir = aSrcDir;
+ }
+
+ public void setExcludes(String aExcludes) {
+ mFileSet.setExcludes(aExcludes);
+ }
+
+ public void setIncludes(String aIncludes) {
+ mFileSet.setIncludes(aIncludes);
+ }
+
+ public void execute() throws BuildException {
+ if(mSrcDir == null)
+ throw new BuildException("srcdir attribute must be set!");
+ if(!mSrcDir.exists())
+ throw new BuildException("srcdir does not exist!");
+ if(!mSrcDir.isDirectory())
+ throw new BuildException("srcdir is not a directory!");
+ mFileSet.setDir(mSrcDir);
+ mFileSet.setDefaultexcludes(true);
+ DirectoryScanner lDirectoryScanner = mFileSet.getDirectoryScanner(this.project);
+ String lFilesArray[] = lDirectoryScanner.getIncludedFiles();
+ for(int i = 0; i < lFilesArray.length; i++)
+ processFile(lFilesArray[i]);
+
+ }
+
+ private void processFile(String aFilename) throws BuildException {
+ String lSrcFilename = mSrcDir.getAbsolutePath() + File.separatorChar + aFilename;
+ String lDstFilename = lSrcFilename + ".tmp";
+ BufferedReader lReader = null;
+ PrintWriter lWriter = null;
+ try {
+ lReader = new BufferedReader(new FileReader(lSrcFilename));
+ lWriter = new PrintWriter(new BufferedWriter(new FileWriter(lDstFilename)));
+ boolean lHadToTrim = false;
+ for(String lLine = lReader.readLine(); lLine != null; lLine = lReader.readLine()) {
+ String lTrimmed = getTrimmedLine(lLine);
+ if(lTrimmed != lLine)
+ lHadToTrim = true;
+ lWriter.println(lTrimmed);
+ }
+
+ lReader.close();
+ lWriter.close();
+ File lSrcFile = new File(lSrcFilename);
+ File lDstFile = new File(lDstFilename);
+ if(lHadToTrim) {
+ if(lSrcFile.canWrite()) {
+ lSrcFile.delete();
+ if(lDstFile.renameTo(lSrcFile))
+ System.out.println("Trimmed: " + aFilename);
+ else
+ System.err.println("Could not trim: " + aFilename);
+ } else {
+ System.err.println("Could not trim: " + aFilename);
+ }
+ } else {
+ lDstFile.delete();
+ }
+ }
+ catch(IOException ioe) {
+ throw new BuildException(ioe.getClass().getName() + ":" + ioe.getMessage());
+ }
+ finally {
+ if(lReader != null)
+ try {
+ lReader.close();
+ }
+ catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+ }
+
+ private String getTrimmedLine(String aLine) {
+ int lLength = aLine.length();
+ int lLastCharIndex = 0;
+ for(int i = lLength - 1; i >= 0; i--) {
+ if(Character.isWhitespace(aLine.charAt(i)))
+ continue;
+ lLastCharIndex = i;
+ break;
+ }
+
+ if(lLength > 0) {
+ if(lLastCharIndex != lLength - 1) {
+ if(!Character.isWhitespace(aLine.charAt(lLastCharIndex)))
+ return aLine.substring(0, lLastCharIndex + 1);
+ else
+ return "";
+ } else {
+ return aLine;
+ }
+ } else {
+ return aLine;
+ }
+ }
+}
Added: incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/MakeTestCaseTask.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/MakeTestCaseTask.java?rev=728296&view=auto
==============================================================================
--- incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/MakeTestCaseTask.java (added)
+++ incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/MakeTestCaseTask.java Sat Dec 20 08:48:07 2008
@@ -0,0 +1,239 @@
+package org.apache.click.tools.devtasks;
+
+import java.io.*;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.text.DateFormat;
+import java.util.Date;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+public class MakeTestCaseTask extends Task {
+
+ private String IND;
+ private String mIndentWidth;
+ private File mSrcDir;
+ private String mClassname;
+
+ public MakeTestCaseTask() {
+ IND = "";
+ mIndentWidth = "4";
+ }
+
+ public void setIndentWidth(String aIndentWidth) {
+ mIndentWidth = aIndentWidth;
+ }
+
+ public void setSrcdir(File aSrcDir) {
+ mSrcDir = aSrcDir;
+ }
+
+ public void setClassname(String aClassname) {
+ mClassname = aClassname;
+ }
+
+ public void execute() throws BuildException {
+ if(mSrcDir == null)
+ throw new BuildException("srcdir attribute must be set!");
+ if(!mSrcDir.exists())
+ throw new BuildException("srcdir does not exist!");
+ if(!mSrcDir.isDirectory())
+ throw new BuildException("srcdir is not a directory!");
+ if(mClassname == null || mClassname.equals("${classname}"))
+ throw new BuildException("classname not specified");
+ try {
+ int indentWidth = Integer.parseInt(mIndentWidth);
+ if(indentWidth > 0) {
+ for(int i = 0; i < indentWidth; i++)
+ IND += " ";
+
+ } else {
+ throw new BuildException("indentwidth must be greater than 0");
+ }
+ }
+ catch(NumberFormatException nfe) {
+ throw new BuildException("indentwidth invalid: " + mIndentWidth);
+ }
+ String lPackagename = mClassname.substring(0, mClassname.lastIndexOf("."));
+ String lPackagenamePath = lPackagename.replace('.', File.separatorChar);
+ String lShortClassname = mClassname.substring(mClassname.lastIndexOf(".") + 1);
+ String lShortTestCaseClassname = "TestCase_" + lShortClassname;
+ String lFilename = mSrcDir.getAbsolutePath() + File.separatorChar + lPackagenamePath + File.separatorChar + lShortTestCaseClassname + ".java";
+ File lFile = new File(lFilename);
+ if(lFile.exists())
+ throw new BuildException("File already exists: " + lFilename);
+ try {
+ Class lClass = Class.forName(mClassname);
+ if(lClass.isInterface())
+ throw new BuildException(lShortClassname + " is an interface. A TestCase cannot be" + " created for a Java interface.");
+ java.lang.reflect.Constructor lConstructors[] = lClass.getDeclaredConstructors();
+ Method lMethods[] = lClass.getDeclaredMethods();
+ PrintWriter lOut = new PrintWriter(new BufferedWriter(new FileWriter(lFilename)));
+ lOut.println("/*");
+ lOut.println(" * " + lShortTestCaseClassname + ".java");
+ lOut.println(" *");
+ lOut.println(" * Created on " + DateFormat.getDateInstance(3).format(new Date()));
+ lOut.println(" */");
+ lOut.println();
+ lOut.println("package " + lPackagename + ";");
+ lOut.println();
+ lOut.println("import junit.framework.TestCase;");
+ lOut.println();
+ lOut.println("/**");
+ lOut.println(" * The <tt>" + lShortClassname + "</tt> class <tt>TestCase</tt>.");
+ lOut.println(" *");
+ lOut.println(" * @author " + System.getProperty("user.name"));
+ lOut.println(" */");
+ lOut.println("public class " + lShortTestCaseClassname + " extends TestCase {");
+ lOut.println();
+ lOut.println(ind(1) + "/**");
+ lOut.println(ind(1) + " * Instatiate a new <tt>" + lShortTestCaseClassname + "</tt>.");
+ lOut.println(ind(1) + " *");
+ lOut.println(ind(1) + " * @param aName the name of the test case");
+ lOut.println(ind(1) + " */");
+ lOut.println(ind(1) + "public " + lShortTestCaseClassname + "(String name) {");
+ lOut.println(ind(2) + "super(name);");
+ lOut.println(ind(1) + "}");
+ lOut.println();
+ if(lConstructors.length > 0) {
+ lOut.println(ind(1) + "/**");
+ lOut.println(ind(1) + " * Test <tt>" + lShortClassname + "</tt> " + " constructors.");
+ lOut.println(ind(1) + " */");
+ lOut.println(ind(1) + "public void test_constructors() {");
+ lOut.println(ind(2) + "// Test constructor with ...");
+ lOut.println(ind(1) + "}");
+ lOut.println();
+ }
+ String lLastMethodName = "";
+ for(int i = 0; i < lMethods.length; i++)
+ if(Modifier.isPublic(lMethods[i].getModifiers()) || Modifier.isProtected(lMethods[i].getModifiers())) {
+ String lMethodName = lMethods[i].getName();
+ if(!lMethodName.equals(lLastMethodName)) {
+ lOut.println(ind(1) + "/**");
+ lOut.println(ind(1) + " * Test <tt>" + lShortClassname + "." + lMethodName + "()</tt> method.");
+ lOut.println(ind(1) + " */");
+ lOut.println(ind(1) + "public void test_" + lMethodName + "() {");
+ lOut.println(ind(2) + "try {");
+ lOut.println(ind(3) + "// " + lShortClassname + "." + lMethodName + "();");
+ lOut.println(ind(2) + "} catch (Throwable t) {");
+ lOut.println(ind(3) + "assertTrue(false);");
+ lOut.println(ind(2) + "}");
+ lOut.println(ind(1) + "}");
+ lOut.println();
+ lLastMethodName = lMethodName;
+ }
+ }
+
+ lOut.print("}");
+ lOut.close();
+ System.out.println("Created " + lShortTestCaseClassname);
+ createUpdateTestSuite(lPackagename, lShortTestCaseClassname);
+ }
+ catch(ClassNotFoundException cnfe) {
+ throw new BuildException(cnfe.getClass().getName() + ":" + cnfe.getMessage());
+ }
+ catch(IOException ioe) {
+ throw new BuildException(ioe.getClass().getName() + ":" + ioe.getMessage());
+ }
+ }
+
+ private String ind(int aTab) {
+ StringBuffer lBuffer = new StringBuffer();
+ for(int i = 0; i < aTab; i++)
+ lBuffer.append(IND);
+
+ return lBuffer.toString();
+ }
+
+ private void createUpdateTestSuite(String aPackageName, String aTestCaseName) throws IOException {
+ if(aPackageName == null)
+ throw new IllegalArgumentException("Null aPackageName parameter");
+ if(aTestCaseName == null)
+ throw new IllegalArgumentException("Null aTestCaseName parameter");
+ String lPackagenamePath = aPackageName.replace('.', File.separatorChar);
+ String lFilename = mSrcDir.getAbsolutePath() + File.separatorChar + lPackagenamePath + File.separatorChar + "TestSuite.java";
+ File lFile = new File(lFilename);
+ if(!lFile.exists()) {
+ PrintWriter lOut = new PrintWriter(new BufferedWriter(new FileWriter(lFilename)));
+ lOut.println("/*");
+ lOut.println(" * TestCase.java");
+ lOut.println(" *");
+ lOut.println(" * Created on " + DateFormat.getDateInstance(3).format(new Date()));
+ lOut.println(" */");
+ lOut.println();
+ lOut.println("package " + aPackageName + ";");
+ lOut.println();
+ lOut.println("import junit.framework.Test;");
+ lOut.println();
+ lOut.println("/**");
+ lOut.println(" * The <tt>" + aPackageName + "</tt> package ");
+ lOut.println(" * unit testing <tt>TestSuite</tt>.");
+ lOut.println(" *");
+ lOut.println(" * @author " + System.getProperty("user.name"));
+ lOut.println(" */");
+ lOut.println("public class TestSuite extends junit.framework.TestSuite {");
+ lOut.println();
+ lOut.println(ind(1) + "/**");
+ lOut.println(ind(1) + " * @see junit.framework.TestSuite#suite()");
+ lOut.println(ind(1) + " */");
+ lOut.println(ind(1) + "public static Test suite() {");
+ lOut.println(ind(2) + "TestSuite suite = new TestSuite();");
+ lOut.println(ind(2) + "suite.addTestSuite(" + aTestCaseName + ".class);");
+ lOut.println(ind(2) + "return suite;");
+ lOut.println(ind(1) + "}");
+ lOut.print("}");
+ lOut.close();
+ System.out.println("Created TestSuite");
+ } else {
+ updateTestSuiteFile(lFilename, aTestCaseName);
+ }
+ }
+
+ private void updateTestSuiteFile(String aFilename, String aTestCaseName) throws BuildException {
+ String lDstFilename = aFilename + ".tmp";
+ BufferedReader lReader = null;
+ PrintWriter lWriter = null;
+ try {
+ lReader = new BufferedReader(new FileReader(aFilename));
+ lWriter = new PrintWriter(new BufferedWriter(new FileWriter(lDstFilename)));
+ boolean lFoundTestCase = false;
+ for(String lLine = lReader.readLine(); lLine != null; lLine = lReader.readLine()) {
+ if(lLine.indexOf(aTestCaseName) != -1)
+ lFoundTestCase = true;
+ if(!lFoundTestCase && lLine.indexOf("return suite;") != -1)
+ lWriter.println(ind(2) + "suite.addTestSuite(" + aTestCaseName + ".class);");
+ lWriter.println(lLine);
+ }
+
+ lReader.close();
+ lWriter.close();
+ File lSrcFile = new File(aFilename);
+ File lDstFile = new File(lDstFilename);
+ if(!lFoundTestCase) {
+ if(lSrcFile.canWrite()) {
+ lSrcFile.delete();
+ if(lDstFile.renameTo(lSrcFile))
+ System.out.println("Updated TestSuite");
+ else
+ System.err.println("Could not update TestSuite");
+ } else {
+ System.err.println("Could not update TestSuite");
+ }
+ } else {
+ lDstFile.delete();
+ }
+ }
+ catch(IOException ioe) {
+ throw new BuildException(ioe.getClass().getName() + ":" + ioe.getMessage());
+ }
+ finally {
+ if(lReader != null)
+ try {
+ lReader.close();
+ }
+ catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+ }
+}
Added: incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/ReplaceTabsTask.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/ReplaceTabsTask.java?rev=728296&view=auto
==============================================================================
--- incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/ReplaceTabsTask.java (added)
+++ incubator/click/trunk/tools/standalone/dev-tasks/src/org/apache/click/tools/devtasks/ReplaceTabsTask.java Sat Dec 20 08:48:07 2008
@@ -0,0 +1,129 @@
+package org.apache.click.tools.devtasks;
+
+import java.io.*;
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.types.FileSet;
+
+public class ReplaceTabsTask extends Task {
+
+ private String tabReplacement;
+ private File mSrcDir;
+ private String mNumberSpaces;
+ protected FileSet mFileSet;
+
+ public ReplaceTabsTask() {
+ tabReplacement = "";
+ mNumberSpaces = "4";
+ mFileSet = new FileSet();
+ }
+
+ public void setNumberspaces(String aNumberSpaces) {
+ mNumberSpaces = aNumberSpaces;
+ }
+
+ public void setSrcdir(File aSrcDir) {
+ mSrcDir = aSrcDir;
+ }
+
+ public void setExcludes(String aExcludes) {
+ mFileSet.setExcludes(aExcludes);
+ }
+
+ public void setIncludes(String aIncludes) {
+ mFileSet.setIncludes(aIncludes);
+ }
+
+ public void execute() throws BuildException {
+ if(mSrcDir == null)
+ throw new BuildException("srcdir attribute must be set!");
+ if(!mSrcDir.exists())
+ throw new BuildException("srcdir does not exist!");
+ if(!mSrcDir.isDirectory())
+ throw new BuildException("srcdir is not a directory!");
+ try {
+ int numberSpaces = Integer.parseInt(mNumberSpaces);
+ if(numberSpaces > 0) {
+ for(int i = 0; i < numberSpaces; i++)
+ tabReplacement += " ";
+
+ } else {
+ throw new BuildException("numberspaces must be greater than 0");
+ }
+ }
+ catch(NumberFormatException nfe) {
+ throw new BuildException("numberspaces invalid: " + mNumberSpaces);
+ }
+ mFileSet.setDir(mSrcDir);
+ mFileSet.setDefaultexcludes(true);
+ DirectoryScanner lDirectoryScanner = mFileSet.getDirectoryScanner(this.project);
+ String lFilesArray[] = lDirectoryScanner.getIncludedFiles();
+ for(int i = 0; i < lFilesArray.length; i++)
+ processFile(lFilesArray[i]);
+
+ }
+
+ private void processFile(String aFilename) throws BuildException {
+ String lSrcFilename = mSrcDir.getAbsolutePath() + File.separatorChar + aFilename;
+ String lDstFilename = lSrcFilename + ".tmp";
+ BufferedReader lReader = null;
+ PrintWriter lWriter = null;
+ try {
+ lReader = new BufferedReader(new FileReader(lSrcFilename));
+ lWriter = new PrintWriter(new BufferedWriter(new FileWriter(lDstFilename)));
+ boolean lHadToTrim = false;
+ for(String lLine = lReader.readLine(); lLine != null; lLine = lReader.readLine()) {
+ String lTrimmed = getTabReplacedLine(lLine);
+ if(lTrimmed != lLine)
+ lHadToTrim = true;
+ lWriter.println(lTrimmed);
+ }
+
+ lReader.close();
+ lWriter.close();
+ File lSrcFile = new File(lSrcFilename);
+ File lDstFile = new File(lDstFilename);
+ if(lHadToTrim) {
+ if(lSrcFile.canWrite()) {
+ lSrcFile.delete();
+ if(lDstFile.renameTo(lSrcFile))
+ System.out.println("Tab replaced: " + aFilename);
+ else
+ System.err.println("Could not tab replace: " + aFilename);
+ } else {
+ System.err.println("Could not tab replace: " + aFilename);
+ }
+ } else {
+ lDstFile.delete();
+ }
+ }
+ catch(IOException ioe) {
+ throw new BuildException(ioe.getClass().getName() + ":" + ioe.getMessage());
+ }
+ finally {
+ if(lReader != null)
+ try {
+ lReader.close();
+ }
+ catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+ }
+
+ private String getTabReplacedLine(String aLine) {
+ if(aLine.indexOf('\t') == -1)
+ return aLine;
+ StringBuffer buffer = new StringBuffer(aLine.length());
+ char aChar = '0';
+ int i = 0;
+ for(int size = aLine.length(); i < size; i++) {
+ aChar = aLine.charAt(i);
+ if(aChar == '\t')
+ buffer.append(tabReplacement);
+ else
+ buffer.append(aChar);
+ }
+
+ return buffer.toString();
+ }
+}