Skip to content

Commit 42c0a12

Browse files
HackerMadCatintellij-monorepo-bot
authored andcommitted
[TrustedProjects] cleanup: introduce the public trusted projects API
The com.intellij.ide.trustedProjects.TrustedProjects utility object is open for public usage. Other stuff is internal or deprecated in favor of this API. ### Issues * IJPL-172505 Trusted Projects' API is marked as Experimental (cherry picked from commit a0f082950faadad8c855cde5090419293aa3646c) (cherry-pick approved by IJ-CR-159977) (cherry picked from commit 1560d86bb1a22b1e77f84be0e276937f7dc071f2) IJ-CR-159977 GitOrigin-RevId: 84a20c94b4bf42fc2d2b51c6aacfe66454bdf483
1 parent cd83683 commit 42c0a12

File tree

4 files changed

+96
-12
lines changed

4 files changed

+96
-12
lines changed

platform/platform-impl/api-dump-unreviewed.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,6 +4137,14 @@ f:com.intellij.ide.troubleshooting.CompositeGeneralTroubleInfoCollector
41374137
- com.intellij.troubleshooting.TroubleInfoCollector
41384138
- <init>():V
41394139
- collectInfo(com.intellij.openapi.project.Project):java.lang.String
4140+
f:com.intellij.ide.trustedProjects.TrustedProjects
4141+
- sf:INSTANCE:com.intellij.ide.trustedProjects.TrustedProjects
4142+
- sf:isProjectTrusted(com.intellij.openapi.project.Project):Z
4143+
- sf:isProjectTrusted(java.nio.file.Path):Z
4144+
- sf:isProjectTrusted(java.nio.file.Path,com.intellij.openapi.project.Project):Z
4145+
- sf:setProjectTrusted(com.intellij.openapi.project.Project,Z):V
4146+
- sf:setProjectTrusted(java.nio.file.Path,com.intellij.openapi.project.Project,Z):V
4147+
- sf:setProjectTrusted(java.nio.file.Path,Z):V
41404148
f:com.intellij.ide.trustedProjects.TrustedProjectsDialog
41414149
- sf:INSTANCE:com.intellij.ide.trustedProjects.TrustedProjectsDialog
41424150
- f:confirmLoadingUntrustedProject(com.intellij.openapi.project.Project,java.lang.String,java.lang.String,java.lang.String,java.lang.String):Z

platform/platform-impl/src/com/intellij/ide/impl/TrustedPaths.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class TrustedPaths : TrustedProjectsStateStorage<TrustedPaths.State>(State()) {
4646
}
4747
}
4848

