r1348 - in trunk: eugene/src/main/java/org/nuiton/eugene/java eugene/src/main/java/org/nuiton/eugene/models/object/reader eugene/src/main/java/org/nuiton/eugene/models/object/xml eugene/src/main/java/org/nuiton/eugene/models/stereotype eugene/src/main/java/org/nuiton/eugene/models/tagvalue eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml
Author: tchemit Date: 2014-05-01 14:17:20 +0200 (Thu, 01 May 2014) New Revision: 1348 Url: http://forge.nuiton.org/projects/eugene/repository/revisions/1348 Log: fixes #3182: to be able to load multiple stereotype from the model properties file fixes #3183: Change stereotypes collection to set fixes #3185: Add a failIfUnsafe flag on generate mojo Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/InvalidModelPropertiesException.java trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/InvalidStereotypeSyntaxException.java trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/Stereotypes.java trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/InvalidTagValueSyntaxException.java Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/StereotypeAble.java trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/TagValues.java Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -649,7 +649,7 @@ protected void cloneStereotypes(ObjectModelClassifier source, ObjectModelClassifier destination) { - Collection<String> stereotypes = source.getStereotypes(); + Set<String> stereotypes = source.getStereotypes(); for (String stereotype : stereotypes) { addStereotype(destination, stereotype); } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -39,15 +39,17 @@ import org.nuiton.eugene.models.object.ObjectModelOperation; import org.nuiton.eugene.models.object.xml.ObjectModelAssociationClassImpl; import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl; -import org.nuiton.eugene.models.object.xml.ObjectModelElementImpl; import org.nuiton.eugene.models.object.xml.ObjectModelImpl; -import org.nuiton.eugene.models.object.xml.ObjectModelImplRef; +import org.nuiton.eugene.models.stereotype.InvalidStereotypeSyntaxException; import org.nuiton.eugene.models.stereotype.MismatchStereotypeTargetException; import org.nuiton.eugene.models.stereotype.StereotypeDefinitionProviders; import org.nuiton.eugene.models.stereotype.StereotypeNotFoundException; +import org.nuiton.eugene.models.stereotype.Stereotypes; +import org.nuiton.eugene.models.tagvalue.InvalidTagValueSyntaxException; import org.nuiton.eugene.models.tagvalue.MismatchTagValueTargetException; import org.nuiton.eugene.models.tagvalue.TagValueDefinitionProviders; import org.nuiton.eugene.models.tagvalue.TagValueNotFoundException; +import org.nuiton.eugene.models.tagvalue.TagValues; import org.nuiton.util.FileUtil; import org.nuiton.util.RecursiveProperties; import org.nuiton.util.StringUtil; @@ -61,8 +63,8 @@ import java.util.Iterator; import java.util.List; import java.util.Properties; +import java.util.Set; import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * Abstract object model reader. @@ -84,31 +86,31 @@ public static final String CLASS = "class"; - /** - * 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 - * fr.isisfish.entities.Population.class.tagvalue.persistenceType=flatfile - * fr.isisfish.entities.Population.attribute.name.stereotype=... - * fr.isisfish.entities.Population.attribute.name.tagvalue.pk=topiaId - * fr.isisfish.entities.Population.operation.getRegion.stereotype=... - * 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]+)\\.)?(?:(tagvalue|tagValue)?)\\.([_a-z0-9][_a-zA-Z0-9]*)?$"); +// /** +// * 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 +// * fr.isisfish.entities.Population.class.tagvalue.persistenceType=flatfile +// * fr.isisfish.entities.Population.attribute.name.stereotype=... +// * fr.isisfish.entities.Population.attribute.name.tagvalue.pk=topiaId +// * fr.isisfish.entities.Population.operation.getRegion.stereotype=... +// * 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]+)\\.)?(?:(tagvalue|tagValue)?)\\.([_a-z0-9][_a-zA-Z0-9]*)?$"); - protected Pattern stereotypePattern = Pattern - .compile("^((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation))\\.(?:([_a-zA-Z0-9]+)\\.)?(?:(stereotype)?)$"); +// protected Pattern stereotypePattern = Pattern +// .compile("^((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation))\\.(?:([_a-zA-Z0-9]+)\\.)?(?:(stereotype)?)$"); - /** - * Pattern to define tag values authorized at model level in the model - * properties file. - */ - protected Pattern modelTagValuePattern = Pattern.compile( - "^model\\.(?:(tagvalue|tagValue)?)\\.((?:.+))$"); +// /** +// * Pattern to define tag values authorized at model level in the model +// * properties file. +// */ +// protected Pattern modelTagValuePattern = Pattern.compile( +// "^model\\.(?:(tagvalue|tagValue)?)\\.((?:.+))$"); public static final String MODEL = "model"; @@ -138,13 +140,6 @@ } setStereotypeDefinitionProvider(StereotypeDefinitionProviders.newProvider(getClass().getClassLoader(), false)); } - -// if (modelPropertiesProvider == null) { -// if (log.isDebugEnabled()) { -// log.debug("No properties provider filled, will instanciate a new default one"); -// } -// setModelPropertiesProvider(ModelPropertiesUtil.newStore(getClass().getClassLoader(), false)); -// } } @Override @@ -223,7 +218,7 @@ ObjectModel model) throws IOException { Properties prop = new RecursiveProperties(); -// try { + FileInputStream inStream = new FileInputStream(propFile); try { prop.load(inStream); @@ -232,19 +227,23 @@ } // number of sucessfull imported tag values into model + boolean safe = true; + int numberImportedTagValues = 0; + int numberImportedStereotypes = 0; // get all the tagvalues keys and sort them List<String> keys = new ArrayList<String>(); CollectionUtils.addAll(keys, prop.keys()); Collections.sort(keys); + boolean strictLoading = isStrictLoading(); // for each tag value try to import in in model for (String key : keys) { String value = prop.getProperty(key); if (log.isDebugEnabled()) { - log.debug("Propriete: '" + key + "' = " + value); + log.debug("Property: '" + key + "' = " + value); } if (key.startsWith(MODEL)) { @@ -252,11 +251,11 @@ // model tag value boolean loaded = loadModelTagValue(model, key, value); - if (loaded) { - numberImportedTagValues++; } + safe &= loaded; + continue; } @@ -266,12 +265,41 @@ // stereotype property - boolean loaded = loadStereotype(model, key, value); + // check key is ok + Matcher matcher; + try { + matcher = Stereotypes.getMatcher(key); + } catch (InvalidStereotypeSyntaxException e) { + String message = "Invalid stereotype [" + key + "] : syntax is not correct."; + if (strictLoading) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } + } + safe = false; + continue; + } - if (loaded) { - numberImportedTagValues++; + String fqn = matcher.group(1); + fqn = StringUtil.substring(fqn, 0, -1); // remove ended . + // target is class, attribute or operation + String target = matcher.group(2); + String targetName = matcher.group(3); + // target real type + Class<?> targetType = getTargetType(target); + + Set<String> stereotypes = Stereotypes.getStereotypes(value); + for (String stereotype : stereotypes) { + boolean loaded = loadStereotype(model, key, fqn, target, targetName, targetType, stereotype); + safe &= loaded; + if (loaded) { + numberImportedStereotypes++; + } } - continue; } @@ -279,30 +307,47 @@ // tag value property boolean loaded = loadTagValue(model, key, value); - if (loaded) { numberImportedTagValues++; } + safe &= loaded; } if (isVerbose()) { log.info(numberImportedTagValues + " tag values were succesfull imported from " + propFile); + log.info(numberImportedStereotypes + " stereotypes 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); + if (!safe) { + + String errorMessage = "There is some tag value(s) or stereotype(s) failed to be imported from " + propFile; + if (strictLoading) { + throw new InvalidModelPropertiesException(errorMessage); + } + if (isVerbose()) { + log.info(errorMessage); + } } return prop; } - public boolean loadModelTagValue(ObjectModel model, String key, String value) { - Matcher matcher = modelTagValuePattern.matcher(key); + protected boolean loadModelTagValue(ObjectModel model, String key, String value) throws InvalidModelPropertiesException { - if (!matcher.find()) { - if (log.isWarnEnabled()) { - log.warn("Invalid model tag value [" + key + "] : only tagvalue or tagValue is allowed on model in properties"); + Matcher matcher; + try { + matcher = TagValues.getModelMatcher(key); + } catch (InvalidTagValueSyntaxException e) { + String message = "Invalid model tag value [" + key + "] : only tagvalue or tagValue is allowed on model in properties"; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } return false; } + String tag = matcher.group(2); boolean safe = false; @@ -311,21 +356,29 @@ tagValueDefinitionProvider.validate(tag, ObjectModel.class); safe = true; } catch (TagValueNotFoundException e) { - if (log.isWarnEnabled()) { - log.warn("Invalid model tag value [" + key + "] : the tagvalue '" + tag + "' is unknown."); + String message = "Invalid model tag value [" + key + "] : the tagvalue '" + tag + "' is unknown."; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } } catch (MismatchTagValueTargetException e) { - if (log.isWarnEnabled()) { - log.warn("Invalid model tag value [" + key + "] : this tagvalue '" + tag + "' can not be apply on the model."); + String message = "Invalid model tag value [" + key + "] : this tagvalue '" + tag + "' can not be apply on the model."; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } } - if (!safe && isStrictLoading()) { - - // in strict loading do not accept unsafe tags - return false; - } - if (safe) { // test if tagValue is deprecated @@ -335,13 +388,17 @@ log.warn("Deprecated tagValue usage [" + key + "] : " + value); } } + } else { + if (isStrictLoading()) { + // in strict loading do not accept unsafe tags + return false; + } } ObjectModelImpl modelImpl = (ObjectModelImpl) model; if (tag.equals(EugeneTagValues.TAG_VERSION)) { - // push directly the version in the model version - // property + // push directly the version in the model version property modelImpl.setVersion(value); } if (isVerbose()) { @@ -351,197 +408,209 @@ return true; } - public boolean loadStereotype(ObjectModel model, String key, String value) { - Matcher matcher = stereotypePattern.matcher(key); + protected boolean loadTagValue(ObjectModel model, String key, String value) { + Matcher matcher; + try { + matcher = TagValues.getMatcher(key); + } catch (InvalidTagValueSyntaxException e) { - if (!matcher.find()) { - - if (log.isWarnEnabled()) { - log.warn("Invalid stereotype [" + key + "] : syntax is not correct."); + String message = "Invalid tag value [" + key + "] : syntax is not correct."; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } return false; } String fqn = matcher.group(1); - fqn = StringUtil.substring(fqn, 0, -1); // remove ended . + fqn = StringUtil.substring(fqn, 0, -1); // remove ended dot // target is class, attribute or operation String target = matcher.group(2); + // name of the target (can be null on class) String targetName = matcher.group(3); - // type is stereotype + // type is tagvalue String type = matcher.group(4).toLowerCase(); + // name of the tag value + String tag = matcher.group(5); // target real type Class<?> targetType = getTargetType(target); + if (log.isDebugEnabled()) { + log.debug("Property: '" + key + "' => " + + "fqn:" + fqn + " target:" + target + + " targetName:" + targetName + + " type:" + type + " tag:" + tag); + } + boolean safe = false; try { - stereotypeDefinitionProvider.validate(value, targetType); + tagValueDefinitionProvider.validate(tag, targetType); safe = true; - } catch (StereotypeNotFoundException e) { - if (log.isWarnEnabled()) { - log.warn("Invalid model stereotype [" + key + "] : the stereotype '" + value + "' is unknown."); + } catch (TagValueNotFoundException e) { + + String message = "Invalid tag value [" + key + "] : this tagvalue '" + tag + "' is unknown."; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } - } catch (MismatchStereotypeTargetException e) { - if (log.isWarnEnabled()) { - log.warn("Invalid model stereotype [" + key + "] : this stereotype '" + value + "' can not be apply on '" + targetType + "'."); + + } catch (MismatchTagValueTargetException e) { + String message = "Invalid tag value [" + key + "] : this tagvalue '" + tag + "' can not be apply on the given type '" + target + "'."; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } } - if (!safe && isStrictLoading()) { - // in strict loading do not accept unsafe stereotypes - return false; - } - if (safe) { // test if tagValue is deprecated - boolean deprecated = stereotypeDefinitionProvider.isDeprecated(value); + boolean deprecated = tagValueDefinitionProvider.isDeprecated(tag); if (deprecated) { if (log.isWarnEnabled()) { - log.warn("Deprecated stereotype usage [" + key + "] : " + value); + log.warn("Deprecated tagValue usage [" + key + "] : " + value); } } - } + } else { - if (log.isDebugEnabled()) { - log.debug("Propriete: '" + key + "' => " - + "fqn:" + fqn + " target:" + target - + " targetName:" + targetName - + " type:" + type); + if (isStrictLoading()) { + // in strict loading do not accept unsafe tags + return false; + } } - ObjectModelClassifier omc = getClassifier(model, STEREOTYPE, key, fqn); + ObjectModelClassifier omc = getClassifier(model, TAGVALUE, key, fqn); if (omc == null) { // classifier not found return false; } - List<ObjectModelElement> elems = getObjectElements(omc, STEREOTYPE, key, fqn, target, targetName); + List<ObjectModelElement> elements = + getObjectElements(omc, TAGVALUE, key, fqn, target, targetName); - if (elems == null) { + if (elements == null) { - // no element to apply + // no elements to apply return false; } - for (ObjectModelElement elem1 : elems) { - //TODO tchemit 2010-11-29 uncomment this if there is some proble, but I don't see why there would be... -// if (elem1 == null) { -// if (log.isWarnEnabled()) { -// log.warn("Invalid stereotype [" + key + "] : Element '" + targetName + "' of type '" + target + "' on classifier '" + fqn + "' is null."); -// } -// continue; -// } - ObjectModelElementImpl elem = (ObjectModelElementImpl) elem1; + for (ObjectModelElement element : elements) { - // pour les stereotypes - ObjectModelImplRef stereotype = new ObjectModelImplRef(); - stereotype.setName(value); - elem.addStereotype(stereotype); + if (log.isDebugEnabled()) { + log.debug("add tagValue " + tag + + ", value:" + value + + " to element:" + element); + } + element.addTagValue(tag, value); + } - if (isVerbose()) { - log.info("stereotype imported " + key + " --> " + fqn + ":" + target + ":" + targetName + ":" + type + " = " + value); + log.info("tag value imported " + key + " --> " + fqn + ":" + target + ":" + targetName + ":" + type + ":" + tag + " = " + value); } - return true; } - private boolean loadTagValue(ObjectModel model, String key, String value) { - Matcher matcher = propertiesPattern.matcher(key); + protected boolean loadStereotype(ObjectModel model, + String key, + String fqn, + String target, + String targetName, + Class<?> targetType, + String stereotype) { - if (!matcher.find()) { - - if (log.isWarnEnabled()) { - log.warn("Invalid tag value [" + key + "] : syntax is not correct."); - } - return false; - } - - String fqn = matcher.group(1); - fqn = StringUtil.substring(fqn, 0, -1); // remove ended dot - // target is class, attribute or operation - String target = matcher.group(2); - // name of the target (can be null on class) - String targetName = matcher.group(3); - // type is tagvalue - String type = matcher.group(4).toLowerCase(); - // name of the tag value - String tag = matcher.group(5); - // target real type - Class<?> targetType = getTargetType(target); - - if (log.isDebugEnabled()) { - log.debug("Propriete: '" + key + "' => " - + "fqn:" + fqn + " target:" + target - + " targetName:" + targetName - + " type:" + type + " tag:" + tag); - } - boolean safe = false; - try { - tagValueDefinitionProvider.validate(tag, targetType); + stereotypeDefinitionProvider.validate(stereotype, targetType); safe = true; - } catch (TagValueNotFoundException e) { - if (log.isWarnEnabled()) { - log.warn("Invalid tag value [" + key + "] : this tagvalue '" + tag + "' is unknown."); + } catch (StereotypeNotFoundException e) { + + String message = "Invalid model stereotype [" + key + "] : the stereotype '" + stereotype + "' is unknown."; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } - } catch (MismatchTagValueTargetException e) { - if (log.isWarnEnabled()) { - log.warn("Invalid tag value [" + key + "] : this tagvalue '" + tag + "' can not be apply on the given type '" + target + "'."); + } catch (MismatchStereotypeTargetException e) { + String message = "Invalid model stereotype [" + key + "] : this stereotype '" + stereotype + "' can not be apply on '" + targetType + "'."; + if (isStrictLoading()) { + if (log.isErrorEnabled()) { + log.error(message); + } + } else { + if (log.isWarnEnabled()) { + log.warn(message); + } } } - if (!safe && isStrictLoading()) { - - // in strict loading do not accept unsafe tags - return false; - } - if (safe) { // test if tagValue is deprecated - boolean deprecated = tagValueDefinitionProvider.isDeprecated(tag); + boolean deprecated = stereotypeDefinitionProvider.isDeprecated(stereotype); if (deprecated) { if (log.isWarnEnabled()) { - log.warn("Deprecated tagValue usage [" + key + "] : " + value); + log.warn("Deprecated stereotype usage [" + key + "] : " + stereotype); } } + } else { + if (isStrictLoading()) { + // in strict loading do not accept unsafe stereotypes + return false; + } } + if (log.isDebugEnabled()) { + log.debug("Property: '" + key + "' => " + + "fqn:" + fqn + " target:" + target + + " targetName:" + targetName + + " type:" + stereotype); + } - ObjectModelClassifier omc = getClassifier(model, TAGVALUE, key, fqn); + ObjectModelClassifier omc = getClassifier(model, STEREOTYPE, key, fqn); if (omc == null) { // classifier not found return false; } - List<ObjectModelElement> elements = - getObjectElements(omc, TAGVALUE, key, fqn, target, targetName); + List<ObjectModelElement> elems = getObjectElements(omc, STEREOTYPE, key, fqn, target, targetName); - if (elements == null) { + if (elems == null) { - // no elements to apply + // no element to apply return false; } - for (ObjectModelElement element : elements) { + for (ObjectModelElement elem : elems) { + elem.addStereotype(stereotype); + } - if (log.isDebugEnabled()) { - log.debug("add tagValue " + tag - + ", value:" + value - + " to element:" + element); - } - element.addTagValue(tag, value); - - } if (isVerbose()) { - log.info("tag value imported " + key + " --> " + fqn + ":" + target + ":" + targetName + ":" + type + ":" + tag + " = " + value); + log.info("stereotype imported " + key + " --> " + fqn + ":" + target + ":" + targetName + ":" + stereotype + " = " + stereotype); } + return true; } Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/InvalidModelPropertiesException.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/InvalidModelPropertiesException.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/InvalidModelPropertiesException.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -0,0 +1,15 @@ +package org.nuiton.eugene.models.object.reader; + +/** + * Created on 5/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.9 + */ +public class InvalidModelPropertiesException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public InvalidModelPropertiesException(String message) { + super(message); + } +} Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/InvalidModelPropertiesException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -35,7 +35,6 @@ import org.nuiton.eugene.models.object.ObjectModelModifier; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -65,7 +64,7 @@ protected String documentation; - protected List<String> stereotypes; + protected Set<String> stereotypes; protected Map<String, String> tagValues; @@ -75,7 +74,7 @@ public ObjectModelElementImpl() { tagValues = new HashMap<String, String>(); - stereotypes = new ArrayList<String>(); + stereotypes = new HashSet<String>(); comments = new ArrayList<String>(); modifiers = new HashSet<ObjectModelModifier>(); } @@ -206,7 +205,7 @@ } @Override - public Collection<String> getStereotypes() { + public Set<String> getStereotypes() { return stereotypes; } @@ -216,6 +215,11 @@ } @Override + public void addStereotype(String stereotype) { + stereotypes.add(stereotype); + } + + @Override public Map<String, String> getTagValues() { return tagValues; } Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/InvalidStereotypeSyntaxException.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/InvalidStereotypeSyntaxException.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/InvalidStereotypeSyntaxException.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -0,0 +1,11 @@ +package org.nuiton.eugene.models.stereotype; + +/** + * Created on 5/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.9 + */ +public class InvalidStereotypeSyntaxException extends Exception { + private static final long serialVersionUID = 1L; +} Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/InvalidStereotypeSyntaxException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/StereotypeAble.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/StereotypeAble.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/StereotypeAble.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -22,7 +22,7 @@ * #L% */ -import java.util.Collection; +import java.util.Set; /** * Created on 4/26/14. @@ -37,7 +37,7 @@ * * @return a Collection containing all stereotypes names associated with this element as String. */ - Collection<String> getStereotypes(); + Set<String> getStereotypes(); /** * Returns whether this element has a stereotype corresponding to the given name, or not. @@ -46,4 +46,11 @@ * @return a boolean indicating whether this element has a stereotype corresponding to the given name, or not. */ boolean hasStereotype(String stereotypeName); + + /** + * Add a stereotype. + * + * @param stereotype stereotype to add + */ + void addStereotype(String stereotype); } Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/Stereotypes.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/Stereotypes.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/Stereotypes.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -0,0 +1,32 @@ +package org.nuiton.eugene.models.stereotype; + +import com.google.common.collect.ImmutableSet; + +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Created on 5/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.9 + */ +public class Stereotypes { + + protected static final Pattern STEREOTYPE_PATTERN = Pattern + .compile("^((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation))\\.(?:([_a-zA-Z0-9]+)\\.)?(?:(stereotype)?)$"); + + public static Matcher getMatcher(String key) throws InvalidStereotypeSyntaxException { + Matcher matcher = STEREOTYPE_PATTERN.matcher(key); + if (!matcher.find()) { + throw new InvalidStereotypeSyntaxException(); + } + return matcher; + } + + public static Set<String> getStereotypes(String value) { + String[] split = value.split("\\s*,\\s*"); + return ImmutableSet.<String>builder().add(split).build(); + } +} Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/stereotype/Stereotypes.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/InvalidTagValueSyntaxException.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/InvalidTagValueSyntaxException.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/InvalidTagValueSyntaxException.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -0,0 +1,11 @@ +package org.nuiton.eugene.models.tagvalue; + +/** + * Created on 5/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.9 + */ +public class InvalidTagValueSyntaxException extends Exception { + private static final long serialVersionUID = 1L; +} Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/InvalidTagValueSyntaxException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/TagValues.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/TagValues.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/tagvalue/TagValues.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -25,6 +25,9 @@ import org.apache.commons.lang3.StringUtils; import org.nuiton.eugene.models.object.ObjectModelElement; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Created on 4/26/14. * @@ -34,6 +37,45 @@ public class TagValues { /** + * 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 + * fr.isisfish.entities.Population.class.tagvalue.persistenceType=flatfile + * fr.isisfish.entities.Population.attribute.name.stereotype=... + * fr.isisfish.entities.Population.attribute.name.tagvalue.pk=topiaId + * fr.isisfish.entities.Population.operation.getRegion.stereotype=... + * fr.isisfish.entities.Population.operation.getRegion.tagvalue.pk=... + */ + protected static final Pattern TAG_VALUE_PATTERN = Pattern + .compile("^((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation))\\.(?:([_a-zA-Z0-9]+)\\.)?(?:(tagvalue|tagValue)?)\\.([_a-z0-9][_a-zA-Z0-9]*)?$"); + + /** + * Pattern to define tag values authorized at model level in the model + * properties file. + */ + protected static final Pattern MODEL_TAG_VALUE_PATTERN = Pattern.compile( + "^model\\.(?:(tagvalue|tagValue)?)\\.((?:.+))$"); + + public static Matcher getModelMatcher(String key) throws InvalidTagValueSyntaxException { + Matcher matcher = MODEL_TAG_VALUE_PATTERN.matcher(key); + if (!matcher.find()) { + throw new InvalidTagValueSyntaxException(); + } + return matcher; + } + + public static Matcher getMatcher(String key) throws InvalidTagValueSyntaxException { + Matcher matcher = TAG_VALUE_PATTERN.matcher(key); + if (!matcher.find()) { + throw new InvalidTagValueSyntaxException(); + } + return matcher; + } + + /** * Seek for a Boolean tag value. * <p/> * Will first the tag value using the method {@link #findTagValue(String, TagValueAble...)}. Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java =================================================================== --- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -29,6 +29,7 @@ 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.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -40,14 +41,14 @@ import org.nuiton.eugene.ModelReader; import org.nuiton.eugene.Template; import org.nuiton.eugene.models.Model; +import org.nuiton.eugene.models.object.reader.InvalidModelPropertiesException; import org.nuiton.eugene.models.stereotype.StereotypeDefinitionProvider; import org.nuiton.eugene.models.stereotype.StereotypeDefinitionProviders; import org.nuiton.eugene.models.tagvalue.TagValueDefinitionProvider; import org.nuiton.eugene.models.tagvalue.TagValueDefinitionProviders; import org.nuiton.eugene.plugin.writer.BaseChainedFileWriter; +import org.nuiton.eugene.plugin.writer.BaseChainedFileWriterToMemoryModel; import org.nuiton.eugene.plugin.writer.XmiChainedFileWriter; -import org.nuiton.eugene.plugin.writer.XmlModelChainedFileWriter; -import org.nuiton.eugene.plugin.writer.YamlModelChainedFileWriter; import org.nuiton.eugene.writer.ChainedFileWriter; import org.nuiton.eugene.writer.ChainedFileWriterConfiguration; import org.nuiton.eugene.writer.ChainedFileWriterData; @@ -284,6 +285,14 @@ protected String extractedPackages; /** + * A flag to fail if model properties is not safe (means some tagValues or stereotypes are not correct). + * + * @since 2.9 + */ + @Parameter(property = "eugene.failIfUnsafe", defaultValue = "false") + protected boolean failIfUnsafe; + + /** * Maven project. * * @since 2.0.0 @@ -436,26 +445,18 @@ properties.put(XmiChainedFileWriter.PROP_RESOLVER, resolver); } - if (engine.containsWriter("xmlmodel")) { + if (engine.containsWriter("model")) { - // add xml model writer support + // add model writer support - properties.put(XmlModelChainedFileWriter.PROP_TAG_VALUE_DEFINITION_PROVIDER, + properties.put(BaseChainedFileWriterToMemoryModel.PROP_TAG_VALUE_DEFINITION_PROVIDER, getTagValueDefinitionProvider()); - properties.put(XmlModelChainedFileWriter.PROP_STEREOTYPE_DEFINITION_PROVIDER, + properties.put(BaseChainedFileWriterToMemoryModel.PROP_STEREOTYPE_DEFINITION_PROVIDER, getStereotypeDefinitionProvider()); - } - if (engine.containsWriter("yamlmodel")) { - - // add yaml model writer support - - properties.put(YamlModelChainedFileWriter.PROP_TAG_VALUE_DEFINITION_PROVIDER, - getTagValueDefinitionProvider()); - - properties.put(YamlModelChainedFileWriter.PROP_STEREOTYPE_DEFINITION_PROVIDER, - getStereotypeDefinitionProvider()); + properties.put(BaseChainedFileWriterToMemoryModel.PROP_FAIL_IF_UNSAFE, + failIfUnsafe); } // init templates @@ -520,8 +521,12 @@ // obtains data to react for this writer ChainedFileWriterData data = engine.getData(writer); - // launch generation - writer.generate(this, data); + try { + // launch generation + writer.generate(this, data); + } catch (InvalidModelPropertiesException e) { + throw new MojoFailureException("failIfUnsafe flag is on, and some errors occurs while loading model.", e); + } if (writer instanceof ChainedFileWriterToMemoryModel) { // keep result Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java =================================================================== --- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -53,6 +53,8 @@ public static final String PROP_STEREOTYPE_DEFINITION_PROVIDER = "stereotypeDefinitionProvider"; + public static final String PROP_FAIL_IF_UNSAFE = "failIfUnsafe"; + @Deprecated public static final String PROP_MODEL_PROPERTIES_PROVIDER = "modelPropertiesProvider"; @@ -70,7 +72,8 @@ PROP_MODEL_READER, "xmlModelReader", PROP_TAG_VALUE_DEFINITION_PROVIDER, "tagValueDefinitionProvider", PROP_STEREOTYPE_DEFINITION_PROVIDER, "stereotypeDefinitionProvider", - PROP_MODEL_PROPERTIES_PROVIDER, "modelPropertiesProvider" + PROP_MODEL_PROPERTIES_PROVIDER, "modelPropertiesProvider", + PROP_FAIL_IF_UNSAFE, "failIfUnsafe" ); } @@ -127,6 +130,11 @@ return getProperty(PROP_STEREOTYPE_DEFINITION_PROVIDER, StereotypeDefinitionProvider.class); } + protected boolean isFailIfUnsafe() { + Boolean property = getProperty(PROP_FAIL_IF_UNSAFE, Boolean.class); + return property != null && property; + } + @Override protected void initWriter(ChainedFileWriterConfiguration configuration) { super.initWriter(configuration); @@ -138,19 +146,20 @@ String modelType = configuration.getModelType(); + ModelReader<?> modelReader; + if (getReader() != null) { + // use a specific reader String reader = getReader(); try { ClassLoader fixedClassLoader = loader; - ModelReader<?> modelReader = (ModelReader<?>) - Class.forName(reader, true, - fixedClassLoader).newInstance(); + modelReader = (ModelReader<?>) Class.forName(reader, true, + fixedClassLoader).newInstance(); String modelTypeFromReader = modelReader.getModelType(); if (!modelType.equals(modelTypeFromReader)) { throw new IllegalStateException("Model reader [" + modelTypeFromReader + "] does not match with modelType: " + modelType); } - properties.put(PROP_MODEL_READER, modelReader); } catch (IllegalStateException eee) { throw eee; } catch (Exception eee) { @@ -160,7 +169,8 @@ } else { String inputType = getInputType(); - ModelReader<?> modelReader = configuration.getModelHelper().getModelReader(modelType, inputType); + + modelReader = configuration.getModelHelper().getModelReader(modelType, inputType); if (modelReader == null) { throw new IllegalStateException( "could not find a model reader for modelType: " + @@ -168,8 +178,10 @@ configuration.getModelHelper().getModelReaders().values() ); } - properties.put(PROP_MODEL_READER, modelReader); + } + modelReader.setStrictLoading(isFailIfUnsafe()); + properties.put(PROP_MODEL_READER, modelReader); } boolean verbose = configuration.isVerbose(); @@ -177,13 +189,6 @@ getModelReader().setStereotypeDefinitionProvider(getStereotypeDefinitionProvider()); getModelReader().setTagValueDefinitionProvider(getTagValueDefinitionProvider()); -// // gets the provider of safe tag values and stereotypes -// ModelPropertiesUtil.ModelPropertiesProvider propertiesProvider = -// getModelPropertiesProvider(); -// -// // affect it to the model reader -// getModelReader().setModelPropertiesProvider(propertiesProvider); - // set the verbose level of the model reader getModelReader().setVerbose(verbose); } Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java =================================================================== --- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -50,7 +50,9 @@ * * @author tchemit * @since 2.0.0 + * @deprecated since 2.6.3, will be removed in 3.0, use instead {@link XmlModelChainedFileWriter}. */ +@Deprecated public class ModelChainedFileWriter extends BaseChainedFileWriter { public static final String PROP_GENERATED_PACKAGES = Template.PROP_GENERATED_PACKAGES; Modified: trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java =================================================================== --- trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java 2014-04-27 13:34:28 UTC (rev 1347) +++ trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java 2014-05-01 12:17:20 UTC (rev 1348) @@ -171,7 +171,7 @@ output.write("\n"); } - public String getFromStereotypes(Collection<String> stereotypes) { + public String getFromStereotypes(Set<String> stereotypes) { StringBuilder stereotype = new StringBuilder(""); if (stereotypes.size() > 0) { stereotype.append("<< ");
participants (1)
-
tchemit@users.nuiton.org