diff --git a/app-robo/.gitignore b/app-robo/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/app-robo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/app-robo/build.gradle b/app-robo/build.gradle deleted file mode 100644 index ee03d87..0000000 --- a/app-robo/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -apply plugin: 'java' - -dependencies { - def androidModule = project(':app') - compile androidModule - def firstLibraryVariant = androidModule.android.libraryVariants.toList().first() - - compile firstLibraryVariant.javaCompile.classpath - compile firstLibraryVariant.javaCompile.outputs.files - compile files(firstLibraryVariant.javaCompile.classpath) - compile firstLibraryVariant.testVariant.javaCompile.classpath - compile files(firstLibraryVariant.testVariant.javaCompile.classpath) - compile firstLibraryVariant.testVariant.javaCompile.outputs.files - compile files(androidModule.plugins.findPlugin("com.android.library").getBootClasspath()) -} - -assemble.dependsOn(':app:compileDebugTestSources') \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index e199501..1d44d49 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,19 +1,18 @@ plugins { id 'com.android.library' - id 'com.github.dcendents.android-maven' } group='com.github.bright' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' + namespace "pl.brightinventions.slf4android" + testNamespace "pl.brightinventions.slf4android.androidTest" + + compileSdk 34 defaultConfig { minSdkVersion 14 - targetSdkVersion 28 - versionCode 14 - versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } packagingOptions { @@ -28,21 +27,20 @@ android { } dependencies { - implementation 'com.android.support:support-compat:28.0.0' - implementation 'org.slf4j:slf4j-api:1.7.7' + implementation 'androidx.core:core:1.12.0' + implementation 'org.slf4j:slf4j-api:1.7.36' implementation 'com.squareup:seismic:1.0.2' - androidTestImplementation 'org.hamcrest:hamcrest-all:1.3' - androidTestImplementation('junit:junit:4.11') { - exclude module: 'hamcrest-core' - } + androidTestImplementation 'org.hamcrest:hamcrest-core:1.3' + androidTestImplementation 'org.hamcrest:hamcrest-library:1.3' + androidTestImplementation('junit:junit:4.13.2') + androidTestImplementation 'androidx.test:rules:1.5.0' androidTestImplementation 'org.easytesting:fest-util:1.2.5' - testImplementation 'org.hamcrest:hamcrest-all:1.3' - testImplementation('junit:junit:4.11') { - exclude module: 'hamcrest-core' - } + testImplementation 'org.hamcrest:hamcrest-core:1.3' + testImplementation 'org.hamcrest:hamcrest-library:1.3' + testImplementation('junit:junit:4.13.2') testImplementation 'org.easytesting:fest-util:1.2.5' - testImplementation('org.robolectric:robolectric:3.0') { + testImplementation('org.robolectric:robolectric:4.11.1') { exclude module: 'classworlds' exclude module: 'commons-logging' exclude module: 'httpclient' @@ -60,5 +58,3 @@ dependencies { exclude module: 'wagon-provider-api' } } - - diff --git a/app/src/androidTest/AndroidManifest.xml b/app/src/androidTest/AndroidManifest.xml index 6d0a03b..bbb0c50 100644 --- a/app/src/androidTest/AndroidManifest.xml +++ b/app/src/androidTest/AndroidManifest.xml @@ -1,13 +1,11 @@ - + + android:value="ignore" /> - + { +public class NotifyDeveloperHandlerTests extends ActivityTestRule { private Logger LOG; private NotifyDeveloperHandler handler; @@ -20,22 +25,23 @@ public NotifyDeveloperHandlerTests() { super(TestActivity.class); } - @Override - protected void setUp() throws Exception { + @Before + public void setUp() { LoggerConfiguration.resetConfigurationToDefault(); LoggerConfiguration configuration = LoggerConfiguration.configuration(); Application targetContext = (Application) getInstrumentation().getTargetContext().getApplicationContext(); handler = configuration.notifyDeveloperHandler(targetContext, "piotr.mionskowski@gmail.com"); configuration.addHandlerToLogger("", handler); LOG = LoggerFactory.getLogger(getClass().getSimpleName()); - super.setUp(); } - public void test_dont_send_message_with_level_lower_than_error() throws Exception { + @Test + public void test_dont_send_message_with_level_lower_than_error() { getActivity(); LOG.warn("Hello"); } + @Test public void test_send_message_with_level_error() throws Exception { getActivity(); LOG.warn("Hello"); @@ -43,7 +49,8 @@ public void test_send_message_with_level_error() throws Exception { Thread.sleep(TimeUnit.SECONDS.toMillis(15)); } - public void test_send_message_with_custom_subject_body_with_level_error() throws Exception{ + @Test + public void test_send_message_with_custom_subject_body_with_level_error() throws Exception { handler.withSubject("Błąd").withBody("Podaj szczegóły błędu: "); getActivity(); LOG.warn("Hello"); diff --git a/app/src/androidTest/java/pl/brightinventions/slf4android/androidTest/TestActivity.java b/app/src/androidTest/java/pl/brightinventions/slf4android/androidTest/TestActivity.java index e84ecce..1b077a8 100644 --- a/app/src/androidTest/java/pl/brightinventions/slf4android/androidTest/TestActivity.java +++ b/app/src/androidTest/java/pl/brightinventions/slf4android/androidTest/TestActivity.java @@ -7,6 +7,6 @@ public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(pl.brightinventions.slf4android.test.R.layout.test); + setContentView(R.layout.test); } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a2875d7..c081391 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,14 +1,12 @@ - + + android:value="ignore" /> + android:theme="@android:style/Theme.NoDisplay" /> = 1 ? files[0].getAbsolutePath() : null; + } catch (IllegalAccessException e) { + LOG.warn("Cant read 'files' field value from {}", fileHandler, e); + } + } + + Field fileNameField = getFileNameField(fileHandler); + if (fileNameField != null) { + try { + return (String) fileNameField.get(fileHandler); } catch (IllegalAccessException e) { LOG.warn("Cant read 'fileName' field value from {}", fileHandler, e); } @@ -26,17 +39,31 @@ public String getCurrentFileName(FileHandler fileHandler) { return null; } - private synchronized Field getFileNameField(FileHandler fileHandler) { - //TODO: this can potentially generate multiple errors for the same reason + private Field getFileNameField(FileHandler fileHandler) { if (fileNameField == null) { - try { - //TODO: check if there is a better way - fileNameField = fileHandler.getClass().getDeclaredField("fileName"); - fileNameField.setAccessible(true); - } catch (NoSuchFieldException e) { - LOG.warn("Could not find field 'fileName' inside class {}", fileHandler.getClass()); - } + fileNameField = getFileHandlerField(fileHandler, "fileName"); } return fileNameField; } + + private Field getFilesField(FileHandler fileHandler) { + if (filesField == null) { + filesField = getFileHandlerField(fileHandler, "files"); + } + return filesField; + } + + private Field getFileHandlerField(FileHandler fileHandler, String fieldName) { + //TODO: this can potentially generate multiple errors for the same reason + Field field = null; + try { + //TODO: check if there is a better way + field = fileHandler.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + } catch (NoSuchFieldException e) { + LOG.warn("Could not find field '{}' inside class {}", fieldName, fileHandler.getClass()); + } + + return field; + } } diff --git a/app/src/main/java/pl/brightinventions/slf4android/LogcatHandler.java b/app/src/main/java/pl/brightinventions/slf4android/LogcatHandler.java index 89cb4a5..ad6e0d1 100644 --- a/app/src/main/java/pl/brightinventions/slf4android/LogcatHandler.java +++ b/app/src/main/java/pl/brightinventions/slf4android/LogcatHandler.java @@ -17,6 +17,7 @@ */ +import android.annotation.SuppressLint; import android.util.Log; import java.util.logging.Handler; @@ -40,6 +41,7 @@ public void flush() { } @Override + @SuppressLint("WrongConstant") public void publish(LogRecord record) { if (!isLoggable(record)) { return; @@ -50,6 +52,10 @@ public void publish(LogRecord record) { try { String message = logRecordFormatter.format(slfRecord); + /* + * Apparently, lint doesn't understand that getAndroidLevel() returns a valid Android + * log level value, hence the @SuppressLint("WrongConstant") above this method. + */ Log.println(level, tag, message); } catch (RuntimeException e) { Log.e("LogcatHandler", "Error logging message.", e); diff --git a/app/src/main/java/pl/brightinventions/slf4android/Slf4AndroidLogFileProvider.java b/app/src/main/java/pl/brightinventions/slf4android/Slf4AndroidLogFileProvider.java index c07afbf..e1db851 100644 --- a/app/src/main/java/pl/brightinventions/slf4android/Slf4AndroidLogFileProvider.java +++ b/app/src/main/java/pl/brightinventions/slf4android/Slf4AndroidLogFileProvider.java @@ -1,7 +1,8 @@ package pl.brightinventions.slf4android; import android.content.Context; -import android.support.v4.content.FileProvider; + +import androidx.core.content.FileProvider; public class Slf4AndroidLogFileProvider extends FileProvider { diff --git a/app/src/test/java/pl/brightinventions/slf4android/HandlerFormatterCompilerTests.java b/app/src/test/java/pl/brightinventions/slf4android/HandlerFormatterCompilerTests.java index 65557c7..e3b41c2 100644 --- a/app/src/test/java/pl/brightinventions/slf4android/HandlerFormatterCompilerTests.java +++ b/app/src/test/java/pl/brightinventions/slf4android/HandlerFormatterCompilerTests.java @@ -1,17 +1,17 @@ package pl.brightinventions.slf4android; -import org.junit.Test; - -import java.util.logging.Level; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -public class HandlerFormatterCompilerTests extends RoboelectricTest { +import org.junit.Test; + +import java.util.logging.Level; + +public class HandlerFormatterCompilerTests { @Test - public void canCompileSimpleMessage() throws Exception { + public void canCompileSimpleMessage() { LogRecordFormatter formatter = compile("%message"); String message = formatter.format(new LogRecord(Level.FINE, "My message")); assertThat(message, is(equalTo("My message"))); @@ -24,13 +24,13 @@ private LogRecordFormatter compile(String formatter) { } @Test - public void canCompileSimpleMessageAndPreserveWhiteSpace() throws Exception { + public void canCompileSimpleMessageAndPreserveWhiteSpace() { String message = compile(" %message\t").format(new LogRecord(Level.FINE, "[message]")); assertThat(message, is(equalTo(" [message]\t"))); } @Test - public void canCompileSimpleMessageAndPreserveNonPatternKeywords() throws Exception { + public void canCompileSimpleMessageAndPreserveNonPatternKeywords() { String message = compile("messageStart %message MESSAGE_end").format(new LogRecord(Level.FINE, "messageContent")); assertThat(message, is(equalTo("messageStart messageContent MESSAGE_end"))); } diff --git a/app/src/test/java/pl/brightinventions/slf4android/MessageValueSupplierTests.java b/app/src/test/java/pl/brightinventions/slf4android/MessageValueSupplierTests.java index 03072bc..fc222ff 100644 --- a/app/src/test/java/pl/brightinventions/slf4android/MessageValueSupplierTests.java +++ b/app/src/test/java/pl/brightinventions/slf4android/MessageValueSupplierTests.java @@ -1,17 +1,17 @@ package pl.brightinventions.slf4android; -import org.junit.Test; - -import java.util.logging.Level; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -public class MessageValueSupplierTests extends RoboelectricTest { +import org.junit.Test; + +import java.util.logging.Level; + +public class MessageValueSupplierTests { @Test - public void canProvideValueOfSimpleString() throws Exception { + public void canProvideValueOfSimpleString() { String message = value("simple message"); assertThat(message, is(equalTo("simple message"))); @@ -27,28 +27,28 @@ String value(String message, Object... args) { } @Test - public void canProvideValueOfSimpleMessageWithOneArgument() throws Exception { + public void canProvideValueOfSimpleMessageWithOneArgument() { assertThat(value("message {}", "arg"), is(equalTo("message arg"))); } @Test - public void canProvideValueOfSimpleMessageWithTwoArguments() throws Exception { + public void canProvideValueOfSimpleMessageWithTwoArguments() { assertThat(value("message {} {}", "arg1", "arg2"), is(equalTo("message arg1 arg2"))); } @Test - public void canProvideValueOfSimpleMessageWithManyArguments() throws Exception { + public void canProvideValueOfSimpleMessageWithManyArguments() { assertThat(value("message {} and {} and {}", "arg1", "arg2", "arg3"), is(equalTo("message arg1 and arg2 and arg3"))); } @Test - public void canAppendExceptionInformationAtTheEndOfMessage() throws Exception { + public void canAppendExceptionInformationAtTheEndOfMessage() { assertThat(value("message", new NullPointerException()), containsString("message")); assertThat(value("message", new NullPointerException()), containsString("NullPointerException")); } @Test - public void canProvideFormattedValueWithExceptionInformationAtTheEndOfMessage() throws Exception { + public void canProvideFormattedValueWithExceptionInformationAtTheEndOfMessage() { assertThat(value("message {}", "arg", new NullPointerException()), containsString("message arg")); assertThat(value("message {}", new NullPointerException()), containsString("NullPointerException")); } diff --git a/app/src/test/java/pl/brightinventions/slf4android/RoboelectricTest.java b/app/src/test/java/pl/brightinventions/slf4android/RoboelectricTest.java deleted file mode 100644 index fb9a40b..0000000 --- a/app/src/test/java/pl/brightinventions/slf4android/RoboelectricTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package pl.brightinventions.slf4android; - -import org.junit.runner.RunWith; -import org.robolectric.annotation.Config; - -@RunWith(RobolectricTestRunner.class) -@Config( - constants = BuildConfig.class -) -public abstract class RoboelectricTest { -} diff --git a/app/src/test/java/pl/brightinventions/slf4android/RobolectricTestRunner.java b/app/src/test/java/pl/brightinventions/slf4android/RobolectricTestRunner.java deleted file mode 100644 index 706dba4..0000000 --- a/app/src/test/java/pl/brightinventions/slf4android/RobolectricTestRunner.java +++ /dev/null @@ -1,25 +0,0 @@ -package pl.brightinventions.slf4android; - -import org.junit.runners.model.InitializationError; - -public class RobolectricTestRunner extends org.robolectric.RobolectricTestRunner { - public RobolectricTestRunner(Class testClass) throws InitializationError { - super(testClass); - } -// -// @Override -// protected AndroidManifest getAppManifest(Config config) { -// String manifestPath = "main/AndroidManifest.xml"; -// String resPath = "main/res"; -// AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resPath)) { -// @Override -// public int getTargetSdkVersion() { -// return 18; -// } -// }; -// manifest.setPackageName("pl.brightinventions.slf4android"); -// return manifest; -// } -// - -} diff --git a/build.gradle b/build.gradle index 5527d4a..2758468 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,18 @@ buildscript { repositories { + gradlePluginPortal() + mavenCentral() google() - jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath 'com.android.tools.build:gradle:8.2.0' + //classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } allprojects { repositories { + mavenCentral() google() - jcenter() } } diff --git a/gradle.properties b/gradle.properties index 5d08ba7..3e4d073 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,16 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Settings specified in this file will override any Gradle settings -# configured through the IDE. - # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - +# # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m +# Default value: -Xmx1024m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - +# # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +#Fri Dec 29 13:06:46 CET 2023 +android.enableJetifier=true +android.useAndroidX=true +org.gradle.jvmargs=-Xmx4g -Xms1g \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b019206..0f23ff6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Dec 02 21:40:22 CET 2014 +#Fri Dec 29 11:11:03 CET 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip