private Shell parent = null;
private Shell shell = null;
private DACustomButton okButton = null;
+ private DACustomButton exportButton = null;
private String message = null;
private boolean returnType = false;
private String titleText = WidgetLabels.DA_WARNING;
private final int defaultHeifght = 153;
private int width = 0;
private int height = 0;
-
private Image iconImage = ImageResources.DYNANMIC_ANALYZER_ICON;
private DACustomButtonClickEventListener okButtonListener = new DACustomButtonClickEventListener() {
-
@Override
public void handleClickEvent(DACustomButton button) {
returnType = true;
shell.dispose();
}
};
-
+
public DADialog(Shell parent, int style) {
this.width = this.defaultWidth;
this.height = this.defaultHeifght;
this.width = width;
this.height = height;
}
-
- public boolean open() {
+
+ public boolean setDialog(boolean isExport) {
shell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
shell.setSize(width, height);
shell.setLayout(new FormLayout());
okData.width = DesignConstants.DA_BUTTON_WIDTH;
okData.height = DesignConstants.DA_BUTTON_HEIGHT;
okButton.setLayoutData(okData);
-
+
+ // Export button
+ if(isExport){
+ exportButton = new DAButton(buttonComp, SWT.NONE);
+ exportButton.setText("ExportLogs");
+ exportButton.setButtonFont(FontResources.DIALOG_BUTTON_FONT);
+
+ FormData exportData = new FormData();
+ exportData.top = new FormAttachment(0, 11);
+ exportData.right = new FormAttachment(okButton,-220, SWT.LEFT);
+ exportData.width = DesignConstants.DA_BUTTON_WIDTH;
+ exportData.height = DesignConstants.DA_BUTTON_HEIGHT;
+ exportButton.setLayoutData(exportData);
+ }
+ return returnType;
+ }
+
+ public void open(){
shell.open();
Display display = Display.getCurrent();
}
shell.dispose();
- return returnType;
}
-
+
public void setMessage(String msg) {
message = msg;
}
public void setTitleText(String title) {
titleText = title;
}
+
+ public DACustomButton getExportButton(){
+ return exportButton;
+ }
}
--- /dev/null
+package org.tizen.dynamicanalyzer.common;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.tizen.dynamicanalyzer.common.path.PathManager;
+import org.tizen.dynamicanalyzer.communicator.DACommunicator;
+import org.tizen.dynamicanalyzer.ui.common.explorer.FileExplorerDialog;
+import org.tizen.dynamicanalyzer.util.CommonUtil;
+import org.tizen.dynamicanalyzer.util.Logger;
+import org.tizen.dynamicanalyzer.util.WorkbenchUtil;
+
+public class DALogExport {
+
+ private String LogexportPath;
+ private String LogZipPath;
+ private String ExportLogName;
+
+ public DALogExport() {
+
+ Boolean result = false;
+
+ result = exportPathDialog();
+ if (result != true) {
+ Logger.info("selected export path is wrong");
+ }
+ result = exportDALog();
+ if (result != true) {
+ Logger.info("export DAConsoleLog failed");
+ }
+ result = exportDaemonLog();
+ if (result != true) {
+ Logger.info("export DaemonLog failed");
+ }
+ result = exportDataLog();
+ if (result != true) {
+ Logger.info("export DataLog failed");
+ }
+ result = exportControlLog();
+ if (result != true) {
+ Logger.info("export ControlLog failed");
+ }
+ result = compressLogs();
+ if (result != true) {
+ Logger.info("compress Logs failed");
+ }
+ result = removeTemp();
+ if (result != true) {
+ Logger.info("remove temp failed");
+ }
+ }
+
+ /// User Select Directory to export Logs
+ public Boolean exportPathDialog(){
+ FileExplorerDialog dialog = new FileExplorerDialog(WorkbenchUtil.getWorkbenchWindow().getShell());
+ dialog.setTitle("Select export path");
+ dialog.getExplorer().setRoot(CommonUtil.getHomeDirectory());
+ Object result = dialog.open();
+ LogexportPath = result.toString();
+
+ if(LogexportPath==null){
+ return false;
+ }
+
+ int cutStart = LogexportPath.indexOf("[");
+ int cutEnd = LogexportPath.indexOf("]");
+ String tmpPath = LogexportPath.substring(cutStart+1, cutEnd);
+
+ SimpleDateFormat format = new SimpleDateFormat(
+ "yyyy_MM_dd_HH-mm-ss", Locale.KOREA); //$NON-NLS-1$
+ Date date = new Date();
+ String logPostFix = format.format(date);
+ ExportLogName = "DALogs_"+ logPostFix;
+ LogZipPath = tmpPath;
+ LogexportPath = tmpPath+"/"+ExportLogName;
+
+ return true;
+ }
+
+ // / set LogExportPath
+ public void setLogExportPath(String path) {
+ LogexportPath = path;
+ }
+
+ // / get LogExportPath
+ public String getLogExportPath(String path) {
+ return LogexportPath;
+ }
+
+ // / Export DA Log
+ public Boolean exportDALog() {
+ File src = getLastDALog(PathManager.DA_LOG_PATH);
+ File dirCheck = new File(LogexportPath);
+ File dest = new File(LogexportPath + "/" + "da_console.log");
+
+ if(!checkDirectory(dirCheck)){
+ return false;
+ }
+
+ if(!copyLogFile(src, dest)){
+ return false;
+ }
+
+ return true;
+ }
+
+ // / Export Daemon Log
+ public Boolean exportDaemonLog() {
+ DACommunicator.exportCustomPathDaemonLog(LogexportPath);
+ return true;
+ }
+
+ // / Export DATA Log
+ public Boolean exportDataLog() {
+ File src = new File(PathManager.DA_DEBUG_DATA_CHANNEL_LOG_FILE);
+ File dest = new File(LogexportPath + "/" + "da_data.log");
+
+ if(!copyLogFile(src, dest)){
+ return false;
+ }
+
+ return true;
+ }
+
+ // / Export Control Log
+ public Boolean exportControlLog() {
+ File src = new File(PathManager.DA_DEBUG_CONTROL_CHANNEL_LOG_FILE);
+ File dest = new File(LogexportPath + "/" + "da_control.log");
+
+ if(!copyLogFile(src, dest)){
+ return false;
+ }
+
+ return true;
+ }
+
+ private Boolean copyLogFile(File source, File dest){
+
+ InputStream input = null;
+ OutputStream output = null;
+
+ try {
+ input = new FileInputStream(source);
+ output = new FileOutputStream(dest);
+
+ byte[] buf = new byte[1024];
+ int bytesRead;
+
+ while ((bytesRead = input.read(buf)) > 0) {
+ output.write(buf, 0, bytesRead);
+ }
+
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ return false;
+ }
+ finally {
+ try {
+ if (input != null) {
+ input.close();
+ }
+ if (output != null) {
+ output.close();
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public File getLastDALog(String dir) {
+ File fl = new File(dir);
+ File[] files = fl.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ return file.isFile();
+ }
+ });
+ long lastMod = Long.MIN_VALUE;
+ File lastModFile = null;
+ for (File file : files) {
+ if (file.toString().contains("da_log_")) {
+ if (file.lastModified() > lastMod) {
+ lastModFile = file;
+ lastMod = file.lastModified();
+ }
+ }
+ }
+ return lastModFile;
+ }
+
+ /// CompressLogs
+ public Boolean compressLogs(){
+ ZipOutputStream zip = null;
+ FileOutputStream fileWriter = null;
+ String srcFolder = LogexportPath;
+ String destZipFile = LogZipPath + "/" + ExportLogName + ".zip";
+
+ try {
+ fileWriter = new FileOutputStream(destZipFile);
+ zip = new ZipOutputStream(fileWriter);
+ addFolderToZip("", srcFolder, zip);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return false;
+ }
+
+ if(zip!=null){
+ try {
+ zip.flush();
+ zip.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return true;
+ }
+
+ /// Make zip from file.
+ private void addFileToZip(String path, String srcFile,ZipOutputStream zip){
+ File folder = new File(srcFile);
+
+ if (folder.isDirectory()) {
+ addFolderToZip(path, srcFile, zip);
+ } else {
+ byte[] buf = new byte[1024];
+ int len;
+ FileInputStream in;
+ try {
+ in = new FileInputStream(srcFile);
+ zip.putNextEntry(new ZipEntry(path + "/" + folder.getName()));
+ while ((len = in.read(buf)) > 0) {
+ zip.write(buf, 0, len);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ /// Compress Files in folder
+ private void addFolderToZip(String path, String srcFolder,ZipOutputStream zip){
+ File folder = new File(srcFolder);
+ for (String fileName : folder.list()) {
+ addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip);
+ }
+ }
+
+ private boolean checkDirectory(File file){
+ if (!file.exists()) {
+ if(!file.mkdirs()){
+ return false;
+ }
+ } else {
+ File[] destroy = file.listFiles();
+ for (File des : destroy) {
+ if(!des.delete()){
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean removeTemp(){
+ File file = new File(LogexportPath);
+ checkDirectory(file);
+ file.delete();
+ return true;
+ }
+}
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.tizen.dynamicanalyzer.common.DALogExport;
import org.tizen.dynamicanalyzer.common.DAResult;
import org.tizen.dynamicanalyzer.constant.CommonConstants;
import org.tizen.dynamicanalyzer.nl.SummaryLabels;
import org.tizen.dynamicanalyzer.util.Logger;
import org.tizen.dynamicanalyzer.util.WorkbenchUtil;
import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
import org.tizen.dynamicanalyzer.widgets.da.base.DADialog;
import org.tizen.dynamicanalyzer.widgets.da.view.DATabComposite;
DADialog dialog = new DADialog(shell, SWT.NONE, width, height);
dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
dialog.setMessage(message);
+ dialog.setDialog(true);
+ dialog.getExportButton().addClickListener(exportListener);
dialog.open();
}
});
Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell();
DADialog dialog = new DADialog(shell, SWT.NONE);
dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
- dialog.setMessage(message);
+ dialog.setMessage(message);
+ dialog.setDialog(true);
+ dialog.getExportButton().addClickListener(exportListener);
dialog.open();
}
});
DADialog dialog = new DADialog(shell, SWT.NONE);
dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
dialog.setMessage(message);
+ dialog.setDialog(true);
+ dialog.getExportButton().addClickListener(exportListener);
dialog.open();
}
});
}
});
}
+
+ private static DACustomButtonClickEventListener exportListener = new DACustomButtonClickEventListener() {
+ @Override
+ public void handleClickEvent(DACustomButton button) {
+ DALogExport export = new DALogExport();
+ }
+ };
}