mboapache commented on code in PR #85:
URL: https://github.com/apache/db-jdo/pull/85#discussion_r1387172217


##########
exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java:
##########
@@ -263,231 +396,261 @@ public void execute() throws MojoExecutionException, 
MojoFailureException {
     } catch (IOException ex) {
       Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
     }
+  }
 
-    // Get ClassLoader URLs to build classpath below
-    URL[] cpURLs = ((URLClassLoader) 
Thread.currentThread().getContextClassLoader()).getURLs();
-    ArrayList<URL> urlList = new ArrayList<>(Arrays.asList(cpURLs));
-
-    // Get contents of pmf properties file to build new file below
-    String pmfPropsReadFileName = confDirectory + File.separator + 
pmfProperties;
-    String defaultPropsContents = "";
+  /**
+   * Get classpath string: add new entries to URLS from loader
+   *
+   * @param urlList ClassLoader URLs
+   * @param enhancedDir
+   * @return
+   */
+  private String getClasspathString(List<URL> urlList, File enhancedDir) {
+    String cpString;
+    ArrayList<URL> cpList = new ArrayList<>();
+    cpList.addAll(urlList);
     try {
-      defaultPropsContents = Utilities.readFile(pmfPropsReadFileName);
-    } catch (IOException ex) {
+      URL url1 = enhancedDir.toURI().toURL();
+      URL url2 =
+          new File(buildDirectory + File.separator + CLASSES_DIR_NAME + 
File.separator)
+              .toURI()
+              .toURL();
+      if (runtckVerbose) {
+        System.out.println("url2 is " + url2.toString());
+      }
+      cpList.add(url1);
+      cpList.add(url2);
+      String[] jars = {"jar"};
+      Iterator<File> fi = FileUtils.iterateFiles(new File(extLibsDirectory), 
jars, true);
+      while (fi.hasNext()) {
+        cpList.add(fi.next().toURI().toURL());
+      }
+      for (String dependency : 
this.dependencyClasspath.split(File.pathSeparator)) {
+        cpList.add(new File(dependency).toURI().toURL());
+      }
+    } catch (MalformedURLException ex) {
+      ex.printStackTrace();
       Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
     }
+    cpString = Utilities.urls2ClasspathString(cpList);
+    if (runtckVerbose) {
+      System.out.println("\nClasspath is " + cpString);
+    }
+    return cpString;
+  }
 
