1. Fix EDKT508: FW should't build Log.log file in current directory

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2341 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
hche10x 2007-01-31 08:20:54 +00:00
parent a8b194b97c
commit 9e011eacdb
6 changed files with 131 additions and 65 deletions

View File

@ -324,12 +324,22 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
@return FrameworkWizardUI The instance of this class @return FrameworkWizardUI The instance of this class
**/ **/
public static FrameworkWizardUI getInstance() { public static FrameworkWizardUI getInstance(String[] args) {
if (fwui == null) { if (fwui == null) {
fwui = new FrameworkWizardUI(); fwui = new FrameworkWizardUI(args);
} }
return fwui; return fwui;
} }
/**
If the class hasn't an instnace, new one.
@return FrameworkWizardUI The instance of this class
**/
public static FrameworkWizardUI getInstance() {
return fwui;
}
/** /**
This method initializes jMenuBar This method initializes jMenuBar
@ -1794,8 +1804,11 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
* Main class, start the GUI * Main class, start the GUI
* *
*/ */
public static void main(String[] args) { public static void main(String[] args) {
FrameworkWizardUI module = FrameworkWizardUI.getInstance(); //
// Start Main UI
//
FrameworkWizardUI module = FrameworkWizardUI.getInstance(args);
module.setVisible(true); module.setVisible(true);
} }
@ -1803,9 +1816,9 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
This is the default constructor This is the default constructor
**/ **/
public FrameworkWizardUI() { public FrameworkWizardUI(String[] args) {
super(); super();
init(); init(args);
} }
/** /**
@ -1813,7 +1826,7 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
**/ **/
private void init() { private void init(String[] args) {
// //
// Set current workspace and check // Set current workspace and check
// Check if exists WORKSPACE // Check if exists WORKSPACE
@ -1826,6 +1839,15 @@ public class FrameworkWizardUI extends IFrame implements KeyListener, MouseListe
// //
SplashScreen ss = new SplashScreen(); SplashScreen ss = new SplashScreen();
ss.setVisible(true); ss.setVisible(true);
//
// Go through args to check if enable log
//
for (int index = 0; index < args.length; index++) {
if (args[index].equals("--log") || args[index].equals("-l")) {
Log.setSaveLog(true);
}
}
// //
// Init Global Data // Init Global Data

View File

@ -23,12 +23,18 @@ import java.io.IOException;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.tianocore.frameworkwizard.FrameworkWizardUI; import org.tianocore.frameworkwizard.FrameworkWizardUI;
import org.tianocore.frameworkwizard.workspace.Workspace;
/** /**
The class is used to provides static interfaces to save log and error information The class is used to provides static interfaces to save log and error information
**/ **/
public class Log { public class Log {
//
//Log file directory path
//
private static String strLogDir = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + "Tools"
+ DataType.FILE_SEPARATOR + "Logs";
// //
//Log file //Log file
@ -48,17 +54,22 @@ public class Log {
// //
//Log file name //Log file name
// //
static String strLogFileName = "Log.log"; private static String strLogFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.log";
// //
//Wrn file name //Wrn file name
// //
static String strWrnFileName = "Wrn.log"; private static String strWrnFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.wrn";
// //
//Err file name //Err file name
// //
static String strErrFileName = "Err.log"; private static String strErrFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.err";
//
//Flag for create log or not
//
private static boolean isSaveLog = false;
/** /**
Main class, used for test Main class, used for test
@ -88,7 +99,7 @@ public class Log {
public static void log(String strItem, String strLog) { public static void log(String strItem, String strLog) {
try { try {
writeToLogFile(strItem + ":" + strLog); writeToLogFile(strItem + ":" + strLog);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -102,7 +113,7 @@ public class Log {
public static void log(String strLog) { public static void log(String strLog) {
try { try {
writeToLogFile(strLog); writeToLogFile(strLog);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -118,7 +129,7 @@ public class Log {
try { try {
writeToWrnFile("Warning when " + strItem + "::" + strWrn); writeToWrnFile("Warning when " + strItem + "::" + strWrn);
showWrnMessage(strWrn); showWrnMessage(strWrn);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -133,7 +144,7 @@ public class Log {
try { try {
writeToWrnFile("Warning::" + strWrn); writeToWrnFile("Warning::" + strWrn);
showWrnMessage("Warning::" + strWrn); showWrnMessage("Warning::" + strWrn);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -148,7 +159,7 @@ public class Log {
public static void err(String strItem, String strErr) { public static void err(String strItem, String strErr) {
try { try {
writeToErrFile("Error when " + strItem + "::" + strErr); writeToErrFile("Error when " + strItem + "::" + strErr);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -162,7 +173,7 @@ public class Log {
public static void err(String strErr) { public static void err(String strErr) {
try { try {
writeToErrFile("Error::" + strErr); writeToErrFile("Error::" + strErr);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -176,8 +187,8 @@ public class Log {
**/ **/
private static void showWrnMessage(String strErr) { private static void showWrnMessage(String strErr) {
String strReturn = Tools.wrapStringByWord(strErr); String strReturn = Tools.wrapStringByWord(strErr);
JOptionPane JOptionPane.showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning",
.showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
} }
/** /**
@ -187,21 +198,25 @@ public class Log {
@throws IOException @throws IOException
**/ **/
private static void writeToLogFile(String strLog) throws IOException { private static void writeToLogFile(String strLog) throws Exception {
try { if (isSaveLog) {
if (fleLogFile == null) { try {
fleLogFile = new File(strLogFileName); createLogDir();
fleLogFile.createNewFile(); if (fleLogFile == null) {
fleLogFile = new File(strLogFileName);
fleLogFile.delete();
fleLogFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(fleLogFile, true);
fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
FileOutputStream fos = new FileOutputStream(fleLogFile, true);
fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
} }
@ -209,24 +224,28 @@ public class Log {
Open wrn file and write wrn information Open wrn file and write wrn information
@param strLog The log information @param strLog The log information
@throws IOException * @throws Exception
**/ **/
private static void writeToWrnFile(String strLog) throws IOException { private static void writeToWrnFile(String strLog) throws Exception {
try { if (isSaveLog) {
if (fleWrnFile == null) { try {
fleWrnFile = new File(strWrnFileName); createLogDir();
fleWrnFile.createNewFile(); if (fleWrnFile == null) {
fleWrnFile = new File(strWrnFileName);
fleWrnFile.delete();
fleWrnFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(fleWrnFile, true);
fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
FileOutputStream fos = new FileOutputStream(fleWrnFile, true);
fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
} }
@ -237,21 +256,46 @@ public class Log {
@throws IOException @throws IOException
**/ **/
private static void writeToErrFile(String strLog) throws IOException { private static void writeToErrFile(String strLog) throws Exception {
try { if (isSaveLog) {
if (fleErrFile == null) { try {
fleErrFile = new File(strErrFileName); createLogDir();
fleErrFile.createNewFile(); if (fleErrFile == null) {
fleErrFile = new File(strErrFileName);
fleErrFile.delete();
fleErrFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(fleErrFile, true);
fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
FileOutputStream fos = new FileOutputStream(fleErrFile, true);
fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
} }
/**
Check if directory for Logs exists or not
Create the directory if it doesn't exist
* @throws Exception
**/
private static void createLogDir() throws Exception {
File f = new File(strLogDir);
if (!f.exists()) {
FileOperation.newFolder(strLogDir);
}
}
public static boolean isSaveLog() {
return isSaveLog;
}
public static void setSaveLog(boolean isSaveLog) {
Log.isSaveLog = isSaveLog;
}
} }

View File

@ -10,4 +10,4 @@
# #
# Run Framework Wizard # 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

View File

@ -29,7 +29,7 @@ if not exist %WORKSPACE%\Tools\bin\FrameworkWizard.jar (
) )
@REM Run Framework Wizard @REM Run Framework Wizard
call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI %%1
goto end goto end

View File

@ -10,4 +10,4 @@
# #
# Run Framework Wizard # 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

View File

@ -29,7 +29,7 @@ if not exist %WORKSPACE%\Tools\bin\FrameworkWizard.jar (
) )
@REM Run Framework Wizard @REM Run Framework Wizard
call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI call "java" -Xmx256m org.tianocore.frameworkwizard.FrameworkWizardUI %%1
goto end goto end