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.
17 package com
.intellij
.facet
.impl
.autodetecting
;
19 import com
.intellij
.util
.xmlb
.annotations
.AbstractCollection
;
20 import com
.intellij
.util
.xmlb
.annotations
.Attribute
;
21 import com
.intellij
.util
.xmlb
.annotations
.Tag
;
22 import com
.intellij
.openapi
.util
.SystemInfo
;
23 import com
.intellij
.openapi
.util
.text
.StringUtil
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.annotations
.Nullable
;
27 import java
.util
.ArrayList
;
28 import java
.util
.Iterator
;
29 import java
.util
.List
;
35 public class DisabledAutodetectionByTypeElement
{
36 private String myFacetTypeId
;
37 private List
<DisabledAutodetectionInModuleElement
> myModuleElements
= new ArrayList
<DisabledAutodetectionInModuleElement
>();
39 public DisabledAutodetectionByTypeElement() {
42 public DisabledAutodetectionByTypeElement(final String facetTypeId
) {
43 myFacetTypeId
= facetTypeId
;
46 public DisabledAutodetectionByTypeElement(String facetTypeId
, String moduleName
) {
48 myModuleElements
.add(new DisabledAutodetectionInModuleElement(moduleName
));
51 public DisabledAutodetectionByTypeElement(String facetTypeId
, String moduleName
, String url
, final boolean recursively
) {
53 myModuleElements
.add(new DisabledAutodetectionInModuleElement(moduleName
, url
, recursively
));
57 public String
getFacetTypeId() {
62 @AbstractCollection(surroundWithTag
= false)
63 public List
<DisabledAutodetectionInModuleElement
> getModuleElements() {
64 return myModuleElements
;
67 public void setFacetTypeId(final String facetTypeId
) {
68 myFacetTypeId
= facetTypeId
;
71 public void setModuleElements(final List
<DisabledAutodetectionInModuleElement
> moduleElements
) {
72 myModuleElements
= moduleElements
;
75 public void addDisabled(@NotNull String moduleName
) {
76 if (myModuleElements
.isEmpty()) return;
78 DisabledAutodetectionInModuleElement element
= findElement(moduleName
);
79 if (element
!= null) {
80 element
.getFiles().clear();
81 element
.getDirectories().clear();
85 myModuleElements
.add(new DisabledAutodetectionInModuleElement(moduleName
));
88 public void disableInProject() {
89 myModuleElements
.clear();
92 public void addDisabled(@NotNull String moduleName
, @NotNull String fileUrl
, final boolean recursively
) {
93 if (myModuleElements
.isEmpty()) return;
95 DisabledAutodetectionInModuleElement element
= findElement(moduleName
);
96 if (element
!= null) {
97 if (!element
.isDisableInWholeModule()) {
99 element
.getDirectories().add(fileUrl
);
102 element
.getFiles().add(fileUrl
);
107 myModuleElements
.add(new DisabledAutodetectionInModuleElement(moduleName
, fileUrl
, recursively
));
111 public DisabledAutodetectionInModuleElement
findElement(final @NotNull String moduleName
) {
112 for (DisabledAutodetectionInModuleElement element
: myModuleElements
) {
113 if (moduleName
.equals(element
.getModuleName())) {
120 public boolean equals(final Object o
) {
121 if (this == o
) return true;
122 if (o
== null || getClass() != o
.getClass()) return false;
124 final DisabledAutodetectionByTypeElement that
= (DisabledAutodetectionByTypeElement
)o
;
125 return myFacetTypeId
.equals(that
.myFacetTypeId
) && myModuleElements
.equals(that
.myModuleElements
);
129 public int hashCode() {
130 return myFacetTypeId
.hashCode()+ 31 * myModuleElements
.hashCode();
133 public boolean isDisabled(final String moduleName
, final String url
) {
134 if (myModuleElements
.isEmpty()) return true;
136 DisabledAutodetectionInModuleElement element
= findElement(moduleName
);
137 if (element
== null) return false;
139 if (element
.isDisableInWholeModule() || element
.getFiles().contains(url
)) {
142 for (String directoryUrl
: element
.getDirectories()) {
143 if (!directoryUrl
.endsWith("/")) {
146 if (url
.startsWith(directoryUrl
) || !SystemInfo
.isFileSystemCaseSensitive
&& StringUtil
.startsWithIgnoreCase(url
, directoryUrl
)) {
153 public boolean removeDisabled(final String moduleName
) {
154 Iterator
<DisabledAutodetectionInModuleElement
> iterator
= myModuleElements
.iterator();
155 while (iterator
.hasNext()) {
156 DisabledAutodetectionInModuleElement element
= iterator
.next();
157 if (element
.getModuleName().equals(moduleName
)) {
162 return myModuleElements
.size() > 0;