Started working on maven plugin and refactored the cel language loader.

This commit is contained in:
Willem Cazander 2013-04-11 09:26:38 +02:00
parent 661ac8079e
commit 6f45317753
30 changed files with 913 additions and 288 deletions

View file

@ -13,6 +13,7 @@
<description>x4o plugins for other applications</description>
<modules>
<module>x4o-plugin-ant</module>
<module>x4o-plugin-maven</module>
</modules>
<build>
<pluginManagement>

View file

@ -86,7 +86,7 @@
<target>
<property name="coredir" value="${basedir}/../../x4o-driver/src/main/resources/META-INF"/>
<taskdef name="writeLanguageSchema" classname="org.x4o.plugin.ant.X4OWriteLanguageSchemaTask" classpathref="maven.plugin.classpath"/>
<writeLanguageSchema destdir="${coredir}/cel" language="cel"/>
<writeLanguageSchema destdir="${coredir}/cel" languageName="cel"/>
</target>
</configuration>
<goals>
@ -121,7 +121,7 @@
<target>
<property name="coredir" value="${basedir}/../../x4o-driver/src/main/resources/META-INF"/>
<taskdef name="writeLanguageSchema" classname="org.x4o.plugin.ant.X4OWriteLanguageSchemaTask" classpathref="maven.plugin.classpath"/>
<writeLanguageSchema destdir="${coredir}/cel" language="eld"/>
<writeLanguageSchema destdir="${coredir}/cel" languageName="eld"/>
</target>
</configuration>
<goals>
@ -141,7 +141,7 @@
</build>
</profile>
<profile>
<id>site-elddoc</id>
<id>site-elddoc2</id>
<build>
<plugins>
<plugin>
@ -161,11 +161,11 @@
<mkdir dir="${coredir}/junit-swixml2"/>
<mkdir dir="${coredir}/junit-swixml3"/>
<taskdef name="writeLanguageDoc" classname="org.x4o.plugin.ant.X4OWriteLanguageDocTask" classpathref="maven.plugin.classpath"/>
<writeLanguageDoc destdir="${coredir}/cel" language="cel"/>
<writeLanguageDoc destdir="${coredir}/eld" language="eld"/>
<writeLanguageDoc destdir="${coredir}/junit-test" language="test"/>
<writeLanguageDoc destdir="${coredir}/junit-swixml2" language="swixml" version="2.0"/>
<writeLanguageDoc destdir="${coredir}/junit-swixml3" language="swixml"/>
<writeLanguageDoc destdir="${coredir}/cel" languageName="cel"/>
<writeLanguageDoc destdir="${coredir}/eld" languageName="eld"/>
<writeLanguageDoc destdir="${coredir}/junit-test" languageName="test"/>
<writeLanguageDoc destdir="${coredir}/junit-swixml2" languageName="swixml" languageVersion="2.0"/>
<writeLanguageDoc destdir="${coredir}/junit-swixml3" languageName="swixml"/>
</target>
</configuration>
<goals>

View file

