dion 2002/10/03 09:15:46
Modified: src/plugins-build/license plugin.jelly project.xml
src/plugins-build/license/src/java/org/apache/maven/license
LicenseTask.java
Log:
Refactored code for:
a) Reuse
b) Performance
Revision Changes Path
1.3 +16 -17 jakarta-turbine-maven/src/plugins-build/license/plugin.jelly
Index: plugin.jelly
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/plugins-build/license/plugin.jelly,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- plugin.jelly 24 Sep 2002 07:32:16 -0000 1.2
+++ plugin.jelly 3 Oct 2002 16:15:45 -0000 1.3
@@ -10,40 +10,39 @@
<!-- ================================================================== -->
<goal name="license"
- description="Generate a xml file from your license.txt"
- prereqs="license:transfer"/>
-
- <goal name="license:transfer"
- description="Generate a xml file from your license.txt">
-
+ description="Generate a xml file from your license.txt"
+ prereqs="license:transfer"/>
+
+ <goal name="license:init-tag">
<define:taglib uri="license">
- <define:jellybean
- name="license"
+ <define:jellybean name="license"
className="org.apache.maven.license.LicenseTask"
- method="doExecute"
- />
+ method="doExecute" />
</define:taglib>
+ </goal>
+
+ <goal name="license:transfer" prereqs="license:init-tag"
+ description="Generate a xml file from your license.txt">
<mkdir dir="${maven.gen.docs}"/>
- <j:set var="licenseX"
value='${context.getVariable("maven.license.licenseFile")}X'/>
+ <j:set var="licenseX" value='${maven.license.licenseFile}X'/>
<j:choose>
<j:when test="${licenseX != 'X'}">
- <j:set var="licenseFile"
value='${context.getVariable("maven.license.licenseFile")}'/>
+ <j:set var="licenseFile" value='${maven.license.licenseFile}'/>
</j:when>
<j:otherwise>
- <j:set var="licenseFile"
value='${context.getVariable("basedir")}/LICENSE.txt'/>
+ <j:set var="licenseFile" value='${basedir}/LICENSE.txt'/>
</j:otherwise>
</j:choose>
<license:license
- projectDescriptor="project.xml"
+ description="Project License"
+ input="${licenseFile}"
output="${maven.gen.docs}/license.xml"
- licenseFile="${licenseFile}"
outputEncoding="${maven.docs.outputencoding}"
- project="${maven.ant.project}"
- mavenProject="${pom}"
+ title="License"
/>
</goal>
1.2 +11 -38 jakarta-turbine-maven/src/plugins-build/license/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/plugins-build/license/project.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.xml 22 Sep 2002 12:06:20 -0000 1.1
+++ project.xml 3 Oct 2002 16:15:46 -0000 1.2
@@ -39,55 +39,28 @@
<id>mmay</id>
<email>[EMAIL PROTECTED]</email>
<organization>Javafreedom</organization>
+ <roles><role>Java Developer</role></roles>
+ </developer>
+ <developer>
+ <name>dIon Gillard</name>
+ <id>dion</id>
+ <email>[EMAIL PROTECTED]</email>
+ <organization>Multitask Consulting</organization>
+ <roles>
+ <role>Java Developer</role>
+ <role>Jelly Developer</role>
+ </roles>
</developer>
-
</developers>
<dependencies>
- <!--
-
- Required because of AbstractExecutor. We can probably make this
- a stand-alone bean now that we are using jelly.
-
- -->
- <dependency>
- <id>maven</id>
- <version>b5</version>
- <jar>maven.jar</jar>
- </dependency>
-
-
</dependencies>
<build>
-
<nagEmailAddress>[EMAIL PROTECTED]</nagEmailAddress>
<sourceDirectory>src/java</sourceDirectory>
-
- <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
-
- <!-- Unit test classes -->
- <unitTest>
- <includes>
- <include>**/*Test.java</include>
- </includes>
- </unitTest>
-
</build>
-
- <!-- Plugin properties -->
- <!--
- <properties>
- <buildDir>${basedir}/target</buildDir>
- <includes>**/*.java</includes>
- <excludes></excludes>
- <failOnViolation>false</failOnViolation>
- <cachefile>${maven.build.dir}/license-cachefile</cachefile>
- <format>sun</format>
- </properties>
- -->
-
</project>
1.2 +114 -99
jakarta-turbine-maven/src/plugins-build/license/src/java/org/apache/maven/license/LicenseTask.java
Index: LicenseTask.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/plugins-build/license/src/java/org/apache/maven/license/LicenseTask.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LicenseTask.java 22 Sep 2002 12:06:20 -0000 1.1
+++ LicenseTask.java 3 Oct 2002 16:15:46 -0000 1.2
@@ -57,66 +57,68 @@
*/
// java imports
-import java.io.*;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Vector;
-// maven imports
-// maven imports
-import org.apache.maven.executor.ProjectExecutor;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
/**
- * This task generates an XML file from the License file provided for the project.
+ * This task generates an xdoc formatted file from an input text file
+ * provided.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Markus M. May</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id$
*/
-public class LicenseTask extends ProjectExecutor
+public class LicenseTask
{
- private Collection lines;
-
- /**
- * The licensefile itself, defaulting to the standard one used by Maven.
- */
- private File licenseFile;
+ /** The input file */
+ private File input;
+ /** Output file for xml document */
+ private File output;
+ /** title of the resulting document */
+ private String title = "";
+ /** description of the resulting document */
+ private String description = "";
+ /** output encoding for the xml document */
+ private String outputEncoding = "ISO-8859-1";
/**
* Output file for xml document
*/
- private File output;
-
- public Collection getLines() {
- return lines;
- }
-
- public void setLines(Collection lines) {
- this.lines = lines;
- }
-
- public File getOutput() {
- return this.output;
+ public File getOutput()
+ {
+ return output;
}
/**
* Set the output file for the log.
* @param output the output file
*/
- public void setOutput(File output)
+ public void setOutput(File aFile)
{
- this.output = output;
+ output = aFile;
}
- public File getLicenseFile() {
- return licenseFile;
+ public File getInput()
+ {
+ return input;
}
- public void setLicenseFile(File licenseFile) {
- this.licenseFile = licenseFile;
+ public void setInput(File aFile)
+ {
+ input = aFile;
}
/**
* Execute task.
- * @throws FileNotFoundException if {@link License} doesn't exist
+ * @throws FileNotFoundException if {@link #getInput()} doesn't exist
* @throws UnsupportedEncodingException if the underlying platform doesn't
* support ISO-8859-1 encoding
*/
@@ -128,87 +130,100 @@
throw new NullPointerException("output must be set");
}
- if (licenseFile == null)
+ if (input == null)
{
- throw new NullPointerException("license must be set");
+ throw new NullPointerException("input must be set");
+ }
+
+ if (!input.exists() || !input.canRead())
+ {
+ throw new IOException("cannot read license file");
}
-
- readLicense(licenseFile);
- createDocument();
- }
-
- /**
- * Create the XML document from the currently available details
- * @throws FileNotFoundException when the output file previously provided
- * does not exist
- * @throws UnsupportedEncodingException when the platform doesn't support
- * ISO-8859-1 encoding
- */
- private void createDocument() throws FileNotFoundException,
- UnsupportedEncodingException
- {
PrintWriter out = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(output), getOutputEncoding()));
- out.println(toXML());
+ out.print("<?xml version=\"1.0\" encoding=\"");
+ out.print(getOutputEncoding());
+ out.println("\" ?>");
+ out.println("<document>");
+ out.print("<properties><title>");
+ out.print(getTitle());
+ out.println("</title></properties>");
+ out.println("<body>");
+ out.print("<section name=\"");
+ out.print(getDescription());
+ out.println("\">");
+ out.println("<source><![CDATA[");
+ FileInputStream fileInput = new FileInputStream(input);
+ BufferedReader data = new BufferedReader(
+ new InputStreamReader(fileInput));
+ char[] buffer = new char[512];
+ int length = 0;
+ while ((length = data.read(buffer, 0, buffer.length)) != -1)
+ {
+ out.write(buffer, 0, length);
+ }
+
+ out.println("]]></source>");
+ out.println("</section>");
+ out.println("</body>");
+ out.println("</document>");
out.flush();
out.close();
}
-
+
/**
- * @return an XML document representing this change log and it's entries
+ * Returns the description.
+ * @return String
*/
- private String toXML()
+ public String getDescription()
{
- StringBuffer buffer = new StringBuffer();
- buffer.append("<?xml version=\"1.0\" encoding=\"")
- .append(getOutputEncoding())
- .append("\" ?>\n")
- .append("<document>\n")
- .append("<properties><title>License</title></properties>\n")
- .append("<body>\n")
- .append("<section name=\"License\">\n")
- .append("<source><![CDATA[\n");
-
- for (Iterator i = lines.iterator(); i.hasNext();)
- {
- buffer.append((String) i.next())
- .append("\n");
- }
-
- buffer.append("]]></source>\n")
- .append("</section>\n")
- .append("</body>\n")
- .append("</document>\n");
+ return description;
+ }
- return buffer.toString();
+ /**
+ * Returns the title.
+ * @return String
+ */
+ public String getTitle()
+ {
+ return title;
}
- public void readLicense(File licenseFile)
- throws IOException, FileNotFoundException
+ /**
+ * Sets the description.
+ * @param description The new description
+ */
+ public void setDescription(String description)
{
- String line = null;
- Vector lines = new Vector();
+ this.description = description;
+ }
- if (!licenseFile.exists() || !licenseFile.canRead()) {
- throw new IOException("cannot read license file");
- }
+ /**
+ * Sets the title.
+ * @param title The new title
+ */
+ public void setTitle(String title)
+ {
+ this.title = title;
+ }
- try {
- FileInputStream fileInput = new FileInputStream(licenseFile);
- BufferedReader licenseData = new BufferedReader(new
InputStreamReader(fileInput));
-
- while ((line = licenseData.readLine()) != null) {
- lines.add(line);
- }
-
- } catch (FileNotFoundException fnfe) {
- throw new FileNotFoundException("license file not found");
- } catch (IOException ie) {
- throw new IOException("cannot read license file");
- }
+ /**
+ * Returns the outputEncoding.
+ * @return String
+ */
+ public String getOutputEncoding()
+ {
+ return outputEncoding;
+ }
- setLines(lines);
- }
+ /**
+ * Sets the outputEncoding.
+ * @param outputEncoding The outputEncoding to set
+ */
+ public void setOutputEncoding(String outputEncoding)
+ {
+ this.outputEncoding = outputEncoding;
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>