mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: avoid using ServiceLoader in test environment
This commit is contained in:
Generated
-1
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ANTLRGenerationPreferences">
|
||||
<option name="perGrammarGenerationSettings">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
plugins{
|
||||
id("com.android.library")
|
||||
id("kotlin-android")
|
||||
id("kotlin-kapt")
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -8,11 +9,14 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
kapt(libs.google.auto.service)
|
||||
|
||||
implementation(projects.common)
|
||||
implementation(projects.resources)
|
||||
implementation(libs.common.editor)
|
||||
implementation(libs.common.kotlin)
|
||||
implementation(libs.common.utilcode)
|
||||
implementation(libs.google.auto.service.annotations)
|
||||
|
||||
implementation(libs.androidx.ktx)
|
||||
implementation(libs.google.material)
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package com.itsaky.androidide.actions
|
||||
|
||||
import android.view.Menu
|
||||
import com.itsaky.androidide.actions.internal.DefaultActionsRegistry
|
||||
import com.itsaky.androidide.utils.ServiceLoader
|
||||
import com.itsaky.androidide.utils.VMUtils
|
||||
|
||||
/** @author Akash Yadav */
|
||||
abstract class ActionsRegistry {
|
||||
@@ -29,7 +31,9 @@ abstract class ActionsRegistry {
|
||||
@JvmStatic
|
||||
fun getInstance(): ActionsRegistry {
|
||||
if (instance == null) {
|
||||
instance = ServiceLoader.load(ActionsRegistry::class.java).findFirstOrThrow()
|
||||
instance = if (VMUtils.isJvm()) {
|
||||
DefaultActionsRegistry()
|
||||
} else ServiceLoader.load(ActionsRegistry::class.java).findFirstOrThrow()
|
||||
}
|
||||
|
||||
return instance as ActionsRegistry
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.itsaky.androidide.services
|
||||
package com.itsaky.androidide.actions.internal
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.PorterDuff.Mode.SRC_ATOP
|
||||
@@ -23,7 +23,7 @@ import com.itsaky.androidide.actions.ActionData
|
||||
import com.itsaky.androidide.actions.ActionItem.Location.EDITOR_FILE_TREE
|
||||
import com.itsaky.androidide.actions.ActionMenu
|
||||
import com.itsaky.androidide.actions.ActionsRegistry
|
||||
import com.itsaky.androidide.services.DefaultActionsRegistry
|
||||
import com.itsaky.androidide.actions.internal.DefaultActionsRegistry
|
||||
import com.itsaky.androidide.activities.editor.EditorHandlerActivity
|
||||
import com.itsaky.androidide.eventbus.events.filetree.FileClickEvent
|
||||
import com.itsaky.androidide.eventbus.events.filetree.FileLongClickEvent
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
|
||||
package com.itsaky.androidide.lookup;
|
||||
|
||||
import com.itsaky.androidide.lookup.internal.DefaultLookup;
|
||||
import com.itsaky.androidide.utils.ServiceLoader;
|
||||
import com.itsaky.androidide.utils.VMUtils;
|
||||
|
||||
/**
|
||||
* Provides instance of {@link Lookup}.
|
||||
@@ -34,6 +36,12 @@ class LookupProvider {
|
||||
if (sLookup != null) {
|
||||
return sLookup;
|
||||
}
|
||||
|
||||
if (VMUtils.isJvm()) {
|
||||
// When in a test environment, load the default lookup
|
||||
return sLookup = new DefaultLookup();
|
||||
}
|
||||
|
||||
return sLookup = ServiceLoader.load(Lookup.class).findFirstOrThrow();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.services;
|
||||
package com.itsaky.androidide.lookup.internal;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.itsaky.androidide.lookup.Lookup;
|
||||
Reference in New Issue
Block a user