From c6cf5d23154b87fcd1bc216075f08c51a22779ae Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 2 Dec 2016 14:59:44 +0100 Subject: [PATCH] [platform] restores 'missing main class' check --- .../configurations/JavaCommandLineTest.java | 34 +++++++++++++------ .../openapi/projectRoots/JdkUtil.java | 3 ++ .../src/messages/ExecutionBundle.properties | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/execution/configurations/JavaCommandLineTest.java b/java/java-tests/testSrc/com/intellij/execution/configurations/JavaCommandLineTest.java index 922a456d484f..eb4c714c7104 100644 --- a/java/java-tests/testSrc/com/intellij/execution/configurations/JavaCommandLineTest.java +++ b/java/java-tests/testSrc/com/intellij/execution/configurations/JavaCommandLineTest.java @@ -22,32 +22,38 @@ import com.intellij.execution.process.KillableColoredProcessHandler; import com.intellij.ide.IdeBundle; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl; -import com.intellij.testFramework.LightIdeaTestCase; -import junit.framework.Assert; +import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; +import org.junit.Test; -public class JavaCommandLineTest extends LightIdeaTestCase { - public void testJdk() { +import static org.junit.Assert.*; + +public class JavaCommandLineTest extends BareTestFixtureTestCase { + @Test + public void testJdkMissing() { try { new JavaParameters().toCommandLine(); - fail("CantRunException (main class is not specified) expected"); + fail("'JDK missing' expected"); } catch (CantRunException e) { - Assert.assertEquals(ExecutionBundle.message("run.configuration.error.no.jdk.specified"), e.getMessage()); + assertEquals(ExecutionBundle.message("run.configuration.error.no.jdk.specified"), e.getMessage()); } } - public void testMainClass() { + @Test + public void testMainClassMissing() { try { JavaParameters javaParameters = new JavaParameters(); javaParameters.setJdk(getProjectJDK()); javaParameters.toCommandLine(); - fail("CantRunException (main class is not specified) expected"); + fail("'main class missing' expected"); } catch (CantRunException e) { assertEquals(ExecutionBundle.message("main.class.is.not.specified.error.message"), e.getMessage()); } } + @Test public void testJarParameter() throws CantRunException { JavaParameters javaParameters = new JavaParameters(); javaParameters.setJdk(getProjectJDK()); @@ -56,12 +62,13 @@ public class JavaCommandLineTest extends LightIdeaTestCase { assertTrue(commandLineString, commandLineString.contains("-jar my-jar-file.jar")); } + @Test public void testClasspath() throws CantRunException { JavaParameters javaParameters; String commandLineString; javaParameters = new JavaParameters(); - final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk(); + Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk(); javaParameters.setJdk(internalJdk); javaParameters.getClassPath().add("my-jar-file.jar"); javaParameters.setMainClass("Main"); @@ -99,13 +106,18 @@ public class JavaCommandLineTest extends LightIdeaTestCase { return commandLineString; } + @Test public void testCreateProcess() { try { new KillableColoredProcessHandler(new GeneralCommandLine()); - fail("ExecutionException (executable is not specified) expected"); + fail("'executable missing' expected"); } catch (ExecutionException e) { assertEquals(IdeBundle.message("run.configuration.error.executable.not.specified"), e.getMessage()); } } -} + + private static Sdk getProjectJDK() { + return IdeaTestUtil.getMockJdk17(); + } +} \ No newline at end of file diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java index 7f1b5d78ffeb..f7eda3a69969 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java @@ -198,6 +198,9 @@ public class JdkUtil { commandLine.addParameter("-jar"); commandLine.addParameter(jarPath); } + else { + throw new CantRunException(ExecutionBundle.message("main.class.is.not.specified.error.message")); + } if (!passProgramParametersViaClassPathJar) { commandLine.addParameters(javaParameters.getProgramParametersList().getList()); diff --git a/platform/platform-resources-en/src/messages/ExecutionBundle.properties b/platform/platform-resources-en/src/messages/ExecutionBundle.properties index 99c4b8b93f96..111a43edba70 100644 --- a/platform/platform-resources-en/src/messages/ExecutionBundle.properties +++ b/platform/platform-resources-en/src/messages/ExecutionBundle.properties @@ -14,7 +14,7 @@ run.configuration.error.dialog.title=Run Configuration Error no.jdk.specified..error.message=No JDK specified home.directory.not.specified.for.jdk.error.message=Home directory is not specified for JDK run.configuration.pause.output.action.name=Pause Output -main.class.is.not.specified.error.message=Main class is not specified +main.class.is.not.specified.error.message=Neither main class nor JAR path is specified close.tab.action.name=Close run.configuration.show.command.line.action.name=Show Console Prompt