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

@ -76,3 +76,9 @@ mvn versions:display-plugin-updates;
mvn versions:display-dependency-updates;
-- Run x4o-plugin-maven from cmd --
cd project-root/;
mvn clean install;
mvn org.x4o.plugin:x4o-plugin-maven:help
mvn org.x4o.plugin:x4o-plugin-maven:write-language-doc -Dlanguages=cel -DoutputDirectory=/tmp/dd -Dverbose=true

View file

@ -52,11 +52,11 @@
<item name="Sample jr4o" href="examples/sample-jr4o.html"/>
</menu>
<menu name="EldDoc">
<item name="cel" href="elddocs/cel/index.html"/>
<item name="eld" href="elddocs/eld/index.html"/>
<item name="junit-test" href="elddocs/junit-test/index.html"/>
<item name="junit-swixml2" href="elddocs/junit-swixml2/index.html"/>
<item name="junit-swixml3" href="elddocs/junit-swixml3/index.html"/>
<item name="cel" href="elddocs/cel-1.0/index.html"/>
<item name="eld" href="elddocs/eld-1.0/index.html"/>
<item name="junit-test" href="elddocs/test-1.0/index.html"/>
<item name="junit-swixml2" href="elddocs/swixml-2.0/index.html"/>
<item name="junit-swixml3" href="elddocs/swixml-3.0/index.html"/>
</menu>
<menu ref="parent"/>

View file

@ -146,6 +146,12 @@ public final class X4ODriverManager {
}
static public void registerX4ODriver(X4ODriver<?> driver) {
if (driver.getLanguageName()==null) {
throw new NullPointerException("Error in driver impl languageName is null in: "+driver.getClass());
}
if (driver.getLanguageVersions()==null) {
throw new NullPointerException("Error in driver impl languageVersions is null in: "+driver.getClass());
}
instance.drivers.put(driver.getLanguageName(), driver);
}

View file

@ -45,6 +45,6 @@ public class CelDriver extends X4ODriver<X4OLanguageModule> {
@Override
public String[] getLanguageVersions() {
return null;
return LANGUAGE_VERSIONS;
}
}

View file

