Skip to content

Commit

Permalink
Merge branch 'master' into 273_Support_for_SSH_agent
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
svennissel committed Apr 5, 2022
2 parents 6a5146c + e9067ff commit 40b6642
Show file tree
Hide file tree
Showing 21 changed files with 369 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import pl.otros.logview.api.services.Services;
import pl.otros.logview.api.theme.Theme;
import pl.otros.logview.api.theme.ThemeConfig;
import pl.otros.vfs.browser.JOtrosVfsBrowserDialog;
import pl.otros.logview.gui.open.LogVfsBrowserDialog;

import javax.swing.*;
import java.awt.*;
Expand All @@ -48,7 +48,7 @@ public class OtrosApplication {
private JTextField searchField;
private MarkerColors selectedMarkColors;
private JMenu pluginsMenu;
private JOtrosVfsBrowserDialog otrosVfsBrowserDialog;
private LogVfsBrowserDialog otrosVfsBrowserDialog;
private AppProperties appProperties;
private final List<MenuActionProvider> menuActionProviders;
private LogLoader logLoader;
Expand All @@ -71,11 +71,11 @@ public JTabbedPane getjTabbedPane() {
return jTabbedPane;
}

public JOtrosVfsBrowserDialog getOtrosVfsBrowserDialog() {
public LogVfsBrowserDialog getOtrosVfsBrowserDialog() {
return otrosVfsBrowserDialog;
}

public void setOtrosVfsBrowserDialog(JOtrosVfsBrowserDialog otrosVfsBrowserDialog) {
public void setOtrosVfsBrowserDialog(LogVfsBrowserDialog otrosVfsBrowserDialog) {
this.otrosVfsBrowserDialog = otrosVfsBrowserDialog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
******************************************************************************/
package pl.otros.logview.api.io;

import static org.apache.commons.io.IOUtils.copy;
import static org.apache.commons.vfs2.util.RandomAccessMode.READ;
import static pl.otros.logview.api.io.Utils.closeQuietly;
import static pl.otros.logview.gui.session.OpenMode.FROM_START;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.RandomAccessContent;
import pl.otros.logview.gui.session.OpenMode;

import java.io.ByteArrayInputStream;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.zip.GZIPInputStream;

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.RandomAccessContent;

import pl.otros.logview.gui.session.OpenMode;
import static org.apache.commons.vfs2.util.RandomAccessMode.READ;
import static pl.otros.logview.api.io.Utils.closeQuietly;
import static pl.otros.logview.gui.session.OpenMode.FROM_START;

public final class LoadingInfo implements AutoCloseable {

Expand All @@ -57,15 +54,17 @@ public LoadingInfo(FileObject fileObject, boolean tailing, OpenMode openMode) th
friendlyUrl = fileObject.getName().getFriendlyURI();

fileObject.refresh();
InputStream inputStream = fileObject.getContent().getInputStream();
byte[] probe = loadProbe(inputStream, 10000);
gzipped = checkIfIsGzipped(probe, probe.length);
inputStreamBufferedStart = gzipped ? ungzip(probe) : probe;
InputStream inputStream = new BufferedInputStream(fileObject.getContent().getInputStream(), 2);
//maximum limit of reset(). Only read 2 bytes
inputStream.mark(2);
gzipped = checkIfIsGzipped(inputStream);
inputStream.reset();

inputStreamBufferedStart = gzipped ? ungzip(inputStream, 10_000) : loadProbe(inputStream, 10_000);

if (openMode == FROM_START || gzipped) {
PushbackInputStream pushBackInputStream = new PushbackInputStream(inputStream, probe.length + 1); // +1 to support empty files
pushBackInputStream.unread(probe);
observableInputStreamImpl = new ObservableInputStreamImpl(pushBackInputStream);
fileObject.refresh();//Reload file
observableInputStreamImpl = new ObservableInputStreamImpl(fileObject.getContent().getInputStream());
contentInputStream = gzipped ? new GZIPInputStream(observableInputStreamImpl) : observableInputStreamImpl;
} else {
RandomAccessContent randomAccessContent = fileObject.getContent().getRandomAccessContent(READ);
Expand Down Expand Up @@ -155,22 +154,33 @@ private static byte[] loadProbe(InputStream in, int buffSize) throws IOException
return bout.toByteArray();
}

private static boolean checkIfIsGzipped(byte[] buffer, int lenght) throws IOException {
boolean gziped;
/**
* Check the first two bytes of a InputStream. If the bytes equals {@link GZIPInputStream#GZIP_MAGIC} the file is
* compressed by gzip
*/
private static boolean checkIfIsGzipped(InputStream inputStream) {
byte[] header = new byte[2];
try {
ByteArrayInputStream bin = new ByteArrayInputStream(buffer, 0, lenght);
GZIPInputStream gzipInputStream = new GZIPInputStream(bin);
gzipInputStream.read(new byte[buffer.length], 0, bin.available());
gziped = true;
int length = inputStream.read(header);
return length == 2
&& (header[0] == (byte) (GZIPInputStream.GZIP_MAGIC))
&& (header[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8));
} catch (IOException e) {
gziped = false;
return false;
}
return gziped;

}

private static byte[] ungzip(byte[] buff) throws IOException {
try (InputStream in = new GZIPInputStream(new ByteArrayInputStream(buff)); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
copy(in, out);
/**
* Unzip only the number of bytes set in size parameter
*/
private static byte[] ungzip(InputStream inputStream, int size) throws IOException {
try (GZIPInputStream in = new GZIPInputStream(inputStream, size); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] buffer = new byte[size];
int len;
if ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
return out.toByteArray();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void initGui() {
bagConstraints.fill = GridBagConstraints.HORIZONTAL;
bagConstraints.gridy++;

final Action tailAction = new TailLogWithAutoDetectActionListener(otrosApplication);
final Action tailAction = new TailLogWithComboActionListener(otrosApplication);
final JButton tailButton = new JButton(tailAction);
tailButton.setName("Open log files");
OtrosSwingUtils.fontSize2(tailButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import pl.otros.logview.gui.message.SearchResultColorizer;
import pl.otros.logview.gui.message.SoapMessageFormatter;
import pl.otros.logview.gui.message.update.MessageUpdateUtils;
import pl.otros.logview.gui.open.LogVfsBrowserDialog;
import pl.otros.logview.gui.renderers.MarkerColorsComboBoxRenderer;
import pl.otros.logview.gui.services.jumptocode.ServicesImpl;
import pl.otros.logview.gui.suggestion.PersistedSuggestionSource;
Expand All @@ -77,7 +78,6 @@
import pl.otros.swing.rulerbar.OtrosJTextWithRulerScrollPane;
import pl.otros.swing.rulerbar.RulerBarHelper;
import pl.otros.swing.suggest.SuggestDecorator;
import pl.otros.vfs.browser.JOtrosVfsBrowserDialog;

import javax.imageio.ImageIO;
import javax.swing.*;
Expand All @@ -89,7 +89,10 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

Expand Down Expand Up @@ -178,7 +181,7 @@ public LogViewMainFrame(DataConfiguration c) {
otrosApplication.setjTabbedPane(logsTabbedPane);
otrosApplication.setStatusObserver(observer);
final LogParsableListener logParsableListener = new LogParsableListener(otrosApplication.getAllPluginables().getLogImportersContainer());
otrosApplication.setOtrosVfsBrowserDialog(new JOtrosVfsBrowserDialog(getVfsFavoritesConfiguration(), logParsableListener));
otrosApplication.setOtrosVfsBrowserDialog(new LogVfsBrowserDialog(logParsableListener, getVfsFavoritesConfiguration()));
otrosApplication.setServices(new ServicesImpl(otrosApplication));
otrosApplication.setLogLoader(new BasicLogLoader(otrosApplication.getServices().getStatsService()));
if (!runningForTests()) {
Expand Down Expand Up @@ -682,7 +685,7 @@ private void initMenu() {
Font menuGroupFont = labelOpenLog.getFont().deriveFont(13f).deriveFont(Font.BOLD);
labelOpenLog.setFont(menuGroupFont);
fileMenu.add(labelOpenLog);
fileMenu.add(new JMenuItem(new TailLogWithAutoDetectActionListener(otrosApplication)));
fileMenu.add(new JMenuItem(new TailLogWithComboActionListener(otrosApplication)));
fileMenu.add(new JMenuItem(new AdvanceOpenAction(otrosApplication)));
fileMenu.add(new JSeparator());
JLabel labelLogInvestigation = new JLabel("Log investigation", SwingConstants.LEFT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.logging.Level;

public class LogViewPanel extends LogViewPanelI {

private static final Logger LOGGER = LoggerFactory.getLogger(LogViewPanel.class.getName());
public static final int CHECK_BOX_WIDTH = (int) Math.ceil(new JCheckBox().getPreferredSize().getWidth());
public static final int LEVEL_ICON_WIDTH = 16;
private final OtrosJTextWithRulerScrollPane<JTextPane> logDetailWithRulerScrollPane;
private final MessageDetailListener messageDetailListener;
private final Font menuLabelFont;
Expand Down Expand Up @@ -347,28 +349,43 @@ private void updateColumnsSize() {
updateLevelColumnSize();
updateColumnSizeIfVisible(TableColumns.CLASS, 100, 500);
updateColumnSizeIfVisible(TableColumns.THREAD, 100, 300);
updateColumnSizeIfVisible(TableColumns.METHOD, 100, 200);
updateColumnSizeIfVisible(TableColumns.METHOD, 100, 400);
updateColumnSizeIfVisible(TableColumns.LINE, fm.stringWidth("0000"), fm.stringWidth("000000"));
updateColumnSizeIfVisible(TableColumns.MARK, 16, 16);
updateMarkColumnSize();
updateColumnSizeIfVisible(TableColumns.NOTE, 100, 1500);
}


private void updateTimeColumnSize() {
FontMetrics fm = table.getFontMetrics(table.getFont());
int dateWidth = fm.stringWidth(new SimpleDateFormat(configuration.getString(ConfKeys.LOG_TABLE_FORMAT_DATE_FORMAT, "HH:mm:ss.SSS")).format(new Date()));
//The time column is bold and bold fond is wider
String dateExample = new SimpleDateFormat(configuration.getString(ConfKeys.LOG_TABLE_FORMAT_DATE_FORMAT, "HH:mm:ss.SSS")).format(new Date());
int dateWidth = calculateTextWidth(dateExample, table);
updateColumnSizeIfVisible(TableColumns.TIME, dateWidth + 1, dateWidth + 1);
}

private void updateMarkColumnSize() {
String tableHeader = TableColumns.MARK.getName() + " ";//Space before and after will be rendered
int headerWidth = calculateTextWidth(tableHeader, table);
int maxHeaderOrContentWidth = Math.max(headerWidth, CHECK_BOX_WIDTH);
updateColumnSizeIfVisible(TableColumns.MARK, maxHeaderOrContentWidth + 1, maxHeaderOrContentWidth + 1);
}

/**
* Set column size depending on configured display text/icon.
* If the header is wider than contend, the width of header will be used.
*/
private void updateLevelColumnSize() {
FontMetrics fm = table.getFontMetrics(table.getFont());
int levelWidth = fm.stringWidth(Level.WARNING.getName());
int levelWidth = calculateTextWidth(Level.WARNING.getName(), table);
String tableHeader = TableColumns.LEVEL.getName() + " ";//Space before and after will be rendered
int headerWidth = calculateTextWidth(tableHeader, table);
int maxIconOrHeaderWidth = Math.max(headerWidth, LEVEL_ICON_WIDTH);

switch (configuration.get(LevelRenderer.Mode.class, ConfKeys.LOG_TABLE_FORMAT_LEVEL_RENDERER, LevelRenderer.Mode.IconsOnly)) {
case IconsOnly:
updateColumnSizeIfVisible(TableColumns.LEVEL, 16 + 1, 16 + 1);
updateColumnSizeIfVisible(TableColumns.LEVEL, maxIconOrHeaderWidth + 1, maxIconOrHeaderWidth + 1);
break;
case IconsAndText:
updateColumnSizeIfVisible(TableColumns.LEVEL, 16 + levelWidth + 5, 16 + levelWidth + 5);
updateColumnSizeIfVisible(TableColumns.LEVEL, maxIconOrHeaderWidth + levelWidth + 5, maxIconOrHeaderWidth + levelWidth + 5);
break;
case TextOnly:
default:
Expand All @@ -382,6 +399,11 @@ private void updateColumnSizeIfVisible(TableColumns column, int width, int maxWi
table.getColumns(true).get(column.getColumn()).setPreferredWidth(width);
}

private int calculateTextWidth(String text, JComponent component) {
FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
return fontMetrics.stringWidth(text);
}

@Override
public JTextPane getLogDetailTextArea() {
return logDetailTextArea;
Expand Down Expand Up @@ -609,7 +631,7 @@ private void addMarkerToMenu(JMenu menu, AutomaticMarker automaticMarker, HashMa
for (String g : groups) {
JMenuItem markerMenuItem = new JMenuItem(automaticMarker.getName());

Icon icon = new ColorIcon(automaticMarker.getColors().getBackground(), automaticMarker.getColors().getForeground(), 16, 16,"Ab");
Icon icon = new ColorIcon(automaticMarker.getColors().getBackground(), automaticMarker.getColors().getForeground(), 16, 16, "Ab");
markerMenuItem.setIcon(icon);
markerMenuItem.setToolTipText(automaticMarker.getDescription());
markerMenuItem.addActionListener(new AutomaticMarkUnamrkActionListener(dataTableModel, automaticMarker, mode, statusObserver));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static void setDefaultSize(int size) {
.forEach(key -> {
Font font = UIManager.getDefaults().getFont(key);
if (font != null) {
font = font.deriveFont((float) size);
//the defaults are bold, but plain needed.
font = font.deriveFont((float) size).deriveFont(Font.PLAIN);
UIManager.put(key, font);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import pl.otros.logview.api.loading.LogLoadingSession;
import pl.otros.logview.api.loading.VfsSource;
import pl.otros.logview.api.parser.ParsingContext;
import pl.otros.logview.gui.open.LogVfsBrowserDialog;
import pl.otros.logview.importer.DetectOnTheFlyLogImporter;
import pl.otros.vfs.browser.JOtrosVfsBrowserDialog;
import pl.otros.vfs.browser.SelectionMode;

Expand All @@ -58,7 +60,7 @@ public TailLogActionListener(OtrosApplication otrosApplication, LogImporter impo

@Override
protected void actionPerformedHook(ActionEvent e) {
JOtrosVfsBrowserDialog chooser = getOtrosApplication().getOtrosVfsBrowserDialog();
LogVfsBrowserDialog chooser = getOtrosApplication().getOtrosVfsBrowserDialog();
initFileChooser(chooser);

JOtrosVfsBrowserDialog.ReturnValue result = chooser.showOpenDialog((Component) e.getSource(), "Tail " + importer.getName() + " log");
Expand All @@ -67,11 +69,22 @@ protected void actionPerformedHook(ActionEvent e) {
}
final FileObject[] files = chooser.getSelectedFiles();
for (FileObject file : files) {
openFileObjectInTailMode(file, Utils.getFileObjectShortName(file));
List<LogImporter> parsableLogImporters = chooser.getParsableLogImporters();
LogImporter logImporter;
if (parsableLogImporters.isEmpty()) {
logImporter = importer;
} else {
logImporter = new DetectOnTheFlyLogImporter(parsableLogImporters);
}
openFileObjectInTailMode(file, Utils.getFileObjectShortName(file), logImporter);
}
}

public void openFileObjectInTailMode(final FileObject file, String tabName) {
openFileObjectInTailMode(file, tabName, importer);
}

public void openFileObjectInTailMode(final FileObject file, String tabName, LogImporter logImporter) {
final LoadingInfo loadingInfo;
try {
loadingInfo = new LoadingInfo(file, true);
Expand All @@ -82,7 +95,7 @@ public void openFileObjectInTailMode(final FileObject file, String tabName) {
return;
}

TableColumns[] tableColumnsToUse = determineTableColumnsToUse(loadingInfo, importer);
TableColumns[] tableColumnsToUse = determineTableColumnsToUse(loadingInfo, logImporter);

final LogViewPanelWrapper panel = new LogViewPanelWrapper(file.getName().getBaseName(), loadingInfo.getObservableInputStreamImpl(),
tableColumnsToUse, getOtrosApplication());
Expand All @@ -92,7 +105,6 @@ public void openFileObjectInTailMode(final FileObject file, String tabName) {

final LogLoader logLoader = getOtrosApplication().getLogLoader();
final VfsSource source = new VfsSource(file);
final LogImporter logImporter = this.importer;
final LogLoadingSession session = logLoader.startLoading(
source,
logImporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,23 @@

public class TailLogWithAutoDetectActionListener extends TailLogActionListener {

// private final

public TailLogWithAutoDetectActionListener(OtrosApplication otrosApplication) {
super(otrosApplication, new DetectOnTheFlyLogImporter(otrosApplication.getAllPluginables().getLogImportersContainer().getElements()));
}

@Override
protected TableColumns[] determineTableColumnsToUse(LoadingInfo loadingInfo, LogImporter importer) {
Collection<LogImporter> logImporters = getOtrosApplication().getAllPluginables().getLogImportersContainer().getElements();
byte[] inputStreamBufferedStart = loadingInfo.getInputStreamBufferedStart();
Optional<LogImporter> detectLogImporter = Utils.detectLogImporter(logImporters, inputStreamBufferedStart);
TableColumns[] determineTableColumnsToUse = super.determineTableColumnsToUse(loadingInfo, importer);
if (detectLogImporter.isPresent()) {
determineTableColumnsToUse = super.determineTableColumnsToUse(loadingInfo, detectLogImporter.get());

if(importer instanceof DetectOnTheFlyLogImporter) {
Collection<LogImporter> logImporters = ((DetectOnTheFlyLogImporter) importer).getLogImporters();
Optional<LogImporter> detectLogImporter = Utils.detectLogImporter(logImporters, inputStreamBufferedStart);
if (detectLogImporter.isPresent()) {
return super.determineTableColumnsToUse(loadingInfo, detectLogImporter.get());
}
}
return determineTableColumnsToUse;

return super.determineTableColumnsToUse(loadingInfo, importer);
}

}
Loading

0 comments on commit 40b6642

Please sign in to comment.