package org.tizen.dynamicanalysis.ide.eplugin.launch;
+import static org.tizen.common.launch.LaunchesListener.LAUNCH_ATTR_KEY_IS_LAUNCHING;
+import static org.tizen.common.launch.LaunchesListener.LAUNCH_ATTR_VALUE_LAUNCHING_ALREADY;
import static org.tizen.sdblib.util.DeviceUtil.isOnline;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
-import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
-import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.ui.newui.CDTPropertyManager;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.TwoPaneElementSelector;
import org.tizen.common.IApplicationConfiguration;
import org.tizen.common.TizenPlatformConstants;
import org.tizen.common.core.application.InstallPathConfig;
-import org.tizen.common.rds.RdsDeployer;
+import org.tizen.common.launch.LaunchMessages;
import org.tizen.common.rds.ui.preference.RdsPreferencePage;
import org.tizen.common.util.HostUtil;
import org.tizen.common.util.OSChecker;
import org.tizen.common.util.SWTUtil;
+import org.tizen.common.util.log.LoggerConstants;
import org.tizen.common.util.log.UserInteraction;
import org.tizen.common.util.log.UserLogger;
import org.tizen.dynamicanalysis.ide.eplugin.Activator;
import org.tizen.dynamicanalysis.ide.eplugin.DALog;
import org.tizen.dynamicanalysis.ide.eplugin.communication.DAServerManager;
import org.tizen.dynamicanalysis.ide.eplugin.nl.Labels;
-import org.tizen.nativecommon.IXMLStore;
import org.tizen.nativecommon.ProjectUtil;
-import org.tizen.nativecommon.build.CommonBuildConstants;
-import org.tizen.nativecommon.build.CommonBuildMessages;
import org.tizen.nativecommon.build.CommonConfigurationManager;
import org.tizen.nativecommon.build.CommonProjectDependentPackager;
-import org.tizen.nativecommon.build.PlatformChangingManager;
-import org.tizen.nativecommon.build.ProjectTypeManager;
import org.tizen.nativecommon.build.SmartBuildInterface;
-import org.tizen.nativecommon.build.exception.SBIException;
-import org.tizen.nativecommon.launch.AbstractTizenCLaunchDelegate;
-import org.tizen.nativecommon.launch.IProjectLaunchCommand;
import org.tizen.nativecommon.launch.LaunchUtils;
-import org.tizen.nativecommon.launch.NativeRdsDeployer;
import org.tizen.nativecommon.launch.TizenLaunchCommand;
import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants;
-import org.tizen.nativecommon.launch.TizenLaunchConsole;
-import org.tizen.nativecommon.launch.TizenLaunchInfo;
+import org.tizen.nativecommon.launch.TizenLaunchDelegate;
import org.tizen.nativecommon.launch.TizenLaunchMessages;
import org.tizen.nativecommon.launch.ui.TizenLaunchDeviceSelectionDialog;
import org.tizen.nativeplatform.build.PlatformConfigurationManager;
import org.tizen.sdblib.Arch;
import org.tizen.sdblib.IDevice;
import org.tizen.sdblib.SmartDevelopmentBridge;
-import org.tizen.sdblib.service.SyncResult;
-public class TizenNativeApplicationDADelegate extends
- AbstractTizenCLaunchDelegate {
+public class TizenNativeApplicationDADelegate extends TizenLaunchDelegate {
private final static String TOOLS = "tools";// $NON_NLS-1$
private final static String DYNAMIC_ANALYZER = "dynamic-analyzer";// $NON_NLS-1$
- private final static String PKG_TYPE = CommonProjectDependentPackager.DEFAULT;
private final static String PLATFORM_PKG_TYPE = CommonProjectDependentPackager.RPM;
- private boolean bSuccessBuild = true;
IProject project;
/*
* for platform project
protected PkgCommandTarget target = null;
protected TizenLaunchCommand tizenCommand = null;
protected IPackageUtil pkgUtil = PkgUtilFactory.getPkgUtil(PlatformProjectUtil.getPkgType());
-
+
private static class ExtFilter implements FilenameFilter {
private String ext;
return name.endsWith(ext);
}
}
-
- @Override
+
public void launch(ILaunchConfiguration config, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
- DALog.printLog("Launch delegate");
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceRoot root = workspace.getRoot();
- project = root.getProject(config.getAttribute(
- ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "")); //$NON-NLS-1$
-
- String device = LaunchUtils.getCurrentDeployDevice().toString();
- ProjectType projectType = ProjectType.NONE;
- String binaryOfTarget = "";
- String executablePath = "";
- List<String> localPackagePathList = null;
-
+ UserLogger.start(UserInteraction.CATE_NATIVE_LAUNCH);
+ if (monitor == null)
+ monitor = new NullProgressMonitor();
+ final IProject project = ProjectUtil.getProject(config);
+
/*
* This "if()" sentence is start point about Platform Project process.
* All source code in this "if()" dependent on another plugin project source code(nativeplatform-eplugin).
if (monitor == null) {
monitor = new NullProgressMonitor();
}
+ String device = LaunchUtils.getCurrentDeployDevice().toString();
+ ProjectType projectType = ProjectType.NONE;
+ String binaryOfTarget = "";
+ String executablePath = "";
+ List<String> localPackagePathList = null;
try {
int totalWorks = 4;
monitor.beginTask("", totalWorks);
isLaunchFailed = true;
newCoreException(PlatformLaunchMessages.CANNOT_LAUNCH, null);
}
-
/*
* Make protocol message with DA(Dynamic Analyzer) Tool.
*/
UserLogger.end(UserInteraction.CATE_PLATFORM_LAUNCH);
}
- if (bSuccessBuild && !isLaunchFailed && isDAReady()) {
+ if (!isLaunchFailed && isDAReady()) {
runDynamicAnalyzer(device, projectType, binaryOfTarget, executablePath, localPackagePathList);
}
} else { // Case : Native application
- projectType = ProjectType.OSP;
- verifyCProjectConfigurationSettings(config);
try {
- verityUnitTestProject(project);
- verifyIMEProject(project);
- LaunchUtils.verifyExecutableProject(project);
- IDevice currentDevice = LaunchUtils.getCurrentDeployDevice();
- if (currentDevice == null) {
- throw new CoreException(new Status(Status.ERROR,
- Activator.PLUGIN_ID, Status.INFO,
- TizenLaunchMessages.CANNOT_CONNECT_TO_DEVICE, null));
+ monitor.beginTask(TizenLaunchMessages.LAUNCH_APPLICATION, 20);
+ monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION);
+
+ if (LAUNCH_ATTR_VALUE_LAUNCHING_ALREADY.equals(launch
+ .getAttribute(LAUNCH_ATTR_KEY_IS_LAUNCHING))) {
+ throw new CoreException(new Status(IStatus.ERROR,
+ Activator.PLUGIN_ID, NLS.bind(
+ LaunchMessages.LAUNCHED_ALREADY,
+ project.getName())));
}
- if (isDAReady()) {
- if (packaging_upload_install(project, currentDevice)) {
+ LaunchUtils.verifyExecutableProject(project);
+ verifyCProjectConfigurationSettings(config);
+
+ // FIXME : verifyDeviceReachability method is needed to change
+ // method signature such as IDevice getDevice() so on.
+ verifyDeviceReachability(config, new SubProgressMonitor(monitor, 8));
+ verifyBuildConfiguration(config, mode, new SubProgressMonitor(
+ monitor, 1));
+
+ // Console should be set after verifying device reachability.
+ setConsole(config);
+ if (LaunchUtils.isVerboseMode(config)) {
+ tizenCommand = new TizenLaunchCommand(currentDevice,
+ launchConsole);
+ } else {
+ tizenCommand = new TizenLaunchCommand(currentDevice, null);
+ }
+ launchConsole.show();
+ org.tizen.common.util.log.FileAppender fileAppender = (org.tizen.common.util.log.FileAppender) org.apache.log4j.Logger
+ .getRootLogger().getAppender(
+ LoggerConstants.NAME_FILE_APPENDER);
+ String logPath = (fileAppender != null) ? fileAppender.getLogPath()
+ : "";
+ launchConsole.println(NLS
+ .bind(LaunchMessages.LAUNCH_START, logPath));
+
+ Long startLaunchTime = (long) 0;
+ Long endLaunchTime = (long) 0;
+ try {
+ monitor.beginTask(TizenLaunchMessages.LAUNCH_APPLICATION, 10);
+ monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION);
+ startLaunchTime = System.currentTimeMillis();
+ deployApplication(config, new SubProgressMonitor(monitor, 9));
+ verifyLaunchableProject(config, ILaunchManager.RUN_MODE);
+
+ String device = LaunchUtils.getCurrentDeployDevice().toString();
+ ProjectType projectType = ProjectType.OSP;
+ String binaryOfTarget = "";
+ String executablePath = "";
+ List<String> localPackagePathList = null;
+ if (isDAReady()) {
IApplicationConfiguration adapter = (IApplicationConfiguration) project
.getAdapter(IApplicationConfiguration.class);
binaryOfTarget = adapter.getAppId();
- runDynamicAnalyzer(device, projectType, binaryOfTarget, executablePath, localPackagePathList);
+ runDynamicAnalyzer(device, projectType, binaryOfTarget,
+ executablePath, localPackagePathList);
}
+ } finally {
+ endLaunchTime = System.currentTimeMillis();
+ launchConsole.println(LaunchMessages.getElapsedTimeMessage(
+ startLaunchTime, endLaunchTime));
+ monitor.done();
}
- } catch (CoreException e) {
- DALog.dlgErrorMessage(Labels.MESSAGE_ERROR, e.getMessage());
+ } catch (OperationCanceledException e) {
+ return;
} finally {
- rollBackBuildConfigSetting(project);
- if (!launch.isTerminated()) {
- launch.terminate();
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ processPostDebug(config);
+ } else {
+ if (!launch.isTerminated())
+ launch.terminate();
+
}
ILaunchManager launchManager = DebugPlugin.getDefault()
.getLaunchManager();
launchManager.removeLaunch(launch);
- }
+ firePostLaunched(project, RdsPreferencePage.isRdsMode(project));
+ monitor.done();
+ UserLogger.end(UserInteraction.CATE_NATIVE_LAUNCH);
+ }
}
}
return true;
}
- private boolean packaging_upload_install(final IProject project,
- final IDevice currentDevice) {
- bSuccessBuild = true;
-
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- IWorkbenchWindow window = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(window
- .getShell());
-
- try {
- dialog.run(true, true, new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) {
- monitor.beginTask(Labels.MESSAGE_PREPARING_PROFILE,
- 1);
-
- IProjectLaunchCommand manifest = ProjectUtil
- .getProjectManifest(project);
- CommonProjectDependentPackager packager = ProjectTypeManager
- .getProjectPackagerInstance(project);
-
- RdsDeployer rdsDeployer = null;
- try {
- if (RdsPreferencePage.isRdsMode(project)) {
- TizenLaunchCommand tizenCommand = new TizenLaunchCommand(
- currentDevice);
- rdsDeployer = new NativeRdsDeployer(
- project,
- currentDevice,
- tizenCommand,
- TizenLaunchConsole
- .getTizenConsole(),
- CommonProjectDependentPackager.DEFAULT
- .toLowerCase(), monitor);
- rdsDeployer.setInterestList(TizenLaunchInfo
- .makeInterestList(project));
- rdsDeployer.setIgnoreList(TizenLaunchInfo
- .makeIgnoreList(project));
- if (!rdsDeployer.deploy()) {
- if (packager == null) {
- bSuccessBuild = false;
- return;
- }
- buildPackage(monitor, project,
- manifest, packager);
- normalDeploy(monitor, project,
- currentDevice, manifest,
- packager);
- }
- rdsDeployer.pushResInfoFile();
- } else {
- if (packager == null) {
- bSuccessBuild = false;
- return;
- }
- buildPackage(monitor, project, manifest,
- packager);
- normalDeploy(monitor, project,
- currentDevice, manifest, packager);
- }
- LaunchUtils.touchExecutableFile(project);
- } catch (CoreException e) {
- DALog.dlgErrorMessage(Labels.MESSAGE_ERROR,
- e.getMessage());
- bSuccessBuild = false;
- monitor.done();
- } finally {
- if (rdsDeployer != null) {
- try {
- rdsDeployer.close();
- } catch (IOException e) {
- DALog.dlgErrorMessage(
- "Failed to close RDSDeployer",
- e.getMessage());
- }
- }
- }
-
- if (monitor.isCanceled()) {
- bSuccessBuild = false;
- monitor.done();
- }
- }
- });
- } catch (InvocationTargetException e) {
- DALog.dlgErrorMessage(Labels.MESSAGE_ERROR,
- Labels.MESSAGE_FAIL_TO_BUILD_PROJECT);
- bSuccessBuild = false;
- } catch (InterruptedException e) {
- DALog.dlgErrorMessage(Labels.MESSAGE_ERROR,
- Labels.MESSAGE_FAIL_TO_BUILD_PROJECT);
- bSuccessBuild = false;
- }
- }
- });
-
- return bSuccessBuild;
- }
-
- private void buildPackage(IProgressMonitor monitor, IProject project,
- IProjectLaunchCommand manifest,
- CommonProjectDependentPackager packager) throws CoreException {
- try {
- monitor.beginTask(Labels.MESSAGE_PREPARING_PROFILE, 3);
- monitor.subTask(Labels.MESSAGE_BUILDING_PACKAGE);
-
- manifest.doMultiAppPreProcess(packager, monitor);
-
- packager.buildPackage(PKG_TYPE,
- TizenPlatformConstants.SIGNING_DEFAULT, true);
- } catch (SBIException e) {
- newCoreException(Labels.MESSAGE_FAIL_TO_BUILD_PROJECT, null);
- }
- }
-
- private void normalDeploy(IProgressMonitor monitor, IProject project,
- IDevice currentDevice, IProjectLaunchCommand manifest,
- CommonProjectDependentPackager packager) throws CoreException {
- if (!packager.checkPackageFile(PKG_TYPE)) {
- DALog.dlgErrorMessage(CommonBuildMessages.BUILD_RESULT,
- CommonBuildMessages.FAIL_TO_BUILD_PACKAGE);
- bSuccessBuild = false;
- monitor.done();
- return;
- }
-
- File packageFile = null;
- String packageDirectory = File.separatorChar
- + ManagedBuildManager.getBuildInfo(project)
- .getConfigurationName() + File.separatorChar;
- IPath packagePath = new Path(project.getLocation().toString()
- + packageDirectory);
- packageFile = findPackageFile(packagePath.toFile(),
- "." + PKG_TYPE.toLowerCase(), project);//$NON-NLS-1$
-
- if (packageFile == null) {
- newCoreException(CommonBuildMessages.FAIL_TO_BUILD_PACKAGE, null);
- }
-
- try {
- uploadApp(monitor, project, currentDevice, packageFile);
- installApp(monitor, manifest, currentDevice, packageFile);
- } catch (Exception e) {
- newCoreException(e.getMessage(), null);
- } finally {
- monitor.done();
- }
- }
-
- private void uploadApp(IProgressMonitor monitor, IProject project,
- IDevice currentDevice, File packageFile) throws CoreException {
- try {
- monitor.worked(2);
- monitor.subTask(TizenLaunchMessages.TRANSFER_PACKAGE);
-
- String destDirectoryPath = TizenPlatformConstants
- .getAppTmpDirectory(currentDevice);
-
- String srcFilePath = packageFile.getAbsoluteFile()
- .getCanonicalPath();
-
- SyncResult syncSuccess = currentDevice.getSyncService().push(
- srcFilePath, currentDevice.getFileEntry(destDirectoryPath)); // Fixxed
-
- if (!syncSuccess.isOk()) {
- newCoreException(TizenLaunchMessages.CANNOT_TRANSFER_FILE, null);
- }
- } catch (IOException e) {
- newCoreException(TizenLaunchMessages.CANNOT_TRANSFER_FILE, null);
- }
- }
-
- @SuppressWarnings("deprecation")
- private void installApp(IProgressMonitor monitor,
- IProjectLaunchCommand manifest, IDevice currentDevice,
- File packageFile) throws CoreException, Exception {
- monitor.worked(1);
- monitor.subTask(TizenLaunchMessages.INSTALL_PACKAGE);
-
- String packageName = manifest.getPackageName();
- String listCmd = manifest.getListCommand();
- String listCmdRet = manifest.getListCommandResult();
- TizenLaunchCommand launcher = new TizenLaunchCommand(currentDevice);
- launcher.run(listCmd);
-
- String endLine = launcher.getEndLine();
- if (endLine != null && endLine.contains(listCmdRet)) {
- String removeCmd = manifest.getRemoveCommand(packageName);
-
- launcher.run(removeCmd);
- }
-
- String installCmd = manifest.getInstallCommand(packageFile,
- PKG_TYPE.toLowerCase(), currentDevice);
- launcher.run(installCmd);
- }
-
- private File findPackageFile(final File searchPath, final String ext,
- IProject project) {
- File[] packageFiles = searchPath.listFiles(new ExtFilter(ext));
-
- if (packageFiles == null || packageFiles.length == 0) {
- return null;
- }
-
- IProjectLaunchCommand manifest = ProjectUtil
- .getProjectManifest(project);
- String packageName = manifest.getPackageName();
- if (packageName == null) {
- return null;
- }
-
- for (File file : packageFiles) {
- String fileName = file.getName();
- if (fileName.contains(packageName)) {
- return file;
- }
- }
-
- return null;
- }
-
- private void newCoreException(final String message, Throwable exception)
- throws CoreException {
- Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message,
- exception);
- throw new CoreException(status);
- }
-
private boolean executeWindowsCommand(final String command) {
if (command == null) {
return false;
return bSuccuss;
}
- private void verityUnitTestProject(IProject project) throws CoreException {
- String[] natures = project.getDescription().getNatureIds();
- for (String nature : natures) {
- if (nature.equals(CommonBuildConstants.UNIT_TEST_NATURE_ID)) {
- newCoreException(Labels.MESSAGE_NOT_SUPPORT_UNIT_TEST_PROJECT,
- null);
- }
- }
- }
-
- private void verifyIMEProject(IProject project) throws CoreException {
- @SuppressWarnings("deprecation")
- IXMLStore store = ProjectUtil.getXmlStore(project);
- if (store.isImeCategory()) {
- newCoreException(Labels.MESSAGE_NOT_SUPPORT_IME_PROJECT, null);
- }
- }
-
private void runDynamicAnalyzer(String device, ProjectType projectType, String binaryOfTarget,
String executablePath, List<String> localPackagePathList) {
if (DAServerManager.getInstance().getClientSocket() == null) {
return rpms;
}
- private void rollBackBuildConfigSetting(IProject project) {
- String prevBuildConfigName = TizenNativeApplicationDAShortcut
- .getPrevBuildConfigName();
- if (prevBuildConfigName != null) {
- ManagedBuildManager.getBuildInfo(project).setDefaultConfiguration(
- prevBuildConfigName);
- }
- }
-
@Override
protected String getPluginID() {
return Activator.PLUGIN_ID;
return new Path(rootstrapPath);
}
- protected IBinaryObject getBinaryObject(ILaunchConfiguration config)
- throws CoreException {
- String appPath = config.getAttribute(
- ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
- IPath hostPath = getHostPath(appPath, config);
- ICProject cproject = CDebugUtils.verifyCProject(config);
- cproject.getBinaryContainer().getPath();
- IBinaryObject binaryObject = verifyBinary(cproject, hostPath);
- return binaryObject;
- }
-
protected String getEnvironments(ILaunchConfiguration config)
throws Exception {
String envs = "";