@ -23,11 +23,11 @@
package org.x4o.xml.eld;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.text.ClassConverter;
import org.x4o.xml.eld.lang.BeanElement;
import org.x4o.xml.eld.lang.DescriptionElement;
import org.x4o.xml.eld.lang.ElementClassAddParentElement;
@ -37,19 +37,20 @@ import org.x4o.xml.eld.lang.ElementInterfaceBindingHandler;
import org.x4o.xml.eld.lang.ElementModuleBindingHandler;
import org.x4o.xml.eld.lang.ElementNamespaceContextBindingHandler;
import org.x4o.xml.eld.lang.ModuleElement;
import org.x4o.xml.element.DefaultElementClass;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageLocal;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageModule;
import org.x4o.xml.lang.X4OLanguageModuleLoader;
import org.x4o.xml.lang.X4OLanguageModuleLoaderException;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageLocal;
/**
* EldModuleLoaderCore provides a few basic elements for the core eld x4o language.
@ -85,47 +86,121 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
* @param elementLanguageModule The module to load it in.
* @see org.x4o.xml.lang.X4OLanguageModuleLoader#loadLanguageModule(org.x4o.xml.element.ElementLanguage, org.x4o.xml.lang.X4OLanguageModule)
*/
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModule elementLanguageModule) throws X4OLanguageModuleLoaderException {
public void loadLanguageModule(X4OLanguageLocal language,X4OLanguageModule languageModule) throws X4OLanguageModuleLoaderException {
elementLanguageModule.setId("cel-module");
elementLanguageModule.setName("Core Element Languag Module");
elementLanguageModule.setProviderName(PP_CEL_PROVIDER);
// Config module meta data
configLanguageModule(languageModule);
List<ElementClass> elementClassList = new ArrayList<ElementClass>(10);
elementClassList.add(new DefaultElementClass("attribute",language.getLanguageConfiguration().getDefaultElementClassAttribute()));
elementClassList.add(new DefaultElementClass("classConverter",ClassConverter.class));
// Config language
addBindingHandler(languageModule,new ElementClassBindingHandler(),"cel-class-bind","Binds the ElementClass childeren.");
addBindingHandler(languageModule,new ElementModuleBindingHandler(),"cel-module-bind","Binds the LanguageModule childeren.");
addBindingHandler(languageModule,new ElementClassAttributeBindingHandler(),"cel-class-attr-bind","Binds the ElementClassAttribute childeren.");
addBindingHandler(languageModule,new ElementInterfaceBindingHandler(),"cel-interface-bind","Binds the ElementInterface childeren.");
addBindingHandler(languageModule,new ElementNamespaceContextBindingHandler(),"cel-namespace-bind","Binds the Namespace childeren.");
createElementClasses(elementClassList,language); // adds all meta info
// Create cel-lang namespace in language
ElementNamespaceContext namespace = createNamespaceContext(language,CEL_CORE,CEL_CORE_URI,CEL_CORE_XSD_URI,CEL_CORE_XSD_FILE,CEL_CORE);
configElementClasses(language,namespace);
startAndAddNamespace(language,languageModule,namespace);
ElementClassAttribute attr;
// Create cel-root namespace in language for schema support
ElementNamespaceContext namespaceRoot = createNamespaceContext(language,CEL_ROOT,CEL_ROOT_URI,CEL_ROOT_XSD_URI,CEL_ROOT_XSD_FILE,CEL_ROOT);
namespaceRoot.setLanguageRoot(true); // Only define single language root so xsd is (mostly) not cicle import.
ElementClass rootElement = createElementClass(language,"module",language.getLanguageConfiguration().getDefaultElementLanguageModule(),ModuleElement.class,"The module tag is the root xml element for ELD language.");
namespaceRoot.addElementClass(rootElement);
startAndAddNamespace(language,languageModule,namespaceRoot);
}
DefaultElementClass ns = new DefaultElementClass("namespace",language.getLanguageConfiguration().getDefaultElementNamespaceContext());
attr = newElementClassAttribute(language);
attr.setName("uri");
attr.setRequired(true);
ns.addElementClassAttribute(attr);
elementClassList.add(ns);
/**
* Adds only Element class beans which need extra meta info for schema.
*
* @param elementClassList The list to fill.
* @throws X4OLanguageModuleLoaderException
*/
private void configElementClasses(X4OLanguage language,ElementNamespaceContext namespace) throws X4OLanguageModuleLoaderException {
ElementClass ec = null;
DefaultElementClass dec = new DefaultElementClass("element",language.getLanguageConfiguration().getDefaultElementClass());
attr = newElementClassAttribute(language);
attr.setName("objectClass");
attr.setObjectConverter(new ClassConverter());
dec.addElementClassAttribute(attr);
namespace.addElementClass(createElementClass(language,"attribute",language.getLanguageConfiguration().getDefaultElementClassAttribute(),null,"Defines xml element attribute."));
namespace.addElementClass(createElementClass(language,"classConverter",ClassConverter.class,null,"Converts string attribute to java class instance."));
attr = newElementClassAttribute(language);
attr.setName("elementClass");
attr.setObjectConverter(new ClassConverter());
dec.addElementClassAttribute(attr);
elementClassList.add(dec);
ec = createElementClass(language,"namespace",language.getLanguageConfiguration().getDefaultElementNamespaceContext(),null,"Defines an xml namespace.");
ec.addElementClassAttribute(createElementClassAttribute(language,"uri",true,null));
namespace.addElementClass(ec);
DefaultElementClass ec = new DefaultElementClass("elementInterface",language.getLanguageConfiguration().getDefaultElementInterface());
attr = newElementClassAttribute(language);
attr.setName("interfaceClass");
attr.setObjectConverter(new ClassConverter());
ec.addElementClassAttribute(attr);
elementClassList.add(ec);
ec = createElementClass(language,"element",language.getLanguageConfiguration().getDefaultElementClass(),null,"Defines xml element tag.");
ec.addElementClassAttribute(createElementClassAttribute(language,"objectClass",false,new ClassConverter()));
ec.addElementClassAttribute(createElementClassAttribute(language,"elementClass",false,new ClassConverter()));
namespace.addElementClass(ec);
logger.finer("Creating eldcore namespace.");
ec = createElementClass(language,"elementInterface",language.getLanguageConfiguration().getDefaultElementInterface(),null,"Defines element interface class.");
ec.addElementClassAttribute(createElementClassAttribute(language,"interfaceClass",false,new ClassConverter()));
namespace.addElementClass(ec);
ec = createElementClass(language,"bindingHandler",null,BeanElement.class,"Defines generic binding handler for languge.");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementClassAttribute(createElementClassAttribute(language,"id",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"attributeHandler",null,BeanElement.class,"Defines generic attribute handler for language.");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"configurator",null,BeanElement.class,"Define generic configurator for language.");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"configAction",false,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"configuratorGlobal",null,BeanElement.class,"Define generic global configuator for languge.");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementClassAttribute(createElementClassAttribute(language,"bean.class",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"configAction",false,null));
namespace.addElementClass(ec);
ec = createElementClass(language,"description",null,DescriptionElement.class,"Adds description as text on all eld elements.");
ec.setSchemaContentBase("string");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent(CEL_CORE_URI, "namespace");
ec.addElementParent(CEL_CORE_URI, "attributeHandler");
ec.addElementParent(CEL_CORE_URI, "bindingHandler");
ec.addElementParent(CEL_CORE_URI, "configurator");
ec.addElementParent(CEL_CORE_URI, "configuratorGlobal");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementParent(CEL_CORE_URI, "attribute");
namespace.addElementClass(ec);
ec = createElementClass(language,"elementParent",null,ElementClassAddParentElement.class,"Added (meta) element parent.");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementClassAttribute(createElementClassAttribute(language,"tag",true,null));
ec.addElementClassAttribute(createElementClassAttribute(language,"uri",false,null));
namespace.addElementClass(ec);
}
private void configLanguageModule(X4OLanguageModule languageModule) {
languageModule.setId("cel-module");
languageModule.setName("Core Element Languag Module");
languageModule.setProviderName(PP_CEL_PROVIDER);
languageModule.setDescription("Core Element Language Module Loader");
languageModule.setSourceResource(this.getClass().getSimpleName()); // todo check if oke.
}
private void startAndAddNamespace(X4OLanguageLocal language,X4OLanguageModule languageModule,ElementNamespaceContext namespace) throws X4OLanguageModuleLoaderException {
try {
namespace.getElementNamespaceInstanceProvider().start(language, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new X4OLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
languageModule.addElementNamespaceContext(namespace);
}
private ElementNamespaceContext createNamespaceContext(X4OLanguageLocal language,String id,String uri,String schemaUri,String schemaResource,String schemaPrefix) throws X4OLanguageModuleLoaderException {
logger.finer("Creating "+language.getLanguageName()+" namespace.");
ElementNamespaceContext namespace;
try {
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespaceContext());
@ -144,143 +219,27 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setId(CEL_CORE);
namespace.setUri(CEL_CORE_URI);
namespace.setSchemaUri(CEL_CORE_XSD_URI);
namespace.setSchemaResource(CEL_CORE_XSD_FILE);
namespace.setSchemaPrefix(CEL_CORE);
logger.finer("Loading elementClassList size: "+elementClassList.size());
for (ElementClass ecL:elementClassList) {
namespace.addElementClass(ecL);
}
addBindingHandler("cel-class-bind",new ElementClassBindingHandler(),elementLanguageModule);
addBindingHandler("cel-module-bind",new ElementModuleBindingHandler(),elementLanguageModule);
addBindingHandler("cel-class-attr-bind",new ElementClassAttributeBindingHandler(),elementLanguageModule);
addBindingHandler("cel-interface-bind",new ElementInterfaceBindingHandler(),elementLanguageModule);
addBindingHandler("cel-namespace-bind",new ElementNamespaceContextBindingHandler(),elementLanguageModule);
try {
namespace.getElementNamespaceInstanceProvider().start(language, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new X4OLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(namespace);
// And define root
try {
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespaceContext());
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
try {
namespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)
X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider())
);
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setId(CEL_ROOT);
namespace.setUri(CEL_ROOT_URI);
namespace.setSchemaUri(CEL_ROOT_XSD_URI);
namespace.setSchemaResource(CEL_ROOT_XSD_FILE);
namespace.setSchemaPrefix(CEL_ROOT);
namespace.addElementClass(new DefaultElementClass("module",language.getLanguageConfiguration().getDefaultElementLanguageModule(),ModuleElement.class));
namespace.setLanguageRoot(true); // Only define single language root so xsd is (mostly) not cicle import.
try {
namespace.getElementNamespaceInstanceProvider().start(language, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new X4OLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(namespace);
namespace.setId(id);
namespace.setUri(uri);
namespace.setSchemaUri(schemaUri);
namespace.setSchemaResource(schemaResource);
namespace.setSchemaPrefix(schemaPrefix);
return namespace;
}
/**
* Adds only Element class beans which need extra meta info for schema.
*
* @param elementClassList The list to fill.
* @throws X4OLanguageModuleLoaderException
*/
private void createElementClasses(List<ElementClass> elementClassList,X4OLanguage language) throws X4OLanguageModuleLoaderException {
ElementClass ec = null;
ElementClassAttribute attr = null;
ec = new DefaultElementClass("bindingHandler",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
attr = newElementClassAttribute(language);
attr.setName("id");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = newElementClassAttribute(language);
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
elementClassList.add(ec);
ec = new DefaultElementClass("attributeHandler",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
attr = newElementClassAttribute(language);
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
elementClassList.add(ec);
ec = new DefaultElementClass("configurator",null,BeanElement.class);
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
attr = newElementClassAttribute(language);
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = newElementClassAttribute(language);
attr.setName("configAction");
ec.addElementClassAttribute(attr);
elementClassList.add(ec);
ec = new DefaultElementClass("configuratorGlobal",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
attr = newElementClassAttribute(language);
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = newElementClassAttribute(language);
attr.setName("configAction");
ec.addElementClassAttribute(attr);
elementClassList.add(ec);
ec = new DefaultElementClass("description",null,DescriptionElement.class);
ec.setSchemaContentBase("string");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent(CEL_CORE_URI, "namespace");
ec.addElementParent(CEL_CORE_URI, "attributeHandler");
ec.addElementParent(CEL_CORE_URI, "bindingHandler");
ec.addElementParent(CEL_CORE_URI, "configurator");
ec.addElementParent(CEL_CORE_URI, "configuratorGlobal");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementParent(CEL_CORE_URI, "attribute");
elementClassList.add(ec);
ec = new DefaultElementClass("elementParent",null,ElementClassAddParentElement.class);
ec.addElementParent(CEL_CORE_URI, "element");
ec.addElementParent(CEL_CORE_URI, "elementInterface");
attr = newElementClassAttribute(language);
attr.setName("tag");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = newElementClassAttribute(language);
attr.setName("uri");
ec.addElementClassAttribute(attr);
elementClassList.add(ec);
private ElementClass createElementClass(X4OLanguage language,String tag,Class<?> objectClass,Class<?> elementClass,String description) throws X4OLanguageModuleLoaderException {
try {
ElementClass result = (ElementClass)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClass());
result.setTag(tag);
result.setObjectClass(objectClass);
result.setElementClass(elementClass);
result.setDescription(description);
return result;
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
}
}
/**
@ -289,9 +248,18 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
* @return The new ElementClassAttribute instance.
* @throws X4OLanguageModuleLoaderException When class could not be created.
*/
private ElementClassAttribute newElementClassAttribute(X4OLanguage language) throws X4OLanguageModuleLoaderException {
private ElementClassAttribute createElementClassAttribute(X4OLanguage language,String name,boolean required,ObjectConverter converter) throws X4OLanguageModuleLoaderException {
try {
return (ElementClassAttribute)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClassAttribute());
ElementClassAttribute result = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(language.getLanguageConfiguration().getDefaultElementClassAttribute());
result.setId(name); // ??
result.setName(name);
if (required) {
result.setRequired(required);
}
if (converter!=null) {
result.setObjectConverter(converter);
}
return result;
} catch (InstantiationException e) {
throw new X4OLanguageModuleLoaderException(this,e.getMessage(),e);
} catch (IllegalAccessException e) {
@ -303,10 +271,11 @@ public class EldModuleLoaderCore implements X4OLanguageModuleLoader {
* Adds binding handler to module.
* @param id The id to set on the handler.
* @param handler The handler to add the the module.
* @param elementLanguageModule The module to add the handler to.
* @param languageModule The module to add the handler to.
*/
private void addBindingHandler(String id,ElementBindingHandler handler,X4OLanguageModule elementLanguageModule) {
private void addBindingHandler(X4OLanguageModule languageModule,ElementBindingHandler handler,String id,String description) {
handler.setId(id);
elementLanguageModule.addElementBindingHandler(handler);
handler.setDescription(description);
languageModule.addElementBindingHandler(handler);
}
}

View file

@ -41,7 +41,8 @@ import org.x4o.xml.io.X4OSchemaWriter;
*/
public class X4OWriteLanguageSchemaExecutor {
private String language = null;
private String languageName = null;
private String languageVersion = null;
private String languageNamespaceUri = null;
private File basePath;
@ -73,10 +74,19 @@ public class X4OWriteLanguageSchemaExecutor {
System.exit(1);
return;
}
languageSchema.setLanguage(arguIterator.next());
languageSchema.setLanguageName(arguIterator.next());
continue;
}
if ("-verbose".equals(arg) || "-v".equals(arg)) {
if ("-version".equals(arg) || "-v".equals(arg)) {
if (arguIterator.hasNext()==false) {
System.err.println("No argument for "+arg+" given.");
System.exit(1);
return;
}
languageSchema.setLanguageVersion(arguIterator.next());
continue;
}
if ("-verbose".equals(arg) || "-V".equals(arg)) {
printStack = true;
}
}
@ -100,23 +110,37 @@ public class X4OWriteLanguageSchemaExecutor {
public void execute() throws ElementException {
// Start xsd generator
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguage());
X4OSchemaWriter xsd = driver.createSchemaWriter(driver.getLanguageVersionDefault());
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName());
X4OSchemaWriter xsd = driver.createSchemaWriter(getLanguageVersion());
xsd.writeSchema(getBasePath(), getLanguageNamespaceUri());
}
/**
* @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

@ -25,37 +25,11 @@ package org.x4o.xml.element;
/**
* The default ElementClass to store the Element information.
* DefaultElementClass stores the XML Element information.
*
* @author Willem Cazander
* @version 1.0 Feb 19, 2007
*/
public class DefaultElementClass extends AbstractElementClass {
/**
* Creates an default DefaultElementClass.
*/
public DefaultElementClass() {
}
/**
* Creates config-ed ElementClass.
* @param tag The tag of this ElementClass.
* @param objectClass The objectClass of the ElementClass.
*/
public DefaultElementClass(String tag,Class<?> objectClass) {
this(tag,objectClass,null);
}
/**
* Creates config-ed ElementClass.
* @param tag The tag of this ElementClass.
* @param objectClass The objectClass of the ElementClass.
* @param elementClass The elementClass of this ElementClass.
*/
public DefaultElementClass(String tag,Class<?> objectClass,Class<?> elementClass) {
setTag(tag);
setObjectClass(objectClass);
setElementClass(elementClass);
}
}

View file

@ -24,6 +24,7 @@
package org.x4o.xml.io;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
/**
* DefaultX4ODriver can be used to create language without code and type safty.
@ -41,9 +42,9 @@ public class DefaultX4ODriver<T> extends X4ODriver<T> {
}
public DefaultX4ODriver(String languageName,String languageVersion) {
super();
this.languageName=languageName;
this.languageVersion=languageVersion;
X4ODriverManager.registerX4ODriver(this);
}
@Override

View file

@ -259,7 +259,8 @@ public class XMLWriter extends DefaultHandler2 {
@Override
public void endElement(String uri, String localName, String name) throws SAXException {
if (startElement!=null) {
write(startElement.toString());
String tag = startElement.toString();
write(tag.substring(0,tag.length()-1));
write(XMLConstants.TAG_CLOSE_EMPTY);
startElement=null;
indent--;

View file

@ -55,21 +55,21 @@ public class X4OWriteLanguageSchemaExecutorTest extends TestCase {
public void testEldSchema() throws Exception {
X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor();
writer.setBasePath(getTempPath("junit-xsd-eld"));
writer.setLanguage(EldDriver.LANGUAGE_NAME);
writer.setLanguageName(EldDriver.LANGUAGE_NAME);
writer.execute();
}
public void testEldCoreSchema() throws Exception {
X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor();
writer.setBasePath(getTempPath("junit-xsd-cel"));
writer.setLanguage(CelDriver.LANGUAGE_NAME);
writer.setLanguageName(CelDriver.LANGUAGE_NAME);
writer.execute();
}
public void testSwiXmlSchema() throws Exception {
X4OWriteLanguageSchemaExecutor writer = new X4OWriteLanguageSchemaExecutor();
writer.setBasePath(getTempPath("junit-xsd-swixml2"));
writer.setLanguage(SwiXmlDriver.LANGUAGE_NAME);
writer.setLanguageName(SwiXmlDriver.LANGUAGE_NAME);
writer.execute();
}

View file

@ -23,18 +23,25 @@
package org.x4o.xml.test;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
import org.x4o.xml.io.DefaultX4ODriver;
import org.x4o.xml.io.X4OReaderContext;
import org.x4o.xml.io.X4OWriterContext;
import org.x4o.xml.test.models.TestObjectRoot;
public class TestDriver extends DefaultX4ODriver<TestObjectRoot> {
public class TestDriver extends X4ODriver<TestObjectRoot> {
static final public String LANGUAGE_NAME = "test";
static final public String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
public TestDriver() {
super(LANGUAGE_NAME);
@Override
public String getLanguageName() {
return LANGUAGE_NAME;
}
@Override
public String[] getLanguageVersions() {
return LANGUAGE_VERSIONS;
}
static public TestDriver getInstance() {

View file

@ -41,7 +41,7 @@ import org.x4o.xml.lang.X4OLanguageContext;
*/
public class X4OWriteLanguageDocExecutor {
private String language = null;
private String languageName = null;
private String languageVersion = null;
private File basePath;
@ -73,7 +73,7 @@ public class X4OWriteLanguageDocExecutor {
return;
}
String languageName = arguIterator.next();
languageSchema.setLanguage(languageName);
languageSchema.setLanguageName(languageName);
continue;
}
}
@ -88,7 +88,7 @@ public class X4OWriteLanguageDocExecutor {
}
public void execute() throws ElementException {
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguage());
X4ODriver<?> driver = X4ODriverManager.getX4ODriver(getLanguageName());
X4OLanguageContext context = driver.createLanguageContext(getLanguageVersion());
// Start doc generator
@ -111,17 +111,17 @@ public class X4OWriteLanguageDocExecutor {
}
/**
* @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;
}
/**

View file

@ -56,28 +56,28 @@ public class X4OWriteLanguageDocExecutorTest extends TestCase {
public void testCelDoc() throws Exception {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(getTempPath("junit-cel"));
writer.setLanguage(CelDriver.LANGUAGE_NAME);
writer.setLanguageName(CelDriver.LANGUAGE_NAME);
writer.execute();
}
public void testEldDoc() throws Exception {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(getTempPath("junit-eld"));
writer.setLanguage(EldDriver.LANGUAGE_NAME);
writer.setLanguageName(EldDriver.LANGUAGE_NAME);
writer.execute();
}
public void testUnitDoc() throws Exception {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(getTempPath("junit-test"));
writer.setLanguage(TestDriver.LANGUAGE_NAME);
writer.setLanguageName(TestDriver.LANGUAGE_NAME);
writer.execute();
}
public void testSwiXml2Doc() throws Exception {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(getTempPath("junit-swixml2"));
writer.setLanguage(SwiXmlDriver.LANGUAGE_NAME);
writer.setLanguageName(SwiXmlDriver.LANGUAGE_NAME);
writer.setLanguageVersion(SwiXmlDriver.LANGUAGE_VERSION_2);
writer.execute();
}
@ -85,7 +85,7 @@ public class X4OWriteLanguageDocExecutorTest extends TestCase {
public void testSwiXml3Doc() throws Exception {
X4OWriteLanguageDocExecutor writer = new X4OWriteLanguageDocExecutor();
writer.setBasePath(getTempPath("junit-swixml3"));
writer.setLanguage(SwiXmlDriver.LANGUAGE_NAME);
writer.setLanguageName(SwiXmlDriver.LANGUAGE_NAME);
writer.setLanguageVersion(SwiXmlDriver.LANGUAGE_VERSION_3);
writer.execute();
}

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>