Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ public static LaunchingDICookie create (
// TODO: This code is likely wrong, we need to run debuggee on JDK that
// is set on the project.
// XXX: This method is likely not called from anywhere.
// But it's an impl. of API method JPDADebugger.launch().
String commandLine = System.getProperty ("java.home") +
"\\bin\\java -agentlib:jdwp=transport=" +
// But it's an impl. of API m ethod JPDADebugger.launch().
String commandLine = "\"" + System.getProperty ("java.home") +
"\\bin\\java\"" + " -agentlib:jdwp=transport=" +
getTransportName () +
",address=name,suspend=" +
",address=name,server=y,suspend=" +
(suspend ? "y" : "n") +
" -classpath \"" +
classPath +
Expand Down
26 changes: 26 additions & 0 deletions java/debugger.jpda/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.extexecution</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>1.53</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.java.openjdk.project</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.2</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.java.source.base</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -142,6 +160,14 @@
<specification-version>8.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.ui</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.13</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<test-dependencies>
<test-type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
import com.sun.jdi.event.Event;
import com.sun.jdi.request.EventRequest;
import java.io.File;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.logging.Level;

import org.netbeans.api.extexecution.ExecutionDescriptor;
import java.util.logging.Logger;
import org.netbeans.api.debugger.ActionsManager;
import org.netbeans.spi.debugger.ContextProvider;
Expand All @@ -42,10 +49,13 @@
import org.netbeans.modules.debugger.jpda.util.Executor;
import org.netbeans.spi.debugger.ActionsProvider;
import org.netbeans.spi.debugger.ActionsProviderListener;

import org.netbeans.api.extexecution.ExecutionService;
import org.netbeans.modules.java.openjdk.jtreg.SingleJavaSourceDebugActionProvider;
import org.netbeans.spi.project.ActionProvider;
import org.openide.filesystems.FileObject;
import org.openide.util.Cancellable;
import org.openide.util.Exceptions;

import org.openide.util.Lookup;

/**
*
Expand Down Expand Up @@ -154,12 +164,48 @@ public void run() {

}

public RunProcess invokeActionHelper (int port) {
List<String> commandsList = new ArrayList<>();
if (org.openide.util.Utilities.isUnix()) {
commandsList.add("bash");
commandsList.add("-c");
}
ActionProvider dap = null;
for (ActionProvider ap : Lookup.getDefault().lookupAll(ActionProvider.class)) {
if (Arrays.asList(ap.getSupportedActions()).contains("debug.single") && ap.isActionEnabled("debug.single", null)) {
dap = ap;
break;
}
}
if (dap instanceof SingleJavaSourceDebugActionProvider) {
SingleJavaSourceDebugActionProvider debugActionProvider = (SingleJavaSourceDebugActionProvider) dap;
FileObject debugFile = debugActionProvider.getFileObject();
File javaPathFile = new File(new File(new File(System.getProperty("java.home")), "bin"), "java");
String javaPath = "\"" + javaPathFile.getAbsolutePath() + "\"";
commandsList.add(javaPath + " -agentlib:jdwp=transport=dt_socket,suspend=y,server=n,address=localhost:" + port + " -classpath \"" + debugFile.getParent().getPath() + "\" " + debugFile.getName());
return new RunProcess(commandsList);
}
return null;
}

private void doStartDebugger(AbstractDICookie cookie) {
logger.fine("S StartActionProvider." +
"doStartDebugger");
Throwable throwable = null;
try {
debuggerImpl.setAttaching(cookie);

if (cookie instanceof ListeningDICookie) {
ListeningDICookie ldc = (ListeningDICookie) cookie;
ExecutionDescriptor descriptor = new ExecutionDescriptor().controllable(true).frontWindow(true).
preExecution(null).postExecution(null);
RunProcess process = invokeActionHelper(ldc.getPortNumber());
ExecutionService exeService = ExecutionService.newService(
process,
descriptor, "Debugging Java File");
Future<Integer> exitCode = exeService.run();
}

VirtualMachine virtualMachine = cookie.getVirtualMachine ();
debuggerImpl.setAttaching(null);
VirtualMachineWrapper.setDebugTraceMode (virtualMachine, jdiTrace);
Expand Down Expand Up @@ -197,6 +243,7 @@ private void doStartDebugger(AbstractDICookie cookie) {

logger.fine("S StartActionProvider." +
"doStartDebugger end: success");
//
} catch (InterruptedException iex) {
throwable = iex;
} catch (IOException ioex) {
Expand Down Expand Up @@ -304,3 +351,56 @@ public boolean cancel() {
}
}
}
class RunProcess implements Callable<Process> {

private static final Logger LOG = Logger.getLogger(RunProcess.class.getName());

private final String dirPath;
private final List<String> commandsList;
private InputStream is;
private Process p;

public RunProcess(String command, String dirPath) {
this.dirPath = dirPath;
commandsList = new ArrayList<>();
commandsList.add(command);
setupProcess();
}

public RunProcess(String command) {
commandsList = new ArrayList<>();
commandsList.add(command);
this.dirPath = System.getProperty("user.home");
setupProcess();
}

public RunProcess(List<String> commandsList) {
this.commandsList = commandsList;
this.dirPath = System.getProperty("user.home");
setupProcess();
}

public void setupProcess() {
try {
ProcessBuilder runFileProcessBuilder = new ProcessBuilder(commandsList);
runFileProcessBuilder.directory(new File(dirPath));
runFileProcessBuilder.redirectErrorStream(true);
p = runFileProcessBuilder.start();
is = p.getInputStream();
} catch (IOException ex) {
LOG.log(
Level.WARNING,
"Could not get InputStream of Run Process"); //NOI18N
}
}

public InputStream getInputStream() {
return is;
}

@Override
public Process call() throws Exception {
return p;
}

}
4 changes: 3 additions & 1 deletion java/java.openjdk.project/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@
</test-dependency>
</test-type>
</test-dependencies>
<public-packages/>
<public-packages>
<package>org.netbeans.modules.java.openjdk.jtreg</package>
</public-packages>
</data>
</configuration>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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.java.openjdk.jtreg;

import java.io.File;
import org.netbeans.spi.project.ActionProvider;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.lookup.ServiceProvider;
import org.openide.windows.IOProvider;
import org.openide.windows.InputOutput;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.netbeans.modules.java.openjdk.project.JDKProject;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;

/**
*
* @author Sarvesh Kesharwani
*/
@ServiceProvider(service = ActionProvider.class)
public class SingleJavaSourceDebugActionProvider implements ActionProvider {

private FileObject fileObject;

@Override
public String[] getSupportedActions() {
return new String[]{ActionProvider.COMMAND_DEBUG_SINGLE};
}

@Override
public void invokeAction(String command, Lookup context) throws IllegalArgumentException {
InputOutput io = IOProvider.getDefault().getIO("Opening Debugger Port", false);
JPDAStart start = new JPDAStart(io, "debug.single");
try {
FileObject fileObject = getJavaFileWithoutProjectFromLookup(context);
File classFile = new File(fileObject.getParent().getPath() + File.separator + fileObject.getName() + ".class");
if (classFile.exists()) {
classFile.delete();
}
File javacPath = new File(new File(new File(System.getProperty("java.home")), "bin"), "javac");
Runtime.getRuntime().exec("\"" + javacPath.getAbsolutePath() + "\" " + "\"" + fileObject.getPath() + "\"");
long startTime = System.currentTimeMillis();
long fintime = startTime + 6000;
while (!classFile.exists() && fintime < System.currentTimeMillis()) {
//
}
if (classFile.exists()) {
this.fileObject = fileObject;
start.execute(new JDKProject(fileObject.getParent(), null, null));
}
} catch (Throwable ex) {
Exceptions.printStackTrace(ex);
}
}

@Override
public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException {
return command.equalsIgnoreCase(ActionProvider.COMMAND_DEBUG_SINGLE);
}

public FileObject getFileObject() {
return fileObject;
}

private FileObject getJavaFileWithoutProjectFromLookup(Lookup lookup) {
for (DataObject dObj : lookup.lookupAll(DataObject.class)) {
FileObject fObj = dObj.getPrimaryFile();
Project p = FileOwnerQuery.getOwner(fObj);
if (p == null && fObj.getExt().equalsIgnoreCase("java")) {
return fObj;
}
}
return null;
}

}