Skip to content

Commit

Permalink
Break build if active plugins are not in app scope (#4977)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1198194956794324/1208197444733454/f

### Description
Active plugins can only be used in AppScope. Break the build if they're wrongly scoped.

### Steps to test this PR
_Test_
* Change the scope of an already existing plugin (eg. `AutofillNewTabShortcutPlugin`)
* clean build
[ ] verify build fails with proper message
  • Loading branch information
aitorvs authored Sep 6, 2024
1 parent afd2226 commit f47aa81
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class ContributesActivePluginPointCodeGenerator : CodeGenerator {
element = vmClass.clazz.identifyingElement,
)
}
if (scope.fqName != appScopeFqName) {
throw AnvilCompilationException(
"${vmClass.fqName}: Active plugins can only be used in 'AppScope'.",
element = vmClass.clazz.identifyingElement,
)
}

val content = FileSpec.buildFile(generatedPackage, pluginPointClassFileName) {
// This is the normal plugin point
Expand Down Expand Up @@ -332,6 +338,12 @@ class ContributesActivePluginPointCodeGenerator : CodeGenerator {
element = vmClass.clazz.identifyingElement,
)
}
if (scope.fqName != appScopeFqName) {
throw AnvilCompilationException(
"${vmClass.fqName}: Active plugins can only be used in 'AppScope'.",
element = vmClass.clazz.identifyingElement,
)
}

val content = FileSpec.buildFile(generatedPackage, pluginClassName) {
// First create the class that will contribute the active plugin.
Expand Down Expand Up @@ -626,5 +638,6 @@ class ContributesActivePluginPointCodeGenerator : CodeGenerator {
private val appCoroutineScopeFqName = FqName("com.duckduckgo.app.di.AppCoroutineScope")
private val sharedPreferencesFqName = FqName("android.content.SharedPreferences")
private val jsonAdapterFqName = FqName("com.squareup.moshi.JsonAdapter")
private val appScopeFqName = FqName("com.duckduckgo.di.scopes.AppScope")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ package com.duckduckgo.app.browser.newtab
import android.content.Context
import android.view.View
import com.duckduckgo.anvil.annotations.ContributesActivePlugin
import com.duckduckgo.anvil.annotations.ContributesActivePluginPoint
import com.duckduckgo.common.utils.plugins.ActivePluginPoint
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.newtabpage.api.FocusedViewPlugin
import com.squareup.anvil.annotations.ContributesBinding
import javax.inject.Inject
Expand All @@ -34,7 +33,7 @@ interface FocusedViewProvider {
}

@ContributesBinding(
scope = ActivityScope::class,
scope = AppScope::class,
)
class RealFocusedViewProvider @Inject constructor(
private val focusedViewVersions: ActivePluginPoint<FocusedViewPlugin>,
Expand All @@ -46,7 +45,7 @@ class RealFocusedViewProvider @Inject constructor(
}

@ContributesActivePlugin(
scope = ActivityScope::class,
scope = AppScope::class,
boundType = FocusedViewPlugin::class,
priority = FocusedViewPlugin.PRIORITY_LEGACY_FOCUSED_PAGE,
supportExperiments = true,
Expand All @@ -59,7 +58,7 @@ class FocusedLegacyPage @Inject constructor() : FocusedViewPlugin {
}

@ContributesActivePlugin(
scope = ActivityScope::class,
scope = AppScope::class,
boundType = FocusedViewPlugin::class,
priority = FocusedViewPlugin.PRIORITY_NEW_FOCUSED_PAGE,
defaultActiveValue = false,
Expand All @@ -72,9 +71,3 @@ class FocusedPage @Inject constructor() : FocusedViewPlugin {
return FocusedView(context)
}
}

@ContributesActivePluginPoint(
scope = ActivityScope::class,
boundType = FocusedViewPlugin::class,
)
private interface FocusedViewPluginPointTrigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.newtabpage.impl

import com.duckduckgo.anvil.annotations.ContributesActivePluginPoint
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.newtabpage.api.FocusedViewPlugin

@ContributesActivePluginPoint(
scope = AppScope::class,
boundType = FocusedViewPlugin::class,
)
private interface FocusedViewPluginPointTrigger

0 comments on commit f47aa81

Please sign in to comment.