Skip to content

Commit c30862d

Browse files
author
Eric Denman
committed
Pushing old commit history
1 parent b6899cb commit c30862d

5 files changed

Lines changed: 160 additions & 13 deletions

File tree

README.md

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,115 @@
1-
squash_java
2-
===========
1+
Squash Client Library: Java
2+
===========================
33

4-
Java client for Squash exception reporting format. The SquashEntry class is meant to be extended
5-
and then serialized with gson for transmission to the Squash server.
4+
This client library reports exceptions to Squash, the Squarish exception
5+
reporting and management system.
66

7-
For more information: https://git.squareup.com/square/squash
7+
Documentation
8+
-------------
9+
10+
For an overview of the various components of Squash, see the website
11+
documentation at https://github.com/SquareSquash/web.
12+
13+
Compatibility
14+
-------------
15+
16+
This library is compatible with J2SE 1.6 or newer. All dependencies are handled
17+
by Maven.
18+
19+
Usage
20+
-----
21+
22+
The `SquashEntry` class is meant to be extended and then serialized with your
23+
choice of json library for transmission to your Squash server. We recommend
24+
using gson, but any auto-field-name-detecting library will do.
25+
26+
First, extend `SquashEntry` and include any additional occurrence data you wish
27+
to send to Squash. See the `Occurrence` class documentation in the Squash web
28+
code for a list of known properties; you can also supply any arbitrary
29+
properties as well.
30+
31+
```` java
32+
import com.squareup.squash.SquashEntry;
33+
34+
public class AndroidSquashEntry extends SquashEntry implements LogEntry {
35+
// The API key used for all Android Squash entries.
36+
private static final String API_KEY = "YOUR_API_KEY";
37+
private static final String CLIENT_ID = "android";
38+
private static final String DEBUG = "Debug";
39+
private static final String RELEASE = "Release";
40+
// Transient so it doesn't try to serialize itself.
41+
private transient Gson gson;
42+
43+
// Device stuff.
44+
private final String device_id;
45+
private final String device_type;
46+
private final String operating_system;
47+
private final boolean rooted;
48+
private final String network_operator;
49+
private final String network_type;
50+
private final String connectivity;
51+
private final String orientation;
52+
53+
// Location stuff.
54+
private final String lat;
55+
private final String lon;
56+
private final String altitude;
57+
private final String location_precision;
58+
private final String heading;
59+
private final String speed;
60+
61+
// Which app am I?
62+
private final String app_id;
63+
}
64+
````
65+
66+
Build a constructor or whatever you need to set all these parameters, and then
67+
add the ability for the class to transmit itself to Squash:
68+
69+
```` java
70+
public class AndroidSquashEntry extends SquashEntry implements LogEntry {
71+
@Override public void writeTo(OutputStream output) throws IOException {
72+
final String json = gson.toJson(this);
73+
output.write(Strings.getBytes(json));
74+
}
75+
}
76+
````
77+
78+
Add an exception handler that will generate these entry instances. (In the below
79+
example we're assuming that you've also built a factory that instantiates Squash
80+
entries, and a `transmit` method that transmits the JSON to Squash.)
81+
82+
```` java
83+
public class SquashUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
84+
@Inject AndroidSquashEntryFactory squashEntryFactory;
85+
86+
@Override public void uncaughtException(Thread thread, Throwable ex) {
87+
try {
88+
transmit(squashEntryFactory.create(message, ex));
89+
} catch (Throwable ignored) {
90+
// write your internal failsafe handler
91+
}
92+
}
93+
}
94+
````
95+
96+
... and install the exception handler.
97+
98+
```` java
99+
final Thread.UncaughtExceptionHandler handler =
100+
Thread.getDefaultUncaughtExceptionHandler();
101+
Thread.setDefaultUncaughtExceptionHandler(
102+
new SquashUncaughtExceptionHandler(this, handler));
103+
````
104+
105+
De-Obfuscation and File Paths
106+
-----------------------------
107+
108+
The [Squash Java Deobfuscator](https://github.com/SquareSquash/java_deobfuscator)
109+
Ruby gem can be included into your build-and-release process to upload yGuard
110+
or ProGuard obfuscation maps to Squash.
111+
112+
Even if you are not using code obfuscation, you can still use this gem to map
113+
Java class names to their original file paths, as Java stack traces do not
114+
include the full path to source files, which Squash needs to perform its
115+
Git-blame magic.

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<inceptionYear>2012</inceptionYear>
2222

2323
<scm>
24-
<url>http://git.squareup.com/square/squash_java</url>
25-
<connection>scm:git:git://git.squareup.com/square/squash_java.git</connection>
26-
<developerConnection>scg:git:git@git.squareup.com/square/squash_java.git</developerConnection>
24+
<url>https://github.com/SquareSquash/java</url>
25+
<connection>scm:git:git://github.com/SquareSquash/java.git</connection>
26+
<developerConnection>scg:git:git@github.com/SquareSquash/java.git</developerConnection>
2727
</scm>
2828

2929
<organization>
@@ -33,7 +33,7 @@
3333

3434
<issueManagement>
3535
<system>GitHub Issues</system>
36-
<url>http://github.com/square/squash_java/issues</url>
36+
<url>https://github.com/SquareSquash/java/issues</url>
3737
</issueManagement>
3838

3939
<licenses>
@@ -47,7 +47,7 @@
4747
<properties>
4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949

50-
<java.version>1.6</java.version>
50+
<java.version>1.5</java.version>
5151
<junit.version>4.10</junit.version>
5252
<fest.version>1.4</fest.version>
5353
<mockito.version>1.8.5</mockito.version>

src/main/java/com/squareup/squash/SquashBacktrace.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
// Copyright 2012 Square, Inc.
1+
// Copyright 2012 Square Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
215
package com.squareup.squash;
316

417
import java.lang.reflect.Field;

src/main/java/com/squareup/squash/SquashEntry.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
// Copyright 2012 Square, Inc.
1+
// Copyright 2012 Square Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
215
package com.squareup.squash;
316

417
import java.text.DateFormat;

src/test/java/com/squareup/squash/SquashEntryTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
// Copyright 2012 Square, Inc.
1+
// Copyright 2012 Square Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
215
package com.squareup.squash;
316

417
import com.google.gson.Gson;

0 commit comments

Comments
 (0)