-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 6c34ae5)
- Loading branch information
Showing
13 changed files
with
252 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
base/src/com/google/idea/blaze/base/execution/BazelGuard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2024 The Bazel Authors. All rights reserved. | ||
* | ||
* 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.google.idea.blaze.base.execution; | ||
|
||
import com.intellij.openapi.extensions.ExtensionPointName; | ||
import com.intellij.openapi.project.Project; | ||
|
||
/** Interface for checking if tools execution is allowed for the imported project. */ | ||
public interface BazelGuard { | ||
|
||
ExtensionPointName<BazelGuard> EP_NAME = | ||
ExtensionPointName.create("com.google.idea.blaze.BlazeGuard"); | ||
|
||
void checkIsExecutionAllowed(Project project) throws ExecutionDeniedException; | ||
|
||
static void checkExtensionsIsExecutionAllowed(Project project) throws ExecutionDeniedException { | ||
for (var extension : EP_NAME.getExtensionList()) { | ||
extension.checkIsExecutionAllowed(project); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
base/src/com/google/idea/blaze/base/execution/ExecutionDeniedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2024 The Bazel Authors. All rights reserved. | ||
* | ||
* 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.google.idea.blaze.base.execution; | ||
|
||
/** Exception thrown when tool execution is denied. */ | ||
public class ExecutionDeniedException extends Exception { | ||
public ExecutionDeniedException(String message) { | ||
super(message); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
base/src/com/google/idea/blaze/base/execution/TrustedProjectGuard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024 The Bazel Authors. All rights reserved. | ||
* | ||
* 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.google.idea.blaze.base.execution; | ||
|
||
import com.intellij.ide.impl.TrustedProjects; | ||
import com.intellij.openapi.project.Project; | ||
|
||
/** A {@link BazelGuard} that only allows execution if the project is trusted. */ | ||
public class TrustedProjectGuard implements BazelGuard { | ||
@Override | ||
public void checkIsExecutionAllowed(Project project) throws ExecutionDeniedException { | ||
if (!TrustedProjects.isTrusted(project)) { | ||
throw new ExecutionDeniedException("Execution is not allowed because project is not trusted"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
base/src/com/google/idea/blaze/base/project/DefaultBazelProjectCreator.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
base/src/com/google/idea/blaze/base/project/TrustAwareProjectCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2024 The Bazel Authors. All rights reserved. | ||
* | ||
* 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.google.idea.blaze.base.project; | ||
|
||
import com.google.idea.blaze.base.settings.BuildSystemName; | ||
import com.intellij.ide.IdeBundle; | ||
import com.intellij.ide.impl.TrustedProjects; | ||
import com.intellij.ide.util.projectWizard.ProjectBuilder; | ||
import com.intellij.openapi.application.ApplicationInfo; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.MessageDialogBuilder; | ||
import java.util.Optional; | ||
import javax.annotation.Nullable; | ||
|
||
/** Creates a project if the user has trusted the project. */ | ||
public class TrustAwareProjectCreator implements ExtendableBazelProjectCreator { | ||
|
||
/** | ||
* Creates a project if the user has trusted the project. | ||
* | ||
* @param builder the project builder | ||
* @param name the name of the project | ||
* @param path the path to the project | ||
* @return the created project, null if the user did not trust the project | ||
*/ | ||
@Override | ||
public Optional<Project> createProject(ProjectBuilder builder, String name, String path) { | ||
if (!canCreateProject(null)) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(builder.createProject(name, path)); | ||
} | ||
|
||
/** Returns true if the user has trusted the project. */ | ||
@Override | ||
public boolean canCreateProject(@Nullable BuildSystemName buildSystemName) { | ||
var trustText = IdeBundle.message("untrusted.project.dialog.trust.button"); | ||
var dontOpenText = IdeBundle.message("untrusted.project.open.dialog.cancel.button"); | ||
|
||
var choice = | ||
new MessageDialogBuilder.Message( | ||
IdeBundle.message("untrusted.project.general.dialog.title"), | ||
IdeBundle.message( | ||
"untrusted.project.open.dialog.text", | ||
ApplicationInfo.getInstance().getFullApplicationName())) | ||
.buttons( | ||
IdeBundle.message("untrusted.project.dialog.trust.button"), | ||
IdeBundle.message("untrusted.project.open.dialog.cancel.button")) | ||
.defaultButton(trustText) | ||
.focusedButton(dontOpenText) | ||
.asWarning() | ||
.help(TrustedProjects.TRUSTED_PROJECTS_HELP_TOPIC) | ||
.show(null, null); | ||
|
||
return trustText.equals(choice); | ||
} | ||
} |
Oops, something went wrong.