From cf69cf2243ec0db762da981a3f739bbac5f13542 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 15 Nov 2016 04:41:18 +0300 Subject: [PATCH] Fix IDEA Maven Importer to properly create facet on maven update project --- .../teavm/idea/maven/TeaVMMavenImporter.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/idea/src/main/java/org/teavm/idea/maven/TeaVMMavenImporter.java b/tools/idea/src/main/java/org/teavm/idea/maven/TeaVMMavenImporter.java index ab2f9e769..6e3ec6149 100644 --- a/tools/idea/src/main/java/org/teavm/idea/maven/TeaVMMavenImporter.java +++ b/tools/idea/src/main/java/org/teavm/idea/maven/TeaVMMavenImporter.java @@ -17,6 +17,7 @@ package org.teavm.idea.maven; import com.intellij.facet.FacetManager; import com.intellij.facet.FacetType; +import com.intellij.facet.ModifiableFacetModel; import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider; import com.intellij.openapi.module.Module; import java.util.HashSet; @@ -54,32 +55,32 @@ public class TeaVMMavenImporter extends MavenImporter { MavenProjectChanges changes, Map mavenProjectToModuleName, List postTasks) { FacetManager facetManager = FacetManager.getInstance(module); - + ModifiableFacetModel facetModel = modifiableModelsProvider.getModifiableFacetModel(module); Set targetTypes = new HashSet<>(); for (MavenPlugin mavenPlugin : mavenProject.getPlugins()) { if (mavenPlugin.getGroupId().equals(myPluginGroupID) && mavenPlugin.getArtifactId().equals(myPluginArtifactID)) { - updateConfiguration(mavenPlugin, facetManager, module, targetTypes); + updateConfiguration(mavenPlugin, facetModel, facetManager, targetTypes); } } } - private void updateConfiguration(MavenPlugin plugin, FacetManager facetManager, Module module, + private void updateConfiguration(MavenPlugin plugin, ModifiableFacetModel facetModel, FacetManager facetManager, Set targetTypes) { if (plugin.getConfigurationElement() != null) { - updateConfiguration(plugin.getConfigurationElement(), facetManager, module, targetTypes); + updateConfiguration(plugin.getConfigurationElement(), facetModel, facetManager, targetTypes); } for (MavenPlugin.Execution execution : plugin.getExecutions()) { if (execution.getGoals().contains("compile")) { if (execution.getConfigurationElement() != null) { - updateConfiguration(execution.getConfigurationElement(), facetManager, module, targetTypes); + updateConfiguration(execution.getConfigurationElement(), facetModel, facetManager, targetTypes); } } } } - private void updateConfiguration(Element source, FacetManager facetManager, Module module, + private void updateConfiguration(Element source, ModifiableFacetModel facetModel, FacetManager facetManager, Set targetTypes) { FacetType facetType; switch (getTargetType(source)) { @@ -98,10 +99,10 @@ public class TeaVMMavenImporter extends MavenImporter { } TeaVMFacet facet = facetManager.getFacetByType(facetType.getId()); + if (facet == null) { - facet = new TeaVMFacet(facetType, module, facetType.getDefaultFacetName(), - facetType.createDefaultConfiguration(), null); - facetManager.addFacet(facetType, facet.getName(), facet); + facet = facetManager.createFacet(facetType, facetType.getDefaultFacetName(), null); + facetModel.addFacet(facet); } TeaVMJpsConfiguration configuration = facet.getConfiguration().getState();