From 0f285dfa9f09524fd37300d89fb16f9a42660c01 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Thu, 6 Nov 2014 15:43:45 +0100 Subject: [PATCH] Removed seamless-android dependency --- README.md | 2 +- core/pom.xml | 2 +- .../cling/android/FixedAndroidLogHandler.java | 145 ++++++++++++++++++ core/src/manual/android/index.xhtml | 2 +- core/src/site/xhtml/index.xhtml | 2 +- demo/android/browser/pom.xml | 2 +- .../demo/android/browser/BrowserActivity.java | 3 +- demo/android/light/pom.xml | 2 +- .../demo/android/light/LightActivity.java | 7 +- demo/android/pom.xml | 19 +-- demo/pom.xml | 2 +- distribution/pom.xml | 2 +- distribution/src/dist/README.txt | 7 +- mediarenderer/pom.xml | 2 +- mediarenderer/src/site/xhtml/index.xhtml | 2 +- pom.xml | 4 +- support/pom.xml | 2 +- support/src/site/xhtml/index.xhtml | 2 +- website/pom.xml | 2 +- website/src/site/xhtml/index.xhtml | 2 +- website/src/site/xhtml/roadmap.xhtml | 2 +- workbench/pom.xml | 2 +- workbench/src/site/xhtml/index.xhtml | 2 +- 23 files changed, 172 insertions(+), 47 deletions(-) create mode 100644 core/src/main/java/org/fourthline/cling/android/FixedAndroidLogHandler.java diff --git a/README.md b/README.md index d852e08d6..16798eb51 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ If your build fails with Android/dex packaging errors, you forgot the clean. org.fourthline.cling cling-core - 2.0.0 + 2.0.1 ```` diff --git a/core/pom.xml b/core/pom.xml index 4f9359e28..11d2d9c07 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -7,7 +7,7 @@ org.fourthline.cling cling - 2.0.0 + 2.0.1 Cling Core diff --git a/core/src/main/java/org/fourthline/cling/android/FixedAndroidLogHandler.java b/core/src/main/java/org/fourthline/cling/android/FixedAndroidLogHandler.java new file mode 100644 index 000000000..6d20e0ebf --- /dev/null +++ b/core/src/main/java/org/fourthline/cling/android/FixedAndroidLogHandler.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.fourthline.cling.android; + +import android.util.Log; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; + +/* +Taken from: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob_plain;f=core/java/com/android/internal/logging/AndroidHandler.java;hb=c2ad241504fcaa12d4579d3b0b4038d1ca8d08c9 + */ +public class FixedAndroidLogHandler extends Handler { + /** + * Holds the formatter for all Android log handlers. + */ + private static final Formatter THE_FORMATTER = new Formatter() { + @Override + public String format(LogRecord r) { + Throwable thrown = r.getThrown(); + if (thrown != null) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + sw.write(r.getMessage()); + sw.write("\n"); + thrown.printStackTrace(pw); + pw.flush(); + return sw.toString(); + } else { + return r.getMessage(); + } + } + }; + + /** + * Constructs a new instance of the Android log handler. + */ + public FixedAndroidLogHandler() { + setFormatter(THE_FORMATTER); + } + + @Override + public void close() { + // No need to close, but must implement abstract method. + } + + @Override + public void flush() { + // No need to flush, but must implement abstract method. + } + + @Override + public void publish(LogRecord record) { + try { + int level = getAndroidLevel(record.getLevel()); + String tag = record.getLoggerName(); + + if (tag == null) { + // Anonymous logger. + tag = "null"; + } else { + // Tags must be <= 23 characters. + int length = tag.length(); + if (length > 23) { + // Most loggers use the full class name. Try dropping the + // package. + int lastPeriod = tag.lastIndexOf("."); + if (length - lastPeriod - 1 <= 23) { + tag = tag.substring(lastPeriod + 1); + } else { + // Use last 23 chars. + tag = tag.substring(tag.length() - 23); + } + } + } + + /* ############################################################################################ + + Instead of using the perfectly fine java.util.logging API for setting the + loggable levels, this call relies on a totally obscure "local.prop" file which you have to place on + your device. By default, if you do not have that file and if you do not execute some magic + "setprop" commands on your device, only INFO/WARN/ERROR is loggable. So whatever you do with + java.util.logging.Logger.setLevel(...) doesn't have any effect. The debug messages might arrive + here but they are dropped because you _also_ have to set the Android internal logging level with + the aforementioned magic switches. + + Also, consider that you have to understand how a JUL logger name is mapped to the "tag" of + the Android log. Basically, the whole cutting and cropping procedure above is what you have to + memorize if you want to log with JUL and configure Android for debug output. + + I actually admire the pure evil of this setup, even Mr. Ceki can learn something! + + Commenting out these lines makes it all work as expected: + + if (!Log.isLoggable(tag, level)) { + return; + } + + ############################################################################################### */ + + String message = getFormatter().format(record); + Log.println(level, tag, message); + } catch (RuntimeException e) { + Log.e("AndroidHandler", "Error logging message.", e); + } + } + + /** + * Converts a {@link java.util.logging.Logger} logging level into an Android one. + * + * @param level The {@link java.util.logging.Logger} logging level. + * + * @return The resulting Android logging level. + */ + static int getAndroidLevel(Level level) { + int value = level.intValue(); + if (value >= 1000) { // SEVERE + return Log.ERROR; + } else if (value >= 900) { // WARNING + return Log.WARN; + } else if (value >= 800) { // INFO + return Log.INFO; + } else { + return Log.DEBUG; + } + } + +} \ No newline at end of file diff --git a/core/src/manual/android/index.xhtml b/core/src/manual/android/index.xhtml index edb6f9675..0534279ed 100644 --- a/core/src/manual/android/index.xhtml +++ b/core/src/manual/android/index.xhtml @@ -150,7 +150,7 @@ on Android you will not see FINE, FINER, and FINEST log messages, as their built-in log handler is broken (or, so badly designed that it might as well be broken). The easiest workaround is to set a custom log handler available in the - seamless-android package. + FixedAndroidLogHandler class.

diff --git a/core/src/site/xhtml/index.xhtml b/core/src/site/xhtml/index.xhtml index 60f3be56e..61ff2eb90 100644 --- a/core/src/site/xhtml/index.xhtml +++ b/core/src/site/xhtml/index.xhtml @@ -92,7 +92,7 @@ org.fourthline.cling cling-core - 2.0.0 + 2.0.1 ]]> diff --git a/demo/android/browser/pom.xml b/demo/android/browser/pom.xml index fc1d89766..52c8ece70 100755 --- a/demo/android/browser/pom.xml +++ b/demo/android/browser/pom.xml @@ -5,7 +5,7 @@ org.fourthline.cling cling-demo-android - 2.0.0 + 2.0.1 Cling Demo Android Browser diff --git a/demo/android/browser/src/main/java/org/fourthline/cling/demo/android/browser/BrowserActivity.java b/demo/android/browser/src/main/java/org/fourthline/cling/demo/android/browser/BrowserActivity.java index 9d1ad302e..e2d0534db 100644 --- a/demo/android/browser/src/main/java/org/fourthline/cling/demo/android/browser/BrowserActivity.java +++ b/demo/android/browser/src/main/java/org/fourthline/cling/demo/android/browser/BrowserActivity.java @@ -33,6 +33,7 @@ import android.widget.Toast; import org.fourthline.cling.android.AndroidUpnpService; import org.fourthline.cling.android.AndroidUpnpServiceImpl; +import org.fourthline.cling.android.FixedAndroidLogHandler; import org.fourthline.cling.model.meta.Device; import org.fourthline.cling.model.meta.LocalDevice; import org.fourthline.cling.model.meta.RemoteDevice; @@ -90,7 +91,7 @@ public void onCreate(Bundle savedInstanceState) { // Fix the logging integration between java.util.logging and Android internal logging org.seamless.util.logging.LoggingUtil.resetRootHandler( - new org.seamless.android.FixedAndroidLogHandler() + new FixedAndroidLogHandler() ); // Now you can enable logging as needed for various categories of Cling: // Logger.getLogger("org.fourthline.cling").setLevel(Level.FINEST); diff --git a/demo/android/light/pom.xml b/demo/android/light/pom.xml index 77302f84c..9f8ccc2bc 100755 --- a/demo/android/light/pom.xml +++ b/demo/android/light/pom.xml @@ -5,7 +5,7 @@ org.fourthline.cling cling-demo-android - 2.0.0 + 2.0.1 Cling Demo Android Light diff --git a/demo/android/light/src/main/java/org/fourthline/cling/demo/android/light/LightActivity.java b/demo/android/light/src/main/java/org/fourthline/cling/demo/android/light/LightActivity.java index c39b92e5f..c1408905d 100644 --- a/demo/android/light/src/main/java/org/fourthline/cling/demo/android/light/LightActivity.java +++ b/demo/android/light/src/main/java/org/fourthline/cling/demo/android/light/LightActivity.java @@ -29,6 +29,7 @@ import android.widget.Toast; import org.fourthline.cling.android.AndroidUpnpService; import org.fourthline.cling.android.AndroidUpnpServiceImpl; +import org.fourthline.cling.android.FixedAndroidLogHandler; import org.fourthline.cling.binding.LocalServiceBindingException; import org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder; import org.fourthline.cling.model.DefaultServiceManager; @@ -110,9 +111,9 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // DOC:LOGGING // Fix the logging integration between java.util.logging and Android internal logging - org.seamless.util.logging.LoggingUtil.resetRootHandler( - new org.seamless.android.FixedAndroidLogHandler() - ); + // org.seamless.util.logging.LoggingUtil.resetRootHandler( + // new FixedAndroidLogHandler() + // ); // Logger.getLogger("org.fourthline.cling").setLevel(Level.FINEST); // DOC:LOGGING diff --git a/demo/android/pom.xml b/demo/android/pom.xml index ab33dff77..ef5806a17 100755 --- a/demo/android/pom.xml +++ b/demo/android/pom.xml @@ -6,7 +6,7 @@ org.fourthline.cling cling-demo - 2.0.0 + 2.0.1 Cling Demo Android @@ -52,23 +52,6 @@ ${project.version} - - org.seamless - seamless-android - ${seamless.version} - - - - com.android.support - support-v4 - - - com.android.support - support-v13 - - - - com.google.android android diff --git a/demo/pom.xml b/demo/pom.xml index 9078751dd..f3b4db6b7 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -7,7 +7,7 @@ org.fourthline.cling cling - 2.0.0 + 2.0.1 Cling Demo diff --git a/distribution/pom.xml b/distribution/pom.xml index 21affeac7..82a8b50dd 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -7,7 +7,7 @@ cling org.fourthline.cling - 2.0.0 + 2.0.1 Cling Distribution diff --git a/distribution/src/dist/README.txt b/distribution/src/dist/README.txt index 5cba77f6d..1edaa69bc 100644 --- a/distribution/src/dist/README.txt +++ b/distribution/src/dist/README.txt @@ -57,7 +57,7 @@ DEPENDENCIES Required dependencies of Cling Core (included with this distribution): - +- org.fourthline.cling:cling-core:jar:2.0.0 + +- org.fourthline.cling:cling-core:jar:2.0.1 +- org.seamless:seamless-util:jar:1.0.0 +- org.seamless:seamless-http:jar:1.0.0 \- org.seamless:seamless-xml:jar:1.0.0 @@ -76,11 +76,6 @@ Additional dependencies of Cling Core on Android (not included): +- org.slf4j:slf4j-jdk14:jar:1.6.1 (or any other SLF4J implementation) \- org.slf4j:slf4j-api:jar:1.6.1 -If you need the fixed Android java.util.logging Handler: - - +- org.seamless:seamless-android:jar:1.0.0 - \- android.support:compatibility-v13:jar:10 (Exclude this in pom.xml) - WARNING: Jetty JAR files each contain an 'about.html' file, you will get an error when trying to package your application with APK. Use the Android Maven plugin and set the "extractDuplicates" option or repackage the Jetty diff --git a/mediarenderer/pom.xml b/mediarenderer/pom.xml index dac6890a9..78aa20061 100644 --- a/mediarenderer/pom.xml +++ b/mediarenderer/pom.xml @@ -7,7 +7,7 @@ org.fourthline.cling cling - 2.0.0 + 2.0.1 Cling MediaRenderer diff --git a/mediarenderer/src/site/xhtml/index.xhtml b/mediarenderer/src/site/xhtml/index.xhtml index 48d38a2d6..c68ffbdf2 100644 --- a/mediarenderer/src/site/xhtml/index.xhtml +++ b/mediarenderer/src/site/xhtml/index.xhtml @@ -51,7 +51,7 @@ java -Djna.library.path=/usr/lib -jar cling-mediarenderer.jar