diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index e2364c04bab4..4eb3dfa3f5ac 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -208,6 +208,8 @@ public class IncProjectBuilder { private void runBuild(CompileContext context) throws ProjectBuildException { context.setDone(0.0f); + LOG.info("Building project '" + context.getProject().getProjectName() + "'; isRebuild:" +context.isProjectRebuild() + "; isMake:" + context.isMake()); + if (context.isProjectRebuild()) { cleanOutputRoots(context); } diff --git a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java index f7dbe66bc798..9f306aab8caa 100644 --- a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java +++ b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java @@ -1445,7 +1445,7 @@ public class Mappings { if ((field.access & Opcodes.ACC_PRIVATE) == 0 && (field.access & mask) == mask) { if ((d.base() & Difference.ACCESS) > 0 || ((d.base() & Difference.VALUE) > 0 && d.hadValue())) { - debug("Inline field changed it's access or value => a switch to non-incremental mode requested"); + debug("Inline field changed its access or value => a switch to non-incremental mode requested"); if (!incrementalDecision(it.name, field, affectedFiles, filter)) { debug("End of Differentiate, returning false"); return false; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateGroup.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateGroup.java index 51faa4ab489b..e86ac895ea47 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateGroup.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateGroup.java @@ -17,12 +17,22 @@ package com.intellij.codeInsight.template.impl; import com.intellij.openapi.options.CompoundScheme; +import org.jetbrains.annotations.Nullable; public class TemplateGroup extends CompoundScheme { + private final String myReplace; public TemplateGroup(final String name) { - super(name); + this(name, null); } + public TemplateGroup(String name, @Nullable String replace) { + super(name); + myReplace = replace; + } + + public String getReplace() { + return myReplace; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java index 41c49b33a83e..a3f82a0e2f0c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java @@ -487,7 +487,14 @@ public class TemplateSettings implements PersistentStateComponent, Expo String templateName = getDefaultTemplateName(defTemplate); InputStream inputStream = DecodeDefaultsUtil.getDefaultsInputStream(provider, defTemplate); if (inputStream != null) { - readDefTemplateFile(inputStream, templateName, provider.getClass().getClassLoader(), registerTemplate); + TemplateGroup group = + readTemplateFile(JDOMUtil.loadDocument(inputStream), templateName, true, registerTemplate, provider.getClass().getClassLoader()); + if (group != null && group.getReplace() != null) { + Collection templates = myTemplates.get(group.getReplace()); + for (TemplateImpl template : templates) { + removeTemplate(template); + } + } } } @@ -495,10 +502,6 @@ public class TemplateSettings implements PersistentStateComponent, Expo return defTemplate.substring(defTemplate.lastIndexOf("/") + 1); } - private void readDefTemplateFile(InputStream inputStream, String defGroupName, ClassLoader classLoader, boolean registerTemplate) throws JDOMException, InvalidDataException, IOException { - readTemplateFile(JDOMUtil.loadDocument(inputStream), defGroupName, true, registerTemplate, classLoader); - } - @Nullable private TemplateGroup readTemplateFile(Document document, @NonNls String defGroupName, boolean isDefault, boolean registerTemplate, ClassLoader classLoader) throws InvalidDataException { if (document == null) { @@ -512,7 +515,7 @@ public class TemplateSettings implements PersistentStateComponent, Expo String groupName = root.getAttributeValue(GROUP); if (groupName == null || groupName.length() == 0) groupName = defGroupName; - TemplateGroup result = new TemplateGroup(groupName); + TemplateGroup result = new TemplateGroup(groupName, root.getAttributeValue("REPLACE")); Map created = new LinkedHashMap(); diff --git a/platform/lang-impl/src/com/intellij/facet/impl/ProjectWideFacetListenersRegistryImpl.java b/platform/lang-impl/src/com/intellij/facet/impl/ProjectWideFacetListenersRegistryImpl.java index 42be07c3b319..daa6e8f3a7f7 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/ProjectWideFacetListenersRegistryImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/ProjectWideFacetListenersRegistryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -176,7 +176,10 @@ public class ProjectWideFacetListenersRegistryImpl extends ProjectWideFacetListe } public void unregisterListener(@NotNull FacetTypeId typeId, @NotNull ProjectWideFacetListener listener) { - myDispatchers.get(typeId).removeListener(listener); + final EventDispatcher dispatcher = myDispatchers.get(typeId); + if (dispatcher != null) { + dispatcher.removeListener(listener); + } } public void registerListener(@NotNull final FacetTypeId typeId, @NotNull final ProjectWideFacetListener listener, diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index c7b2b88a308c..6f8f8bf192fb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -195,26 +195,32 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { private static final boolean IS_UNDER_TEAMCITY = System.getProperty("bootstrap.testcases") != null; - private static final boolean SHOULD_PERFORM_ACCESS_CHECK = System.getenv("NO_FS_ROOTS_ACCESS_CHECK") == null; - private static final boolean IS_UNIT_TESTS = ApplicationManager.getApplication().isUnitTestMode(); - - - private static final Collection additionalRoots = new THashSet(); + private static final Collection ourAdditionalRoots = new THashSet(); @TestOnly - public static void allowToAccess(@NotNull String root) { - additionalRoots.add(FileUtil.toSystemIndependentName(root)); + public static void allowRootAccess(@NotNull String... roots) { + for (String root : roots) { + ourAdditionalRoots.add(FileUtil.toSystemIndependentName(root)); + } + } + + @TestOnly + public static void disallowRootAccess(@NotNull String... roots) { + for (String root : roots) { + ourAdditionalRoots.remove(FileUtil.toSystemIndependentName(root)); + } } @TestOnly private static void assertAccessInTests(VirtualFileSystemEntry child) { - if (IS_UNIT_TESTS && - IS_UNDER_TEAMCITY && - ApplicationManager.getApplication() instanceof ApplicationImpl && - ((ApplicationImpl)ApplicationManager.getApplication()).isComponentsCreated() && - SHOULD_PERFORM_ACCESS_CHECK) { + final Application application = ApplicationManager.getApplication(); + if (IS_UNDER_TEAMCITY && + SHOULD_PERFORM_ACCESS_CHECK && + application.isUnitTestMode() && + application instanceof ApplicationImpl && + ((ApplicationImpl)application).isComponentsCreated()) { NewVirtualFileSystem fileSystem = child.getFileSystem(); if (fileSystem != LocalFileSystem.getInstance() && fileSystem != JarFileSystem.getInstance()) { return; @@ -256,25 +262,25 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { @Nullable private static Set allowedRoots() { if (insideGettingRoots) return null; + Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length == 0) return null; + final Set allowed = new THashSet(); - String homePath = PathManager.getHomePath(); - allowed.add(FileUtil.toSystemIndependentName(homePath)); + allowed.add(FileUtil.toSystemIndependentName(PathManager.getHomePath())); + try { URL outUrl = Application.class.getResource("/"); String output = new File(outUrl.toURI()).getParentFile().getParentFile().getPath(); allowed.add(FileUtil.toSystemIndependentName(output)); } catch (URISyntaxException ignored) { } - String javaHome = SystemProperties.getJavaHome(); - allowed.add(FileUtil.toSystemIndependentName(javaHome)); - String tempDirectorySpecific = new File(FileUtil.getTempDirectory()).getParent(); - allowed.add(FileUtil.toSystemIndependentName(tempDirectorySpecific)); - String tempDirectory = System.getProperty("java.io.tmpdir"); - allowed.add(FileUtil.toSystemIndependentName(tempDirectory)); - String userHome = SystemProperties.getUserHome(); - allowed.add(FileUtil.toSystemIndependentName(userHome)); + + allowed.add(FileUtil.toSystemIndependentName(SystemProperties.getJavaHome())); + allowed.add(FileUtil.toSystemIndependentName(new File(FileUtil.getTempDirectory()).getParent())); + allowed.add(FileUtil.toSystemIndependentName(System.getProperty("java.io.tmpdir"))); + allowed.add(FileUtil.toSystemIndependentName(SystemProperties.getUserHome())); + for (Project project : openProjects) { if (!project.isInitialized()) { return null; // all is allowed @@ -290,12 +296,8 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { allowed.add(FileUtil.toSystemIndependentName(location)); } - //for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) { - // allowed.add(FileUtil.toSystemIndependentName(sdk.getHomePath())); - //} - for (String root : additionalRoots) { - allowed.add(root); - } + allowed.addAll(ourAdditionalRoots); + return allowed; } @@ -303,20 +305,19 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { private static VirtualFile[] getAllRoots(Project project) { insideGettingRoots = true; - Set roots = new THashSet(); + final Set roots = new THashSet(); + final Module[] modules = ModuleManager.getInstance(project).getModules(); for (Module module : modules) { final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries(); for (OrderEntry entry : orderEntries) { - VirtualFile[] files = entry.getFiles(OrderRootType.CLASSES); - ContainerUtil.addAll(roots, files); - files = entry.getFiles(OrderRootType.SOURCES); - ContainerUtil.addAll(roots, files); - files = entry.getFiles(OrderRootType.CLASSES_AND_OUTPUT); - ContainerUtil.addAll(roots, files); + ContainerUtil.addAll(roots, entry.getFiles(OrderRootType.CLASSES)); + ContainerUtil.addAll(roots, entry.getFiles(OrderRootType.SOURCES)); + ContainerUtil.addAll(roots, entry.getFiles(OrderRootType.CLASSES_AND_OUTPUT)); } } + insideGettingRoots = false; return VfsUtil.toVirtualFileArray(roots); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java index 074522040598..23d615fd2871 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java @@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent; import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent; import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; +import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl; import com.intellij.testFramework.PlatformLangTestCase; import com.intellij.util.Function; import com.intellij.util.TimeoutUtil; @@ -334,32 +335,40 @@ public class FileWatcherTest extends PlatformLangTestCase { final int rv = new GeneralCommandLine("subst", subst + ":", targetDir.getAbsolutePath()).createProcess().waitFor(); assertEquals(0, rv); - final File substDir = new File((subst + ":\\").toUpperCase(Locale.US), subDir.getName()); - final File substFile = new File(substDir, file.getName()); - refresh(targetDir); - refresh(substDir); + final String substRoot = (subst + ":\\").toUpperCase(Locale.US); + VirtualDirectoryImpl.allowRootAccess(substRoot); - final LocalFileSystem.WatchRequest request = watch(substDir); try { - FileUtil.writeToFile(file, "new content"); - assertEvent(VFileContentChangeEvent.class, substFile.getAbsolutePath()); + final File substDir = new File(substRoot, subDir.getName()); + final File substFile = new File(substDir, file.getName()); + refresh(targetDir); + refresh(substDir); - final LocalFileSystem.WatchRequest request2 = watch(targetDir); + final LocalFileSystem.WatchRequest request = watch(substDir); try { - FileUtil.delete(file); - assertEvent(VFileDeleteEvent.class, file.getAbsolutePath(), substFile.getAbsolutePath()); + FileUtil.writeToFile(file, "new content"); + assertEvent(VFileContentChangeEvent.class, substFile.getAbsolutePath()); + + final LocalFileSystem.WatchRequest request2 = watch(targetDir); + try { + FileUtil.delete(file); + assertEvent(VFileDeleteEvent.class, file.getAbsolutePath(), substFile.getAbsolutePath()); + } + finally { + unwatch(request2); + } + + FileUtil.writeToFile(file, "re-creation"); + assertEvent(VFileCreateEvent.class, substFile.getAbsolutePath()); } finally { - unwatch(request2); + myFileSystem.removeWatchedRoot(request); } - - FileUtil.writeToFile(file, "re-creation"); - assertEvent(VFileCreateEvent.class, substFile.getAbsolutePath()); } finally { - myFileSystem.removeWatchedRoot(request); - new GeneralCommandLine("subst", subst + ":", "/d").createProcess().waitFor(); + VirtualDirectoryImpl.disallowRootAccess(substRoot); FileUtil.delete(targetDir); + new GeneralCommandLine("subst", subst + ":", "/d").createProcess().waitFor(); } } diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index 8fa2af3f11e6..e100b4112753 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -20,7 +20,10 @@ import com.intellij.Patches; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.util.*; +import com.intellij.util.ArrayUtil; +import com.intellij.util.ObjectUtils; +import com.intellij.util.Processor; +import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Stack; import com.intellij.util.io.URLUtil; @@ -679,11 +682,19 @@ public class FileUtil extends FileUtilRt { return next1 == '/' || next1 == File.separatorChar; } - public static boolean pathsEqual(@NotNull String path1, @NotNull String path2) { + public static boolean filesEqual(@Nullable File file1, @Nullable File file2) { + // on MacOS java.io.File.equals() is incorrectly case-sensitive + return pathsEqual(file1 == null ? null : file1.getPath(), file2 == null ? null : file2.getPath(), true); + } + + public static boolean pathsEqual(@Nullable String path1, @Nullable String path2) { return pathsEqual(path1, path2, false); } - public static boolean pathsEqual(@NotNull String path1, @NotNull String path2, boolean convertSeparators) { + public static boolean pathsEqual(@Nullable String path1, @Nullable String path2, boolean convertSeparators) { + if (path1 == path2) return true; + if (path1 == null || path2 == null) return false; + if (convertSeparators) { path1 = toSystemIndependentName(path1); path2 = toSystemIndependentName(path2); @@ -691,12 +702,13 @@ public class FileUtil extends FileUtilRt { return SystemInfo.isFileSystemCaseSensitive ? path1.equals(path2) : path1.equalsIgnoreCase(path2); } - public static int comparePaths(@NotNull String path1, @NotNull String path2) { - return SystemInfo.isFileSystemCaseSensitive ? path1.compareTo(path2) : path1.compareToIgnoreCase(path2); + public static int comparePaths(@Nullable String path1, @Nullable String path2) { + return StringUtil.compare(path1, path2, !SystemInfo.isFileSystemCaseSensitive); } - public static int pathHashCode(@NotNull String path) { - return SystemInfo.isFileSystemCaseSensitive ? path.hashCode() : path.toLowerCase().hashCode(); + public static int pathHashCode(@Nullable String path) { + if (path == null) return 0; + return SystemInfo.isFileSystemCaseSensitive ? path.hashCode() : StringUtil.toLowerCase(path).hashCode(); } @NotNull diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 80cdd2788289..5129886f6768 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -222,8 +222,8 @@ public class StringUtil extends StringUtilRt { return html.replaceAll("<(.|\n)*?>", ""); } - @Nullable public static String toLowerCase(@Nullable final String str) { + //noinspection ConstantConditions return str == null ? null : str.toLowerCase(); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java index fc837c44f1fc..5466b73ee0fc 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java @@ -28,6 +28,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; +import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiErrorElement; import com.intellij.psi.XmlElementFactory; import com.intellij.psi.XmlRecursiveElementVisitor; @@ -168,6 +169,10 @@ public class ModelParser extends XmlRecursiveElementVisitor { } }); + XmlFile xmlFile = container.getRoot().getClientProperty(XML_FILE_KEY); + PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(xmlFile.getProject()); + psiDocumentManager.commitDocument(psiDocumentManager.getDocument(xmlFile)); + PropertyParser propertyParser = container.getRoot().getClientProperty(PropertyParser.KEY); propertyParser.load(movedComponent); }