]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Fix EDKT508: FW should't build Log.log file in current directory
authorhche10x <hche10x@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 31 Jan 2007 08:20:54 +0000 (08:20 +0000)
committerhche10x <hche10x@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 31 Jan 2007 08:20:54 +0000 (08:20 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2341 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/FrameworkWizardUI.java
Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Log.java
Tools/bin/FrameworkWizard
Tools/bin/FrameworkWizard.bat
Tools/bin/fw
Tools/bin/fw.bat

index c3452d7b4c86741226cc0ce4dc464dd3c2205e57..69d47423a572ddd5244db64dcdbe7546c24f721c 100644 (file)
@@ -324,12 +324,22 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
      @return FrameworkWizardUI The instance of this class\r
      \r
      **/\r
-    public static FrameworkWizardUI getInstance() {\r
+    public static FrameworkWizardUI getInstance(String[] args) {\r
         if (fwui == null) {\r
-            fwui = new FrameworkWizardUI();\r
+            fwui = new FrameworkWizardUI(args);\r
         }\r
         return fwui;\r
     }\r
+    \r
+    /**\r
+    If the class hasn't an instnace, new one.\r
+    \r
+    @return FrameworkWizardUI The instance of this class\r
+    \r
+    **/\r
+   public static FrameworkWizardUI getInstance() {\r
+       return fwui;\r
+   }\r
 \r
     /**\r
      This method initializes jMenuBar \r
@@ -1794,8 +1804,11 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
      * Main class, start the GUI\r
      * \r
      */\r
-    public static void main(String[] args) {\r
-        FrameworkWizardUI module = FrameworkWizardUI.getInstance();\r
+    public static void main(String[] args) {      \r
+        //\r
+        // Start Main UI\r
+        //\r
+        FrameworkWizardUI module = FrameworkWizardUI.getInstance(args);\r
         module.setVisible(true);\r
     }\r
 \r
@@ -1803,9 +1816,9 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
      This is the default constructor\r
      \r
      **/\r
-    public FrameworkWizardUI() {\r
+    public FrameworkWizardUI(String[] args) {\r
         super();\r
-        init();\r
+        init(args);\r
     }\r
 \r
     /**\r
@@ -1813,7 +1826,7 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
      \r
      \r
      **/\r
-    private void init() {\r
+    private void init(String[] args) {\r
         //\r
         // Set current workspace and check\r
         // Check if exists WORKSPACE\r
@@ -1826,6 +1839,15 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
         //\r
         SplashScreen ss = new SplashScreen();\r
         ss.setVisible(true);\r
+        \r
+        //\r
+        // Go through args to check if enable log\r
+        //\r
+        for (int index = 0; index < args.length; index++) {\r
+            if (args[index].equals("--log") || args[index].equals("-l")) {\r
+                Log.setSaveLog(true);\r
+            }\r
+        }\r
 \r
         //\r
         // Init Global Data\r
index cab190946b2f66359e4f3e921826d8e9be334a54..49a7a3615bc8e14b0804935d41286825176f0ea3 100644 (file)
@@ -23,12 +23,18 @@ import java.io.IOException;
 import javax.swing.JOptionPane;\r
 \r
 import org.tianocore.frameworkwizard.FrameworkWizardUI;\r
+import org.tianocore.frameworkwizard.workspace.Workspace;\r
 \r
 /**\r
  The class is used to provides static interfaces to save log and error information\r
  \r
  **/\r
 public class Log {\r
+    //\r
+    //Log file directory path\r
+    //\r
+    private static String strLogDir = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + "Tools"\r
+                                      + DataType.FILE_SEPARATOR + "Logs";\r
 \r
     //\r
     //Log file\r
@@ -48,17 +54,22 @@ public class Log {
     //\r
     //Log file name\r
     //\r
-    static String strLogFileName = "Log.log";\r
+    private static String strLogFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.log";\r
 \r
     //\r
     //Wrn file name\r
     //\r
-    static String strWrnFileName = "Wrn.log";\r
+    private static String strWrnFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.wrn";\r
 \r
     //\r
     //Err file name\r
     //\r
-    static String strErrFileName = "Err.log";\r
+    private static String strErrFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.err";\r
+\r
+    //\r
+    //Flag for create log or not\r
+    //\r
+    private static boolean isSaveLog = false;\r
 \r
     /**\r
      Main class, used for test\r
@@ -88,7 +99,7 @@ public class Log {
     public static void log(String strItem, String strLog) {\r
         try {\r
             writeToLogFile(strItem + ":" + strLog);\r
-        } catch (IOException e) {\r
+        } catch (Exception e) {\r
             e.printStackTrace();\r
         }\r
     }\r
@@ -102,7 +113,7 @@ public class Log {
     public static void log(String strLog) {\r
         try {\r
             writeToLogFile(strLog);\r
-        } catch (IOException e) {\r
+        } catch (Exception e) {\r
             e.printStackTrace();\r
         }\r
     }\r
@@ -118,7 +129,7 @@ public class Log {
         try {\r
             writeToWrnFile("Warning when " + strItem + "::" + strWrn);\r
             showWrnMessage(strWrn);\r
-        } catch (IOException e) {\r
+        } catch (Exception e) {\r
             e.printStackTrace();\r
         }\r
     }\r
@@ -133,7 +144,7 @@ public class Log {
         try {\r
             writeToWrnFile("Warning::" + strWrn);\r
             showWrnMessage("Warning::" + strWrn);\r
-        } catch (IOException e) {\r
+        } catch (Exception e) {\r
             e.printStackTrace();\r
         }\r
     }\r
@@ -148,7 +159,7 @@ public class Log {
     public static void err(String strItem, String strErr) {\r
         try {\r
             writeToErrFile("Error when " + strItem + "::" + strErr);\r
-        } catch (IOException e) {\r
+        } catch (Exception e) {\r
             e.printStackTrace();\r
         }\r
     }\r
@@ -162,7 +173,7 @@ public class Log {
     public static void err(String strErr) {\r
         try {\r
             writeToErrFile("Error::" + strErr);\r
-        } catch (IOException e) {\r
+        } catch (Exception e) {\r
             e.printStackTrace();\r
         }\r
     }\r
@@ -176,8 +187,8 @@ public class Log {
      **/\r
     private static void showWrnMessage(String strErr) {\r
         String strReturn = Tools.wrapStringByWord(strErr);\r
-        JOptionPane\r
-                   .showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
+        JOptionPane.showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning",\r
+                                      JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
     }\r
 \r
     /**\r
@@ -187,21 +198,25 @@ public class Log {
      @throws IOException\r
      \r
      **/\r
-    private static void writeToLogFile(String strLog) throws IOException {\r
-        try {\r
-            if (fleLogFile == null) {\r
-                fleLogFile = new File(strLogFileName);\r
-                fleLogFile.createNewFile();\r
+    private static void writeToLogFile(String strLog) throws Exception {\r
+        if (isSaveLog) {\r
+            try {\r
+                createLogDir();\r
+                if (fleLogFile == null) {\r
+                    fleLogFile = new File(strLogFileName);\r
+                    fleLogFile.delete();\r
+                    fleLogFile.createNewFile();\r
+                }\r
+                FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
+                fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+                fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+                fos.flush();\r
+                fos.close();\r
+            } catch (FileNotFoundException e) {\r
+                e.printStackTrace();\r
+            } catch (IOException e) {\r
+                e.printStackTrace();\r
             }\r
-            FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
-            fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
-            fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
-            fos.flush();\r
-            fos.close();\r
-        } catch (FileNotFoundException e) {\r
-            e.printStackTrace();\r
-        } catch (IOException e) {\r
-            e.printStackTrace();\r
         }\r
     }\r
 \r
@@ -209,24 +224,28 @@ public class Log {
      Open wrn file and write wrn information\r
      \r
      @param strLog The log information\r
-     @throws IOException\r
+     * @throws Exception \r
      \r
      **/\r
-    private static void writeToWrnFile(String strLog) throws IOException {\r
-        try {\r
-            if (fleWrnFile == null) {\r
-                fleWrnFile = new File(strWrnFileName);\r
-                fleWrnFile.createNewFile();\r
+    private static void writeToWrnFile(String strLog) throws Exception {\r
+        if (isSaveLog) {\r
+            try {\r
+                createLogDir();\r
+                if (fleWrnFile == null) {\r
+                    fleWrnFile = new File(strWrnFileName);\r
+                    fleWrnFile.delete();\r
+                    fleWrnFile.createNewFile();\r
+                }\r
+                FileOutputStream fos = new FileOutputStream(fleWrnFile, true);\r
+                fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+                fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+                fos.flush();\r
+                fos.close();\r
+            } catch (FileNotFoundException e) {\r
+                e.printStackTrace();\r
+            } catch (IOException e) {\r
+                e.printStackTrace();\r
             }\r
-            FileOutputStream fos = new FileOutputStream(fleWrnFile, true);\r
-            fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
-            fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
-            fos.flush();\r
-            fos.close();\r
-        } catch (FileNotFoundException e) {\r
-            e.printStackTrace();\r
-        } catch (IOException e) {\r
-            e.printStackTrace();\r
         }\r
     }\r
 \r
@@ -237,21 +256,46 @@ public class Log {
      @throws IOException\r
      \r
      **/\r
-    private static void writeToErrFile(String strLog) throws IOException {\r
-        try {\r
-            if (fleErrFile == null) {\r
-                fleErrFile = new File(strErrFileName);\r
-                fleErrFile.createNewFile();\r
+    private static void writeToErrFile(String strLog) throws Exception {\r
+        if (isSaveLog) {\r
+            try {\r
+                createLogDir();\r
+                if (fleErrFile == null) {\r
+                    fleErrFile = new File(strErrFileName);\r
+                    fleErrFile.delete();\r
+                    fleErrFile.createNewFile();\r
+                }\r
+                FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
+                fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+                fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+                fos.flush();\r
+                fos.close();\r
+            } catch (FileNotFoundException e) {\r
+                e.printStackTrace();\r
+            } catch (IOException e) {\r
+                e.printStackTrace();\r
             }\r
-            FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
-            fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
-            fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
-            fos.flush();\r
-            fos.close();\r
-        } catch (FileNotFoundException e) {\r
-            e.printStackTrace();\r
-        } catch (IOException e) {\r
-            e.printStackTrace();\r
         }\r
     }\r
+\r
+    /**\r
+     Check if directory for Logs exists or not\r
+     Create the directory if it doesn't exist  \r
+     * @throws Exception \r
+     \r
+     **/\r
+    private static void createLogDir() throws Exception {\r
+        File f = new File(strLogDir);\r
+        if (!f.exists()) {\r
+            FileOperation.newFolder(strLogDir);\r
+        }\r
+    }\r
+\r
+    public static boolean isSaveLog() {\r
+        return isSaveLog;\r
+    }\r
+\r
+    public static void setSaveLog(boolean isSaveLog) {\r
+        Log.isSaveLog = isSaveLog;\r
+    }\r
 }\r
index 1473909cdb2c5069ccb3865018534547d4f580aa..efc650d95e2f8910f8837af6fd03b26ee503d1a3 100755 (executable)
@@ -10,4 +10,4 @@
 #
 
 # Run Framework Wizard
-java -Xmx256m -cp "$CLASSPATH:$WORKSPACE/Tools/bin/FrameworkWizard.jar" org.tianocore.frameworkwizard.FrameworkWizardUI
+java -Xmx256m -cp "$CLASSPATH:$WORKSPACE/Tools/bin/FrameworkWizard.jar" org.tianocore.frameworkwizard.FrameworkWizardUI $1
index 41ac5dc6a677f3f0638f7620e4aae9565d9c12f8..056a3312da9c4016cc379dd188aa5c0a7dfa385d 100644 (file)
@@ -29,7 +29,7 @@ if not exist %WORKSPACE%\Tools\bin\FrameworkWizard.jar (
 )\r
 \r
 @REM Run Framework Wizard\r
-call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI\r
+call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI %%1\r
 \r
 goto end\r
 \r
index 0f8c80f2c06afe390567be66e18c0a0807d10cda..505fe7bc28a883d485ea7beddf86a0125b65621c 100755 (executable)
@@ -10,4 +10,4 @@
 #
 
 # Run Framework Wizard
-java -cp "$CLASSPATH:$WORKSPACE/Tools/bin/FrameworkWizard.jar" org.tianocore.frameworkwizard.FrameworkWizardUI
+java -cp "$CLASSPATH:$WORKSPACE/Tools/bin/FrameworkWizard.jar" org.tianocore.frameworkwizard.FrameworkWizardUI $1
index 41ac5dc6a677f3f0638f7620e4aae9565d9c12f8..056a3312da9c4016cc379dd188aa5c0a7dfa385d 100644 (file)
@@ -29,7 +29,7 @@ if not exist %WORKSPACE%\Tools\bin\FrameworkWizard.jar (
 )\r
 \r
 @REM Run Framework Wizard\r
-call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI\r
+call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI %%1\r
 \r
 goto end\r
 \r