From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- tags/java-stable-20060304/sdo/plugin/pom.xml | 42 ++++++ .../apache/tuscany/sdo/plugin/GeneratorMojo.java | 162 +++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 tags/java-stable-20060304/sdo/plugin/pom.xml create mode 100644 tags/java-stable-20060304/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java (limited to 'tags/java-stable-20060304/sdo/plugin') diff --git a/tags/java-stable-20060304/sdo/plugin/pom.xml b/tags/java-stable-20060304/sdo/plugin/pom.xml new file mode 100644 index 0000000000..925c1de881 --- /dev/null +++ b/tags/java-stable-20060304/sdo/plugin/pom.xml @@ -0,0 +1,42 @@ + + + + + org.apache.tuscany + tuscany-sdo + SNAPSHOT + + 4.0.0 + tuscany-sdo-plugin + maven-plugin + SNAPSHOT + Tuscany SDO Maven Plugin + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.tuscany + tuscany-sdo-tools + ${pom.version} + compile + + + diff --git a/tags/java-stable-20060304/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java b/tags/java-stable-20060304/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java new file mode 100644 index 0000000000..9ded67e657 --- /dev/null +++ b/tags/java-stable-20060304/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java @@ -0,0 +1,162 @@ +/** + * + * Copyright 2005 BEA Systems Inc. + * Copyright 2005 International Business Machines Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.sdo.plugin; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.List; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +import org.apache.tuscany.sdo.generate.JavaGenerator; + +/** + * @version $Rev$ $Date$ + * @goal generate + * @phase generate-sources + * @description Generate SDO interface classes from an XML Schema + */ +public class GeneratorMojo extends AbstractMojo { + /** + * The directory containing schema files; defaults to ${basedir}/src/main/xsd + * @parameter expression="${basedir}/src/main/xsd" + */ + private String schemaDir; + + /** + * Name of the schema file; if omitted all files in the directory are processed + * @parameter + */ + private File schemaFile; + + /** + * The Java package to generate into. By default the value is derived from the schema URI. + * + * @parameter + */ + private String javaPackage; + + /** + * The directory to generate into; defaults to ${project.build.directory}/sdo-source + * + * @parameter expression="${project.build.directory}/sdo-source" + */ + private String targetDirectory; + + /** + * Specifies the prefix string to use for naming the generated factory. + * @parameter + */ + private String prefix; + + /** + * This option can be used to eliminate the generated interface and to generate only an implementation class. + * @parameter + */ + private boolean noInterfaces; + + /** + * Turns off container management for containment properties. + * @parameter + */ + private boolean noContainment; + + /** + * This option eliminates all change notification overhead in the generated classes. + * @parameter + */ + private boolean noNotification; + + /** + * With this option, all generated properties will not record their unset state. + * @parameter + */ + private boolean noUnsettable; + + /** + * Generate a fast XML parser/loader for instances of the model. + * @parameter + */ + private boolean generateLoader; + + /** + * Generate a Switch class for the model. + * @parameter + */ + private boolean generateSwitch; + + /** + * @parameter expression="${project.compileSourceRoots}" + * @readonly + */ + private List compilerSourceRoots; + + public void execute() throws MojoExecutionException { + File[] files; + if (schemaFile == null) { + files = new File(schemaDir).listFiles(FILTER); + } else { + files = new File[]{schemaFile}; + } + + int genOptions = 0; + if (noInterfaces) { + genOptions |= JavaGenerator.OPTION_NO_INTERFACES; + } + if (noContainment) { + genOptions |= JavaGenerator.OPTION_NO_CONTAINMENT; + } + if (noNotification) { + genOptions |= JavaGenerator.OPTION_NO_NOTIFICATION; + } + if (generateLoader) { + genOptions |= JavaGenerator.OPTION_GENERATE_LOADER; + } + if (noUnsettable) { + genOptions |= JavaGenerator.OPTION_NO_UNSETTABLE; + } + if (generateSwitch) { + genOptions |= JavaGenerator.OPTION_GENERATE_SWITCH; + } + + for (int i = 0; i < files.length; i++) { + File file = files[i]; + File marker = new File(targetDirectory, ".gen#" + file.getName()); + if (file.lastModified() > marker.lastModified()) { + getLog().info("Generating SDO interfaces from " + file); + JavaGenerator.generateFromXMLSchema(file.toString(), targetDirectory, javaPackage, prefix, genOptions); + } + try { + marker.createNewFile(); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + marker.setLastModified(System.currentTimeMillis()); + } + + compilerSourceRoots.add(targetDirectory); + } + + private static final FileFilter FILTER = new FileFilter() { + public boolean accept(File pathname) { + return (pathname.isFile() || !pathname.isHidden()); + } + }; +} \ No newline at end of file -- cgit v1.2.3