Skip to content

Commit

Permalink
6204: Flight recorder launcher tab bugs out
Browse files Browse the repository at this point in the history
Reviewed-by: aptmac
  • Loading branch information
mirage22 committed Jul 7, 2021
1 parent 81344ce commit 1d7397e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.FormText;
Expand Down Expand Up @@ -219,7 +220,10 @@ public void createControl(Composite parent) {
* considered a quick & dirty fix as this may well happen in other dialogs too.
*/
if (Environment.getOSType() == Environment.OSType.LINUX) {
getShell().layout();
Shell shell = getShell();
if (shell != null) {
shell.layout();
}
}

if (m_displayHelp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ public void initializeFrom(ILaunchConfiguration configuration) {
jfrLaunchPage.setAutoOpen(tempModel.getAutoOpen());
model.setAutoOpen(tempModel.getAutoOpen());
}
if (model.getOracleJdkLessThan11() != tempModel.getOracleJdkLessThan11()) {
jfrLaunchPage.setLessThanOracleJdk11(tempModel.getOracleJdkLessThan11());
model.setOracleJdkLessThan11(tempModel.getOracleJdkLessThan11());
}
if (model.isContinuous() != tempModel.isContinuous()) {
jfrLaunchPage.setContinuous(tempModel.isContinuous());
model.setFixedRecording(!tempModel.isContinuous());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import org.openjdk.jmc.flightrecorder.controlpanel.ui.wizards.RecordingWizardPage;
import org.openjdk.jmc.ide.launch.model.JfrLaunchModel;

public class JfrLaunchPage extends RecordingWizardPage implements Observer {

private Button enabledCheckbox;
private Button autoOpenCheckbox;
private Button lessThanOracleJDK11Checkbox;
private JfrLaunchModel model;

public JfrLaunchPage(JfrLaunchModel model) {
Expand All @@ -62,16 +62,15 @@ public JfrLaunchPage(JfrLaunchModel model) {
@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
int cols = 2;
int cols = 3;
comp.setLayout(new GridLayout(cols, false));

GridData gd1 = new GridData(SWT.FILL, SWT.FILL, true, true);
comp.setLayoutData(gd1);

createEnabled(comp, cols);
createOpenAutomatically(comp, cols);
// TODO: Add info text and help text

createLessThanOracleJdk11(comp, cols);
createSeparator(comp, cols);

super.createControl(comp);
Expand Down Expand Up @@ -119,6 +118,21 @@ public void widgetSelected(SelectionEvent e) {
autoOpenCheckbox.setLayoutData(gd);
}

private void createLessThanOracleJdk11(Composite parent, int cols) {
lessThanOracleJDK11Checkbox = new Button(parent, SWT.CHECK);
lessThanOracleJDK11Checkbox.setText(Messages.JfrLaunch_ORACLE_JDK_LESS_THAN_11);
lessThanOracleJDK11Checkbox.setToolTipText(Messages.JfrLaunch_ORACLE_JDK_CECHKBOX_MESSAGE);
lessThanOracleJDK11Checkbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
model.setOracleJdkLessThan11(lessThanOracleJDK11Checkbox.getSelection());
}
});
GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
gd.horizontalSpan = cols - 1;
lessThanOracleJDK11Checkbox.setLayoutData(gd);
}

public void setJfrEnabled(boolean jfrEnabled) {
enabledCheckbox.setSelection(jfrEnabled);
}
Expand All @@ -135,6 +149,14 @@ public boolean getAutoOpen() {
return autoOpenCheckbox.getSelection();
}

public void setLessThanOracleJdk11(boolean lessThanOracleJdk11) {
lessThanOracleJDK11Checkbox.setSelection(lessThanOracleJdk11);
}

public boolean getLessThanOracleJdk11() {
return lessThanOracleJDK11Checkbox.getSelection();
}

@Override
public void update(Observable o, Object arg) {
if (arg != null && arg.equals(JfrLaunchModel.JRE_SUPPORTS_DUMPONEXIT_CHANGED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class Messages extends NLS {
public static String JfrLaunch_RECORDING_WAITER_INTERRUPTED;
public static String JfrLaunch_UNKNOWN_JRE_NAME;
public static String JfrLaunch_UNKNOWN_JRE_VERSION;
public static String JfrLaunch_ORACLE_JDK_LESS_THAN_11;
public static String JfrLaunch_ORACLE_JDK_CECHKBOX_MESSAGE;
public static String VOLATILE_CONFIGURATION_IN_JRE;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ public class JfrArgsBuilder {
private final String jfrFilename;
private final String name;
private final boolean continuous;
private final boolean lessThanOracleJdk11;
private boolean supportsDumpOnExitWithoutDefaultRecording;

public JfrArgsBuilder(boolean jfrEnabled, boolean supportsDumpOnExitWithoutDefaultRecording, IQuantity duration,
IQuantity delay, String settings, String jfrFilename, String name, boolean continuous) {
IQuantity delay, String settings, String jfrFilename, String name, boolean continuous,
boolean lessThenOracleJdk11) {
this.jfrEnabled = jfrEnabled;
this.supportsDumpOnExitWithoutDefaultRecording = supportsDumpOnExitWithoutDefaultRecording;
this.duration = duration;
Expand All @@ -110,14 +112,17 @@ public JfrArgsBuilder(boolean jfrEnabled, boolean supportsDumpOnExitWithoutDefau
this.jfrFilename = jfrFilename;
this.name = name;
this.continuous = continuous;
this.lessThanOracleJdk11 = lessThenOracleJdk11;
}

public String[] getJfrArgs(boolean quotWhitespace) throws Exception {
List<String> jfrArgs = new ArrayList<>();

if (jfrEnabled) {

jfrArgs.add(UNLOCKCOMMERCIAL_ARGUMENT);
if (lessThanOracleJdk11) {
jfrArgs.add(UNLOCKCOMMERCIAL_ARGUMENT);
}
jfrArgs.add(FLIGHTRECORDER_ARGUMENT);
String adaptedFilename = getQuotedFilename(quotWhitespace);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class JfrLaunchModel extends RecordingWizardModel {

private static final boolean DEFAULT_ENABLED = false;
private static final boolean DEFAULT_AUTO_OPEN = false;
private static final boolean DEFAULT_ORACLE_JDK_LESS_THAN_11 = false;

// TODO: Should this be changed to "profile"?
private static final String DEFAULT_SETTINGS = "default"; //$NON-NLS-1$
Expand All @@ -94,6 +95,7 @@ public class JfrLaunchModel extends RecordingWizardModel {

private static final String ENABLED_ATTRIBUTE = "jmc.jfr.launching.JFR.ENABLED"; //$NON-NLS-1$
private static final String AUTO_OPEN_ATTRIBUTE = "jmc.jfr.launching.JFR.AUTO_OPEN"; //$NON-NLS-1$
private static final String ORACLE_JDK_LESS_THAN_11 = "jmc.jfr.launching.JFR.ORACLE_JDK_LESS_THAN_11"; //$NON-NLS-1$
private static final String DURATION_ATTRIBUTE = "jmc.jfr.launching.JFR.DURATION"; //$NON-NLS-1$
private static final String DELAY_ATTRIBUTE = "jmc.jfr.launching.JFR.DELAY"; //$NON-NLS-1$
private static final String SETTINGS_ATTRIBUTE = "jmc.jfr.launching.JFR.SETTINGS"; //$NON-NLS-1$
Expand All @@ -107,10 +109,11 @@ public class JfrLaunchModel extends RecordingWizardModel {

private boolean m_autoOpen;
private boolean m_jfrEnabled = true;
private boolean m_oracleJdkLessThan11;
private boolean jreSupportsDumpOnExitWithoutDefaultRecording;

public JfrLaunchModel(boolean jfrEnabled, boolean autoOpen) {
super(new NullFlightRecorderService(JavaVersionSupport.JDK_7_U_4), ControlPanel.getDefaultRecordingFile("")); //$NON-NLS-1$
super(new NullFlightRecorderService(JavaVersionSupport.JDK_11), ControlPanel.getDefaultRecordingFile("")); //$NON-NLS-1$

setFixedRecording(!DEFAULT_CONTINUOUS);

Expand Down Expand Up @@ -297,6 +300,7 @@ private void updateJfrLaunchFromConfiguration(ILaunchConfiguration configuration
throws CoreException, QuantityConversionException {
setJfrEnabled(configuration.getAttribute(ENABLED_ATTRIBUTE, DEFAULT_ENABLED));
setAutoOpen(configuration.getAttribute(AUTO_OPEN_ATTRIBUTE, DEFAULT_AUTO_OPEN));
setOracleJdkLessThan11(configuration.getAttribute(ORACLE_JDK_LESS_THAN_11, DEFAULT_ORACLE_JDK_LESS_THAN_11));
setName(configuration.getAttribute(NAME_ATTRIBUTE, DEFAULT_NAME));
String filePath = configuration.getAttribute(FILENAME_ATTRIBUTE, (String) null);
if (filePath != null) {
Expand Down Expand Up @@ -351,6 +355,7 @@ private static String getJREName(ILaunchConfiguration configuration) throws Core
public void updateToConfiguration(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(ENABLED_ATTRIBUTE, isJfrEnabled());
configuration.setAttribute(AUTO_OPEN_ATTRIBUTE, getAutoOpen());
configuration.setAttribute(ORACLE_JDK_LESS_THAN_11, getOracleJdkLessThan11());
configuration.setAttribute(DURATION_ATTRIBUTE, getDurationString());
configuration.setAttribute(DELAY_ATTRIBUTE, getDelayString());
configuration.setAttribute(SETTINGS_ATTRIBUTE, getTemplatePath());
Expand All @@ -377,9 +382,24 @@ public void setJfrEnabled(boolean enabled) {
onChange();
}

public void setOracleJdkLessThan11(boolean oracleJdkLessThan11) {
m_oracleJdkLessThan11 = oracleJdkLessThan11;
if (oracleJdkLessThan11) {
setVersion(SchemaVersion.V1);
} else {
setVersion(SchemaVersion.V2);
}
onChange();
}

public boolean getOracleJdkLessThan11() {
return m_oracleJdkLessThan11;
}

public JfrArgsBuilder createArgsBuilder() throws Exception {
return new JfrArgsBuilder(isJfrEnabled(), jreSupportsDumpOnExitWithoutDefaultRecording, getDuration(),
getDelay(), getTemplatePath(), getRecordingFile().getAbsolutePath(), getName(), isContinuous());
getDelay(), getTemplatePath(), getRecordingFile().getAbsolutePath(), getName(), isContinuous(),
getOracleJdkLessThan11());
}

public File getRecordingFile() throws FileNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ JfrLaunch_RECORDING_WAITER_INTERRUPTED=Thread waiting to open time fixed flight
JfrLaunch_JFR_OPTIONS_PROBLEM=Problem when creating VM arguments for JFR
JfrLaunch_UNKNOWN_JRE_NAME=Unknown JRE name
JfrLaunch_UNKNOWN_JRE_VERSION=Unknown JRE version
JfrLaunch_ORACLE_JDK_LESS_THAN_11=Oracle JDK < 11
JfrLaunch_ORACLE_JDK_CECHKBOX_MESSAGE=Only check this if it really is an Oracle JDK. For OpenJDK, leave this unchecked.

VOLATILE_CONFIGURATION_IN_JRE=in JRE
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ JfrLaunch_RECORDING_WAITER_INTERRUPTED=\u4E00\u5B9A\u6642\u9593\u306E\u30D5\u30E
JfrLaunch_JFR_OPTIONS_PROBLEM=JFR\u306EVM\u5F15\u6570\u3092\u4F5C\u6210\u4E2D\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F
JfrLaunch_UNKNOWN_JRE_NAME=\u4E0D\u660E\u306AJRE\u540D
JfrLaunch_UNKNOWN_JRE_VERSION=\u4E0D\u660E\u306AJRE\u30D0\u30FC\u30B8\u30E7\u30F3
JfrLaunch_ORACLE_JDK_LESS_THAN_11=Oracle JDK < 11
JfrLaunch_ORACLE_JDK_CECHKBOX_MESSAGE=Only check this if it really is an Oracle JDK. For OpenJDK, leave this unchecked.

VOLATILE_CONFIGURATION_IN_JRE=JRE\u5185
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ JfrLaunch_RECORDING_WAITER_INTERRUPTED=\u7B49\u5F85\u6253\u5F00\u56FA\u5B9A\u65F
JfrLaunch_JFR_OPTIONS_PROBLEM=\u4E3A JFR \u521B\u5EFA VM \u53C2\u6570\u65F6\u51FA\u73B0\u95EE\u9898
JfrLaunch_UNKNOWN_JRE_NAME=\u672A\u77E5 JRE \u540D\u79F0
JfrLaunch_UNKNOWN_JRE_VERSION=\u672A\u77E5 JRE \u7248\u672C
JfrLaunch_ORACLE_JDK_LESS_THAN_11=Oracle JDK < 11
JfrLaunch_ORACLE_JDK_CECHKBOX_MESSAGE=Only check this if it really is an Oracle JDK. For OpenJDK, leave this unchecked.

VOLATILE_CONFIGURATION_IN_JRE=\u4F4D\u4E8E JRE
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public class JfrArgsBuilderJfrArgsTest {
@Test
public void testNoArgsrIfJfrDisabled() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(false, false, okDuration, okDelay, okSettings, okFilename, okName,
false);
false, false);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(false));
Assert.assertEquals("", jfrArgs);
}

@Test
public void testJfrArgsIfEnabledDurationDelayProfileNameFilename() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(true, false, okDuration, okDelay, okSettings, okFilename, okName,
false);
false, true);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(false));
Assert.assertEquals(
"-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=default,duration=10s,name=kossa,filename=apa.jfr",
Expand All @@ -74,7 +74,7 @@ public void testJfrArgsIfEnabledDurationDelayProfileNameFilename() throws Except
@Test
public void testJfrArgsIfContinuousDefaultSettingsPre8u20() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(true, false, okDuration, okDelay, okSettings, okFilename, okName,
true);
true, true);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(false));
Assert.assertEquals(
"-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=defaultrecording=true -XX:FlightRecorderOptions=dumponexit=true,dumponexitpath=apa.jfr",
Expand All @@ -84,7 +84,7 @@ public void testJfrArgsIfContinuousDefaultSettingsPre8u20() throws Exception {
@Test
public void testJfrArgsIfContinuousOtherSettingsPre8u20() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(true, false, okDuration, okDelay, otherSettings, okFilename, okName,
true);
true, true);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(false));
Assert.assertEquals(
"-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=defaultrecording=true -XX:FlightRecorderOptions=dumponexit=true,dumponexitpath=apa.jfr",
Expand All @@ -94,7 +94,7 @@ public void testJfrArgsIfContinuousOtherSettingsPre8u20() throws Exception {
@Test
public void testJfrArgsIfContinuousDefaultSettingsPost8u20() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(true, true, okDuration, okDelay, okSettings, okFilename, okName,
true);
true, true);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(false));
Assert.assertEquals(
"-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=default,dumponexit=true,name=kossa,filename=apa.jfr",
Expand All @@ -104,7 +104,7 @@ public void testJfrArgsIfContinuousDefaultSettingsPost8u20() throws Exception {
@Test
public void testJfrArgsIfContinuousOtherSettingsPost8u20() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(true, true, okDuration, okDelay, otherSettings, okFilename, okName,
true);
true, true);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(false));
Assert.assertEquals(
"-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,dumponexit=true,name=kossa,filename=apa.jfr",
Expand All @@ -114,13 +114,23 @@ public void testJfrArgsIfContinuousOtherSettingsPost8u20() throws Exception {
@Test
public void testJfrArgsIfQuotedSpacePaths() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(true, true, okDuration, okDelay, spaceProfile, spaceFilename,
okName, true);
okName, true, true);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(true));
Assert.assertEquals(
"-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=\"default foobar\",dumponexit=true,name=kossa,filename=\"Kossa Apa/apa.jfr\"",
jfrArgs);
}

@Test
public void testJfrArgsIfQuotedSpacePathsDefaultSettingsJdkHigherThan11() throws Exception {
JfrArgsBuilder options = new JfrArgsBuilder(true, true, okDuration, okDelay, spaceProfile, spaceFilename,
okName, true, false);
String jfrArgs = JfrArgsBuilder.joinToCommandline(options.getJfrArgs(true));
Assert.assertEquals(
"-XX:+FlightRecorder -XX:StartFlightRecording=settings=\"default foobar\",dumponexit=true,name=kossa,filename=\"Kossa Apa/apa.jfr\"",
jfrArgs);
}

/*
* FIXME: Add test for not destroying original arguments when disabled.
*
Expand Down

0 comments on commit 1d7397e

Please sign in to comment.