Skip to content

Commit cfd3860

Browse files
jpbempelthegreystone
authored andcommitted
5603: Version specific help links in event type missing result
Reviewed-by: hirt
1 parent 371aa9a commit cfd3860

File tree

3 files changed

+144
-114
lines changed
  • core
    • org.openjdk.jmc.flightrecorder.rules/src/main
    • tests/org.openjdk.jmc.flightrecorder.rules.jdk.test/src/test/resources/baseline

3 files changed

+144
-114
lines changed

core/org.openjdk.jmc.flightrecorder.rules/src/main/java/org/openjdk/jmc/flightrecorder/rules/util/RulesToolkit.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,22 +533,28 @@ private static boolean hasEvents(IItemCollection items, String ... typeIds) {
533533
*/
534534
public static Result getEventAvailabilityResult(
535535
IRule rule, IItemCollection items, EventAvailability eventAvailability, String ... typeIds) {
536+
JavaVersion javaVersion;
537+
String link;
536538
switch (eventAvailability) {
537539
case ENABLED:
538540
case NONE:
539541
String requiredEventsTypeNames = getEventTypeNames(items, typeIds);
542+
javaVersion = RulesToolkit.getJavaSpecVersion(items);
543+
link = RulesToolkit.getJavaCommandHelpLink(javaVersion);
540544
return getNotApplicableResult(rule,
541545
MessageFormat.format(Messages.getString(Messages.RulesToolkit_RULE_REQUIRES_EVENTS),
542546
requiredEventsTypeNames),
543547
MessageFormat.format(Messages.getString(Messages.RulesToolkit_RULE_REQUIRES_EVENTS_LONG),
544-
rule.getName(), requiredEventsTypeNames));
548+
rule.getName(), requiredEventsTypeNames, link));
545549
case DISABLED:
546550
String disabledEventTypeNames = getDisabledEventTypeNames(items, typeIds);
551+
javaVersion = RulesToolkit.getJavaSpecVersion(items);
552+
link = RulesToolkit.getJavaCommandHelpLink(javaVersion);
547553
return getNotApplicableResult(rule,
548554
MessageFormat.format(Messages.getString(Messages.RulesToolkit_RULE_REQUIRES_EVENT_TYPE),
549555
disabledEventTypeNames),
550556
MessageFormat.format(Messages.getString(Messages.RulesToolkit_RULE_REQUIRES_EVENT_TYPE_LONG),
551-
rule.getName(), disabledEventTypeNames));
557+
rule.getName(), disabledEventTypeNames, link));
552558
case UNKNOWN:
553559
// Can't get type names if the event type is unavailable
554560
List<String> quotedTypeIds = new ArrayList<>();
@@ -565,12 +571,14 @@ public static Result getEventAvailabilityResult(
565571
rule.getName(), unavailableTypeNames));
566572
case AVAILABLE:
567573
String availableEventTypeNames = getEventTypeNames(items, typeIds);
574+
javaVersion = RulesToolkit.getJavaSpecVersion(items);
575+
link = RulesToolkit.getJavaCommandHelpLink(javaVersion);
568576
return getNotApplicableResult(rule,
569577
MessageFormat.format(
570578
Messages.getString(Messages.RulesToolkit_RULE_REQUIRES_EVENT_TYPE_NOT_AVAILABLE),
571579
availableEventTypeNames),
572580
MessageFormat.format(Messages.RulesToolkit_RULE_REQUIRES_EVENT_TYPE_NOT_AVAILABLE_LONG,
573-
rule.getName(), availableEventTypeNames));
581+
rule.getName(), availableEventTypeNames, link));
574582
default:
575583
throw new IllegalArgumentException("Unsupported event availability: " + eventAvailability); //$NON-NLS-1$
576584
}
@@ -1008,6 +1016,29 @@ public static JavaVersion getJavaVersion(String vmInfoVersionString) {
10081016
return null;
10091017
}
10101018

1019+
static String getJavaCommandHelpLink(JavaVersion javaVersion) {
1020+
if (javaVersion != null) {
1021+
int major = javaVersion.getMajorVersion();
1022+
switch (major) {
1023+
case 8:
1024+
return "https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html"; //$NON-NLS-1$
1025+
case 9:
1026+
case 10:
1027+
return "https://docs.oracle.com/javase/" + major + "/tools/java.htm#JSWOR624";
1028+
case 11:
1029+
case 12:
1030+
return "https://docs.oracle.com/en/java/javase/" + major
1031+
+ "/tools/java.html#GUID-3B1CE181-CD30-4178-9602-230B800D4FAE";
1032+
case 13:
1033+
case 14:
1034+
case 15:
1035+
return "https://docs.oracle.com/en/java/javase/" + major + "/docs/specs/man/java.html";
1036+
}
1037+
}
1038+
// by default use version 8
1039+
return "https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html"; //$NON-NLS-1$
1040+
}
1041+
10111042
/**
10121043
* Gets the {@link IType} representation of a specific event type in an {@link IItemCollection}.
10131044
*

core/org.openjdk.jmc.flightrecorder.rules/src/main/resources/org/openjdk/jmc/flightrecorder/rules/messages/internal/messages.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ RulesToolkit_RULE_REQUIRES_UNAVAILABLE_EVENT_TYPE=The {0} rule requires the foll
4141
RulesToolkit_RULE_REQUIRES_UNAVAILABLE_EVENT_TYPE_LONG=The {0} rule requires the following event types: {1}.<p>They are either not available in this version of Java, or must be enabled in a third-party component. If you are using an older Java version, then you can consider upgrading.
4242
# {0} is an event type name
4343
RulesToolkit_RULE_REQUIRES_EVENT_TYPE_NOT_AVAILABLE=This rule requires that there are no events from the following types: {0}.
44-
# {0} is a rule name, {1} is one or more event type names
45-
RulesToolkit_RULE_REQUIRES_EVENT_TYPE_NOT_AVAILABLE_LONG=The {0} rule requires that there are no events from the following types: {1}.<p>Please disable the event types for this rule to work. If you are using JMC to create a flight recording, then you can disable event types in the Start Flight Recording wizard. If you are starting the flight recording from the command line, then you can use the settings parameter of <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html">-XX:FlightRecorderOptions</a>.
44+
# {0} is a rule name, {1} is one or more event type names, {2} is a link to java command help
45+
RulesToolkit_RULE_REQUIRES_EVENT_TYPE_NOT_AVAILABLE_LONG=The {0} rule requires that there are no events from the following types: {1}.<p>Please disable the event types for this rule to work. If you are using JMC to create a flight recording, then you can disable event types in the Start Flight Recording wizard. If you are starting the flight recording from the command line, then you can use the settings parameter of <a href="{2}">-XX:FlightRecorderOptions</a>.
4646
# {0} is an event type name
4747
RulesToolkit_RULE_REQUIRES_EVENTS=This rule requires events to be available from the following event types: {0}.
48-
# {0} is a rule name, {1} is one or more event type names
49-
RulesToolkit_RULE_REQUIRES_EVENTS_LONG=The {0} rule requires events to be available from the following event types: {1}.<p>They were either disabled during the recording or there might not have happened anything to trigger an event. Event settings like period and threshold may also prevent some events from being emitted. If you are using JMC to create a flight recording, then you can enable and configure event types in the Start Flight Recording wizard. If you are starting the flight recording from the command line, then you can use the settings parameter of <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html">-XX:FlightRecorderOptions</a>.
48+
# {0} is a rule name, {1} is one or more event type names, {2} is a link to java command help
49+
RulesToolkit_RULE_REQUIRES_EVENTS_LONG=The {0} rule requires events to be available from the following event types: {1}.<p>They were either disabled during the recording or there might not have happened anything to trigger an event. Event settings like period and threshold may also prevent some events from being emitted. If you are using JMC to create a flight recording, then you can enable and configure event types in the Start Flight Recording wizard. If you are starting the flight recording from the command line, then you can use the settings parameter of <a href="{2}">-XX:FlightRecorderOptions</a>.
5050
# {0} is an event type name
5151
RulesToolkit_RULE_REQUIRES_EVENT_TYPE=This rule requires that the following event types are enabled: {0}.
5252
# {0} is a rule name, {1} is one or more event type names
53-
RulesToolkit_RULE_REQUIRES_EVENT_TYPE_LONG=The {0} rule requires that the following event types are enabled: {1}.<p>If you are using JMC to create a flight recording, then you can enable event types in the Start Flight Recording wizard. If you are starting the flight recording from the command line, then you can use the settings parameter of <a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html">-XX:FlightRecorderOptions</a>.
53+
RulesToolkit_RULE_REQUIRES_EVENT_TYPE_LONG=The {0} rule requires that the following event types are enabled: {1}.<p>If you are using JMC to create a flight recording, then you can enable event types in the Start Flight Recording wizard. If you are starting the flight recording from the command line, then you can use the settings parameter of <a href="{2}">-XX:FlightRecorderOptions</a>.
5454
# {0} is a rule name, {1} is one or more event type names
5555
RulesToolkit_RULE_REQUIRES_SOME_EVENTS=The {0} rule requires events to be available from at least one of the following event types: {1}.
5656
# {0} is one or more event type names

0 commit comments

Comments
 (0)