Initial revision

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jvanzyl committed 2003-01-24 03:44:26 +00:00
1 parent 66e44f2734
commit 530c640d4f
821 files changed
+55754

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
target
maven.log
velocity.log
+35
View File
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<project
xmlns:j="jelly:core"
xmlns:d="jelly:define"
xmlns:codeswitcher="codeswitcher">
<!-- ================================================================== -->
<!-- C O D E S W I T C H E R -->
<!-- ================================================================== -->
<goal
name="codeswitcher:init"
description="Validate the Maven XML project descriptor">
<d:taglib uri="codeswitcher">
<d:jellybean
name="codeswitcher"
className="org.apache.maven.codeswitcher.CodeSwitcher"
method="execute"
/>
<d:tag name="process">
<codeswitcher:codeswitcher
onSwitches="${onSwitches}"
offSwitches="${offSwitches}"
directory="${directory}"
/>
</d:tag>
</d:taglib>
</goal>
</project>
+5
View File
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------
# P L U G I N P R O P E R I E S
# -------------------------------------------------------------------
# POM plugin.
# -------------------------------------------------------------------
+5
View File
@@ -0,0 +1,5 @@
# -------------------------------------------------------------------
# P R O J E C T P R O P E R T I E S
# -------------------------------------------------------------------
maven.xdoc.version=${pom.currentVersion}
maven.xdoc.date=left
+66
View File
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<extend>${basedir}/../project.xml</extend>
<pomVersion>3</pomVersion>
<id>maven-codeswitcher-plugin</id>
<name>Maven CodeSwitcher Plugin</name>
<currentVersion>1.0</currentVersion>
<description>
</description>
<shortDescription>Java Project Management Tools</shortDescription>
<url>http://jakarta.apache.org/turbine/maven/reference/plugins/codeswitcher/</url>
<issueTrackingUrl>http://jira.werken.com/BrowseProject.jspa?id=10030</issueTrackingUrl>
<siteAddress>jakarta.apache.org</siteAddress>
<siteDirectory>/www/jakarta.apache.org/turbine/maven/reference/plugins/codeswitcher/</siteDirectory>
<distributionDirectory>/www/jakarta.apache.org/builds/jakarta-turbine-maven/</distributionDirectory>
<developers>
<developer>
<name>dIon Gillard</name>
<id>dion</id>
<email>dion@multitask.com.au</email>
<organization>Multitask Consulting</organization>
<roles>
<role>Documentation</role>
</roles>
</developer>
<developer>
<name>Jason van Zyl</name>
<id>jvanzyl</id>
<email>jason@zenplex.com</email>
<organization>Zenplex</organization>
<roles>
<role>Architect</role>
<role>Release Manager</role>
</roles>
</developer>
</developers>
<dependencies>
<dependency>
<id>ant</id>
<version>1.5.1</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency>
<dependency>
<id>commons-lang</id>
<version>1.0-b1.1</version>
<properties>
<classloader>root.maven</classloader>
</properties>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,541 @@
/* Copyrights and Licenses
*
* This product includes Hypersonic SQL.
* Originally developed by Thomas Mueller and the Hypersonic SQL Group.
*
* Copyright (c) 1995-2000 by the Hypersonic SQL Group. All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* - All advertising materials mentioning features or use of this software must display the
* following acknowledgment: "This product includes Hypersonic SQL."
* - Products derived from this software may not be called "Hypersonic SQL" nor may
* "Hypersonic SQL" appear in their names without prior written permission of the
* Hypersonic SQL Group.
* - Redistributions of any form whatsoever must retain the following acknowledgment: "This
* product includes Hypersonic SQL."
* This software is provided "as is" and any expressed or implied warranties, including, but
* not limited to, the implied warranties of merchantability and fitness for a particular purpose are
* disclaimed. In no event shall the Hypersonic SQL Group or its contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential damages (including, but
* not limited to, procurement of substitute goods or services; loss of use, data, or profits;
* or business interruption). However caused any on any theory of liability, whether in contract,
* strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
* software, even if advised of the possibility of such damage.
* This software consists of voluntary contributions made by many individuals on behalf of the
* Hypersonic SQL Group.
*
*
* For work added by the HSQL Development Group:
*
* Copyright (c) 2001-2002, The HSQL Development Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer, including earlier
* license statements (above) and comply with all above license conditions.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution, including earlier
* license statements (above) and comply with all above license conditions.
*
* Neither the name of the HSQL Development Group nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.apache.maven.codeswitcher;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import org.apache.commons.lang.StringUtils;
import org.apache.tools.ant.DirectoryScanner;
/**
* changes the source code to support different JDK or profile settings
*
* @version 1.7.0
*/
public class CodeSwitcher
{
private final static String ls = System.getProperty("line.separator", "\n");
private List onSwitches;
private List offSwitches;
private List switches;
private final static int MAX_LINELENGTH = 82;
private String[] files;
/**
* Constructor declaration
*/
public CodeSwitcher()
{
onSwitches = new ArrayList();
offSwitches = new ArrayList();
switches = new ArrayList();
}
/**
* Method declaration
*
* @param a
*/
public void execute()
{
System.out.println("On Switches");
System.out.println(onSwitches);
System.out.println("Off Switches");
System.out.println(offSwitches);
process();
}
/**
* Set the on switches
*/
public void setOnSwitches(String onSwitchesCSV)
{
String[] onSwitchesArray = StringUtils.split(onSwitchesCSV, ",");
for (int i = 0; i < onSwitchesArray.length; i++)
{
onSwitches.add(onSwitchesArray[i]);
}
}
/**
* Set the off switches
*/
public void setOffSwitches(String offSwitchesCSV)
{
String[] offSwitchesArray = StringUtils.split(offSwitchesCSV, ",");
for (int i = 0; i < offSwitchesArray.length; i++)
{
offSwitches.add(offSwitchesArray[i]);
}
}
/**
* Set the directory of sources to preprocess
*/
public void setDirectory(String directory)
{
// Grab all the java source files in the listed
// directory.
files = getFiles(new File(directory), "**/*.java");
}
/**
* Method declaration
*/
private void process()
{
for (int i = 0; i < files.length; i++)
{
System.out.print(".");
String file = files[i];
if (!processFile(file))
{
System.out.println("in file " + file + " !");
}
}
System.out.println("");
}
/**
* Method declaration
*
* @param s
* @return
*/
private boolean isLongline(String s)
{
char c = s.charAt(s.length() - 1);
if (",(+-&|".indexOf(c) >= 0)
{
return true;
}
return false;
}
/**
* Method declaration
*
* @param name
* @return
*/
private boolean processFile(String name)
{
File f = new File(name);
File fnew = new File(name + ".new");
int state = 0;// 0=normal 1=inside_if 2=inside_else
boolean switchoff = false;
boolean working = false;
try
{
LineNumberReader read = new LineNumberReader(new FileReader(f));
FileWriter write = new FileWriter(fnew);
while (true)
{
String line = read.readLine();
if (line == null)
{
break;
}
if (working)
{
if (line.equals("/*") || line.equals("*/"))
{
continue;
}
}
if (!line.startsWith("//#"))
{
write.write(line + ls);
}
else
{
if (line.startsWith("//#ifdef "))
{
if (state != 0)
{
printError(
"'#ifdef' not allowed inside '#ifdef'");
return false;
}
write.write(line + ls);
state = 1;
String s = line.substring(9);
if (onSwitches.indexOf(s) != -1)
{
working = true;
switchoff = false;
}
else if (offSwitches.indexOf(s) != -1)
{
working = true;
write.write("/*" + ls);
switchoff = true;
}
if (switches.indexOf(s) == -1)
{
switches.add(s);
}
}
else if (line.startsWith("//#else"))
{
if (state != 1)
{
printError("'#else' without '#ifdef'");
return false;
}
state = 2;
if (!working)
{
write.write(line + ls);
}
else if (switchoff)
{
write.write("*/" + ls);
write.write(line + ls);
switchoff = false;
}
else
{
write.write(line + ls);
write.write("/*" + ls);
switchoff = true;
}
}
else if (line.startsWith("//#endif"))
{
if (state == 0)
{
printError("'#endif' without '#ifdef'");
return false;
}
state = 0;
if (working && switchoff)
{
write.write("*/" + ls);
}
write.write(line + ls);
working = false;
}
else
{
write.write(line + ls);
}
}
}
if (state != 0)
{
printError("'#endif' missing");
return false;
}
read.close();
write.flush();
write.close();
File fbak = new File(name + ".bak");
fbak.delete();
f.renameTo(fbak);
File fcopy = new File(name);
fnew.renameTo(fcopy);
fbak.delete();
return true;
}
catch (Exception e)
{
printError(e.getMessage());
return false;
}
}
/**
* Method declaration
*
* @param name
* @return
*/
int testFile(String name)
{
File f = new File(name);
try
{
LineNumberReader read = new LineNumberReader(new FileReader(f));
int l = 1;
int
maxline = 0;
boolean longline = false;
while (true)
{
String line = read.readLine();
if (line == null)
{
break;
}
if (line.length() > MAX_LINELENGTH
&& !line.startsWith("org.hsqldb.test.Profile."))
{
System.out.println("long line in " + name + " at line "
+ l);
}
if (line.startsWith(" "))
{
int spaces = 0;
for (; spaces < line.length(); spaces++)
{
if (line.charAt(spaces) != ' ')
{
break;
}
}
if (spaces > 3 && testLine(line) && !longline)
{
maxline++;
}
else if (isLongline(line))
{
longline = true;
}
else
{
longline = false;
}
String s = line.substring(spaces);
if (s.startsWith("if("))
{
if (!s.endsWith(" {"))
{
System.out.println("if( without { in " + name
+ " at line " + l);
}
}
else if (s.startsWith("} else if("))
{
if (!s.endsWith(" {"))
{
System.out.println("} else if without { in "
+ name + " at line " + l);
}
}
else if (s.startsWith("while("))
{
if (!s.endsWith(" {"))
{
System.out.println("while( without { in " + name
+ " at line " + l);
}
}
else if (s.startsWith("switch("))
{
if (!s.endsWith(" {"))
{
System.out.println("switch( without { in " + name
+ " at line " + l);
}
}
else if (s.startsWith("do "))
{
if (!s.endsWith(" {"))
{
System.out.println("do without { in " + name
+ " at line " + l);
}
}
}
l++;
}
read.close();
return maxline;
}
catch (Exception e)
{
printError(e.getMessage());
}
return -1;
}
/**
* Method declaration
*
* @param line
* @return
*/
private boolean testLine(String line)
{
if (!line.endsWith(";"))
{
return false;
}
if (line.trim().startsWith("super("))
{
return false;
}
return true;
}
/**
* Method declaration
*
* @param error
*/
private void printError(String error)
{
System.out.println("");
System.out.println("ERROR: " + error);
}
/**
* Get a set of files from a specifed directory with a set of includes.
*
* @param directory Directory to scan
* @param includes Comma separated list of includes
* @return files
*/
public String[] getFiles(File directory, String includes)
{
String[] includePatterns = null;
if (includes != null)
{
includePatterns = StringUtils.split(includes, ",");
}
DirectoryScanner directoryScanner = new DirectoryScanner();
directoryScanner.setBasedir(directory);
directoryScanner.setIncludes(includePatterns);
directoryScanner.scan();
String[] files = directoryScanner.getIncludedFiles();
for (int i = 0; i < files.length; i++)
{
files[i] = new File(directory, files[i]).getAbsolutePath();
}
return files;
}
}
+1
View File
@@ -0,0 +1 @@
stylesheets
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<document>
<properties>
<title>Changes</title>
<author email="jason@zenplex.com">Jason van Zyl</author>
</properties>
<body>
<release version="1.0" date="2002-08-04">
<action dev="jvanzyl" type="add">
Original release for Maven 1.0-beta8
</action>
</release>
</body>
</document>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<document>
<properties>
<title>Maven CodeSwitcher Plug-in Goals</title>
<author email="jason@zenplex.com">Jason van Zyl</author>
</properties>
<body>
<goals>
<goal>
<name>codeswitcher:init</name>
<description>
Set up the code switcher tag library
</description>
</goal>
</goals>
</body>
</document>
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<document>
<properties>
<title>Maven CodeSwitcher Plug-in</title>
<author email="jason@zenplex.com">Jason van Zyl</author>
</properties>
<body>
<section name="Maven CodeSwitcher Plug-in">
<p>
A preprocessor plug-in for Maven.
</p>
</section>
</body>
</document>
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Maven CodeSwitcher Plugin">
<title>Maven CodeSwitcher Plugin</title>
<body>
<links>
<item name="Maven" href="http://jakarta.apache.org/turbine/maven/"/>
</links>
<menu name="Overview">
<item name="Goals" href="/goals.html" />
<item name="Properties" href="/properties.html" />
</menu>
</body>
</project>
+25
View File
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<properties>
<title>Maven CodeSwitcher Plugin Properties</title>
<author email="jason@zenplex.com">Jason van Zyl</author>
</properties>
<body>
<section name="Maven CodeSwitcher Plugin Settings">
<table>
<tr>
<th>Property name</th>
<th>Optional?</th>
<th>Description</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</section>
</body>
</document>