JaroslavTulach commented on a change in pull request #3180: URL: https://github.com/apache/netbeans/pull/3180#discussion_r718122912
########## File path: cpplite/cpplite.debugger/test/unit/src/org/netbeans/modules/cpplite/debugger/ProcessParametersTest.java ########## @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.modules.cpplite.debugger; + +import java.io.File; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import junit.framework.Test; +import org.netbeans.api.extexecution.base.ExplicitProcessParameters; +import org.netbeans.junit.NbModuleSuite; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; + +/** + * Tests application parameters set through {@link ExplicitProcessParameters}. + * + * @author Martin Entlicher + */ +public class ProcessParametersTest extends AbstractDebugTest { + + private static final String CPP_APP = + "#include <unistd.h>\n" + + "#include <stdio.h>\n" + + "#include <limits.h>\n" + + "\n" + + "int main(int argc, char **argv, char **envp) {\n" + + " char buffer[PATH_MAX];\n" + + " if (getcwd(buffer, sizeof(buffer)) != NULL) {\n" + + " printf(\"CWD:%s\\n\", buffer);\n" + + " } else {\n" + + " perror(\"getcwd() error\");\n" + + " return 1;\n" + + " }\n" + + " while (--argc) {\n" + + " printf(\"ARG:%s\\n\", *(++argv));\n" + Review comment: Printing arguments from last to first one! ########## File path: cpplite/cpplite.debugger/test/unit/src/org/netbeans/modules/cpplite/debugger/ProcessParametersTest.java ########## @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.modules.cpplite.debugger; + +import java.io.File; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import junit.framework.Test; +import org.netbeans.api.extexecution.base.ExplicitProcessParameters; +import org.netbeans.junit.NbModuleSuite; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; + +/** + * Tests application parameters set through {@link ExplicitProcessParameters}. + * + * @author Martin Entlicher + */ +public class ProcessParametersTest extends AbstractDebugTest { + + private static final String CPP_APP = + "#include <unistd.h>\n" + + "#include <stdio.h>\n" + + "#include <limits.h>\n" + + "\n" + + "int main(int argc, char **argv, char **envp) {\n" + + " char buffer[PATH_MAX];\n" + + " if (getcwd(buffer, sizeof(buffer)) != NULL) {\n" + + " printf(\"CWD:%s\\n\", buffer);\n" + + " } else {\n" + + " perror(\"getcwd() error\");\n" + + " return 1;\n" + + " }\n" + + " while (--argc) {\n" + + " printf(\"ARG:%s\\n\", *(++argv));\n" + + " }\n" + + " for (char **e = envp; *e; e++) {\n" + + " printf(\"ENV:%s\\n\", *e);\n" + + " }\n" + + " return 0;\n" + + "}"; + + public ProcessParametersTest(String s) { + super(s); + } + + @Override + protected void setUp() throws Exception { + clearWorkDir(); + } + + public void testWorkingDir() throws Exception { + File wd = getWorkDir(); + createSourceFile("main.cpp", wd, CPP_APP); + compileCPP("main", wd); + File appWD = Files.createTempDirectory("TestCWD").toFile(); + try { + ExplicitProcessParameters params = ExplicitProcessParameters.builder(). + workingDirectory(appWD). + build(); + startDebugging("main", wd, params); + assertEquals(0, waitAppProcessExit()); + String output = stdOut.toString(); + assertEquals("CWD:" + appWD.getAbsolutePath(), output.substring(0, output.indexOf('\n'))); + } finally { + appWD.delete(); + } + } + + public void testArgumentsOwn() throws Exception { + File wd = getWorkDir(); + createSourceFile("main.cpp", wd, CPP_APP); + compileCPP("main", wd); + ExplicitProcessParameters params = ExplicitProcessParameters.empty(); + startDebugging(Arrays.asList(new File(wd, "main").getAbsolutePath(), "Param1", "Param 2"), params); + assertEquals(0, waitAppProcessExit()); + assertArguments("Param1", "Param 2"); + } + + public void testArgumentsExplicit() throws Exception { + File wd = getWorkDir(); + createSourceFile("main.cpp", wd, CPP_APP); + compileCPP("main", wd); + ExplicitProcessParameters params = ExplicitProcessParameters.builder(). + arg("ExpParam1"). + arg("ExpParam 2"). + build(); + startDebugging(Arrays.asList(new File(wd, "main").getAbsolutePath()), params); + assertEquals(0, waitAppProcessExit()); + assertArguments("ExpParam1", "ExpParam 2"); + } + + public void testArgumentsCombinedReplace() throws Exception { + File wd = getWorkDir(); + createSourceFile("main.cpp", wd, CPP_APP); + compileCPP("main", wd); + ExplicitProcessParameters params = ExplicitProcessParameters.builder(). + arg("ExpParam1"). + arg("ExpParam 2"). + build(); + startDebugging(Arrays.asList(new File(wd, "main").getAbsolutePath(), "Param1", "Param 2"), params); Review comment: combined, explicit, own parameters - that looks like explicit set of tests. Thanks. ########## File path: ide/nativeimage.api/src/org/netbeans/modules/nativeimage/api/debug/StartDebugParameters.java ########## @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.modules.nativeimage.api.debug; + +import java.io.File; +import java.util.List; +import org.netbeans.api.extexecution.ExecutionDescriptor; +import org.openide.util.Lookup; + +/** + * Parameters passed to {@link NIDebugger#start(org.netbeans.modules.nativeimage.api.debug.StartDebugParameters, java.util.function.Consumer)}. + * + * @since 0.5 + */ +public final class StartDebugParameters { + + private final List<String> command; + private final File workingDirectory; + private final String debugger; + private final String displayName; + private final ExecutionDescriptor executionDescriptor; + private final Lookup contextLookup; + + private StartDebugParameters(List<String> command, File workingDirectory, String debugger, String displayName, ExecutionDescriptor executionDescriptor, Lookup contextLookup) { + this.command = command; + this.workingDirectory = workingDirectory; + this.debugger = debugger; + this.displayName = displayName; + this.executionDescriptor = executionDescriptor; + this.contextLookup = contextLookup; + } + + /** + * The command to run the native image. + * + * @return the command with arguments. + */ + public List<String> getCommand() { + return command; + } + + /** + * Working directory of the process. + * + * @return the working directory + */ + public File getWorkingDirectory() { + return workingDirectory; + } + + /** + * The native debugger command. + * + * @return the debugger command + */ + public String getDebugger() { + return debugger; + } + + /** + * Display name of the debugger task. + * + * @return the display name of debugger task + */ + public String getDisplayName() { + return displayName; + } + + /** + * Execution descriptor that describes the runtime attributes. + * + * @return the execution descriptor + */ + public ExecutionDescriptor getExecutionDescriptor() { + return executionDescriptor; + } + + /** + * Context lookup. The lookup may contain other parameters, like ExplicitProcessParameters. + * + * @return the context lookup + */ + public Lookup getContextLookup() { + return contextLookup; + } + + /** + * Create a new debug parameters builder. + * + * @param command the command to run the native image. + * @return a new builder + */ + public static Builder newBuilder(List<String> command) { Review comment: Wouldn't this method be more usable with vargargs? ########## File path: ide/nativeimage.api/src/org/netbeans/modules/nativeimage/api/debug/StartDebugParameters.java ########## @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.modules.nativeimage.api.debug; + +import java.io.File; +import java.util.List; +import org.netbeans.api.extexecution.ExecutionDescriptor; +import org.openide.util.Lookup; + +/** + * Parameters passed to {@link NIDebugger#start(org.netbeans.modules.nativeimage.api.debug.StartDebugParameters, java.util.function.Consumer)}. + * + * @since 0.5 + */ +public final class StartDebugParameters { Review comment: Final class forms a good [open space](http://wiki.apidesign.org/wiki/ClientAPI) and it can easily grow over time - you'll be able to add new parameters to it. ########## File path: java/gradle.java/arch.xml ########## @@ -110,6 +110,18 @@ in action's context Lookup. See <a href="@TOP@/org/netbeans/modules/gradle/java/api/ProjectActions.html#TOKEN_JAVAEXEC_ARGS">ProjectActions.TOKEN_JAVAEXEC_ARGS</a> for more details. </api> + <api category="stable" group="property" name="javaExec.runWorkingDir" type="export"> Review comment: Actually this is `type="import"` as you are importing/using the Gradle API here. Thanks for documenting the contract anyway! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For additional commands, e-mail: notifications-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists