Author: tchemit Date: 2010-06-29 13:50:43 +0200 (Tue, 29 Jun 2010) New Revision: 931 Url: http://nuiton.org/repositories/revision/eugene/931 Log: Evolution #713: Remove deprecated mojos Evolution #735: Use mavenpom 2.2.2 Evolution #736: Use maven-helper-plugin 1.2.6 Removed: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java trunk/pom.xml Deleted: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java 2010-06-29 11:50:43 UTC (rev 931) @@ -1,193 +0,0 @@ -/* - * #%L - * EUGene :: Maven plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2006 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.eugene.plugin; - -import org.nuiton.plugin.PluginIOContext; - -import java.io.File; -import java.util.Arrays; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; -import org.apache.maven.settings.Settings; -import org.nuiton.plugin.AbstractPlugin; - -/** - * La classe de base pour definir des mojos dans eugene. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.0-rc-8 - */ -public abstract class EugeneAbstractMojo extends AbstractPlugin { - - /** - * Maven project. - * - * @parameter default-value="${project}" - * @readonly - * @since 1.0.0-rc-8 - */ - protected MavenProject project; - /** - * Le settings (pour obtenir le mode offline). - * - * @parameter default-value="${settings}" - * @readonly - * @since 1.0.0-rc-4 - */ - protected Settings settings; - /** - * Ecrase les fichiers générés. - * - * @parameter expression="${eugene.overwrite}" default-value="false" - * @since 0.50 - */ - protected boolean overwrite; - /** - * Pour activer le mode verbeux. - * - * @parameter expression="${eugene.verbose}" default-value="${maven.verbose}" - * @since 1.0.0-rc-8 - */ - protected boolean verbose; - /** - * Encoding to be used for generation of files. - * - * @parameter expression="${eugene.encoding}" default-value="${project.build.sourceEncoding}" - * @since 0.60 - */ - protected String encoding; - /** - * A flag to mark the mojo to be used in a test phase. This will permits - * to add generated sources in test compile roots. - * - * @parameter expression="${eugene.testPhase}" default-value="false" - * @since 0.64 - */ - protected boolean testPhase; - - /** - * Note : l'objet peut etre {@code null} si la configuration ne definit - * pas la propriété associées dans l'implentation. - * <p/> - * Dans tous les cas, une fois la methode {@link #initResources()} appele, - * l'objet devrait ne plus être null! - * - * @return l'io du plugin ou {@code null} si non initialisé - */ - protected abstract PluginIOContext getResources(); - - /** - * Initialiser les io du plugins. - * - * @return l'io intialisé (avec les valeurs par défaut, là où rien n'a - * été renseigné). - */ - protected abstract PluginIOContext initResources(); - - /** - * Build the {@link #getResources()} data. - * - * @param defaultIn the default input directory - * @param defaultOut the default output directory - * @param defaultTestIn the default test input directory - * @param defaultTestOut the default test output directory - * @return the new {@link PluginIOContext} to use in the goal - */ - protected PluginIOContext initResources(File defaultIn, - File defaultOut, - File defaultTestIn, - File defaultTestOut) { - - PluginIOContext resources = getResources(); - if (resources == null) { - resources = new PluginIOContext(); - } - - // adding default inputs only if not consumed - if (resources.getInputs() == null) { - if (testPhase) { - resources.setInput(defaultTestIn); - } else { - resources.setInput(defaultIn); - } - getLog().info(" using default in : " + - Arrays.asList(resources.getInputs())); - } else { - getLog().info(" in : " + - Arrays.asList(resources.getInputs())); - } - - if (resources.getOutput() == null) { - if (testPhase) { - resources.setOutput(defaultTestOut); - } else { - resources.setOutput(defaultOut); - } - getLog().info(" using default out : " + resources.getOutput()); - } else { - getLog().info(" out : " + resources.getOutput()); - } - - return resources; - } - - @Override - protected void init() throws Exception { - - // init goal io context - PluginIOContext p = initResources(); - - if (p.getInputs() == null || p.getInputs().length == 0) { - throw new MojoExecutionException("no input defined"); - } - if (p.getOutput() == null) { - throw new MojoExecutionException("no output defined"); - } - - createDirectoryIfNecessary(p.getOutput()); - } - - @Override - public MavenProject getProject() { - return project; - } - - @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setProject(MavenProject project) { - this.project = project; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } -} Deleted: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2010-06-29 11:50:43 UTC (rev 931) @@ -1,458 +0,0 @@ -/* - * #%L - * EUGene :: Maven plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2006 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.eugene.plugin; - -import org.apache.commons.lang.StringUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Resource; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.project.MavenProject; -import org.nuiton.eugene.DefaultTemplateConfiguration; -import org.nuiton.eugene.ModelReader; -import org.nuiton.eugene.Template; -import org.nuiton.eugene.models.Model; -import org.nuiton.plugin.PluginHelper; -import org.nuiton.plugin.PluginIOContext; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.*; -import java.util.Map.Entry; - -/** - * Effectue toutes les générations et copie les fichiers générés - * dans le répertoire de compilation - * - * @author ruchaud - * @version $Revision$ - * <p/> - * Last update: $Date$ - * by : * @goal generate - * @requiresProject true - * @deprecated since 2.0.0, use now the {@link SmartGenerateMojo}. - */ -@Deprecated -public class EugenePlugin extends EugeneAbstractMojo { - - /** - * Les entrées sorties du plugin. - * <p/> - * <p/> - * <p/> - * En entrée on demande des répertoires où chercher les fichiers - * objectmodel a convertir. - * <p/> - * En sortie on demande le répertoire ou generer les classes java. - * <p/> - * Par défaut on a les valeurs suivantes : - * </p> - * <pre> - * <generateResources> - * </p> - * <input>target/generated-sources/models</input> - * </p> - * <output>target/generated-sources/java</output> - * </p> - * </generateResources> - * </pre> - * </p> - * <p/> - * Note: si {@link #testPhase} est activée, les valeurs par défaut sont : - * </p> - * <pre> - * <generateResources> - * </p> - * <input>target/generated-sources/test-models</input> - * </p> - * <output>target/generated-sources/test-java</output> - * </p> - * </generateResources> - * </pre> - * - * @parameter - * @since 1.0.0-rc-8 - */ - protected PluginIOContext generateResources; - /** - * Templates à utiliser, séparés par des virgules. - * - * @parameter expression="${eugene.templates}" - * @required - * @since 0.50 - */ - protected String templates; - /** - * Templates à ne pas utiliser. - * - * @parameter expression="${eugene.excludeTemplates}" - * @since 0.63 - */ - protected String[] excludeTemplates; - /** - * Fichier à inclure. - * - * @parameter expression="${eugene.includes}" default-value="*.*model" - * @since 0.50 - */ - protected String includes; - /** - * Nom par défaut du paquetage généré. - * - * @parameter expression="${eugene.defaultPackage}" default-value="${project.groupId}.${project.artifactId}" - * @since 0.50 - */ - protected String defaultPackage; - /** - * An extra directory to be added to the classpath. - * - * @parameter expression="${eugene.extraClassPathDirectory}" - * @since 0.63 - */ - protected File extraClassPathDirectory; - /** - * List of packages to generate (comma separated). - * <p/> - * If the parameter is not filled, will generate all packages. - * - * @parameter expression="${eugene.generatedPackages}" - * @since 1.0.0-rc-8 - */ - protected String generatedPackages; - - /** - * Reader for transform input files in a Model to generate - * - * @parameter expression="${eugene.reader}" - * @since 1.1.0 - */ - protected String reader; - - - @Override - public void doAction() throws Exception { - - getLog().info("Generating java sources from models"); - getLog().info(" reader : " + reader); - getLog().info(" includes : " + includes); - getLog().info(" using template : " + templates); - getLog().info(" using defaultPackage : " + defaultPackage); - - File[] modelFiles = getModelFiles(); - if (modelFiles.length == 0) { - // can skip - getLog().warn("no model to treate"); - return; - } - if (verbose) { - for (File m : modelFiles) { - getLog().info("will treate model file : " + m); - } - } - ModelReader<?> modelReader = getReader(); - generate(modelFiles, modelReader); - - fixCompileSourceRoots(); - } - - protected <M extends Model> void generate( - File[] modelFiles, ModelReader<M> modelReader) throws Exception { - - if (modelReader == null) { - // can skip - getLog().warn("no reader to use"); - return; - } - M model = modelReader.read(modelFiles); - - if (StringUtils.isEmpty(generatedPackages)) { - getLog().info(" generating all packages"); - } else { - getLog().info(" generating only for packages " + generatedPackages); - } - - List<Template<M>> templatesList = getTemplates(modelReader); - - for (Template<M> template : templatesList) { - getLog().info("Apply " + template.getClass().getSimpleName() + - " generator"); - - template.applyTemplate(model, generateResources.getOutput()); - } - } - - @Override - protected PluginIOContext getResources() { - return generateResources; - } - - @Override - protected PluginIOContext initResources() { - - File defaultIn = getFileFromBasedir("target", "generated-sources", - "models"); - File defaultOut = getFileFromBasedir("target", "generated-sources", - "java"); - - File defaultTestIn = getFileFromBasedir("target", "generated-sources", - "test-models"); - File defaultTestOut = getFileFromBasedir("target", "generated-sources", - "test-java"); - - generateResources = initResources( - defaultIn, - defaultOut, - defaultTestIn, - defaultTestOut - ); - - return generateResources; - } - - /** - * Recuperation de la liste des fichiers de modele a traite. - * - * @return la liste des modeles a utiliser - */ - protected File[] getModelFiles() { - List<File> modelFiles = new ArrayList<File>(); - String[] includePatterns = includes.split(","); - - for (File srcDirGen : generateResources.getInputs()) { - - if (verbose) { - getLog().info("Search for " + Arrays.toString(includePatterns) - + " in " + srcDirGen.getAbsolutePath()); - } - List<File> currentFiles = PluginHelper.getIncludedFiles( - srcDirGen, - includePatterns, - null - ); - modelFiles.addAll(currentFiles); - } - return modelFiles.toArray(new File[modelFiles.size()]); - } - - protected ModelReader<?> getReader() throws MojoFailureException, - MojoExecutionException { - ModelReader<?> modelReader; - try { - ClassLoader fixedClassLoader = fixClassLoader(); - modelReader = (ModelReader<?>) Class.forName( - reader, - true, - fixedClassLoader).newInstance(); - } catch (InstantiationException eee) { - throw new MojoFailureException("Can't instantiate reader : " + - reader, eee); - } catch (IllegalAccessException eee) { - throw new MojoFailureException("Can't access reader : " + reader, - eee); - } catch (ClassNotFoundException eee) { - throw new MojoFailureException("Can't found reader : " + reader, - eee); - } - return modelReader; - } - - @SuppressWarnings("unchecked") - protected <M extends Model> List<Template<M>> getTemplates( - ModelReader<M> modelReader) - throws MojoFailureException, MojoExecutionException { - // init generators - Properties templateProperties = new Properties(); - templateProperties.setProperty(Template.PROP_DEFAULT_PACKAGE, - defaultPackage); - templateProperties.setProperty(Template.PROP_OVERWRITE, - String.valueOf(overwrite)); - templateProperties.setProperty(Template.PROP_ENCODING, encoding); - templateProperties.setProperty( - Template.PROP_LAST_MODIFIED_SOURCE, - String.valueOf(modelReader.getLastModifiedSource())); - if (generatedPackages != null) { - templateProperties.setProperty(Template.PROP_GENERATED_PACKAGES, - generatedPackages); - } - templateProperties.setProperty(Template.PROP_EXCLUDE_TEMPLATES, - getExcludeTemplatesAsString()); - - List<Template<M>> templatesList = new ArrayList<Template<M>>(); - String[] templatesNames = templates.split(","); - ClassLoader fixedClassLoader = fixClassLoader(); - for (String templateName : templatesNames) { - // remove trailing spaces - templateName = templateName.trim(); - try { - Template<M> template = (Template<M>) Class.forName(templateName, - true, fixedClassLoader).newInstance(); - // configuration - template.setConfiguration(new DefaultTemplateConfiguration(templateProperties)); -// template.setProperties(templateProperties); - templatesList.add(template); - } catch (InstantiationException e) { - throw new MojoFailureException("Can't instantiate generator : " - + templateName, e); - } catch (IllegalAccessException e) { - throw new MojoFailureException("Can't access generator : " + - templateName, e); - } catch (ClassNotFoundException e) { - throw new MojoFailureException("Can't found generator : " + - templateName, e); - } - } - return templatesList; - } - - protected String getExcludeTemplatesAsString() { - String result = ""; - for (int i = 0; i < excludeTemplates.length; i++) { - result += excludeTemplates[i]; - if (i != excludeTemplates.length - 1) { - result += ","; - } - } - return result; - } - - /** - * permet d'ajout le répertoire de génération des fichiers java dans les - * répertoires de compilation du projet Maven. - */ - protected void fixCompileSourceRoots() { - - if (project == null) { - // no project defined, can not fix anything - // this case could appears if we wanted to do some tests of the - // plugin - return; - } - - File destDirGen = generateResources.getOutput(); - - //TODO-TC20091016 should use AbstractPlugin api - if (testPhase) { - if (!project.getTestCompileSourceRoots().contains( - destDirGen.getPath())) { - getLog().info("Add test compile source root : " + destDirGen); - project.addTestCompileSourceRoot(destDirGen.getPath()); - Resource resources = new Resource(); - resources.setDirectory(destDirGen.getAbsolutePath()); - resources.setExcludes(Arrays.asList("**/*.java")); - getLog().info("Add test resource root :" + resources); - project.addTestResource(resources); - } - } else { - if (!project.getCompileSourceRoots().contains( - destDirGen.getPath())) { - getLog().info("Add compile source root : " + destDirGen); - project.addCompileSourceRoot(destDirGen.getPath()); - Resource resources = new Resource(); - resources.setDirectory(destDirGen.getAbsolutePath()); - resources.setExcludes(Arrays.asList("**/*.java")); - getLog().info("Add resource root :" + resources); - project.addResource(resources); - } - } - } - - /** - * Prepare le classLoader a utiliser dans le generateur. - * <p/> - * Si un {@link #extraClassPathDirectory} a été renseigné, il est rajouté. - * <p/> - * Si des références à des sibling modules, ils seront rajoutés aussi. - * - * @return le class loader modifie - * @throws MojoExecutionException if any pb - */ - protected ClassLoader fixClassLoader() throws MojoExecutionException { - List<URL> urls = new ArrayList<URL>(); - Set<String> urlsAsString = new HashSet<String>(); - try { - ClassLoader loader = null; - if (extraClassPathDirectory != null) { - if (verbose) { - getLog().info("Add extra directory in generator's" + - " classLoader : " + extraClassPathDirectory); - } - addDirectoryToUrlsList( - extraClassPathDirectory, - urls, - urlsAsString - ); - } - if (project.getProjectReferences() != null) { - // this case is for multi-module when calling from a parent - // module - for (Object o : project.getProjectReferences().entrySet()) { - Entry<?, ?> entry = (Entry<?, ?>) o; - MavenProject relatedProject = - (MavenProject) entry.getValue(); - if (verbose) { - getLog().info("Add project reference in " + - "generator's classLoader : '" + - relatedProject.getArtifact() + "'"); - } - //TODO il faudrait peut-etre aussi ajouter les dependances ? - addDirectoryToUrlsList( - relatedProject.getArtifact().getFile(), - urls, - urlsAsString - ); - } - } - if (!project.getArtifacts().isEmpty()) { - // this is a special case when artifacts were resolved (for - // example in site phase) - if (verbose) { - getLog().info("Use resolved artifacts to build class-path"); - } - for (Object o : project.getArtifacts()) { - Artifact a = (Artifact) o; - if (!a.getScope().equals("provided")) { - addDirectoryToUrlsList(a.getFile(), urls, urlsAsString); - } - } - } - // we ask to add the directory in classloader - loader = getClass().getClassLoader(); - if (!urls.isEmpty()) { - loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), - loader); - } - return loader; - } catch (MalformedURLException e) { - throw new MojoExecutionException(e.getMessage()); - } finally { - urls.clear(); - urlsAsString.clear(); - } - - } -} Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java 2010-06-29 11:50:43 UTC (rev 931) @@ -44,6 +44,7 @@ import org.nuiton.eugene.writer.ChainedWriterEngine; import org.nuiton.eugene.writer.WriterReport; import org.nuiton.plugin.AbstractPlugin; +import org.nuiton.plugin.PluginWithEncoding; import org.nuiton.util.StringUtil; import java.io.File; @@ -71,7 +72,7 @@ * @requiresProject true * @requiresDependencyResolution compile */ -public class SmartGenerateMojo extends AbstractPlugin implements ChainedFileWriterConfiguration { +public class SmartGenerateMojo extends AbstractPlugin implements ChainedFileWriterConfiguration, PluginWithEncoding { /** * Inputs files to used to generate the required model files. @@ -153,6 +154,9 @@ /** * Encoding to be used for generation of files. + * <p/> + * <b>Note:</b> If nothing is filled here, we will use the system + * property {@code file.encoding}. * * @parameter expression="${eugene.encoding}" default-value="${project.build.sourceEncoding}" * @since 2.0.0 @@ -574,6 +578,11 @@ } @Override + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + @Override public boolean isOverwrite() { return overwrite; } Deleted: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java 2010-06-29 11:50:43 UTC (rev 931) @@ -1,466 +0,0 @@ -/* - * #%L - * EUGene :: Maven plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2006 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.eugene.plugin; - -import org.nuiton.plugin.PluginIOContext; -import java.io.File; -import java.io.FileOutputStream; -import java.lang.reflect.Constructor; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -import java.util.Map.Entry; -import java.util.Set; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.URIResolver; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; -import org.nuiton.plugin.PluginHelper; -import org.nuiton.util.FasterCachedResourceResolver; -import org.nuiton.util.FileUtil; -import org.nuiton.util.Resource; -import org.nuiton.util.ResourceResolver; -import org.nuiton.util.StringUtil; - -/** - * Converti les fichiers XMI en fichier Model via une transformation XSLT a - * définir. - * - * Class abstraite sans feuille de style ni extension. - * - * @author ruchaud - * @version $Revision$ - * - * Last update: $Date$ - * by : */ -public abstract class Xmi2Model extends EugeneAbstractMojo { - - /** - * Les entrées sorties du plugin. - * - * <p/> - * - * En entrée on demande des répertoires où chercher les fichiers xmi a - * convertir. - * <p/> - * En sortie on demande le répertoire ou extraire les xmi et copier les - * resources. - * <p/> - * Par défaut on a les valeurs suivantes : - * </p> - * <pre> - * <xmiResources> - * </p> - * <input>target/generated-sources/xmi<\input> - * </p> - * <output>target/generated-sources/models<\output> - * </p> - * </xmiResources> - * </pre> - * - * </p> - * - * Note: si {@link #testPhase} est activée, les valeurs par défaut sont : - * </p> - * <pre> - * <xmiResources> - * </p> - * <input>target/generated-sources/xmi<\input> - * </p> - * <output>target/generated-sources/test-models<\output> - * </p> - * </xmiResources> - * </p> - * </pre> - * - * @parameter - * @since 1.0.0-rc-8 - */ - protected PluginIOContext xmiResources; - /** - * Nom du paquetage pour les fichiers générés - * - * @parameter expression="${generator.fullPackagePath}" default-value="${project.groupId}.${project.artifactId}" - * @since 0.50 - */ - protected String fullPackagePath; - /** - * Nom du paquetage à généré - * - * @parameter expression="${generator.extractedPackages}" default-value="${project.groupId}.${project.artifactId}" - * @since 0.50 - */ - protected String extractedPackages; - /** - * Liste des types de modeles acceptés séparés par des vigules. - * - * @parameter expression="${generator.acceptedXmiTypes}" default-value="xmi,uml" - * @since 1.0.0-rc-4 - */ - protected String acceptedXmiTypes; - /** - * Nom du resolver a utiliser - * - * @parameter expression="${generator.resolver}" default-value="org.nuiton.util.ResourceResolver" - * @since 1.0.0-rc-4 - */ - protected String resolver; - /** - * An extra directory to be added to the classpath. - * - * @parameter expression="${eugene.extraClassPathDirectory}" - * @since 1.0.0-rc-4 - */ - protected File extraClassPathDirectory; - - /** - * Get extension. - * - * @return the extension - */ - protected abstract String getExtension(); - - /** - * Get style sheet. - * - * @param model the model file used to determine the stylesheet to use - * @return the stylesheet name - */ - protected abstract String getStyleSheet(File model); - - @Override - public void doAction() throws Exception { - long t0 = System.nanoTime(); - try { - - getLog().info("Processing XSL tranformation"); - getLog().info(" with fullPackagePath : " + fullPackagePath); - getLog().info(" with extractedPackages : " + extractedPackages); - getLog().info(" with acceptedXmiTypes : " + acceptedXmiTypes); - getLog().info(" with resolver : " + resolver); - - TransformerFactory factory = TransformerFactory.newInstance(); - - ClassLoader fixedClassLoader = fixClassLoader(); - String[] includes = getSuffixPattern("*"); - - String[] acceptedTypesAsArray = getAcceptedTypesAsArray(); - - for (File dir : xmiResources.getInputs()) { - // recuperation des fichiers a traiter - List<File> files = - PluginHelper.getIncludedFiles(dir, includes, null); - - // lancement des traitements xsl sur les fichiers trouvés - // dans le repertoire - actionXsl(dir, - files, - factory, - fixedClassLoader, - acceptedTypesAsArray - ); - } - } finally { - getLog().info("xsl done in " + - StringUtil.convertTime(System.nanoTime() - t0)); - } - - getLog().info("Copy resources files"); - - String[] excludes = getSuffixPattern("**/*"); - PluginHelper.copyFiles(xmiResources, null, excludes, overwrite); - } - - @Override - protected PluginIOContext getResources() { - return xmiResources; - } - - @Override - protected PluginIOContext initResources() { - - File defaultIn = getFileFromBasedir("target", "generated-sources", - "xmi"); - File defaultOut = getFileFromBasedir("target", "generated-sources", - "models"); - File defaultTestIn = getFileFromBasedir("target", "generated-sources", - "test-xmi"); - File defaultTestOut = getFileFromBasedir("target", "generated-sources", - "test-models"); - - xmiResources = initResources( - defaultIn, - defaultOut, - defaultTestIn, - defaultTestOut - ); - - return xmiResources; - } - - protected String[] getSuffixPattern(String prefix) { - String[] acceptedSuffixes = getAcceptedTypesAsArray(); - int max = acceptedSuffixes.length; - String[] patterns = new String[max]; - for (int i = 0; i < max; i++) { - patterns[i] = prefix + acceptedSuffixes[i]; - } - return patterns; - } - - protected void actionXsl(File dir, - List<File> files, - TransformerFactory factory, - ClassLoader fixedClassLoader, - String[] acceptedSuffixes) - throws MojoExecutionException { - for (File file : files) { - try { - if (getLog().isDebugEnabled()) { - getLog().debug("treate file : " + file); - } - // Prepare resolver, stylesheet - URIResolver fileResolver = getUriResolver(file, - fixedClassLoader); - String styleSheet = getStyleSheet(file); - URL xsl = Resource.getURL(styleSheet); - - //TC-20090820 : using recursive for xmi -// File result = new File(destDirModel, FileUtil.basename(file, -// acceptedSuffixes).concat(".").concat(getExtension())); - String filename = FileUtil.basename( - file, - acceptedSuffixes).concat(".").concat(getExtension() - ); - String relatifPath = file.getParentFile().getAbsolutePath(). - substring(dir.getAbsolutePath().length()); - File dstDir = xmiResources.getOutput(); - if (!relatifPath.isEmpty()) { - dstDir = new File(dstDir, relatifPath); - createDirectoryIfNecessary(dstDir); -// dstDir.mkdirs(); - } - File result = new File(dstDir, filename); - if (!overwrite && file.lastModified() < result.lastModified()) { - getLog().info("file up-to-date : " + result); - continue; - } - if (getLog().isDebugEnabled()) { - getLog().debug("generate " + result); - } - - // Create the xsl transformer and set parameters - Transformer transformer = factory.newTransformer( - new StreamSource(xsl.openStream())); - - transformer.setParameter("fullPackagePath", fullPackagePath); - transformer.setParameter("extraPackages", extractedPackages); - - transformer.setURIResolver(fileResolver); - transformer.transform( - new StreamSource(file), - new StreamResult(new FileOutputStream(result)) - ); - - } catch (Exception e) { - throw new MojoExecutionException(e.getMessage(), e); - } - } - } - - /** - * Look for the types declared in property "acceptedXmiTypes", split it - * on ',' and check for the leading '.'. - * - * @return an array with all the accepted xmi types and a leading '.' - */ - protected String[] getAcceptedTypesAsArray() { - String[] splittedTypes = acceptedXmiTypes.split(","); - String[] result = new String[splittedTypes.length]; - - for (int i = 0; i < splittedTypes.length; i++) { - String type = splittedTypes[i]; - if (!type.startsWith(".")) { - type = "." + type; - } - result[i] = type; - } - - return result; - } - - protected URIResolver getUriResolver(File model, ClassLoader cl) { - URIResolver result = null; - - try { - Class<?> clazz = Class.forName(resolver, true, cl); - - // Try to set the base using the constructor - try { - // Look for a constructor with a String parameter (base) - Constructor<?> withBaseConstructor = - clazz.getConstructor(String.class); - // Set the xmi folder as the base - String base = model.getParentFile().getAbsolutePath(); - // Instantiate - result = (URIResolver) withBaseConstructor.newInstance(base); - } catch (Exception eee) { - getLog().warn( - "Unable to instantiate resolver with String parameter", - eee); - } - - // If resolver is still not created, create it using the default - // constructor - if (result == null) { - result = (URIResolver) clazz.newInstance(); - } - - if (result instanceof ResourceResolver) { - ((ResourceResolver) result).setVerbose(verbose); - ((ResourceResolver) result).setCl(cl); - if (result instanceof FasterCachedResourceResolver) { - boolean offline = settings.isOffline(); - getLog().debug("using offline mode ? : " + offline); - ((FasterCachedResourceResolver) result).setOffline(offline); - } - } - - } catch (Exception eee) { - getLog().warn("Unable to instantiate resolver using the default " + - "constructor", eee); - } - - return result; - } - - /** - * Prepare le classLoader a utiliser dans le generateur. - * <p/> - * Si un {@link #extraClassPathDirectory} a été renseigné, il est rajouté. - * <p/> - * Si des références à des sibling modules, ils seront rajoutés aussi. - * - * @return le class loader modifie - * @throws MojoExecutionException if any pb - */ - protected ClassLoader fixClassLoader() throws MojoExecutionException { - Set<String> urlsAsString = new HashSet<String>(); - List<URL> urls = new ArrayList<URL>(); - try { - ClassLoader loader; - if (extraClassPathDirectory != null) { - if (verbose) { - getLog().info("Add extra directory in generator's " + - "classLoader : " + extraClassPathDirectory); - } - addDirectoryToUrlsList( - extraClassPathDirectory, - urls, - urlsAsString - ); - } - if (project.getProjectReferences() != null) { - // this case is for multi-module when calling from a parent - // module - for (Object o : project.getProjectReferences().entrySet()) { - Entry<?, ?> entry = (Entry<?, ?>) o; - MavenProject relatedProject = - (MavenProject) entry.getValue(); - if (verbose) { - getLog().info("Add project reference in" + - " generator's classLoader : '" + - relatedProject.getArtifact() + "'"); - } - //TODO il faudrait peut-etre aussi ajouter les dependances ? - addDirectoryToUrlsList( - relatedProject.getArtifact().getFile(), - urls, - urlsAsString - ); - } - } - if (!project.getArtifacts().isEmpty()) { - // this is a special case when artifacts were resolved - // (for example in site phase) - if (verbose) { - getLog().info("Use resolved artifacts to build class-path"); - } - for (Object o : project.getArtifacts()) { - Artifact a = (Artifact) o; - if (!a.getScope().equals("provided")) { - addDirectoryToUrlsList(a.getFile(), urls, urlsAsString); - } - } - } - // we ask to add the directory in classloader - loader = getClass().getClassLoader(); - if (getLog().isDebugEnabled()) { - getLog().info("original classloader " + loader); - } - if (loader instanceof URLClassLoader) { - // on reinjecte les urls de loader de base - // car sinon on risque de ne pas retrouver les resources... - for (URL u : ((URLClassLoader) loader).getURLs()) { - addUrlToUrlsList(u, urls, urlsAsString); - if (getLog().isDebugEnabled()) { - getLog().debug("original cp entry: " + u); - } - } - // et on force l'utilisation du classloader parent - // s'il existe - if (loader.getParent() != null) { - loader = loader.getParent(); - } - } - if (!urls.isEmpty()) { - loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), - loader); - } - if (getLog().isDebugEnabled()) { - for (URL u : urls) { - getLog().debug("cp entry: " + u); - } - } - return loader; - } catch (MalformedURLException e) { - throw new MojoExecutionException(e.getMessage()); - } finally { - urls.clear(); - urlsAsString.clear(); - } - - } -} Deleted: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java 2010-06-29 11:50:43 UTC (rev 931) @@ -1,136 +0,0 @@ -/* - * #%L - * EUGene :: Maven plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2006 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.eugene.plugin; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import java.io.File; -import java.io.IOException; - -/** - * Converti les fichiers XMI en fichier ObjectModel - * - * @goal xmi2objectmodel - * - * @requiresDependencyResolution compile - * @requiresProject - */ -public class Xmi2ObjectModel extends Xmi2Model { - - @Override - public void doAction() throws Exception { - getLog().info("Conversion of XMI files into ObjectModel"); - super.doAction(); - } - - @Override - public String getExtension() { - return "objectmodel"; - } - - @Override - protected String getStyleSheet(File model) { - String styleSheet = null; - - String version = getXmiVersion(model); - if (version.startsWith("1.")) { - styleSheet = "xmi1.2ToObjectModel.xsl"; - } else if (version.startsWith("2.")) { - styleSheet = "xmi2.1ToObjectModel.xsl"; - } else { - getLog().error("Unsupported xmi version [" + version + "]"); - } - - return styleSheet; - } - - /** - * Try to find xmi version on a file. - * - * @param xmiFile - * file to inspect - * @return version or null if version can't have been found - */ - protected String getXmiVersion(File xmiFile) { - String version = null; - - SAXParserFactory factory = SAXParserFactory.newInstance(); - - try { - SAXParser parser = factory.newSAXParser(); - - XmiVersionHandler handler = new XmiVersionHandler(); - parser.parse(xmiFile, handler); - - version = handler.getVersion(); - } catch (ParserConfigurationException e) { - getLog().debug("Can't parse file as xmi", e); - } catch (SAXException e) { - getLog().debug("Can't parse file as xmi", e); - } catch (IOException e) { - getLog().debug("Can't parse file as xmi", e); - } - - return version; - } - - /** - * Sax handler to find xmi version into xmi document. - */ - protected class XmiVersionHandler extends DefaultHandler { - - public String version; - - public XmiVersionHandler() { - } - - public String getVersion() { - return version; - } - - @Override - public void startElement(String uri, String localName, String qName, - Attributes attributes) throws SAXException { - - if (qName.equals("XMI")) { - version = attributes.getValue("xmi.version"); - getLog().debug("XMI version found : " + version); - } - - if (version == null) { - version = attributes.getValue("xmi:version"); - getLog().debug("XMI version found : " + version); - } - - } - } - -} Deleted: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java 2010-06-29 11:50:43 UTC (rev 931) @@ -1,54 +0,0 @@ -/* - * #%L - * EUGene :: Maven plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2006 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.eugene.plugin; - -import java.io.File; - -/** - * Converti les fichiers XMI en fichier StateModel - * - * @goal xmi2statemodel - */ -public class Xmi2StateModel extends Xmi2Model { - - @Override - public void doAction() throws Exception { - getLog().info("Conversion of XMI files into StateModel"); - super.doAction(); - } - - @Override - protected String getExtension() { - return "statemodel"; - } - - @Override - protected String getStyleSheet(File model) { - //TODO when StateModel will be supported in 2.1, compute the version - //TODO to resolve the correct stylesheet - return "xmi1.2ToStateModel.xsl"; - } -} Deleted: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java 2010-06-29 11:50:43 UTC (rev 931) @@ -1,129 +0,0 @@ -/* - * #%L - * EUGene :: Maven plugin - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2006 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.eugene.plugin; - -import org.nuiton.plugin.PluginHelper; -import org.nuiton.plugin.PluginIOContext; - -import java.io.File; - -/** - * Extract zipped XMI files from zargo archive. - * - * @author ruchaud - * @version $Revision$ - * - * Last update: $Date$ - * by : * - * @goal zargo2xmi - */ -public class Zargo2Xmi extends EugeneAbstractMojo { - - public static final String[] ZARGO_FILE_FILTER = - new String[]{"**/*.zargo", "**/*.zuml"}; - public static final String[] XMI_FILE_FILTER = - new String[]{"*.xmi", "**/*.xmi"}; - /** - * Les entrées-sorties du plugin. - * - * <p/> - * - * En entrée on demande des répertoires où chercher les fichiers zargo a - * convertir. - * <p/> - * En sortie on demande le répertoire ou extraire les xmi et copier les - * resources. - * <p/> - * Par défaut on a les valeurs suivantes : - * </p> - * <pre> - * <zargoResources> - * </p> - * <input>src/main/xmi</input> - * </p> - * <output>target/generated-sources/xmi</ouput> - * </p> - * </zargoResources> - * </pre> - * </p> - * - * Note: si {@link #testPhase} est activée, les valeurs par défaut sont : - * </p> - * <pre> - * <zargoResources> - * </p> - * <input>src/test/xmi</input> - * </p> - * <output>target/generated-sources/test-xmi</ouput> - * </p> - * <zargoResources> - * </pre> - * - * @parameter - * @since 1.0.0-rc-8 - */ - protected PluginIOContext zargoResources; - - @Override - public void doAction() throws Exception { - getLog().info("Extract zipped XMI files from zargo archive and " + - "copy resources"); - - getLog().info("Extract zipped XMI files"); - PluginHelper.expandFiles(zargoResources, ZARGO_FILE_FILTER, null, - XMI_FILE_FILTER, overwrite); - - getLog().info("Copy resources"); - PluginHelper.copyFiles(zargoResources, null, ZARGO_FILE_FILTER, - overwrite); - } - - @Override - protected PluginIOContext getResources() { - return zargoResources; - } - - @Override - protected PluginIOContext initResources() { - - File defaultIn = getFileFromBasedir("src", "main", "xmi"); - File defaultOut = getFileFromBasedir("target", "generated-sources", - "xmi"); - - File defaultTestIn = getFileFromBasedir("src", "test", "xmi"); - File defaultTestOut = getFileFromBasedir("target", "generated-sources", - "test-xmi"); - - zargoResources = initResources( - defaultIn, - defaultOut, - defaultTestIn, - defaultTestOut - ); - - return zargoResources; - } -} Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-06-28 13:35:15 UTC (rev 930) +++ trunk/pom.xml 2010-06-29 11:50:43 UTC (rev 931) @@ -33,7 +33,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmine</artifactId> - <version>2.2.1</version> + <version>2.2.2-SNAPSHOT</version> </parent> <artifactId>eugene</artifactId>