mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-10 13:17:09 +07:00
Consistent OS-independent command line params' quoting and escaping
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
<orderEntry type="module" module-name="testng" scope="TEST" />
|
||||
<orderEntry type="module" module-name="ui-designer" scope="TEST" />
|
||||
<orderEntry type="module" module-name="eclipse" scope="TEST" />
|
||||
<orderEntry type="module" module-name="execution-openapi" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.execution.configurations;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.process.DefaultJavaProcessHandler;
|
||||
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;
|
||||
|
||||
public class JavaCommandLineTest extends LightIdeaTestCase {
|
||||
public void testJdk() {
|
||||
try {
|
||||
CommandLineBuilder.createFromJavaParameters(new JavaParameters());
|
||||
fail("CantRunException (main class is not specified) expected");
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
Assert.assertEquals(ExecutionBundle.message("run.configuration.error.no.jdk.specified"), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testMainClass() {
|
||||
try {
|
||||
JavaParameters javaParameters = new JavaParameters();
|
||||
javaParameters.setJdk(getProjectJDK());
|
||||
CommandLineBuilder.createFromJavaParameters(javaParameters);
|
||||
fail("CantRunException (main class is not specified) expected");
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
assertEquals(ExecutionBundle.message("main.class.is.not.specified.error.message"), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testClasspath() throws CantRunException {
|
||||
JavaParameters javaParameters;
|
||||
String commandLineString;
|
||||
|
||||
javaParameters = new JavaParameters();
|
||||
final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
|
||||
javaParameters.setJdk(internalJdk);
|
||||
javaParameters.setMainClass("Main");
|
||||
commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
|
||||
assertTrue(containsClassPath(commandLineString));
|
||||
|
||||
javaParameters = new JavaParameters();
|
||||
javaParameters.setJdk(internalJdk);
|
||||
javaParameters.setMainClass("Main");
|
||||
javaParameters.getVMParametersList().add("-cp");
|
||||
javaParameters.getVMParametersList().add("..");
|
||||
commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
|
||||
commandLineString = removeClassPath(commandLineString, "-cp ..");
|
||||
assertTrue(!containsClassPath(commandLineString));
|
||||
|
||||
javaParameters = new JavaParameters();
|
||||
javaParameters.setJdk(internalJdk);
|
||||
javaParameters.setMainClass("Main");
|
||||
javaParameters.getVMParametersList().add("-classpath");
|
||||
javaParameters.getVMParametersList().add("..");
|
||||
commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
|
||||
commandLineString = removeClassPath(commandLineString, "-classpath ..");
|
||||
assertTrue(!containsClassPath(commandLineString));
|
||||
}
|
||||
|
||||
private static boolean containsClassPath(String commandLineString) {
|
||||
return commandLineString.contains("-cp") || commandLineString.contains("-classpath");
|
||||
}
|
||||
|
||||
private static String removeClassPath(String commandLineString, String pathString) {
|
||||
int i = commandLineString.indexOf(pathString);
|
||||
commandLineString = commandLineString.substring(0, i) + commandLineString.substring(i + pathString.length());
|
||||
return commandLineString;
|
||||
}
|
||||
|
||||
public void testCreateProcess() {
|
||||
try {
|
||||
new DefaultJavaProcessHandler(new GeneralCommandLine());
|
||||
fail("ExecutionException (executable is not specified) expected");
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
assertEquals(IdeBundle.message("run.configuration.error.executable.not.specified"), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.execution.configurations;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.roots.ModuleRootManagerTestCase;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JavaParametersTest extends ModuleRootManagerTestCase {
|
||||
public void testLibrary() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary());
|
||||
assertClasspath(myModule, JavaParameters.JDK_AND_CLASSES_AND_TESTS,
|
||||
getRtJar(), getJDomJar());
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_ONLY,
|
||||
getJDomJar());
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_AND_TESTS,
|
||||
getJDomJar());
|
||||
assertClasspath(myProject, JavaParameters.JDK_AND_CLASSES_AND_TESTS,
|
||||
getRtJar(), getJDomJar());
|
||||
}
|
||||
|
||||
public void testModuleSourcesAndOutput() throws Exception {
|
||||
addSourceRoot(myModule, false);
|
||||
addSourceRoot(myModule, true);
|
||||
final VirtualFile output = setModuleOutput(myModule, false);
|
||||
final VirtualFile testOutput = setModuleOutput(myModule, true);
|
||||
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_ONLY,
|
||||
output);
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_AND_TESTS,
|
||||
testOutput, output);
|
||||
assertClasspath(myModule, JavaParameters.JDK_AND_CLASSES_AND_TESTS,
|
||||
getRtJar(), testOutput, output);
|
||||
}
|
||||
|
||||
public void testLibraryScope() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary(), DependencyScope.RUNTIME, false);
|
||||
addLibraryDependency(myModule, createAsmLibrary(), DependencyScope.TEST, false);
|
||||
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_AND_TESTS,
|
||||
getJDomJar(), getAsmJar());
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_ONLY,
|
||||
getJDomJar());
|
||||
}
|
||||
|
||||
public void testProvidedScope() throws Exception {
|
||||
addLibraryDependency(myModule, createJDomLibrary(), DependencyScope.PROVIDED, false);
|
||||
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_AND_TESTS, getJDomJar());
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_ONLY);
|
||||
}
|
||||
|
||||
public void testModuleDependency() throws Exception {
|
||||
final Module dep = createModule("dep");
|
||||
final VirtualFile depOutput = setModuleOutput(dep, false);
|
||||
final VirtualFile depTestOutput = setModuleOutput(dep, true);
|
||||
addLibraryDependency(dep, createJDomLibrary());
|
||||
addModuleDependency(myModule, dep);
|
||||
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_ONLY,
|
||||
depOutput, getJDomJar());
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_AND_TESTS,
|
||||
depTestOutput, depOutput, getJDomJar());
|
||||
}
|
||||
|
||||
public void testModuleDependencyScope() throws Exception {
|
||||
final Module dep = createModule("dep");
|
||||
addLibraryDependency(dep, createJDomLibrary());
|
||||
addModuleDependency(myModule, dep, DependencyScope.TEST, true);
|
||||
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_ONLY);
|
||||
assertClasspath(myModule, JavaParameters.CLASSES_AND_TESTS,
|
||||
getJDomJar());
|
||||
|
||||
assertClasspath(myProject, JavaParameters.CLASSES_ONLY,
|
||||
getJDomJar());
|
||||
}
|
||||
|
||||
private static void assertClasspath(final Module module, final int type, VirtualFile... roots) throws CantRunException {
|
||||
final JavaParameters javaParameters = new JavaParameters();
|
||||
javaParameters.configureByModule(module, type);
|
||||
assertRoots(javaParameters.getClassPath(), roots);
|
||||
}
|
||||
|
||||
private void assertClasspath(final Project project, final int type, VirtualFile... roots) throws CantRunException {
|
||||
final JavaParameters javaParameters = new JavaParameters();
|
||||
javaParameters.configureByProject(project, type, getTestProjectJdk());
|
||||
assertRoots(javaParameters.getClassPath(), roots);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user