49+
@Deprecated("Use TrustedProjects.setProjectTrusted(Path, Boolean) instead")
4950
fun setProjectPathTrusted(path: Path, value: Boolean) {
5051
updateState {
5152
State(it.trustedPaths + (path.toString() to value))

platform/platform-impl/src/com/intellij/ide/impl/TrustedProjects.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.intellij.ide.IdeBundle
88
import com.intellij.ide.trustedProjects.TrustedProjects
99
import com.intellij.ide.trustedProjects.TrustedProjectsDialog
1010
import com.intellij.ide.trustedProjects.TrustedProjectsListener
11-
import com.intellij.ide.trustedProjects.TrustedProjectsLocator
1211
import com.intellij.openapi.actionSystem.ActionUpdateThread
1312
import com.intellij.openapi.actionSystem.AnActionEvent
1413
import com.intellij.openapi.application.ApplicationManager
@@ -45,20 +44,38 @@ enum class OpenUntrustedProjectChoice {
4544
CANCEL;
4645
}
4746

47+
@Suppress("unused") // Used externally
48+
@Deprecated(
49+
"Use TrustedProjects.isProjectTrusted instead",
50+
ReplaceWith(
51+
"TrustedProjects.isProjectTrusted(this)",
52+
"com.intellij.ide.trustedProjects.TrustedProjects"
53+
)
54+
)
4855
fun Project.isTrusted(): Boolean {
49-
return TrustedProjects.isProjectTrusted(TrustedProjectsLocator.locateProject(this))
56+
return TrustedProjects.isProjectTrusted(this)
5057
}
5158

59+
@Suppress("unused") // Used externally
60+
@Deprecated(
61+
"Use TrustedProjects.setProjectTrusted instead",
62+
ReplaceWith(
63+
"TrustedProjects.setProjectTrusted(this, isTrusted)",
64+
"com.intellij.ide.trustedProjects.TrustedProjects"
65+
)
66+
)
5267
fun Project.setTrusted(isTrusted: Boolean) {
53-
TrustedProjects.setProjectTrusted(TrustedProjectsLocator.locateProject(this), isTrusted)
68+
TrustedProjects.setProjectTrusted(this, isTrusted)
5469
}
5570

5671
@Suppress("unused") // Used externally
72+
@Deprecated("Use TrustedProjects.isProjectTrusted instead")
5773
fun Project.getTrustedState(): ThreeState {
58-
return TrustedProjects.getProjectTrustedState(TrustedProjectsLocator.locateProject(this))
74+
return TrustedProjects.getProjectTrustedState(this)
5975
}
6076

6177
@Suppress("unused") // Used externally
78+
@Deprecated("Use TrustedProjects.isTrustedCheckDisabled instead")
6279
fun isTrustedCheckDisabled(): Boolean {
6380
return TrustedProjects.isTrustedCheckDisabled()
6481
}

platform/platform-impl/src/com/intellij/ide/trustedProjects/TrustedProjects.kt

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,65 @@ import com.intellij.ide.impl.TrustedPathsSettings
66
import com.intellij.ide.impl.TrustedProjectsStatistics
77
import com.intellij.ide.lightEdit.LightEdit
88
import com.intellij.ide.trustedProjects.TrustedProjectsLocator.LocatedProject
9-
import com.intellij.openapi.application.ApplicationManager
9+
import com.intellij.openapi.project.Project
1010
import com.intellij.util.ThreeState
11+
import com.intellij.util.application
1112
import org.jetbrains.annotations.ApiStatus
13+
import java.nio.file.Path
1214

13-
@ApiStatus.Internal
1415
object TrustedProjects {
15-
fun isProjectTrusted(locatedProject: LocatedProject): Boolean = getProjectTrustedState(locatedProject) == ThreeState.YES
1616

17+
@JvmStatic
18+
fun isProjectTrusted(project: Project): Boolean {
19+
return isProjectTrusted(TrustedProjectsLocator.locateProject(project))
20+
}
21+
22+
@JvmStatic
23+
fun setProjectTrusted(project: Project, isTrusted: Boolean) {
24+
setProjectTrusted(TrustedProjectsLocator.locateProject(project), isTrusted)
25+
}
26+
27+
@ApiStatus.Internal
28+
fun getProjectTrustedState(project: Project): ThreeState {
29+
return getProjectTrustedState(TrustedProjectsLocator.locateProject(project))
30+
}
31+
32+
@JvmStatic
33+
fun isProjectTrusted(path: Path): Boolean {
34+
return isProjectTrusted(path, project = null)
35+
}
36+
37+
@JvmStatic
38+
fun setProjectTrusted(path: Path, isTrusted: Boolean) {
39+
setProjectTrusted(path, project = null, isTrusted)
40+
}
41+
42+
@ApiStatus.Internal
43+
fun getProjectTrustedState(path: Path): ThreeState {
44+
return getProjectTrustedState(path, project = null)
45+
}
46+
47+
@JvmStatic
48+
fun isProjectTrusted(path: Path, project: Project?): Boolean {
49+
return isProjectTrusted(TrustedProjectsLocator.locateProject(path, project))
50+
}
51+
52+
@JvmStatic
53+
fun setProjectTrusted(path: Path, project: Project?, isTrusted: Boolean) {
54+
setProjectTrusted(TrustedProjectsLocator.locateProject(path, project), isTrusted)
55+
}
56+
57+
@ApiStatus.Internal
58+
fun getProjectTrustedState(path: Path, project: Project?): ThreeState {
59+
return getProjectTrustedState(TrustedProjectsLocator.locateProject(path, project))
60+
}
61+
62+
@ApiStatus.Internal
63+
fun isProjectTrusted(locatedProject: LocatedProject): Boolean {
64+
return getProjectTrustedState(locatedProject) == ThreeState.YES
65+
}
66+
67+
@ApiStatus.Internal
1768
fun getProjectTrustedState(locatedProject: LocatedProject): ThreeState {
1869
val explicitTrustedState = TrustedPaths.getInstance().getProjectTrustedState(locatedProject)
1970
return when {
@@ -28,13 +79,14 @@ object TrustedProjects {
2879
}
2980
}
3081

82+
@ApiStatus.Internal
3183
fun setProjectTrusted(locatedProject: LocatedProject, isTrusted: Boolean) {
3284
val trustedPaths = TrustedPaths.getInstance()
3385
val oldState = trustedPaths.getProjectTrustedState(locatedProject)
3486
trustedPaths.setProjectTrustedState(locatedProject, isTrusted)
3587
val newState = trustedPaths.getProjectTrustedState(locatedProject)
3688
if (oldState != newState) {
37-
val syncPublisher = ApplicationManager.getApplication().messageBus.syncPublisher(TrustedProjectsListener.TOPIC)
89+
val syncPublisher = application.messageBus.syncPublisher(TrustedProjectsListener.TOPIC)
3890
when (isTrusted) {
3991
true -> syncPublisher.onProjectTrusted(locatedProject)
4092
else -> syncPublisher.onProjectUntrusted(locatedProject)
@@ -43,12 +95,18 @@ object TrustedProjects {
4395
}
4496

4597
/**
46-
* Checks that IDEA is loaded with safe environment. In this mode, trusted checks aren't needed at all.
98+
* Checks that IDEA is loaded with a safe environment.
99+
* In this mode, all projects are trusted automatically.
47100
*/
101+
@ApiStatus.Internal
48102
fun isTrustedCheckDisabled(): Boolean {
49-
val app = ApplicationManager.getApplication()
50-
return app.isUnitTestMode || app.isHeadlessEnvironment || java.lang.Boolean.getBoolean("idea.trust.all.projects")
103+
return java.lang.Boolean.getBoolean("idea.trust.all.projects") ||
104+
application.isUnitTestMode ||
105+
application.isHeadlessEnvironment
51106
}
52107

53-
private fun isTrustedCheckDisabledForProduct(): Boolean = isTrustedCheckDisabled() || java.lang.Boolean.getBoolean("idea.trust.disabled")
108+
private fun isTrustedCheckDisabledForProduct(): Boolean {
109+
return java.lang.Boolean.getBoolean("idea.trust.disabled") ||
110+
isTrustedCheckDisabled()
111+
}
54112
}

0 commit comments

Comments
 (0)