@ -38,11 +38,17 @@ import org.apache.tools.ant.Task;
*/
abstract public class AbstractX4OLanguageTask extends Task {
private String language = null;
private String languageName = null;
private String languageVersion = null;
private String destdir = null;
private boolean verbose = false;
private boolean failonerror = true;
abstract String getLanguageTaskName();
abstract void executeLanguageTask(File basePath) throws BuildException;
/**
* Executes the x4o eld schema task.
* @see org.apache.tools.ant.Task#execute()
@ -51,11 +57,12 @@ abstract public class AbstractX4OLanguageTask extends Task {
public void execute() throws BuildException {
try {
if (isVerbose()) {
log("Task Location: "+getLocation());
log("X4O Language:"+getLanguage());
log("Destination Dir:"+getDestdir());
log("Verbose:"+isVerbose());
log("Fail on error:"+isFailonerror());
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());
}
executeLanguageTask();
} catch (BuildException e) {
@ -68,13 +75,13 @@ abstract public class AbstractX4OLanguageTask extends Task {
}
private void executeLanguageTask() throws BuildException {
if (getLanguage()==null) {
if (getLanguageName()==null) {
throw new BuildException("language attribute is not set.");
}
if (getDestdir()==null) {
throw new BuildException("basePath attribute is not set.");
}
if (getLanguage().length()==0) {
if (getLanguageName().length()==0) {
throw new BuildException("language attribute is empty.");
}
if (getDestdir().length()==0) {
@ -93,22 +100,32 @@ abstract public class AbstractX4OLanguageTask extends Task {
log("Done "+getLanguageTaskName()+" in "+(stopTime-startTime)+" ms.");
}
abstract String getLanguageTaskName();
abstract void executeLanguageTask(File basePath) throws BuildException;
/**
* @return the language
* @return the languageName
*/
public String getLanguage() {
return language;
public String getLanguageName() {
return languageName;
}
/**
* @param language the language to set
* @param languageName the languageName to set
*/
public void setLanguage(String language) {
this.language = language;
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;
}
/**

View file

@ -54,7 +54,8 @@ public class X4OWriteLanguageDocTask extends AbstractX4OLanguageTask {
void executeLanguageTask(File basePath) throws BuildException {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(basePath);
writer.setLanguage(getLanguage());
writer.setLanguageName(getLanguageName());
writer.setLanguageVersion(getLanguageVersion());
try {
writer.execute();
} catch (ElementException e) {

View file

@ -58,7 +58,8 @@ public class X4OWriteLanguageSchemaTask extends AbstractX4OLanguageTask {
}
X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor();
writer.setBasePath(basePath);
writer.setLanguage(getLanguage());
writer.setLanguageName(getLanguageName());
writer.setLanguageVersion(getLanguageVersion());
writer.setLanguageNamespaceUri(getNsuri()); // null is all namespaces
try {
writer.execute();

View file

@ -36,7 +36,7 @@ import org.apache.tools.ant.BuildFileTest;
public class X4OWriteLanguageDocTaskTest extends BuildFileTest {
public void setUp() {
configureProject("src/test/resources/tests/test-write-language-doc.xml");
configureProject("src/test/resources/junit/test-write-language-doc.xml");
}
public void testEldDocCel() {

View file

@ -36,7 +36,7 @@ import org.apache.tools.ant.BuildFileTest;
public class X4OWriteLanguageSchemaTaskTest extends BuildFileTest {
public void setUp() {
configureProject("src/test/resources/tests/test-write-language-schema.xml");
configureProject("src/test/resources/junit/test-write-language-schema.xml");
}
public void testCelSchemaFull() {

View file

@ -37,7 +37,7 @@
<mkdir dir="${test.dir}/cel"/>
<writeLanguageDoc
destdir="${test.dir}/cel"
language="cel"
languageName="cel"
/>
</target>
@ -46,7 +46,7 @@
<writeLanguageDoc
verbose="true"
destdir="${test.dir}/cel"
language="cel"
languageName="cel"
/>
</target>
@ -54,7 +54,7 @@
<mkdir dir="${test.dir}/eld"/>
<writeLanguageDoc
destdir="${test.dir}/eld"
language="cel"
languageName="cel"
/>
</target>
@ -62,16 +62,16 @@
<writeLanguageDoc/>
</target>
<target name="test-fail-destdir" depends="init">
<writeLanguageDoc language="cel"/>
<writeLanguageDoc languageName="cel"/>
</target>
<target name="test-fail-destdir-error" depends="init">
<writeLanguageDoc language="cel" destdir="${test.dir}/no-dir"/>
<writeLanguageDoc languageName="cel" destdir="${test.dir}/no-dir"/>
</target>
<target name="test-fail-language" depends="init">
<writeLanguageDoc destdir="${test.dir}/test"/>
</target>
<target name="test-fail-language-error" depends="init">
<writeLanguageDoc destdir="${test.dir}/test" language="cel-error"/>
<writeLanguageDoc destdir="${test.dir}/test" languageName="cel-error"/>
</target>
</project>

View file

@ -37,7 +37,7 @@
<mkdir dir="${test.dir}/cel-full"/>
<writeLanguageSchema
destdir="${test.dir}/cel-full"
language="eld"
languageName="eld"
/>
</target>
@ -45,7 +45,7 @@
<mkdir dir="${test.dir}/cel-single"/>
<writeLanguageSchema
destdir="${test.dir}/cel-single"
language="cel"
languageName="cel"
nsuri="http://cel.x4o.org/xml/ns/cel-core"
/>
</target>
@ -55,7 +55,7 @@
<writeLanguageSchema
verbose="true"
destdir="${test.dir}/cel-single"
language="cel"
languageName="cel"
nsuri="http://cel.x4o.org/xml/ns/cel-core"
/>
</target>
@ -64,16 +64,16 @@
<writeLanguageSchema/>
</target>
<target name="test-fail-destdir" depends="init">
<writeLanguageSchema language="cel"/>
<writeLanguageSchema languageName="cel"/>
</target>
<target name="test-fail-destdir-error" depends="init">
<writeLanguageSchema language="cel" destdir="${test.dir}/no-dir"/>
<writeLanguageSchema languageName="cel" destdir="${test.dir}/no-dir"/>
</target>
<target name="test-fail-language" depends="init">
<writeLanguageSchema destdir="${test.dir}/test"/>
</target>
<target name="test-fail-language-error" depends="init">
<writeLanguageSchema destdir="${test.dir}/test" language="eld-error"/>
<writeLanguageSchema destdir="${test.dir}/test" languageName="eld-error"/>
</target>
</project>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>x4o-plugin-maven</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,125 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.x4o.plugin</groupId>
<artifactId>x4o-plugin</artifactId>
<version>0.8.5-SNAPSHOT</version>
</parent>
<artifactId>x4o-plugin-maven</artifactId>
<packaging>maven-plugin</packaging>
<name>x4o-plugin-maven</name>
<description>x4o-plugin-maven</description>
<dependencies>
<dependency>
<groupId>org.x4o</groupId>
<artifactId>x4o-driver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.x4o</groupId>
<artifactId>x4o-elddoc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
<!-- generated help mojo has a dependency to plexus-utils -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals><goal>descriptor</goal></goals>
</execution>
<execution>
<id>mojo-help</id>
<goals><goal>helpmojo</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>site-elddoc</id>
<build>
<plugins>
<plugin>
<groupId>org.x4o.plugin</groupId>
<artifactId>x4o-plugin-maven</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>site-elddoc-maven</id>
<phase>pre-site</phase>
<configuration>
<outputDirectory>${basedir}/../../target/site/elddocs</outputDirectory>
<languages>
<cel>ALL</cel>
<eld>ALL</eld>
<test>ALL</test>
<swixml>2.0-3.0</swixml>
</languages>
</configuration>
<goals>
<goal>write-language-doc</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.x4o</groupId>
<artifactId>x4o-driver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.x4o</groupId>
<artifactId>x4o-driver</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.x4o</groupId>
<artifactId>x4o-elddoc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel</artifactId>
<version>${juel.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View file

@ -0,0 +1,189 @@
/*
* Copyright (c) 2004-2012, 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.maven;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
/**
* X4OWriteLanguageDocMojo creates docs for language.
*
* @author Willem Cazander
* @version 1.0 Apr 9, 2013
*/
public abstract class AbstractX4OLanguageMojo extends AbstractMojo {
@Parameter(property="outputDirectory")
private File outputDirectory;
@Parameter(required=true,property="languages")
private Map<String,String> languages;
@Parameter(defaultValue="false",property="verbose")
private boolean verbose = false;
@Parameter(defaultValue="true",property="failOnError")
private boolean failOnError = true;
abstract String getLanguageTaskName();
abstract void executeLanguageTask(String languageName,String languageVersion,File outputDirectory) throws MojoExecutionException;
private void executeLanguageTask() throws MojoExecutionException {
if (outputDirectory==null) {
throw new MojoExecutionException("outputDirectory attribute is not set.");
}
if (languages==null) {
throw new MojoExecutionException("languages attribute is not set.");
}
if (languages.size()==0) {
throw new MojoExecutionException("languages attribute is empty.");
}
long startTime = System.currentTimeMillis();
if (verbose) {
getLog().info("Starting "+getLanguageTaskName());
}
if (outputDirectory.exists()==false) {
outputDirectory.mkdir();
if (verbose) {
getLog().info("Created directory: "+outputDirectory);
}
}
for (String languageName:languages.keySet()) {
String languageVersions = languages.get(languageName);
if (languageVersions.contains("*") || languageVersions.contains("ALL")) {
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(languageName);
if (driver==null) {
throw new MojoExecutionException("Couln't load x4o language driver for: "+languageName);
}
for (String supportedVersion:driver.getLanguageVersions()) {
executeLanguageTask(languageName,supportedVersion);
}
} else if (languageVersions.contains("-")) {
for (String languageVersion:languageVersions.split("-")) {
executeLanguageTask(languageName,languageVersion);
}
} else {
executeLanguageTask(languageName,languageVersions); // only one version
}
}
long stopTime = System.currentTimeMillis();
getLog().info("Done "+getLanguageTaskName()+" in "+(stopTime-startTime)+" ms.");
}
private void executeLanguageTask(String languageName,String languageVersion) throws MojoExecutionException {
File outputLanguagPath = new File(outputDirectory.getAbsolutePath()+File.separatorChar+languageName+"-"+languageVersion);
if (outputLanguagPath.exists()==false) {
outputLanguagPath.mkdir();
if (verbose) {
getLog().info("Created directory: "+outputLanguagPath);
}
}
executeLanguageTask(languageName,languageVersion,outputLanguagPath);
}
public void execute() throws MojoExecutionException {
try {
if (verbose) {
if (languages!=null) {
getLog().info("X4O Languages: "+languages.size());
}
getLog().info("Output directory: "+outputDirectory);
getLog().info("Verbose: "+verbose);
getLog().info("Fail on error: "+failOnError);
}
executeLanguageTask();
} catch (MojoExecutionException e) {
if (failOnError) {
throw e;
} else {
getLog().warn(e.getMessage());
}
}
}
/**
* @return the outputDirectory
*/
public File getOutputDirectory() {
return outputDirectory;
}
/**
* @param outputDirectory the outputDirectory to set
*/
public void setOutputDirectory(File outputDirectory) {
this.outputDirectory = outputDirectory;
}
/**
* @return the languages
*/
public Map<String, String> getLanguages() {
return languages;
}
/**
* @param languages the languages to set
*/
public void addLanguage(String languageName,String languageVersion) {
languages.put(languageName,languageVersion);
}
/**
* @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;
}
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2004-2012, 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.maven;
import java.io.File;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.x4o.xml.eld.doc.X4OWriteLanguageDocExecutor;
import org.x4o.xml.element.ElementException;
/**
* X4OWriteLanguageDocMojo creates docs for language.
*
* @author Willem Cazander
* @version 1.0 Apr 9, 2013
*/
@Mojo( name = X4OWriteLanguageDocMojo.GOAL,requiresProject=true,requiresDependencyResolution=ResolutionScope.COMPILE)
public class X4OWriteLanguageDocMojo extends AbstractX4OLanguageMojo {
static public final String GOAL = "write-language-doc";
String getLanguageTaskName() {
return "X4O Write language documentation";
}
void executeLanguageTask(String languageName,String languageVersion,File basePath) throws MojoExecutionException {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(basePath);
writer.setLanguageName(languageName);
writer.setLanguageVersion(languageVersion);
try {
writer.execute();
} catch (ElementException e) {
throw new MojoExecutionException(e.getMessage(),e);
}
}
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2004-2012, 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.maven;
import java.io.File;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.x4o.xml.eld.xsd.X4OWriteLanguageSchemaExecutor;
import org.x4o.xml.element.ElementException;
/**
* X4OWriteLanguageSchemaMojo creates schema for language.
*
* @author Willem Cazander
* @version 1.0 Apr 10, 2013
*/
@Mojo( name = X4OWriteLanguageSchemaMojo.GOAL,requiresProject=true,requiresDependencyResolution=ResolutionScope.COMPILE)
public class X4OWriteLanguageSchemaMojo extends AbstractX4OLanguageMojo {
static public final String GOAL = "write-language-schema";
String getLanguageTaskName() {
return "X4O Write language schema";
}
void executeLanguageTask(String languageName,String languageVersion,File basePath) throws MojoExecutionException {
X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor();
writer.setBasePath(basePath);
writer.setLanguageName(languageName);
writer.setLanguageVersion(languageVersion);
try {
writer.execute();
} catch (ElementException e) {
throw new MojoExecutionException(e.getMessage(),e);
}
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-2012, 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.
*/
/**
* The maven plugin mojos.
*
* @since 1.0
*/
package org.x4o.plugin.maven;

View file

@ -0,0 +1,95 @@
/*
* Copyright (c) 2004-2012, 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.maven;
import java.io.File;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
/**
* X4OWriteLanguageDocMojoTest.
*
* @author Willem Cazander
* @version 1.0 Apr 6, 2013
*/
public class X4OWriteLanguageDocMojoTest extends AbstractMojoTestCase {
/** {@inheritDoc} */
protected void setUp() throws Exception {
super.setUp(); // required
}
/** {@inheritDoc} */
protected void tearDown() throws Exception {
super.tearDown(); // required
}
private void executeGoal() throws Exception {
File pom = getTestFile( "src/test/resources/junit/test-write-language-doc.pom" );
assertNotNull( pom );
assertTrue( pom.exists() );
X4OWriteLanguageDocMojo mojo = (X4OWriteLanguageDocMojo) lookupMojo( X4OWriteLanguageDocMojo.GOAL, pom );
//mojo.s
assertNotNull( mojo );
mojo.execute();
}
public void testEldDocCel() throws Exception {
executeGoal(); //"test-elddoc-cel"
File testDir = new File("target/test-elddoc/cel");
//int files = testDir.listFiles().length;
//assertEquals("Should created more then two files", true, files>2);
}
/*
public void testEldDocEld() {
executeTarget("test-elddoc-eld");
File testDir = new File("target/test-elddoc/eld");
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:");
}
public void testFailAllMissing() {
expectBuildException("test-fail-all", "Should get exception with no attributes.");
}
public void testFailBasePath() {
expectBuildException("test-fail-destdir", "Should get exception id destdir is not set.");
}
public void testFailBasePathError() {
expectBuildException("test-fail-destdir-error", "Should get exception id destdir does not exists.");
}
public void testFailLanguage() {
expectBuildException("test-fail-language", "Should get exception id language is not set.");
}
public void testFailLanguageError() {
expectBuildException("test-fail-language-error", "Should get exception id language throws error.");
}
*/
}

View file

@ -0,0 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.x4o.plugin.junit</groupId>
<artifactId>x4o-plugin-maven-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>x4o-plugin-maven-test</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>x4o-plugin-maven</artifactId>
<configuration>
<outputDirectory>target/jtest/write-language-doc</outputDirectory>
<languages>
<cel>ALL</cel>
<eld>ALL</eld>
</languages>
</configuration>
</plugin>
</plugins>
</build>
</project>