r1003 - in trunk: eugene/src/main/java/org/nuiton/eugene eugene/src/main/java/org/nuiton/eugene/models/object maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/writer
Author: tchemit Date: 2010-11-27 18:50:05 +0100 (Sat, 27 Nov 2010) New Revision: 1003 Url: http://nuiton.org/repositories/revision/eugene/1003 Log: Evolution #1109: Add verbose flag in ModelReader (used after with eugene.verbose maven pom properties in the plugin) fix tag values import (when using tagValue) Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java 2010-11-27 15:55:17 UTC (rev 1002) +++ trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java 2010-11-27 17:50:05 UTC (rev 1003) @@ -47,6 +47,16 @@ /** date de derniere modification de la source la plus recente */ protected long lastModifiedSource; + protected boolean verbose; + + public boolean isVerbose() { + return verbose; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + protected void setLastModifiedSource(File... files) { for (File file : files) { if (file.lastModified() > getLastModifiedSource()) { Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2010-11-27 15:55:17 UTC (rev 1002) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2010-11-27 17:50:05 UTC (rev 1003) @@ -26,16 +26,7 @@ package org.nuiton.eugene.models.object; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.List; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.digester.Digester; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -52,9 +43,20 @@ import org.nuiton.util.RecursiveProperties; import org.nuiton.util.StringUtil; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * To read object model files into an memory object model. - * + * <p/> * Created: 26 oct. 2009 * * @author fdesbois <fdesbois@codelutin.com> @@ -65,7 +67,7 @@ private static final Log log = LogFactory.getLog(ObjectModelReader.class); - public static final String TAGVALUE = "tagvalue"; + public static final String TAGVALUE = "tagvalue"; public static final String STEREOTYPE = "stereotype"; @@ -78,7 +80,7 @@ /** * Pattern to define tag values authorized at classifier level in the model * properties file. - * + * <p/> * L'expression réguliere match les chaines de type * <package.ClassName>.<class|attribute|operation>.[name].<stereotype|tagvalue>.[tag] * fr.isisfish.entities.Population.class.stereotype=entity @@ -89,7 +91,7 @@ * fr.isisfish.entities.Population.operation.getRegion.tagvalue.pk=... */ protected Pattern propertiesPattern = Pattern - .compile("((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation))\\.(?:([_a-zA-Z0-9]+)\\.)?(?:(stereotype|tagvalue|tagValue)?)\\.([_a-z0-9][_a-zA-Z0-9]*)?"); + .compile("^((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation))\\.(?:([_a-zA-Z0-9]+)\\.)?(?:(stereotype|tagvalue|tagValue)?)\\.([_a-z0-9][_a-zA-Z0-9]*)?$"); /** * Pattern to define tag values authorized at model level in the model @@ -98,15 +100,15 @@ * @since 2.2.1 */ protected Pattern modelTagValuePattern = Pattern - .compile("^model\\.(?:(tagvalue|tagValue)?)\\.((?:[_a-zA-Z0-9]+)(?:\\.[_a-zA-Z0-9]+)*)$"); + .compile("^model\\.(?:(tagvalue|tagValue)?)\\.((?:[_a-zA-Z0-9]+)(?:\\.[_a-zA-Z0-9]+)*)$"); public static final String MODEL = "model"; /** * @param files les noms des fichiers existant contenant du XML représentant - * des ObjectModel. Il est automatiquement recherche un fichier de - * propriété associé a ce fichier pour pouvoir ajouter des - * stereotype ou des tag value sur les class, attribute ou operation + * des ObjectModel. Il est automatiquement recherche un fichier de + * propriété associé a ce fichier pour pouvoir ajouter des + * stereotype ou des tag value sur les class, attribute ou operation */ @Override public ObjectModel read(File... files) { @@ -140,14 +142,14 @@ if (!propFile.exists()) { if (log.isInfoEnabled()) { log.info("Pas de fichier de propriete " + propFile - + " associé au model"); + + " associé au model"); } } else { if (log.isInfoEnabled()) { log.info("Lecture du fichier de propriete " + propFile - + " associé au model"); + + " associé au model"); } - loadModelPropertiesFile(propFile, model); + loadTagValues(propFile, model); } } if (log.isDebugEnabled()) { @@ -164,22 +166,22 @@ * attributes if needed. * * @param clazz where the attribute need to be find - * @param name attribute name to find + * @param name attribute name to find * @return the attribute found or null */ protected ObjectModelAttribute getAttribute(ObjectModelClass clazz, String name) { - ObjectModelAttribute result = clazz.getAttribute(name); + ObjectModelAttribute result = clazz.getAttribute(name); // Ano #619 : FD-2010-05-17 : Specific case for Association class : // check on participant attributes if (result == null && clazz instanceof ObjectModelAssociationClassImpl) { if (log.isDebugEnabled()) { log.debug("Attribute " + name + " not found from " + - clazz.getQualifiedName() +" association class. " + - "Will check participants..."); + clazz.getQualifiedName() + " association class. " + + "Will check participants..."); } - ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz; + ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz; for (ObjectModelAttribute participant : assoc.getParticipantsAttributes()) { if (participant.getName().equals(name)) { result = participant; @@ -190,7 +192,8 @@ return result; } - public Properties loadModelPropertiesFile(File propFile, ObjectModel model) { + public Properties loadTagValues(File propFile, ObjectModel model) { + Properties prop = new RecursiveProperties(); try { FileInputStream inStream = new FileInputStream(propFile); @@ -205,9 +208,17 @@ + propFile, eee); } } - // on ajoute les proprietes du fichier associe au model - for (Enumeration<Object> e = prop.keys(); e.hasMoreElements();) { - String key = (String) e.nextElement(); + + // number of sucessfull imported tag values into model + int numberImportedTagValues = 0; + + // get all the tagvalues keys and sort them + List<String> keys = new ArrayList<String>(); + CollectionUtils.addAll(keys, prop.keys()); + Collections.sort(keys); + + // for each tag value try to import in in model + for (String key : keys) { String value = prop.getProperty(key); if (key.startsWith(MODEL)) { @@ -223,15 +234,6 @@ continue; } String tag = matcher.group(2); -// if (!key.startsWith("model.tagvalue.") || -// !key.startsWith("model.tagValue.")) { -// if (log.isWarnEnabled()) { -// log.warn("Invalid tag value [" + key + "] : only tagvalue or tagValue is allowed on model in properties"); -// } -// continue; -// } -// String tag = key.substring("model.tagvalue.".length()); - ObjectModelImpl modelImpl = (ObjectModelImpl) model; if (tag.equals(JavaGeneratorUtil.TAG_VERSION)) { @@ -239,7 +241,11 @@ // property modelImpl.setVersion(value); } + if (isVerbose()) { + log.info("import model tag value " + key); + } modelImpl.addTagValue(tag, value); + numberImportedTagValues++; continue; } @@ -264,7 +270,7 @@ String target = matcher.group(2); String targetName = matcher.group(3); // type is stereotype or tagvalue - String type = matcher.group(4); + String type = matcher.group(4).toLowerCase(); String tag = matcher.group(5); if (log.isDebugEnabled()) { @@ -346,8 +352,18 @@ } } + if (isVerbose()) { + log.info("import tag value " + key + " --> " + fqn + ":" + target + ":" + targetName + ":" + type + ":" + tag+" = " + value); + } + numberImportedTagValues++; } - + if (log.isInfoEnabled()) { + log.info(numberImportedTagValues + " tag values were succesfull imported from " + propFile); + } + int nbFailed = prop.size() - numberImportedTagValues; + if (nbFailed > 0 && isVerbose()) { + log.info(nbFailed + " tag values failed to be imported from " + propFile); + } return prop; } } Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java =================================================================== --- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2010-11-27 15:55:17 UTC (rev 1002) +++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2010-11-27 17:50:05 UTC (rev 1003) @@ -282,6 +282,8 @@ if (configuration.isVerbose()) { getLog().info("Will read " + filesToRead.length + " model(s)."); } + + getModelReader().setVerbose(configuration.isVerbose()); // read memory model from all files models Model model = getModelReader().read(filesToRead);
participants (1)
-
tchemit@users.nuiton.org