-    // Reset logfile content (may not be empty if previous run crashed)
-    resetFileContent(implLogFile);
-    resetFileContent(TCK_LOG_FILE);
-
-    int failureCount = 0;
-    for (String db : dbs) {
-      System.setProperty("jdo.tck.database", db);
-      alreadyran = false;
-
-      for (String idtype : idtypes) {
-        List<String> idPropsString = new ArrayList<>();
-        idPropsString.addAll(propsString);
-        idPropsString.add("-Djdo.tck.identitytype=" + idtype);
-        String enhancedDirName =
-            buildDirectory
-                + File.separator
-                + "enhanced"
-                + File.separator
-                + impl
-                + File.separator
-                + idtype
-                + File.separator;
-        File enhancedDir = new File(enhancedDirName);
-        if (!(enhancedDir.exists())) {
-          throw new MojoExecutionException(
-              "Could not find enhanced directory "
-                  + enhancedDirName
-                  + ". Execute Enhance goal before RunTCK.");
-        }
-
-        // Set classpath string: add new entries to URLS from loader
-        ArrayList<URL> cpList = new ArrayList<>();
-        cpList.addAll(urlList);
-        try {
-          URL url1 = enhancedDir.toURI().toURL();
-          URL url2 =
-              new File(buildDirectory + File.separator + CLASSES_DIR_NAME + 
File.separator)
-                  .toURI()
-                  .toURL();
-          if (runtckVerbose) {
-            System.out.println("url2 is " + url2.toString());
-          }
-          cpList.add(url1);
-          cpList.add(url2);
-          String[] jars = {"jar"};
-          Iterator<File> fi = FileUtils.iterateFiles(new 
File(extLibsDirectory), jars, true);
-          while (fi.hasNext()) {
-            cpList.add(fi.next().toURI().toURL());
-          }
-          for (String dependency : 
this.dependencyClasspath.split(File.pathSeparator)) {
-            cpList.add(new File(dependency).toURI().toURL());
-          }
-        } catch (MalformedURLException ex) {
-          ex.printStackTrace();
-          Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        cpString = Utilities.urls2ClasspathString(cpList);
-        if (runtckVerbose) {
-          System.out.println("\nClasspath is " + cpString);
-        }
-
-        for (String cfg : cfgs) {
-          List<String> cfgPropsString = new ArrayList<>();
-          cfgPropsString.addAll(idPropsString);
-          // Parse conf file and set properties String
-          props = PropertyUtils.getProperties(confDirectory + File.separator + 
cfg);
-          cfgPropsString.add(
-              "-Djdo.tck.testdata=" + getTrimmedPropertyValue(props, 
"jdo.tck.testdata"));
-          cfgPropsString.add(
-              "-Djdo.tck.standarddata=" + getTrimmedPropertyValue(props, 
"jdo.tck.standarddata"));
-          cfgPropsString.add(
-              "-Djdo.tck.mapping.companyfactory="
-                  + getTrimmedPropertyValue(props, 
"jdo.tck.mapping.companyfactory"));
-          cfgPropsString.add(
-              "-Djdo.tck.requiredOptions="
-                  + getTrimmedPropertyValue(props, "jdo.tck.requiredOptions"));
-          cfgPropsString.add("-Djdo.tck.signaturefile=" + signaturefile);
-          String mapping = getTrimmedPropertyValue(props, "jdo.tck.mapping");
-          if (mapping == null) {
-            throw new MojoExecutionException("Could not find mapping value in 
conf file: " + cfg);
-          }
-          String classes = getTrimmedPropertyValue(props, "jdo.tck.classes");
-          String excludeList =
-              
getTrimmedPropertyValue(PropertyUtils.getProperties(excludeFile), 
"jdo.tck.exclude");
-          if (classes == null) {
-            throw new MojoExecutionException("Could not find classes value in 
conf file: " + cfg);
-          }
-          classes = Utilities.removeSubstrs(classes, excludeList);
-          if (classes.equals("")) {
-            System.out.println("Skipping configuration " + cfg + ": classes 
excluded");
-            continue;
-          }
-          List<String> classesList = Arrays.asList(classes.split(" "));
-
-          cfgPropsString.add("-Djdo.tck.schemaname=" + idtype + mapping);
-          cfgPropsString.add("-Djdo.tck.cfg=" + cfg);
-
-          runonce = getTrimmedPropertyValue(props, "runOnce");
-          runonce = (runonce == null) ? "false" : runonce;
-
-          // Add Mapping and schemaname to properties file
-          StringBuilder propsFileData = new StringBuilder();
-          propsFileData.append("\n### Properties below added by maven 2 goal 
RunTCK.jdori");
-          propsFileData.append("\njavax.jdo.mapping.Schema=" + idtype + 
mapping);
-          mapping = (mapping.equals("0")) ? "" : mapping;
-          propsFileData.append("\njavax.jdo.option.Mapping=standard" + 
mapping);
-          propsFileData.append("\n");
-          String pmfPropsWriteFileName =
-              buildDirectory + File.separator + CLASSES_DIR_NAME + 
File.separator + pmfProperties;
-          try {
-            BufferedWriter out = new BufferedWriter(new 
FileWriter(pmfPropsWriteFileName, false));
-            out.write(defaultPropsContents + propsFileData.toString());
-            out.close();
-          } catch (IOException ex) {
-            Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null, 
ex);
-          }
-
-          // build command line string
-          command = new ArrayList<>();
-          command.add("java");
-          command.add("-cp");
-          command.add(cpString);
-          command.addAll(cfgPropsString);
-          command.add(dbproperties);
-          command.add(jvmproperties);
-          if (debugTCK) {
-            command.add(debugDirectives);
-          }
-          command.add(testRunnerClass);
-          command.addAll(classesList);
+  /**
+   * Create the jdo pmf properties file.
+   *
+   * @param idtype identity type
+   * @param mapping the mapping index
+   * @param defaultPropsContents default pmf properties
+   */
+  private void writePMFPropsFile(String idtype, String mapping, String 
defaultPropsContents) {
+    StringBuilder propsFileData = new StringBuilder();
+    propsFileData.append("\n### Properties below added by maven 2 goal 
RunTCK.jdori");
+    propsFileData.append("\njavax.jdo.mapping.Schema=" + idtype + mapping);
+    mapping = (mapping.equals("0")) ? "" : mapping;

Review Comment:
   I double checked this. The old code used the variable mapping only once 
after the code of the method writePMFPropsFile and this is in the 
System.out.println "*> Running tests for ...". So this code change does not 
result in a bug.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jdo-dev-unsubscr...@db.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to