2 * Copyright 2000-2005 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 com
.intellij
.ide
.util
.projectWizard
;
18 import com
.intellij
.CommonBundle
;
19 import com
.intellij
.application
.options
.PathMacrosCollector
;
20 import com
.intellij
.application
.options
.PathMacrosImpl
;
21 import com
.intellij
.conversion
.ConversionService
;
22 import com
.intellij
.ide
.IdeBundle
;
23 import com
.intellij
.openapi
.application
.PathMacros
;
24 import com
.intellij
.openapi
.diagnostic
.Logger
;
25 import com
.intellij
.openapi
.module
.ModifiableModuleModel
;
26 import com
.intellij
.openapi
.module
.Module
;
27 import com
.intellij
.openapi
.module
.ModuleType
;
28 import com
.intellij
.openapi
.module
.ModuleWithNameAlreadyExists
;
29 import com
.intellij
.openapi
.options
.ConfigurationException
;
30 import com
.intellij
.openapi
.project
.Project
;
31 import com
.intellij
.openapi
.project
.impl
.ProjectMacrosUtil
;
32 import com
.intellij
.openapi
.roots
.ModifiableRootModel
;
33 import com
.intellij
.openapi
.ui
.Messages
;
34 import com
.intellij
.openapi
.util
.InvalidDataException
;
35 import com
.intellij
.openapi
.util
.JDOMUtil
;
36 import org
.jdom
.Document
;
37 import org
.jdom
.Element
;
38 import org
.jdom
.JDOMException
;
39 import org
.jetbrains
.annotations
.NotNull
;
42 import java
.io
.IOException
;
46 * @author Eugene Zhuravlev
49 public class ExistingModuleLoader
extends ModuleBuilder
{
50 private static final Logger LOG
= Logger
.getInstance("#com.intellij.ide.util.projectWizard.ExistingModuleLoader");
53 public Module
createModule(ModifiableModuleModel moduleModel
)
54 throws InvalidDataException
, IOException
, ModuleWithNameAlreadyExists
, JDOMException
, ConfigurationException
{
55 LOG
.assertTrue(getName() != null);
57 final String moduleFilePath
= getModuleFilePath();
59 LOG
.assertTrue(moduleFilePath
!= null);
60 LOG
.assertTrue(new File(moduleFilePath
).exists());
62 return moduleModel
.loadModule(moduleFilePath
);
65 public void setupRootModel(ModifiableRootModel modifiableRootModel
) throws ConfigurationException
{
69 public ModuleType
getModuleType() {
70 return null; // no matter
73 public boolean validate(final Project current
, final Project dest
) {
74 if (getName() == null) return false;
75 if (getModuleFilePath() == null) return false;
76 final File file
= new File(getModuleFilePath());
79 if (!ConversionService
.getInstance().convertModule(dest
, file
)) {
82 final Document document
= JDOMUtil
.loadDocument(file
);
83 final Element root
= document
.getRootElement();
84 final Set
<String
> usedMacros
= PathMacrosCollector
.getMacroNames(root
);
85 final Set
<String
> definedMacros
= PathMacros
.getInstance().getAllMacroNames();
86 usedMacros
.remove("$" + PathMacrosImpl
.MODULE_DIR_MACRO_NAME
+ "$");
87 usedMacros
.removeAll(definedMacros
);
89 if (usedMacros
.size() > 0) {
90 final boolean ok
= ProjectMacrosUtil
.showMacrosConfigurationDialog(current
, usedMacros
);
96 catch (JDOMException e
) {
97 Messages
.showMessageDialog(e
.getMessage(), IdeBundle
.message("title.error.reading.file"), Messages
.getErrorIcon());
100 catch (IOException e
) {
101 Messages
.showMessageDialog(e
.getMessage(), IdeBundle
.message("title.error.reading.file"), Messages
.getErrorIcon());
105 Messages
.showErrorDialog(current
, IdeBundle
.message("title.module.file.does.not.exist"), CommonBundle
.message("title.error"));