[Jrisk-cvs] SF.net SVN: jrisk-code:[1058] Grasshopper
Brought to you by:
yuranet
|
From: <yu...@us...> - 2024-12-27 20:06:15
|
Revision: 1058
http://sourceforge.net/p/jrisk/code/1058
Author: yuranet
Date: 2024-12-27 20:06:13 +0000 (Fri, 27 Dec 2024)
Log Message:
-----------
truncate the system log, not the other logs
Modified Paths:
--------------
Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java
Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitterMultipart.java
Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java
Added Paths:
-----------
Grasshopper/src/net/yura/grasshopper/util/TruncatedContentBody.java
Modified: Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java 2024-12-27 16:47:27 UTC (rev 1057)
+++ Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java 2024-12-27 20:06:13 UTC (rev 1058)
@@ -261,6 +261,13 @@
List keys = new ArrayList(map.keySet());
Collections.sort(keys, new Comparator() {
public int compare(Object key1, Object key2) {
+ if ("log".equals(key1) && !"log".equals(key2)) {
+ return 1;
+ }
+ if ("log".equals(key2) && !"log".equals(key1)) {
+ return -1;
+ }
+
Object value1 = map.get(key1);
Object value2 = map.get(key2);
if (value1 instanceof LogText && !(value2 instanceof LogText)) {
Modified: Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitterMultipart.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitterMultipart.java 2024-12-27 16:47:27 UTC (rev 1057)
+++ Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitterMultipart.java 2024-12-27 20:06:13 UTC (rev 1058)
@@ -13,10 +13,12 @@
import net.yura.grasshopper.info.LogText;
import net.yura.grasshopper.info.ScreenShot;
import net.yura.grasshopper.util.TailOutputStream;
+import net.yura.grasshopper.util.TruncatedContentBody;
import org.apache.http.entity.mime.MIME;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.AbstractContentBody;
import org.apache.http.entity.mime.content.ByteArrayBody;
+import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.StringBody;
/**
@@ -57,6 +59,8 @@
Object key = it.next();
Object value = map.get(key);
+ ContentBody contentBody;
+
if (value instanceof LogText) {
// can not use this as unknown length fails on Android
// requestContent.addPart(key, new InputStreamBody( new FileInputStream( (File)value ) , null ) );
@@ -67,27 +71,12 @@
final LogText logtext = (LogText)value;
- long sizeSoFar = requestContent.getContentLength();
-
- final long truncate;
- if (sizeSoFar + logtext.getContentLength() > MAX_PAYLOAD_SIZE) {
- truncate = MAX_PAYLOAD_SIZE - sizeSoFar;
- }
- else {
- truncate = -1L;
- }
-
- requestContent.addPart(String.valueOf(key), new AbstractContentBody("text/plain") {
+ contentBody = new AbstractContentBody("text/plain") {
public long getContentLength() {
- return truncate == -1L ? logtext.getContentLength() : truncate;
+ return logtext.getContentLength();
}
public void writeTo(OutputStream out) throws IOException {
- if (truncate == -1L) {
- logtext.writeTo(out);
- }
- else {
- logtext.writeTo(new TailOutputStream(out, logtext.getContentLength() - truncate));
- }
+ logtext.writeTo(out);
}
public String getFilename() {
return null;
@@ -98,11 +87,24 @@
public String getTransferEncoding() {
return MIME.ENC_8BIT;
}
- } );
+ };
}
else {
- requestContent.addPart(String.valueOf(key), new StringBody(String.valueOf(value)));
+ contentBody = new StringBody(String.valueOf(value));
}
+
+ long sizeSoFar = requestContent.getContentLength();
+
+ if (sizeSoFar + contentBody.getContentLength() > MAX_PAYLOAD_SIZE) {
+ long spaceAvailable = MAX_PAYLOAD_SIZE - sizeSoFar;
+ if (spaceAvailable > 0) {
+ requestContent.addPart(String.valueOf(key), new TruncatedContentBody(contentBody, contentBody.getContentLength() - spaceAvailable));
+ }
+ // else we can fit NONE of this item, so sadly we must ignore it
+ }
+ else {
+ requestContent.addPart(String.valueOf(key), contentBody);
+ }
}
doPost(url, requestContent);
Added: Grasshopper/src/net/yura/grasshopper/util/TruncatedContentBody.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/util/TruncatedContentBody.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/util/TruncatedContentBody.java 2024-12-27 20:06:13 UTC (rev 1058)
@@ -0,0 +1,51 @@
+package net.yura.grasshopper.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import org.apache.http.entity.mime.content.ContentBody;
+
+public class TruncatedContentBody implements ContentBody {
+
+ private final ContentBody body;
+ private final long bytesToSkip;
+
+ public TruncatedContentBody(ContentBody body, long bytesToSkip) {
+ this.body = body;
+ this.bytesToSkip = bytesToSkip;
+ if (bytesToSkip >= body.getContentLength()) {
+ throw new IllegalArgumentException("skipping " + bytesToSkip + " for " + body);
+ }
+ }
+
+ public long getContentLength() {
+ return body.getContentLength() - bytesToSkip;
+ }
+
+ public void writeTo(OutputStream out) throws IOException {
+ body.writeTo(new TailOutputStream(out, bytesToSkip));
+ }
+
+ public String getFilename() {
+ return body.getFilename();
+ }
+
+ public String getCharset() {
+ return body.getCharset();
+ }
+
+ public String getTransferEncoding() {
+ return body.getTransferEncoding();
+ }
+
+ public String getMimeType() {
+ return body.getMimeType();
+ }
+
+ public String getMediaType() {
+ return body.getMediaType();
+ }
+
+ public String getSubType() {
+ return body.getSubType();
+ }
+}
Modified: Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java
===================================================================
--- Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java 2024-12-27 16:47:27 UTC (rev 1057)
+++ Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java 2024-12-27 20:06:13 UTC (rev 1058)
@@ -21,6 +21,9 @@
import javax.swing.JTextArea;
/**
+ * when an error happens this pops up a window with the log and offers to submit the bug report.
+ * when another error happens it will silently submit the bug again with the same info as was provided the first time
+ *
* @author Yura Mamyrin
*/
public class PopupBug extends Writer {
@@ -36,13 +39,13 @@
private PopupBug() {
debugText = new JTextArea();
-
+
// trigger the fonts to load so any errors that get logged when loading fonts happen before intercept is setup
// otherwise this can cause deadlocks (see todo.txt)
debugText.getFontMetrics(debugText.getFont());
appendString("testing 123\n"); // we use the same method as the logging system to make sure we catch any possible swing warnings
debugText.setText("");
-
+
debugText.setEditable(false);
simplePrintStream = new BugManager() {
@@ -56,11 +59,10 @@
}
}
};
-
+
BugManager.interceptAndAlert(this, simplePrintStream);
}
-
public static void initSimple(String appname,String version,String locale) {
if (instance==null) {
instance = new PopupBug();
@@ -86,7 +88,7 @@
if (errFrame==null) {
//errFrame = new JFrame("an error has occurred!!!");
-
+
// if we use a frame or a none-model dialog and we alredy have a [Frame->ModelDialog] open, we cant access this window
errFrame = new JDialog((JFrame)null,"an error has occurred!!!",true);
|