details:   https://code.openbravo.com/erp/devel/pi/rev/b31225b09af9
changeset: 35175:b31225b09af9
user:      Javier Armendáriz <javier.armendariz <at> openbravo.com>
date:      Wed Nov 28 17:15:40 2018 +0100
summary:   Fixed issue 39713: CopyLog4jConfigurationFromTemplates fails if no 
source.path.

Build validation task fails when source.path is not properly configured because
it uses this value as a base folder to copy the log4j config files. Using
another implementation based on user.dir system property to get the base folder
and failing if the resulting folder does not contain config folder.

diffstat:

 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/CopyLog4jConfigurationFromTemplates.class
 |  Bin 
 
src-util/buildvalidation/src/org/openbravo/buildvalidation/CopyLog4jConfigurationFromTemplates.java
            |   49 +++------
 2 files changed, 17 insertions(+), 32 deletions(-)

diffs (84 lines):

diff -r 9045f47e9ae7 -r b31225b09af9 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/CopyLog4jConfigurationFromTemplates.class
Binary file 
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/CopyLog4jConfigurationFromTemplates.class
 has changed
diff -r 9045f47e9ae7 -r b31225b09af9 
src-util/buildvalidation/src/org/openbravo/buildvalidation/CopyLog4jConfigurationFromTemplates.java
--- 
a/src-util/buildvalidation/src/org/openbravo/buildvalidation/CopyLog4jConfigurationFromTemplates.java
       Wed Nov 28 13:52:50 2018 +0100
+++ 
b/src-util/buildvalidation/src/org/openbravo/buildvalidation/CopyLog4jConfigurationFromTemplates.java
       Wed Nov 28 17:15:40 2018 +0100
@@ -18,16 +18,12 @@
  */
 package org.openbravo.buildvalidation;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.net.URL;
 import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Properties;
 
 import org.openbravo.base.ExecutionLimits;
 import org.openbravo.modulescript.OpenbravoVersion;
@@ -48,7 +44,7 @@
   @Override
   public List<String> execute() {
     try {
-      String sourcePath = 
getSourcePathFromProperties(getOpenbravoPropertiesFile());
+      String sourcePath = getSourcePath();
       copyFromTemplateFile(sourcePath + CONFIG_DIR + LOG4J_CONF_FILE);
       copyFromTemplateFile(sourcePath + CONFIG_DIR + LOG4J_WEB_CONF_FILE);
       copyFromTemplateFile(sourcePath + TEST_SRC_DIR + LOG4J_TEST_CONF_FILE);
@@ -71,36 +67,25 @@
   }
 
   /**
-   * Starting from the location of this class, navigates backwards through the 
file hierarchy until
-   * the config/Openbravo.properties is found
+   * Get the source path using the user.dir System Property. Navigates two 
folders backwards and
+   * checks the config directory is available to ensure the directory is an 
Openbravo instance,
+   * throwing an exception otherwise
    * 
-   * @return a File descriptor of Openbravo.properties
-   * @throws FileNotFoundException
-   *           if Openbravo.properties cannot be found
+   * @return String the source path
+   * @throws NoSuchFileException
+   *           when the source path directory is not valid
    */
-  private File getOpenbravoPropertiesFile() throws FileNotFoundException {
-    final URL url = this.getClass().getResource(getClass().getSimpleName() + 
".class");
-    File f = new File(url.getPath());
-    File propertiesFile;
-    while (f.getParentFile() != null && f.getParentFile().exists()) {
-      f = f.getParentFile();
-      final File configDirectory = new File(f, "config");
-      if (configDirectory.exists()) {
-        propertiesFile = new File(configDirectory, "Openbravo.properties");
-        if (propertiesFile.exists()) {
-          return propertiesFile;
-        }
-      }
+  private String getSourcePath() throws NoSuchFileException {
+    String userDir = System.getProperty("user.dir");
+    Path sourcePath = Paths.get(userDir, "/../..").normalize();
+
+    Path configDir = sourcePath.resolve("config");
+    if (Files.exists(configDir)) {
+      return sourcePath.toString();
     }
 
-    throw new FileNotFoundException("Openbravo.properties file not found");
-  }
-
-  private String getSourcePathFromProperties(File openbravoProperties) throws 
Exception {
-    Properties properties = new Properties();
-    properties.load(new FileReader(openbravoProperties));
-
-    return properties.getProperty("source.path");
+    throw new NoSuchFileException("Source path directory is not valid. Cannot 
find "
+        + configDir.toString());
   }
 
   @Override


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to