From 3ba30bfc6f1f0f10d72d8fb87cedde26cb937c4c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 2 Dec 2016 13:48:03 +0100 Subject: [PATCH] Cleanup (updates deprecated API usages) --- .../configurations/CommandLineBuilder.java | 19 ++----------------- .../configurations/JavaCommandLineState.java | 10 +++++----- .../process/DefaultJavaProcessHandler.java | 5 ++--- .../configurations/JavaCommandLineTest.java | 14 +++++++------- .../intellij/debugger/DebuggerTestCase.java | 6 +++--- .../config/execution/ExecutionHandler.java | 5 ++--- .../appengine/actions/AppEngineUploader.java | 7 ++----- .../plugins/groovy/mvc/MvcFramework.java | 2 +- .../junit4/JUnit4IntegrationTest.java | 4 ++-- .../execution/MavenExternalExecutor.java | 3 +-- 10 files changed, 27 insertions(+), 48 deletions(-) diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/CommandLineBuilder.java b/java/execution/openapi/src/com/intellij/execution/configurations/CommandLineBuilder.java index 6c21d76e4727..74e9bee75deb 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/CommandLineBuilder.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/CommandLineBuilder.java @@ -22,6 +22,8 @@ package com.intellij.execution.configurations; import com.intellij.execution.CantRunException; import com.intellij.openapi.project.Project; +/** @deprecated use {@link SimpleJavaParameters#toCommandLine()} (to be removed in IDEA 2019) */ +@SuppressWarnings("unused") public class CommandLineBuilder { private CommandLineBuilder() { } @@ -29,17 +31,6 @@ public class CommandLineBuilder { return javaParameters.toCommandLine(); } - /** - * In order to avoid too long cmd problem dynamic classpath can be used - if allowed by both {@code dynamicClasspath} parameter - * and project settings. - * - * @param javaParameters parameters. - * @param project a project to get a dynamic classpath setting from. - * @param dynamicClasspath whether system properties and project settings will be able to cause using dynamic classpath. If false, - * classpath will always be passed through the command line. - * @return a command line. - * @throws CantRunException if there are problems with JDK setup. - */ public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters, final Project project, final boolean dynamicClasspath) throws CantRunException { @@ -52,12 +43,6 @@ public class CommandLineBuilder { return javaParameters.toCommandLine(); } - /** - * @param javaParameters parameters. - * @param forceDynamicClasspath whether dynamic classpath will be used for this execution, to prevent problems caused by too long command line. - * @return a command line. - * @throws CantRunException if there are problems with JDK setup. - */ public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters, final boolean forceDynamicClasspath) throws CantRunException { javaParameters.setUseDynamicClasspath(forceDynamicClasspath); diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineState.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineState.java index e26183f76f64..c4e70e364401 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineState.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaCommandLineState.java @@ -18,7 +18,6 @@ package com.intellij.execution.configurations; import com.intellij.execution.ExecutionException; import com.intellij.execution.process.OSProcessHandler; import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; public abstract class JavaCommandLineState extends CommandLineState implements JavaCommandLine { @@ -39,7 +38,7 @@ public abstract class JavaCommandLineState extends CommandLineState implements J public void clear() { myParams = null; } - + @Override @NotNull protected OSProcessHandler startProcess() throws ExecutionException { @@ -53,11 +52,12 @@ public abstract class JavaCommandLineState extends CommandLineState implements J protected abstract JavaParameters createJavaParameters() throws ExecutionException; protected GeneralCommandLine createCommandLine() throws ExecutionException { - final Project project = getEnvironment().getProject(); - return CommandLineBuilder.createFromJavaParameters(getJavaParameters(), project, true); + SimpleJavaParameters javaParameters = getJavaParameters(); + javaParameters.setUseDynamicClasspath(getEnvironment().getProject()); + return javaParameters.toCommandLine(); } public boolean shouldAddJavaProgramRunnerActions() { return true; } -} +} \ No newline at end of file diff --git a/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java b/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java index a0620bda7b19..e0e42004c2e5 100644 --- a/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java +++ b/java/execution/openapi/src/com/intellij/execution/process/DefaultJavaProcessHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -16,7 +16,6 @@ package com.intellij.execution.process; import com.intellij.execution.ExecutionException; -import com.intellij.execution.configurations.CommandLineBuilder; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.configurations.JavaParameters; import org.jetbrains.annotations.NotNull; @@ -26,7 +25,7 @@ import java.nio.charset.Charset; /** @deprecated use {@link OSProcessHandler} (to be removed in IDEA 17) */ public class DefaultJavaProcessHandler extends OSProcessHandler { public DefaultJavaProcessHandler(@NotNull JavaParameters javaParameters) throws ExecutionException { - super(CommandLineBuilder.createFromJavaParameters(javaParameters)); + super(javaParameters.toCommandLine()); } public DefaultJavaProcessHandler(@NotNull GeneralCommandLine commandLine) throws ExecutionException { 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 730ea6005104..922a456d484f 100644 --- a/java/java-tests/testSrc/com/intellij/execution/configurations/JavaCommandLineTest.java +++ b/java/java-tests/testSrc/com/intellij/execution/configurations/JavaCommandLineTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -28,7 +28,7 @@ import junit.framework.Assert; public class JavaCommandLineTest extends LightIdeaTestCase { public void testJdk() { try { - CommandLineBuilder.createFromJavaParameters(new JavaParameters()); + new JavaParameters().toCommandLine(); fail("CantRunException (main class is not specified) expected"); } catch (CantRunException e) { @@ -40,7 +40,7 @@ public class JavaCommandLineTest extends LightIdeaTestCase { try { JavaParameters javaParameters = new JavaParameters(); javaParameters.setJdk(getProjectJDK()); - CommandLineBuilder.createFromJavaParameters(javaParameters); + javaParameters.toCommandLine(); fail("CantRunException (main class is not specified) expected"); } catch (CantRunException e) { @@ -52,7 +52,7 @@ public class JavaCommandLineTest extends LightIdeaTestCase { JavaParameters javaParameters = new JavaParameters(); javaParameters.setJdk(getProjectJDK()); javaParameters.setJarPath("my-jar-file.jar"); - String commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString(); + String commandLineString = javaParameters.toCommandLine().getCommandLineString(); assertTrue(commandLineString, commandLineString.contains("-jar my-jar-file.jar")); } @@ -65,7 +65,7 @@ public class JavaCommandLineTest extends LightIdeaTestCase { javaParameters.setJdk(internalJdk); javaParameters.getClassPath().add("my-jar-file.jar"); javaParameters.setMainClass("Main"); - commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString(); + commandLineString = javaParameters.toCommandLine().getCommandLineString(); assertTrue(containsClassPath(commandLineString)); javaParameters = new JavaParameters(); @@ -74,7 +74,7 @@ public class JavaCommandLineTest extends LightIdeaTestCase { javaParameters.setMainClass("Main"); javaParameters.getVMParametersList().add("-cp"); javaParameters.getVMParametersList().add(".."); - commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString(); + commandLineString = javaParameters.toCommandLine().getCommandLineString(); commandLineString = removeClassPath(commandLineString, "-cp .."); assertTrue(!containsClassPath(commandLineString)); @@ -84,7 +84,7 @@ public class JavaCommandLineTest extends LightIdeaTestCase { javaParameters.setMainClass("Main"); javaParameters.getVMParametersList().add("-classpath"); javaParameters.getVMParametersList().add(".."); - commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString(); + commandLineString = javaParameters.toCommandLine().getCommandLineString(); commandLineString = removeClassPath(commandLineString, "-classpath .."); assertTrue(!containsClassPath(commandLineString)); } diff --git a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java index 95dc4ecd97b8..3e79a2b0a849 100644 --- a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java +++ b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java @@ -151,7 +151,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas @Override protected GeneralCommandLine createCommandLine() throws ExecutionException { - return CommandLineBuilder.createFromJavaParameters(getJavaParameters()); + return getJavaParameters().toCommandLine(); } }; @@ -212,7 +212,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas @Override protected GeneralCommandLine createCommandLine() throws ExecutionException { - return CommandLineBuilder.createFromJavaParameters(getJavaParameters()); + return getJavaParameters().toCommandLine(); } }; @@ -270,7 +270,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas javaParameters.getVMParametersList().add(token); } - GeneralCommandLine commandLine = CommandLineBuilder.createFromJavaParameters(javaParameters); + GeneralCommandLine commandLine = javaParameters.toCommandLine(); DebuggerSession debuggerSession; diff --git a/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java b/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java index d755ed52140b..46d3bac2967b 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -18,7 +18,6 @@ package com.intellij.lang.ant.config.execution; import com.intellij.concurrency.JobScheduler; import com.intellij.execution.CantRunException; import com.intellij.execution.ExecutionException; -import com.intellij.execution.configurations.CommandLineBuilder; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.process.*; import com.intellij.execution.testframework.Printable; @@ -122,7 +121,7 @@ public final class ExecutionHandler { builder.getCommandLine().setCharset(EncodingProjectManager.getInstance(buildFile.getProject()).getDefaultCharset()); messageView = prepareMessageView(buildMessageViewToReuse, buildFile, targets, additionalProperties); - commandLine = CommandLineBuilder.createFromJavaParameters(builder.getCommandLine()); + commandLine = builder.getCommandLine().toCommandLine(); messageView.setBuildCommandLine(commandLine.getCommandLineString()); } catch (RunCanceledException e) { diff --git a/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java b/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java index e2226bb97f6f..1db06ee18197 100644 --- a/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java +++ b/plugins/google-app-engine/source/com/intellij/appengine/actions/AppEngineUploader.java @@ -24,10 +24,7 @@ import com.intellij.appengine.facet.AppEngineFacet; import com.intellij.appengine.sdk.AppEngineSdk; import com.intellij.appengine.util.AppEngineUtil; import com.intellij.execution.ExecutionException; -import com.intellij.execution.configurations.CommandLineBuilder; -import com.intellij.execution.configurations.GeneralCommandLine; -import com.intellij.execution.configurations.JavaParameters; -import com.intellij.execution.configurations.ParametersList; +import com.intellij.execution.configurations.*; import com.intellij.execution.process.*; import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; @@ -192,7 +189,7 @@ public class AppEngineUploader { programParameters.add("update"); programParameters.add(FileUtil.toSystemDependentName(myArtifact.getOutputPath())); - final GeneralCommandLine commandLine = CommandLineBuilder.createFromJavaParameters(parameters); + final GeneralCommandLine commandLine = parameters.toCommandLine(); processHandler = new OSProcessHandler(commandLine); } catch (ExecutionException e) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java index 0990ad551ad9..74b49265cc91 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java @@ -428,7 +428,7 @@ public abstract class MvcFramework { } public static GeneralCommandLine createCommandLine(@NotNull JavaParameters params) throws CantRunException { - return CommandLineBuilder.createFromJavaParameters(params); + return params.toCommandLine(); } private void extractPlugins(Project project, @Nullable VirtualFile pluginRoot, boolean refreshPluginRoot, Map res) { diff --git a/plugins/junit5_rt_tests/test/com/intellij/junit4/JUnit4IntegrationTest.java b/plugins/junit5_rt_tests/test/com/intellij/junit4/JUnit4IntegrationTest.java index 016f17464af9..0b8093ff4b28 100644 --- a/plugins/junit5_rt_tests/test/com/intellij/junit4/JUnit4IntegrationTest.java +++ b/plugins/junit5_rt_tests/test/com/intellij/junit4/JUnit4IntegrationTest.java @@ -17,7 +17,6 @@ package com.intellij.junit4; import com.intellij.execution.BaseConfigurationTestCase; import com.intellij.execution.Executor; import com.intellij.execution.ProgramRunnerUtil; -import com.intellij.execution.configurations.CommandLineBuilder; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.configurations.JavaParameters; import com.intellij.execution.executors.DefaultRunExecutor; @@ -145,7 +144,8 @@ public class JUnit4IntegrationTest extends BaseConfigurationTestCase { ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject()); TestObject state = configuration.getState(executor, environment); JavaParameters parameters = state.getJavaParameters(); - GeneralCommandLine commandLine = CommandLineBuilder.createFromJavaParameters(parameters, getProject(), true); + parameters.setUseDynamicClasspath(getProject()); + GeneralCommandLine commandLine = parameters.toCommandLine(); StringBuffer buf = new StringBuffer(); StringBuffer err = new StringBuffer(); OSProcessHandler process = new OSProcessHandler(commandLine); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java index 3a9163902cad..f74459529072 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java @@ -19,7 +19,6 @@ package org.jetbrains.idea.maven.execution; import com.intellij.execution.ExecutionException; -import com.intellij.execution.configurations.CommandLineBuilder; import com.intellij.execution.configurations.JavaParameters; import com.intellij.execution.process.OSProcessHandler; import com.intellij.openapi.application.ApplicationManager; @@ -67,7 +66,7 @@ public class MavenExternalExecutor extends MavenExecutor { } myProcessHandler = - new OSProcessHandler(CommandLineBuilder.createFromJavaParameters(myJavaParameters)) { + new OSProcessHandler(myJavaParameters.toCommandLine()) { @Override public void notifyTextAvailable(String text, Key outputType) { // todo move this logic to ConsoleAdapter class