Create language task api and converted the current tasks.

This commit is contained in:
Willem Cazander 2013-08-30 22:40:39 +02:00
parent 57f3c20655
commit 6cd968eb17
69 changed files with 2092 additions and 1315 deletions

View file

@ -22,11 +22,15 @@
*/
package org.x4o.plugin.ant;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.x4o.xml.lang.task.X4OLanguageTaskException;
import org.x4o.xml.lang.task.run.X4OTaskProperty;
import org.x4o.xml.lang.task.run.X4OTaskRunner;
/**
@ -35,18 +39,29 @@ import org.apache.tools.ant.Task;
* @author Willem Cazander
* @version 1.0 Apr 8, 2013
*/
abstract public class AbstractX4OLanguageTask extends Task {
public class X4OTask extends Task {
private String taskId = null;
private String languageName = null;
private String languageVersion = null;
private String destdir = null;
private boolean verbose = false;
private boolean failonerror = true;
private List<X4OTaskProperty> taskProperties = null;
/**
* Constructs this ant x4o task.
*/
public X4OTask() {
taskProperties = new ArrayList<X4OTaskProperty>(15);
}
abstract String getLanguageTaskName();
abstract void executeLanguageTask(File basePath) throws BuildException;
/**
* Adds the ant child x4oTaskProperty element.
* @param property
*/
public void addX4oTaskProperty(X4OTaskProperty property) {
taskProperties.add(property);
}
/**
* Executes the x4o eld schema task.
@ -59,7 +74,6 @@ abstract public class AbstractX4OLanguageTask extends Task {
log("Task location: "+getLocation());
log("X4O language name: "+getLanguageName());
log("X4O language version: "+getLanguageVersion());
log("Destination directory: "+getDestdir());
log("Verbose: "+isVerbose());
log("Fail on error: "+isFailonerror());
}
@ -75,28 +89,31 @@ abstract public class AbstractX4OLanguageTask extends Task {
private void executeLanguageTask() throws BuildException {
if (getLanguageName()==null) {
throw new BuildException("language attribute is not set.");
}
if (getDestdir()==null) {
throw new BuildException("basePath attribute is not set.");
throw new BuildException("languageName attribute is not set.");
}
if (getLanguageName().length()==0) {
throw new BuildException("language attribute is empty.");
throw new BuildException("languageName attribute is empty.");
}
if (getDestdir().length()==0) {
throw new BuildException("basePath attribute is empty.");
if (getLanguageVersion()!=null && getLanguageVersion().length()==0) {
throw new BuildException("languageVersion attribute is empty.");
}
File basePathFile = new File(getDestdir());
if (basePathFile.exists()==false) {
throw new BuildException("destdir does not exists: "+basePathFile);
if (getTaskId()==null) {
throw new BuildException("taskId attribute is not set.");
}
if (getTaskId().length()==0) {
throw new BuildException("taskId attribute is empty.");
}
if (isVerbose()) {
log("Starting "+getLanguageTaskName());
log("Starting "+getTaskId());
}
long startTime = System.currentTimeMillis();
executeLanguageTask(basePathFile);
try {
X4OTaskRunner.runTask(getLanguageName(),getLanguageVersion(), getTaskId(), taskProperties);
} catch (X4OLanguageTaskException e) {
throw new BuildException(e);
}
long stopTime = System.currentTimeMillis();
log("Done "+getLanguageTaskName()+" in "+(stopTime-startTime)+" ms.");
log("Done "+getTaskId()+" in "+(stopTime-startTime)+" ms.");
}
/**
@ -105,67 +122,67 @@ abstract public class AbstractX4OLanguageTask extends Task {
public String getLanguageName() {
return languageName;
}
/**
* @param languageName the languageName to set
*/
public void setLanguageName(String languageName) {
this.languageName = languageName;
}
/**
* @return the languageVersion
*/
public String getLanguageVersion() {
return languageVersion;
}
/**
* @param languageVersion the languageVersion to set
*/
public void setLanguageVersion(String languageVersion) {
this.languageVersion = languageVersion;
}
/**
* @return the destdir
*/
public String getDestdir() {
return destdir;
}
/**
* @param destdir the destdir to set
*/
public void setDestdir(String destdir) {
this.destdir = destdir;
}
/**
* @return the verbose
*/
public boolean isVerbose() {
return verbose;
}
/**
* @param verbose the verbose to set
*/
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
/**
* @return the failonerror
*/
public boolean isFailonerror() {
return failonerror;
}
/**
* @param failonerror the failonerror to set
*/
public void setFailonerror(boolean failonerror) {
this.failonerror = failonerror;
}
/**
* @return the taskId
*/
public String getTaskId() {
return taskId;
}
/**
* @param taskId the taskId to set
*/
public void setTaskId(String taskId) {
this.taskId = taskId;
}
}

View file

@ -1,64 +0,0 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* 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.
*
* 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
* THE COPYRIGHT HOLDER 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.x4o.plugin.ant;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.x4o.xml.eld.doc.X4OWriteLanguageDocExecutor;
import org.x4o.xml.element.ElementException;
/**
* X4OWriteDocTask creates schema for language.
*
* @author Willem Cazander
* @version 1.0 Aug 24, 2012
*/
public class X4OWriteLanguageDocTask extends AbstractX4OLanguageTask {
/**
* @see org.x4o.plugin.ant.AbstractX4OLanguageTask#getLanguageTaskName()
*/
@Override
String getLanguageTaskName() {
return "X4O Write language documentation";
}
/**
* Config and start eld writer
* @see org.x4o.plugin.ant.AbstractX4OLanguageTask#executeLanguageTask(java.io.File)
*/
@Override
void executeLanguageTask(File basePath) throws BuildException {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(basePath);
writer.setLanguageName(getLanguageName());
writer.setLanguageVersion(getLanguageVersion());
try {
writer.execute();
} catch (ElementException e) {
throw new BuildException(e);
}
}
}

View file

@ -1,83 +0,0 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* 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.
*
* 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
* THE COPYRIGHT HOLDER 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.x4o.plugin.ant;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.x4o.xml.eld.xsd.X4OWriteLanguageSchemaExecutor;
import org.x4o.xml.element.ElementException;
/**
* X4OWriteSchemaTask creates schema for language.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2012
*/
public class X4OWriteLanguageSchemaTask extends AbstractX4OLanguageTask {
private String nsuri = null;
/**
* @see org.x4o.plugin.ant.AbstractX4OLanguageTask#getLanguageTaskName()
*/
@Override
String getLanguageTaskName() {
return "X4O Write language schema";
}
/**
* Config and start schema writer
* @see org.x4o.plugin.ant.AbstractX4OLanguageTask#executeLanguageTask(java.io.File)
*/
@Override
void executeLanguageTask(File basePath) throws BuildException {
if (isVerbose() && getNsuri()!=null) {
log("Namespace uri: "+getNsuri());
}
X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor();
writer.setBasePath(basePath);
writer.setLanguageName(getLanguageName());
writer.setLanguageVersion(getLanguageVersion());
writer.setLanguageNamespaceUri(getNsuri()); // null is all namespaces
try {
writer.execute();
} catch (ElementException e) {
throw new BuildException(e);
}
}
/**
* @return the nsuri
*/
public String getNsuri() {
return nsuri;
}
/**
* @param nsuri the nsuri to set
*/
public void setNsuri(String nsuri) {
this.nsuri = nsuri;
}
}

View file

@ -56,6 +56,13 @@ public class X4OWriteLanguageDocTaskTest extends BuildFileTest {
//assertLogContaining("Nested Element 1");
}
public void testEldDocEldCustom() {
executeTarget("test-elddoc-eld-custom");
File testDir = new File("target/test-elddoc/eld-custom");
int files = testDir.listFiles().length;
assertEquals("Should created more then two files", true, files>2);
}
public void testEldDocEldVerbose() {
executeTarget("test-elddoc-cel-verbose");
assertLogContaining("Verbose:");

View file

@ -42,7 +42,7 @@ public class X4OWriteLanguageSchemaTaskTest extends BuildFileTest {
executeTarget("test-cel-schema-full");
File testDir = new File("target/test-schemas/cel-full");
int files = testDir.listFiles().length;
assertEquals("Should created only 3 files", 3, files);
assertEquals("Should created only 2 files", 2, files);
}
public void testCelSchemaSingle() {

View file

@ -28,50 +28,83 @@
<property name="test.dir" value="${basedir}/target/test-elddoc/"/>
<target name="init">
<taskdef name="writeLanguageDoc" classname="org.x4o.plugin.ant.X4OWriteLanguageDocTask"/>
<taskdef name="x4oTask" classname="org.x4o.plugin.ant.X4OTask"/>
<mkdir dir="${test.dir}"/>
<mkdir dir="${test.dir}/test"/>
</target>
<target name="test-elddoc-cel" depends="init">
<mkdir dir="${test.dir}/cel"/>
<writeLanguageDoc
destdir="${test.dir}/cel"
languageName="cel"
<x4oTask languageName="cel" taskId="eld-doc">
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-doc/output/path"
value="${test.dir}/cel"
/>
</x4oTask>
</target>
<target name="test-elddoc-cel-verbose" depends="init">
<mkdir dir="${test.dir}/cel"/>
<writeLanguageDoc
verbose="true"
destdir="${test.dir}/cel"
languageName="cel"
<mkdir dir="${test.dir}/cel-verbose"/>
<x4oTask languageName="cel" taskId="eld-doc" verbose="true">
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-doc/output/path"
value="${test.dir}/cel-verbose"
/>
</x4oTask>
</target>
<target name="test-elddoc-eld" depends="init">
<mkdir dir="${test.dir}/eld"/>
<writeLanguageDoc
destdir="${test.dir}/eld"
languageName="cel"
<x4oTask languageName="eld" taskId="eld-doc">
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-doc/output/path"
value="${test.dir}/eld"
/>
</x4oTask>
</target>
<target name="test-elddoc-eld-custom" depends="init">
<mkdir dir="${test.dir}/eld-custom"/>
<x4oTask languageName="eld" taskId="eld-doc">
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-doc/output/path"
value="${test.dir}/eld-custom"
/>
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/content/output/charTab"
value=" "
/>
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-doc/meta/stylesheet-thema"
value="jdk6"
/>
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-doc/javadoc/link"
value="http://docs.oracle.com/javase/7/docs/api/"
/>
<!-- fixme map type property config
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-doc/javadoc/link-offline"
value="http://www.x4o.org/apidocs/,file:///home/willemc/devv/git/x4o/x4o-driver/target/apidocs"
/>
-->
</x4oTask>
</target>
<target name="test-fail-all" depends="init">
<writeLanguageDoc/>
<x4oTask/>
</target>
<target name="test-fail-destdir" depends="init">
<writeLanguageDoc languageName="cel"/>
<x4oTask languageName="cel"/>
</target>
<target name="test-fail-destdir-error" depends="init">
<writeLanguageDoc languageName="cel" destdir="${test.dir}/no-dir"/>
<x4oTask languageName="cel" destdir="${test.dir}/no-dir"/>
</target>
<target name="test-fail-language" depends="init">
<writeLanguageDoc destdir="${test.dir}/test"/>
<x4oTask destdir="${test.dir}/test"/>
</target>
<target name="test-fail-language-error" depends="init">
<writeLanguageDoc destdir="${test.dir}/test" languageName="cel-error"/>
<x4oTask destdir="${test.dir}/test" languageName="cel-error"/>
</target>
</project>

View file

@ -28,52 +28,63 @@
<property name="test.dir" value="${basedir}/target/test-schemas/"/>
<target name="init">
<taskdef name="writeLanguageSchema" classname="org.x4o.plugin.ant.X4OWriteLanguageSchemaTask"/>
<taskdef name="x4oTask" classname="org.x4o.plugin.ant.X4OTask"/>
<mkdir dir="${test.dir}"/>
<mkdir dir="${test.dir}/test"/>
</target>
<target name="test-cel-schema-full" depends="init">
<mkdir dir="${test.dir}/cel-full"/>
<writeLanguageSchema
destdir="${test.dir}/cel-full"
languageName="eld"
<x4oTask languageName="cel" taskId="eld-xsd">
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-xsd/output/path"
value="${test.dir}/cel-full"
/>
</x4oTask>
</target>
<target name="test-cel-schema-single" depends="init">
<mkdir dir="${test.dir}/cel-single"/>
<writeLanguageSchema
destdir="${test.dir}/cel-single"
languageName="cel"
nsuri="http://cel.x4o.org/xml/ns/cel-core"
<x4oTask languageName="cel" taskId="eld-xsd">
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-xsd/output/path"
value="${test.dir}/cel-single"
/>
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-xsd/filter/namespace"
value="http://cel.x4o.org/xml/ns/cel-core"
/>
</x4oTask>
</target>
<target name="test-cel-schema-verbose" depends="init">
<mkdir dir="${test.dir}/cel-single"/>
<writeLanguageSchema
verbose="true"
destdir="${test.dir}/cel-single"
languageName="cel"
nsuri="http://cel.x4o.org/xml/ns/cel-core"
<mkdir dir="${test.dir}/cel-single-verbose"/>
<x4oTask languageName="cel" taskId="eld-xsd" verbose="true">
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-xsd/output/path"
value="${test.dir}/cel-single-verbose"
/>
<x4oTaskProperty
key="http://language.x4o.org/xml/properties/eld-xsd/filter/namespace"
value="http://cel.x4o.org/xml/ns/cel-core"
/>
</x4oTask>
</target>
<target name="test-fail-all" depends="init">
<writeLanguageSchema/>
<x4oTask/>
</target>
<target name="test-fail-destdir" depends="init">
<writeLanguageSchema languageName="cel"/>
<x4oTask languageName="cel"/>
</target>
<target name="test-fail-destdir-error" depends="init">
<writeLanguageSchema languageName="cel" destdir="${test.dir}/no-dir"/>
<x4oTask languageName="cel" destdir="${test.dir}/no-dir"/>
</target>
<target name="test-fail-language" depends="init">
<writeLanguageSchema destdir="${test.dir}/test"/>
<x4oTask destdir="${test.dir}/test"/>
</target>
<target name="test-fail-language-error" depends="init">
<writeLanguageSchema destdir="${test.dir}/test" languageName="eld-error"/>
<x4oTask destdir="${test.dir}/test" languageName="eld-error"/>
</target>
</project>