From 9876292bcdb0b823d14383a4c6e2d987f62a61c7 Mon Sep 17 00:00:00 2001 From: djamn Date: Fri, 14 Mar 2025 16:42:24 +0100 Subject: [PATCH 01/18] migrated ci from java to kotlin --- .idea/compiler.xml | 2 +- .idea/gradle.xml | 3 +- .idea/misc.xml | 3 +- .idea/vcs.xml | 3 +- app/build.gradle | 77 ------------------- app/build.gradle.kts | 59 ++++++++++++++ .../testapp/ExampleInstrumentedTest.java | 26 ------- .../jamnig/testapp/ExampleInstrumentedTest.kt | 24 ++++++ app/src/main/AndroidManifest.xml | 4 +- .../java/net/jamnig/testapp/MainActivity.java | 17 ---- .../java/net/jamnig/testapp/MainActivity.kt | 47 +++++++++++ .../java/net/jamnig/testapp/ui/theme/Color.kt | 11 +++ .../java/net/jamnig/testapp/ui/theme/Theme.kt | 58 ++++++++++++++ .../java/net/jamnig/testapp/ui/theme/Type.kt | 34 ++++++++ app/src/main/res/layout/activity_main.xml | 9 --- app/src/main/res/values-night/themes.xml | 16 ---- app/src/main/res/values/themes.xml | 19 +---- app/src/main/res/xml/backup_rules.xml | 2 +- .../net/jamnig/testapp/ExampleUnitTest.java | 14 ---- .../net/jamnig/testapp/ExampleUnitTest.kt | 17 ++++ build.gradle | 4 - build.gradle.kts | 6 ++ gradle.properties | 6 +- gradle/libs.versions.toml | 38 +++++---- gradle/wrapper/gradle-wrapper.properties | 4 +- settings.gradle => settings.gradle.kts | 11 ++- 26 files changed, 307 insertions(+), 207 deletions(-) delete mode 100644 app/build.gradle create mode 100644 app/build.gradle.kts delete mode 100644 app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.java create mode 100644 app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.kt delete mode 100644 app/src/main/java/net/jamnig/testapp/MainActivity.java create mode 100644 app/src/main/java/net/jamnig/testapp/MainActivity.kt create mode 100644 app/src/main/java/net/jamnig/testapp/ui/theme/Color.kt create mode 100644 app/src/main/java/net/jamnig/testapp/ui/theme/Theme.kt create mode 100644 app/src/main/java/net/jamnig/testapp/ui/theme/Type.kt delete mode 100644 app/src/main/res/layout/activity_main.xml delete mode 100644 app/src/main/res/values-night/themes.xml delete mode 100644 app/src/test/java/net/jamnig/testapp/ExampleUnitTest.java create mode 100644 app/src/test/java/net/jamnig/testapp/ExampleUnitTest.kt delete mode 100644 build.gradle create mode 100644 build.gradle.kts rename settings.gradle => settings.gradle.kts (55%) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b589d56..b86273d 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 0897082..97f0a8e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,9 +1,9 @@ - diff --git a/.idea/misc.xml b/.idea/misc.xml index 8978d23..74dd639 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,7 @@ + - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 288b36b..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,7 +1,6 @@ - - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index d287568..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,77 +0,0 @@ -plugins { - alias(libs.plugins.androidApplication) - id 'jacoco' - id "org.sonarqube" version "4.4.1.3373" -} - -android { - namespace 'net.jamnig.testapp' - compileSdk 34 - - defaultConfig { - applicationId "net.jamnig.testapp" - minSdk 29 - targetSdk 34 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - testOptions { - unitTests.all { - useJUnitPlatform() - finalizedBy jacocoTestReport - } - } -} - -tasks.register('jacocoTestReport', JacocoReport) { - dependsOn 'testDebugUnitTest' - - reports { - xml.required = true - xml.destination file("${project.projectDir}/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml") - } - - def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] - def debugTree = fileTree(dir: "${project.layout.buildDirectory.get().asFile}/intermediates/javac/debug", excludes: fileFilter) - def mainSrc = "${project.projectDir}/src/main/java" - - sourceDirectories.from = files([mainSrc]) - classDirectories.from = files([debugTree]) - executionData.from = files("${project.layout.buildDirectory.get().asFile}/jacoco/testDebugUnitTest.exec") -} - -sonar { - properties { - property "sonar.projectKey", "uni-aau_github-ci" - property "sonar.organization", "uni-aau" - property "sonar.host.url", "https://sonarcloud.io" - property "sonar.java.coveragePlugin", "jacoco" - property "sonar.coverage.jacoco.xmlReportPaths", "${project.projectDir}/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml" - } -} - -dependencies { - implementation libs.activity - implementation libs.appcompat - implementation libs.material - implementation libs.constraintlayout - testImplementation libs.junit - testImplementation libs.junit.jupiter.api - testRuntimeOnly libs.junit.jupiter.engine - androidTestImplementation libs.ext.junit - androidTestImplementation libs.espresso.core -} \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..fc0d945 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,59 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) +} + +android { + namespace = "net.jamnig.testapp" + compileSdk = 35 + + defaultConfig { + applicationId = "net.jamnig.testapp" + minSdk = 30 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } + buildFeatures { + compose = true + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.ui) + implementation(libs.androidx.ui.graphics) + implementation(libs.androidx.ui.tooling.preview) + implementation(libs.androidx.material3) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.ui.test.junit4) + debugImplementation(libs.androidx.ui.tooling) + debugImplementation(libs.androidx.ui.test.manifest) +} \ No newline at end of file diff --git a/app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.java b/app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.java deleted file mode 100644 index 87d8e8f..0000000 --- a/app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.jamnig.testapp; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -//@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("net.jamnig.testapp", appContext.getPackageName()); - } -} \ No newline at end of file diff --git a/app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.kt b/app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..e149f55 --- /dev/null +++ b/app/src/androidTest/java/net/jamnig/testapp/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package net.jamnig.testapp + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("net.jamnig.testapp", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a042090..c565e5f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,9 @@ tools:targetApi="31"> + android:exported="true" + android:label="@string/app_name" + android:theme="@style/Theme.TestApp"> diff --git a/app/src/main/java/net/jamnig/testapp/MainActivity.java b/app/src/main/java/net/jamnig/testapp/MainActivity.java deleted file mode 100644 index 2ddf583..0000000 --- a/app/src/main/java/net/jamnig/testapp/MainActivity.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.jamnig.testapp; - -import androidx.appcompat.app.AppCompatActivity; - -import android.os.Bundle; -import android.util.Log; - -public class MainActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - Log.d("TAG", "Hello World!"); - } -} \ No newline at end of file diff --git a/app/src/main/java/net/jamnig/testapp/MainActivity.kt b/app/src/main/java/net/jamnig/testapp/MainActivity.kt new file mode 100644 index 0000000..7542ece --- /dev/null +++ b/app/src/main/java/net/jamnig/testapp/MainActivity.kt @@ -0,0 +1,47 @@ +package net.jamnig.testapp + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import net.jamnig.testapp.ui.theme.TestAppTheme + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContent { + TestAppTheme { + Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> + Greeting( + name = "Android", + modifier = Modifier.padding(innerPadding) + ) + } + } + } + } +} + +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + Text( + text = "Hello $name!", + modifier = modifier + ) +} + +@Preview(showBackground = true) +@Composable +fun GreetingPreview() { + TestAppTheme { + Greeting("Android") + } +} \ No newline at end of file diff --git a/app/src/main/java/net/jamnig/testapp/ui/theme/Color.kt b/app/src/main/java/net/jamnig/testapp/ui/theme/Color.kt new file mode 100644 index 0000000..7ad0a7e --- /dev/null +++ b/app/src/main/java/net/jamnig/testapp/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package net.jamnig.testapp.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/app/src/main/java/net/jamnig/testapp/ui/theme/Theme.kt b/app/src/main/java/net/jamnig/testapp/ui/theme/Theme.kt new file mode 100644 index 0000000..cc08215 --- /dev/null +++ b/app/src/main/java/net/jamnig/testapp/ui/theme/Theme.kt @@ -0,0 +1,58 @@ +package net.jamnig.testapp.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun TestAppTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/net/jamnig/testapp/ui/theme/Type.kt b/app/src/main/java/net/jamnig/testapp/ui/theme/Type.kt new file mode 100644 index 0000000..8d2cd0f --- /dev/null +++ b/app/src/main/java/net/jamnig/testapp/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package net.jamnig.testapp.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 895f007..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml deleted file mode 100644 index 43bf1ff..0000000 --- a/app/src/main/res/values-night/themes.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 0c7ca4f..2814b87 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,16 +1,5 @@ - - - + + + +