From 6f453177536e7eebffdcc87b3b440c6a20ff2ac7 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Thu, 11 Apr 2013 09:26:38 +0200 Subject: [PATCH] Started working on maven plugin and refactored the cel language loader. --- build.txt | 6 + src/site/site.xml | 10 +- .../java/org/x4o/xml/X4ODriverManager.java | 6 + .../main/java/org/x4o/xml/eld/CelDriver.java | 2 +- .../org/x4o/xml/eld/EldModuleLoaderCore.java | 325 ++++++++---------- .../xsd/X4OWriteLanguageSchemaExecutor.java | 46 ++- .../x4o/xml/element/DefaultElementClass.java | 30 +- .../java/org/x4o/xml/io/DefaultX4ODriver.java | 3 +- .../java/org/x4o/xml/io/sax/XMLWriter.java | 3 +- .../X4OWriteLanguageSchemaExecutorTest.java | 6 +- .../java/org/x4o/xml/test/TestDriver.java | 15 +- .../eld/doc/X4OWriteLanguageDocExecutor.java | 18 +- .../doc/X4OWriteLanguageDocExecutorTest.java | 10 +- x4o-plugin/pom.xml | 1 + x4o-plugin/x4o-plugin-ant/pom.xml | 16 +- .../plugin/ant/AbstractX4OLanguageTask.java | 53 ++- .../plugin/ant/X4OWriteLanguageDocTask.java | 3 +- .../ant/X4OWriteLanguageSchemaTask.java | 3 +- .../ant/X4OWriteLanguageDocTaskTest.java | 2 +- .../ant/X4OWriteLanguageSchemaTaskTest.java | 2 +- .../test-write-language-doc.xml | 12 +- .../test-write-language-schema.xml | 12 +- x4o-plugin/x4o-plugin-maven/.project | 23 ++ x4o-plugin/x4o-plugin-maven/pom.xml | 125 +++++++ .../plugin/maven/AbstractX4OLanguageMojo.java | 189 ++++++++++ .../plugin/maven/X4OWriteLanguageDocMojo.java | 61 ++++ .../maven/X4OWriteLanguageSchemaMojo.java | 61 ++++ .../org/x4o/plugin/maven/package-info.java | 30 ++ .../maven/X4OWriteLanguageDocMojoTest.java | 95 +++++ .../junit/test-write-language-doc.pom | 33 ++ 30 files changed, 913 insertions(+), 288 deletions(-) rename x4o-plugin/x4o-plugin-ant/src/test/resources/{tests => junit}/test-write-language-doc.xml (90%) rename x4o-plugin/x4o-plugin-ant/src/test/resources/{tests => junit}/test-write-language-schema.xml (91%) create mode 100644 x4o-plugin/x4o-plugin-maven/.project create mode 100644 x4o-plugin/x4o-plugin-maven/pom.xml create mode 100644 x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/AbstractX4OLanguageMojo.java create mode 100644 x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojo.java create mode 100644 x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageSchemaMojo.java create mode 100644 x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/package-info.java create mode 100644 x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java create mode 100644 x4o-plugin/x4o-plugin-maven/src/test/resources/junit/test-write-language-doc.pom diff --git a/build.txt b/build.txt index 3148c65..170a8db 100644 --- a/build.txt +++ b/build.txt @@ -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 diff --git a/src/site/site.xml b/src/site/site.xml index 0d89da4..621c55c 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -52,11 +52,11 @@ - - - - - + + + + + diff --git a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java index 3eb96cc..0680232 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java +++ b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java @@ -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); } diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java b/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java index d1de632..54dc2ae 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/CelDriver.java @@ -45,6 +45,6 @@ public class CelDriver extends X4ODriver { @Override public String[] getLanguageVersions() { - return null; + return LANGUAGE_VERSIONS; } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java b/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java index 026bc83..89d9975 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/EldModuleLoaderCore.java @@ -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 elementClassList = new ArrayList(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); + + // 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); + } + + /** + * 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; - ElementClassAttribute 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.")); - DefaultElementClass ns = new DefaultElementClass("namespace",language.getLanguageConfiguration().getDefaultElementNamespaceContext()); - attr = newElementClassAttribute(language); - attr.setName("uri"); - attr.setRequired(true); - ns.addElementClassAttribute(attr); - elementClassList.add(ns); + ec = createElementClass(language,"namespace",language.getLanguageConfiguration().getDefaultElementNamespaceContext(),null,"Defines an xml namespace."); + ec.addElementClassAttribute(createElementClassAttribute(language,"uri",true,null)); + namespace.addElementClass(ec); - DefaultElementClass dec = new DefaultElementClass("element",language.getLanguageConfiguration().getDefaultElementClass()); - attr = newElementClassAttribute(language); - attr.setName("objectClass"); - attr.setObjectConverter(new ClassConverter()); - dec.addElementClassAttribute(attr); + 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); - attr = newElementClassAttribute(language); - attr.setName("elementClass"); - attr.setObjectConverter(new ClassConverter()); - dec.addElementClassAttribute(attr); - elementClassList.add(dec); + ec = createElementClass(language,"elementInterface",language.getLanguageConfiguration().getDefaultElementInterface(),null,"Defines element interface class."); + ec.addElementClassAttribute(createElementClassAttribute(language,"interfaceClass",false,new ClassConverter())); + 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,"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); - logger.finer("Creating eldcore namespace."); + 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 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); } } diff --git a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java index 4da0df0..5c89308 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java +++ b/x4o-driver/src/main/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutor.java @@ -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; } /** diff --git a/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementClass.java b/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementClass.java index 3cc1d77..f19ee34 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementClass.java +++ b/x4o-driver/src/main/java/org/x4o/xml/element/DefaultElementClass.java @@ -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); - } + } diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java index dd7581c..7d016c3 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/DefaultX4ODriver.java @@ -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 extends X4ODriver { } public DefaultX4ODriver(String languageName,String languageVersion) { - super(); this.languageName=languageName; this.languageVersion=languageVersion; + X4ODriverManager.registerX4ODriver(this); } @Override diff --git a/x4o-driver/src/main/java/org/x4o/xml/io/sax/XMLWriter.java b/x4o-driver/src/main/java/org/x4o/xml/io/sax/XMLWriter.java index 587ee40..9e3b664 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/io/sax/XMLWriter.java +++ b/x4o-driver/src/main/java/org/x4o/xml/io/sax/XMLWriter.java @@ -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--; diff --git a/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java b/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java index 39be25a..834d103 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/eld/xsd/X4OWriteLanguageSchemaExecutorTest.java @@ -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(); } diff --git a/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java b/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java index e86cd3e..d10eaa7 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java +++ b/x4o-driver/src/test/java/org/x4o/xml/test/TestDriver.java @@ -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 { +public class TestDriver extends X4ODriver { 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() { diff --git a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java index 4c24659..10d84d4 100644 --- a/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java +++ b/x4o-elddoc/src/main/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutor.java @@ -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; } /** diff --git a/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutorTest.java b/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutorTest.java index c9e9727..d8af6a0 100644 --- a/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutorTest.java +++ b/x4o-elddoc/src/test/java/org/x4o/xml/eld/doc/X4OWriteLanguageDocExecutorTest.java @@ -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(); } diff --git a/x4o-plugin/pom.xml b/x4o-plugin/pom.xml index bd2085a..f63a471 100644 --- a/x4o-plugin/pom.xml +++ b/x4o-plugin/pom.xml @@ -13,6 +13,7 @@ x4o plugins for other applications x4o-plugin-ant + x4o-plugin-maven diff --git a/x4o-plugin/x4o-plugin-ant/pom.xml b/x4o-plugin/x4o-plugin-ant/pom.xml index afee6b5..1968713 100644 --- a/x4o-plugin/x4o-plugin-ant/pom.xml +++ b/x4o-plugin/x4o-plugin-ant/pom.xml @@ -86,7 +86,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -141,7 +141,7 @@ - site-elddoc + site-elddoc2 @@ -161,11 +161,11 @@ - - - - - + + + + + diff --git a/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/AbstractX4OLanguageTask.java b/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/AbstractX4OLanguageTask.java index 68c2dff..f8aa45b 100644 --- a/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/AbstractX4OLanguageTask.java +++ b/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/AbstractX4OLanguageTask.java @@ -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; } /** diff --git a/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageDocTask.java b/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageDocTask.java index bfa9022..2ca9419 100644 --- a/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageDocTask.java +++ b/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageDocTask.java @@ -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) { diff --git a/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTask.java b/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTask.java index e6a3bfe..c69f73b 100644 --- a/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTask.java +++ b/x4o-plugin/x4o-plugin-ant/src/main/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTask.java @@ -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(); diff --git a/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageDocTaskTest.java b/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageDocTaskTest.java index faff422..1af0285 100644 --- a/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageDocTaskTest.java +++ b/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageDocTaskTest.java @@ -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() { diff --git a/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTaskTest.java b/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTaskTest.java index f01a022..c6df6f3 100644 --- a/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTaskTest.java +++ b/x4o-plugin/x4o-plugin-ant/src/test/java/org/x4o/plugin/ant/X4OWriteLanguageSchemaTaskTest.java @@ -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() { diff --git a/x4o-plugin/x4o-plugin-ant/src/test/resources/tests/test-write-language-doc.xml b/x4o-plugin/x4o-plugin-ant/src/test/resources/junit/test-write-language-doc.xml similarity index 90% rename from x4o-plugin/x4o-plugin-ant/src/test/resources/tests/test-write-language-doc.xml rename to x4o-plugin/x4o-plugin-ant/src/test/resources/junit/test-write-language-doc.xml index 1598db3..7421f26 100644 --- a/x4o-plugin/x4o-plugin-ant/src/test/resources/tests/test-write-language-doc.xml +++ b/x4o-plugin/x4o-plugin-ant/src/test/resources/junit/test-write-language-doc.xml @@ -37,7 +37,7 @@ @@ -46,7 +46,7 @@ @@ -54,7 +54,7 @@ @@ -62,16 +62,16 @@ - + - + - + \ No newline at end of file diff --git a/x4o-plugin/x4o-plugin-ant/src/test/resources/tests/test-write-language-schema.xml b/x4o-plugin/x4o-plugin-ant/src/test/resources/junit/test-write-language-schema.xml similarity index 91% rename from x4o-plugin/x4o-plugin-ant/src/test/resources/tests/test-write-language-schema.xml rename to x4o-plugin/x4o-plugin-ant/src/test/resources/junit/test-write-language-schema.xml index 3b4eb68..1ffdf91 100644 --- a/x4o-plugin/x4o-plugin-ant/src/test/resources/tests/test-write-language-schema.xml +++ b/x4o-plugin/x4o-plugin-ant/src/test/resources/junit/test-write-language-schema.xml @@ -37,7 +37,7 @@ @@ -45,7 +45,7 @@ @@ -55,7 +55,7 @@ @@ -64,16 +64,16 @@ - + - + - + \ No newline at end of file diff --git a/x4o-plugin/x4o-plugin-maven/.project b/x4o-plugin/x4o-plugin-maven/.project new file mode 100644 index 0000000..d75c8de --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/.project @@ -0,0 +1,23 @@ + + + x4o-plugin-maven + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/x4o-plugin/x4o-plugin-maven/pom.xml b/x4o-plugin/x4o-plugin-maven/pom.xml new file mode 100644 index 0000000..92d3128 --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/pom.xml @@ -0,0 +1,125 @@ + + 4.0.0 + + org.x4o.plugin + x4o-plugin + 0.8.5-SNAPSHOT + + x4o-plugin-maven + maven-plugin + x4o-plugin-maven + x4o-plugin-maven + + + org.x4o + x4o-driver + ${project.version} + + + org.x4o + x4o-elddoc + ${project.version} + + + org.apache.maven + maven-plugin-api + 3.0 + provided + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.2 + provided + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 2.0 + test + + + + org.codehaus.plexus + plexus-utils + 3.0.1 + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.2 + + true + + + + mojo-descriptor + descriptor + + + mojo-help + helpmojo + + + + + + + + site-elddoc + + + + org.x4o.plugin + x4o-plugin-maven + ${project.version} + + + site-elddoc-maven + pre-site + + ${basedir}/../../target/site/elddocs + + ALL + ALL + ALL + 2.0-3.0 + + + + write-language-doc + + + + + + org.x4o + x4o-driver + ${project.version} + + + org.x4o + x4o-driver + ${project.version} + test-jar + + + org.x4o + x4o-elddoc + ${project.version} + + + de.odysseus.juel + juel + ${juel.version} + + + + + + + + \ No newline at end of file diff --git a/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/AbstractX4OLanguageMojo.java b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/AbstractX4OLanguageMojo.java new file mode 100644 index 0000000..597666f --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/AbstractX4OLanguageMojo.java @@ -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 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 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; + } +} diff --git a/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojo.java b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojo.java new file mode 100644 index 0000000..4a0acb7 --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojo.java @@ -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); + } + } +} diff --git a/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageSchemaMojo.java b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageSchemaMojo.java new file mode 100644 index 0000000..bbfc6fb --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/X4OWriteLanguageSchemaMojo.java @@ -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); + } + } +} diff --git a/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/package-info.java b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/package-info.java new file mode 100644 index 0000000..fe0e808 --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/src/main/java/org/x4o/plugin/maven/package-info.java @@ -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; \ No newline at end of file diff --git a/x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java b/x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java new file mode 100644 index 0000000..cd7d51f --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/src/test/java/org/x4o/plugin/maven/X4OWriteLanguageDocMojoTest.java @@ -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."); + } + */ +} diff --git a/x4o-plugin/x4o-plugin-maven/src/test/resources/junit/test-write-language-doc.pom b/x4o-plugin/x4o-plugin-maven/src/test/resources/junit/test-write-language-doc.pom new file mode 100644 index 0000000..be69750 --- /dev/null +++ b/x4o-plugin/x4o-plugin-maven/src/test/resources/junit/test-write-language-doc.pom @@ -0,0 +1,33 @@ + + 4.0.0 + org.x4o.plugin.junit + x4o-plugin-maven-test + 1.0.0-SNAPSHOT + jar + x4o-plugin-maven-test + + + junit + junit + 4.10 + test + + + + + + x4o-plugin-maven + + target/jtest/write-language-doc + + ALL + ALL + + + + + + \ No newline at end of file