Merge changes to master

This commit is contained in:
Martin Hare Robertson 2010-08-06 00:23:41 +01:00
commit 4247ea0234
21 changed files with 563 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="org.intrace.visualvm" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project org.intrace.visualvm.</description>
<import file="nbproject/build-impl.xml"/>
</project>

View File

@ -0,0 +1,7 @@
Manifest-Version: 1.0
OpenIDE-Module: org.intrace.visualvm
OpenIDE-Module-Install: org/intrace/visualvm/Installer.class
OpenIDE-Module-Layer: org/intrace/visualvm/layer.xml
OpenIDE-Module-Localizing-Bundle: org/intrace/visualvm/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0
OpenIDE-Module-Name: InTrace: VisualVM Plugin

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="org.intrace.visualvm-impl" basedir="..">
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
<not>
<antversion atleast="1.7.1"/>
</not>
</condition>
</fail>
<property file="nbproject/private/platform-private.properties"/>
<property file="nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="property"/>
<attribute name="value"/>
<sequential>
<property name="@{property}" value="@{value}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
<condition>
<not>
<contains string="${cluster.path.evaluated}" substring="platform"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>

View File

@ -0,0 +1,5 @@
cluster.path=\
${nbplatform.active.dir}/platform:\
${nbplatform.active.dir}/profiler:\
${nbplatform.active.dir}/visualvm
nbplatform.active=VisualVM_1.2.2

View File

@ -0,0 +1,3 @@
cp.extra=${tools.jar}
javac.source=1.6
javac.compilerargs=-Xlint -Xlint:-serial

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>org.intrace.visualvm</code-name-base>
<standalone/>
<module-dependencies>
<dependency>
<code-name-base>com.sun.tools.visualvm.application</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>0-1</release-version>
<specification-version>1.2</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.tools.visualvm.attach</code-name-base>
<run-dependency>
<release-version>0-1</release-version>
<specification-version>1.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.tools.visualvm.core</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>0-1</release-version>
<specification-version>1.3</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.tools.visualvm.host</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>0-1</release-version>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.tools.visualvm.tools</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>0-1</release-version>
<specification-version>1.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.modules</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.13.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.31.1.1</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<public-packages/>
</data>
</configuration>
</project>

Binary file not shown.

View File

@ -0,0 +1 @@
OpenIDE-Module-Name=InTrace: Visual VM Plugin

View File

@ -0,0 +1,20 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.intrace.visualvm;
import org.intrace.visualvm.view.InTraceViewProvider;
import org.openide.modules.ModuleInstall;
/**
* Manages a module's lifecycle. Remember that an installer is optional and
* often not needed at all.
*/
public class Installer extends ModuleInstall {
@Override
public void restored() {
InTraceViewProvider.initialize();
}
}

View File

@ -0,0 +1,50 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.intrace.visualvm;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openide.modules.InstalledFileLocator;
/**
*
* @author mch50
*/
public class Locator {
public static final String agentPath;
public static final String clientPath;
static {
File locatedFile = InstalledFileLocator.getDefault().locate("modules/ext/intrace-agent.jar", null, false); // NOI18N
if (locatedFile != null) {
agentPath = locatedFile.getAbsolutePath();
} else {
agentPath = null;
}
String osName = System.getProperty("os.name", "unknown");
if (osName.contains("Windows")) {
locatedFile = InstalledFileLocator.getDefault().locate("modules/ext/intrace-client-gui-win.jar", null, false); // NOI18N
if (locatedFile != null) {
clientPath = locatedFile.getAbsolutePath();
} else {
clientPath = null;
}
}
else if (osName.contains("Linux")) {
locatedFile = InstalledFileLocator.getDefault().locate("modules/ext/intrace-client-gui-linux.jar", null, false); // NOI18N
if (locatedFile != null) {
clientPath = locatedFile.getAbsolutePath();
} else {
clientPath = null;
}
}
else {
clientPath = null;
}
}
}

View File

@ -0,0 +1 @@
InTraceApplicationAction.title=InTrace Application...

View File

