IDEA-26403: Maia 92​.​65 and 92​.​81 overwrite and destroy existing Grails run config...
[fedora-idea.git] / plugins / groovy / src / org / jetbrains / plugins / groovy / config / GroovyModuleConverter.java
blob727e74b3a941e221daac5db432eb61cce4445f1c
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.plugins.groovy.config;
18 import com.intellij.conversion.CannotConvertException;
19 import com.intellij.conversion.ConversionProcessor;
20 import com.intellij.conversion.ModuleSettings;
21 import com.intellij.facet.FacetManagerImpl;
22 import com.intellij.openapi.module.StdModuleTypes;
23 import org.jdom.Element;
25 import java.util.List;
27 /**
28 * @author peter
30 public class GroovyModuleConverter extends ConversionProcessor<ModuleSettings> {
31 @Override
32 public boolean isConversionNeeded(ModuleSettings moduleSettings) {
33 if ("GRAILS_MODULE".equals(moduleSettings.getModuleType())) {
34 return true;
37 if (!moduleSettings.getFacetElements("Grails").isEmpty()) {
38 return true;
41 if (!moduleSettings.getFacetElements("Groovy").isEmpty()) {
42 return true;
45 return false;
48 @Override
49 public void process(ModuleSettings moduleSettings) throws CannotConvertException {
50 if ("GRAILS_MODULE".equals(moduleSettings.getModuleType())) {
51 moduleSettings.setModuleType(StdModuleTypes.JAVA.getId());
54 final Element facetManagerElement = moduleSettings.getComponentElement(FacetManagerImpl.COMPONENT_NAME);
55 if (facetManagerElement == null) return;
57 final Element[] facetElements = getChildren(facetManagerElement, FacetManagerImpl.FACET_ELEMENT);
58 for (Element facetElement : facetElements) {
59 final String facetType = facetElement.getAttributeValue(FacetManagerImpl.TYPE_ATTRIBUTE);
60 if ("Grails".equals(facetType) || "Groovy".equals(facetType)) {
61 facetElement.detach();
66 private static Element[] getChildren(Element parent, final String name) {
67 final List<?> children = parent.getChildren(name);
68 return children.toArray(new Element[children.size()]);