branch develop updated (4ff5f4f -> cca191f)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git from 4ff5f4f Update parent pom new c65e5d2 Add ResourcesHelper (See #3930) new 00bdb91 Use ResourcesHelper where we cans and depreciates some methods new cca191f Fixes #3930 Merge branch 'feature/3930' into develop The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit cca191f6df2b91253bed985f264010524f954ec0 Merge: 4ff5f4f 00bdb91 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 8 16:53:42 2016 +0200 Fixes #3930 Merge branch 'feature/3930' into develop commit 00bdb91f49ba6e8d12986cd14ee9ae8ee86770cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 8 16:53:35 2016 +0200 Use ResourcesHelper where we cans and depreciates some methods commit c65e5d29120dda0c64b0068f735dc7da9156cb4c Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 8 16:53:17 2016 +0200 Add ResourcesHelper (See #3930) Summary of changes: .../eugene/java/AbstractJavaBeanTransformer.java | 2 +- .../java/org/nuiton/eugene/ResourcesHelper.java | 88 ++++++++++++++++++++++ .../src/main/java/org/nuiton/eugene/Template.java | 7 ++ .../eugene/java/ObjectModelTransformerToJava.java | 25 ++---- 4 files changed, 103 insertions(+), 19 deletions(-) create mode 100644 eugene/src/main/java/org/nuiton/eugene/ResourcesHelper.java -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git commit c65e5d29120dda0c64b0068f735dc7da9156cb4c Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 8 16:53:17 2016 +0200 Add ResourcesHelper (See #3930) --- .../java/org/nuiton/eugene/ResourcesHelper.java | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/eugene/src/main/java/org/nuiton/eugene/ResourcesHelper.java b/eugene/src/main/java/org/nuiton/eugene/ResourcesHelper.java new file mode 100644 index 0000000..a0369a9 --- /dev/null +++ b/eugene/src/main/java/org/nuiton/eugene/ResourcesHelper.java @@ -0,0 +1,88 @@ +package org.nuiton.eugene; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.net.URL; + +/** + * Some useful methods to locate resources. + * + * Created on 08/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0 + */ +public class ResourcesHelper { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ResourcesHelper.class); + + protected final ClassLoader classLoader; + protected final boolean verbose; + + public ResourcesHelper(ClassLoader classLoader, boolean verbose) { + this.classLoader = classLoader; + this.verbose = verbose; + } + + /** + * Checks if the given fully qualified name java file is in class-path and log a message that fqn will not generated if found. + * + * @param fqn fully qualified name to test + * @return {@code true} if java file was found in class-path, {@code false} otherwise. + */ + public boolean isJavaFileInClassPath(String fqn) { + return isFullyQualifiedNameInClassPath(fqn, ".java"); + } + + /** + * Checks if the given fully qualified name (path separated by {@code pathSeparator} and optionaly suffixed by + * {@code extension}) is in class-path and log a message that fqn will not generated if found. + * + * @param extension file extension + * @param fqn fully qualified name to test + * @return {@code true} if resource was found in class-path, {@code false} otherwise. + */ + public boolean isFullyQualifiedNameInClassPath(String fqn, String extension) { + return isInClassPath(fqn,"\\.", extension); + } + + /** + * Checks if the given fully qualified name (path separated by {@code pathSeparator} and optionaly suffixed by + * {@code extension}) is in class-path and log a message that fqn will not generated if found. + * + * @param extension file extension + * @param fqn fully qualified name to test + * @return {@code true} if resource was found in class-path, {@code false} otherwise. + */ + public boolean isInClassPath(String fqn, String pathSeparator, String extension) { + + URL fileLocation = getFileInClassPath(fqn, pathSeparator, extension); + + if (fileLocation != null) { + + // there is already a existing file in class-path, skip + + if (log.isDebugEnabled()) { + log.debug("Will not generate [" + fqn + "], already found in class-path at location : " + fileLocation); + } else if (verbose) { + log.info("Will not generate [" + fqn + "], already found in class-path."); + } + + return true; + } + + // is not found + return false; + } + + protected URL getFileInClassPath(String fqn, String pathSeparator, String extension) { + String resourceName = fqn.replaceAll(pathSeparator, "/") + extension; + URL fileLocation = classLoader.getResource(resourceName); + if (log.isDebugEnabled()) { + log.debug("Look for resource : " + resourceName + " = " + fileLocation); + } + return fileLocation; + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git commit 00bdb91f49ba6e8d12986cd14ee9ae8ee86770cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 8 16:53:35 2016 +0200 Use ResourcesHelper where we cans and depreciates some methods --- .../eugene/java/AbstractJavaBeanTransformer.java | 2 +- .../src/main/java/org/nuiton/eugene/Template.java | 7 ++++++ .../eugene/java/ObjectModelTransformerToJava.java | 25 ++++++---------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java index fd48793..4f2549f 100644 --- a/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java +++ b/eugene-java-templates/src/main/java/org/nuiton/eugene/java/AbstractJavaBeanTransformer.java @@ -80,7 +80,7 @@ public abstract class AbstractJavaBeanTransformer extends ObjectModelTransformer protected boolean notFoundInClassPath(ObjectModelClass input, String className) { String fqn = input.getPackageName() + "." + className; - boolean inClassPath = isInClassPath(fqn); + boolean inClassPath = getResourcesHelper().isJavaFileInClassPath(fqn); return !inClassPath; } diff --git a/eugene/src/main/java/org/nuiton/eugene/Template.java b/eugene/src/main/java/org/nuiton/eugene/Template.java index 950ecbb..aa8980b 100644 --- a/eugene/src/main/java/org/nuiton/eugene/Template.java +++ b/eugene/src/main/java/org/nuiton/eugene/Template.java @@ -57,6 +57,7 @@ public abstract class Template<M extends Model> implements TemplateConfiguration /** Model */ protected M model; + protected ResourcesHelper resourcesHelper; public abstract void applyTemplate(M model, File destDir) throws IOException; @@ -164,4 +165,10 @@ public abstract class Template<M extends Model> implements TemplateConfiguration return model; } + protected ResourcesHelper getResourcesHelper() { + if (resourcesHelper == null) { + resourcesHelper = new ResourcesHelper(getClassLoader(), isVerbose()); + } + return resourcesHelper; + } } diff --git a/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java b/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java index 40b5f17..52072fa 100644 --- a/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java +++ b/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java @@ -978,7 +978,9 @@ public abstract class ObjectModelTransformerToJava extends ObjectModelTransforme * @return {@code true} if fqn of classifier was found in class-path, * {@code false} otherwise. * @since 2.5 + * @deprecated since 3.0, use the {@link #getResourcesHelper()} object directly. */ + @Deprecated protected boolean isInClassPath(ObjectModelClassifier classifier) { return isInClassPath(classifier.getQualifiedName()); } @@ -991,26 +993,11 @@ public abstract class ObjectModelTransformerToJava extends ObjectModelTransforme * @return {@code true} if fqn was found in class-path, * {@code false} otherwise. * @since 2.5 + * @deprecated since 3.0, use the {@link #getResourcesHelper()} object directly. */ + @Deprecated protected boolean isInClassPath(String fqn) { - - URL fileLocation = getFileInClassPath(fqn); - - if (fileLocation != null) { - - // there is already a existing file in class-path, skip - - if (log.isDebugEnabled()) { - log.debug("Will not generate [" + fqn + "], already found in class-path at location : " + fileLocation); - } else if (isVerbose()) { - log.info("Will not generate [" + fqn + "], already found in class-path."); - } - - return true; - } - - // is not found - return false; + return getResourcesHelper().isJavaFileInClassPath(fqn); } /** @@ -1022,7 +1009,9 @@ public abstract class ObjectModelTransformerToJava extends ObjectModelTransforme * @return {@code true} if fqn was found in class-path, * {@code false} otherwise. * @since 2.7.1 + * @deprecated since 3.0, use the {@link #getResourcesHelper()} object directly. */ + @Deprecated protected boolean isInClassPath(String packageName, String className) { return isInClassPath(packageName + "." + className); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git commit cca191f6df2b91253bed985f264010524f954ec0 Merge: 4ff5f4f 00bdb91 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Apr 8 16:53:42 2016 +0200 Fixes #3930 Merge branch 'feature/3930' into develop .../eugene/java/AbstractJavaBeanTransformer.java | 2 +- .../java/org/nuiton/eugene/ResourcesHelper.java | 88 ++++++++++++++++++++++ .../src/main/java/org/nuiton/eugene/Template.java | 7 ++ .../eugene/java/ObjectModelTransformerToJava.java | 25 ++---- 4 files changed, 103 insertions(+), 19 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm