Skip to content

Commit

Permalink
Bug 582308 Add description information to snapshot history or details
Browse files Browse the repository at this point in the history
Extract first line from notes file.

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=582308
Change-Id: I6eca723821c2e3d595f07fbf4459c14f52986118
  • Loading branch information
ajohnson1 committed Sep 14, 2023
1 parent 9111d16 commit ec54cbe
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2022 SAP AG and IBM Corporation.
* Copyright (c) 2008, 2023 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -593,14 +593,20 @@ public void run()
// notes management
// //////////////////////////////////////////////////////////////

private static String readNotes(File resourcePath)
/**
* Read the contents of the notes file, based on the
* snapshot resource.
* @param resourcePath The editor file (snapshot or index file).
* @return The contents of the notes file, lines separated by \n.
*/
public static String readNotes(File resourcePath)
{
try
{
if (resourcePath != null)
{
File notesFile = getDefaultNotesFile(resourcePath);
if (notesFile.exists())
if (notesFile.canRead())
{
FileInputStream fileInput = new FileInputStream(getDefaultNotesFile(resourcePath));
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 SAP AG and others.
* Copyright (c) 2008, 2023 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -49,6 +49,8 @@ public class Messages extends NLS

public static String jvm_version;

public static String notes;

static
{
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2021 SAP AG, IBM Corporation and others.
* Copyright (c) 2008, 2023 SAP AG, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -9,7 +9,7 @@
*
* Contributors:
* SAP AG - initial API and implementation
* Andrew Johnson/IBM Corporation - com.ibm.icu fixes
* Andrew Johnson/IBM Corporation - com.ibm.icu fixes, notes
*******************************************************************************/
package org.eclipse.mat.ui.snapshot.views;

Expand All @@ -32,6 +32,7 @@
import org.eclipse.mat.snapshot.SnapshotInfo;
import org.eclipse.mat.snapshot.UnreachableObjectsHistogram;
import org.eclipse.mat.ui.accessibility.AccessibleCompositeAdapter;
import org.eclipse.mat.ui.internal.views.NotesView;
import org.eclipse.mat.ui.snapshot.editor.ISnapshotEditorInput;
import org.eclipse.mat.ui.util.Copy;
import org.eclipse.mat.util.MessageUtil;
Expand Down Expand Up @@ -378,6 +379,10 @@ protected void updateSnapshotInput()
Serializable bDiscard_seed = bInfo.getProperty("discard_seed"); //$NON-NLS-1$
category.addChild(new Label(org.eclipse.mat.ui.Messages.UIPreferencePage_DiscardSeed, discard_seed, bDiscard_seed));
}
String note = getNotes(info);
String noteb = getNotes(bInfo);
if (note != null)
category.addChild(new Label(Messages.notes, note, noteb));

category = new Category(Messages.statistic_info);
elements.add(category);
Expand Down Expand Up @@ -421,7 +426,9 @@ else if (getSnapshotPath() != null)

final Double fileLength = Double.valueOf((double) osFile.length() / (1024 * 1024));
category.addChild(new Label(Messages.file_length, fileLength, null));

String note = getNotes(osFile);
if (note != null)
category.addChild(new Label(Messages.notes, note, null));
}

treeViewer.getTree().setRedraw(false);
Expand All @@ -430,6 +437,36 @@ else if (getSnapshotPath() != null)
treeViewer.getTree().setRedraw(true);
}

private String getNotes(SnapshotInfo info)
{
if (info != null)
{
String path = info.getPath();
String pfx = info.getPrefix();
if (path == null)
return null;
// See SnapshotHistoryFile#openFile
if (pfx != null && info.getProperty("$runtimeId") != null) //$NON-NLS-1$
{
return getNotes(new File(pfx + "index")); //$NON-NLS-1$
}
else
{
return getNotes(new File(path));
}
}
return null;
}

private String getNotes(File snapshotFile)
{
String notes = NotesView.readNotes(snapshotFile);
// Just use the first line
if (notes != null)
return notes.split("\n", 2)[0]; //$NON-NLS-1$
return null;
}

private long[] unreachableObjects(SnapshotInfo info)
{
long discardedObjects = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2013, 2018 SAP AG and others.
# Copyright (c) 2013, 2023 SAP AG and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand Down Expand Up @@ -39,4 +39,4 @@ col_file=File

baseline=Baseline
jvm_version=JVM version

notes=Notes

0 comments on commit ec54cbe

Please sign in to comment.