Skip to content

Commit

Permalink
fix: finalize indexing API; remove api versions index
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Jul 20, 2024
1 parent f3e460c commit c3e1330
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 183 deletions.
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {
implementation(libs.common.retrofit.gson)
implementation(libs.common.charts)
implementation(libs.common.hiddenApiBypass)
implementation(libs.aapt2.common)

implementation(libs.google.auto.service.annotations)
implementation(libs.google.gson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/

package com.itsaky.androidide.indexing.core.internal.platform
package com.itsaky.androidide.indexing.platform

import com.google.auto.service.AutoService
import com.itsaky.androidide.indexing.IIndexService
import com.itsaky.androidide.progress.IProgressIndicator
import com.itsaky.androidide.projects.api.Project
import org.slf4j.LoggerFactory
import java.io.File

/**
Expand All @@ -29,19 +29,26 @@ import java.io.File
@AutoService(IIndexService::class)
internal class PlatformIndexService : IIndexService {

companion object {
private val log = LoggerFactory.getLogger(PlatformIndexService::class.java)
}

override val displayName: String
get() = "Android Platform Indexing Service"

override fun scanFiles(project: Project): Collection<File> {
return mutableListOf<File>().apply {
project.findAndroidModules().forEach { androidModule ->
add(androidModule.getPlatformDir() ?: return@forEach)
add(androidModule.getPlatformDir()?.also {
log.debug("Adding {} to the list of indexable paths", it)
} ?: return@forEach)
}
}
}

override suspend fun indexFiles(
project: Project,
progress: IProgressIndicator,
files: Collection<File>
) {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.itsaky.androidide.projects.api.AndroidModule
import com.itsaky.androidide.projects.api.ModuleProject
import com.itsaky.androidide.projects.api.Project
import com.itsaky.androidide.projects.builder.BuildService
import com.itsaky.androidide.projects.util.ProjectTransformer
import com.itsaky.androidide.tasks.executeAsync
import com.itsaky.androidide.tooling.api.IAndroidProject
import com.itsaky.androidide.tooling.api.IProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/

package com.itsaky.androidide.projects.util
package com.itsaky.androidide.projects

import com.itsaky.androidide.projects.api.AndroidModule
import com.itsaky.androidide.projects.api.GradleProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import io.realm.Realm
* @property params The index parameters.
* @author Akash Yadav
*/
abstract class AbstractDBIndex<T : IIndexable, C : IIndexParams>(
abstract class AbstractDBIndex<T : IIndexable>(
protected val params: IIndexParams?
) : IIndex<T, C> {
) : IDatabaseIndex<T> {

protected abstract val realm: Realm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/

package com.itsaky.androidide.indexing.core.platform
package com.itsaky.androidide.indexing

import com.itsaky.androidide.indexing.IIndexParams
import com.itsaky.androidide.indexing.core.platform.IApiVersionsIndex.Params
import io.realm.RealmQuery

/**
* Index which provides access to the API versions informations (`api-versions.xml`) from the
* Android SDK.
* An index which is stored in the database.
*
* @author Akash Yadav
*/
interface IApiVersionsIndex : IPlatformIndex<ClassOrMemberInfo, Params> {
interface IDatabaseIndex<IndexableT : IIndexable> : IIndex<IndexableT> {

class Params(
val platformId: String
) : IIndexParams
/**
* Perform a query on the Realm database.
*/
fun query(): RealmQuery<IndexableT>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.itsaky.androidide.db.IRealmProvider
*
* @author Akash Yadav
*/
interface IIndex<IndexableT : IIndexable, ConfigT : IIndexParams> {
interface IIndex<IndexableT : IIndexable> {

companion object {

Expand All @@ -36,7 +36,7 @@ interface IIndex<IndexableT : IIndexable, ConfigT : IIndexParams> {
/**
* Base path for indices.
*/
const val INDEX_BASE_PATH = "${IRealmProvider.PATH_SEPARATOR}index"
val INDEX_BASE_PATH = createIndexPath("", "index")

private const val DEF_IS_ASYNC = true

Expand Down Expand Up @@ -91,9 +91,9 @@ interface IIndex<IndexableT : IIndexable, ConfigT : IIndexParams> {
*
* @return The created sub-index.
*/
fun <I : IIndexable, C : IIndexParams> createSubIndex(
fun <I : IIndexable> createSubIndex(
params: IIndexParams? = null
): IIndex<I, C> {
): IIndex<I> {
throw UnsupportedOperationException()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface IIndexFactory<I : IIndexable, P : IIndexParams> {
* @return The created [IIndex].
*/
@Throws(NotFoundException::class)
fun create(): IIndex<I, P>
fun create(): IIndex<I>

companion object {

Expand Down Expand Up @@ -99,10 +99,10 @@ interface IIndexFactory<I : IIndexable, P : IIndexParams> {
return factory
}

val impls = ServiceLoader.load(symTyp).iterator()
val impls = ServiceLoader.load(IIndexFactory::class.java).iterator()
while (impls.hasNext()) {
val impl = impls.next()
if (impl is IIndexFactory<*, *> && symTyp == impl.indexableType()) {
if (symTyp == impl.indexableType()) {
if (factory == null) {
factory = impl as IIndexFactory<T, P>
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package com.itsaky.androidide.indexing

/**
* Index configuration
* Index configuration parameters. All implementations of this interface must implement the
* [Object.equals] and [Object.hashCode] methods properly as the parameters may be used to cache
* the index implementations in [IIndexFactory]s.
*
* @author Akash Yadav
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.itsaky.androidide.indexing

import com.itsaky.androidide.progress.IProgressIndicator
import com.itsaky.androidide.projects.api.Project
import kotlinx.coroutines.Deferred
import java.io.File
Expand All @@ -29,6 +28,11 @@ import java.io.File
*/
interface IIndexService {

/**
* The display name of the service.
*/
val displayName: String

/**
* Called to scan files that need to be indexed by this index service.
*
Expand All @@ -41,8 +45,7 @@ interface IIndexService {
* Called to index the given files.
*
* @param project The root project model which can be used to query the project properties.
* @param progress An [IProgressIndicator] to report progress of the indexing process.
* @param files The files to index.
*/
suspend fun indexFiles(project: Project, progress: IProgressIndicator, files: Collection<File>)
suspend fun indexFiles(project: Project, files: Collection<File>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ import io.realm.RealmModel
*
* @author Akash Yadav
*/
interface IIndexable : RealmModel {
}
interface IIndexable : RealmModel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.indexing.core

import io.realm.annotations.RealmModule

/**
* @author Akash Yadav
*/
@RealmModule(classes = [])
class IndexingCoreRealmModule

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ open class ApiVersionsParser {
consumeEndElement(event.asEndElement())
}
}

onFinishParse()
}

/**
* Called when the parser is done parsing the `api-versions.xml` file.
*/
protected open fun onFinishParse() {}

private fun consumeStartElement(event: StartElement) {
when (event.name.localPart) {
"api" -> apiVersion = event.getAttributeByName(QName("version")).value.toInt()
Expand Down Expand Up @@ -110,6 +117,12 @@ open class ApiVersionsParser {
return false
}

/**
* Consume [ApiVersion] info of a class.
*
* @param name The fully qualified name of the class in its internal form.
* @param apiVersion The [ApiVersion] info of the class.
*/
protected open fun consumeClassVersionInfo(name: String, apiVersion: ApiVersion) {}

private fun consumeMember(event: StartElement, memberType: String) {
Expand All @@ -130,6 +143,14 @@ open class ApiVersionsParser {
return false
}

/**
* Consume [ApiVersion] info for a member of a class.
*
* @param className The name of the class which declares this member.
* @param member The identifier of the member. This is the name of the field and the method signature for methods.
* @param memberType The type of member. This may be "field" or "method".
* @param apiVersion The [ApiVersion] info.
*/
protected open fun consumeMemberVersionInfo(
className: String,
member: String,
Expand Down
Loading

0 comments on commit c3e1330

Please sign in to comment.