[stack] jdk7: JDK7 build validation needs to be executed the very first
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 27 Sep 2016 15:32:57 +0200
changeset 30602 0ce4739a898b
parent 30601 7240dd41e2d7
child 30603 27becd2271e8
[stack] jdk7: JDK7 build validation needs to be executed the very first

If it fails (running in JVM 6) no other validations compiled with JDK 7 can be
even loaded.
src-core/src/org/openbravo/buildvalidation/BuildValidationHandler.java
--- a/src-core/src/org/openbravo/buildvalidation/BuildValidationHandler.java	Tue Sep 27 15:31:19 2016 +0200
+++ b/src-core/src/org/openbravo/buildvalidation/BuildValidationHandler.java	Tue Sep 27 15:32:57 2016 +0200
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2010-2015 Openbravo S.L.U.
+ * Copyright (C) 2010-2016 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -23,6 +23,16 @@
 public class BuildValidationHandler {
   private static final Logger log4j = Logger.getLogger(BuildValidationHandler.class);
 
+  /** Prerequisite validations are ensured to be executed before the rest of other ones */
+  @SuppressWarnings("serial")
+  private static final List<String> prerequisiteValidations = new ArrayList<String>() {
+    {
+      // guarantee current JVM version before executing other validations that can be compiled with
+      // a higher version
+      add("org.openbravo.buildvalidation.JdkVersionCheck");
+    }
+  };
+
   private static File basedir;
   private static String module;
 
@@ -48,6 +58,7 @@
       }
       Collections.sort(modFolders);
     }
+
     for (File modFolder : modFolders) {
       if (modFolder.isDirectory()) {
         File validationFolder = new File(modFolder, "build/classes");
@@ -56,6 +67,9 @@
         }
       }
     }
+
+    sortPrerequisites(classes);
+
     for (String s : classes) {
       ArrayList<String> errors = new ArrayList<String>();
       try {
@@ -79,6 +93,16 @@
     }
   }
 
+  /** Prerequisites are set at the beginning of the list */
+  private static void sortPrerequisites(List<String> classes) {
+    Collections.reverse(prerequisiteValidations);
+    for (String prerequisite : prerequisiteValidations) {
+      if (classes.remove(prerequisite)) {
+        classes.add(0, prerequisite);
+      }
+    }
+  }
+
   private static void printMessage(List<String> errors) {
     String errorMessage = "";
     for (String error : errors) {