mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show output of 'android' tool on console
This commit is contained in:
@@ -237,4 +237,5 @@ android.sdk.configure.jdk.error=Please configure internal JDK
|
||||
no.jdk.for.android.found.error=No Java SDK of appropriate version found. In addition to the Android SDK, you need to define a JSDK 1.5 or 1.6
|
||||
no.jdk.error=You need to create at least one JSDK of versions 1.5 or 1.6
|
||||
cannot.parse.sdk.error=Cannot parse Android SDK
|
||||
android.add.sdk.tooltip=Add SDK
|
||||
android.add.sdk.tooltip=Add SDK
|
||||
android.console.tool.window.title=Android Console
|
||||
@@ -79,6 +79,6 @@ public class RunAndroidSdkManagerAction extends AnAction {
|
||||
}
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||
commandLine.setExePath(sdkPath + File.separator + AndroidUtils.toolPath(SdkConstants.androidCmdName()));
|
||||
AndroidUtils.runExternalToolInSeparateThread(project, commandLine, null);
|
||||
AndroidUtils.runExternalToolInSeparateThread(project, commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ public class AndroidFacet extends Facet<AndroidFacetConfiguration> {
|
||||
return myAvdManager;
|
||||
}
|
||||
|
||||
public void launchEmulator(@Nullable final String avdName, @NotNull final String commands, @Nullable final ProcessHandler handler) {
|
||||
public void launchEmulator(@Nullable final String avdName, @NotNull final String commands) {
|
||||
AndroidPlatform platform = getConfiguration().getAndroidPlatform();
|
||||
if (platform != null) {
|
||||
final String emulatorPath = platform.getSdk().getLocation() + File.separator + AndroidUtils.toolPath(EMULATOR);
|
||||
@@ -335,7 +335,7 @@ public class AndroidFacet extends Facet<AndroidFacetConfiguration> {
|
||||
commandLine.addParameter(s);
|
||||
}
|
||||
}
|
||||
AndroidUtils.runExternalToolInSeparateThread(getModule().getProject(), commandLine, handler);
|
||||
AndroidUtils.runExternalToolInSeparateThread(getModule().getProject(), commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.CommonBundle;
|
||||
import com.intellij.execution.RunManagerEx;
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.facet.FacetManager;
|
||||
import com.intellij.facet.ModifiableFacetModel;
|
||||
import com.intellij.ide.util.projectWizard.JavaModuleBuilder;
|
||||
@@ -234,7 +235,8 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
@Override
|
||||
public void run() {
|
||||
final Project project = module.getProject();
|
||||
final String result = AndroidUtils.runExternalTool(project, commandLine, null);
|
||||
AndroidUtils.runExternalTool(project, commandLine, true);
|
||||
|
||||
StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
|
||||
public void run() {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
@@ -247,8 +249,8 @@ public class AndroidModuleBuilder extends JavaModuleBuilder {
|
||||
public void run() {
|
||||
|
||||
if (contentRoot.findChild(SdkConstants.FN_ANDROID_MANIFEST_XML) == null) {
|
||||
Messages.showErrorDialog(project, "The project wasn't generated by 'android' tool\n" + (result != null ? result : ""),
|
||||
CommonBundle.getErrorTitle());
|
||||
AndroidUtils.printMessageToConsole(project, "The project wasn't generated by 'android' tool.",
|
||||
ConsoleViewContentType.ERROR_OUTPUT);
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
|
||||
@@ -356,14 +356,14 @@ public abstract class AndroidRunningState implements RunProfileState, AndroidDeb
|
||||
chooseAvd();
|
||||
}
|
||||
if (myAvdName != null) {
|
||||
myFacet.launchEmulator(myAvdName, myCommandLine, myProcessHandler);
|
||||
myFacet.launchEmulator(myAvdName, myCommandLine);
|
||||
}
|
||||
else if (getProcessHandler().isStartNotified()) {
|
||||
getProcessHandler().destroyProcess();
|
||||
}
|
||||
}
|
||||
else {
|
||||
myFacet.launchEmulator(myAvdName, myCommandLine, myProcessHandler);
|
||||
myFacet.launchEmulator(myAvdName, myCommandLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class AvdChooser extends DialogWrapper {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||
commandLine.setExePath(androidToolPath);
|
||||
AndroidUtils.runExternalToolInSeparateThread(project, commandLine, null);
|
||||
AndroidUtils.runExternalToolInSeparateThread(project, commandLine);
|
||||
}
|
||||
});
|
||||
updateTable();
|
||||
|
||||
@@ -221,7 +221,7 @@ public class DeviceChooser extends DialogWrapper implements AndroidDebugBridge.I
|
||||
if (chooser.getExitCode() != OK_EXIT_CODE) return;
|
||||
if (avd == null) return;
|
||||
}
|
||||
myFacet.launchEmulator(avd != null ? avd.getName() : null, "", null);
|
||||
myFacet.launchEmulator(avd != null ? avd.getName() : null, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@ import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.RunManagerEx;
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.impl.ConsoleViewImpl;
|
||||
import com.intellij.execution.process.*;
|
||||
import com.intellij.execution.ui.ConsoleView;
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.ide.util.DefaultPsiElementCellRenderer;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -53,12 +56,20 @@ import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentManagerAdapter;
|
||||
import com.intellij.ui.content.impl.ContentImpl;
|
||||
import com.intellij.util.PsiNavigateUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -125,6 +136,8 @@ public class AndroidUtils {
|
||||
|
||||
public static final int TIMEOUT = 300000;
|
||||
|
||||
private static final Key<ConsoleView> CONSOLE_VIEW_KEY = new Key<ConsoleView>("AndroidConsoleView");
|
||||
|
||||
private AndroidUtils() {
|
||||
}
|
||||
|
||||
@@ -432,25 +445,19 @@ public class AndroidUtils {
|
||||
}
|
||||
|
||||
public static void runExternalToolInSeparateThread(@NotNull final Project project,
|
||||
@NotNull final GeneralCommandLine commandLine,
|
||||
@Nullable final ProcessHandler processHandler) {
|
||||
@NotNull final GeneralCommandLine commandLine) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
public void run() {
|
||||
runExternalTool(project, commandLine, processHandler);
|
||||
runExternalTool(project, commandLine, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String runExternalTool(final Project project,
|
||||
GeneralCommandLine commandLine,
|
||||
ProcessHandler processHandler) {
|
||||
public static void runExternalTool(final Project project, GeneralCommandLine commandLine, boolean printOutputToConsole) {
|
||||
String[] commands = commandLine.getCommands();
|
||||
String command = StringUtil.join(commands, " ");
|
||||
LOG.info("Execute: " + command);
|
||||
if (processHandler != null && !processHandler.isProcessTerminated()) {
|
||||
processHandler.notifyTextAvailable(command + '\n', ProcessOutputTypes.STDOUT);
|
||||
}
|
||||
|
||||
StringBuilder messageBuilder = new StringBuilder();
|
||||
String result;
|
||||
boolean success = false;
|
||||
@@ -461,21 +468,19 @@ public class AndroidUtils {
|
||||
catch (ExecutionException e) {
|
||||
result = e.getMessage();
|
||||
}
|
||||
if (result != null && !success) {
|
||||
final String errorMessage = result;
|
||||
if (processHandler != null) {
|
||||
processHandler.notifyTextAvailable(errorMessage + '\n', ProcessOutputTypes.STDERR);
|
||||
processHandler.destroyProcess();
|
||||
}
|
||||
else {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
Messages.showErrorDialog(project, errorMessage, AndroidBundle.message("emulator.error.dialog.title"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (result != null && printOutputToConsole) {
|
||||
final ConsoleViewContentType contentType = success ?
|
||||
ConsoleViewContentType.NORMAL_OUTPUT :
|
||||
ConsoleViewContentType.ERROR_OUTPUT;
|
||||
final String finalResult = result;
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
printMessageToConsole(project, finalResult, contentType);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getSimpleNameByRelativePath(String relativePath) {
|
||||
@@ -589,4 +594,50 @@ public class AndroidUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void printMessageToConsole(@NotNull Project project, @NotNull String s, @NotNull ConsoleViewContentType contentType) {
|
||||
activateConsoleToolWindow(project);
|
||||
final ConsoleView consoleView = project.getUserData(CONSOLE_VIEW_KEY);
|
||||
|
||||
if (consoleView != null) {
|
||||
consoleView .print(s + '\n', contentType);
|
||||
}
|
||||
}
|
||||
|
||||
private static void activateConsoleToolWindow(@NotNull Project project) {
|
||||
final ToolWindowManager manager = ToolWindowManager.getInstance(project);
|
||||
final String toolWindowId = AndroidBundle.message("android.console.tool.window.title");
|
||||
|
||||
ToolWindow toolWindow = manager.getToolWindow(toolWindowId);
|
||||
if (toolWindow != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
toolWindow = manager.registerToolWindow(toolWindowId, true, ToolWindowAnchor.BOTTOM);
|
||||
final ConsoleView console = new ConsoleViewImpl(project, false);
|
||||
project.putUserData(CONSOLE_VIEW_KEY, console);
|
||||
toolWindow.getContentManager().addContent(new ContentImpl(console.getComponent(), "", false));
|
||||
|
||||
final ToolWindowManagerListener listener = new ToolWindowManagerListener() {
|
||||
@Override
|
||||
public void toolWindowRegistered(@NotNull String id) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged() {
|
||||
ToolWindow window = manager.getToolWindow(toolWindowId);
|
||||
if (window != null && !window.isVisible()) {
|
||||
manager.unregisterToolWindow(toolWindowId);
|
||||
((ToolWindowManagerEx)manager).removeToolWindowManagerListener(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
toolWindow.show(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((ToolWindowManagerEx)manager).addToolWindowManagerListener(listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user