@ -0,0 +1,43 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.intrace.visualvm.actions;
import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import com.sun.tools.visualvm.core.ui.DataSourceWindowManager;
import com.sun.tools.visualvm.core.ui.actions.SingleDataSourceAction;
import java.awt.event.ActionEvent;
import org.intrace.visualvm.impl.InTraceDataSource;
import org.openide.util.NbBundle;
/**
*
* @author mch50
*/
public class InTraceApplicationAction extends SingleDataSourceAction<Application> {
@Override
protected void actionPerformed(Application app, ActionEvent actionEvent) {
InTraceDataSource dataSource = new InTraceDataSource(app);
DataSourceWindowManager.sharedInstance().openDataSource(dataSource);
}
@Override
protected boolean isEnabled(Application app) {
Jvm jvm = JvmFactory.getJVMFor(app);
return app.isLocalApplication() && jvm.isAttachable() && jvm.isGetSystemPropertiesSupported();
}
public static synchronized InTraceApplicationAction newInstance() {
return new InTraceApplicationAction();
}
private InTraceApplicationAction() {
super(Application.class);
putValue(NAME, NbBundle.getMessage(InTraceApplicationAction.class, "InTraceApplicationAction.title")); // NOI18N
}
}

View File

@ -0,0 +1,23 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.intrace.visualvm.impl;
import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.core.datasource.DataSource;
/**
*
* @author mch50
*/
public class InTraceDataSource extends DataSource {
public final Application app;
public InTraceDataSource(Application app) {
super(app);
this.app = app;
}
}

View File

