Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 636666969
  • Loading branch information
mai93 authored and Copybara-Service committed May 23, 2024
1 parent f3cb334 commit 3d74d46
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
2 changes: 2 additions & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@
<applicationService serviceImplementation="com.google.idea.blaze.base.wizard2.BlazeWizardUserSettingsStorage"/>
<applicationService serviceInterface="com.google.idea.blaze.base.wizard2.BlazeWizardOptionProvider"
serviceImplementation="com.google.idea.blaze.base.wizard2.BazelWizardOptionProvider"/>
<applicationService serviceInterface="com.google.idea.blaze.base.project.ExtendableBazelProjectCreator"
serviceImplementation="com.google.idea.blaze.base.project.DefaultBazelProjectCreator"/>
<projectService serviceInterface="com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverProvider"
serviceImplementation="com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverProviderImpl"/>
<projectService serviceInterface="com.google.idea.blaze.base.sync.projectview.WorkspaceFileFinder$Provider"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.intellij.ide.util.projectWizard.ProjectBuilder;
import com.intellij.openapi.project.Project;

/** Default implementation of {@link ExtendableBazelProjectCreator}. */
public class DefaultBazelProjectCreator implements ExtendableBazelProjectCreator {

@Override
public Project createProject(ProjectBuilder builder, String name, String path) {
return builder.createProject(name, path);
}

@Override
public boolean canCreateProject() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.intellij.ide.util.projectWizard.ProjectBuilder;
import com.intellij.openapi.project.Project;

/** Interface for creating a project with additional configuration. */
public interface ExtendableBazelProjectCreator {
/**
* Creates a project with additional configuration.
*
* @param builder the project builder
* @param name the name of the project
* @param path the path to the project
* @return the created project
*/
public Project createProject(ProjectBuilder builder, String name, String path);

/** Returns true if the project can be created. */
public boolean canCreateProject();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.idea.blaze.base.wizard2;

import com.google.idea.blaze.base.project.ExtendableBazelProjectCreator;
import com.google.idea.sdkcompat.general.BaseSdkCompat;
import com.intellij.ide.SaveAndSyncHandler;
import com.intellij.ide.impl.ProjectUtil;
Expand Down Expand Up @@ -104,7 +105,10 @@ public BlazeProjectCreator.CreatedProjectDescriptor createProject(
FileUtil.ensureExists(ideaDir);
}

Project newProject = projectBuilder.createProject(projectName, projectFilePath);
Project newProject =
ApplicationManager.getApplication()
.getService(ExtendableBazelProjectCreator.class)
.createProject(projectBuilder, projectName, projectFilePath);
if (newProject == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.base.project.ExtendableBazelProjectCreator;
import com.google.idea.blaze.base.wizard2.BlazeNewProjectBuilder;
import com.google.idea.blaze.base.wizard2.BlazeProjectCommitException;
import com.google.idea.blaze.base.wizard2.BlazeSelectWorkspaceOption;
Expand All @@ -25,6 +26,8 @@
import com.google.idea.blaze.base.wizard2.TopLevelSelectWorkspaceOption;
import com.google.idea.blaze.base.wizard2.WorkspaceTypeList;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.CancelledConfigurationException;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.ui.IdeBorderFactory.PlainSmallWithoutIndent;
import com.intellij.ui.components.JBScrollPane;
Expand Down Expand Up @@ -152,6 +155,12 @@ public JComponent getUiComponent() {
}

public void validateAndUpdateBuilder() throws ConfigurationException {
if (!ApplicationManager.getApplication()
.getService(ExtendableBazelProjectCreator.class)
.canCreateProject()) {
throw new CancelledConfigurationException();
}

getSelectedOption().validateAndUpdateBuilder(builder);
}

Expand Down

0 comments on commit 3d74d46

Please sign in to comment.