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 com
.intellij
.openapi
.deployment
;
18 import com
.intellij
.openapi
.application
.ApplicationManager
;
19 import com
.intellij
.openapi
.compiler
.CompilerBundle
;
20 import com
.intellij
.openapi
.diagnostic
.Logger
;
21 import com
.intellij
.openapi
.module
.Module
;
22 import com
.intellij
.openapi
.module
.ModuleManager
;
23 import com
.intellij
.openapi
.module
.ModuleUtil
;
24 import com
.intellij
.openapi
.roots
.ui
.configuration
.FacetsProvider
;
25 import com
.intellij
.openapi
.roots
.ui
.configuration
.ModulesProvider
;
26 import com
.intellij
.openapi
.util
.Comparing
;
27 import com
.intellij
.openapi
.util
.Computable
;
28 import com
.intellij
.openapi
.util
.InvalidDataException
;
29 import com
.intellij
.openapi
.util
.WriteExternalException
;
30 import org
.jdom
.Element
;
31 import org
.jetbrains
.annotations
.NonNls
;
32 import org
.jetbrains
.annotations
.NotNull
;
33 import org
.jetbrains
.annotations
.Nullable
;
35 public class ModuleLinkImpl
extends ModuleLink
{
36 private static final Logger LOG
= Logger
.getInstance("#com.intellij.openapi.deployment.ModuleLink");
37 @NonNls public static final String NAME_ATTRIBUTE_NAME
= "name";
38 @NonNls private static final String TEMP_ELEMENT_NAME
= "temp";
39 private Module myModule
;
40 private String myModuleName
;
42 public ModuleLinkImpl(@NotNull Module module
, @NotNull Module parentModule
) {
45 myModuleName
= ModuleUtil
.getModuleNameInReadAction(myModule
);
48 public ModuleLinkImpl(String moduleName
, @NotNull Module parentModule
) {
50 myModuleName
= moduleName
;
53 private Module
getModule(ModulesProvider provider
) {
54 if (myModule
!= null && myModule
.isDisposed()) {
57 if (myModule
== null) {
58 myModule
= provider
.getModule(myModuleName
);
64 public Module
getModule() {
65 if (myModule
!= null && myModule
.isDisposed()) {
68 if (myModule
== null) {
69 myModule
= ApplicationManager
.getApplication().runReadAction(new Computable
<Module
>() {
70 public Module
compute() {
71 return ModuleManager
.getInstance(getParentModule().getProject()).findModuleByName(myModuleName
);
78 public String
toString() {
79 return CompilerBundle
.message("module.link.string.representation", getName(), getURI());
82 public boolean equalsIgnoreAttributes(ContainerElement otherElement
) {
83 return otherElement
instanceof ModuleLink
&& Comparing
.strEqual(((ModuleLink
)otherElement
).getName(), getName());
86 public String
getPresentableName() {
90 public boolean resolveElement(ModulesProvider provider
, final FacetsProvider facetsProvider
) {
91 return getModule(provider
) != null;
94 public void readExternal(Element element
) throws InvalidDataException
{
95 super.readExternal(element
);
96 myModuleName
= element
.getAttributeValue(NAME_ATTRIBUTE_NAME
);
97 migratePackagingMethods();
100 private void migratePackagingMethods() {
101 if (getPackagingMethod() == PackagingMethod
.COPY_CLASSES
) {
102 setPackagingMethod(PackagingMethod
.COPY_FILES
);
106 public void writeExternal(Element element
) throws WriteExternalException
{
107 super.writeExternal(element
);
108 element
.setAttribute(NAME_ATTRIBUTE_NAME
, getName());
111 public String
getName() {
112 if (myModule
== null) {
116 return ModuleUtil
.getModuleNameInReadAction(myModule
);
120 public ModuleLink
clone() {
121 ModuleLink moduleLink
= new ModuleLinkImpl(getName(), getParentModule());
122 Element temp
= new Element(TEMP_ELEMENT_NAME
);
125 moduleLink
.readExternal(temp
);
127 catch (Exception e
) {