@ -0,0 +1,89 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.intrace.visualvm.impl;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.visualvm.application.Application;
import com.sun.tools.visualvm.application.jvm.Jvm;
import com.sun.tools.visualvm.application.jvm.JvmFactory;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.intrace.visualvm.Locator;
import org.openide.util.Exceptions;
/**
*
* @author mch50
*/
public class InTraceLoader {
public static interface StatusHandler {
public void handleStatus(String statusLine);
}
public static void loadAgent(Application app, StatusHandler handler) {
Jvm jvm = JvmFactory.getJVMFor(app);
if (app.isLocalApplication() && jvm.isAttachable() && jvm.isGetSystemPropertiesSupported()) {
try {
VirtualMachine vm = VirtualMachine.attach(String.valueOf(app.getPid()));
handler.handleStatus("Attached to JVM (PID: " + app.getPid() + ")");
vm.loadAgent(Locator.agentPath, "");
handler.handleStatus("InTrace Agent loaded");
} catch (Exception ex) {
handler.handleStatus("Exception thrown:\n" + throwableToString(ex));
Exceptions.printStackTrace(ex);
}
}
}
public static void launchClient(final StatusHandler handler) {
Runnable launchClientThread = new Runnable() {
@Override
public void run() {
try {
List<String> command = new ArrayList<String>();
command.add("java");
command.add("-jar");
command.add(Locator.clientPath);
ProcessBuilder builder = new ProcessBuilder(command);
System.out.println("Directory : " + System.getenv("temp"));
builder.start();
handler.handleStatus("InTrace Client launched");
} catch (Exception ex) {
handler.handleStatus("Exception thrown:\n" + throwableToString(ex));
Exceptions.printStackTrace(ex);
}
}
};
new Thread(launchClientThread).start();
}
private static String throwableToString(Throwable throwable) {
StringBuilder throwToStr = new StringBuilder();
if (throwable == null) {
throwToStr.append("null");
} else {
StringWriter strWriter = new StringWriter();
PrintWriter writer = new PrintWriter(strWriter);
throwable.printStackTrace(writer);
throwToStr.append(strWriter.toString());
}
return throwToStr.toString();
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
<folder name="VisualVM">
<folder name="ExplorerPopupSelection">
<file name="ExplorerPopupSelection-Separator-2000_1.instance" url="ExplorerPopupSelection-Separator-2000_1.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="2350"/>
</file>
<file name="org-intrace-visualvm-actions-InTraceApplicationAction.instance">
<attr name="instanceCreate" methodvalue="org.intrace.visualvm.actions.InTraceApplicationAction.newInstance"/>
<attr name="position" intvalue="2400"/>
</file>
</folder>
</folder>
</filesystem>

View File

@ -0,0 +1,144 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.intrace.visualvm.view;
import com.sun.tools.visualvm.core.ui.DataSourceView;
import com.sun.tools.visualvm.core.ui.components.DataViewComponent;
import java.awt.BorderLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import org.intrace.visualvm.Locator;
import org.intrace.visualvm.impl.InTraceLoader;
import org.intrace.visualvm.impl.InTraceDataSource;
import org.openide.util.Utilities;
/**
*
* @author mch50
*/
public class InTraceView extends DataSourceView {
private final InTraceDataSource application;
private JTextArea textArea;
private DataViewComponent dvc;
//Reusing an image from the sources:
private static final String IMAGE_PATH = "com/sun/tools/visualvm/coredump/resources/coredump.png"; // NOI18N
public InTraceView(InTraceDataSource application) {
super(application, "InTrace", new ImageIcon(Utilities.loadImage(IMAGE_PATH, true)).getImage(), 60, false);
this.application = application;
}
@Override
protected DataViewComponent createComponent() {
//Data area for master view:
JPanel generalDataArea = new JPanel();
generalDataArea.setBorder(BorderFactory.createEmptyBorder(14, 8, 14, 8));
generalDataArea.setOpaque(false);
JButton loadAgentButton = new JButton("Load InTrace Agent");
loadAgentButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
InTraceLoader.loadAgent(application.app, new InTraceLoader.StatusHandler() {
@Override
public void handleStatus(String statusLine) {
appendText(statusLine);
}
});
}
});
JButton launchClient = new JButton("Launch InTrace Client");
launchClient.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
InTraceLoader.launchClient(new InTraceLoader.StatusHandler() {
@Override
public void handleStatus(String statusLine) {
appendText(statusLine);
}
});
}
});
JButton clearStatus = new JButton("Clear Status Text");
clearStatus.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clearText();
}
});
generalDataArea.add(loadAgentButton);
generalDataArea.add(launchClient);
generalDataArea.add(clearStatus);
//Master view:
DataViewComponent.MasterView masterView = new DataViewComponent.MasterView
("Control", null, generalDataArea);
//Configuration of master view:
DataViewComponent.MasterViewConfiguration masterConfiguration =
new DataViewComponent.MasterViewConfiguration(false);
//Add the master view and configuration view to the component:
dvc = new DataViewComponent(masterView, masterConfiguration);
//Add detail view to the component:
JPanel statusArea = new JPanel();
statusArea.setOpaque(false);
statusArea.setLayout(new BorderLayout());
textArea = new JTextArea(5, 20);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setMargin(new Insets(10,10,10,10));
statusArea.add(scrollPane, BorderLayout.CENTER);
dvc.addDetailsView(new DataViewComponent.DetailsView(
"Status", null, 10, statusArea, null), DataViewComponent.BOTTOM_LEFT);
appendText("Agent Path: " + Locator.agentPath);
appendText("Client Path: " + Locator.clientPath);
if (Locator.clientPath == null) {
appendText("Warning: The Client is only supported on Windows " +
"and Linux");
}
else {
appendText("Ready");
}
return dvc;
}
private void appendText(String str) {
if (textArea != null) {
textArea.append(str + "\n");
}
}
private void clearText() {
if (textArea != null) {
textArea.setText("");
}
}
}

View File

@ -0,0 +1,39 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.intrace.visualvm.view;
import com.sun.tools.visualvm.core.ui.DataSourceView;
import com.sun.tools.visualvm.core.ui.DataSourceViewProvider;
import com.sun.tools.visualvm.core.ui.DataSourceViewsManager;
import org.intrace.visualvm.impl.InTraceDataSource;
/**
*
* @author mch50
*/
public class InTraceViewProvider extends DataSourceViewProvider<InTraceDataSource> {
private static DataSourceViewProvider<InTraceDataSource> instance = new InTraceViewProvider();
@Override
public boolean supportsViewFor(InTraceDataSource application) {
//Always shown:
return true;
}
@Override
public synchronized DataSourceView createView(final InTraceDataSource application) {
return new InTraceView(application);
}
public static void initialize() {
DataSourceViewsManager.sharedInstance().addViewProvider(instance, InTraceDataSource.class);
}
static void unregister() {
DataSourceViewsManager.sharedInstance().removeViewProvider(instance);
}
}