diff options
author | Siva Velusamy <vsiva@google.com> | 2013-02-13 11:18:54 -0800 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2013-02-13 15:31:49 -0800 |
commit | fc5b696e02f1710b4df38faa0fdf4f02e6f0f98f (patch) | |
tree | c1ca0e48083f9a070157e7b0c7a6cbb3c4e194bb | |
parent | 60917212e76892d2cc76105ced65fcc84dadf253 (diff) | |
download | idea-fc5b696e02f1710b4df38faa0fdf4f02e6f0f98f.tar.gz |
logcat: Add support for filtering by package name
Change-Id: Ibd9e8008908d5eef5b06824170842b61157387d9
6 files changed, 126 insertions, 50 deletions
diff --git a/android/src/org/jetbrains/android/logcat/AndroidConfiguredLogFilters.java b/android/src/org/jetbrains/android/logcat/AndroidConfiguredLogFilters.java index 0385ac08d96..72ba905c4c7 100644 --- a/android/src/org/jetbrains/android/logcat/AndroidConfiguredLogFilters.java +++ b/android/src/org/jetbrains/android/logcat/AndroidConfiguredLogFilters.java @@ -93,6 +93,7 @@ public class AndroidConfiguredLogFilters implements PersistentStateComponent<And private String myLogLevel; private String myLogTagPattern; private String myPid; + private String myPackageNamePattern; public String getName() { return myName; @@ -133,5 +134,13 @@ public class AndroidConfiguredLogFilters implements PersistentStateComponent<And public void setPid(String pid) { myPid = pid; } + + public String getPackageNamePattern() { + return myPackageNamePattern; + } + + public void setPackageNamePattern(String packageNamePattern) { + myPackageNamePattern = packageNamePattern; + } } } diff --git a/android/src/org/jetbrains/android/logcat/AndroidLogFilterModel.java b/android/src/org/jetbrains/android/logcat/AndroidLogFilterModel.java index 90103bc1859..c82015f1224 100644 --- a/android/src/org/jetbrains/android/logcat/AndroidLogFilterModel.java +++ b/android/src/org/jetbrains/android/logcat/AndroidLogFilterModel.java @@ -40,6 +40,7 @@ public abstract class AndroidLogFilterModel extends LogFilterModel { private Log.LogLevel myPrevMessageLogLevel; private String myPrevTag; + private String myPrevPkg; private String myPrevPid; private boolean myFullMessageApplicable = false; private boolean myFullMessageApplicableByCustomFilter = false; @@ -130,6 +131,7 @@ public abstract class AndroidLogFilterModel extends LogFilterModel { Log.LogLevel logLevel = null; String tag = null; + String pkg = null; String pid = null; String message = text; @@ -138,6 +140,7 @@ public abstract class AndroidLogFilterModel extends LogFilterModel { LogMessageHeader header = result.getFirst(); logLevel = header.myLogLevel; tag = header.myTag; + pkg = header.myAppPackage; pid = Integer.toString(header.myPid); if (result.getSecond() != null) { message = result.getSecond(); @@ -147,7 +150,9 @@ public abstract class AndroidLogFilterModel extends LogFilterModel { if (tag == null) { tag = myPrevTag; } - + if (pkg == null) { + pkg = myPrevPkg; + } if (pid == null) { pid = myPrevPid; } @@ -155,7 +160,7 @@ public abstract class AndroidLogFilterModel extends LogFilterModel { logLevel = myPrevMessageLogLevel; } - return configuredFilterName.isApplicable(message, tag, pid, logLevel); + return configuredFilterName.isApplicable(message, tag, pkg, pid, logLevel); } public List<? extends LogFilter> getLogFilters() { @@ -218,6 +223,7 @@ public abstract class AndroidLogFilterModel extends LogFilterModel { public void processingStarted() { myPrevMessageLogLevel = null; myPrevTag = null; + myPrevPkg = null; myPrevPid = null; myFullMessageApplicable = false; myFullMessageApplicableByCustomFilter = false; @@ -239,6 +245,10 @@ public abstract class AndroidLogFilterModel extends LogFilterModel { myPrevTag = header.myTag; } + if (!header.myAppPackage.isEmpty()) { + myPrevPkg = header.myAppPackage; + } + if (header.myPid != 0) { myPrevPid = Integer.toString(header.myPid); } diff --git a/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java b/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java index 5ef2ea30613..42ff709acdb 100644 --- a/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java +++ b/android/src/org/jetbrains/android/logcat/AndroidLogcatView.java @@ -36,6 +36,7 @@ import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.CollectionListModel; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.ListCellRendererWrapper; @@ -340,28 +341,10 @@ public abstract class AndroidLogcatView implements Disposable { return null; } - Pattern logMessagePattern = null; - final String logMessagePatternStr = entry.getLogMessagePattern(); - if (logMessagePatternStr != null && logMessagePatternStr.length() > 0) { - try { - logMessagePattern = Pattern.compile(logMessagePatternStr, AndroidConfiguredLogFilters.getPatternCompileFlags(logMessagePatternStr)); - } - catch (PatternSyntaxException e) { - LOG.info(e); - } - } + Pattern logMessagePattern = compilePattern(entry.getLogMessagePattern()); + Pattern logTagPattern = compilePattern(entry.getLogTagPattern()); + Pattern pkgNamePattern = compilePattern(entry.getPackageNamePattern()); - Pattern logTagPattern = null; - final String logTagPatternStr = entry.getLogTagPattern(); - if (logTagPatternStr != null && logTagPatternStr.length() > 0) { - try { - logTagPattern = Pattern.compile(logTagPatternStr, AndroidConfiguredLogFilters.getPatternCompileFlags(logTagPatternStr)); - } - catch (PatternSyntaxException e) { - LOG.info(e); - } - } - final String pid = entry.getPid(); Log.LogLevel logLevel = null; @@ -370,7 +353,22 @@ public abstract class AndroidLogcatView implements Disposable { logLevel = Log.LogLevel.getByString(logLevelStr); } - return new ConfiguredFilter(name, logMessagePattern, logTagPattern, pid, logLevel); + return new ConfiguredFilter(name, logMessagePattern, logTagPattern, pkgNamePattern, + pid, logLevel); + } + + private static Pattern compilePattern(String pattern) { + Pattern p = null; + if (StringUtil.isNotEmpty(pattern)) { + try { + p = Pattern.compile(pattern, AndroidConfiguredLogFilters.getPatternCompileFlags(pattern)); + } + catch (PatternSyntaxException e) { + LOG.info(e); + } + } + + return p; } public void activate() { diff --git a/android/src/org/jetbrains/android/logcat/ConfiguredFilter.java b/android/src/org/jetbrains/android/logcat/ConfiguredFilter.java index 985d05c01b7..77eeded8c06 100644 --- a/android/src/org/jetbrains/android/logcat/ConfiguredFilter.java +++ b/android/src/org/jetbrains/android/logcat/ConfiguredFilter.java @@ -13,22 +13,26 @@ class ConfiguredFilter { private final String myName; private final Pattern myMessagePattern; private final Pattern myTagPattern; + private final Pattern myPkgNamePattern; private final String myPid; private final Log.LogLevel myLogLevel; public ConfiguredFilter(@NotNull String name, @Nullable Pattern messagePattern, @Nullable Pattern tagPattern, + @Nullable Pattern pkgNamePattern, @Nullable String pid, @Nullable Log.LogLevel logLevel) { myName = name; myMessagePattern = messagePattern; myTagPattern = tagPattern; + myPkgNamePattern = pkgNamePattern; myPid = pid; myLogLevel = logLevel; } - public boolean isApplicable(String message, String tag, String pid, Log.LogLevel logLevel) { + public boolean isApplicable(String message, String tag, String pkg, + String pid, Log.LogLevel logLevel) { if (myMessagePattern != null && (message == null || !myMessagePattern.matcher(message).find())) { return false; } @@ -37,6 +41,10 @@ class ConfiguredFilter { return false; } + if (myPkgNamePattern != null && (pkg == null || !myPkgNamePattern.matcher(pkg).find())) { + return false; + } + if (myPid != null && myPid.length() > 0 && !myPid.equals(pid)) { return false; } diff --git a/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.form b/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.form index 7a2aff18759..6f054ef739c 100644 --- a/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.form +++ b/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.form @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.android.logcat.EditLogFilterDialog"> - <grid id="27dc6" binding="myContentPanel" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="27dc6" binding="myContentPanel" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> <xy x="20" y="20" width="439" height="242"/> @@ -19,7 +19,7 @@ </component> <vspacer id="375d8"> <constraints> - <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> + <grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> </constraints> </vspacer> <component id="98dc3" class="com.intellij.ui.components.JBLabel" binding="myLogTagLabel"> @@ -41,7 +41,7 @@ </component> <component id="e7fb3" class="javax.swing.JLabel"> <constraints> - <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> </constraints> <properties> <text resource-bundle="messages/AndroidBundle" key="android.logcat.new.filter.dialog.pid.label"/> @@ -49,7 +49,7 @@ </component> <component id="3f59d" class="javax.swing.JLabel"> <constraints> - <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> </constraints> <properties> <labelFor value="79468"/> @@ -74,7 +74,7 @@ </component> <component id="79468" class="javax.swing.JComboBox" binding="myLogLevelCombo"> <constraints> - <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> + <grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> </constraints> <properties/> </component> @@ -96,6 +96,22 @@ </grid> <grid id="67e6" binding="myPidFieldWrapper" layout-manager="BorderLayout" hgap="0" vgap="0"> <constraints> + <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + </constraints> + <properties/> + <border type="none"/> + <children/> + </grid> + <component id="7d3c3" class="com.intellij.ui.components.JBLabel"> + <constraints> + <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text value="by P&ackage Name:"/> + </properties> + </component> + <grid id="cf3ae" binding="myPackageNameFieldWrapper" layout-manager="BorderLayout" hgap="0" vgap="0"> + <constraints> <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> </constraints> <properties/> diff --git a/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.java b/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.java index 64b06bc216d..7befdc466de 100644 --- a/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.java +++ b/android/src/org/jetbrains/android/logcat/EditLogFilterDialog.java @@ -53,6 +53,8 @@ class EditLogFilterDialog extends DialogWrapper { private JPanel myTagFieldWrapper; private JPanel myPidFieldWrapper; private JBLabel myLogTagLabel; + private final TextFieldWithAutoCompletion<String> myPackageNameField; + private JPanel myPackageNameFieldWrapper; private final AndroidConfiguredLogFilters.MyFilterEntry myEntry; private final AndroidLogcatView myView; @@ -61,6 +63,7 @@ class EditLogFilterDialog extends DialogWrapper { private String[] myUsedTags; private String[] myUsedPids; + private String[] myUsedPackageNames; protected EditLogFilterDialog(@NotNull final AndroidLogcatView view, @Nullable AndroidConfiguredLogFilters.MyFilterEntry entry) { @@ -101,6 +104,19 @@ class EditLogFilterDialog extends DialogWrapper { }, true, null); myPidFieldWrapper.add(myPidField); + myPackageNameField = new TextFieldWithAutoCompletion<String>( + project, new TextFieldWithAutoCompletion.StringsCompletionProvider(null, null) { + @NotNull + @Override + public Collection<String> getItems(String prefix, boolean cached, + CompletionParameters parameters) { + parseExistingMessagesIfNecessary(); + setItems(Arrays.asList(myUsedPackageNames)); + return super.getItems(prefix, cached, parameters); + } + }, true, null); + myPackageNameFieldWrapper.add(myPackageNameField); + myLogLevelCombo.setModel(new EnumComboBoxModel<Log.LogLevel>(Log.LogLevel.class)); myLogLevelCombo.setRenderer(new ListCellRendererWrapper() { @Override @@ -135,6 +151,7 @@ class EditLogFilterDialog extends DialogWrapper { final Set<String> tagSet = new HashSet<String>(); final Set<String> pidSet = new HashSet<String>(); + final Set<String> pkgSet = new HashSet<String>(); final String[] lines = StringUtil.splitByLines(document.toString()); for (String line : lines) { @@ -144,15 +161,21 @@ class EditLogFilterDialog extends DialogWrapper { } final String tag = result.getFirst().myTag; - if (tag != null && tag.length() > 0) { + if (StringUtil.isNotEmpty(tag)) { tagSet.add(tag); } + final String pkg = result.getFirst().myAppPackage; + if (StringUtil.isNotEmpty(pkg)) { + pkgSet.add(pkg); + } + pidSet.add(Integer.toString(result.getFirst().myPid)); } myUsedTags = tagSet.toArray(new String[tagSet.size()]); myUsedPids = pidSet.toArray(new String[pidSet.size()]); + myUsedPackageNames = pkgSet.toArray(new String[pkgSet.size()]); } private void reset() { @@ -160,6 +183,7 @@ class EditLogFilterDialog extends DialogWrapper { myTagField.setText(myEntry.getLogTagPattern()); myMessageField.setText(myEntry.getLogMessagePattern()); myPidField.setText(myEntry.getPid()); + myPackageNameField.setText(myEntry.getPackageNamePattern()); final String logLevelStr = myEntry.getLogLevel(); final Log.LogLevel logLevel = Log.LogLevel.getByString(logLevelStr); @@ -172,6 +196,7 @@ class EditLogFilterDialog extends DialogWrapper { myEntry.setLogMessagePattern(myMessageField.getText().trim()); myEntry.setPid(myPidField.getText().trim()); myEntry.setLogLevel(((Log.LogLevel)myLogLevelCombo.getSelectedItem()).getStringValue()); + myEntry.setPackageNamePattern(myPackageNameField.getText().trim()); } @Override @@ -208,28 +233,25 @@ class EditLogFilterDialog extends DialogWrapper { return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.name.busy.error", name)); } - try { - final String tagPattern = myTagField.getText().trim(); - if (tagPattern.length() > 0) { - Pattern.compile(tagPattern, AndroidConfiguredLogFilters.getPatternCompileFlags(tagPattern)); - } - } - catch (PatternSyntaxException e) { - final String message = e.getMessage(); - return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.log.tag.pattern.error") + - (message != null ? ('\n' + message) : "")); + ValidationInfo info = validatePattern( + myTagField.getText().trim(), + AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.log.tag.pattern.error")); + if (info != null) { + return info; } - try { - final String messagePattern = myMessageField.getText().trim(); - if (messagePattern.length() > 0) { - Pattern.compile(messagePattern, AndroidConfiguredLogFilters.getPatternCompileFlags(messagePattern)); - } + info = validatePattern( + myMessageField.getText().trim(), + AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.message.pattern.error")); + if (info != null) { + return info; } - catch (PatternSyntaxException e) { - final String message = e.getMessage(); - return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.message.pattern.error") + - (message != null ? ('\n' + message) : "")); + + info = validatePattern( + myPackageNameField.getText().trim(), + AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.application.name.pattern.error")); + if (info != null) { + return info; } boolean validPid = false; @@ -250,6 +272,19 @@ class EditLogFilterDialog extends DialogWrapper { return null; } + private static ValidationInfo validatePattern(String pattern, String errorMessage) { + try { + if (!pattern.isEmpty()) { + Pattern.compile(pattern, AndroidConfiguredLogFilters.getPatternCompileFlags(pattern)); + } + return null; + } + catch (PatternSyntaxException e) { + String message = e.getMessage(); + return new ValidationInfo(errorMessage + (message != null ? ('\n' + message) : "")); + } + } + @NotNull public AndroidConfiguredLogFilters.MyFilterEntry getCustomLogFiltersEntry() { return myEntry; |