]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java
1, Make exception string friendly, readable.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / PlatformPcdPreprocessActionForBuilding.java
index 2e50531d7e6111005301916093ca542cbedf7cbb..fd1ae56eb646bcfd71281f3ce6fa30a753e0a5b4 100644 (file)
@@ -39,6 +39,8 @@ import org.tianocore.pcd.entity.Token;
 import org.tianocore.pcd.entity.UsageIdentification;\r
 import org.tianocore.pcd.exception.EntityException;\r
 import org.tianocore.pcd.action.PlatformPcdPreprocessAction;\r
+import org.tianocore.build.exception.PlatformPcdPreprocessBuildException;\r
+import org.tianocore.pcd.exception.PlatformPcdPreprocessException;\r
 \r
 /**\r
    This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
@@ -46,11 +48,6 @@ import org.tianocore.pcd.action.PlatformPcdPreprocessAction;
    from buildAction or UIAction.\r
 **/\r
 public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreprocessAction {\r
-    ///\r
-    /// Workspacepath hold the workspace information.\r
-    ///\r
-    private String                      workspacePath;\r
-\r
     ///\r
     /// FPD file is the root file.\r
     ///\r
@@ -66,15 +63,6 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
     ///\r
     private PlatformSurfaceAreaDocument fpdDocInstance;\r
 \r
-    /**\r
-      Set WorkspacePath parameter for this action class.\r
-\r
-      @param workspacePath parameter for this action\r
-    **/\r
-    public void setWorkspacePath(String workspacePath) {\r
-        this.workspacePath = workspacePath;\r
-    }\r
-\r
     /**\r
       Set action message level for CollectPcdAction tool.\r
 \r
@@ -99,17 +87,16 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
     /**\r
       Common function interface for outer.\r
 \r
-      @param workspacePath The path of workspace of current build or analysis.\r
-      @param fpdFilePath   The fpd file path of current build or analysis.\r
-      @param messageLevel  The message level for this Action.\r
+      @param fpdFilePath    The fpd file path of current build or analysis.\r
+      @param messageLevel   The message level for this Action.\r
 \r
-      @throws  Exception The exception of this function. Because it can *not* be predict\r
-                         where the action class will be used. So only Exception can be throw.\r
+      @throws  PlatformPreprocessBuildException \r
+                            The exception of this function. Because it can *not* be predict\r
+                            where the action class will be used. So only Exception can be throw.\r
 \r
     **/\r
-    public void perform(String workspacePath, String fpdFilePath,\r
-                        int messageLevel) throws Exception {\r
-        setWorkspacePath(workspacePath);\r
+    public void perform(String fpdFilePath, int messageLevel) \r
+        throws PlatformPcdPreprocessBuildException {\r
         setFPDFilePath(fpdFilePath);\r
         setActionMessageLevel(messageLevel);\r
         checkParameter();\r
@@ -132,32 +119,34 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
       @throws  EntityException Exception indicate failed to execute this action.\r
 \r
     **/\r
-    public void execute() throws EntityException {\r
-        MemoryDatabaseManager pcdDbManager = null;\r
-\r
+    public void execute() throws PlatformPcdPreprocessBuildException {\r
+        String errorMessageHeader = "Fail to initialize Pcd memory database for building. Because:";\r
         //\r
         // Get memoryDatabaseManager instance from GlobalData.\r
-        // The memoryDatabaseManager should be initialized for whatever build\r
-        // tools or wizard tools\r
+        // The memoryDatabaseManager should be initialized as static variable\r
+        // in some Pre-process class.\r
         //\r
-        if((pcdDbManager = GlobalData.getPCDMemoryDBManager()) == null) {\r
-            throw new EntityException("The instance of PCD memory database manager is null");\r
-        }\r
-\r
-        this.setPcdDbManager(pcdDbManager);\r
+        setPcdDbManager(GlobalData.getPCDMemoryDBManager());\r
 \r
         //\r
         // Collect all PCD information defined in FPD file.\r
         // Evenry token defind in FPD will be created as an token into\r
         // memory database.\r
         //\r
-        initPcdMemoryDbWithPlatformInfo();\r
+        try {\r
+            initPcdMemoryDbWithPlatformInfo();\r
+        } catch (PlatformPcdPreprocessException exp) {\r
+            throw new PlatformPcdPreprocessBuildException(errorMessageHeader + exp.getMessage());\r
+        }\r
 \r
         //\r
         // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
         //\r
-        genPcdDatabaseSourceCode ();\r
-\r
+        try {\r
+            genPcdDatabaseSourceCode ();\r
+        } catch (EntityException exp) {\r
+            throw new PlatformPcdPreprocessBuildException(errorMessageHeader + exp.getMessage());\r
+        }\r
     }\r
 \r
     /**\r
@@ -166,13 +155,15 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
       @param guidCName      Guid CName string.\r
 \r
       @return String[]      Guid information from SPD file.\r
+      @throws PlatformPcdPreprocessException\r
+                            Fail to get Guid information from SPD file.\r
     **/\r
-    public String[] getGuidInfoFromSpd(String guidCName) throws EntityException {\r
+    public String[] getGuidInfoFromSpd(String guidCName) throws PlatformPcdPreprocessException {\r
         String[] tokenSpaceStrRet = null;\r
         try {\r
             tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(guidCName);\r
         } catch ( Exception e ) {\r
-            throw new EntityException ("Failed get Guid CName " + guidCName + "from SPD file!");\r
+            throw new PlatformPcdPreprocessException ("Failed get Guid CName " + guidCName + "from SPD file!");\r
         }\r
         return tokenSpaceStrRet;\r
     }\r
@@ -180,7 +171,6 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
     /**\r
       This function generates source code for PCD Database.\r
 \r
-      @param void\r
       @throws EntityException  If the token does *not* exist in memory database.\r
 \r
     **/\r
@@ -210,11 +200,12 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
 \r
       This function maybe provided by some Global class.\r
 \r
-      @return List<ModuleInfo> the component array.\r
+      @return List<ModuleInfo>                  the component array.\r
+      @throws PlatformPcdPreprocessException    get all modules in <ModuleSA> in FPD file.\r
 \r
-     */\r
+    **/\r
     public List<ModulePcdInfoFromFpd> getComponentsFromFpd()\r
-        throws EntityException {\r
+        throws PlatformPcdPreprocessException {\r
         List<ModulePcdInfoFromFpd>                  allModules          = new ArrayList<ModulePcdInfoFromFpd>();\r
         Map<FpdModuleIdentification, XmlObject>     pcdBuildDefinitions = null;\r
         UsageIdentification                         usageId             = null;\r
@@ -246,15 +237,14 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
        Override function: Verify the datum value according its datum size and datum type, this\r
        function maybe moved to FPD verification tools in future.\r
 \r
-       @param cName\r
-       @param moduleName\r
-       @param datum\r
-       @param datumType\r
-       @param maxDatumSize\r
+       @param cName         The token name\r
+       @param moduleName    The module who use this PCD token\r
+       @param datum         The PCD's datum\r
+       @param datumType     The PCD's datum type\r
+       @param maxDatumSize  The max size for PCD's Datum.\r
 \r
-       @return String\r
+       @return String       exception strings.\r
      */\r
-    /***/\r
     public String verifyDatum(String            cName,\r
                               String            moduleName,\r
                               String            datum,\r
@@ -584,7 +574,7 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
     **/\r
     public DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFpd(Token     token,\r
                                                                          String    moduleName)\r
-        throws EntityException {\r
+        throws PlatformPcdPreprocessException {\r
         int    index             = 0;\r
         String exceptionString   = null;\r
         String dynamicPrimaryKey = null;\r
@@ -600,9 +590,9 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
             try {\r
                 fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
             } catch(IOException ioE) {\r
-                throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
+                throw new PlatformPcdPreprocessException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
             } catch(XmlException xmlE) {\r
-                throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
+                throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
             }\r
         }\r
 \r
@@ -612,7 +602,7 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
                                             "PCD entry %s in module %s!",\r
                                             token.cName,\r
                                             moduleName);\r
-            throw new EntityException(exceptionString);\r
+            throw new PlatformPcdPreprocessException(exceptionString);\r
         }\r
 \r
         dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
@@ -620,11 +610,11 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
             try {\r
                 tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName());\r
             } catch (Exception e) {\r
-                throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
+                throw new PlatformPcdPreprocessException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
             }\r
 \r
             if (tokenSpaceStrRet == null) {\r
-                throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
+                throw new PlatformPcdPreprocessException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
             }\r
 \r
             dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
@@ -640,11 +630,13 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
     /**\r
        Override function: get all <DynamicPcdBuildDefinition> from FPD file.\r
 \r
-       @return List<DynamicPcdBuildDefinitions.PcdBuildData>\r
+       @return List<DynamicPcdBuildDefinitions.PcdBuildData>    All DYNAMIC PCD list in <DynamicPcdBuildDefinitions> in FPD file.\r
+       @throws PlatformPcdPreprocessBuildException              Failure to get dynamic information list.\r
+\r
     **/\r
     public List<DynamicPcdBuildDefinitions.PcdBuildData>\r
                                             getAllDynamicPcdInfoFromFpd()\r
-        throws EntityException {\r
+        throws PlatformPcdPreprocessException {\r
         DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
 \r
         //\r
@@ -655,9 +647,9 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
             try {\r
                 fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
             } catch(IOException ioE) {\r
-                throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
+                throw new PlatformPcdPreprocessException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
             } catch(XmlException xmlE) {\r
-                throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
+                throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
             }\r
         }\r
 \r
@@ -672,28 +664,23 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
     /**\r
       check parameter for this action.\r
 \r
-      @throws EntityException  Bad parameter.\r
+      @throws PlatformPcdPreprocessBuildException  Bad parameter.\r
     **/\r
-    private void checkParameter() throws EntityException {\r
+    private void checkParameter() throws PlatformPcdPreprocessBuildException {\r
         File file = null;\r
 \r
-        if((fpdFilePath    == null) ||(workspacePath  == null)) {\r
-            throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
+        if (fpdFilePath == null) {\r
+            throw new PlatformPcdPreprocessBuildException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
         }\r
 \r
-        if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {\r
-            throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
-        }\r
-\r
-        file = new File(workspacePath);\r
-        if(!file.exists()) {\r
-            throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");\r
+        if (fpdFilePath.length() == 0) {\r
+            throw new PlatformPcdPreprocessBuildException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
         }\r
 \r
         file = new File(fpdFilePath);\r
 \r
         if(!file.exists()) {\r
-            throw new EntityException("FPD File " + fpdFilePath + " does not exist!");\r
+            throw new PlatformPcdPreprocessBuildException("FPD File " + fpdFilePath + " does not exist!");\r
         }\r
     }\r
 \r
@@ -702,10 +689,9 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces
 \r
       @param argv  parameter from command line\r
     **/\r
-    public static void main(String argv[]) throws EntityException {\r
+    public static void main(String argv[]) throws PlatformPcdPreprocessBuildException {\r
         PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r
         String projectDir = "x:/edk2";\r
-        ca.setWorkspacePath(projectDir);\r
         ca.setFPDFilePath(projectDir + "/EdkNt32Pkg/Nt32.fpd");\r
         ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r