Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 2eb0f32

Browse files
committedJan 21, 2018
Bugfix and minor improvements
1 parent 26b7c70 commit 2eb0f32

File tree

15 files changed

+168
-52
lines changed

15 files changed

+168
-52
lines changed
 

‎app/build.gradle

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.application'
22
apply from: "../shared.gradle"
33

44
android {
5-
compileSdkVersion 24
6-
buildToolsVersion '25.0.0'
5+
compileSdkVersion 26
6+
buildToolsVersion '26.0.2'
77
defaultConfig {
88
applicationId "ru.bartwell.ultradebugger.sampleapp"
99
minSdkVersion 16
10-
targetSdkVersion 24
10+
targetSdkVersion 26
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {
@@ -16,6 +16,7 @@ android {
1616
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1717
}
1818
}
19+
flavorDimensions "default"
1920
productFlavors {
2021
dev {}
2122
master {}
@@ -27,7 +28,7 @@ dependencies {
2728
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2829
exclude group: 'com.android.support', module: 'support-annotations'
2930
})
30-
compile 'com.android.support:appcompat-v7:24.2.1'
31+
compile 'com.android.support:appcompat-v7:26.1.0'
3132
testCompile 'junit:junit:4.12'
3233
compile project(':ultradebugger')
3334
}

‎base/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ dependencies {
1313
apply from: '../maven_push.gradle'
1414

1515
android {
16-
buildToolsVersion '25.0.0'
16+
buildToolsVersion '26.0.2'
1717
}

‎base/src/main/java/ru/bartwell/ultradebugger/base/model/HttpResponse.java

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.support.annotation.Nullable;
55

66
import java.io.InputStream;
7+
import java.util.HashMap;
8+
import java.util.Map;
79

810
/**
911
* Created by BArtWell on 05.01.2017.
@@ -22,6 +24,8 @@ public class HttpResponse {
2224
@Nullable
2325
private InputStream mStream;
2426
private long mContentLength;
27+
@NonNull
28+
Map<String, String> mHeaders = new HashMap<>();
2529

2630
public HttpResponse(@NonNull String content) {
2731
mStatus = Status.OK;
@@ -70,6 +74,15 @@ public long getContentLength() {
7074
return mContentLength;
7175
}
7276

77+
public void addHeader(@NonNull String name, @NonNull String value) {
78+
mHeaders.put(name, value);
79+
}
80+
81+
@NonNull
82+
public Map<String, String> getHeaders() {
83+
return mHeaders;
84+
}
85+
7386
public enum Status {
7487
OK(200, "OK"),
7588
BAD_REQUEST(400, "Bad request"),

‎build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
buildscript {
44
repositories {
55
jcenter()
6+
google()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.3.3'
9+
classpath 'com.android.tools.build:gradle:3.0.1'
910

1011
// NOTE: Do not place your application dependencies here; they belong
1112
// in the individual module build.gradle files
@@ -22,6 +23,7 @@ allprojects {
2223

2324
repositories {
2425
mavenCentral()
26+
google()
2527
}
2628
}
2729

‎gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ org.gradle.jvmargs=-Xmx1536m
1616
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1717
# org.gradle.parallel=true
1818

19-
VERSION_NAME=1.3
20-
VERSION_CODE=4
19+
VERSION_NAME=1.4.1
20+
VERSION_CODE=6
2121
GROUP=ru.bartwell
2222

2323
POM_DESCRIPTION=Ultra Debugger is an open source modules-based android library for application debugging.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Mar 13 18:04:03 MSK 2017
1+
#Sun Jan 21 18:19:31 MSK 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

‎info/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dependencies {
66
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
77
exclude group: 'com.android.support', module: 'support-annotations'
88
})
9-
compile 'com.android.support:appcompat-v7:25.2.0'
9+
compile 'com.android.support:appcompat-v7:26.1.0'
1010
testCompile 'junit:junit:4.12'
1111
compile project(':base')
1212
}

‎logger/src/main/java/ru/bartwell/ultradebugger/module/logger/Logger.java

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public static void addLog(@NonNull Context context, @NonNull String text, @Nulla
2727
}
2828
}
2929

30+
public static String getLogDownloadPath() {
31+
return Utils.getDownloadPath();
32+
}
33+
34+
public static void clearLogs(@NonNull Context context) {
35+
StorageHelper.clearLogs(context);
36+
}
37+
3038
public static void saveValue(@NonNull Context context, @NonNull String key, @Nullable Object value) {
3139
StorageHelper.saveValue(context, key, value);
3240
}

‎logger/src/main/java/ru/bartwell/ultradebugger/module/logger/Module.java

+65-32
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package ru.bartwell.ultradebugger.module.logger;
22

33
import android.content.Context;
4+
import android.net.Uri;
45
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
57
import android.text.TextUtils;
68

9+
import java.io.ByteArrayInputStream;
10+
import java.io.InputStream;
11+
import java.text.SimpleDateFormat;
12+
import java.util.Date;
13+
import java.util.Locale;
714
import java.util.Map;
815
import java.util.Random;
916

@@ -48,44 +55,60 @@ public String getDescription() {
4855
@NonNull
4956
@Override
5057
public HttpResponse handle(@NonNull HttpRequest request) {
51-
Page page = new Page();
52-
page.setTitle(getName());
53-
Content content = new Content();
58+
if (request.getUri().contains(Utils.DOWNLOAD_URI_PART)) {
59+
InputStream inputStream = getLogsFileStream();
60+
if (inputStream == null) {
61+
return new HttpResponse(HttpResponse.Status.INTERNAL_SERVER_ERROR);
62+
} else {
63+
HttpResponse response = new HttpResponse("text/plain", inputStream);
64+
String fileName = Uri.parse(request.getUri()).getLastPathSegment();
65+
if (fileName.contains(Utils.LOG_FILE_EXTENSION)) {
66+
StorageHelper.addLog(getContext(), "--- Download log file " + fileName + " ---");
67+
response.addHeader("content-disposition", "attachment; filename=\"" + fileName + "\"");
68+
}
69+
return response;
70+
}
71+
} else {
72+
Page page = new Page();
73+
page.setTitle(getName());
74+
Content content = new Content();
5475

55-
StorageHelper.rotateLogs(getContext());
76+
StorageHelper.rotateLogs(getContext());
5677

57-
if (isActionParameterValid(request, PARAMETER_CLEAR_LOGS)) {
58-
StorageHelper.clearLogs(getContext());
59-
}
60-
String deleteValue = HttpUtils.getParameterValue(request.getParameters(), PARAMETER_DELETE_VALUE_KEY);
61-
if (isActionParameterValid(request, PARAMETER_DELETE_VALUE) && !TextUtils.isEmpty(deleteValue)) {
62-
StorageHelper.removeValue(getContext(), deleteValue);
63-
}
78+
if (isActionParameterValid(request, PARAMETER_CLEAR_LOGS)) {
79+
StorageHelper.clearLogs(getContext());
80+
}
81+
String deleteValue = HttpUtils.getParameterValue(request.getParameters(), PARAMETER_DELETE_VALUE_KEY);
82+
if (isActionParameterValid(request, PARAMETER_DELETE_VALUE) && !TextUtils.isEmpty(deleteValue)) {
83+
StorageHelper.removeValue(getContext(), deleteValue);
84+
}
6485

65-
mLastPageRandom = getRandInt();
66-
page.addNavigationLink("?" + PARAMETER_CLEAR_LOGS + "=" + mLastPageRandom, "Clear logs");
67-
68-
Map<String, ?> allValues = StorageHelper.getAllValues(getContext());
69-
if (!allValues.isEmpty()) {
70-
content.add(new HeadingContentPart(3, "Saved values"));
71-
Table table = new Table();
72-
int i = 0;
73-
for (Map.Entry<String, ?> entry : allValues.entrySet()) {
74-
table.add(0, i, new RawContentPart(entry.getKey()));
75-
table.add(1, i, new RawContentPart(String.valueOf(entry.getValue())));
76-
table.add(2, i, new Link("?" + PARAMETER_DELETE_VALUE + "=" + mLastPageRandom
77-
+ "&" + PARAMETER_DELETE_VALUE_KEY + "=" + entry.getKey()
78-
, "Remove"));
79-
i++;
86+
mLastPageRandom = getRandInt();
87+
page.addNavigationLink(Utils.getDownloadPath(), "Download logs");
88+
page.addNavigationLink("?" + PARAMETER_CLEAR_LOGS + "=" + mLastPageRandom, "Clear logs");
89+
90+
Map<String, ?> allValues = StorageHelper.getAllValues(getContext());
91+
if (!allValues.isEmpty()) {
92+
content.add(new HeadingContentPart(3, "Saved values"));
93+
Table table = new Table();
94+
int i = 0;
95+
for (Map.Entry<String, ?> entry : allValues.entrySet()) {
96+
table.add(0, i, new RawContentPart(entry.getKey()));
97+
table.add(1, i, new RawContentPart(String.valueOf(entry.getValue())));
98+
table.add(2, i, new Link("?" + PARAMETER_DELETE_VALUE + "=" + mLastPageRandom
99+
+ "&" + PARAMETER_DELETE_VALUE_KEY + "=" + entry.getKey()
100+
, "Remove"));
101+
i++;
102+
}
103+
content.add(table);
80104
}
81-
content.add(table);
82-
}
83105

84-
content.add(new HeadingContentPart(3, "Logs"));
85-
content.add(new RawContentPart(StorageHelper.readLogs(getContext(), "<br/>")));
106+
content.add(new HeadingContentPart(3, "Logs"));
107+
content.add(new RawContentPart(StorageHelper.readLogs(getContext(), "<br/>")));
86108

87-
page.setContent(content);
88-
return new HttpResponse(page.toHtml());
109+
page.setContent(content);
110+
return new HttpResponse(page.toHtml());
111+
}
89112
}
90113

91114
private int getRandInt() {
@@ -96,4 +119,14 @@ private boolean isActionParameterValid(@NonNull HttpRequest request, @NonNull St
96119
String value = HttpUtils.getParameterValue(request.getParameters(), parameter);
97120
return !TextUtils.isEmpty(value) && value.equals(String.valueOf(mLastPageRandom));
98121
}
122+
123+
@Nullable
124+
private InputStream getLogsFileStream() {
125+
try {
126+
return new ByteArrayInputStream(StorageHelper.readLogs(getContext(), "\r\n").getBytes());
127+
} catch (Exception e) {
128+
e.printStackTrace();
129+
}
130+
return null;
131+
}
99132
}

‎logger/src/main/java/ru/bartwell/ultradebugger/module/logger/StorageHelper.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private static SharedPreferences getSharedPreferences(@NonNull Context context)
5252
}
5353

5454
static void addLog(@NonNull Context context, @NonNull String text) {
55+
rotateLogs(context);
5556
writeToLogsFile(context, getLogDate() + " " + text + "\n", true);
5657
}
5758

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ru.bartwell.ultradebugger.module.logger;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import java.text.SimpleDateFormat;
6+
import java.util.Date;
7+
import java.util.Locale;
8+
9+
/**
10+
* Created by BArtWell on 18.11.2017.
11+
*/
12+
13+
class Utils {
14+
15+
private static final String MODULE_ID = "logger";
16+
static final String DOWNLOAD_URI_PART = "/download/";
17+
static final String LOG_FILE_EXTENSION = ".log";
18+
19+
@NonNull
20+
static String getDownloadPath() {
21+
return "/" + MODULE_ID + DOWNLOAD_URI_PART + Utils.getFileName();
22+
}
23+
24+
@NonNull
25+
private static String getFileName() {
26+
String date = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date());
27+
return date + LOG_FILE_EXTENSION;
28+
}
29+
}

‎shared.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
android {
2-
compileSdkVersion 25
3-
buildToolsVersion "25.0.0"
2+
compileSdkVersion 26
3+
buildToolsVersion "26.0.2"
44

55
defaultConfig {
6-
minSdkVersion 9
7-
targetSdkVersion 25
8-
versionCode 4
9-
versionName "1.3"
6+
minSdkVersion 14
7+
targetSdkVersion 26
8+
versionCode 6
9+
versionName "1.4.1"
1010

1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212

‎ultradebugger/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
"\"logger\"" +
1313
"}"
1414
}
15-
buildToolsVersion '25.0.0'
15+
buildToolsVersion '26.0.2'
1616
}
1717

1818
dependencies {

‎ultradebugger/src/main/java/ru/bartwell/ultradebugger/HttpServer.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ public Response serve(IHTTPSession session) {
7171
if (response.getStream() == null) {
7272
return newFixedLengthResponse(convertResponseStatus(response.getStatus()), response.getContentType(), response.getContent());
7373
} else {
74+
Response result;
7475
if (response.getContentLength() >= 0) {
75-
return newFixedLengthResponse(convertResponseStatus(response.getStatus()), response.getContentType(), response.getStream(), response.getContentLength());
76+
result = newFixedLengthResponse(convertResponseStatus(response.getStatus()), response.getContentType(), response.getStream(), response.getContentLength());
7677
} else {
77-
return newChunkedResponse(convertResponseStatus(response.getStatus()), response.getContentType(), response.getStream());
78+
result = newChunkedResponse(convertResponseStatus(response.getStatus()), response.getContentType(), response.getStream());
7879
}
80+
for (Map.Entry<String, String> entry : response.getHeaders().entrySet()) {
81+
result.addHeader(entry.getKey(), entry.getValue());
82+
}
83+
return result;
7984
}
8085
}
8186
}

‎wrapper/src/main/java/ru/bartwell/ultradebugger/wrapper/UltraDebuggerWrapper.java

+24
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ public static void addLog(@NonNull Context context, @NonNull String text, @Nulla
9494
}
9595
}
9696

97+
@NonNull
98+
public static String getLogDownloadPath() {
99+
if (sIsEnabled) {
100+
try {
101+
Class<?> clazz = Class.forName("ru.bartwell.ultradebugger.module.logger.Logger");
102+
Method method = clazz.getMethod("getLogDownloadPath");
103+
return (String) method.invoke(null);
104+
} catch (Exception ignored) {
105+
}
106+
}
107+
return "";
108+
}
109+
110+
public static void clearLogs(@NonNull Context context) {
111+
if (sIsEnabled) {
112+
try {
113+
Class<?> clazz = Class.forName("ru.bartwell.ultradebugger.module.logger.Logger");
114+
Method method = clazz.getMethod("clearLogs", Context.class);
115+
method.invoke(null, context);
116+
} catch (Exception ignored) {
117+
}
118+
}
119+
}
120+
97121
public static void saveValue(@NonNull Context context, @NonNull String key, @Nullable Object value) {
98122
if (sIsEnabled) {
99123
try {

0 commit comments

Comments
 (0)
This repository has been archived.