diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/AutodetectionFilter.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/AutodetectionFilter.java deleted file mode 100644 index f21902b38af0..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/AutodetectionFilter.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.openapi.module.Module; -import com.intellij.facet.FacetType; - -/** - * @author nik - */ -public interface AutodetectionFilter { - - boolean isAutodetectionEnabled(Module module, FacetType facetType, final String url); - -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DefaultDetectedFacetPresentation.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DefaultDetectedFacetPresentation.java deleted file mode 100644 index 65220d03b9cd..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DefaultDetectedFacetPresentation.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.FacetType; -import com.intellij.facet.autodetecting.DetectedFacetPresentation; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; - -/** - * @author nik - */ -public class DefaultDetectedFacetPresentation extends DetectedFacetPresentation { - public static final DefaultDetectedFacetPresentation INSTANCE = new DefaultDetectedFacetPresentation(); - - @Nullable - public String getDetectedFacetDescription(final VirtualFile root, final VirtualFile[] files) { - VirtualFile file = files[0]; - if (root == null) return file.getPresentableUrl(); - String path = VfsUtil.getRelativePath(file, root, File.separatorChar); - return path != null ? path : file.getPresentableUrl(); - } - - public String getAutodetectionPopupText(@NotNull final Module module, @NotNull final FacetType facetType, @NotNull final String facetName, - @NotNull final VirtualFile[] files) { - String fileUrl = getRelativeFileUrl(files[0], module.getProject()); - return ProjectBundle.message("facet.autodetected.popup.default.text", fileUrl, module.getName(), facetType.getPresentableName(), facetName); - } - - private static String getRelativeFileUrl(final @NotNull VirtualFile file, final Project project) { - String fileUrl = file.getPresentableUrl(); - - VirtualFile baseDir = project.getBaseDir(); - if (baseDir == null) { - return fileUrl; - } - - String prefix = baseDir.getPresentableUrl() + File.separator; - if (fileUrl.startsWith(prefix)) { - return fileUrl.substring(prefix.length()); - } - return fileUrl; - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DetectedFacetManager.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DetectedFacetManager.java deleted file mode 100644 index 4864acc0677f..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DetectedFacetManager.java +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.ProjectTopics; -import com.intellij.facet.*; -import com.intellij.facet.autodetecting.DetectedFacetPresentation; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.impl.autodetecting.facetsTree.DetectedFacetsDialog; -import com.intellij.facet.impl.autodetecting.model.*; -import com.intellij.ide.caches.FileContent; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationListener; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.application.Result; -import com.intellij.openapi.application.WriteAction; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.ModuleAdapter; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.roots.ModifiableRootModel; -import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.MultiValuesMap; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.util.Alarm; -import com.intellij.util.ArrayUtil; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -import javax.swing.event.HyperlinkEvent; -import java.util.*; - -/** - * @author nik - */ -public class DetectedFacetManager implements Disposable { - private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.autodetecting.DetectedFacetManager"); - @NonNls private static final String NOTIFICATION_ID = "Facet Detector"; - private static final int NOTIFICATION_DELAY = 200; - private final Project myProject; - private final FacetAutodetectingManagerImpl myAutodetectingManager; - private final ProjectWideFacetListenersRegistry myProjectWideFacetListenersRegistry; - private boolean myUIInitialized; - private final Set> myPendingNewFacets = new HashSet>(); - private final Alarm myNotificationAlarm = new Alarm(); - private final ProjectFacetInfoSet myDetectedFacetSet; - private final List myNotifications = new ArrayList(); - - public DetectedFacetManager(final Project project, final FacetAutodetectingManagerImpl autodetectingManager, - final ProjectFacetInfoSet detectedFacetSet) { - myDetectedFacetSet = detectedFacetSet; - myProjectWideFacetListenersRegistry = ProjectWideFacetListenersRegistry.getInstance(project); - myProject = project; - myAutodetectingManager = autodetectingManager; - myDetectedFacetSet.addListener(new ProjectFacetInfoSet.DetectedFacetListener() { - public void facetDetected(final DetectedFacetInfo info) { - onDetectedFacetChanged(Collections.singletonList(info), Collections.>emptyList()); - } - - public void facetRemoved(final DetectedFacetInfo info) { - myAutodetectingManager.getFileIndex().removeFromIndex(info); - onDetectedFacetChanged(Collections.>emptyList(), Collections.singletonList(info)); - } - }); - Disposer.register(myProject, this); - myProject.getMessageBus().connect().subscribe(ProjectTopics.MODULES, new ModuleAdapter() { - @Override - public void moduleRemoved(final Project project, final Module module) { - myDetectedFacetSet.removeDetectedFacets(module); - } - }); - } - - public , C extends FacetConfiguration> void registerListeners(final FacetType type) { - myProjectWideFacetListenersRegistry.registerListener(type.getId(), new MyProjectWideFacetListener(), this); - } - - public Project getProject() { - return myProject; - } - - public void onDetectedFacetChanged(@NotNull final Collection> added, @NotNull final Collection> removed) { - if (!myUIInitialized) return; - - if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { - Runnable runnable = new Runnable() { - public void run() { - if (isDisposed()) return; - - myPendingNewFacets.addAll(added); - for (FacetDetectedNotification notification : myNotifications) { - for (DetectedFacetInfo facetInfo : removed) { - notification.processFacetRemoved(facetInfo); - } - } - queueNotificationPopup(); - } - }; - ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL); - } - } - - private void queueNotificationPopup() { - myNotificationAlarm.cancelAllRequests(); - myNotificationAlarm.addRequest(new Runnable() { - public void run() { - firePendingNotifications(); - } - }, NOTIFICATION_DELAY); - } - - public boolean isDisposed() { - return myProject.isDisposed() || !myUIInitialized; - } - - private void firePendingNotifications() { - if (myPendingNewFacets.isEmpty() || myProject.isDisposed()) return; - - List> newFacets = new ArrayList>(); - for (DetectedFacetInfo newFacet : myPendingNewFacets) { - newFacets.add(newFacet); - } - myPendingNewFacets.clear(); - //fireNotification(newFacets); - } - - private void fireNotification(final List> newFacets) { - if (newFacets.isEmpty()) { - return; - } - - boolean showNotification = true;//todo[nik] may be we shouldn't show notification if "Facets Detected" dialog is opened - HashMap, List> filesMap = getFilesMap(newFacets); - if (!filesMap.isEmpty() && showNotification) { - final Set> detectedFacetInfos = filesMap.keySet(); - final FacetDetectedNotification notification; - if (filesMap.size() == 1) { - final DetectedFacetInfo facetInfo = detectedFacetInfos.iterator().next(); - final List files = filesMap.get(facetInfo); - notification = createSingleFacetDetectedNotification(facetInfo, VfsUtil.toVirtualFileArray(files)); - } - else { - notification = createSeveralFacetsDetectedNotification(filesMap.keySet()); - } - myNotifications.add(notification); - Notifications.Bus.notify(notification, myProject); - } - else { - myPendingNewFacets.addAll(newFacets); - } - } - - public void dispose() { - } - - public void initUI() { - myUIInitialized = true; - onDetectedFacetChanged(myDetectedFacetSet.getAllDetectedFacets(), Collections.>emptyList()); - } - - public void disposeUI() { - if (!myUIInitialized) return; - - myNotificationAlarm.cancelAllRequests(); - } - - public void disableDetectionInFile(final DetectedFacetInfo detectedFacet) { - Collection urls = myAutodetectingManager.getFileIndex().getFiles(detectedFacet.getId()); - if (urls != null && !urls.isEmpty()) { - myAutodetectingManager.disableAutodetectionInFiles(detectedFacet.getFacetType(), detectedFacet.getModule(), ArrayUtil.toStringArray(urls)); - } - myAutodetectingManager.getDetectedFacetSet().removeFacetInfo(detectedFacet); - } - - public void disableDetectionInModule(final DetectedFacetInfo detectedFacetInfo) { - disableDetectionInModule(detectedFacetInfo.getFacetType(), detectedFacetInfo.getModule()); - } - - public void disableDetectionInModule(final FacetType type, final Module module) { - myAutodetectingManager.disableAutodetectionInModule(type, module); - myAutodetectingManager.getDetectedFacetSet().removeDetectedFacets(type.getId(), module); - } - - public boolean showDetectedFacetsDialog() { - List> detectedFacets = new ArrayList>(myDetectedFacetSet.getAllDetectedFacets()); - HashMap, List> filesMap = getFilesMap(detectedFacets); - - if (detectedFacets.isEmpty()) { - removeAllNotifications(); - return false; - } - DetectedFacetsDialog dialog = new DetectedFacetsDialog(myProject, this, detectedFacets, filesMap); - dialog.show(); - final boolean processed = dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE; - if (processed) { - removeAllNotifications(); - } - return processed; - } - - private HashMap, List> getFilesMap(final List> detectedFacets) { - MultiValuesMap, DetectedFacetInfo> facet2Children = new MultiValuesMap, DetectedFacetInfo>(); - for (DetectedFacetInfo detected : detectedFacets) { - FacetInfo2 underlying = detected.getUnderlyingFacetInfo(); - if (underlying instanceof DetectedFacetInfo) { - facet2Children.put((DetectedFacetInfo)underlying, detected); - } - } - - HashMap, List> filesMap = new HashMap, List>(); - Set> toRemove = new HashSet>(); - for (DetectedFacetInfo detected : detectedFacets) { - Set urls = myAutodetectingManager.getFileIndex().getFiles(detected.getId()); - List files = new ArrayList(); - if (urls != null) { - for (String url : urls) { - VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); - if (file != null) { - files.add(file); - } - } - } - if (!files.isEmpty()) { - filesMap.put(detected, files); - } - else { - addWithChildren(detected, facet2Children, toRemove); - } - } - - detectedFacets.removeAll(toRemove); - - return filesMap; - } - - private static void addWithChildren(final DetectedFacetInfo detected, - final MultiValuesMap, DetectedFacetInfo> facet2Children, - final Set> result) { - if (result.add(detected)) { - Collection> children = facet2Children.get(detected); - if (children != null) { - for (DetectedFacetInfo info : children) { - addWithChildren(info, facet2Children, result); - } - } - } - } - - public Facet createFacet(final DetectedFacetInfo info, final Facet underlyingFacet) { - final Module module = info.getModule(); - - FacetType type = info.getFacetType(); - final Facet facet = createFacet(info, module, underlyingFacet, type); - ModifiableFacetModel model = FacetManager.getInstance(module).createModifiableModel(); - ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); - final FacetDetector detector = myAutodetectingManager.findDetector(info.getDetectorId()); - if (detector != null) { - detector.beforeFacetAdded(facet, model, rootModel); - } - model.addFacet(facet); - if (rootModel.isChanged()) { - rootModel.commit(); - } - else { - rootModel.dispose(); - } - - model.commit(); - myAutodetectingManager.getFileIndex().updateIndexEntryForCreatedFacet(info, facet); - myAutodetectingManager.getDetectedFacetSet().removeFacetInfo(info); - if (detector != null) { - detector.afterFacetAdded(facet); - } - return facet; - } - - private static Facet createFacet(final DetectedFacetInfo info, final Module module, final Facet underlyingFacet, - final FacetType facetType) { - return FacetManager.getInstance(module).createFacet(facetType, info.getFacetName(), (C)info.getConfiguration(), underlyingFacet); - } - - private FacetDetectedNotification createSingleFacetDetectedNotification(final DetectedFacetInfo detectedFacetInfo, final VirtualFile[] files) { - @SuppressWarnings({"RedundantCast"}) DetectedFacetPresentation presentation = FacetDetectorRegistryEx.getDetectedFacetPresentation((FacetType)detectedFacetInfo.getFacetType()); - - String text = presentation.getAutodetectionPopupText(detectedFacetInfo.getModule(), detectedFacetInfo.getFacetType(), - detectedFacetInfo.getFacetName(), files); - if (text == null) { - text = DefaultDetectedFacetPresentation.INSTANCE.getAutodetectionPopupText(detectedFacetInfo.getModule(), detectedFacetInfo.getFacetType(), - detectedFacetInfo.getFacetName(), files); - } - final String description = ProjectBundle.message("facet.autodetected.info.text", detectedFacetInfo.getFacetType().getPresentableName(), text, - detectedFacetInfo.getFacetName()); - final String title = ProjectBundle.message("notification.name.0.facet.detected", detectedFacetInfo.getFacetType().getPresentableName()); - return new FacetDetectedNotification(title, description, new NotificationListener() { - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - notification.expire(); - if (isDisposed()) { - return; - } - - String link = event.getDescription(); - if ("create".equals(link)) { - new WriteAction() { - protected void run(final Result result) { - createFacetWithUnderlyingFacets(detectedFacetInfo); - } - }.execute(); - } - else if ("disable".equals(link)) { - disableDetectionInModule(detectedFacetInfo); - } - else { - LOG.error(link); - } - } - } - }, Collections.singletonList(detectedFacetInfo)); - } - - private Facet createFacetWithUnderlyingFacets(DetectedFacetInfo detectedFacetInfo) { - FacetInfo2 underlyingInfo = detectedFacetInfo.getUnderlyingFacetInfo(); - final Facet underlyingFacet; - if (underlyingInfo instanceof FacetInfoBackedByFacet) { - underlyingFacet = ((FacetInfoBackedByFacet)underlyingInfo).getFacet(); - } - else if (underlyingInfo instanceof DetectedFacetInfo) { - underlyingFacet = createFacetWithUnderlyingFacets((DetectedFacetInfo)underlyingInfo); - } - else { - underlyingFacet = null; - } - return createFacet(detectedFacetInfo, underlyingFacet); - } - - private FacetDetectedNotification createSeveralFacetsDetectedNotification(final Set> facets) { - final String title = ProjectBundle.message("notification.name.0.facets.detected", facets.size()); - final String content = ProjectBundle.message("facet.autodetection.several.facets.detected.text", facets.size()); - return new FacetDetectedNotification(title, content, new NotificationListener() { - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - if (isDisposed()) { - return; - } - - if ("more".equals(event.getDescription())) { - showDetectedFacetsDialog(); - } - } - } - }, facets); - } - - private void removeAllNotifications() { - for (Notification notification : myNotifications) { - if (!notification.isExpired()) { - notification.expire(); - } - } - myNotifications.clear(); - } - - private class MyProjectWideFacetListener, C extends FacetConfiguration> extends ProjectWideFacetAdapter { - @Override - public void facetAdded(final F facet) { - Map> map = myDetectedFacetSet.getConfigurations((FacetTypeId)facet.getTypeId(), facet.getModule()); - Collection> infos = map.values(); - Set files = new HashSet(); - for (FacetInfo2 info : infos) { - if (info instanceof DetectedFacetInfo) { - Set urls = myAutodetectingManager.getFileIndex().getFiles(((DetectedFacetInfo)info).getId()); - if (urls != null) { - for (String url : urls) { - VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); - if (file != null) { - files.add(file); - } - } - } - } - } - for (VirtualFile file : files) { - myAutodetectingManager.processFile(new FileContent(file)); - } - } - - @Override - public void beforeFacetRemoved(final F facet) { - Set files = myAutodetectingManager.getFiles(facet); - if (files != null) { - myAutodetectingManager.disableAutodetectionInFiles(facet.getType(), facet.getModule(), ArrayUtil.toStringArray(files)); - } - myAutodetectingManager.removeFacetFromCache(facet); - } - } - - private static class FacetDetectedNotification extends Notification { - private final List> myFacets = new ArrayList>(); - - private FacetDetectedNotification(@NotNull String title, @NotNull String content, NotificationListener listener, Collection> facets) { - super(NOTIFICATION_ID, title, content, NotificationType.INFORMATION, listener); - myFacets.addAll(facets); - } - - public void processFacetRemoved(DetectedFacetInfo facetInfo) { - myFacets.remove(facetInfo); - if (myFacets.isEmpty() && !isExpired()) { - expire(); - } - } - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/EnableAutodetectionWorker.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/EnableAutodetectionWorker.java deleted file mode 100644 index 57bcf1f1ca55..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/EnableAutodetectionWorker.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.FacetType; -import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionByTypeElement; -import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionInModuleElement; -import com.intellij.ide.caches.FileContent; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.roots.ContentIterator; -import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.util.MultiValuesMap; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashSet; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.TestOnly; - -import java.util.*; - -/** - * @author nik - */ -public class EnableAutodetectionWorker { - private final MultiValuesMap, Module> myModulesToProcess = new MultiValuesMap, Module>(); - private final MultiValuesMap, VirtualFile> myFilesToProcess = new MultiValuesMap, VirtualFile>(); - private final Project myProject; - private final FacetAutodetectingManagerImpl myFacetAutodetectingManager; - - public EnableAutodetectionWorker(@NotNull Project project, final FacetAutodetectingManagerImpl facetAutodetectingManager) { - myProject = project; - myFacetAutodetectingManager = facetAutodetectingManager; - } - - public void addFile(@NotNull FacetType type, @NotNull String url) { - VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); - if (file != null) { - myFilesToProcess.put(type, file); - } - } - - public void queueChanges(final @NotNull FacetType facetType, final @Nullable DisabledAutodetectionByTypeElement oldElement, - final @Nullable DisabledAutodetectionByTypeElement newElement) { - if (oldElement == null || newElement != null && newElement.getModuleElements().isEmpty()) return; - - ModuleManager moduleManager = ModuleManager.getInstance(myProject); - List modulesToProcess = new ArrayList(); - - List moduleElements = oldElement.getModuleElements(); - for (DisabledAutodetectionInModuleElement moduleElement : moduleElements) { - if (moduleElement.isDisableInWholeModule()) { - Module module = moduleManager.findModuleByName(moduleElement.getModuleName()); - if (module != null) { - modulesToProcess.add(module); - } - } - else { - for (String url : moduleElement.getFiles()) { - if (newElement == null || !newElement.isDisabled(moduleElement.getModuleName(), url)) { - addFile(facetType, url); - } - } - for (String directoryUrl : moduleElement.getDirectories()) { - if (newElement == null || !newElement.isDisabled(moduleElement.getModuleName(), directoryUrl)) { - addFile(facetType, directoryUrl); - } - } - } - } - - if (moduleElements.isEmpty()) { - ContainerUtil.addAll(modulesToProcess, moduleManager.getModules()); - } - if (newElement != null) { - Set toRemove = new THashSet(); - for (DisabledAutodetectionInModuleElement moduleElement : newElement.getModuleElements()) { - if (moduleElement.isDisableInWholeModule()) { - toRemove.add(moduleElement.getModuleName()); - } - } - - Iterator iterator = modulesToProcess.iterator(); - while (iterator.hasNext()) { - Module module = iterator.next(); - if (toRemove.contains(module.getName())) { - iterator.remove(); - } - } - } - - if (!modulesToProcess.isEmpty()) { - myModulesToProcess.putAll(facetType, modulesToProcess); - } - } - - public void redetectFacets() { - ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { - public void run() { - for (FacetType type : myModulesToProcess.keySet()) { - detectFacetsInModules(type, myModulesToProcess.get(type)); - } - myModulesToProcess.clear(); - - for (FacetType type : myFilesToProcess.keySet()) { - detectFacetsInFiles(type, myFilesToProcess.get(type)); - } - myFilesToProcess.clear(); - } - - }, ProjectBundle.message("progress.text.detecting.facets"), false, myProject); - myFacetAutodetectingManager.getDetectedFacetManager().showDetectedFacetsDialog(); - } - - private void detectFacetsInModules(final FacetType type, final Collection modules) { - for (Module module : modules) { - ModuleRootManager.getInstance(module).getFileIndex().iterateContent(new ContentIterator() { - public boolean processFile(final VirtualFile file) { - detectFacetsInFile(type, file); - return true; - } - }); - } - } - - private void detectFacetsInFile(final FacetType type, final VirtualFile file) { - //todo[nik] detect only facets of specified type - if (file.isDirectory()) { - for (VirtualFile child : file.getChildren()) { - detectFacetsInFile(type, child); - } - } - else { - myFacetAutodetectingManager.processFile(new FileContent(file)); - } - } - - private void detectFacetsInFiles(final FacetType type, final Collection virtualFiles) { - for (VirtualFile file : virtualFiles) { - detectFacetsInFile(type, file); - } - } - - @TestOnly - @Nullable - public Collection getModulesToProcess(FacetType facetType) { - return myModulesToProcess.get(facetType); - } - - @TestOnly - @Nullable - public Collection getFilesToProcess(FacetType facetType) { - return myFilesToProcess.get(facetType); - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManager.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManager.java deleted file mode 100644 index 63ef7c113fc8..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManager.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.FacetType; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; - -/** - * @author nik - */ -public abstract class FacetAutodetectingManager { - public static FacetAutodetectingManager getInstance(Project project) { - return project.getComponent(FacetAutodetectingManager.class); - } - - public abstract void disableAutodetectionInFiles(@NotNull FacetType type, @NotNull Module module, @NotNull String... fileUrls); - - public abstract void disableAutodetectionInModule(FacetType type, Module module); -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java deleted file mode 100644 index f92f7e5b8492..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.facet.FacetTypeRegistry; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.facet.impl.autodetecting.model.FacetInfo2; -import com.intellij.facet.impl.autodetecting.model.ProjectFacetInfoSet; -import com.intellij.facet.pointers.FacetPointersManager; -import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionByTypeElement; -import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionInfo; -import com.intellij.ide.caches.FileContent; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ProjectComponent; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.MultiValuesMap; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.util.SmartList; -import com.intellij.util.ui.update.MergingUpdateQueue; -import com.intellij.util.ui.update.Update; -import gnu.trove.THashSet; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.TestOnly; - -import java.util.*; - -/** - * @author nik - */ -public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager implements AutodetectionFilter, ProjectComponent { - private final MultiValuesMap myDetectors = new MultiValuesMap(); - private final Map> myId2Detector = new HashMap>(); - private final Project myProject; - private final PsiManager myPsiManager; - private final FacetPointersManager myFacetPointersManager; - private FacetDetectionIndex myFileIndex; - private MergingUpdateQueue myMergingUpdateQueue; - private final ProjectFacetInfoSet myDetectedFacetSet; - private DetectedFacetManager myDetectedFacetManager; - private DisabledAutodetectionInfo myDisabledAutodetectionInfo = new DisabledAutodetectionInfo(); - private boolean myDetectionInProgress; - private final Set> myFacetTypesWithDetectors = new THashSet>(); - private final EnableAutodetectionWorker myEnableAutodetectionWorker; - private final Object myLock = new Object(); - - public FacetAutodetectingManagerImpl(final Project project, PsiManager psiManager, FacetPointersManager facetPointersManager) { - myProject = project; - myPsiManager = psiManager; - myFacetPointersManager = facetPointersManager; - myDetectedFacetSet = new ProjectFacetInfoSet(project, project); - myEnableAutodetectionWorker = new EnableAutodetectionWorker(project, this); - } - - public void projectOpened() { - if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) return; - - myDetectedFacetSet.loadDetectedFacets(FacetDetectionIndex.getDetectedFacetsFile(myProject)); - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - myDetectedFacetManager.initUI(); - } - }); - } - - public void projectClosed() { - if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) return; - - myDetectedFacetSet.saveDetectedFacets(FacetDetectionIndex.getDetectedFacetsFile(myProject)); - if (myDetectedFacetManager != null) { - myDetectedFacetManager.disposeUI(); - } - } - - @NonNls - @NotNull - public String getComponentName() { - return "OldFacetAutodetectingManagerImpl"; - } - - public void initComponent() { - boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode(); - if (!unitTestMode && !myProject.isDefault()) { - initialize(); - } - } - - public void initialize() { - myDetectedFacetManager = new DetectedFacetManager(myProject, this, myDetectedFacetSet); - FacetType[] types = FacetTypeRegistry.getInstance().getFacetTypes(); - for (FacetType type : types) { - registerDetectors(type); - } - myFileIndex = new FacetDetectionIndex(myProject, this, myDetectors.keySet()); - myFileIndex.initialize(); - MyPsiTreeChangeListener psiTreeChangeListener = new MyPsiTreeChangeListener(); - myPsiManager.addPsiTreeChangeListener(psiTreeChangeListener, myProject); - myMergingUpdateQueue = new MergingUpdateQueue("FacetAutodetectionQueue", 500, true, null, myProject); - } - - private , C extends FacetConfiguration> void registerDetectors(final FacetType type) { - FacetOnTheFlyDetectorRegistryImpl detectorRegistry = new FacetOnTheFlyDetectorRegistryImpl(type); - type.registerDetectors(new FacetDetectorRegistryEx(null, detectorRegistry)); - if (detectorRegistry.hasDetectors()) { - myFacetTypesWithDetectors.add(type); - myDetectedFacetManager.registerListeners(type); - } - } - - @Nullable - public DisabledAutodetectionByTypeElement getDisabledAutodetectionState(@NotNull FacetType type) { - return myDisabledAutodetectionInfo.findElement(type.getStringId()); - } - - public void processFile(FileContent fileContent) { - final VirtualFile file = fileContent.getVirtualFile(); - if (!file.isValid() || file.isDirectory() || myProject.isDisposed() - || !file.exists() || !myFileIndex.getProjectFileIndex().isInContent(file)) return; - - FileType fileType = file.getFileType(); - Collection detectors = myDetectors.get(fileType); - if (detectors == null) return; - - synchronized (myLock) { - List> facets = null; - for (FacetDetectorWrapper detector : detectors) { - facets = process(file, fileContent, detector, facets); - } - - String url = file.getUrl(); - FacetDetectionIndexEntry indexEntry = myFileIndex.getIndexEntry(url); - if (indexEntry == null) { - indexEntry = new FacetDetectionIndexEntry(file.getTimeStamp()); - } - - Collection removed = indexEntry.update(myFacetPointersManager, facets); - myFileIndex.putIndexEntry(url, indexEntry); - - if (removed != null) { - removeObsoleteFacets(removed); - } - } - } - - public void removeObsoleteFacets(final Collection ids) { - for (Integer id : ids) { - Set urls = myFileIndex.getFiles(id); - if (urls == null || urls.isEmpty()) { - myDetectedFacetSet.removeDetectedFacetWithSubFacets(id); - } - } - } - - public ProjectFacetInfoSet getDetectedFacetSet() { - return myDetectedFacetSet; - } - - private List> process(final VirtualFile virtualFile, - FileContent fileContent, - final FacetDetectorWrapper detector, - List> facets) { - if (!myDetectionInProgress && detector.getFileContentPattern().accepts(fileContent)) { - try { - myDetectionInProgress = true; - FacetInfo2 facet = detector.detectFacet(virtualFile, myPsiManager); - - if (facet != null) { - if (facets == null) { - facets = new SmartList>(); - } - facets.add(facet); - } - } - finally { - myDetectionInProgress = false; - } - } - return facets; - } - - public void disposeComponent() { - if (!ApplicationManager.getApplication().isUnitTestMode() && !myProject.isDefault()) { - dispose(); - } - } - - public void dispose() { - if (myFileIndex != null) { - myFileIndex.dispose(); - } - } - - public void redetectFacets() { - myEnableAutodetectionWorker.redetectFacets(); - } - - @TestOnly - public EnableAutodetectionWorker getEnableAutodetectionWorker() { - return myEnableAutodetectionWorker; - } - - public boolean isAutodetectionEnabled(final Module module, final FacetType facetType, final String url) { - return !myDisabledAutodetectionInfo.isDisabled(facetType.getStringId(), module.getName(), url); - } - - private void queueUpdate(final PsiFile psiFile) { - if (!myDetectors.keySet().contains(psiFile.getFileType())) return; - - VirtualFile virtualFile = psiFile.getVirtualFile(); - if (virtualFile != null) { - queueUpdate(virtualFile); - } - } - - public void queueUpdate(final VirtualFile file) { - Update update = new Update("file:" + file.getUrl()) { - public void run() { - processFile(new FileContent(file)); - } - }; - - if (ApplicationManager.getApplication().isUnitTestMode()) { - update.run(); - } - else { - myMergingUpdateQueue.queue(update); - } - } - - @Nullable - public Set getFiles(final Facet facet) { - return myFileIndex.getFiles(facet); - } - - public void removeFacetFromCache(final Facet facet) { - myFileIndex.removeFacetFromCache(myFacetPointersManager.create(facet)); - } - - public Set getFileTypes(final Set facetTypes) { - THashSet fileTypes = new THashSet(); - for (FileType type : myDetectors.keySet()) { - Collection detectorWrappers = myDetectors.get(type); - if (detectorWrappers != null) { - for (FacetDetectorWrapper detectorWrapper : detectorWrappers) { - if (facetTypes.contains(detectorWrapper.getFacetType())) { - fileTypes.add(type); - break; - } - } - } - } - return fileTypes; - } - - public void disableAutodetectionInModule(final FacetType type, final Module module) { - myDisabledAutodetectionInfo.addDisabled(type.getStringId(), module.getName()); - } - - public void disableAutodetectionInFiles(@NotNull final FacetType type, @NotNull final Module module, @NotNull final String... fileUrls) { - myDisabledAutodetectionInfo.addDisabled(type.getStringId(), module.getName(), fileUrls); - } - - public void setDisabledAutodetectionState(final @NotNull FacetType facetType, final @Nullable DisabledAutodetectionByTypeElement element) { - String id = facetType.getStringId(); - DisabledAutodetectionByTypeElement oldElement = myDisabledAutodetectionInfo.findElement(id); - myEnableAutodetectionWorker.queueChanges(facetType, oldElement, element); - myDisabledAutodetectionInfo.replaceElement(id, element); - } - - public DetectedFacetManager getDetectedFacetManager() { - return myDetectedFacetManager; - } - - @Nullable - public FacetDetector findDetector(final String detectorId) { - return myId2Detector.get(detectorId); - } - - public FacetDetectionIndex getFileIndex() { - return myFileIndex; - } - - private class FacetOnTheFlyDetectorRegistryImpl> implements FacetOnTheFlyDetectorRegistry { - private final FacetType myType; - private boolean myHasDetectors; - - public FacetOnTheFlyDetectorRegistryImpl(final FacetType type) { - myType = type; - } - - public void register(@NotNull final FileType fileType, @NotNull final OldFileContentPattern fileContentFilter, - @NotNull final FacetDetector facetDetector, - final UnderlyingFacetSelector selector) { - myHasDetectors = true; - myId2Detector.put(facetDetector.getId(), facetDetector); - myDetectors.put(fileType, new FacetByVirtualFileDetectorWrapper(myDetectedFacetSet, myType, - FacetAutodetectingManagerImpl.this, fileContentFilter, - facetDetector, selector)); - } - - public void register(@NotNull final FileType fileType, @NotNull final OldFileContentPattern fileContentFilter, - @NotNull final Condition psiFileFilter, @NotNull final FacetDetector facetDetector, - final UnderlyingFacetSelector selector) { - myHasDetectors = true; - myId2Detector.put(facetDetector.getId(), facetDetector); - myDetectors.put(fileType, new FacetByPsiFileDetectorWrapper(myDetectedFacetSet, myType, FacetAutodetectingManagerImpl.this, - fileContentFilter, facetDetector, psiFileFilter, selector)); - } - - public boolean hasDetectors() { - return myHasDetectors; - } - } - - private class MyPsiTreeChangeListener extends PsiTreeChangeAdapter { - public void childAdded(final PsiTreeChangeEvent event) { - PsiElement child = event.getChild(); - if (child instanceof PsiFile) { - queueUpdate((PsiFile)child); - } - else { - processChangedElement(event); - } - } - - private void processChangedElement(final PsiTreeChangeEvent event) { - PsiFile psiFile = event.getFile(); - if (psiFile != null) { - queueUpdate(psiFile); - } - } - - public void childRemoved(final PsiTreeChangeEvent event) { - PsiElement child = event.getChild(); - if (child instanceof PsiFile) { - VirtualFile virtualFile = ((PsiFile)child).getVirtualFile(); - if (virtualFile != null) { - myFileIndex.removeIndexEntry(virtualFile); - } - } - else { - processChangedElement(event); - } - } - - public void childReplaced(final PsiTreeChangeEvent event) { - processChangedElement(event); - } - - public void childMoved(final PsiTreeChangeEvent event) { - processChangedElement(event); - } - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetByPsiFileDetectorWrapper.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetByPsiFileDetectorWrapper.java deleted file mode 100644 index f40274fe128b..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetByPsiFileDetectorWrapper.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.facet.impl.autodetecting.model.FacetInfo2; -import com.intellij.facet.impl.autodetecting.model.ProjectFacetInfoSet; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; - -/** - * @author nik - */ -public class FacetByPsiFileDetectorWrapper, U extends FacetConfiguration> extends FacetDetectorWrapper { - private final Condition myPsiFileFilter; - - public FacetByPsiFileDetectorWrapper(ProjectFacetInfoSet projectFacetSet, FacetType facetType, - final AutodetectionFilter autodetectionFilter, final OldFileContentPattern fileContentPattern, - final FacetDetector facetDetector, - Condition psiFileFilter, final UnderlyingFacetSelector selector) { - super(projectFacetSet, facetType, autodetectionFilter, fileContentPattern, facetDetector, selector); - myPsiFileFilter = psiFileFilter; - } - - public FacetInfo2 detectFacet(final VirtualFile virtualFile, final PsiManager psiManager) { - PsiFile psiFile = psiManager.findFile(virtualFile); - if (psiFile == null || !myPsiFileFilter.value(psiFile)) { - return null; - } - - Module module = ModuleUtil.findModuleForFile(virtualFile, psiManager.getProject()); - if (module == null) return null; - - return detectFacet(module, virtualFile, psiFile); - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetByVirtualFileDetectorWrapper.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetByVirtualFileDetectorWrapper.java deleted file mode 100644 index f73c0be75f5d..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetByVirtualFileDetectorWrapper.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.facet.impl.autodetecting.model.FacetInfo2; -import com.intellij.facet.impl.autodetecting.model.ProjectFacetInfoSet; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiManager; -import org.jetbrains.annotations.Nullable; - -/** - * @author nik - */ -public class FacetByVirtualFileDetectorWrapper, U extends FacetConfiguration> extends FacetDetectorWrapper { - public FacetByVirtualFileDetectorWrapper(ProjectFacetInfoSet projectFacetSet, FacetType facetType, - final AutodetectionFilter autodetectionFilter, final OldFileContentPattern fileContentPattern, - final FacetDetector facetDetector, - final UnderlyingFacetSelector selector) { - super(projectFacetSet, facetType, autodetectionFilter, fileContentPattern, facetDetector, selector); - } - - @Nullable - public FacetInfo2 detectFacet(final VirtualFile virtualFile, final PsiManager psiManager) { - Module module = ModuleUtil.findModuleForFile(virtualFile, psiManager.getProject()); - if (module == null) { - return null; - } - return detectFacet(module, virtualFile, virtualFile); - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectionIndex.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectionIndex.java deleted file mode 100644 index 0d448a06c2c4..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectionIndex.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetType; -import com.intellij.facet.FacetTypeRegistry; -import com.intellij.facet.impl.autodetecting.model.DetectedFacetInfo; -import com.intellij.facet.pointers.FacetPointer; -import com.intellij.facet.pointers.FacetPointersManager; -import com.intellij.ide.caches.FileContent; -import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ArrayUtil; -import com.intellij.util.SmartList; -import com.intellij.util.containers.BidirectionalMultiMap; -import com.intellij.util.fileIndex.AbstractFileIndex; -import gnu.trove.THashSet; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -/** - * @author nik - */ -public class FacetDetectionIndex extends AbstractFileIndex { - private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.autodetecting.FacetDetectionIndex"); - private static final byte CURRENT_VERSION = 1; - @NonNls private static final String CACHE_DIRECTORY_NAME = "facets"; - private final FileTypeManager myFileTypeManager; - private final Set myFileTypes; - private final Set myNewFacetTypes = new THashSet(); - private final FacetPointersManager myFacetPointersManager; - private final FacetAutodetectingManagerImpl myAutodetectingManager; - private final BidirectionalMultiMap myFacets; - private final BidirectionalMultiMap myDetectedFacetIds; - - public FacetDetectionIndex(final Project project, final FacetAutodetectingManagerImpl autodetectingManager, Set fileTypes) { - super(project); - myAutodetectingManager = autodetectingManager; - myFileTypes = new THashSet(fileTypes); - myFileTypeManager = FileTypeManager.getInstance(); - myFacetPointersManager = FacetPointersManager.getInstance(project); - myFacets = new BidirectionalMultiMap(); - myDetectedFacetIds = new BidirectionalMultiMap(); - } - - protected FacetDetectionIndexEntry createIndexEntry(final DataInputStream input) throws IOException { - return new FacetDetectionIndexEntry(input, myFacetPointersManager); - } - - public boolean belongs(final VirtualFile file) { - FileType fileType = myFileTypeManager.getFileTypeByFile(file); - return myFileTypes.contains(fileType); - } - - protected String getLoadingIndicesMessage() { - return ProjectBundle.message("progress.text.loading.facet.detection.indices"); - } - - public byte getCurrentVersion() { - return CURRENT_VERSION; - } - - public String getCachesDirName() { - return CACHE_DIRECTORY_NAME; - } - - public static File getDetectedFacetsFile(@NotNull Project project) { - return new File(PathManager.getSystemPath() + File.separator + CACHE_DIRECTORY_NAME + File.separator + project.getName() + ".detected." + project.getLocationHash()); - } - - protected void readHeader(final DataInputStream input) throws IOException { - int size = input.readInt(); - Set facetTypesInCache = new THashSet(); - while (size-- > 0) { - facetTypesInCache.add(input.readUTF()); - } - Set unknownTypes = new THashSet(facetTypesInCache); - for (FacetType type : FacetTypeRegistry.getInstance().getFacetTypes()) { - unknownTypes.remove(type.getStringId()); - if (!facetTypesInCache.contains(type.getStringId())) { - myNewFacetTypes.add(type); - } - } - if (!unknownTypes.isEmpty()) { - LOG.info("Unknown facet types in cache: " + new HashSet(unknownTypes)); - } - } - - @Nullable - protected Set getFileTypesToRefresh() { - if (myNewFacetTypes.isEmpty()) { - return null; - } - - return myAutodetectingManager.getFileTypes(myNewFacetTypes); - } - - protected void writeHeader(final DataOutputStream output) throws IOException { - FacetType[] types = FacetTypeRegistry.getInstance().getFacetTypes(); - output.writeInt(types.length); - for (FacetType type : types) { - output.writeUTF(type.getStringId()); - } - } - - public void queueEntryUpdate(final VirtualFile file) { - myAutodetectingManager.queueUpdate(file); - } - - protected void doUpdateIndexEntry(final FileContent fileContent) { - myAutodetectingManager.processFile(fileContent); - } - - @Nullable - public Set getFiles(Integer id) { - return myDetectedFacetIds.getKeys(id); - } - - @Nullable - public Set getFiles(final Facet facet) { - return myFacets.getKeys(myFacetPointersManager.create(facet)); - } - - protected void onEntryAdded(final String url, final FacetDetectionIndexEntry entry) { - myFacets.removeKey(url); - SmartList detectedFacets = entry.getFacets(); - if (detectedFacets != null) { - for (FacetPointer detectedFacet : detectedFacets) { - myFacets.put(url, detectedFacet); - } - } - myDetectedFacetIds.removeKey(url); - SmartList facetIds = entry.getDetectedFacetIds(); - if (facetIds != null) { - for (Integer id : facetIds) { - myDetectedFacetIds.put(url, id); - } - } - } - - protected void onEntryRemoved(final String url, final FacetDetectionIndexEntry entry) { - Set ids = myDetectedFacetIds.getValues(url); - myDetectedFacetIds.removeKey(url); - if (ids != null && !ids.isEmpty()) { - myAutodetectingManager.removeObsoleteFacets(ids); - } - } - - public void removeFacetFromCache(final FacetPointer facetPointer) { - Set urls = myFacets.getKeys(facetPointer); - if (urls != null) { - for (String url : urls) { - FacetDetectionIndexEntry indexEntry = getIndexEntry(url); - if (indexEntry != null) { - indexEntry.remove(facetPointer); - } - } - } - myFacets.removeValue(facetPointer); - } - - public void updateIndexEntryForCreatedFacet(final DetectedFacetInfo info, final Facet facet) { - FacetPointer pointer = FacetPointersManager.getInstance(facet.getModule().getProject()).create(facet); - Set urls = myDetectedFacetIds.getKeys(info.getId()); - if (urls != null) { - String[] urlsArray = ArrayUtil.toStringArray(urls); - for (String url : urlsArray) { - myDetectedFacetIds.remove(url, info.getId()); - myFacets.put(url, pointer); - FacetDetectionIndexEntry indexEntry = getIndexEntry(url); - indexEntry.remove(info.getId()); - indexEntry.add(pointer); - } - } - } - - public boolean isEmpty() { - return myDetectedFacetIds.isEmpty() && myFacets.isEmpty(); - } - - public void removeFromIndex(final DetectedFacetInfo info) { - int id = info.getId(); - Set urls = myDetectedFacetIds.getKeys(id); - if (urls != null) { - for (String url : urls) { - FacetDetectionIndexEntry entry = getIndexEntry(url); - if (entry != null) { - entry.remove(id); - } - } - } - myDetectedFacetIds.removeValue(id); - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectionIndexEntry.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectionIndexEntry.java deleted file mode 100644 index f77be9dfee5b..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectionIndexEntry.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.Facet; -import com.intellij.facet.impl.autodetecting.model.DetectedFacetInfo; -import com.intellij.facet.impl.autodetecting.model.FacetInfo2; -import com.intellij.facet.impl.autodetecting.model.FacetInfoBackedByFacet; -import com.intellij.facet.pointers.FacetPointer; -import com.intellij.facet.pointers.FacetPointersManager; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.util.SmartList; -import com.intellij.util.fileIndex.FileIndexEntry; -import org.jetbrains.annotations.Nullable; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * @author nik -*/ -public class FacetDetectionIndexEntry extends FileIndexEntry { - private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.autodetecting.FacetDetectionIndexEntry"); - private SmartList myFacets; - private SmartList myDetectedFacetIds; - - public FacetDetectionIndexEntry(final long timestamp) { - super(timestamp); - } - - public FacetDetectionIndexEntry(final DataInputStream stream, final FacetPointersManager facetPointersManager) throws IOException { - super(stream); - int size = stream.readInt(); - if (size > 0) { - while (size-- > 0) { - String id = stream.readUTF(); - if (id.startsWith("/")) { - if (myDetectedFacetIds == null) { - myDetectedFacetIds = new SmartList(); - } - myDetectedFacetIds.add(Integer.parseInt(id.substring(1))); - } - else { - if (myFacets == null) { - myFacets = new SmartList(); - } - myFacets.add(facetPointersManager.create(id)); - } - } - } - } - - @Nullable - public SmartList getFacets() { - return myFacets; - } - - @Nullable - public SmartList getDetectedFacetIds() { - return myDetectedFacetIds; - } - - public void write(final DataOutputStream stream) throws IOException { - super.write(stream); - int number = (myFacets != null ? myFacets.size() : 0) + (myDetectedFacetIds != null ? myDetectedFacetIds.size() : 0); - stream.writeInt(number); - if (myFacets != null) { - for (FacetPointer facetPointer : myFacets) { - stream.writeUTF(facetPointer.getId()); - } - } - if (myDetectedFacetIds != null) { - for (Integer id : myDetectedFacetIds) { - stream.writeUTF("/" + id); - } - } - } - - @Nullable - public Collection update(final FacetPointersManager facetPointersManager, final @Nullable List> detectedFacets) { - if (detectedFacets == null || detectedFacets.isEmpty()) { - SmartList old = myDetectedFacetIds; - myFacets = null; - myDetectedFacetIds = null; - return old; - } - - if (myFacets == null) { - myFacets = new SmartList(); - } - else { - myFacets.clear(); - } - - if (myDetectedFacetIds == null) { - myDetectedFacetIds = new SmartList(); - } - - Set toRemove = new HashSet(myDetectedFacetIds); - for (FacetInfo2 info : detectedFacets) { - if (info instanceof FacetInfoBackedByFacet) { - FacetPointer pointer = facetPointersManager.create(((FacetInfoBackedByFacet)info).getFacet()); - LOG.assertTrue(pointer.getModuleName().length() > 0);//IDEADEV-34200 - myFacets.add(pointer); - } - else { - Integer id = ((DetectedFacetInfo)info).getId(); - boolean removed = toRemove.remove(id); - if (!removed) { - myDetectedFacetIds.add(id); - } - } - } - myDetectedFacetIds.removeAll(toRemove); - return toRemove; - } - - public void remove(final FacetPointer facetPointer) { - if (myFacets != null) { - myFacets.remove(facetPointer); - } - } - - public void remove(final Integer id) { - if (myDetectedFacetIds != null) { - myDetectedFacetIds.remove(id); - } - } - - public void add(final FacetPointer pointer) { - if (myFacets == null) { - myFacets = new SmartList(); - } - LOG.assertTrue(pointer.getModuleName().length() > 0);//IDEADEV-34200 - myFacets.add(pointer); - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorForWizardRegistry.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorForWizardRegistry.java deleted file mode 100644 index f003acf34734..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorForWizardRegistry.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; - -/** - * @author nik - */ -public interface FacetDetectorForWizardRegistry { - void register(final FileType fileType, @NotNull final OldFileContentPattern fileContentPattern, - final FacetDetector facetDetector, - final UnderlyingFacetSelector underlyingFacetSelector); -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorRegistryEx.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorRegistryEx.java deleted file mode 100644 index ac513ef16012..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorRegistryEx.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.facet.autodetecting.DetectedFacetPresentation; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.FacetDetectorRegistry; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileFilter; -import com.intellij.patterns.ElementPattern; -import com.intellij.patterns.VirtualFilePattern; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author nik - */ -public class FacetDetectorRegistryEx implements FacetDetectorRegistry { - private final @Nullable FacetDetectorForWizardRegistry myForWizardDelegate; - private final @Nullable FacetOnTheFlyDetectorRegistry myOnTheFlyDelegate; - private DetectedFacetPresentation myPresentation; - - public FacetDetectorRegistryEx(final @Nullable FacetDetectorForWizardRegistry forWizardDelegate, final @Nullable FacetOnTheFlyDetectorRegistry onTheFlyDelegate) { - myForWizardDelegate = forWizardDelegate; - myOnTheFlyDelegate = onTheFlyDelegate; - } - - public void customizeDetectedFacetPresentation(@NotNull final DetectedFacetPresentation presentation) { - myPresentation = presentation; - } - - public void registerUniversalDetectorByRootTag(@NotNull final String rootTag, @NotNull final FacetDetector detector) { - registerUniversalDetector(StdFileTypes.XML, OldFileContentPattern.fileContent().xmlWithRootTag(rootTag), detector, null); - } - - public void registerUniversalDetectorByFileNameAndRootTag(@NotNull @NonNls String fileName, - @NotNull @NonNls String rootTag, - @NotNull final FacetDetector detector, - @Nullable UnderlyingFacetSelector underlyingFacetSelector) { - registerUniversalDetector(StdFileTypes.XML, OldFileContentPattern.fileContent().withName(fileName).xmlWithRootTag(rootTag), detector, underlyingFacetSelector); - } - - public void registerDetectorForWizard(@NotNull final FileType fileType, @NotNull final VirtualFileFilter virtualFileFilter, @NotNull final FacetDetector facetDetector) { - if (myForWizardDelegate != null) { - myForWizardDelegate.register(fileType, OldFileContentPattern.byFilter(virtualFileFilter), facetDetector, null); - } - } - - public void registerDetectorForWizard(@NotNull final FileType fileType, @NotNull final VirtualFilePattern virtualFilePattern, - @NotNull final FacetDetector facetDetector) { - if (myForWizardDelegate != null) { - myForWizardDelegate.register(fileType, OldFileContentPattern.byFilePattern(virtualFilePattern), facetDetector, null); - } - } - - public void registerSubFacetDetectorForWizard(@NotNull final FileType fileType, @NotNull final VirtualFilePattern virtualFilePattern, - @NotNull final FacetDetector facetDetector, - @NotNull final UnderlyingFacetSelector underlyingFacetSelector) { - if (myForWizardDelegate != null) { - myForWizardDelegate.register(fileType, OldFileContentPattern.byFilePattern(virtualFilePattern), facetDetector, underlyingFacetSelector); - } - } - - - private void registerOnTheFlyDetector(@NotNull final FileType fileType, - @NotNull final VirtualFileFilter virtualFileFilter, - @NotNull final Condition psiFileFilter, - @NotNull final FacetDetector facetDetector, - @Nullable UnderlyingFacetSelector selector) { - if (myOnTheFlyDelegate != null) { - myOnTheFlyDelegate.register(fileType, OldFileContentPattern.byFilter(virtualFileFilter), psiFileFilter, facetDetector, selector); - } - } - - public void registerOnTheFlySubFacetDetector(@NotNull final FileType fileType, - @NotNull final VirtualFilePattern virtualFilePattern, - @NotNull final ElementPattern psiFilePattern, - @NotNull final FacetDetector facetDetector, - final UnderlyingFacetSelector selector) { - registerOnTheFlyDetector(fileType, new MyPatternFilter(virtualFilePattern), new Condition() { - public boolean value(final PsiFile psiFile) { - return psiFilePattern.accepts(psiFile); - } - }, facetDetector, selector); - } - - public void registerOnTheFlyDetector(@NotNull final FileType fileType, @NotNull final VirtualFilePattern virtualFilePattern, - @NotNull final ElementPattern psiFilePattern, - @NotNull final FacetDetector facetDetector) { - registerOnTheFlySubFacetDetector(fileType, virtualFilePattern, psiFilePattern, facetDetector, null); - } - - public void registerOnTheFlyDetector(@NotNull final FileType fileType, @NotNull final VirtualFileFilter virtualFileFilter, @NotNull final Condition psiFileFilter, - @NotNull final FacetDetector facetDetector) { - registerOnTheFlyDetector(fileType, virtualFileFilter, psiFileFilter, facetDetector, null); - } - - - - public void registerUniversalDetector(@NotNull final FileType fileType, @NotNull final VirtualFilePattern virtualFilePattern, - @NotNull final FacetDetector facetDetector) { - registerUniversalDetector(fileType, new MyPatternFilter(virtualFilePattern), facetDetector); - } - - public void registerUniversalDetector(@NotNull final FileType fileType, @NotNull final VirtualFileFilter virtualFileFilter, @NotNull final FacetDetector facetDetector) { - registerUniversalDetector(fileType, OldFileContentPattern.byFilter(virtualFileFilter), facetDetector, null); - } - - public void registerUniversalDetector(@NotNull final FileType fileType, - @NotNull final OldFileContentPattern fileContentFilter, - @NotNull final FacetDetector facetDetector, - final UnderlyingFacetSelector underlyingFacetSelector) { - if (myForWizardDelegate != null) { - myForWizardDelegate.register(fileType, fileContentFilter, facetDetector, underlyingFacetSelector); - } - if (myOnTheFlyDelegate != null) { - myOnTheFlyDelegate.register(fileType, fileContentFilter, facetDetector, underlyingFacetSelector); - } - } - - public void registerUniversalSubFacetDetector(@NotNull final FileType fileType, @NotNull final VirtualFilePattern virtualFilePattern, - @NotNull final FacetDetector facetDetector, - final UnderlyingFacetSelector underlyingFacetSelector) { - registerUniversalDetector(fileType, OldFileContentPattern.byFilePattern(virtualFilePattern), facetDetector, underlyingFacetSelector); - } - - private static class MyPatternFilter implements VirtualFileFilter { - private final VirtualFilePattern myVirtualFilePattern; - - public MyPatternFilter(final VirtualFilePattern virtualFilePattern) { - myVirtualFilePattern = virtualFilePattern; - } - - public boolean accept(final VirtualFile file) { - return myVirtualFilePattern.accepts(file); - } - } - - @NotNull - public static DetectedFacetPresentation getDetectedFacetPresentation(@NotNull FacetType facetType) { - FacetDetectorRegistryEx registry = new FacetDetectorRegistryEx(null, null); - facetType.registerDetectors(registry); - DetectedFacetPresentation presentation = registry.myPresentation; - return presentation != null ? presentation : DefaultDetectedFacetPresentation.INSTANCE; - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorWrapper.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorWrapper.java deleted file mode 100644 index c0408f54466f..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetDetectorWrapper.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.facet.FacetTypeId; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.facet.impl.autodetecting.model.FacetInfo2; -import com.intellij.facet.impl.autodetecting.model.ProjectFacetInfoSet; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiManager; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.Map; - -/** - * @author nik - */ -public abstract class FacetDetectorWrapper, U extends FacetConfiguration> { - private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.autodetecting.FacetDetectorWrapper"); - private final AutodetectionFilter myAutodetectionFilter; - private final OldFileContentPattern myFileContentPattern; - private final FacetDetector myFacetDetector; - private final UnderlyingFacetSelector myUnderlyingFacetSelector; - private final ProjectFacetInfoSet myDetectedFacetSet; - private final FacetType myFacetType; - - protected FacetDetectorWrapper(ProjectFacetInfoSet projectFacetSet, FacetType facetType, final AutodetectionFilter autodetectionFilter, final OldFileContentPattern fileContentPattern, - final FacetDetector facetDetector, - final UnderlyingFacetSelector selector) { - myDetectedFacetSet = projectFacetSet; - myFacetType = facetType; - myAutodetectionFilter = autodetectionFilter; - myFileContentPattern = fileContentPattern; - myFacetDetector = facetDetector; - myUnderlyingFacetSelector = selector; - } - - public OldFileContentPattern getFileContentPattern() { - return myFileContentPattern; - } - - public FacetType getFacetType() { - return myFacetType; - } - - @Nullable - protected FacetInfo2 detectFacet(@NotNull final Module module, VirtualFile virtualFile, S source) { - if (!myFacetType.isSuitableModuleType(module.getModuleType())) return null; - - String url = virtualFile.getUrl(); - if (!myAutodetectionFilter.isAutodetectionEnabled(module, myFacetType, url)) { - LOG.debug("Autodetection disabled for " + myFacetType.getPresentableName() + " facets in module " + module.getName()); - return null; - } - - FacetInfo2 underlyingFacet = null; - FacetTypeId underlyingFacetType = myFacetType.getUnderlyingFacetType(); - if (underlyingFacetType != null) { - if (myUnderlyingFacetSelector != null) { - Map> underlyingFacets = myDetectedFacetSet.getConfigurations(underlyingFacetType, module); - FacetConfiguration undelyingConfiguration = - myUnderlyingFacetSelector.selectUnderlyingFacet(virtualFile, Collections.unmodifiableSet(underlyingFacets.keySet())); - underlyingFacet = underlyingFacets.get(undelyingConfiguration); - } - if (underlyingFacet == null) { - LOG.debug("Underlying " + underlyingFacetType + " facet not found for " + url); - return null; - } - } - - Map> configurations = myDetectedFacetSet.getConfigurations(myFacetType.getId(), module); - - final C detectedConfiguration = myFacetDetector.detectFacet(source, Collections.unmodifiableSet(configurations.keySet())); - if (detectedConfiguration == null) { - return null; - } - - if (configurations.containsKey(detectedConfiguration)) { - return configurations.get(detectedConfiguration); - } - - final String name = myDetectedFacetSet.generateName(module, myFacetType); - FacetInfo2 detected = myDetectedFacetSet.createInfo(module, url, underlyingFacet, detectedConfiguration, name, myFacetType, myFacetDetector.getId()); - myDetectedFacetSet.addFacetInfo(detected); - return detected; - } - - @Override - public String toString() { - return myFacetType.getStringId() + ": " + myFacetDetector.getId(); - } - - @Nullable - public abstract FacetInfo2 detectFacet(final VirtualFile virtualFile, final PsiManager psiManager); -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetOnTheFlyDetectorRegistry.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetOnTheFlyDetectorRegistry.java deleted file mode 100644 index 8fec858683b6..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetOnTheFlyDetectorRegistry.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting; - -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; - -/** - * @author nik - */ -public interface FacetOnTheFlyDetectorRegistry { - - void register(@NotNull FileType fileType, @NotNull OldFileContentPattern fileContentPattern, - @NotNull FacetDetector detector, UnderlyingFacetSelector selector); - - - void register(@NotNull FileType fileType, @NotNull OldFileContentPattern fileContentPattern, - @NotNull Condition psiFileFilter, @NotNull FacetDetector detector, - UnderlyingFacetSelector selector); -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/OldFileContentPattern.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/OldFileContentPattern.java deleted file mode 100644 index 86f333ee3364..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/OldFileContentPattern.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting; - -import com.intellij.ide.caches.FileContent; -import com.intellij.openapi.vfs.VirtualFileFilter; -import com.intellij.patterns.*; -import com.intellij.psi.impl.cache.impl.CacheUtil; -import com.intellij.util.ProcessingContext; -import com.intellij.util.text.CharSequenceReader; -import com.intellij.util.xml.NanoXmlUtil; -import com.intellij.util.xml.XmlFileHeader; -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; - -/** - * @author nik - */ -public class OldFileContentPattern extends ObjectPattern { - public OldFileContentPattern() { - super(FileContent.class); - } - - public static OldFileContentPattern fileContent() { - return new OldFileContentPattern(); - } - - public OldFileContentPattern withName(@NotNull final String name) { - return with(new PatternCondition("withName") { - @Override - public boolean accepts(@NotNull FileContent fileContent, ProcessingContext context) { - return name.equals(fileContent.getVirtualFile().getName()); - } - }); - } - - public OldFileContentPattern withName(final StringPattern namePattern) { - return with(new PatternCondition("withName") { - @Override - public boolean accepts(@NotNull FileContent fileContent, ProcessingContext context) { - return namePattern.accepts(fileContent.getVirtualFile().getName()); - } - }); - } - - public OldFileContentPattern inDirectory(final @NotNull String name) { - return with(new PatternCondition("inDirectory") { - @Override - public boolean accepts(@NotNull FileContent fileContent, ProcessingContext context) { - return name.equals(fileContent.getVirtualFile().getParent().getName()); - } - }); - } - - public OldFileContentPattern xmlWithRootTag(@NotNull final String rootTag) { - return with(new PatternCondition("withRootTag") { - @Override - public boolean accepts(@NotNull FileContent fileContent, ProcessingContext context) { - try { - return rootTag.equals(parseHeaderWithException(fileContent).getRootTagLocalName()); - } - catch (IOException e) { - return false; - } - } - }); - } - - public OldFileContentPattern xmlWithRootTagNamespace(final String namespace) { - return xmlWithRootTagNamespace(StandardPatterns.string().equalTo(namespace)); - } - - public OldFileContentPattern xmlWithRootTagNamespace(final ElementPattern namespacePattern) { - return with(new PatternCondition("xmlWithRootTagNamespace") { - public boolean accepts(@NotNull final FileContent fileContent, final ProcessingContext context) { - try { - String rootTagNamespace = parseHeaderWithException(fileContent).getRootTagNamespace(); - return rootTagNamespace != null && namespacePattern.getCondition().accepts(rootTagNamespace, context); - } - catch (IOException e) { - return false; - } - } - }); - } - - public static OldFileContentPattern byFilter(@NotNull final VirtualFileFilter filter) { - return fileContent().with(new PatternCondition("withFileFilter") { - @Override - public boolean accepts(@NotNull FileContent fileContent, ProcessingContext context) { - return filter.accept(fileContent.getVirtualFile()); - } - }); - } - - public static OldFileContentPattern byFilePattern(@NotNull final VirtualFilePattern pattern) { - return fileContent().with(new PatternCondition("withFilePattern") { - @Override - public boolean accepts(@NotNull FileContent fileContent, ProcessingContext context) { - return pattern.accepts(fileContent.getVirtualFile()); - } - }); - } - - @NotNull - private static XmlFileHeader parseHeaderWithException(FileContent fileContent) throws IOException { - final CharSequence contentText = CacheUtil.getContentText(fileContent); - //noinspection IOResourceOpenedButNotSafelyClosed - return NanoXmlUtil.parseHeaderWithException(new CharSequenceReader(contentText)); - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsDialog.form b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsDialog.form deleted file mode 100644 index c1e808b35a12..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsDialog.form +++ /dev/null @@ -1,36 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsDialog.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsDialog.java deleted file mode 100644 index 9714f55121cb..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsDialog.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting.facetsTree; - -import com.intellij.facet.impl.autodetecting.DetectedFacetManager; -import com.intellij.facet.impl.autodetecting.model.DetectedFacetInfo; -import com.intellij.openapi.application.Result; -import com.intellij.openapi.application.WriteAction; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.help.HelpManager; -import com.intellij.util.ui.tree.TreeUtil; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - -/** - * @author nik - */ -public class DetectedFacetsDialog extends DialogWrapper { - private final ImplicitFacetsTreeComponent myFacetsTreeComponent; - private JPanel myMainPanel; - private JPanel myTreePanel; - - public DetectedFacetsDialog(final Project project, final DetectedFacetManager detectedFacetsManager, final Collection> detectedFacets, - final HashMap, List> files) { - super(project, true); - setTitle(ProjectBundle.message("dialog.title.facets.detected")); - myFacetsTreeComponent = new ImplicitFacetsTreeComponent(detectedFacetsManager, detectedFacets, files); - DetectedFacetsTree tree = myFacetsTreeComponent.getTree(); - TreeUtil.expandAll(tree); - myTreePanel.add(tree, BorderLayout.CENTER); - setOKButtonText(ProjectBundle.message("button.text.accept.detected.facets")); - setCancelButtonText(ProjectBundle.message("button.text.postpone.detected.facets")); - init(); - } - - @Nullable - protected JComponent createCenterPanel() { - return myMainPanel; - } - - @Override - protected Action[] createActions() { - return new Action[]{getOKAction(), getCancelAction(), getHelpAction()}; - } - - @Override - protected void doHelpAction() { - HelpManager.getInstance().invokeHelp("procedures.workingwithmodules.facet"); - } - - protected void doOKAction() { - new WriteAction() { - protected void run(final Result result) { - myFacetsTreeComponent.createFacets(); - } - }.execute(); - super.doOKAction(); - } - -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsTree.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsTree.java deleted file mode 100644 index 5516585d0a65..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsTree.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting.facetsTree; - -import com.intellij.facet.FacetType; -import com.intellij.facet.autodetecting.DetectedFacetPresentation; -import com.intellij.facet.impl.autodetecting.FacetDetectorRegistryEx; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.CheckboxTreeBase; -import com.intellij.ui.CheckedTreeNode; -import com.intellij.ui.ColoredTreeCellRenderer; -import com.intellij.ui.SimpleTextAttributes; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author nik -*/ -public class DetectedFacetsTree extends CheckboxTreeBase { - private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.autodetecting.facetsTree.DetectedFacetsTree"); - private static final Icon MODULE_ICON = IconLoader.getIcon("/nodes/ModuleClosed.png"); - - public DetectedFacetsTree(final Collection roots) { - super(new FacetsCheckboxTreeCellRenderer(), createRoot(roots), new CheckPolicy(true, true, true, false)); - } - - private static CheckedTreeNode createRoot(final Collection nodes) { - CheckedTreeNode root = new CheckedTreeNode(null); - for (CheckedTreeNode node : nodes) { - if (!(node instanceof FacetTypeNode) && !(node instanceof ModuleNode) && !(node instanceof FacetNode)) { - LOG.error("incorrect node class: " + node.getClass().getName()); - - } - root.add(node); - } - return root; - } - - private static class FacetsCheckboxTreeCellRenderer extends CheckboxTreeCellRendererBase { - public void customizeRenderer(final JTree tree, - final Object value, - final boolean selected, - final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { - ColoredTreeCellRenderer renderer = getTextRenderer(); - if (value instanceof ModuleNode) { - ModuleNode moduleNode = (ModuleNode)value; - renderer.setIcon(MODULE_ICON); - renderer.append(moduleNode.getModuleName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); - renderer.append(moduleNode.getModuleDescription(), SimpleTextAttributes.GRAY_ATTRIBUTES); - } - else if (value instanceof FacetNode) { - final FacetNode node = (FacetNode)value; - FacetType type = node.getFacetType(); - renderer.setIcon(type.getIcon()); - renderer.append(node.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); - String description = node.getDescription(); - if (description != null) { - renderer.append(" (" + description + ")", SimpleTextAttributes.GRAY_ATTRIBUTES); - } - } - else if (value instanceof FacetTypeNode) { - FacetType type = ((FacetTypeNode)value).getFacetType(); - renderer.setIcon(type.getIcon()); - renderer.append(ProjectBundle.message("detected.facet.type.node", type.getPresentableName()), SimpleTextAttributes.REGULAR_ATTRIBUTES); - } - } - - } - - public static abstract class ModuleNode extends CheckedTreeNode{ - private final List myRootFacets = new ArrayList(); - - public ModuleNode(Object userObject) { - super(userObject); - } - - - public abstract String getModuleName(); - - public abstract String getModuleDescription(); - - public void addRootFacet(FacetNode facetInfo) { - myRootFacets.add(facetInfo); - add(facetInfo); - } - - public List getRootFacets() { - return myRootFacets; - } - } - - public static class FacetTypeNode extends CheckedTreeNode { - private final FacetType myFacetType; - private final List myModuleNodes = new ArrayList(); - - public FacetTypeNode(final FacetType facetType) { - super(facetType); - myFacetType = facetType; - } - - public FacetType getFacetType() { - return myFacetType; - } - - public void addModuleNode(ModuleNode moduleNode) { - myModuleNodes.add(moduleNode); - add(moduleNode); - } - - public List getModuleNodes() { - return myModuleNodes; - } - } - - public static class FacetNode extends CheckedTreeNode { - private final VirtualFile[] myFiles; - private final FacetType myFacetType; - private final VirtualFile myProjectRoot; - private final List myChildren = new ArrayList(); - - public FacetNode(Object userObject, FacetType facetType, VirtualFile projectRoot, final VirtualFile[] files, @Nullable FacetNode parent) { - super(userObject); - myFacetType = facetType; - myProjectRoot = projectRoot; - myFiles = files; - if (parent != null) { - parent.myChildren.add(this); - parent.add(this); - } - } - - public String getName() { - return myFacetType.getPresentableName(); - } - - public VirtualFile[] getFiles() { - return myFiles; - } - - public List getChildren() { - return myChildren; - } - - public FacetType getFacetType() { - return myFacetType; - } - - @Nullable - public String getDescription() { - DetectedFacetPresentation presentation = FacetDetectorRegistryEx.getDetectedFacetPresentation(myFacetType); - return presentation.getDetectedFacetDescription(myProjectRoot, myFiles); - } - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsTreeComponent.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsTreeComponent.java deleted file mode 100644 index 0d25027c6780..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/DetectedFacetsTreeComponent.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting.facetsTree; - -import com.intellij.facet.*; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager; -import com.intellij.facet.impl.ui.FacetDetectionProcessor; -import com.intellij.ide.util.importProject.ModuleDescriptor; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.roots.ModifiableRootModel; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.CheckboxTreeBase; -import com.intellij.util.ui.tree.TreeUtil; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.util.*; -import java.util.List; - -/** - * @author nik - */ -public class DetectedFacetsTreeComponent { - private final JPanel myMainPanel; - private final List myModuleNodes = new ArrayList(); - - public DetectedFacetsTreeComponent() { - myMainPanel = new JPanel(new BorderLayout()); - } - - public JPanel getMainPanel() { - return myMainPanel; - } - - public void addFacets(ModuleDescriptor moduleDescriptor, Map> root2Facets) { - for (File root : root2Facets.keySet()) { - ModuleDescriptorNode moduleNode = new ModuleDescriptorNode(moduleDescriptor, root); - - Map facetInfos = new HashMap(); - for (FacetDetectionProcessor.DetectedInWizardFacetInfo detectedFacetInfo : root2Facets.get(root)) { - DetectedFacetsTree.FacetNode parent = null; - FacetInfo underlyingFacet = detectedFacetInfo.getFacetInfo().getUnderlyingFacet(); - if (underlyingFacet != null) { - parent = facetInfos.get(underlyingFacet); - } - - VirtualFile virtualRoot = LocalFileSystem.getInstance().findFileByIoFile(root); - DetectedFacetsTree.FacetNode detectedFacet = new FacetInfoNode(detectedFacetInfo, virtualRoot, parent); - facetInfos.put(detectedFacetInfo.getFacetInfo(), detectedFacet); - if (parent == null) { - moduleNode.addRootFacet(detectedFacet); - } - } - - myModuleNodes.add(moduleNode); - } - } - - public void createTree() { - final CheckboxTreeBase tree = new DetectedFacetsTree(myModuleNodes); - TreeUtil.expandAll(tree); - myMainPanel.add(tree, BorderLayout.CENTER); - } - - public void clear() { - myMainPanel.removeAll(); - myModuleNodes.clear(); - } - - public void createFacets(final ModuleDescriptor descriptor, final Module module, final ModifiableRootModel rootModel) { - List> createdFacets = new ArrayList>(); - ModifiableFacetModel modifiableModel = FacetManager.getInstance(module).createModifiableModel(); - for (ModuleDescriptorNode moduleNode : myModuleNodes) { - if (moduleNode.myModuleDescriptor.equals(descriptor)) { - processFacetsInfos(moduleNode.getRootFacets(), module, rootModel, modifiableModel, null, createdFacets, moduleNode.isChecked()); - } - } - modifiableModel.commit(); - for (Pair createdFacet : createdFacets) { - createdFacet.getFirst().afterFacetAdded(createdFacet.getSecond()); - } - } - - private static void processFacetsInfos(final List facets, final Module module, final ModifiableRootModel rootModel, - final ModifiableFacetModel facetModel, Facet underlyingFacet, - final List> createdFacets, boolean createFacets) { - for (DetectedFacetsTree.FacetNode facetNode : facets) { - boolean createFacet = createFacets && facetNode.isChecked(); - FacetDetectionProcessor.DetectedInWizardFacetInfo detectedFacetInfo = ((FacetInfoNode)facetNode).getDetectedFacetInfo(); - FacetInfo facetInfo = detectedFacetInfo.getFacetInfo(); - FacetType type = facetInfo.getFacetType(); - Facet facet = null; - - if (createFacet) { - //noinspection unchecked - facet = FacetManager.getInstance(module).createFacet(type, facetInfo.getName(), facetInfo.getConfiguration(), underlyingFacet); - FacetDetector facetDetector = detectedFacetInfo.getFacetDetector(); - facetDetector.beforeFacetAdded(facet, facetModel, rootModel); - - facetModel.addFacet(facet); - createdFacets.add(Pair.create(facetDetector, facet)); - } - else { - VirtualFile[] files = facetNode.getFiles(); - String[] urls = new String[files.length]; - for (int i = 0; i < files.length; i++) { - urls[i] = files[i].getUrl(); - } - FacetAutodetectingManager.getInstance(module.getProject()).disableAutodetectionInFiles(type, module, urls); - } - - processFacetsInfos(facetNode.getChildren(), module, rootModel, facetModel, facet, createdFacets, createFacet); - } - } - - private static class FacetInfoNode extends DetectedFacetsTree.FacetNode { - private final FacetDetectionProcessor.DetectedInWizardFacetInfo myDetectedFacetInfo; - - private FacetInfoNode(final FacetDetectionProcessor.DetectedInWizardFacetInfo detectedFacetInfo, final VirtualFile root, @Nullable final DetectedFacetsTree.FacetNode parent) { - super(detectedFacetInfo.getFacetInfo(), detectedFacetInfo.getFacetInfo().getFacetType(), root, new VirtualFile[]{detectedFacetInfo.getFile()}, parent); - myDetectedFacetInfo = detectedFacetInfo; - } - - public FacetDetectionProcessor.DetectedInWizardFacetInfo getDetectedFacetInfo() { - return myDetectedFacetInfo; - } - } - - private static class ModuleDescriptorNode extends DetectedFacetsTree.ModuleNode { - private final ModuleDescriptor myModuleDescriptor; - private final File myRoot; - - private ModuleDescriptorNode(ModuleDescriptor moduleDescriptor, final File root) { - super(moduleDescriptor); - myModuleDescriptor = moduleDescriptor; - myRoot = root; - } - - public String getModuleName() { - return myModuleDescriptor.getName(); - } - - public String getModuleDescription() { - return " (" + myRoot.getPath() + ")"; - } - } - -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/ImplicitFacetsTreeComponent.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/ImplicitFacetsTreeComponent.java deleted file mode 100644 index b297ea5b6d68..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/facetsTree/ImplicitFacetsTreeComponent.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.autodetecting.facetsTree; - -import com.intellij.facet.FacetType; -import com.intellij.facet.Facet; -import com.intellij.facet.impl.autodetecting.DetectedFacetManager; -import com.intellij.facet.impl.autodetecting.model.DetectedFacetInfo; -import com.intellij.facet.impl.autodetecting.model.FacetInfo2; -import com.intellij.facet.impl.autodetecting.model.FacetInfoBackedByFacet; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; - -import java.util.*; - -/** - * @author nik - */ -public class ImplicitFacetsTreeComponent { - private final DetectedFacetsTree myTree; - private final DetectedFacetManager myDetectedFacetManager; - private final Collection myFacetTypeNodes; - - public ImplicitFacetsTreeComponent(DetectedFacetManager detectedFacetManager, Collection> detectedFacets, HashMap, List> files) { - myDetectedFacetManager = detectedFacetManager; - - Map facetTypeNodes = new HashMap(); - - Collection> sortedFacets = new LinkedHashSet>(); - for (FacetInfo2 facet : detectedFacets) { - addUnderlying(facet, sortedFacets); - } - - Map, DetectedFacetsTree.FacetNode> facetNodes = new HashMap, DetectedFacetsTree.FacetNode>(); - for (FacetInfo2 facetInfo : sortedFacets) { - FacetType facetType = getRootFacetType(facetInfo); - DetectedFacetsTree.FacetTypeNode facetTypeNode = facetTypeNodes.get(facetType); - if (facetTypeNode == null) { - facetTypeNode = new DetectedFacetsTree.FacetTypeNode(facetType); - facetTypeNodes.put(facetType, facetTypeNode); - } - - Module module = facetInfo.getModule(); - ModuleNodeImpl moduleNode = findOrCreateModuleNode(facetTypeNode, module); - - DetectedFacetsTree.FacetNode parentNode = null; - FacetInfo2 underlyingFacet = facetInfo.getUnderlyingFacetInfo(); - if (underlyingFacet != null) { - parentNode = facetNodes.get(underlyingFacet); - } - - VirtualFile projectRoot = facetInfo.getModule().getProject().getBaseDir(); - DetectedFacetsTree.FacetNode facetNode; - if (facetInfo instanceof DetectedFacetInfo) { - facetNode = new FacetNodeImpl((DetectedFacetInfo)facetInfo, projectRoot, parentNode, files.get(facetInfo)); - } - else { - facetNode = new RealFacetNode((FacetInfoBackedByFacet)facetInfo, projectRoot, parentNode); - } - facetNodes.put(facetInfo, facetNode); - if (parentNode == null) { - moduleNode.addRootFacet(facetNode); - } - } - - myFacetTypeNodes = facetTypeNodes.values(); - myTree = new DetectedFacetsTree(myFacetTypeNodes); - } - - public void createFacets() { - for (DetectedFacetsTree.FacetTypeNode facetTypeNode : myFacetTypeNodes) { - for (DetectedFacetsTree.ModuleNode moduleNode : facetTypeNode.getModuleNodes()) { - boolean accept = facetTypeNode.isChecked() && moduleNode.isChecked(); - processFacetNodes(moduleNode.getRootFacets(), accept, null); - } - } - } - - private void processFacetNodes(final List facetNodes, final boolean accept, final Facet underlyingFacet) { - for (DetectedFacetsTree.FacetNode facetNode : facetNodes) { - Facet facet = null; - if (facetNode instanceof FacetNodeImpl) { - DetectedFacetInfo detectedFacetInfo = ((FacetNodeImpl)facetNode).getDetectedFacetInfo(); - if (accept && facetNode.isChecked()) { - facet = myDetectedFacetManager.createFacet(detectedFacetInfo, underlyingFacet); - } - else { - myDetectedFacetManager.disableDetectionInFile(detectedFacetInfo); - } - } - else { - facet = ((RealFacetNode)facetNode).myFacetInfo.getFacet(); - } - processFacetNodes(facetNode.getChildren(), accept && facetNode.isChecked(), facet); - } - } - - private static void addUnderlying(final FacetInfo2 facet, final Collection> sortedFacets) { - FacetInfo2 underlying = facet.getUnderlyingFacetInfo(); - if (underlying != null && !sortedFacets.contains(underlying)) { - addUnderlying(underlying, sortedFacets); - } - sortedFacets.add(facet); - } - - private static ModuleNodeImpl findOrCreateModuleNode(final DetectedFacetsTree.FacetTypeNode facetTypeNode, final Module module) { - for (DetectedFacetsTree.ModuleNode node : facetTypeNode.getModuleNodes()) { - ModuleNodeImpl moduleNode = (ModuleNodeImpl)node; - if (moduleNode.myModule.equals(module)) { - return moduleNode; - } - } - ModuleNodeImpl moduleNode = new ModuleNodeImpl(module); - facetTypeNode.addModuleNode(moduleNode); - return moduleNode; - } - - private static FacetType getRootFacetType(final FacetInfo2 detectedFacet) { - FacetInfo2 facet = detectedFacet; - FacetInfo2 underlyingFacet; - while ((underlyingFacet = facet.getUnderlyingFacetInfo()) != null) { - facet = underlyingFacet; - } - return facet.getFacetType(); - } - - public DetectedFacetsTree getTree() { - return myTree; - } - - private static class FacetNodeImpl extends DetectedFacetsTree.FacetNode { - private final DetectedFacetInfo myDetectedFacetInfo; - - private FacetNodeImpl(@NotNull DetectedFacetInfo detectedFacet, VirtualFile projectRoot, @Nullable final DetectedFacetsTree.FacetNode parent, - final @NotNull List files) { - super(detectedFacet, detectedFacet.getFacetType(), projectRoot, VfsUtil.toVirtualFileArray(files), parent); - myDetectedFacetInfo = detectedFacet; - } - - public DetectedFacetInfo getDetectedFacetInfo() { - return myDetectedFacetInfo; - } - - public String getName() { - return myDetectedFacetInfo.getFacetName(); - } - } - - private static class RealFacetNode extends DetectedFacetsTree.FacetNode { - private final FacetInfoBackedByFacet myFacetInfo; - - private RealFacetNode(final FacetInfoBackedByFacet facetInfo, final VirtualFile projectRoot, @Nullable final DetectedFacetsTree.FacetNode parent) { - super(facetInfo, facetInfo.getFacetType(), projectRoot, VirtualFile.EMPTY_ARRAY, parent); - myFacetInfo = facetInfo; - } - - public String getDescription() { - return ""; - } - - public String getName() { - return myFacetInfo.getFacetName(); - } - } - - private static class ModuleNodeImpl extends DetectedFacetsTree.ModuleNode { - private final Module myModule; - - private ModuleNodeImpl(final Module module) { - super(module); - myModule = module; - } - - public String getModuleName() { - return myModule.getName(); - } - - public String getModuleDescription() { - return ""; - } - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/DetectedFacetInfo.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/DetectedFacetInfo.java deleted file mode 100644 index f3d8cc998697..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/DetectedFacetInfo.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting.model; - -/** - * @author nik - */ -public interface DetectedFacetInfo extends FacetInfo2 { - - int getId(); - - String getDetectorId(); -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/DetectedFacetInfoImpl.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/DetectedFacetInfoImpl.java deleted file mode 100644 index b0e825265f38..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/DetectedFacetInfoImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting.model; - -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * @author nik - */ -public class DetectedFacetInfoImpl implements DetectedFacetInfo { - private final String myFacetName; - private final FacetConfiguration myConfiguration; - private final FacetType myFacetType; - private final FacetInfo2 myUnderlyingFacetInfo; - private final M myModule; - private final Collection myUrls; - private final int myId; - private final String myDetectorId; - - public DetectedFacetInfoImpl(final @NotNull String facetName, final @NotNull FacetConfiguration configuration, final @NotNull FacetType facetType, - final @NotNull M module, - final @Nullable FacetInfo2 underlyingFacetInfo, - final String url, - final int id, - final String detectorId) { - myFacetName = facetName; - myConfiguration = configuration; - myFacetType = facetType; - myModule = module; - myUnderlyingFacetInfo = underlyingFacetInfo; - myId = id; - myDetectorId = detectorId; - myUrls = new ArrayList(); - myUrls.add(url); - } - - @NotNull - public String getFacetName() { - return myFacetName; - } - - @NotNull - public FacetConfiguration getConfiguration() { - return myConfiguration; - } - - @NotNull - public FacetType getFacetType() { - return myFacetType; - } - - public FacetInfo2 getUnderlyingFacetInfo() { - return myUnderlyingFacetInfo; - } - - @NotNull - public M getModule() { - return myModule; - } - - public int getId() { - return myId; - } - - public String getDetectorId() { - return myDetectorId; - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfo2.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfo2.java deleted file mode 100644 index 7b1cc8a19938..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfo2.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting.model; - -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author nik - */ -public interface FacetInfo2 { - - @NotNull - String getFacetName(); - - @NotNull - FacetConfiguration getConfiguration(); - - @NotNull - FacetType getFacetType(); - - @Nullable - FacetInfo2 getUnderlyingFacetInfo(); - - @NotNull - M getModule(); -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfoBackedByFacet.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfoBackedByFacet.java deleted file mode 100644 index cfdf9333e6bf..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfoBackedByFacet.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting.model; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.openapi.module.Module; -import org.jetbrains.annotations.NotNull; - -/** - * @author nik - */ -public class FacetInfoBackedByFacet implements FacetInfo2 { - private final Facet myFacet; - private final ProjectFacetInfoSet myProjectFacetSet; - - FacetInfoBackedByFacet(@NotNull Facet facet, final ProjectFacetInfoSet projectFacetSet) { - myFacet = facet; - myProjectFacetSet = projectFacetSet; - } - - @NotNull - public String getFacetName() { - return myFacet.getName(); - } - - @NotNull - public FacetConfiguration getConfiguration() { - return myFacet.getConfiguration(); - } - - @NotNull - public FacetType getFacetType() { - return myFacet.getType(); - } - - public FacetInfo2 getUnderlyingFacetInfo() { - Facet underlying = myFacet.getUnderlyingFacet(); - return underlying != null ? myProjectFacetSet.getOrCreateInfo(underlying) : null; - } - - @NotNull - public Module getModule() { - return myFacet.getModule(); - } - - public Facet getFacet() { - return myFacet; - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfoSet.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfoSet.java deleted file mode 100644 index 41f443e02c1f..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/FacetInfoSet.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting.model; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.facet.FacetTypeId; -import com.intellij.openapi.util.MultiValuesMap; -import com.intellij.util.containers.FactoryMap; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -/** - * @author nik - */ -public class FacetInfoSet { - private final Map> myFacetInfos = new HashMap>(); - private final Map>> myInfosByType = new FactoryMap>>() { - protected MultiValuesMap> create(final FacetTypeId key) { - return new MultiValuesMap>(); - } - }; - private final Map> myDetectedById = new HashMap>(); - - public void addFacetInfo(@NotNull FacetInfo2 facetInfo) { - myFacetInfos.put(facetInfo.getConfiguration(), facetInfo); - myInfosByType.get(facetInfo.getFacetType().getId()).put(facetInfo.getModule(), facetInfo); - if (facetInfo instanceof DetectedFacetInfo) { - DetectedFacetInfo detected = (DetectedFacetInfo)facetInfo; - myDetectedById.put(detected.getId(), detected); - } - } - - public void removeFacetInfo(@NotNull FacetInfo2 facetInfo) { - myFacetInfos.remove(facetInfo.getConfiguration()); - myInfosByType.get(facetInfo.getFacetType().getId()).remove(facetInfo.getModule(), facetInfo); - if (facetInfo instanceof DetectedFacetInfo) { - final DetectedFacetInfo detected = (DetectedFacetInfo)facetInfo; - myDetectedById.remove(detected.getId()); - } - } - - public void removeDetectedFacets(final FacetTypeId type, final M module) { - Collection> facets = myInfosByType.get(type).get(module); - if (facets != null) { - List> infos = new ArrayList>(facets); - for (FacetInfo2 info : infos) { - if (info instanceof DetectedFacetInfo) { - removeFacetInfo(info); - } - } - } - } - - public void removeDetectedFacets(FacetTypeId type) { - List> infos = new ArrayList>(myInfosByType.get(type).values()); - for (FacetInfo2 info : infos) { - if (info instanceof DetectedFacetInfo) { - removeFacetInfo(info); - } - } - } - - @Nullable - public FacetInfo2 findFacet(final @NotNull FacetTypeId typeId, @NotNull M module, final @NotNull String name) { - Collection> detectedFacets = myInfosByType.get(typeId).get(module); - if (detectedFacets != null) { - for (FacetInfo2 detected : detectedFacets) { - if (detected.getFacetName().equals(name)) { - return detected; - } - } - } - return null; - } - - public > Map> getConfigurations(final FacetTypeId typeId, final M module) { - //todo[nik] cache? - Map> configurations = new LinkedHashMap>(); - Collection> detectedFacets = myInfosByType.get(typeId).get(module); - if (detectedFacets != null) { - for (FacetInfo2 detected : detectedFacets) { - if (detected instanceof FacetInfoBackedByFacet) { - //noinspection unchecked - configurations.put((C)detected.getConfiguration(), detected); - } - } - for (FacetInfo2 detected : detectedFacets) { - if (!(detected instanceof FacetInfoBackedByFacet)) { - //noinspection unchecked - configurations.put((C)detected.getConfiguration(), detected); - } - } - } - return configurations; - } - - public String generateName(final M module, final FacetType facetType) { - String baseName = facetType.getDefaultFacetName(); - int i = 2; - String name = baseName; - while (findFacet(facetType.getId(), module, name) != null) { - name = baseName + i; - i++; - } - return name; - } - - @Nullable - public FacetInfo2 findById(int id) { - return myDetectedById.get(id); - } - - public void removeDetectedFacetWithSubFacets(final Integer id) { - FacetInfo2 detected = myDetectedById.get(id); - if (detected != null) { - Set> set = collectSubFacets(detected); - for (FacetInfo2 info : set) { - removeFacetInfo(info); - } - } - } - - public void removeDetectedFacets(@NotNull M module) { - List typeIds = new ArrayList(myInfosByType.keySet()); - for (FacetTypeId typeId : typeIds) { - removeDetectedFacets(typeId, module); - } - } - - private Set> collectSubFacets(final FacetInfo2 facetInfo) { - final Set> set = new HashSet>(); - set.add(facetInfo); - boolean setChanged = true; - while (setChanged) { - setChanged = false; - for (FacetInfo2 info : myFacetInfos.values()) { - FacetInfo2 underlying = info.getUnderlyingFacetInfo(); - if (underlying != null && set.contains(underlying) && !set.contains(info)) { - set.add(info); - setChanged = true; - } - } - } - return set; - } - - public Collection> getAllDetectedFacets() { - return Collections.unmodifiableCollection(myDetectedById.values()); - } - -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/ProjectFacetInfoSet.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/ProjectFacetInfoSet.java deleted file mode 100644 index 7eb00cf0b267..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/model/ProjectFacetInfoSet.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.autodetecting.model; - -import com.intellij.facet.*; -import com.intellij.facet.impl.FacetUtil; -import com.intellij.facet.pointers.FacetPointersManager; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.JDOMUtil; -import com.intellij.openapi.util.WriteExternalException; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.EventDispatcher; -import com.intellij.util.SystemProperties; -import com.intellij.util.xmlb.XmlSerializer; -import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; -import com.intellij.util.xmlb.annotations.AbstractCollection; -import com.intellij.util.xmlb.annotations.Attribute; -import com.intellij.util.xmlb.annotations.Tag; -import org.jdom.Document; -import org.jdom.Element; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.IOException; -import java.util.*; - -/** - * @author nik - */ -public class ProjectFacetInfoSet extends FacetInfoSet { - private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.autodetecting.model.ProjectFacetInfoSet"); - private final Map myFacetInfos = new HashMap(); - private final EventDispatcher myDispatcher = EventDispatcher.create(DetectedFacetListener.class); - private int myNextId; - private final Project myProject; - - public ProjectFacetInfoSet(Project project, Disposable parentDisposable) { - myProject = project; - ProjectWideFacetListenersRegistry.getInstance(project).registerListener(new MyProjectWideFacetAdapter(), parentDisposable); - } - - public FacetInfoBackedByFacet getOrCreateInfo(@NotNull Facet facet) { - FacetInfoBackedByFacet info = myFacetInfos.get(facet); - if (info == null) { - info = new FacetInfoBackedByFacet(facet, this); - myFacetInfos.put(facet, info); - } - return info; - } - - public void addFacetInfo(@NotNull final FacetInfo2 facetInfo) { - super.addFacetInfo(facetInfo); - if (facetInfo instanceof DetectedFacetInfo) { - myDispatcher.getMulticaster().facetDetected((DetectedFacetInfo)facetInfo); - } - } - - public void removeFacetInfo(@NotNull final FacetInfo2 facetInfo) { - super.removeFacetInfo(facetInfo); - if (facetInfo instanceof DetectedFacetInfo) { - myDispatcher.getMulticaster().facetRemoved((DetectedFacetInfo)facetInfo); - } - } - - public void loadDetectedFacets(@NotNull File file) { - if (!file.exists()) return; - - FacetTypeRegistry facetTypeRegistry = FacetTypeRegistry.getInstance(); - ModuleManager moduleManager = ModuleManager.getInstance(myProject); - - Document document; - try { - document = JDOMUtil.loadDocument(file); - } - catch (Exception e) { - LOG.info(e); - return; - } - - DetectedFacetsBean detectedFacetsBean = XmlSerializer.deserialize(document, DetectedFacetsBean.class); - if (detectedFacetsBean == null) return; - - for (DetectedFacetBean facetBean : detectedFacetsBean.myFacets) { - FacetType type = facetTypeRegistry.findFacetType(facetBean.myTypeId); - if (type == null) { - LOG.info("facet type '" + facetBean.myTypeId + " not found"); - continue; - } - Module module = moduleManager.findModuleByName(facetBean.myModuleName); - if (module == null) { - LOG.info("module '" + facetBean.myModuleName + "' not found"); - continue; - } - - FacetInfo2 underlyingFacet = null; - String underlyingId = facetBean.myUnderlyingId; - if (underlyingId != null) { - if (underlyingId.startsWith("/")) { - underlyingFacet = findById(Integer.parseInt(underlyingId.substring(1))); - } - else { - Facet facet = FacetPointersManager.getInstance(myProject).create(underlyingId).getFacet(); - underlyingFacet = facet != null ? getOrCreateInfo(facet) : null; - } - } - FacetConfiguration configuration = type.createDefaultConfiguration(); - try { - FacetUtil.loadFacetConfiguration(configuration, facetBean.myConfiguration); - } - catch (InvalidDataException e) { - LOG.info(e); - continue; - } - - int id = facetBean.myId; - myNextId = Math.max(myNextId, id + 1); - addFacetInfo(new DetectedFacetInfoImpl(facetBean.myFacetName, configuration, type, module, underlyingFacet, null, id, - facetBean.myDetectorId)); - } - } - - public void saveDetectedFacets(File file) { - DetectedFacetsBean facetsBean = new DetectedFacetsBean(); - Collection> facets = getAllDetectedFacets(); - Set> added = new HashSet>(); - for (DetectedFacetInfo facet : facets) { - addFacetBean(facet, facetsBean, added); - } - - Element element = XmlSerializer.serialize(facetsBean, new SkipDefaultValuesSerializationFilters()); - try { - FileUtil.delete(file); - FileUtil.createParentDirs(file); - JDOMUtil.writeDocument(new Document(element), file, SystemProperties.getLineSeparator()); - } - catch (IOException e) { - LOG.info(e); - } - } - - private static boolean addFacetBean(final DetectedFacetInfo facet, final DetectedFacetsBean facetsBean, - final Set> added) { - if (!added.add(facet)) { - return true; - } - - FacetInfo2 underlyingInfo = facet.getUnderlyingFacetInfo(); - if (underlyingInfo instanceof DetectedFacetInfo && !addFacetBean((DetectedFacetInfo)underlyingInfo, facetsBean, added)) { - return false; - } - - try { - final Element configuration = FacetUtil.saveFacetConfiguration(facet.getConfiguration()); - final String underlyingId; - if (underlyingInfo instanceof FacetInfoBackedByFacet) { - underlyingId = FacetPointersManager.constructId(((FacetInfoBackedByFacet)underlyingInfo).getFacet()); - } - else { - underlyingId = underlyingInfo != null ? "/" + ((DetectedFacetInfo)underlyingInfo).getId() : null; - } - DetectedFacetBean facetBean = new DetectedFacetBean(facet.getId(), facet.getFacetName(), facet.getModule().getName(), configuration, - facet.getFacetType().getStringId(), underlyingId, facet.getDetectorId()); - facetsBean.myFacets.add(facetBean); - return true; - } - catch (WriteExternalException e) { - LOG.info(e); - return false; - } - } - - public void addListener(@NotNull DetectedFacetListener listener) { - myDispatcher.addListener(listener); - } - - public > DetectedFacetInfo createInfo(final Module module, - final String url, final FacetInfo2 underlyingFacet, - final C detectedConfiguration, - final String name, - final FacetType facetType, - final String detectorId) { - return new DetectedFacetInfoImpl(name, detectedConfiguration, facetType, module, underlyingFacet, url, - generateId(), detectorId); - } - - private int generateId() { - return myNextId++; - } - - private class MyProjectWideFacetAdapter extends ProjectWideFacetAdapter { - public void facetAdded(final Facet facet) { - addFacetInfo(getOrCreateInfo(facet)); - } - - public void facetRemoved(final Facet facet) { - FacetInfoBackedByFacet detected = myFacetInfos.remove(facet); - if (detected != null) { - removeFacetInfo(detected); - } - } - } - - public static interface DetectedFacetListener extends EventListener { - void facetDetected(final DetectedFacetInfo info); - void facetRemoved(DetectedFacetInfo info); - } - - - public static class DetectedFacetsBean { - @Tag("facets") - @AbstractCollection(surroundWithTag = false) - public List myFacets = new ArrayList(); - } - - @Tag("facet") - public static class DetectedFacetBean { - @Attribute("type") - public String myTypeId; - - @Attribute("facet-name") - public String myFacetName; - - @Attribute("id") - public int myId; - - @Tag("configuration") - public Element myConfiguration; - - @Attribute("underlying-id") - public String myUnderlyingId; - - @Attribute("module-name") - public String myModuleName; - - @Attribute("detector-id") - public String myDetectorId; - - public DetectedFacetBean() { - } - - public DetectedFacetBean(final int id, final String facetName, final String moduleName, final Element configuration, - final String typeId, final String underlyingId, String detectorId) { - myId = id; - myFacetName = facetName; - myConfiguration = configuration; - myTypeId = typeId; - myModuleName = moduleName; - myUnderlyingId = underlyingId; - myDetectorId = detectorId; - } - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/FacetDetectionProcessor.java b/java/idea-ui/src/com/intellij/facet/impl/ui/FacetDetectionProcessor.java deleted file mode 100644 index 7aa4ee7efa86..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/FacetDetectionProcessor.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.facet.impl.ui; - -import com.intellij.facet.*; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.facet.impl.autodetecting.FacetDetectorForWizardRegistry; -import com.intellij.facet.impl.autodetecting.FacetDetectorRegistryEx; -import com.intellij.facet.impl.autodetecting.OldFileContentPattern; -import com.intellij.ide.caches.FileContent; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.openapi.module.ModuleType; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.util.MultiValuesMap; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.util.*; - -/** - * @author nik - */ -public class FacetDetectionProcessor { - private static final Logger LOG = Logger.getInstance("#com.intellij.facet.impl.ui.FacetDetectionProcessor"); - private final Map myDetectedFacets = new LinkedHashMap(); - private final Map> myDetectedConfigurations = new HashMap>(); - private final ProgressIndicator myProgressIndicator; - private final FileTypeManager myFileTypeManager; - private final List> myDetectors = new ArrayList>(); - - public FacetDetectionProcessor(final ProgressIndicator progressIndicator, final ModuleType moduleType) { - myProgressIndicator = progressIndicator; - myFileTypeManager = FileTypeManager.getInstance(); - FacetType[] types = FacetTypeRegistry.getInstance().getFacetTypes(); - for (FacetType type : types) { - if (type.isSuitableModuleType(moduleType)) { - registerDetectors(type); - myDetectedConfigurations.put(type.getId(), new ArrayList()); - } - } - } - - private void registerDetectors(final FacetType type) { - type.registerDetectors(new FacetDetectorRegistryEx(new MyFacetDetectorRegistry(type), null)); - } - - public void process(final File root) { - final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root); - if (virtualFile == null) return; - - for (int i = 0; i < myDetectors.size(); i++) { - MultiValuesMap map = myDetectors.get(i); - if (i > 0) { - List toRemove = new ArrayList(); - for (MyFacetDetectorWrapper detector : map.values()) { - FacetTypeId typeId = detector.getFacetType().getUnderlyingFacetType(); - LOG.assertTrue(typeId != null); - List list = myDetectedConfigurations.get(typeId); - if (list == null || list.isEmpty()) { - toRemove.add(detector); - } - } - - for (MyFacetDetectorWrapper detectorWrapper : toRemove) { - map.remove(detectorWrapper.getFileType(), detectorWrapper); - } - } - - if (map.isEmpty()) break; - process(virtualFile, map); - } - } - - private void process(final VirtualFile file, MultiValuesMap detectorsMap) { - if (myProgressIndicator.isCanceled()) return; - - if (file.isDirectory()) { - file.getChildren();//initialize myChildren field to ensure that refresh will be really performed - file.refresh(false, false); - VirtualFile[] children = file.getChildren(); - for (VirtualFile child : children) { - process(child, detectorsMap); - } - return; - } - - myProgressIndicator.setText2(file.getPresentableUrl()); - FileType fileType = myFileTypeManager.getFileTypeByFile(file); - Collection detectors = detectorsMap.get(fileType); - if (detectors == null) return; - - final FileContent content = new FileContent(file); - for (MyFacetDetectorWrapper detector : detectors) { - detector.detectFacet(content); - } - } - - public List getDetectedFacetsInfos() { - return new ArrayList(myDetectedFacets.values()); - } - - public List getDetectedFacets() { - List list = new ArrayList(); - for (DetectedInWizardFacetInfo info : myDetectedFacets.values()) { - list.add(info.getFacetInfo()); - } - return list; - } - - private class MyFacetDetectorWrapper { - private final FacetType myFacetType; - private final FileType myFileType; - private final OldFileContentPattern myFileContentPattern; - private final FacetDetector myDetector; - private final UnderlyingFacetSelector myUnderlyingFacetSelector; - - public MyFacetDetectorWrapper(final FacetType facetType, final FileType fileType, final OldFileContentPattern fileContentFilter, final FacetDetector detector, - final UnderlyingFacetSelector underlyingFacetSelector) { - myUnderlyingFacetSelector = underlyingFacetSelector; - myFacetType = facetType; - myFileType = fileType; - myFileContentPattern = fileContentFilter; - myDetector = detector; - } - - public FileType getFileType() { - return myFileType; - } - - public FacetType getFacetType() { - return myFacetType; - } - - public void detectFacet(final FileContent fileContent) { - if (!myFileContentPattern.accepts(fileContent)) return; - final VirtualFile file = fileContent.getVirtualFile(); - - FacetInfo underlyingFacet = null; - if (myUnderlyingFacetSelector != null) { - List list = (List)myDetectedConfigurations.get(myFacetType.getUnderlyingFacetType()); - U underlying = myUnderlyingFacetSelector.selectUnderlyingFacet(file, list); - if (underlying == null) { - return; - } - underlyingFacet = myDetectedFacets.get(underlying).getFacetInfo(); - } - - List configurations = (List)myDetectedConfigurations.get(myFacetType.getId()); - C newConfiguration = myDetector.detectFacet(file, configurations); - if (newConfiguration == null || configurations.contains(newConfiguration)) { - return; - } - - FacetInfo facetInfo = new FacetInfo(myFacetType, generateFacetName(), newConfiguration, underlyingFacet); - configurations.add(newConfiguration); - myDetectedFacets.put(newConfiguration, new DetectedInWizardFacetInfo(facetInfo, file, myDetector)); - } - - private String generateFacetName() { - String baseName = myFacetType.getDefaultFacetName(); - - String name = baseName; - int i = 2; - while (isUsed(name)) { - name = baseName + i; - i++; - } - - return name; - } - - private boolean isUsed(final String name) { - List configurations = myDetectedConfigurations.get(myFacetType.getId()); - if (configurations != null) { - for (FacetConfiguration configuration : configurations) { - if (name.equals(myDetectedFacets.get(configuration).getFacetInfo().getName())) { - return true; - } - } - } - return false; - } - - } - - private class MyFacetDetectorRegistry implements FacetDetectorForWizardRegistry { - private final FacetType myFacetType; - private final int myLevel; - - public MyFacetDetectorRegistry(final FacetType facetType) { - myFacetType = facetType; - int level = 0; - FacetTypeId typeId = facetType.getUnderlyingFacetType(); - Set parentTypes = new HashSet(); - parentTypes.add(facetType.getId()); - while (typeId != null) { - level++; - FacetType underlying = FacetTypeRegistry.getInstance().findFacetType(typeId); - LOG.assertTrue(underlying != null, "Cannot find underlying facet type by id: " + typeId + " (for facet " + facetType.getId() + ")"); - typeId = underlying.getUnderlyingFacetType(); - if (!parentTypes.add(typeId)) { - LOG.error("Circular dependency between facets: " + parentTypes); - break; - } - } - myLevel=level; - } - - public void register(final FileType fileType, @NotNull final OldFileContentPattern fileContentPattern, final FacetDetector facetDetector, - final UnderlyingFacetSelector underlyingFacetSelector) { - if (myFacetType.getUnderlyingFacetType() != null) { - LOG.assertTrue(underlyingFacetSelector != null, "UnderlyingFacetSelector must be specified for " + myFacetType.getPresentableName() + " detector"); - } - else { - LOG.assertTrue(underlyingFacetSelector == null, "UnderlyingFacetSelector must not be specified for " + myFacetType.getPresentableName() + " detector"); - } - MyFacetDetectorWrapper detector = new MyFacetDetectorWrapper(myFacetType, fileType, fileContentPattern, - facetDetector, underlyingFacetSelector); - getDetectorsMap().put(fileType, detector); - } - - private MultiValuesMap getDetectorsMap() { - while (myLevel >= myDetectors.size()) { - myDetectors.add(new MultiValuesMap()); - } - return myDetectors.get(myLevel); - } - } - - //todo[nik] use DetectedFacetInfo instead - public static class DetectedInWizardFacetInfo { - private final FacetInfo myFacetInfo; - private final VirtualFile myFile; - private final FacetDetector myFacetDetector; - - public DetectedInWizardFacetInfo(final FacetInfo facetInfo, final VirtualFile file, final FacetDetector facetDetector) { - myFacetInfo = facetInfo; - myFile = file; - myFacetDetector = facetDetector; - } - - public FacetInfo getFacetInfo() { - return myFacetInfo; - } - - public VirtualFile getFile() { - return myFile; - } - - public FacetDetector getFacetDetector() { - return myFacetDetector; - } - } -} diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.form b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.form deleted file mode 100644 index 11c7faac4eb0..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.form +++ /dev/null @@ -1,174 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java deleted file mode 100644 index 8a1380aff2fd..000000000000 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.facet.impl.ui.facetType; - -import com.intellij.facet.FacetType; -import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionByTypeElement; -import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionInModuleElement; -import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager; -import com.intellij.facet.impl.autodetecting.FacetAutodetectingManagerImpl; -import com.intellij.openapi.actionSystem.CommonShortcuts; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog; -import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.ui.ColoredListCellRenderer; -import com.intellij.ui.ListUtil; -import com.intellij.ui.SimpleTextAttributes; -import com.intellij.util.PlatformIcons; -import com.intellij.util.containers.BidirectionalMap; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.TestOnly; - -import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.util.*; - -/** - * @author nik - */ -public class FacetAutodetectionConfigurable implements Configurable { - private final Project myProject; - private final StructureConfigurableContext myContext; - private final FacetType myFacetType; - private JPanel myMainPanel; - private JCheckBox myEnableAutoDetectionCheckBox; - private JList myModulesList; - private JButton myAddModuleButton; - private JButton myRemoveModuleButton; - private JList myFilesList; - private JButton myRemoveFileButton; - private JPanel mySettingsPanel; - private JPanel mySkipFilesListPanel; - private final DefaultListModel myModulesListModel; - private final DefaultListModel myFilesListModel; - private final BidirectionalMap myFile2Module = new BidirectionalMap(); - private final Set myRemovedModules = new HashSet(); - private final Set myAddedModules = new HashSet(); - private final Set myRemovedFiles = new HashSet(); - private boolean myAutodetectionWasEnabled; - - public FacetAutodetectionConfigurable(@NotNull Project project, final StructureConfigurableContext context, final @NotNull FacetType facetType) { - myProject = project; - myContext = context; - myFacetType = facetType; - - myModulesList.setCellRenderer(new ModulesListCellRenderer()); - myModulesListModel = new DefaultListModel(); - myModulesList.setModel(myModulesListModel); - - myFilesList.setCellRenderer(new FilesListCellRenderer()); - myFilesListModel = new DefaultListModel(); - myFilesList.setModel(myFilesListModel); - - myAddModuleButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - String description = ProjectBundle.message("choose.description.facet.auto.detection.will.be.disabled.in.the.selected.modules", - myFacetType.getPresentableName()); - String title = ProjectBundle.message("choose.modules.dialog.title"); - ChooseModulesDialog dialog = new ChooseModulesDialog(myProject, getEnabledModules(), title, description); - dialog.show(); - List chosenElements = dialog.getChosenElements(); - if (dialog.isOK() && !chosenElements.isEmpty()) { - for (Module module : chosenElements) { - String moduleName = module.getName(); - myModulesListModel.addElement(moduleName); - if (!myRemovedModules.remove(moduleName)) { - myAddedModules.add(moduleName); - } - } - updateButtons(); - myModulesList.repaint(); - } - } - }); - UIUtil.addKeyboardShortcut(myModulesList, myAddModuleButton, CommonShortcuts.getInsertKeystroke()); - - myRemoveModuleButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - //noinspection unchecked - List removed = ListUtil.removeSelectedItems(myModulesList); - for (String moduleName : removed) { - if (!myAddedModules.remove(moduleName)) { - myRemovedModules.add(moduleName); - } - } - updateButtons(); - } - }); - KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); - UIUtil.addKeyboardShortcut(myModulesList, myRemoveModuleButton, delete); - - myRemoveFileButton.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - //noinspection unchecked - List removed = ListUtil.removeSelectedItems(myFilesList); - myRemovedFiles.addAll(removed); - updateButtons(); - } - }); - UIUtil.addKeyboardShortcut(myFilesList, myRemoveFileButton, delete); - - myEnableAutoDetectionCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - updateButtons(); - } - }); - - ListSelectionListener selectionListener = new ListSelectionListener() { - public void valueChanged(final ListSelectionEvent e) { - updateRemoveButtons(); - } - }; - myFilesList.addListSelectionListener(selectionListener); - myModulesList.addListSelectionListener(selectionListener); - } - - private List getEnabledModules() { - List modules = new ArrayList(Arrays.asList(getAllModules())); - Iterator iterator = modules.iterator(); - - Set disabled = getDisabledModules(); - - while (iterator.hasNext()) { - Module module = iterator.next(); - if (disabled.contains(module.getName())) { - iterator.remove(); - } - } - return modules; - } - - protected Module[] getAllModules() { - return myContext.getModules(); - } - - private Set getDisabledModules() { - Set disabled = new LinkedHashSet(); - for (int i = 0; i < myModulesListModel.getSize(); i++) { - disabled.add((String)myModulesListModel.getElementAt(i)); - } - return disabled; - } - - public String getDisplayName() { - return ProjectBundle.message("auto.detection.configurable.display.name"); - } - - public Icon getIcon() { - return null; - } - - public String getHelpTopic() { - return "reference.settingsdialog.project.structure.facet"; - } - - public JComponent createComponent() { - return myMainPanel; - } - - public boolean isModified() { - return myAutodetectionWasEnabled != myEnableAutoDetectionCheckBox.isSelected() - || !myRemovedFiles.isEmpty() || !myAddedModules.isEmpty() || !myRemovedModules.isEmpty(); - } - - public void apply() throws ConfigurationException { - DisabledAutodetectionByTypeElement state = getAutodetectingManager().getDisabledAutodetectionState(myFacetType); - DisabledAutodetectionByTypeElement newState = modifyState(state); - getAutodetectingManager().setDisabledAutodetectionState(myFacetType, newState); - } - - @Nullable - private DisabledAutodetectionByTypeElement modifyState(final DisabledAutodetectionByTypeElement state) { - if (!myEnableAutoDetectionCheckBox.isSelected()) { - return new DisabledAutodetectionByTypeElement(myFacetType.getStringId()); - } - - if (state == null) { - if (myAddedModules.isEmpty()) { - return null; - } - DisabledAutodetectionByTypeElement newState = new DisabledAutodetectionByTypeElement(myFacetType.getStringId()); - for (String moduleName : myAddedModules) { - newState.getModuleElements().add(new DisabledAutodetectionInModuleElement(moduleName)); - } - return newState; - } - - DisabledAutodetectionByTypeElement newState = copyState(state); - boolean someModuleRemoved = false; - for (String url : myRemovedFiles) { - String moduleName = myFile2Module.get(url); - DisabledAutodetectionInModuleElement element = newState.findElement(moduleName); - if (element != null) { - boolean removed = element.getFiles().remove(url) | element.getDirectories().remove(url); - if (removed && element.isDisableInWholeModule()) { - newState.removeDisabled(moduleName); - someModuleRemoved = true; - } - } - } - for (String moduleName : myAddedModules) { - newState.getModuleElements().add(new DisabledAutodetectionInModuleElement(moduleName)); - } - for (String moduleName : myRemovedModules) { - someModuleRemoved |= newState.findElement(moduleName) != null; - newState.removeDisabled(moduleName); - } - if ((someModuleRemoved || !myAutodetectionWasEnabled) && newState.getModuleElements().isEmpty()) { - return null; - } - return newState; - } - - private DisabledAutodetectionByTypeElement copyState(final DisabledAutodetectionByTypeElement state) { - DisabledAutodetectionByTypeElement newState = new DisabledAutodetectionByTypeElement(myFacetType.getStringId()); - for (DisabledAutodetectionInModuleElement moduleElement : state.getModuleElements()) { - DisabledAutodetectionInModuleElement newModuleElement = new DisabledAutodetectionInModuleElement(moduleElement.getModuleName()); - newModuleElement.getFiles().addAll(moduleElement.getFiles()); - newModuleElement.getDirectories().addAll(moduleElement.getDirectories()); - newState.getModuleElements().add(newModuleElement); - } - return newState; - } - - public void reset() { - DisabledAutodetectionByTypeElement autodetectionInfo = getAutodetectingManager().getDisabledAutodetectionState(myFacetType); - myModulesListModel.removeAllElements(); - myFilesListModel.removeAllElements(); - myFile2Module.clear(); - myRemovedModules.clear(); - myAddedModules.clear(); - myRemovedFiles.clear(); - - myEnableAutoDetectionCheckBox.setSelected(true); - if (autodetectionInfo != null) { - List moduleElements = autodetectionInfo.getModuleElements(); - if (moduleElements.isEmpty()) { - myEnableAutoDetectionCheckBox.setSelected(false); - } - else { - List modules = new ArrayList(); - List urls = new ArrayList(); - - for (DisabledAutodetectionInModuleElement moduleElement : moduleElements) { - String moduleName = moduleElement.getModuleName(); - if (moduleElement.isDisableInWholeModule()) { - modules.add(moduleName); - } - else { - for (String url : moduleElement.getFiles()) { - myFile2Module.put(url, moduleName); - urls.add(url); - } - for (String url : moduleElement.getDirectories()) { - myFile2Module.put(url, moduleName); - urls.add(url); - } - } - } - - Collections.sort(urls); - Collections.sort(modules); - for (String url : urls) { - myFilesListModel.addElement(url); - } - for (String moduleName : modules) { - myModulesListModel.addElement(moduleName); - } - } - } - myAutodetectionWasEnabled = myEnableAutoDetectionCheckBox.isSelected(); - mySkipFilesListPanel.setVisible(!myFilesListModel.isEmpty()); - updateButtons(); - } - - @TestOnly - public Set getRemovedModules() { - return myRemovedModules; - } - - @TestOnly - public Set getAddedModules() { - return myAddedModules; - } - - @TestOnly - public Set getRemovedFiles() { - return myRemovedFiles; - } - - @TestOnly - public JCheckBox getEnableAutoDetectionCheckBox() { - return myEnableAutoDetectionCheckBox; - } - - private void updateButtons() { - if (!myEnableAutoDetectionCheckBox.isSelected()) { - UIUtil.setEnabled(mySettingsPanel, false, true); - return; - } - - UIUtil.setEnabled(mySettingsPanel, true, true); - myAddModuleButton.setEnabled(!getEnabledModules().isEmpty()); - updateRemoveButtons(); - } - - private void updateRemoveButtons() { - myRemoveModuleButton.setEnabled(myEnableAutoDetectionCheckBox.isSelected() && myModulesList.getSelectedIndices().length > 0); - myRemoveFileButton.setEnabled(myEnableAutoDetectionCheckBox.isSelected() && myFilesList.getSelectedIndices().length > 0); - } - - - private FacetAutodetectingManagerImpl getAutodetectingManager() { - return (FacetAutodetectingManagerImpl)FacetAutodetectingManager.getInstance(myProject); - } - - public void disposeUIResources() { - } - - private static class FilesListCellRenderer extends ColoredListCellRenderer { - protected void customizeCellRenderer(final JList list, - final Object value, - final int index, - final boolean selected, - final boolean hasFocus) { - String url = (String)value; - String path = VfsUtil.urlToPath(url); - VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); - if (file != null) { - append(path, SimpleTextAttributes.REGULAR_ATTRIBUTES); - setIcon(file.isDirectory() ? PlatformIcons.FOLDER_ICON : file.getIcon()); - } - else { - append(path, SimpleTextAttributes.ERROR_ATTRIBUTES); - setIcon(null); - } - } - } - - private class ModulesListCellRenderer extends ColoredListCellRenderer { - protected void customizeCellRenderer(final JList list, - final Object value, - final int index, - final boolean selected, - final boolean hasFocus) { - String moduleName = (String)value; - Module module = myContext.myModulesConfigurator.getModule(moduleName); - if (module != null) { - append(moduleName, SimpleTextAttributes.REGULAR_ATTRIBUTES); - setIcon(module.getModuleType().getNodeIcon(false)); - } - else { - append(moduleName, SimpleTextAttributes.ERROR_ATTRIBUTES); - setIcon(null); - } - } - } -} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java index 3b44253e3729..d4036fdd8845 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java @@ -19,8 +19,6 @@ import com.intellij.facet.Facet; import com.intellij.facet.FacetManager; import com.intellij.facet.FacetType; import com.intellij.facet.FacetTypeRegistry; -import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager; -import com.intellij.facet.impl.autodetecting.FacetAutodetectingManagerImpl; import com.intellij.facet.impl.invalid.InvalidFacetManager; import com.intellij.facet.impl.invalid.InvalidFacetType; import com.intellij.facet.impl.ui.facetType.FacetTypeEditor; @@ -150,9 +148,6 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable { for (FacetTypeEditor editor : myFacetTypeEditors.values()) { editor.apply(); } - if (!myProject.isDefault()) { - ((FacetAutodetectingManagerImpl)FacetAutodetectingManager.getInstance(myProject)).redetectFacets(); - } } public boolean isModified() { diff --git a/platform/platform-resources-en/src/messages/ProjectBundle.properties b/platform/platform-resources-en/src/messages/ProjectBundle.properties index e947f0e4256b..112f4e015156 100644 --- a/platform/platform-resources-en/src/messages/ProjectBundle.properties +++ b/platform/platform-resources-en/src/messages/ProjectBundle.properties @@ -46,32 +46,13 @@ project.import.jbuilder.home=JBuilder &Home: project.import.jbuilder.home.title=Set JBuilder Home Location project.import.jbuilder.home.prompt=Choose directory with JBuilder installation -progress.text.loading.facet.detection.indices=Loading facet detection indices... -progress.text.detecting.facets=Detecting facets... - framework.detected.info.text={0} {1, choice, 1#framework is|2#frameworks are} detected in the project Configure -facet.autodetected.info.text= \ - {1}
\ - Create {0} Facet
\ - Don''t detect {0} Facets in module\ -
-facet.autodetected.popup.default.text={0}
\ - from module {1} appears to be a {2} Facet descriptor -notification.name.0.facets.detected={0} facets detected -notification.name.0.facet.detected={0} facet detected -facet.autodetection.several.facets.detected.text={0} facets detected. More... - progress.text.searching.frameworks=Searching for frameworks. Please wait. message.text.stop.searching.for.frameworks={0} is currently searching for frameworks. Would you like to stop the search? label.text.the.following.frameworks.are.detected=Several frameworks are detected in the project. Please review the following items and exclude mistakenly detected. label.text.no.frameworks.detected=No frameworks detected. -dialog.title.facets.detected=New Facets Detected -label.text.the.following.facets.are.detected.on.the.fly=Several facets are detected in the project. Please review the following facets and exclude mistakenly detected. -detected.facet.type.node={0} Facets -button.text.accept.detected.facets=&Accept -button.text.postpone.detected.facets=&Postpone sdk.java.name=JSDK sdk.java.unknown.name=Unknown sdk.java.corrupt.error=Probably SDK installed in ''{0}'' is corrupt @@ -374,36 +355,11 @@ project.roots.external.annotations.description=Manage external annotations attac add.external.annotations.path.title=Add path to external annotations add.external.annotations.path.description=Select path in which external annotations for module sources is located -node.text.packaging.included.from.0=from {0} -node.text.packaging.compile.output=(compile output) -node.text.packed.0.compile.output=(''{0}'' compile output) -node.text.library.of.module=(library from ''{0}'' module) -button.text.packaging.tree.add=Add... -button.text.packaging.tree.edit=Edit... -message.text.packaging.selected.item.belongs.to.0.do.you.want.to.exlude.1.from.2=Selected item belongs to {0}.\nDo you want to exlude {1} from {2}? -message.text.packaging.do.you.want.to.exlude.0.from.1=Do you want to exlude {0} from {1}? -message.text.individial.files.cannot.be.removed.from.packaging.do.you.want.to.remove.the.whole.libraries=An individial files cannot be removed from packaging. \nDo you want to remove the whole {0} {1, choice, 1#library|2#libraries}? -dialog.title.packaging.remove.included=Remove -action.name.packaging.add.library=Add Library... dialog.title.packaging.choose.library=Choose Library -action.name.packaging.add.module=Add Module... dialog.title.packaging.choose.module=Choose Module -dialog.title.packaging.edit.properties=Edit Properties -label.text.packaging.method=&Packaging method: -label.text.output.relative.path=&Output relative path: -checkbox.text.show.content.of.included.facets=Show content of &included facets -checkbox.text.show.library.files=Show &library files -text.module.link.description.0.module=''{0}'' module -element.description.0.items={0} items project.facets.display.name=Facets facet.type.banner.text=''{0}'' Facets -auto.detection.configurable.display.name=Auto-detection -choose.description.facet.auto.detection.will.be.disabled.in.the.selected.modules={0} facet auto-detection will be disabled in the selected modules -checkbox.text.enable.auto.detection=&Enable auto-detection -label.text.autodetection.skip.modules=Skip modules -label.text.autodetection.skip.files=Skip files -button.text.autodetection.remove.file=Rem&ove facet.defaults.display.name=Defaults multiple.facets.banner.0.1.facets={0} {1} facets tab.name.all.facets=All Facets diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index 9232d2649d42..38d166ac198c 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -17,10 +17,6 @@ - - com.intellij.facet.impl.autodetecting.FacetAutodetectingManager - com.intellij.facet.impl.autodetecting.FacetAutodetectingManagerImpl - com.intellij.framework.detection.impl.FrameworkDetectionManager