From fcdbe6940a861fd38fc5d67485e8e6969db035b3 Mon Sep 17 00:00:00 2001 From: Pranav Purwar Date: Fri, 16 Aug 2024 16:48:17 +0530 Subject: [PATCH] fix: Fix string concatenation in Java and bump dependencies (#558) Bumped several dependencies to their latest versions, including: - com.android.tools:r8 to 8. 5.35 - androidx.lifecycle:lifecycle-runtime-ktx to 2.8.4 - androidx.appcompat:appcompat to 1.7.0 - androidx.fragment:fragment-ktx to 1.8.2 - androidx.activity:activity-ktx to 1.9.1 - androidx.core:core-ktx to 1.13.1 - com.google.android.material:material to 1.12.0 - androidx.annotation:annotation to 1.8.2 - com.google.gms:google-services to 4.4.2 Updated JavaAnalyzer to support custom compiler options, allowing users to pass flags like "-XDstringConcat=inline" to the Java compiler. Also, removed unnecessary license headers and cleaned up some code. Signed-off-by: Pranav Purwar --- .gitignore | 1 + ...kotlin-compiler-8214769348286012165.salive | 0 build-tools/build.gradle.kts | 2 +- .../cosmicide/build/java/JavaCompileTask.kt | 1 + .../analyzers/EditorDiagnosticsMarker.kt | 7 ++++- .../editor/analyzers/JavaAnalyzer.kt | 27 +++++++------------ build.gradle.kts | 2 +- datadir/build.gradle.kts | 2 +- feature/TreeView/build.gradle.kts | 6 ++--- .../main/res/drawable/outline_folder_24.xml | 11 ++------ .../drawable/outline_insert_drive_file_24.xml | 11 ++------ .../res/drawable/round_chevron_right_24.xml | 11 ++------ .../res/drawable/round_expand_more_24.xml | 11 ++------ .../main/res/layout/recycler_view_item.xml | 4 +-- .../TreeView/src/main/res/values/strings.xml | 9 +------ feature/appwrite/build.gradle.kts | 8 +++--- feature/completion/java/build.gradle.kts | 2 +- .../kotlin/completion/KotlinEnvironment.kt | 2 +- util/build.gradle.kts | 2 +- 19 files changed, 42 insertions(+), 77 deletions(-) delete mode 100644 .kotlin/sessions/kotlin-compiler-8214769348286012165.salive diff --git a/.gitignore b/.gitignore index e02b2f1a8..afc35293b 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,4 @@ lint/outputs/ lint/tmp/ # lint/reports/ /.idea/sonarlint/ +/.kotlin/ diff --git a/.kotlin/sessions/kotlin-compiler-8214769348286012165.salive b/.kotlin/sessions/kotlin-compiler-8214769348286012165.salive deleted file mode 100644 index e69de29bb..000000000 diff --git a/build-tools/build.gradle.kts b/build-tools/build.gradle.kts index a18933558..10ea15f66 100644 --- a/build-tools/build.gradle.kts +++ b/build-tools/build.gradle.kts @@ -56,5 +56,5 @@ dependencies { implementation("io.github.Rosemoe.sora-editor:editor:0.23.4-cac2770-SNAPSHOT") implementation("io.github.itsaky:nb-javac-android:17.0.0.3") implementation("com.google.guava:guava:33.1.0-android") - implementation("com.android.tools:r8:8.3.37") + implementation("com.android.tools:r8:8.5.35") } diff --git a/build-tools/src/main/java/org/cosmicide/build/java/JavaCompileTask.kt b/build-tools/src/main/java/org/cosmicide/build/java/JavaCompileTask.kt index 49d3c1294..fa1af3321 100644 --- a/build-tools/src/main/java/org/cosmicide/build/java/JavaCompileTask.kt +++ b/build-tools/src/main/java/org/cosmicide/build/java/JavaCompileTask.kt @@ -68,6 +68,7 @@ class JavaCompileTask(val project: Project) : Task { val flags = Prefs.javacFlags val options = listOf( + "-XDstringConcat=inline", "-proc:none", "-source", version, diff --git a/build-tools/src/main/java/org/cosmicide/editor/analyzers/EditorDiagnosticsMarker.kt b/build-tools/src/main/java/org/cosmicide/editor/analyzers/EditorDiagnosticsMarker.kt index e4f108698..4029077a2 100644 --- a/build-tools/src/main/java/org/cosmicide/editor/analyzers/EditorDiagnosticsMarker.kt +++ b/build-tools/src/main/java/org/cosmicide/editor/analyzers/EditorDiagnosticsMarker.kt @@ -16,6 +16,7 @@ import io.github.rosemoe.sora.widget.CodeEditor import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import org.cosmicide.common.Prefs import org.cosmicide.project.Project import java.io.File @@ -26,7 +27,11 @@ class EditorDiagnosticsMarker( ) : EventReceiver { private val diagnostics = DiagnosticsContainer() - private var analyzer = JavaAnalyzer(editor, project) + private var analyzer = JavaAnalyzer( + editor, + project, + if (Prefs.javacFlags.isNotEmpty()) Prefs.javacFlags.split(" ").toList() else listOf() + ) init { analyze(editor.text) diff --git a/build-tools/src/main/java/org/cosmicide/editor/analyzers/JavaAnalyzer.kt b/build-tools/src/main/java/org/cosmicide/editor/analyzers/JavaAnalyzer.kt index 29751c355..547b5ec15 100644 --- a/build-tools/src/main/java/org/cosmicide/editor/analyzers/JavaAnalyzer.kt +++ b/build-tools/src/main/java/org/cosmicide/editor/analyzers/JavaAnalyzer.kt @@ -7,7 +7,6 @@ package org.cosmicide.editor.analyzers -import android.util.Log import com.sun.tools.javac.api.JavacTool import com.sun.tools.javac.file.JavacFileManager import io.github.rosemoe.sora.lang.diagnostic.DiagnosticDetail @@ -28,10 +27,12 @@ import javax.tools.StandardLocation class JavaAnalyzer( val editor: CodeEditor, - val project: Project + val project: Project, + val compilerOptions: List = mutableListOf() ) { private val args by lazy { listOf( + "-XDstringConcat=inline", "-XDcompilePolicy=byfile", "-XD-Xprefer=source", "-XDide", @@ -62,8 +63,7 @@ class JavaAnalyzer( init { standardFileManager.setLocation( - StandardLocation.PLATFORM_CLASS_PATH, - FileUtil.classpathDir.walk().toList() + StandardLocation.PLATFORM_CLASS_PATH, FileUtil.classpathDir.walk().toList() ) if (!project.binDir.exists()) { project.binDir.mkdirs() @@ -86,6 +86,7 @@ class JavaAnalyzer( add(version.toString()) add("-target") add(version.toString()) + addAll(compilerOptions) } tool.getTask(System.out.writer(), standardFileManager, diagnostics, copy, null, toCompile) @@ -121,7 +122,6 @@ class JavaAnalyzer( if (it.code == "compiler.err.cant.resolve.location") { val symbol = it.source.getCharContent(true) .substring(it.startPosition.toInt(), it.endPosition.toInt()) - Log.d("JavaAnalyzer", symbol) CompletionProvider.symbolCacher.filterClassNames(symbol).forEach { name -> quickFixes.add(Quickfix("Import ${name.value}", 0L) { val lines = editor.text.lines() @@ -130,11 +130,8 @@ class JavaAnalyzer( firstImportLine = lines.indexOfFirst { it.startsWith("package ") } + 1 } - Log.d("JavaAnalyzer", "index: $firstImportLine") editor.text.insert( - firstImportLine, - 0, - "import ${name.key}.${name.value};\n" + firstImportLine, 0, "import ${name.key}.${name.value};\n" ) }) } @@ -166,15 +163,11 @@ class JavaAnalyzer( } - project.binDir - .resolve("classes") - .walk() - .filter { it.extension == "class" } - .forEach { - if (Cache.getCache(it) != null && Cache.getCache(it)!!.lastModified == it.lastModified()) { - classpath.add(it) - } + project.binDir.resolve("classes").walk().filter { it.extension == "class" }.forEach { + if (Cache.getCache(it) != null && Cache.getCache(it)!!.lastModified == it.lastModified()) { + classpath.add(it) } + } return classpath } diff --git a/build.gradle.kts b/build.gradle.kts index 9ddd6757d..035d97b94 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,6 +16,6 @@ plugins { buildscript { dependencies { - classpath("com.google.gms:google-services:4.4.1") + classpath("com.google.gms:google-services:4.4.2") } } diff --git a/datadir/build.gradle.kts b/datadir/build.gradle.kts index f03056fb6..ea031054f 100644 --- a/datadir/build.gradle.kts +++ b/datadir/build.gradle.kts @@ -33,5 +33,5 @@ android { dependencies { implementation(projects.util) implementation("de.maxr1998:modernandroidpreferences:2.3.2") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha03") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4") } diff --git a/feature/TreeView/build.gradle.kts b/feature/TreeView/build.gradle.kts index 717958b99..09bd8cf1e 100644 --- a/feature/TreeView/build.gradle.kts +++ b/feature/TreeView/build.gradle.kts @@ -40,7 +40,7 @@ android { } dependencies { - implementation("androidx.core:core-ktx:1.13.0-beta01") - implementation("androidx.appcompat:appcompat:1.7.0-alpha03") - implementation("com.google.android.material:material:1.12.0-beta01") + implementation("androidx.core:core-ktx:1.13.1") + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("com.google.android.material:material:1.12.0") } diff --git a/feature/TreeView/src/main/res/drawable/outline_folder_24.xml b/feature/TreeView/src/main/res/drawable/outline_folder_24.xml index 41becf5aa..b668a650c 100644 --- a/feature/TreeView/src/main/res/drawable/outline_folder_24.xml +++ b/feature/TreeView/src/main/res/drawable/outline_folder_24.xml @@ -5,19 +5,12 @@ ~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see . --> - - + android:fillColor="?colorOnSurfaceVariant" + android:pathData="M9.2,6l2,2H20v10H4V6h5.2M10,4H4c-1.1,0 -2,0.9 -2,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z" /> diff --git a/feature/TreeView/src/main/res/drawable/outline_insert_drive_file_24.xml b/feature/TreeView/src/main/res/drawable/outline_insert_drive_file_24.xml index f549cd880..6bef1cf75 100644 --- a/feature/TreeView/src/main/res/drawable/outline_insert_drive_file_24.xml +++ b/feature/TreeView/src/main/res/drawable/outline_insert_drive_file_24.xml @@ -5,13 +5,6 @@ ~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see . --> - - + android:fillColor="?colorOnSurfaceVariant" + android:pathData="M14,2H6c-1.1,0 -2,0.9 -2,2L4,20c0,1.1 0.9,2 2,2H18c1.1,0 2,-0.9 2,-2V8l-6,-6zM6,20V4h7v5h5v11H6z" /> diff --git a/feature/TreeView/src/main/res/drawable/round_chevron_right_24.xml b/feature/TreeView/src/main/res/drawable/round_chevron_right_24.xml index 02a797b3c..e81d91727 100644 --- a/feature/TreeView/src/main/res/drawable/round_chevron_right_24.xml +++ b/feature/TreeView/src/main/res/drawable/round_chevron_right_24.xml @@ -5,19 +5,12 @@ ~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see . --> - - + android:fillColor="?colorOnSurfaceVariant" + android:pathData="M9.3,6.7c-0.4,0.4 -0.4,1 0,1.4L13.2,12l-3.9,3.9c-0.4,0.4 -0.4,1 0,1.4 0.4,0.4 1,0.4 1.4,0l4.6,-4.6c0.4,-0.4 0.4,-1 0,-1.4L10.7,6.7c-0.4,-0.4 -1,-0.4 -1.4,0z" /> diff --git a/feature/TreeView/src/main/res/drawable/round_expand_more_24.xml b/feature/TreeView/src/main/res/drawable/round_expand_more_24.xml index ce2291012..ef5fd0d5c 100644 --- a/feature/TreeView/src/main/res/drawable/round_expand_more_24.xml +++ b/feature/TreeView/src/main/res/drawable/round_expand_more_24.xml @@ -5,19 +5,12 @@ ~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see . --> - - + android:fillColor="?colorOnSurfaceVariant" + android:pathData="M15.9,9.3L12,13.2 8.1,9.3c-0.4,-0.4 -1,-0.4 -1.4,0 -0.4,0.4 -0.4,1 0,1.4l4.6,4.6c0.4,0.4 1,0.4 1.4,0l4.6,-4.6c0.4,-0.4 0.4,-1 0,-1.4 -0.4,-0.4 -1,-0.4 -1.4,0z" /> diff --git a/feature/TreeView/src/main/res/layout/recycler_view_item.xml b/feature/TreeView/src/main/res/layout/recycler_view_item.xml index 36c8b4bb3..42568d781 100644 --- a/feature/TreeView/src/main/res/layout/recycler_view_item.xml +++ b/feature/TreeView/src/main/res/layout/recycler_view_item.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:paddingVertical="8dp"> + android:paddingVertical="12dp"> diff --git a/feature/TreeView/src/main/res/values/strings.xml b/feature/TreeView/src/main/res/values/strings.xml index a7a9c5d32..dbf0d360d 100644 --- a/feature/TreeView/src/main/res/values/strings.xml +++ b/feature/TreeView/src/main/res/values/strings.xml @@ -5,14 +5,7 @@ ~ You should have received a copy of the GNU General Public License along with Cosmic IDE. If not, see . --> - - File type Expand - \ No newline at end of file + diff --git a/feature/appwrite/build.gradle.kts b/feature/appwrite/build.gradle.kts index 4b09e1efe..8a3465182 100644 --- a/feature/appwrite/build.gradle.kts +++ b/feature/appwrite/build.gradle.kts @@ -44,9 +44,9 @@ dependencies { implementation("com.squareup.okhttp3:logging-interceptor") implementation("com.google.code.gson:gson:2.10.1") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.0-alpha03") - implementation("androidx.appcompat:appcompat:1.7.0-alpha03") - implementation("androidx.fragment:fragment-ktx:1.7.0-beta01") - implementation("androidx.activity:activity-ktx:1.9.0-beta01") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4") + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("androidx.fragment:fragment-ktx:1.8.2") + implementation("androidx.activity:activity-ktx:1.9.1") implementation("androidx.browser:browser:1.8.0") } diff --git a/feature/completion/java/build.gradle.kts b/feature/completion/java/build.gradle.kts index dc3f806cd..1f3ede2f9 100644 --- a/feature/completion/java/build.gradle.kts +++ b/feature/completion/java/build.gradle.kts @@ -34,7 +34,7 @@ dependencies { implementation("com.github.Cosmic-Ide.kotlinc-android:kotlinc:2a0a6a7291") implementation("com.google.auto.value:auto-value-annotations:1.10.4") implementation("io.github.itsaky:nb-javac-android:17.0.0.3") - implementation("androidx.annotation:annotation:1.8.0-alpha02") + implementation("androidx.annotation:annotation:1.8.2") implementation("com.google.code.gson:gson:2.10.1") api("com.google.guava:guava:33.1.0-android") diff --git a/feature/completion/kotlin/src/main/java/com/tyron/kotlin/completion/KotlinEnvironment.kt b/feature/completion/kotlin/src/main/java/com/tyron/kotlin/completion/KotlinEnvironment.kt index 75782d376..4dee4ca1f 100644 --- a/feature/completion/kotlin/src/main/java/com/tyron/kotlin/completion/KotlinEnvironment.kt +++ b/feature/completion/kotlin/src/main/java/com/tyron/kotlin/completion/KotlinEnvironment.kt @@ -523,7 +523,7 @@ data class KotlinEnvironment( setupIdeaStandaloneExecution() return KotlinEnvironment( KotlinCoreEnvironment.createForProduction( - parentDisposable = {}, + {}, configFiles = EnvironmentConfigFiles.JVM_CONFIG_FILES, configuration = CompilerConfiguration().apply { diff --git a/util/build.gradle.kts b/util/build.gradle.kts index b291419f0..015cd5727 100644 --- a/util/build.gradle.kts +++ b/util/build.gradle.kts @@ -36,5 +36,5 @@ android { dependencies { implementation("de.maxr1998:modernandroidpreferences:2.3.2") implementation(projects.feature.aliuhook) - implementation("androidx.core:core-ktx:1.13.0-beta01") + implementation("androidx.core:core-ktx:1.13.1") }