mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-250250 broken extension must not break "New Project" action
GitOrigin-RevId: 58c373558b48dd9fd83bee61de7dc38e7c071f12
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b5faf2138a
commit
4507f51b8a
@@ -1,21 +1,14 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.projectWizard;
|
||||
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkRole;
|
||||
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public abstract class ProjectCategory {
|
||||
|
||||
public static final ExtensionPointName<ProjectCategory> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.projectWizard.projectCategory");
|
||||
|
||||
@NotNull
|
||||
public abstract ModuleBuilder createModuleBuilder();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.module.WebModuleTypeBase;
|
||||
@@ -68,8 +69,10 @@ import java.util.*;
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, Disposable {
|
||||
private static final Logger LOG = Logger.getInstance(ProjectTypeStep.class);
|
||||
private static final ExtensionPointName<ProjectCategory> EP_NAME =
|
||||
new ExtensionPointName<>("com.intellij.projectWizard.projectCategory");
|
||||
|
||||
private static final Convertor<FrameworkSupportInModuleProvider,String> PROVIDER_STRING_CONVERTOR =
|
||||
private static final Convertor<FrameworkSupportInModuleProvider, String> PROVIDER_STRING_CONVERTOR =
|
||||
o -> o.getId();
|
||||
private static final Function<FrameworkSupportNode, String> NODE_STRING_FUNCTION = FrameworkSupportNodeBase::getId;
|
||||
private static final String TEMPLATES_CARD = "templates card";
|
||||
@@ -246,35 +249,37 @@ public final class ProjectTypeStep extends ModuleWizardStep implements SettingsS
|
||||
return FRAMEWORKS_CARD.equals(myCurrentCard) && getSelectedBuilder().equals(myContext.getProjectBuilder());
|
||||
}
|
||||
|
||||
private List<TemplatesGroup> fillTemplatesMap(WizardContext context) {
|
||||
|
||||
private @NotNull List<TemplatesGroup> fillTemplatesMap(@NotNull WizardContext context) {
|
||||
List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
|
||||
if (context.isCreatingNewProject()) {
|
||||
builders.add(new EmptyModuleBuilder());
|
||||
}
|
||||
Map<String, TemplatesGroup> groupMap = new HashMap<>();
|
||||
for (ModuleBuilder builder : builders) {
|
||||
BuilderBasedTemplate template = new BuilderBasedTemplate(builder);
|
||||
if (builder.isTemplate()) {
|
||||
TemplatesGroup group = groupMap.get(builder.getGroupName());
|
||||
if (group == null) {
|
||||
group = new TemplatesGroup(builder);
|
||||
try {
|
||||
BuilderBasedTemplate template = new BuilderBasedTemplate(builder);
|
||||
if (builder.isTemplate()) {
|
||||
TemplatesGroup group = groupMap.get(builder.getGroupName());
|
||||
if (group == null) {
|
||||
group = new TemplatesGroup(builder);
|
||||
}
|
||||
myTemplatesMap.putValue(group, template);
|
||||
}
|
||||
else {
|
||||
TemplatesGroup group = new TemplatesGroup(builder);
|
||||
groupMap.put(group.getName(), group);
|
||||
myTemplatesMap.put(group, new ArrayList<>());
|
||||
}
|
||||
myTemplatesMap.putValue(group, template);
|
||||
}
|
||||
else {
|
||||
TemplatesGroup group = new TemplatesGroup(builder);
|
||||
groupMap.put(group.getName(), group);
|
||||
myTemplatesMap.put(group, new ArrayList<>());
|
||||
catch (Throwable e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
MultiMap<TemplatesGroup, ProjectTemplate> map = getTemplatesMap(context);
|
||||
myTemplatesMap.putAllValues(map);
|
||||
myTemplatesMap.putAllValues(getTemplatesMap(context));
|
||||
|
||||
for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) {
|
||||
for (ProjectCategory category : EP_NAME.getExtensionList()) {
|
||||
TemplatesGroup group = new TemplatesGroup(category);
|
||||
|
||||
ModuleBuilder builder = group.getModuleBuilder();
|
||||
if (builder == null || builder.isAvailable()) {
|
||||
myTemplatesMap.remove(group);
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.util.newProjectWizard;
|
||||
|
||||
import com.intellij.ide.projectWizard.ProjectCategory;
|
||||
@@ -30,8 +16,7 @@ import javax.swing.*;
|
||||
* The groups are shown in "Project Type" selection list.
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class TemplatesGroup implements Comparable<TemplatesGroup> {
|
||||
|
||||
public final class TemplatesGroup implements Comparable<TemplatesGroup> {
|
||||
private final String myName;
|
||||
private final String myDescription;
|
||||
private final Icon myIcon;
|
||||
@@ -61,7 +46,7 @@ public class TemplatesGroup implements Comparable<TemplatesGroup> {
|
||||
myProjectCategory = category;
|
||||
}
|
||||
|
||||
public TemplatesGroup(ModuleBuilder builder) {
|
||||
public TemplatesGroup(@NotNull ModuleBuilder builder) {
|
||||
this(builder.getPresentableName(), builder.getDescription(), builder.getNodeIcon(), builder.getWeight(), builder.getParentGroup(), builder.getBuilderId(), builder);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
import com.intellij.util.EventDispatcher;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -43,8 +42,7 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class ModuleBuilder extends AbstractModuleBuilder {
|
||||
|
||||
public static final ExtensionPointName<ModuleBuilderFactory> EP_NAME = ExtensionPointName.create("com.intellij.moduleBuilder");
|
||||
private static final ExtensionPointName<ModuleBuilderFactory> EP_NAME = new ExtensionPointName<>("com.intellij.moduleBuilder");
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(ModuleBuilder.class);
|
||||
private final Set<ModuleConfigurationUpdater> myUpdaters = new HashSet<>();
|
||||
@@ -59,16 +57,21 @@ public abstract class ModuleBuilder extends AbstractModuleBuilder {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<ModuleBuilder> getAllBuilders() {
|
||||
public static @NotNull List<ModuleBuilder> getAllBuilders() {
|
||||
List<ModuleBuilder> result = new ArrayList<>();
|
||||
for (final ModuleType<?> moduleType : ModuleTypeManager.getInstance().getRegisteredTypes()) {
|
||||
result.add(moduleType.createModuleBuilder());
|
||||
for (ModuleType<?> moduleType : ModuleTypeManager.getInstance().getRegisteredTypes()) {
|
||||
ModuleBuilder builder = moduleType.createModuleBuilder();
|
||||
if (builder.isAvailable()) {
|
||||
result.add(builder);
|
||||
}
|
||||
}
|
||||
for (ModuleBuilderFactory factory : EP_NAME.getExtensions()) {
|
||||
result.add(factory.createBuilder());
|
||||
}
|
||||
return ContainerUtil.filter(result, moduleBuilder -> moduleBuilder.isAvailable());
|
||||
EP_NAME.forEachExtensionSafe(factory -> {
|
||||
ModuleBuilder builder = factory.createBuilder();
|
||||
if (builder.isAvailable()) {
|
||||
result.add(builder);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void deleteModuleFile(String moduleFilePath) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ModuleTypeManager {
|
||||
public static ModuleTypeManager getInstance() {
|
||||
return ApplicationManager.getApplication().getService(ModuleTypeManager.class);
|
||||
@@ -21,7 +23,7 @@ public abstract class ModuleTypeManager {
|
||||
@ApiStatus.Internal
|
||||
public abstract void unregisterModuleType(ModuleType<?> type);
|
||||
|
||||
public abstract ModuleType<?>[] getRegisteredTypes();
|
||||
public abstract @NotNull List<ModuleType<?>> getRegisteredTypes();
|
||||
|
||||
public abstract ModuleType<?> findByID(@Nullable String moduleTypeID);
|
||||
|
||||
|
||||
@@ -52,15 +52,15 @@ public class ModuleTypeManagerImpl extends ModuleTypeManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleType<?>[] getRegisteredTypes() {
|
||||
public @NotNull List<ModuleType<?>> getRegisteredTypes() {
|
||||
List<ModuleType<?>> result = new ArrayList<>(myModuleTypes.keySet());
|
||||
for (ModuleTypeEP moduleTypeEP : EP_NAME.getExtensionList()) {
|
||||
ModuleType<?> moduleType = moduleTypeEP.getModuleType();
|
||||
EP_NAME.forEachExtensionSafe(ep -> {
|
||||
ModuleType<?> moduleType = ep.getModuleType();
|
||||
if (!myModuleTypes.containsKey(moduleType)) {
|
||||
result.add(moduleType);
|
||||
}
|
||||
}
|
||||
return result.toArray(new ModuleType[0]);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user