diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpSyntaxHighlighterFactory.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpSyntaxHighlighterFactory.java index 5c48f05dff63..9850a68376d4 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpSyntaxHighlighterFactory.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpSyntaxHighlighterFactory.java @@ -15,6 +15,7 @@ */ package org.intellij.lang.regexp; +import com.intellij.lang.Language; import com.intellij.lang.LanguageParserDefinitions; import com.intellij.lang.ParserDefinition; import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory; @@ -25,9 +26,14 @@ public class RegExpSyntaxHighlighterFactory extends SingleLazyInstanceSyntaxHigh private final ParserDefinition myParserDefinition; public RegExpSyntaxHighlighterFactory() { - myParserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(RegExpLanguage.INSTANCE); + this(RegExpLanguage.INSTANCE); } + protected RegExpSyntaxHighlighterFactory(@NotNull Language language) { + myParserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language); + } + + @NotNull protected SyntaxHighlighter createHighlighter() { return new RegExpHighlighter(null, myParserDefinition); diff --git a/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java b/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java index aa038f4bca01..5402d7ee78d2 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/_RegExLexer.java @@ -1,13 +1,14 @@ -/* The following code was generated by JFlex 1.4.3 on 21.06.11 21:06 */ +/* The following code was generated by JFlex 1.4.3 on 10/1/12 11:19 AM */ /* It's an automatically generated code. Do not modify it. */ package org.intellij.lang.regexp; import com.intellij.lexer.FlexLexer; -import com.intellij.psi.tree.IElementType; -import java.util.LinkedList; -import java.util.EnumSet; import com.intellij.psi.StringEscapesTokenTypes; +import com.intellij.psi.tree.IElementType; + +import java.util.EnumSet; +import java.util.LinkedList; // IDEADEV-11055 @SuppressWarnings({ "ALL", "SameParameterValue", "WeakerAccess", "SameReturnValue", "RedundantThrows", "UnusedDeclaration", "UnusedDeclaration" }) @@ -15,8 +16,8 @@ import com.intellij.psi.StringEscapesTokenTypes; /** * This class is a scanner generated by * JFlex 1.4.3 - * on 21.06.11 21:06 from the specification file - * C:/IDEA/tools/lexer/../../community/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex + * on 10/1/12 11:19 AM from the specification file + * C:/work/IDEA/tools/lexer/../../community/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex */ class _RegExLexer implements FlexLexer { /** initial size of the lookahead buffer */ @@ -680,106 +681,6 @@ class _RegExLexer implements FlexLexer { { return RegExpTT.STAR; } case 81: break; - case 58: - { yybegin(PY_COND_REF); return RegExpTT.PYTHON_COND_REF; - } - case 82: break; - case 48: - { return RegExpTT.CHAR_CLASS; - } - case 83: break; - case 35: - { handleOptions(); return RegExpTT.OPTIONS_OFF; - } - case 84: break; - case 54: - { yypopstate(); return RegExpTT.QUOTE_END; - } - case 85: break; - case 34: - { yybegin(YYINITIAL); return RegExpTT.GROUP_END; - } - case 86: break; - case 5: - { return RegExpTT.GROUP_BEGIN; - } - case 87: break; - case 36: - { yybegin(YYINITIAL); return RegExpTT.COLON; - } - case 88: break; - case 6: - { return RegExpTT.GROUP_END; - } - case 89: break; - case 25: - { assert false : yytext(); - } - case 90: break; - case 18: - { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.CHARACTER; - } - case 91: break; - case 45: - { return commentMode ? RegExpTT.CHARACTER : RegExpTT.REDUNDANT_ESCAPE; - } - case 92: break; - case 23: - { return RegExpTT.NAME; - } - case 93: break; - case 72: - { if (allowOctalNoLeadingZero) return RegExpTT.OCT_CHAR; - return yystate() != CLASS2 ? RegExpTT.BACKREF : RegExpTT.ESC_CHARACTER; - } - case 94: break; - case 29: - { yypopstate(); return RegExpTT.CLASS_END; - } - case 95: break; - case 33: - { yybegin(YYINITIAL); return RegExpTT.BAD_CHARACTER; - } - case 96: break; - case 51: - { yypushstate(QUOTED); return RegExpTT.QUOTE_BEGIN; - } - case 97: break; - case 21: - { return RegExpTT.NUMBER; - } - case 98: break; - case 4: - { return RegExpTT.DOT; - } - case 99: break; - case 70: - { return RegExpTT.NEG_LOOKBEHIND; - } - case 100: break; - case 40: - // lookahead expression with fixed base length - zzMarkedPos = zzStartRead + 1; - { yypushstate(CLASS1); - return RegExpTT.CLASS_BEGIN; - } - case 101: break; - case 61: - { return RegExpTT.NEG_LOOKAHEAD; - } - case 102: break; - case 10: - { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.CTRL_CHARACTER; - } - case 103: break; - case 59: - { return RegExpTT.NON_CAPT_GROUP; - } - case 104: break; - case 63: - { yybegin(QUOTED_NAMED_GROUP); return RegExpTT.RUBY_QUOTED_NAMED_GROUP; - } - case 105: break; case 28: { if (allowNestedCharacterClasses) { yypushstate(CLASS2); @@ -787,6 +688,105 @@ class _RegExLexer implements FlexLexer { } return RegExpTT.CHARACTER; } + case 82: break; + case 58: + { yybegin(PY_COND_REF); return RegExpTT.PYTHON_COND_REF; + } + case 83: break; + case 48: + { return RegExpTT.CHAR_CLASS; + } + case 84: break; + case 35: + { handleOptions(); return RegExpTT.OPTIONS_OFF; + } + case 85: break; + case 40: + // lookahead expression with fixed base length + zzMarkedPos = zzStartRead + 1; + { yypushstate(CLASS1); + return RegExpTT.CLASS_BEGIN; + } + case 86: break; + case 54: + { yypopstate(); return RegExpTT.QUOTE_END; + } + case 87: break; + case 34: + { yybegin(YYINITIAL); return RegExpTT.GROUP_END; + } + case 88: break; + case 5: + { return RegExpTT.GROUP_BEGIN; + } + case 89: break; + case 36: + { yybegin(YYINITIAL); return RegExpTT.COLON; + } + case 90: break; + case 6: + { return RegExpTT.GROUP_END; + } + case 91: break; + case 25: + { assert false : yytext(); + } + case 92: break; + case 18: + { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.CHARACTER; + } + case 93: break; + case 45: + { return commentMode ? RegExpTT.CHARACTER : RegExpTT.REDUNDANT_ESCAPE; + } + case 94: break; + case 23: + { return RegExpTT.NAME; + } + case 95: break; + case 29: + { yypopstate(); return RegExpTT.CLASS_END; + } + case 96: break; + case 33: + { yybegin(YYINITIAL); return RegExpTT.BAD_CHARACTER; + } + case 97: break; + case 51: + { yypushstate(QUOTED); return RegExpTT.QUOTE_BEGIN; + } + case 98: break; + case 21: + { return RegExpTT.NUMBER; + } + case 99: break; + case 4: + { return RegExpTT.DOT; + } + case 100: break; + case 70: + { return RegExpTT.NEG_LOOKBEHIND; + } + case 101: break; + case 43: + { return (allowOctalNoLeadingZero ? RegExpTT.OCT_CHAR : RegExpTT.BAD_OCT_VALUE); + } + case 102: break; + case 61: + { return RegExpTT.NEG_LOOKAHEAD; + } + case 103: break; + case 10: + { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.CTRL_CHARACTER; + } + case 104: break; + case 59: + { return RegExpTT.NON_CAPT_GROUP; + } + case 105: break; + case 63: + { yybegin(QUOTED_NAMED_GROUP); return RegExpTT.RUBY_QUOTED_NAMED_GROUP; + } case 106: break; case 19: { if (commentMode) { yypushstate(COMMENT); return RegExpTT.COMMENT; } else return RegExpTT.CHARACTER; @@ -796,75 +796,51 @@ class _RegExLexer implements FlexLexer { { yypushstate(PROP); return RegExpTT.PROPERTY; } case 108: break; - case 8: - { yypushstate(CLASS2); - return RegExpTT.CLASS_BEGIN; - } - case 109: break; case 69: { return RegExpTT.POS_LOOKBEHIND; } - case 110: break; + case 109: break; case 42: { return yystate() != CLASS2 ? RegExpTT.BACKREF : RegExpTT.ESC_CHARACTER; } - case 111: break; + case 110: break; case 71: { return RegExpTT.HEX_CHAR; } - case 112: break; + case 111: break; case 1: { handleOptions(); return RegExpTT.OPTIONS_ON; } - case 113: break; + case 112: break; case 57: { return allowNestedCharacterClasses ? RegExpTT.ANDAND : RegExpTT.CHARACTER; } - case 114: break; + case 113: break; case 2: { yypopstate(); return RegExpTT.COMMENT; } - case 115: break; + case 114: break; case 17: { return RegExpTT.MINUS; } - case 116: break; + case 115: break; case 46: { return RegExpTT.ESC_CTRL_CHARACTER; } - case 117: break; + case 116: break; case 32: { yypopstate(); yypushstate(EMBRACED); return RegExpTT.LBRACE; } + case 117: break; + case 56: + { if (!allowNestedCharacterClasses) return RegExpTT.CHARACTER; + return RegExpTT.REDUNDANT_ESCAPE; + } case 118: break; case 13: { return RegExpTT.QUEST; } case 119: break; - case 15: - { return RegExpTT.PLUS; - } - case 120: break; - case 65: - { return RegExpTT.OCT_CHAR; - } - case 121: break; - case 38: - { yybegin(YYINITIAL); return RegExpTT.QUOTE; - } - case 122: break; - case 64: - // lookahead expression with fixed base length - zzMarkedPos = zzStartRead + 1; - { if (!allowNestedCharacterClasses) { - yypushstate(CLASS1PY); - } - else { - yypushstate(CLASS2); - } - return RegExpTT.CLASS_BEGIN; - } - case 123: break; case 20: { if (allowDanglingMetacharacters) { yypopstate(); yypushback(1); @@ -872,6 +848,23 @@ class _RegExLexer implements FlexLexer { return RegExpTT.BAD_CHARACTER; } } + case 120: break; + case 15: + { return RegExpTT.PLUS; + } + case 121: break; + case 65: + { return RegExpTT.OCT_CHAR; + } + case 122: break; + case 72: + { if (allowOctalNoLeadingZero) return RegExpTT.OCT_CHAR; + return yystate() != CLASS2 ? RegExpTT.BACKREF : RegExpTT.ESC_CHARACTER; + } + case 123: break; + case 38: + { yybegin(YYINITIAL); return RegExpTT.QUOTE; + } case 124: break; case 31: { yypopstate(); yypushback(1); @@ -881,6 +874,87 @@ class _RegExLexer implements FlexLexer { { yybegin(CLASS1); return RegExpTT.CARET; } case 126: break; + case 37: + { yybegin(YYINITIAL); return RegExpTT.GT; + } + case 127: break; + case 67: + { yybegin(PY_NAMED_GROUP_REF); return RegExpTT.PYTHON_NAMED_GROUP_REF; + } + case 128: break; + case 16: + { return RegExpTT.UNION; + } + case 129: break; + case 3: + { return RegExpTT.CHARACTER; + } + case 130: break; + case 62: + { yybegin(NAMED_GROUP); return RegExpTT.RUBY_NAMED_GROUP; + } + case 131: break; + case 39: + { yybegin(OPTIONS); return RegExpTT.SET_OPTIONS; + } + case 132: break; + case 26: + { yybegin(CLASS2); return RegExpTT.CHARACTER; + } + case 133: break; + case 66: + { if (xmlSchemaMode) { yypushback(1); return RegExpTT.CHAR_CLASS; } else return RegExpTT.CTRL; + } + case 134: break; + case 30: + { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.ESC_CHARACTER; + } + case 135: break; + case 12: + { return RegExpTT.DOLLAR; + } + case 136: break; + case 49: + { if (xmlSchemaMode) return RegExpTT.CHAR_CLASS; else return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; + } + case 137: break; + case 41: + { return RegExpTT.REDUNDANT_ESCAPE; + } + case 138: break; + case 47: + { return yystate() != CLASS2 ? RegExpTT.BOUNDARY : RegExpTT.ESC_CHARACTER; + } + case 139: break; + case 8: + { yypushstate(CLASS2); + return RegExpTT.CLASS_BEGIN; + } + case 140: break; + case 22: + { yypopstate(); return RegExpTT.RBRACE; + } + case 141: break; + case 53: + { return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; + } + case 142: break; + case 52: + { return RegExpTT.BAD_HEX_VALUE; + } + case 143: break; + case 9: + { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; + } + case 144: break; + case 11: + { return RegExpTT.CARET; + } + case 145: break; + case 44: + { return RegExpTT.ESC_CHARACTER; + } + case 146: break; case 55: // lookahead expression with fixed base length zzMarkedPos = zzStartRead + 1; @@ -890,90 +964,17 @@ class _RegExLexer implements FlexLexer { } return RegExpTT.CHARACTER; } - case 127: break; - case 56: - { if (!allowNestedCharacterClasses) return RegExpTT.CHARACTER; - return RegExpTT.REDUNDANT_ESCAPE; - } - case 128: break; - case 37: - { yybegin(YYINITIAL); return RegExpTT.GT; - } - case 129: break; - case 67: - { yybegin(PY_NAMED_GROUP_REF); return RegExpTT.PYTHON_NAMED_GROUP_REF; - } - case 130: break; - case 16: - { return RegExpTT.UNION; - } - case 131: break; - case 3: - { return RegExpTT.CHARACTER; - } - case 132: break; - case 62: - { yybegin(NAMED_GROUP); return RegExpTT.RUBY_NAMED_GROUP; - } - case 133: break; - case 39: - { yybegin(OPTIONS); return RegExpTT.SET_OPTIONS; - } - case 134: break; - case 26: - { yybegin(CLASS2); return RegExpTT.CHARACTER; - } - case 135: break; - case 66: - { if (xmlSchemaMode) { yypushback(1); return RegExpTT.CHAR_CLASS; } else return RegExpTT.CTRL; - } - case 136: break; - case 30: - { return commentMode ? com.intellij.psi.TokenType.WHITE_SPACE : RegExpTT.ESC_CHARACTER; - } - case 137: break; - case 12: - { return RegExpTT.DOLLAR; - } - case 138: break; - case 49: - { if (xmlSchemaMode) return RegExpTT.CHAR_CLASS; else return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; - } - case 139: break; - case 41: - { return RegExpTT.REDUNDANT_ESCAPE; - } - case 140: break; - case 47: - { return yystate() != CLASS2 ? RegExpTT.BOUNDARY : RegExpTT.ESC_CHARACTER; - } - case 141: break; - case 22: - { yypopstate(); return RegExpTT.RBRACE; - } - case 142: break; - case 53: - { return StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN; - } - case 143: break; - case 43: - { return RegExpTT.BAD_OCT_VALUE; - } - case 144: break; - case 52: - { return RegExpTT.BAD_HEX_VALUE; - } - case 145: break; - case 9: - { return StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN; - } - case 146: break; - case 11: - { return RegExpTT.CARET; - } case 147: break; - case 44: - { return RegExpTT.ESC_CHARACTER; + case 64: + // lookahead expression with fixed base length + zzMarkedPos = zzStartRead + 1; + { if (!allowNestedCharacterClasses) { + yypushstate(CLASS1PY); + } + else { + yypushstate(CLASS2); + } + return RegExpTT.CLASS_BEGIN; } case 148: break; default: diff --git a/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex b/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex index 2dc4f76afa46..e3d403c369ce 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex +++ b/RegExpSupport/src/org/intellij/lang/regexp/regexp-lexer.flex @@ -123,7 +123,7 @@ HEX_CHAR=[0-9a-fA-F] /* octal escapes */ {ESCAPE} "0" [0-7]{1,3} { return RegExpTT.OCT_CHAR; } -{ESCAPE} "0" { return RegExpTT.BAD_OCT_VALUE; } +{ESCAPE} "0" { return (allowOctalNoLeadingZero ? RegExpTT.OCT_CHAR : RegExpTT.BAD_OCT_VALUE); } /* single character after "\c" */ {ESCAPE} "c" {ANY} { if (xmlSchemaMode) { yypushback(1); return RegExpTT.CHAR_CLASS; } else return RegExpTT.CTRL; } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java index d25af7a06351..dce9d8485a47 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SelectTemplateStep.java @@ -75,10 +75,12 @@ public class SelectTemplateStep extends ModuleWizardStep { ProjectTemplate template = getSelectedTemplate(); if (template != null) { JComponent settingsPanel = template.getSettingsPanel(); - mySettingsPanel.add(settingsPanel, BorderLayout.NORTH); - mySettingsPanel.repaint(); + if (settingsPanel != null) { + mySettingsPanel.add(settingsPanel, BorderLayout.NORTH); + } } mySettingsPanel.revalidate(); + mySettingsPanel.repaint(); } }); if (myTemplatesList.getModel().getSize() > 0) { diff --git a/java/idea-ui/src/com/intellij/platform/templates/GithubBasedProjectTemplate.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java similarity index 52% rename from java/idea-ui/src/com/intellij/platform/templates/GithubBasedProjectTemplate.java rename to java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java index 03bddf383ada..a32e48962eed 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/GithubBasedProjectTemplate.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedProjectTemplate.java @@ -16,84 +16,83 @@ package com.intellij.platform.templates; import com.intellij.ide.util.newProjectWizard.modes.ImportImlMode; -import com.intellij.ide.util.projectWizard.ExistingModuleLoader; import com.intellij.ide.util.projectWizard.ProjectBuilder; import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.platform.templates.github.AbstractGithubTagDownloadedProjectGenerator; +import com.intellij.platform.ProjectTemplate; +import com.intellij.platform.templates.github.ZipUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.List; +import java.util.zip.ZipInputStream; /** * @author Dmitry Avdeev * Date: 10/1/12 */ -public class GithubBasedProjectTemplate extends AbstractGithubTagDownloadedProjectGenerator { - private String myDisplayName; - private String myGithubUserName; - private String myGithubRepositoryName; - private String myHomepageUrl; - private String myDescription; +public class ArchivedProjectTemplate implements ProjectTemplate { + private final String myDisplayName; + private final String myDescription; + private final String myArchivePath; + private final ClassLoader myResourceLoader; private final WizardContext myContext; - public GithubBasedProjectTemplate(String displayName, - String githubRepositoryName, - String homepageUrl, - String description, - WizardContext context) { + public ArchivedProjectTemplate(String displayName, + String description, + String archivePath, + ClassLoader resourceLoader, + WizardContext context) { + myDisplayName = displayName; - myGithubRepositoryName = githubRepositoryName; - myHomepageUrl = homepageUrl; myDescription = description; + myArchivePath = archivePath; + myResourceLoader = resourceLoader; myContext = context; } - @NotNull @Override - protected String getDisplayName() { + public String getName() { return myDisplayName; } - @Override - protected String getGithubUserName() { - return myGithubUserName; - } - - @NotNull - @Override - protected String getGithubRepositoryName() { - return myGithubRepositoryName; - } - - @Override - public String getHomepageUrl() { - return myHomepageUrl; - } - @Override public String getDescription() { return myDescription; } + @NotNull @Override public ProjectBuilder createModuleBuilder() { - final String path = myContext.getProjectFileDirectory() + "/empty-java.iml"; - final ExistingModuleLoader loader = ImportImlMode.setUpLoader(path); return new ProjectBuilder() { @Nullable @Override public List commit(Project project, ModifiableModuleModel model, ModulesProvider modulesProvider) { - VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(myContext.getProjectFileDirectory()); - doGenerate(project, file, myPeer.getValue().getSettings()); - return loader.commit(project, model, modulesProvider); + InputStream stream = myResourceLoader.getResourceAsStream(myArchivePath); + if (stream == null) { + throw new RuntimeException("Can't open " + myArchivePath); + } + final String path = myContext.getProjectFileDirectory(); + try { + ZipUtil.unzip(null, new File(path), new ZipInputStream(stream)); + } + catch (IOException e) { + throw new RuntimeException(e); + } + return ImportImlMode.setUpLoader(path).commit(project, model, modulesProvider); } }; } + + @Override + public JComponent getSettingsPanel() { + return null; + } } diff --git a/java/idea-ui/src/com/intellij/platform/templates/GithubBasedTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java similarity index 84% rename from java/idea-ui/src/com/intellij/platform/templates/GithubBasedTemplatesFactory.java rename to java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java index 28eeca213814..15233933e3e8 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/GithubBasedTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java @@ -24,13 +24,13 @@ import org.jetbrains.annotations.NotNull; * @author Dmitry Avdeev * Date: 10/1/12 */ -public class GithubBasedTemplatesFactory implements ProjectTemplatesFactory { +public class ArchivedTemplatesFactory implements ProjectTemplatesFactory { @NotNull @Override public ProjectTemplate[] createTemplates(WizardContext context) { return new ProjectTemplate[]{ - new GithubBasedProjectTemplate("Web Application", "JetBrains/idea-templates/web/empty-java", null, null, context) + new ArchivedProjectTemplate("Web Application", null, "foo", ClassLoader.getSystemClassLoader(), context) }; } } diff --git a/java/java-tests/testData/codeInsight/template/AllowTypingRandomExpressionsWithLookupOpen-out.java b/java/java-tests/testData/codeInsight/template/AllowTypingRandomExpressionsWithLookupOpen-out.java new file mode 100644 index 000000000000..a760125d3208 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/AllowTypingRandomExpressionsWithLookupOpen-out.java @@ -0,0 +1,11 @@ +import java.io.File; +import java.lang.Object; +import java.util.Map; + +class Foo { + void foo(Map files, File file, Object filx) { + for (File file1 : file.) { + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/AllowTypingRandomExpressionsWithLookupOpen.java b/java/java-tests/testData/codeInsight/template/AllowTypingRandomExpressionsWithLookupOpen.java new file mode 100644 index 000000000000..25938313726a --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/AllowTypingRandomExpressionsWithLookupOpen.java @@ -0,0 +1,9 @@ +import java.io.File; +import java.lang.Object; +import java.util.Map; + +class Foo { + void foo(Map files, File file, Object filx) { + + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy index fba0aed5b8fe..454df188c95e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy @@ -190,6 +190,14 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { assert !state.finished } + public void testAllowTypingRandomExpressionsWithLookupOpen() { + configure(); + startTemplate("iter", "iterations") + myFixture.type('file.') + checkResult() + assert !state.finished + } + private TemplateState getState() { TemplateManagerImpl.getTemplateState(getEditor()) } diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/BuildRootIndex.java b/jps/jps-builders/src/org/jetbrains/jps/builders/BuildRootIndex.java index eb53d4408c55..ab9f6b390173 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/BuildRootIndex.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/BuildRootIndex.java @@ -2,8 +2,8 @@ package org.jetbrains.jps.builders; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.incremental.CompileContext; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import java.io.File; import java.io.FileFilter; @@ -43,7 +43,7 @@ public interface BuildRootIndex { Collection findAllParentDescriptors(@NotNull File file, @Nullable CompileContext context); @Nullable - RootDescriptor getModuleAndRoot(@Nullable CompileContext context, File file); + JavaSourceRootDescriptor getModuleAndRoot(@Nullable CompileContext context, File file); @NotNull FileFilter getRootFilter(@NotNull BuildRootDescriptor descriptor); diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/impl/BuildRootIndexImpl.java b/jps/jps-builders/src/org/jetbrains/jps/builders/impl/BuildRootIndexImpl.java index a6db7f3e56e0..b907db6ca11e 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/impl/BuildRootIndexImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/impl/BuildRootIndexImpl.java @@ -9,11 +9,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.builders.*; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.incremental.BuilderRegistry; import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.indices.IgnoredFileIndex; import org.jetbrains.jps.indices.ModuleExcludeIndex; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.model.JpsModel; import org.jetbrains.jps.service.JpsServiceManager; @@ -213,7 +213,7 @@ public class BuildRootIndexImpl implements BuildRootIndex { public Collection clearTempRoots(@NotNull CompileContext context) { try { final Map map = ROOT_DESCRIPTOR_MAP.get(context); - return map != null? map.values() : Collections.emptyList(); + return map != null? map.values() : Collections.emptyList(); } finally { TEMP_TARGET_ROOTS_MAP.set(context, null); @@ -223,7 +223,7 @@ public class BuildRootIndexImpl implements BuildRootIndex { @Override @Nullable - public RootDescriptor getModuleAndRoot(@Nullable CompileContext context, File file) { + public JavaSourceRootDescriptor getModuleAndRoot(@Nullable CompileContext context, File file) { return findParentDescriptor(file, JavaModuleBuildTargetType.ALL_TYPES, context); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java index 9e854b388ba1..4f5f2ec25170 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaBuilderUtil.java @@ -14,7 +14,6 @@ import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.incremental.FSOperations; import org.jetbrains.jps.incremental.ModuleBuildTarget; import org.jetbrains.jps.incremental.Utils; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.messages.ProgressMessage; import org.jetbrains.jps.model.module.JpsModule; @@ -164,7 +163,7 @@ public class JavaBuilderUtil { final List> result = new ArrayList>(); for (File file : affected) { if (!moduleBasedFilter.accept(file)) { - final RootDescriptor moduleAndRoot = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); + final JavaSourceRootDescriptor moduleAndRoot = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); result.add(Pair.create(file, moduleAndRoot != null ? moduleAndRoot.target.getModule() : null)); } } @@ -176,7 +175,7 @@ public class JavaBuilderUtil { final Set chunkModules = chunk.getModules(); if (!chunkModules.isEmpty()) { for (File file : affected) { - final RootDescriptor moduleAndRoot = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); + final JavaSourceRootDescriptor moduleAndRoot = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); if (moduleAndRoot != null && chunkModules.contains(moduleAndRoot.target.getModule())) { return true; } @@ -250,7 +249,7 @@ public class JavaBuilderUtil { @Override public boolean accept(File file) { - final RootDescriptor rd = myContext.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(myContext, file); + final JavaSourceRootDescriptor rd = myContext.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(myContext, file); if (rd == null) { return true; } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/RootDescriptor.java b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaSourceRootDescriptor.java similarity index 78% rename from jps/jps-builders/src/org/jetbrains/jps/incremental/fs/RootDescriptor.java rename to jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaSourceRootDescriptor.java index 1b150b0ccbb2..04c3dc8fb715 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/RootDescriptor.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/java/JavaSourceRootDescriptor.java @@ -1,4 +1,4 @@ -package org.jetbrains.jps.incremental.fs; +package org.jetbrains.jps.builders.java; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; @@ -15,19 +15,21 @@ import java.io.FileFilter; * @author Eugene Zhuravlev * Date: 1/3/12 */ -public final class RootDescriptor extends BuildRootDescriptor { +public final class JavaSourceRootDescriptor extends BuildRootDescriptor { @NotNull public final File root; @NotNull public final ModuleBuildTarget target; public final boolean isGeneratedSources; public final boolean isTemp; + private final String myPackagePrefix; - public RootDescriptor(@NotNull File root, @NotNull ModuleBuildTarget target, boolean isGenerated, boolean isTemp) { + public JavaSourceRootDescriptor(@NotNull File root, @NotNull ModuleBuildTarget target, boolean isGenerated, boolean isTemp, @NotNull String packagePrefix) { this.root = root; this.target = target; this.isGeneratedSources = isGenerated; this.isTemp = isTemp; + myPackagePrefix = packagePrefix; } @Override @@ -39,6 +41,11 @@ public final class RootDescriptor extends BuildRootDescriptor { '}'; } + @NotNull + public String getPackagePrefix() { + return myPackagePrefix; + } + @Override public String getRootId() { return FileUtil.toSystemIndependentName(root.getPath()); diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java index 9536aed12ac4..a3bade8b0d37 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildRunner.java @@ -153,7 +153,7 @@ public class BuildRunner { targetTypes.add(targetType); } else { - BuildTargetLoader loader = targetType.createLoader(pd.jpsModel); + BuildTargetLoader loader = targetType.createLoader(pd.getModel()); for (String targetId : scope.getTargetIdList()) { BuildTarget target = loader.createTarget(targetId); if (target != null) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java index d3f3a434dbef..73995ab4d56b 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/BuildSession.java @@ -166,7 +166,7 @@ final class BuildSession implements Runnable, CanceledStatus { if (fsStateStream != null) { try { try { - fsState.load(fsStateStream, pd.jpsModel, pd.getBuildRootIndex()); + fsState.load(fsStateStream, pd.getModel(), pd.getBuildRootIndex()); applyFSEvent(pd, myInitialFSDelta); } finally { @@ -330,7 +330,7 @@ final class BuildSession implements Runnable, CanceledStatus { out.writeInt(FSState.VERSION); out.writeLong(myLastEventOrdinal); boolean hasWorkToDoWithModules = false; - for (JpsModule module : pd.jpsProject.getModules()) { + for (JpsModule module : pd.getProject().getModules()) { for (JavaModuleBuildTargetType type : JavaModuleBuildTargetType.ALL_TYPES) { if (state.hasWorkToDo(new ModuleBuildTarget(module, type))) { hasWorkToDoWithModules = true; diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/ProjectDescriptor.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/ProjectDescriptor.java index 85728c1016d3..7454ac156ea5 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/ProjectDescriptor.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/ProjectDescriptor.java @@ -25,14 +25,14 @@ import java.util.Set; * Date: 1/8/12 */ public final class ProjectDescriptor { - public final JpsProject jpsProject; - public final JpsModel jpsModel; + private final JpsProject myProject; + private final JpsModel myModel; public final BuildFSState fsState; public final ProjectTimestamps timestamps; public final BuildDataManager dataManager; private final BuildLoggingManager myLoggingManager; private final BuildTargetsState myTargetsState; - public ModuleExcludeIndex moduleExcludeIndex; + private final ModuleExcludeIndex myModuleExcludeIndex; private int myUseCounter = 1; private Set> myProjectJavaSdks; private CompilerEncodingConfiguration myEncodingConfiguration; @@ -40,7 +40,7 @@ public final class ProjectDescriptor { private final BuildTargetIndex myBuildTargetIndex; private final IgnoredFileIndex myIgnoredFileIndex; - public ProjectDescriptor(JpsModel jpsModel, + public ProjectDescriptor(JpsModel model, BuildFSState fsState, ProjectTimestamps timestamps, BuildDataManager dataManager, @@ -48,19 +48,19 @@ public final class ProjectDescriptor { final ModuleExcludeIndex moduleExcludeIndex, final BuildTargetsState targetsState, final BuildTargetIndex buildTargetIndex, final BuildRootIndex buildRootIndex, IgnoredFileIndex ignoredFileIndex) { - this.jpsModel = jpsModel; + myModel = model; myIgnoredFileIndex = ignoredFileIndex; - this.jpsProject = jpsModel.getProject(); + myProject = model.getProject(); this.fsState = fsState; this.timestamps = timestamps; this.dataManager = dataManager; myBuildTargetIndex = buildTargetIndex; myBuildRootIndex = buildRootIndex; myLoggingManager = loggingManager; - this.moduleExcludeIndex = moduleExcludeIndex; + myModuleExcludeIndex = moduleExcludeIndex; myProjectJavaSdks = new HashSet>(); - myEncodingConfiguration = new CompilerEncodingConfiguration(jpsModel, buildRootIndex); - for (JpsModule module : jpsProject.getModules()) { + myEncodingConfiguration = new CompilerEncodingConfiguration(model, buildRootIndex); + for (JpsModule module : myProject.getModules()) { final JpsSdk sdk = module.getSdk(JpsJavaSdkType.INSTANCE); if (sdk != null && !myProjectJavaSdks.contains(sdk) && sdk.getVersionString() != null && sdk.getHomePath() != null) { myProjectJavaSdks.add(sdk); @@ -121,4 +121,16 @@ public final class ProjectDescriptor { } } } + + public ModuleExcludeIndex getModuleExcludeIndex() { + return myModuleExcludeIndex; + } + + public JpsModel getModel() { + return myModel; + } + + public JpsProject getProject() { + return myProject; + } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java index fc9ef933e0eb..9acb359678eb 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContextImpl.java @@ -55,7 +55,7 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon myIsProjectRebuild = isProjectRebuild; myIsMake = !isProjectRebuild && isMake; myDelegateMessageHandler = delegateMessageHandler; - myProjectPaths = new ProjectPaths(pd.jpsProject); + myProjectPaths = new ProjectPaths(pd.getProject()); } @Override @@ -102,12 +102,13 @@ public class CompileContextImpl extends UserDataHolderBase implements CompileCon @Override @NotNull public ProcessorConfigProfile getAnnotationProcessingProfile(JpsModule module) { - final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(getProjectDescriptor().jpsProject); + final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration( + getProjectDescriptor().getProject()); Map map = myAnnotationProcessingProfileMap; if (map == null) { map = new HashMap(); final Map namesMap = new HashMap(); - for (JpsModule m : getProjectDescriptor().jpsProject.getModules()) { + for (JpsModule m : getProjectDescriptor().getProject().getModules()) { namesMap.put(m.getName(), m); } if (!namesMap.isEmpty()) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompilerEncodingConfiguration.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompilerEncodingConfiguration.java index 3213284cf44c..df28a3585498 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompilerEncodingConfiguration.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompilerEncodingConfiguration.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.JpsPathUtil; import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.builders.BuildRootIndex; -import org.jetbrains.jps.incremental.fs.RootDescriptor; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.model.JpsEncodingConfigurationService; import org.jetbrains.jps.model.JpsEncodingProjectConfiguration; import org.jetbrains.jps.model.JpsModel; @@ -49,7 +49,7 @@ public class CompilerEncodingConfiguration { File file = JpsPathUtil.urlToFile(fileUrl); if (charset == null || (!file.isDirectory() && !shouldHonorEncodingForCompilation(builders, file))) continue; - final RootDescriptor rootDescriptor = myRootsIndex.getModuleAndRoot(null, file); + final JavaSourceRootDescriptor rootDescriptor = myRootsIndex.getModuleAndRoot(null, file); if (rootDescriptor == null) continue; final JpsModule module = rootDescriptor.target.getModule(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/FSOperations.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/FSOperations.java index 4fc9ed4d9f2a..71c8d09673ce 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/FSOperations.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/FSOperations.java @@ -10,9 +10,9 @@ import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.builders.BuildTarget; import org.jetbrains.jps.builders.FileProcessor; import org.jetbrains.jps.builders.impl.BuildTargetChunk; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.cmdline.ProjectDescriptor; import org.jetbrains.jps.incremental.fs.BuildFSState; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.storage.Timestamps; import org.jetbrains.jps.indices.ModuleExcludeIndex; import org.jetbrains.jps.model.java.JpsJavaClasspathKind; @@ -30,7 +30,7 @@ import java.util.Set; */ public class FSOperations { public static void markDirty(CompileContext context, final File file) throws IOException { - final RootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); + final JavaSourceRootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); if (rd != null) { final ProjectDescriptor pd = context.getProjectDescriptor(); pd.fsState.markDirty(context, file, rd, pd.timestamps.getStorage()); @@ -38,7 +38,7 @@ public class FSOperations { } public static void markDirtyIfNotDeleted(CompileContext context, final File file) throws IOException { - final RootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); + final JavaSourceRootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); if (rd != null) { final ProjectDescriptor pd = context.getProjectDescriptor(); pd.fsState.markDirtyIfNotDeleted(context, file, rd, pd.timestamps.getStorage()); @@ -46,7 +46,7 @@ public class FSOperations { } public static void markDeleted(CompileContext context, File file) throws IOException { - final RootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); + final JavaSourceRootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); if (rd != null) { final ProjectDescriptor pd = context.getProjectDescriptor(); pd.fsState.registerDeleted(rd.target, file, pd.timestamps.getStorage()); @@ -130,9 +130,9 @@ public class FSOperations { ModuleBuildTarget target, Timestamps timestamps, boolean forceMarkDirty, @Nullable THashSet currentFiles) throws IOException { - final ModuleExcludeIndex rootsIndex = context.getProjectDescriptor().moduleExcludeIndex; + final ModuleExcludeIndex rootsIndex = context.getProjectDescriptor().getModuleExcludeIndex(); final Set excludes = new HashSet(rootsIndex.getModuleExcludes(target.getModule())); - for (RootDescriptor rd : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) { + for (JavaSourceRootDescriptor rd : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) { if (!rd.root.exists()) { continue; } @@ -141,7 +141,7 @@ public class FSOperations { } } - private static void traverseRecursively(CompileContext context, final RootDescriptor rd, final File file, Set excludes, @NotNull final Timestamps tsStorage, final boolean forceDirty, @Nullable Set currentFiles) throws IOException { + private static void traverseRecursively(CompileContext context, final JavaSourceRootDescriptor rd, final File file, Set excludes, @NotNull final Timestamps tsStorage, final boolean forceDirty, @Nullable Set currentFiles) throws IOException { final File[] children = file.listFiles(); if (children != null) { // is directory if (children.length > 0 && !JpsPathUtil.isUnder(excludes, file)) { 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 d155a0bf1745..d2c396150a10 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -24,12 +24,12 @@ import org.jetbrains.jps.builders.*; import org.jetbrains.jps.builders.impl.BuildTargetChunk; import org.jetbrains.jps.builders.java.JavaBuilderUtil; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.builders.java.dependencyView.Callbacks; import org.jetbrains.jps.builders.storage.SourceToOutputMapping; import org.jetbrains.jps.cmdline.BuildRunner; import org.jetbrains.jps.cmdline.ProjectDescriptor; import org.jetbrains.jps.incremental.fs.BuildFSState; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.java.ExternalJavacDescriptor; import org.jetbrains.jps.incremental.java.JavaBuilder; import org.jetbrains.jps.incremental.java.JavaBuilderLogger; @@ -262,7 +262,7 @@ public class IncProjectBuilder { private void cleanOutputRoots(CompileContext context) throws ProjectBuildException { // whole project is affected final boolean shouldClear = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration( - context.getProjectDescriptor().jpsProject).isClearOutputDirectoryOnRebuild(); + context.getProjectDescriptor().getProject()).isClearOutputDirectoryOnRebuild(); try { if (shouldClear) { clearOutputs(context); @@ -598,9 +598,7 @@ public class IncProjectBuilder { rootFiles.add(rd.getRootFile()); context.getProjectDescriptor().fsState.clearRecompile(rd); } - myAsyncTasks.add( - FileUtil.asyncDelete(rootFiles) - ); + myAsyncTasks.add(FileUtil.asyncDelete(rootFiles)); } try { @@ -760,9 +758,9 @@ public class IncProjectBuilder { nextPassRequired = false; myProjectDescriptor.fsState.beforeNextRoundStart(context, chunk); - DirtyFilesHolder dirtyFilesHolder = new DirtyFilesHolder() { + DirtyFilesHolder dirtyFilesHolder = new DirtyFilesHolder() { @Override - public void processDirtyFiles(@NotNull FileProcessor processor) throws IOException { + public void processDirtyFiles(@NotNull FileProcessor processor) throws IOException { FSOperations.processFilesToRecompile(context, chunk, processor); } }; @@ -834,16 +832,16 @@ public class IncProjectBuilder { } private static void syncOutputFiles(final CompileContext context, - DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { + DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { final BuildDataManager dataManager = context.getProjectDescriptor().dataManager; try { final Collection allOutputs = new LinkedList(); - dirtyFilesHolder.processDirtyFiles(new FileProcessor() { + dirtyFilesHolder.processDirtyFiles(new FileProcessor() { private final Map storageMap = new HashMap(); @Override - public boolean apply(ModuleBuildTarget target, File file, RootDescriptor sourceRoot) throws IOException { + public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException { SourceToOutputMapping srcToOut = storageMap.get(target); if (srcToOut == null) { srcToOut = dataManager.getSourceToOutputMap(target); @@ -943,7 +941,7 @@ public class IncProjectBuilder { fsState.markInitialScanPerformed(target); } final Timestamps timestamps = pd.timestamps.getStorage(); - for (RootDescriptor rd : pd.getBuildRootIndex().getTargetRoots(target, context)) { + for (JavaSourceRootDescriptor rd : pd.getBuildRootIndex().getTargetRoots(target, context)) { marked |= fsState.markAllUpToDate(context, rd, timestamps); } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java index c87aa2b5e8ee..01182286d436 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleBuildTarget.java @@ -6,16 +6,18 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.JpsPathUtil; import org.jetbrains.jps.builders.BuildRootIndex; import org.jetbrains.jps.builders.BuildTarget; +import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.indices.IgnoredFileIndex; import org.jetbrains.jps.indices.ModuleExcludeIndex; -import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.model.JpsModel; +import org.jetbrains.jps.model.JpsSimpleElement; +import org.jetbrains.jps.model.java.JavaSourceRootProperties; import org.jetbrains.jps.model.java.JavaSourceRootType; import org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator; import org.jetbrains.jps.model.java.JpsJavaExtensionService; import org.jetbrains.jps.model.module.JpsModule; -import org.jetbrains.jps.model.module.JpsModuleSourceRoot; +import org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot; import java.io.File; import java.util.ArrayList; @@ -26,7 +28,7 @@ import java.util.List; /** * @author nik */ -public class ModuleBuildTarget extends BuildTarget { +public class ModuleBuildTarget extends BuildTarget { private final JpsModule myModule; private final String myModuleName; private final JavaModuleBuildTargetType myTargetType; @@ -77,21 +79,19 @@ public class ModuleBuildTarget extends BuildTarget { @NotNull @Override - public List computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex) { - List roots = new ArrayList(); - for (JpsModuleSourceRoot sourceRoot : myModule.getSourceRoots()) { + public List computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex) { + List roots = new ArrayList(); + JavaSourceRootType type = isTests() ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE; + for (JpsTypedModuleSourceRoot> sourceRoot : myModule.getSourceRoots(type)) { final File root = JpsPathUtil.urlToFile(sourceRoot.getUrl()); - final boolean testRoot = JavaSourceRootType.TEST_SOURCE.equals(sourceRoot.getRootType()); - if (testRoot == isTests()) { - roots.add(new RootDescriptor(root, this, false, false)); - } + roots.add(new JavaSourceRootDescriptor(root, this, false, false, sourceRoot.getProperties().getData().getPackagePrefix())); } return roots; } @Override - public RootDescriptor findRootDescriptor(String rootId, BuildRootIndex rootIndex) { - List descriptors = rootIndex.getRootDescriptors(new File(rootId), Collections.singletonList(myTargetType), null); + public JavaSourceRootDescriptor findRootDescriptor(String rootId, BuildRootIndex rootIndex) { + List descriptors = rootIndex.getRootDescriptors(new File(rootId), Collections.singletonList(myTargetType), null); return ContainerUtil.getFirstItem(descriptors); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java index 5eefe58c52d4..550a38235aa6 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/ModuleLevelBuilder.java @@ -2,7 +2,7 @@ package org.jetbrains.jps.incremental; import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.builders.DirtyFilesHolder; -import org.jetbrains.jps.incremental.fs.RootDescriptor; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import java.io.File; @@ -25,7 +25,7 @@ public abstract class ModuleLevelBuilder extends Builder { public abstract ExitCode build(CompileContext context, ModuleChunk chunk, - DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException; + DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException; public boolean shouldHonorFileEncodingForCompilation(File file) { return false; diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactBuildTarget.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactBuildTarget.java index 44c62e59b767..0e39ecbb829f 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactBuildTarget.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactBuildTarget.java @@ -3,7 +3,6 @@ package org.jetbrains.jps.incremental.artifacts; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.builders.BuildRootDescriptor; import org.jetbrains.jps.builders.BuildRootIndex; import org.jetbrains.jps.builders.BuildTarget; @@ -105,7 +104,7 @@ public class ArtifactBuildTarget extends BuildTarget { @Override public List computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex) { ArtifactInstructionsBuilderImpl builder = new ArtifactInstructionsBuilderImpl(index, ignoredFileIndex, this); - ArtifactInstructionsBuilderContext context = new ArtifactInstructionsBuilderContextImpl(model, new ProjectPaths(model.getProject())); + ArtifactInstructionsBuilderContext context = new ArtifactInstructionsBuilderContextImpl(); String outputPath = StringUtil.notNullize(myArtifact.getOutputPath()); final CopyToDirectoryInstructionCreator instructionCreator = new CopyToDirectoryInstructionCreator(builder, outputPath); LayoutElementBuildersRegistry.getInstance().generateInstructions(myArtifact, instructionCreator, context); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/IncArtifactBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/IncArtifactBuilder.java index d1a76f7e769a..ad50f36d7384 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/IncArtifactBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/IncArtifactBuilder.java @@ -43,7 +43,7 @@ public class IncArtifactBuilder extends TargetBuilder { return; } final ProjectDescriptor pd = context.getProjectDescriptor(); - final ArtifactSorter sorter = new ArtifactSorter(pd.jpsModel); + final ArtifactSorter sorter = new ArtifactSorter(pd.getModel()); final Map selfIncludingNameMap = sorter.getArtifactToSelfIncludingNameMap(); final JpsArtifact selfIncluding = selfIncludingNameMap.get(artifact); if (selfIncluding != null) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContext.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContext.java index fd1e1164cb1c..b6f7899f9407 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContext.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContext.java @@ -1,9 +1,5 @@ package org.jetbrains.jps.incremental.artifacts.instructions; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.ProjectPaths; -import org.jetbrains.jps.model.JpsModel; -import org.jetbrains.jps.model.JpsProject; import org.jetbrains.jps.model.artifact.JpsArtifact; /** @@ -11,13 +7,6 @@ import org.jetbrains.jps.model.artifact.JpsArtifact; */ public interface ArtifactInstructionsBuilderContext { - @NotNull - ProjectPaths getProjectPaths(); - - JpsProject getJpsProject(); - - JpsModel getJpsModel(); - boolean enterArtifact(JpsArtifact artifact); void leaveArtifact(JpsArtifact artifact); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContextImpl.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContextImpl.java index 339976a92559..cf24cf98c650 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContextImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/instructions/ArtifactInstructionsBuilderContextImpl.java @@ -1,9 +1,5 @@ package org.jetbrains.jps.incremental.artifacts.instructions; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jps.ProjectPaths; -import org.jetbrains.jps.model.JpsModel; -import org.jetbrains.jps.model.JpsProject; import org.jetbrains.jps.model.artifact.JpsArtifact; import java.util.HashSet; @@ -13,28 +9,12 @@ import java.util.Set; * @author nik */ public class ArtifactInstructionsBuilderContextImpl implements ArtifactInstructionsBuilderContext { - private final JpsProject myJpsProject; - private final ProjectPaths myProjectPaths; private final Set myParentArtifacts; - private JpsModel myModel; - public ArtifactInstructionsBuilderContextImpl(JpsModel jpsModel, ProjectPaths projectPaths) { - myJpsProject = jpsModel.getProject(); - myModel = jpsModel; - myProjectPaths = projectPaths; + public ArtifactInstructionsBuilderContextImpl() { myParentArtifacts = new HashSet(); } - @Override - public JpsProject getJpsProject() { - return myJpsProject; - } - - @Override - public JpsModel getJpsModel() { - return myModel; - } - @Override public boolean enterArtifact(JpsArtifact artifact) { return myParentArtifacts.add(artifact); @@ -44,10 +24,4 @@ public class ArtifactInstructionsBuilderContextImpl implements ArtifactInstructi public void leaveArtifact(JpsArtifact artifact) { myParentArtifacts.remove(artifact); } - - @NotNull - @Override - public ProjectPaths getProjectPaths() { - return myProjectPaths; - } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/BuildFSState.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/BuildFSState.java index 0244743ed3b2..cf7ee4b5a610 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/BuildFSState.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/BuildFSState.java @@ -10,9 +10,9 @@ import org.jetbrains.jps.builders.BuildRootDescriptor; import org.jetbrains.jps.builders.BuildRootIndex; import org.jetbrains.jps.builders.BuildTarget; import org.jetbrains.jps.builders.FileProcessor; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.incremental.CompileScope; -import org.jetbrains.jps.incremental.ModuleBuildTarget; import org.jetbrains.jps.incremental.Utils; import org.jetbrains.jps.incremental.artifacts.instructions.ArtifactRootDescriptor; import org.jetbrains.jps.incremental.storage.Timestamps; @@ -30,7 +30,7 @@ import java.util.Set; */ public class BuildFSState extends FSState { private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.fs.BuildFSState"); - private static final Key> CONTEXT_TARGETS_KEY = Key.create("_fssfate_context_modules_"); + private static final Key>> CONTEXT_TARGETS_KEY = Key.create("_fssfate_context_targets_"); private static final Key CURRENT_ROUND_DELTA_KEY = Key.create("_current_round_delta_"); private static final Key LAST_ROUND_DELTA_KEY = Key.create("_last_round_delta_"); @@ -69,12 +69,12 @@ public class BuildFSState extends FSState { if (context == null) { return false; } - Set targets = CONTEXT_TARGETS_KEY.get(context, Collections.emptySet()); + Set> targets = CONTEXT_TARGETS_KEY.get(context, Collections.>emptySet()); return targets.contains(rd.getTarget()); } @Override - public boolean markDirtyIfNotDeleted(@Nullable CompileContext context, File file, final RootDescriptor rd, @Nullable Timestamps tsStorage) throws IOException { + public boolean markDirtyIfNotDeleted(@Nullable CompileContext context, File file, final BuildRootDescriptor rd, @Nullable Timestamps tsStorage) throws IOException { final boolean marked = super.markDirtyIfNotDeleted(context, file, rd, tsStorage); if (marked) { final FilesDelta roundDelta = getRoundDelta(CURRENT_ROUND_DELTA_KEY, context); @@ -112,7 +112,7 @@ public class BuildFSState extends FSState { setRoundDelta(CURRENT_ROUND_DELTA_KEY, context, new FilesDelta()); } - public > boolean processFilesToRecompile(CompileContext context, final T target, final FileProcessor processor) throws IOException { + public > boolean processFilesToRecompile(CompileContext context, final T target, final FileProcessor processor) throws IOException { final Map> data = getSourcesToRecompile(context, target); BuildRootIndex rootIndex = context.getProjectDescriptor().getBuildRootIndex(); final CompileScope scope = context.getScope(); @@ -137,7 +137,7 @@ public class BuildFSState extends FSState { /** * @return true if marked something, false otherwise */ - public boolean markAllUpToDate(CompileContext context, final RootDescriptor rd, final Timestamps stamps) throws IOException { + public boolean markAllUpToDate(CompileContext context, final JavaSourceRootDescriptor rd, final Timestamps stamps) throws IOException { boolean marked = false; final FilesDelta delta = getDelta(rd.target); final Set files = delta.clearRecompile(rd); @@ -192,7 +192,7 @@ public class BuildFSState extends FSState { return marked; } - private static void setContextTargets(@Nullable CompileContext context, @Nullable Set targets) { + private static void setContextTargets(@Nullable CompileContext context, @Nullable Set> targets) { if (context != null) { CONTEXT_TARGETS_KEY.set(context, targets); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FSState.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FSState.java index 04b6d9e7ffa7..099bde222228 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FSState.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FSState.java @@ -89,11 +89,11 @@ public class FSState { public boolean markDirtyIfNotDeleted(@Nullable CompileContext context, final File file, - final RootDescriptor rd, + final BuildRootDescriptor rd, final @Nullable Timestamps tsStorage) throws IOException { - final boolean marked = getDelta(rd.target).markRecompileIfNotDeleted(rd, file); + final boolean marked = getDelta(rd.getTarget()).markRecompileIfNotDeleted(rd, file); if (marked && tsStorage != null) { - tsStorage.removeStamp(file, rd.target); + tsStorage.removeStamp(file, rd.getTarget()); } return marked; } diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FilesDelta.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FilesDelta.java index 7917adbc8aae..b242d03c65c8 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FilesDelta.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/fs/FilesDelta.java @@ -109,7 +109,7 @@ final class FilesDelta { return added; } - public boolean markRecompileIfNotDeleted(RootDescriptor root, File file) { + public boolean markRecompileIfNotDeleted(BuildRootDescriptor root, File file) { final boolean isMarkedDeleted; synchronized (myDeletedPaths) { isMarkedDeleted = !myDeletedPaths.isEmpty() && myDeletedPaths.contains(FileUtil.toCanonicalPath(file.getPath())); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index 007a2b3ff907..a9c87ffb6413 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -35,11 +35,11 @@ import org.jetbrains.jps.builders.BuildRootIndex; import org.jetbrains.jps.builders.DirtyFilesHolder; import org.jetbrains.jps.builders.FileProcessor; import org.jetbrains.jps.builders.java.JavaBuilderUtil; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.builders.java.dependencyView.Callbacks; import org.jetbrains.jps.builders.java.dependencyView.Mappings; import org.jetbrains.jps.cmdline.ProjectDescriptor; import org.jetbrains.jps.incremental.*; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.messages.BuildMessage; import org.jetbrains.jps.incremental.messages.CompilerMessage; import org.jetbrains.jps.incremental.messages.ProgressMessage; @@ -124,7 +124,7 @@ public class JavaBuilder extends ModuleLevelBuilder { if (srcFile != null && content != null) { final String outputPath = FileUtil.toSystemIndependentName(out.getFile().getPath()); final String sourcePath = FileUtil.toSystemIndependentName(srcFile.getPath()); - final RootDescriptor rootDescriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, srcFile); + final JavaSourceRootDescriptor rootDescriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, srcFile); final BuildDataManager dataManager = context.getProjectDescriptor().dataManager; boolean isTemp = false; if (rootDescriptor != null) { @@ -172,13 +172,13 @@ public class JavaBuilder extends ModuleLevelBuilder { public ExitCode build(final CompileContext context, final ModuleChunk chunk, - DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { + DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { try { final Set filesToCompile = new THashSet(FileUtil.FILE_HASHING_STRATEGY); final Set formsToCompile = new THashSet(FileUtil.FILE_HASHING_STRATEGY); - dirtyFilesHolder.processDirtyFiles(new FileProcessor() { - public boolean apply(ModuleBuildTarget target, File file, RootDescriptor sourceRoot) throws IOException { + dirtyFilesHolder.processDirtyFiles(new FileProcessor() { + public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException { if (JAVA_SOURCES_FILTER.accept(file)) { filesToCompile.add(file); } @@ -190,15 +190,16 @@ public class JavaBuilder extends ModuleLevelBuilder { }); // force compilation of bound source file if the form is dirty - final JpsCompilerExcludes excludes = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(context.getProjectDescriptor().jpsProject).getCompilerExcludes(); + final JpsCompilerExcludes excludes = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration( + context.getProjectDescriptor().getProject()).getCompilerExcludes(); if (!context.isProjectRebuild()) { for (Iterator formsIterator = formsToCompile.iterator(); formsIterator.hasNext(); ) { final File form = formsIterator.next(); - final RootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, form); + final JavaSourceRootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, form); if (descriptor == null) { continue; } - for (RootDescriptor rd : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(descriptor.target, context)) { + for (JavaSourceRootDescriptor rd : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(descriptor.target, context)) { final File boundSource = getBoundSource(rd.root, form); if (boundSource == null) { continue; @@ -311,7 +312,7 @@ public class JavaBuilder extends ModuleLevelBuilder { final ProjectPaths paths = context.getProjectPaths(); final ProjectDescriptor pd = context.getProjectDescriptor(); final boolean addNotNullAssertions = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration( - pd.jpsProject).isAddNotNullAssertions(); + pd.getProject()).isAddNotNullAssertions(); final Collection classpath = paths.getCompilationClasspath(chunk, false/*context.isProjectRebuild()*/); @@ -329,7 +330,7 @@ public class JavaBuilder extends ModuleLevelBuilder { final Set tempRootsSourcePath = new HashSet(); final BuildRootIndex index = pd.getBuildRootIndex(); for (ModuleBuildTarget target : chunk.getTargets()) { - for (RootDescriptor rd : index.getTempTargetRoots(target, context)) { + for (JavaSourceRootDescriptor rd : index.getTempTargetRoots(target, context)) { tempRootsSourcePath.add(rd.root); } } @@ -365,7 +366,8 @@ public class JavaBuilder extends ModuleLevelBuilder { try { context.processMessage(new ProgressMessage("Instrumenting forms [" + chunkName + "]")); instrumentForms(context, chunk, chunkSourcePath, finder, forms, outputSink); - JpsUiDesignerConfiguration configuration = JpsUiDesignerExtensionService.getInstance().getUiDesignerConfiguration(pd.jpsProject); + JpsUiDesignerConfiguration configuration = JpsUiDesignerExtensionService.getInstance().getUiDesignerConfiguration( + pd.getProject()); if (configuration != null && configuration.isCopyFormsRuntimeToOutput() && !chunk.containsTests()) { for (JpsModule module : chunk.getModules()) { final File outputDir = paths.getModuleOutputDir(module, false); @@ -505,7 +507,7 @@ public class JavaBuilder extends ModuleLevelBuilder { } private static boolean useEclipseCompiler(CompileContext context) { - JpsProject project = context.getProjectDescriptor().jpsProject; + JpsProject project = context.getProjectDescriptor().getProject(); return USE_EMBEDDED_JAVAC && "Eclipse".equalsIgnoreCase(JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project).getJavaCompilerId()); } @@ -625,7 +627,7 @@ public class JavaBuilder extends ModuleLevelBuilder { } private static int getJavacServerHeapSize(CompileContext context) { - final JpsProject project = context.getProjectDescriptor().jpsProject; + final JpsProject project = context.getProjectDescriptor().getProject(); final JpsJavaCompilerConfiguration config = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project); final JpsJavaCompilerOptions options = config.getCurrentCompilerOptions(); return options.MAXIMUM_HEAP_SIZE; @@ -705,7 +707,7 @@ public class JavaBuilder extends ModuleLevelBuilder { } JpsJavaCompilerConfiguration compilerConfiguration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration( - context.getProjectDescriptor().jpsProject); + context.getProjectDescriptor().getProject()); String bytecodeTarget = null; int chunkSdkVersion = -1; for (JpsModule module : chunk.getModules()) { @@ -823,7 +825,7 @@ public class JavaBuilder extends ModuleLevelBuilder { final List options = new ArrayList(); final List vmOptions = new ArrayList(); - final JpsProject project = context.getProjectDescriptor().jpsProject; + final JpsProject project = context.getProjectDescriptor().getProject(); final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project); final boolean useEclipseCompiler = useEclipseCompiler(context); final JpsJavaCompilerOptions compilerOptions = compilerConfig.getCurrentCompilerOptions(); @@ -891,7 +893,7 @@ public class JavaBuilder extends ModuleLevelBuilder { continue; } final Set roots = new LinkedHashSet(); - for (RootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) { + for (JavaSourceRootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) { roots.add(descriptor.root); } map.put(outputDir, roots); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java index 3e6b4aada61e..f6493bb53996 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/resources/ResourcesBuilder.java @@ -8,9 +8,9 @@ import org.jetbrains.jps.JpsPathUtil; import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.builders.DirtyFilesHolder; import org.jetbrains.jps.builders.FileProcessor; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.builders.storage.SourceToOutputMapping; import org.jetbrains.jps.incremental.*; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.messages.BuildMessage; import org.jetbrains.jps.incremental.messages.CompilerMessage; import org.jetbrains.jps.incremental.messages.ProgressMessage; @@ -43,13 +43,13 @@ public class ResourcesBuilder extends ModuleLevelBuilder { // init patterns ResourcePatterns patterns = ResourcePatterns.KEY.get(context); if (patterns == null) { - ResourcePatterns.KEY.set(context, new ResourcePatterns(context.getProjectDescriptor().jpsProject)); + ResourcePatterns.KEY.set(context, new ResourcePatterns(context.getProjectDescriptor().getProject())); } } public ExitCode build(final CompileContext context, final ModuleChunk chunk, - DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { + DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { final ResourcePatterns patterns = ResourcePatterns.KEY.get(context); assert patterns != null; try { @@ -66,8 +66,8 @@ public class ResourcesBuilder extends ModuleLevelBuilder { } }; - FSOperations.processFilesToRecompile(context, chunk, moduleFilter, new FileProcessor() { - public boolean apply(final ModuleBuildTarget target, final File file, final RootDescriptor sourceRoot) throws IOException { + FSOperations.processFilesToRecompile(context, chunk, moduleFilter, new FileProcessor() { + public boolean apply(final ModuleBuildTarget target, final File file, final JavaSourceRootDescriptor sourceRoot) throws IOException { if (patterns.isResourceFile(file, sourceRoot.root)) { try { context.processMessage(new ProgressMessage("Copying " + file.getPath())); @@ -99,7 +99,7 @@ public class ResourcesBuilder extends ModuleLevelBuilder { private static void copyResource(CompileContext context, JpsModule module, File file, - RootDescriptor sourceRoot, + JavaSourceRootDescriptor sourceRoot, final SourceToOutputMapping outputToSourceMapping, final boolean tests) throws IOException { final String outputRootUrl = JpsJavaExtensionService.getInstance().getOutputUrl(module, tests); if (outputRootUrl == null) { @@ -107,11 +107,11 @@ public class ResourcesBuilder extends ModuleLevelBuilder { } String rootPath = FileUtil.toSystemIndependentName(sourceRoot.root.getAbsolutePath()); final String relativePath = FileUtil.getRelativePath(rootPath, FileUtil.toSystemIndependentName(file.getPath()), '/'); - final String prefix = JpsJavaExtensionService.getInstance().getSourcePrefix(module, JpsPathUtil.pathToUrl(rootPath)); + final String prefix = sourceRoot.getPackagePrefix(); final StringBuilder targetPath = new StringBuilder(); targetPath.append(JpsPathUtil.urlToPath(outputRootUrl)); - if (prefix != null && prefix.length() > 0) { + if (prefix.length() > 0) { targetPath.append('/').append(prefix.replace('.', '/')); } targetPath.append('/').append(relativePath); diff --git a/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java b/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java index 342637fdfcaa..4251bb9b6825 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java +++ b/jps/jps-builders/testSrc/org/jetbrains/ether/IncrementalTestCase.java @@ -76,7 +76,12 @@ public abstract class IncrementalTestCase extends JpsBuildTestCase { }); String outputPath = getAbsolutePath("out"); - JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(myJpsProject).setOutputUrl(JpsPathUtil.pathToUrl(outputPath)); + JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(myProject).setOutputUrl(JpsPathUtil.pathToUrl(outputPath)); + } + + @Override + protected File doGetProjectDir() throws IOException { + return workDir; } protected String getUrl(String pathRelativeToProjectRoot) { @@ -244,7 +249,7 @@ public abstract class IncrementalTestCase extends JpsBuildTestCase { } protected JpsLibrary addLibrary(final String jarPath) { - JpsLibrary library = myJpsProject.addLibrary("l", JpsJavaLibraryType.INSTANCE); + JpsLibrary library = myProject.addLibrary("l", JpsJavaLibraryType.INSTANCE); library.addRoot(new File(getAbsolutePath(jarPath)), JpsOrderRootType.COMPILED); return library; } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java index 6e81ebbd2b4c..b0ba2beb3728 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/JpsBuildTestCase.java @@ -1,16 +1,15 @@ package org.jetbrains.jps.builders; +import com.intellij.openapi.util.io.FileSystemUtil; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.testFramework.UsefulTestCase; +import com.intellij.util.io.TestFileSystemBuilder; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.JpsPathUtil; import org.jetbrains.jps.api.CanceledStatus; import org.jetbrains.jps.builders.impl.BuildRootIndexImpl; import org.jetbrains.jps.builders.impl.BuildTargetIndexImpl; -import org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl; -import org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl; -import org.jetbrains.jps.indices.ModuleExcludeIndex; import org.jetbrains.jps.cmdline.ClasspathBootstrap; import org.jetbrains.jps.cmdline.ProjectDescriptor; import org.jetbrains.jps.incremental.*; @@ -20,6 +19,9 @@ import org.jetbrains.jps.incremental.java.JavaBuilderLoggerImpl; import org.jetbrains.jps.incremental.storage.BuildDataManager; import org.jetbrains.jps.incremental.storage.BuildTargetsState; import org.jetbrains.jps.incremental.storage.ProjectTimestamps; +import org.jetbrains.jps.indices.ModuleExcludeIndex; +import org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl; +import org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl; import org.jetbrains.jps.model.JpsDummyElement; import org.jetbrains.jps.model.JpsElementFactory; import org.jetbrains.jps.model.JpsModel; @@ -41,18 +43,62 @@ import java.util.Set; * @author nik */ public abstract class JpsBuildTestCase extends UsefulTestCase { - protected JpsProject myJpsProject; + private File myProjectDir; + protected JpsProject myProject; protected JpsModel myModel; + private JpsSdk myJdk; private File myDataStorageRoot; @Override protected void setUp() throws Exception { super.setUp(); myModel = JpsElementFactory.getInstance().createModel(); - myJpsProject = myModel.getProject(); + myProject = myModel.getProject(); myDataStorageRoot = FileUtil.createTempDirectory("compile-server-" + getProjectName(), null); } + @Override + protected void tearDown() throws Exception { + myProjectDir = null; + super.tearDown(); + } + + protected static void assertOutput(final String outputPath, TestFileSystemBuilder expected) { + expected.build().assertDirectoryEqual(new File(FileUtil.toSystemDependentName(outputPath))); + } + + protected static void assertOutput(JpsModule module, TestFileSystemBuilder expected) { + String outputUrl = JpsJavaExtensionService.getInstance().getOutputUrl(module, false); + assertNotNull(outputUrl); + assertOutput(JpsPathUtil.urlToPath(outputUrl), expected); + } + + protected static void change(String filePath) { + change(filePath, null); + } + + protected static void change(String filePath, final @Nullable String newContent) { + try { + File file = new File(FileUtil.toSystemDependentName(filePath)); + assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists()); + if (newContent != null) { + FileUtil.writeToFile(file, newContent); + } + boolean updated = file.setLastModified(FileSystemUtil.lastModified(file) + Utils.TIMESTAMP_ACCURACY); + assertTrue("Cannot modify timestamp for " + file.getAbsolutePath(), updated); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + protected static void delete(String filePath) { + File file = new File(FileUtil.toSystemDependentName(filePath)); + assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists()); + final boolean deleted = FileUtil.delete(file); + assertTrue("Cannot delete file " + file.getAbsolutePath(), deleted); + } + protected JpsSdk addJdk(final String name) { try { return addJdk(name, FileUtil.toSystemIndependentName(ClasspathBootstrap.getResourcePath(Object.class).getCanonicalPath())); @@ -101,7 +147,7 @@ public abstract class JpsBuildTestCase extends UsefulTestCase { String testDataRootPath = getTestDataRootPath(); String fullProjectPath = FileUtil.toSystemDependentName(testDataRootPath != null ? testDataRootPath + "/" + projectPath : projectPath); pathVariables = addPathVariables(pathVariables); - JpsProjectLoader.loadProject(myJpsProject, pathVariables, fullProjectPath); + JpsProjectLoader.loadProject(myProject, pathVariables, fullProjectPath); } catch (IOException e) { throw new RuntimeException(e); @@ -121,7 +167,7 @@ public abstract class JpsBuildTestCase extends UsefulTestCase { String[] srcPaths, @Nullable final String outputPath, final JpsSdk jdk) { - final JpsModule module = myJpsProject.addModule(moduleName, JpsJavaModuleType.INSTANCE); + final JpsModule module = myProject.addModule(moduleName, JpsJavaModuleType.INSTANCE); module.getSdkReferencesTable().setSdkReference(JpsJavaSdkType.INSTANCE, jdk.createReference()); module.getDependenciesList().addSdkDependency(JpsJavaSdkType.INSTANCE); if (srcPaths.length > 0) { @@ -164,4 +210,52 @@ public abstract class JpsBuildTestCase extends UsefulTestCase { } return result; } + + protected String createFile(String relativePath) { + return createFile(relativePath, ""); + } + + protected String createFile(String relativePath, final String text) { + try { + File file = new File(getOrCreateProjectDir(), relativePath); + FileUtil.writeToFile(file, text); + return FileUtil.toSystemIndependentName(file.getAbsolutePath()); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + private File getOrCreateProjectDir() { + if (myProjectDir == null) { + try { + myProjectDir = doGetProjectDir(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + return myProjectDir; + } + + protected File doGetProjectDir() throws IOException { + return FileUtil.createTempDirectory("prj", null); + } + + protected String getAbsolutePath(final String pathRelativeToProjectRoot) { + return FileUtil.toSystemIndependentName(new File(getOrCreateProjectDir(), pathRelativeToProjectRoot).getAbsolutePath()); + } + + protected JpsModule addModule(String moduleName, String... srcPaths) { + if (myJdk == null) { + myJdk = addJdk("1.6"); + } + return addModule(moduleName, srcPaths, getAbsolutePath("out/production/" + moduleName), myJdk); + } + + protected String getProjectRelativePath(String path) { + assertNotNull(myProjectDir); + final String projectDir = FileUtil.toSystemIndependentName(myProjectDir.getAbsolutePath()); + return FileUtil.getRelativePath(projectDir, path, '/'); + } } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy index de82d179febd..d5520c42f2f5 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy @@ -50,17 +50,17 @@ public class ModuleClasspathTest extends JpsRebuildTestCase { } private ProjectPaths getProjectPaths() { - return new ProjectPaths(myJpsProject) + return new ProjectPaths(myProject) } private def assertClasspath(String moduleName, boolean includeTests, List expected) { ModuleChunk chunk = createChunk(moduleName) - final List classpath = getPathsList(new ProjectPaths(myJpsProject).getCompilationClasspathFiles(chunk, includeTests, true, true)) + final List classpath = getPathsList(new ProjectPaths(myProject).getCompilationClasspathFiles(chunk, includeTests, true, true)) assertClasspath(expected, toSystemIndependentPaths(classpath)) } private ModuleChunk createChunk(String moduleName) { - def module = myJpsProject.modules.find {it.name == moduleName} + def module = myProject.modules.find {it.name == moduleName} return new ModuleChunk([new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION)] as Set) } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/rebuild/JpsRebuildTestCase.groovy b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/rebuild/JpsRebuildTestCase.groovy index d1e17a768062..5bdd0854bb4a 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/rebuild/JpsRebuildTestCase.groovy +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/rebuild/JpsRebuildTestCase.groovy @@ -38,7 +38,7 @@ abstract class JpsRebuildTestCase extends JpsBuildTestCase { } protected void rebuild() { - JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(myJpsProject).outputUrl = JpsPathUtil.pathToUrl(FileUtil.toSystemIndependentName(getOrCreateOutputDirectory().getAbsolutePath())) + JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(myProject).outputUrl = JpsPathUtil.pathToUrl(FileUtil.toSystemIndependentName(getOrCreateOutputDirectory().getAbsolutePath())) doRebuild() } diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/resources/ResourceCopyingTest.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/resources/ResourceCopyingTest.java new file mode 100644 index 000000000000..a4eca58617fe --- /dev/null +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/resources/ResourceCopyingTest.java @@ -0,0 +1,41 @@ +package org.jetbrains.jps.builders.resources; + +import com.intellij.util.PathUtil; +import org.jetbrains.jps.builders.JpsBuildTestCase; +import org.jetbrains.jps.model.JpsSimpleElement; +import org.jetbrains.jps.model.java.JavaSourceRootProperties; +import org.jetbrains.jps.model.java.JavaSourceRootType; +import org.jetbrains.jps.model.java.JpsJavaExtensionService; +import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.model.module.JpsModuleSourceRoot; +import org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot; + +import static com.intellij.util.io.TestFileSystemItem.fs; + +/** + * @author nik + */ +public class ResourceCopyingTest extends JpsBuildTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myProject).addResourcePattern("*.xml"); + } + + public void testSimple() { + String file = createFile("src/a.xml"); + JpsModule m = addModule("m", PathUtil.getParentPath(file)); + doRebuild(); + assertOutput(m, fs().file("a.xml")); + } + public void testPackagePrefix() { + String file = createFile("src/a.xml"); + JpsModule m = addModule("m", PathUtil.getParentPath(file)); + JpsModuleSourceRoot sourceRoot = assertOneElement(m.getSourceRoots()); + JpsTypedModuleSourceRoot> typed = sourceRoot.asTyped(JavaSourceRootType.SOURCE); + assertNotNull(typed); + typed.getProperties().setData(new JavaSourceRootProperties("xxx")); + doRebuild(); + assertOutput(m, fs().dir("xxx").file("a.xml")); + } +} diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/util/FileSystemItem.groovy b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/util/FileSystemItem.groovy deleted file mode 100644 index 5604e16b4620..000000000000 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/util/FileSystemItem.groovy +++ /dev/null @@ -1,51 +0,0 @@ -package org.jetbrains.jps.builders.util - -import com.intellij.openapi.util.io.FileUtil -import com.intellij.util.io.ZipUtil -import junit.framework.Assert - -/** - * @author nik - */ -class FileSystemItem { - boolean directory = false - boolean archive = false - String name - String content = null - private final Map children = [:] - - FileSystemItem leftShift(FileSystemItem item) { - assert !children.containsKey(item.getName()) : "${item.name} already added" - children[item.name] = item - return this - } - - def assertDirectoryEqual(File file, String relativePath) throws IOException { - Set notFound = new HashSet(children.keySet()); - file.listFiles()?.each {File child -> - final def name = child.name - final def item = children[name] - Assert.assertNotNull("unexpected file: $relativePath$name", item) - item.assertFileEqual(child, relativePath + name + "/") - notFound.remove(name) - } - Assert.assertTrue("files $notFound not found in $relativePath", notFound.isEmpty()); - } - - def assertFileEqual(File file, String relativePath) throws IOException { - Assert.assertEquals("in $relativePath", name, file.name); - if (archive) { - final File dirForExtracted = FileUtil.createTempDirectory("extracted_archive", ""); - ZipUtil.extract(file, dirForExtracted, null); - assertDirectoryEqual(dirForExtracted, relativePath); - } - else if (directory) { - Assert.assertTrue("$relativePath${file.name} is not a directory", file.isDirectory()); - assertDirectoryEqual(file, relativePath); - } - else if (content != null) { - final String actualContent = FileUtil.loadFile(file); - Assert.assertEquals("content mismatch for " + relativePath, content, actualContent); - } - } -} diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/util/TempFiles.java b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/util/TempFiles.java deleted file mode 100644 index 15dce4a18391..000000000000 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/util/TempFiles.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.jetbrains.jps.builders.util; - -import com.intellij.openapi.util.io.FileUtil; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -/** - * @author Pavel.Sher - * Date: 05.03.2008 - */ -public class TempFiles { - private static final File ourCurrentTempDir = new File(System.getProperty("java.io.tmpdir")); - private final File myCurrentTempDir; - - private static Random ourRandom; - - static { - ourRandom = new Random(); - ourRandom.setSeed(System.currentTimeMillis()); - } - - private final List myFilesToDelete = new ArrayList(); - - public TempFiles() { - myCurrentTempDir = ourCurrentTempDir; - if (!myCurrentTempDir.isDirectory()) { - throw new IllegalStateException("Temp directory is not a directory, was deleted by some process: " + myCurrentTempDir.getAbsolutePath()); - } - } - - private File doCreateTempDir(String prefix, String suffix) throws IOException { - prefix = prefix == null ? "" : prefix; - suffix = suffix == null ? ".tmp" : suffix; - - do { - int count = ourRandom.nextInt(); - final File f = new File(myCurrentTempDir, prefix + count + suffix); - if (!f.exists() && f.mkdirs()) { - return f.getCanonicalFile(); - } - } while (true); - } - - private File doCreateTempFile(String prefix, String suffix) throws IOException { - final File file = doCreateTempDir(prefix, suffix); - file.delete(); - file.createNewFile(); - return file; - } - - public final File createTempFile() throws IOException { - File tempFile = doCreateTempFile("test", null); - registerAsTempFile(tempFile); - return tempFile; - } - - private void registerAsTempFile(final File tempFile) { - myFilesToDelete.add(tempFile); - } - - /** - * Returns a File object for created temp directory. - * - * @return a File object for created temp directory - * @throws IOException if directory creation fails. - */ - public final File createTempDir() throws IOException { - File f = doCreateTempDir("test", ""); - registerAsTempFile(f); - return f; - } - - public void cleanup() { - for (File file : myFilesToDelete) { - if (file.exists()) { - FileUtil.delete(file); - } - } - myFilesToDelete.clear(); - } -} diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/incremental/artifacts/ArtifactBuilderTestCase.java b/jps/jps-builders/testSrc/org/jetbrains/jps/incremental/artifacts/ArtifactBuilderTestCase.java index ab87c94f34e5..54e91b64ada1 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/incremental/artifacts/ArtifactBuilderTestCase.java +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/incremental/artifacts/ArtifactBuilderTestCase.java @@ -16,11 +16,9 @@ package org.jetbrains.jps.incremental.artifacts; import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.util.io.FileSystemUtil; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.io.TestFileSystemBuilder; import com.intellij.util.text.UniqueNameGenerator; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.JpsPathUtil; import org.jetbrains.jps.builders.BuildResult; import org.jetbrains.jps.builders.BuildTarget; @@ -30,9 +28,7 @@ import org.jetbrains.jps.cmdline.ProjectDescriptor; import org.jetbrains.jps.incremental.BuildLoggingManager; import org.jetbrains.jps.incremental.CompileScope; import org.jetbrains.jps.incremental.CompileScopeImpl; -import org.jetbrains.jps.incremental.Utils; import org.jetbrains.jps.incremental.java.JavaBuilderLoggerImpl; -import org.jetbrains.jps.model.JpsDummyElement; import org.jetbrains.jps.model.JpsElementFactory; import org.jetbrains.jps.model.artifact.DirectoryArtifactType; import org.jetbrains.jps.model.artifact.JpsArtifact; @@ -40,8 +36,6 @@ import org.jetbrains.jps.model.artifact.JpsArtifactService; import org.jetbrains.jps.model.java.JpsJavaLibraryType; import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.library.JpsOrderRootType; -import org.jetbrains.jps.model.library.sdk.JpsSdk; -import org.jetbrains.jps.model.module.JpsModule; import java.io.File; import java.io.IOException; @@ -53,9 +47,7 @@ import static com.intellij.util.io.TestFileSystemItem.fs; * @author nik */ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase { - private File myProjectDir; private TestArtifactBuilderLogger myArtifactBuilderLogger; - private JpsSdk myJdk; protected void setUp() throws Exception { super.setUp(); @@ -64,31 +56,15 @@ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase { @Override protected void tearDown() throws Exception { - for (JpsArtifact artifact : JpsArtifactService.getInstance().getArtifacts(myJpsProject)) { + for (JpsArtifact artifact : JpsArtifactService.getInstance().getArtifacts(myProject)) { String outputPath = artifact.getOutputPath(); if (outputPath != null) { FileUtil.delete(new File(FileUtil.toSystemDependentName(outputPath))); } } - myProjectDir = null; super.tearDown(); } - protected String createFile(String relativePath) { - return createFile(relativePath, ""); - } - - protected String createFile(String relativePath, final String text) { - try { - File file = new File(getOrCreateProjectDir(), relativePath); - FileUtil.writeToFile(file, text); - return FileUtil.toSystemIndependentName(file.getAbsolutePath()); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - protected JpsArtifact addArtifact(LayoutElementTestUtil.LayoutElementCreator root) { Set usedNames = getArtifactNames(); final String name = UniqueNameGenerator.generateUniqueName("a", usedNames); @@ -97,51 +73,28 @@ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase { private Set getArtifactNames() { Set usedNames = new HashSet(); - for (JpsArtifact artifact : JpsArtifactService.getInstance().getArtifacts(myJpsProject)) { + for (JpsArtifact artifact : JpsArtifactService.getInstance().getArtifacts(myProject)) { usedNames.add(artifact.getName()); } return usedNames; } - private File getOrCreateProjectDir() { - if (myProjectDir == null) { - try { - myProjectDir = FileUtil.createTempDirectory("prj", null); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - return myProjectDir; - } - protected JpsArtifact addArtifact(String name, LayoutElementTestUtil.LayoutElementCreator root) { assertFalse("JpsArtifact " + name + " already exists", getArtifactNames().contains(name)); - JpsArtifact artifact = JpsArtifactService.getInstance().addArtifact(myJpsProject, name, root.buildElement(), DirectoryArtifactType.INSTANCE, + JpsArtifact artifact = JpsArtifactService.getInstance().addArtifact(myProject, name, root.buildElement(), DirectoryArtifactType.INSTANCE, JpsElementFactory.getInstance().createDummyElement()); artifact.setOutputPath(getAbsolutePath("out/artifacts/" + name)); return artifact; } - private String getAbsolutePath(final String pathRelativeToProjectRoot) { - return FileUtil.toSystemIndependentName(new File(getOrCreateProjectDir(), pathRelativeToProjectRoot).getAbsolutePath()); - } - - protected JpsModule addModule(String moduleName, String... srcPaths) { - if (myJdk == null) { - myJdk = addJdk("1.6"); - } - return addModule(moduleName, srcPaths, getAbsolutePath("out/production/" + moduleName), myJdk); - } - protected JpsLibrary addProjectLibrary(String name, String jarPath) { - final JpsLibrary library = myJpsProject.getLibraryCollection().addLibrary(name, JpsJavaLibraryType.INSTANCE); + final JpsLibrary library = myProject.getLibraryCollection().addLibrary(name, JpsJavaLibraryType.INSTANCE); library.addRoot(JpsPathUtil.pathToUrl(jarPath), JpsOrderRootType.COMPILED); return library; } protected void buildAll() { - Collection artifacts = JpsArtifactService.getInstance().getArtifacts(myJpsProject); + Collection artifacts = JpsArtifactService.getInstance().getArtifacts(myProject); buildArtifacts(artifacts.toArray(new JpsArtifact[artifacts.size()])); } @@ -182,32 +135,6 @@ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase { doBuild(false, a).assertFailed(); } - protected static void change(String filePath) { - change(filePath, null); - } - - protected static void change(String filePath, final @Nullable String newContent) { - try { - File file = new File(FileUtil.toSystemDependentName(filePath)); - assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists()); - if (newContent != null) { - FileUtil.writeToFile(file, newContent); - } - boolean updated = file.setLastModified(FileSystemUtil.lastModified(file) + Utils.TIMESTAMP_ACCURACY); - assertTrue("Cannot modify timestamp for " + file.getAbsolutePath(), updated); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - protected static void delete(String filePath) { - File file = new File(FileUtil.toSystemDependentName(filePath)); - assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists()); - final boolean deleted = FileUtil.delete(file); - assertTrue("Cannot delete file " + file.getAbsolutePath(), deleted); - } - protected void assertCopied(String... filePaths) { assertSameElements(myArtifactBuilderLogger.myCopiedFilePaths, filePaths); assertEmpty(myArtifactBuilderLogger.myDeletedFilePaths); @@ -226,10 +153,6 @@ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase { assertOutput(a.getOutputPath(), expected); } - protected static void assertOutput(final String outputPath, TestFileSystemBuilder expected) { - expected.build().assertDirectoryEqual(new File(FileUtil.toSystemDependentName(outputPath))); - } - protected void assertDeleted(String... filePaths) { assertSameElements(myArtifactBuilderLogger.myDeletedFilePaths, filePaths); assertEmpty(myArtifactBuilderLogger.myCopiedFilePaths); @@ -245,12 +168,6 @@ public abstract class ArtifactBuilderTestCase extends JpsBuildTestCase { assertEmpty(myArtifactBuilderLogger.myCopiedFilePaths); } - private String getProjectRelativePath(String path) { - assertNotNull(myProjectDir); - final String projectDir = FileUtil.toSystemIndependentName(myProjectDir.getAbsolutePath()); - return FileUtil.getRelativePath(projectDir, path, '/'); - } - protected static void rename(String path, String newName) { try { File file = new File(FileUtil.toSystemDependentName(path)); diff --git a/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaExtensionService.java b/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaExtensionService.java index 48b54edce03f..8484a678ebfa 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaExtensionService.java +++ b/jps/model-api/src/org/jetbrains/jps/model/java/JpsJavaExtensionService.java @@ -83,9 +83,6 @@ public abstract class JpsJavaExtensionService { @Nullable public abstract File getOutputDirectory(JpsModule module, boolean forTests); - @Nullable - public abstract String getSourcePrefix(JpsModule module, String rootUrl); - public abstract JpsTypedLibrary> addJavaSdk(@NotNull JpsGlobal global, @NotNull String name, @NotNull String homePath); diff --git a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java index eb050b145d8a..8e2fdb1f2a7c 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java +++ b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModule.java @@ -25,6 +25,10 @@ public interface JpsModule extends JpsNamedElement, JpsReferenceableElement getSourceRoots(); + @NotNull +

+ Iterable> getSourceRoots(@NotNull JpsModuleSourceRootType

type); + @NotNull

& JpsElementTypeWithDefaultProperties

> JpsModuleSourceRoot addSourceRoot(@NotNull String url, @NotNull Type rootType); diff --git a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRoot.java b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRoot.java index 8695702c8a64..ff3d5abda4a5 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRoot.java +++ b/jps/model-api/src/org/jetbrains/jps/model/module/JpsModuleSourceRoot.java @@ -16,6 +16,9 @@ public interface JpsModuleSourceRoot extends JpsElement { @Nullable

P getProperties(@NotNull JpsModuleSourceRootType

type); + @Nullable +

JpsTypedModuleSourceRoot

asTyped(@NotNull JpsModuleSourceRootType

type); + @NotNull JpsElement getProperties(); diff --git a/jps/model-api/src/org/jetbrains/jps/model/module/JpsTypedModuleSourceRoot.java b/jps/model-api/src/org/jetbrains/jps/model/module/JpsTypedModuleSourceRoot.java new file mode 100644 index 000000000000..f428bc5c642e --- /dev/null +++ b/jps/model-api/src/org/jetbrains/jps/model/module/JpsTypedModuleSourceRoot.java @@ -0,0 +1,18 @@ +package org.jetbrains.jps.model.module; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.JpsElement; +import org.jetbrains.jps.model.JpsTypedElement; + +/** + * @author nik + */ +public interface JpsTypedModuleSourceRoot

extends JpsModuleSourceRoot, JpsTypedElement

{ + @NotNull + @Override + P getProperties(); + + @NotNull + @Override + JpsModuleSourceRootType

getRootType(); +} diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java index 323a0b1e34fc..52f144b29d56 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JpsJavaExtensionServiceImpl.java @@ -7,7 +7,6 @@ import org.jetbrains.jps.JpsPathUtil; import org.jetbrains.jps.model.JpsDummyElement; import org.jetbrains.jps.model.JpsGlobal; import org.jetbrains.jps.model.JpsProject; -import org.jetbrains.jps.model.JpsSimpleElement; import org.jetbrains.jps.model.java.*; import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration; import org.jetbrains.jps.model.java.impl.compiler.JpsJavaCompilerConfigurationImpl; @@ -118,22 +117,6 @@ public class JpsJavaExtensionServiceImpl extends JpsJavaExtensionService { return url != null ? JpsPathUtil.urlToFile(url) : null; } - @Override - public String getSourcePrefix(JpsModule module, String rootUrl) { - for (JpsModuleSourceRoot root : module.getSourceRoots()) { - if (root.getUrl().equals(rootUrl)) { - JpsModuleSourceRootType type = root.getRootType(); - if (type instanceof JavaSourceRootType) { - final JpsSimpleElement properties = root.getProperties((JavaSourceRootType)type); - if (properties != null) { - return properties.getData().getPackagePrefix(); - } - } - } - } - return null; - } - @Override public JpsTypedLibrary> addJavaSdk(@NotNull JpsGlobal global, @NotNull String name, @NotNull String homePath) { String version = JdkVersionDetector.getInstance().detectJdkVersion(homePath); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java index 76d2aedf5bbd..1346467b912c 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleImpl.java @@ -90,6 +90,12 @@ public class JpsModuleImpl

extends JpsNamedCompositeElemen return myContainer.getChild(JpsModuleSourceRootRole.ROOT_COLLECTION_ROLE).getElements(); } + @NotNull + @Override + public

Iterable> getSourceRoots(@NotNull JpsModuleSourceRootType

type) { + return myContainer.getChild(JpsModuleSourceRootRole.ROOT_COLLECTION_ROLE).getElementsOfType(type); + } + @NotNull @Override public

& JpsElementTypeWithDefaultProperties

> diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootImpl.java index 4f4a5c018133..331bb24d3c97 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsModuleSourceRootImpl.java @@ -1,18 +1,20 @@ package org.jetbrains.jps.model.module.impl; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.JpsPathUtil; import org.jetbrains.jps.model.JpsElement; +import org.jetbrains.jps.model.JpsElementType; import org.jetbrains.jps.model.impl.JpsCompositeElementBase; -import org.jetbrains.jps.model.module.JpsModuleSourceRoot; import org.jetbrains.jps.model.module.JpsModuleSourceRootType; +import org.jetbrains.jps.model.module.JpsTypedModuleSourceRoot; import java.io.File; /** * @author nik */ -public class JpsModuleSourceRootImpl

extends JpsCompositeElementBase> implements JpsModuleSourceRoot { +public class JpsModuleSourceRootImpl

extends JpsCompositeElementBase> implements JpsTypedModuleSourceRoot

{ private final JpsModuleSourceRootType

myRootType; private final String myUrl; @@ -38,6 +40,18 @@ public class JpsModuleSourceRootImpl

extends JpsCompositeE return null; } + @Nullable + @Override + public

JpsTypedModuleSourceRoot

asTyped(@NotNull JpsModuleSourceRootType

type) { + //noinspection unchecked + return myRootType.equals(type) ? (JpsTypedModuleSourceRoot

)this : null; + } + + @Override + public JpsElementType getType() { + return myRootType; + } + @NotNull @Override public P getProperties() { @@ -46,7 +60,7 @@ public class JpsModuleSourceRootImpl

extends JpsCompositeE @NotNull @Override - public JpsModuleSourceRootType getRootType() { + public JpsModuleSourceRootType

getRootType() { return myRootType; } diff --git a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java index 8a1f7ef6f99f..7ea19d044e09 100644 --- a/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java +++ b/jps/model-impl/testSrc/org/jetbrains/jps/model/JpsModuleTest.java @@ -1,6 +1,7 @@ package org.jetbrains.jps.model; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.jps.model.java.*; import org.jetbrains.jps.model.library.JpsLibrary; import org.jetbrains.jps.model.library.sdk.JpsSdk; @@ -23,9 +24,11 @@ public class JpsModuleTest extends JpsModelTestCase { final JpsModuleSourceRoot root = assertOneElement(module.getSourceRoots()); assertEquals("file://url", root.getUrl()); - final JpsSimpleElement properties2 = root.getProperties(JavaSourceRootType.SOURCE); - assertNotNull(properties2); - assertEquals("com.xxx", properties2.getData().getPackagePrefix()); + assertSameElements(ContainerUtilRt.newArrayList(module.getSourceRoots(JavaSourceRootType.SOURCE)), root); + assertEmpty(ContainerUtil.newArrayList(module.getSourceRoots(JavaSourceRootType.TEST_SOURCE))); + JpsTypedModuleSourceRoot> typedRoot = root.asTyped(JavaSourceRootType.SOURCE); + assertNotNull(typedRoot); + assertEquals("com.xxx", typedRoot.getProperties().getData().getPackagePrefix()); } public void testGetModulesOfType() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java index 65b87eb8a1da..9ca465e44cf0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java @@ -95,7 +95,12 @@ public class CompletionLookupArranger extends LookupArranger { } private MultiMap groupItemsBySorter(List source) { - MultiMap inputBySorter = new MultiMap(); + MultiMap inputBySorter = new MultiMap() { + @Override + protected Map> createMap() { + return ContainerUtil.newLinkedHashMap(); + } + }; for (LookupElement element : source) { inputBySorter.putValue(obtainSorter(element), element); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCharFilter.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCharFilter.java index 20c02c3a66c1..966912e3d330 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCharFilter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateCharFilter.java @@ -34,6 +34,10 @@ public class LiveTemplateCharFilter extends CharFilter { } return Result.HIDE_LOOKUP; } + if (item instanceof TemplateExpressionLookupElement) { + if (Character.isJavaIdentifierPart(c)) return Result.ADD_TO_PREFIX; + return Result.HIDE_LOOKUP; + } return null; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java index 29eff09ae690..5aa90f415713 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java @@ -98,17 +98,21 @@ public class LiveTemplateSettingsEditor extends JPanel { myTemplate.setId(null); createComponents(allowNoContext); - - com.intellij.ui.DocumentAdapter listener = new com.intellij.ui.DocumentAdapter() { + + myKeyField.getDocument().addDocumentListener(new com.intellij.ui.DocumentAdapter() { @Override protected void textChanged(javax.swing.event.DocumentEvent e) { myTemplate.setKey(myKeyField.getText().trim()); + nodeChanged.run(); + } + }); + myDescription.getDocument().addDocumentListener(new com.intellij.ui.DocumentAdapter() { + @Override + protected void textChanged(javax.swing.event.DocumentEvent e) { myTemplate.setDescription(myDescription.getText().trim()); nodeChanged.run(); } - }; - myKeyField.getDocument().addDocumentListener(listener); - myDescription.getDocument().addDocumentListener(listener); + }); new UiNotifyConnector(this, new Activatable.Adapter() { @Override @@ -474,7 +478,7 @@ public class LiveTemplateSettingsEditor extends JPanel { myEditVariablesButton.setEnabled(!parseVariables(myTemplateEditor.getDocument().getCharsSequence()).isEmpty()); } - private void reset() { + void resetUi() { myKeyField.setText(myTemplate.getKey()); myDescription.setText(myTemplate.getDescription()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateExpressionLookupElement.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateExpressionLookupElement.java new file mode 100644 index 000000000000..c82c2af7e1a0 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateExpressionLookupElement.java @@ -0,0 +1,97 @@ +/* + * 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. + * 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.codeInsight.template.impl; + +import com.intellij.codeInsight.AutoPopupController; +import com.intellij.codeInsight.completion.CompletionInitializationContext; +import com.intellij.codeInsight.completion.InsertionContext; +import com.intellij.codeInsight.completion.OffsetMap; +import com.intellij.codeInsight.completion.PrioritizedLookupElement; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupElementDecorator; +import com.intellij.codeInsight.lookup.LookupItem; +import com.intellij.codeInsight.template.TemplateLookupSelectionHandler; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorModificationUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiFile; + +import java.util.List; + +/** +* @author peter +*/ +class TemplateExpressionLookupElement extends LookupElementDecorator { + private TemplateState myState; + + public TemplateExpressionLookupElement(final TemplateState state, LookupElement element, int index) { + super(PrioritizedLookupElement.withPriority(element, Integer.MAX_VALUE - 10 - index)); + myState = state; + } + + private static InsertionContext createInsertionContext(LookupElement item, + PsiFile psiFile, + List elements, + Editor editor) { + final OffsetMap offsetMap = new OffsetMap(editor.getDocument()); + final InsertionContext context = new InsertionContext(offsetMap, (char)0, elements.toArray(new LookupElement[elements.size()]), psiFile, editor, false); + context.setTailOffset(editor.getCaretModel().getOffset()); + offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, context.getTailOffset() - item.getLookupString().length()); + offsetMap.addOffset(CompletionInitializationContext.SELECTION_END_OFFSET, context.getTailOffset()); + offsetMap.addOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET, context.getTailOffset()); + return context; + } + + void handleTemplateInsert(List elements) { + InsertionContext context = createInsertionContext(this, myState.getPsiFile(), elements, myState.getEditor()); + handleInsert(context); + Disposer.dispose(context.getOffsetMap()); + } + + @Override + public void handleInsert(InsertionContext context) { + LookupElement item = getDelegate(); + Project project = context.getProject(); + Editor editor = context.getEditor(); + + PsiDocumentManager.getInstance(project).commitAllDocuments(); + + TextRange range = myState.getCurrentVariableRange(); + final TemplateLookupSelectionHandler handler = + item instanceof LookupItem ? ((LookupItem)item).getAttribute(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM) : null; + if (handler != null && range != null) { + handler.itemSelected(item, context.getFile(), context.getDocument(), range.getStartOffset(), range.getEndOffset()); + } + else { + super.handleInsert(context); + } + + if (context.getCompletionChar() == '.') { + EditorModificationUtil.insertStringAtCaret(editor, "."); + AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null); + return; + } + + if (!myState.isFinished()) { + myState.calcResults(true); + } + + myState.nextTab(); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java index 5c7b97cfde76..0607ef24cf1a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java @@ -892,6 +892,7 @@ public class TemplateListPanel extends JPanel implements Disposable { } createTemplateEditor(newTemplate, (String)myExpandByCombo.getSelectedItem(), getTemplateOptions(newTemplate), getTemplateContext(newTemplate)); + myCurrentTemplateEditor.resetUi(); if (focusKey) { myCurrentTemplateEditor.focusKey(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java index 2ee637c7a880..968a10b8057a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java @@ -16,12 +16,11 @@ package com.intellij.codeInsight.template.impl; -import com.intellij.codeInsight.AutoPopupController; import com.intellij.codeInsight.CodeInsightSettings; -import com.intellij.codeInsight.completion.CompletionInitializationContext; -import com.intellij.codeInsight.completion.InsertionContext; -import com.intellij.codeInsight.completion.OffsetMap; -import com.intellij.codeInsight.lookup.*; +import com.intellij.codeInsight.lookup.LookupAdapter; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupEvent; +import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.codeInsight.template.*; import com.intellij.lang.LanguageLiteralEscapers; @@ -31,7 +30,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandAdapter; import com.intellij.openapi.command.CommandEvent; import com.intellij.openapi.command.CommandProcessor; -import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.command.undo.BasicUndoableAction; import com.intellij.openapi.command.undo.DocumentReference; import com.intellij.openapi.command.undo.DocumentReferenceManager; @@ -44,7 +42,6 @@ import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; @@ -57,6 +54,7 @@ import com.intellij.psi.util.PsiUtilBase; import com.intellij.refactoring.rename.inplace.InplaceRefactoring; import com.intellij.util.IncorrectOperationException; import com.intellij.util.PairProcessor; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; import com.intellij.util.containers.IntArrayList; import org.jetbrains.annotations.NonNls; @@ -313,7 +311,7 @@ public class TemplateState implements Disposable { myTemplateRange = myDocument.createRangeMarker(caretOffset, caretOffset + template.getTemplateText().length()); } else { - PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); + PsiFile file = getPsiFile(); preprocessTemplate(file, myEditor.getCaretModel().getOffset(), myTemplate.getTemplateText()); int caretOffset = myEditor.getCaretModel().getOffset(); myTemplateRange = myDocument.createRangeMarker(caretOffset, caretOffset); @@ -402,7 +400,7 @@ public class TemplateState implements Disposable { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); + final PsiFile file = getPsiFile(); if (file != null) { IntArrayList indices = initEmptyVariables(); mySegments.setSegmentsGreedy(false); @@ -486,26 +484,23 @@ public class TemplateState implements Disposable { myEditor.getSelectionModel().setSelection(start, end); } - Expression expressionNode = myTemplate.getExpressionAt(myCurrentVariableNumber); - final ExpressionContext context = createExpressionContext(start); - final LookupElement[] lookupItems = expressionNode.calculateLookupItems(context); - final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); - if (lookupItems != null && lookupItems.length > 0) { + Expression expressionNode = getCurrentExpression(); + final List lookupItems = getCurrentExpressionLookupItems(); + final PsiFile psiFile = getPsiFile(); + if (!lookupItems.isEmpty()) { if (((TemplateManagerImpl)TemplateManager.getInstance(myProject)).shouldSkipInTests()) { - final String s = lookupItems[0].getLookupString(); - EditorModificationUtil.insertStringAtCaret(myEditor, s); - itemSelected(lookupItems[0], psiFile, currentSegmentNumber, ' ', lookupItems); + insertSingleItem(lookupItems); } else { for (LookupElement lookupItem : lookupItems) { assert lookupItem != null : expressionNode; } - runLookup(currentSegmentNumber, lookupItems, expressionNode.getAdvertisingText(), psiFile); + runLookup(lookupItems, expressionNode.getAdvertisingText()); } } else { - Result result = expressionNode.calculateResult(context); + Result result = expressionNode.calculateResult(getCurrentExpressionContext()); if (result != null) { result.handleFocused(psiFile, myDocument, mySegments.getSegmentStart(currentSegmentNumber), mySegments.getSegmentEnd(currentSegmentNumber)); @@ -514,12 +509,42 @@ public class TemplateState implements Disposable { focusCurrentHighlighter(true); } - private void runLookup(final int currentSegmentNumber, final LookupElement[] lookupItems, String advertisingText, final PsiFile psiFile) { + PsiFile getPsiFile() { + return PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); + } + + private void insertSingleItem(List lookupItems) { + TemplateExpressionLookupElement first = lookupItems.get(0); + EditorModificationUtil.insertStringAtCaret(myEditor, first.getLookupString()); + first.handleTemplateInsert(lookupItems); + } + + @NotNull + List getCurrentExpressionLookupItems() { + LookupElement[] elements = getCurrentExpression().calculateLookupItems(getCurrentExpressionContext()); + if (elements == null) return Collections.emptyList(); + + List result = ContainerUtil.newArrayList(); + for (int i = 0; i < elements.length; i++) { + result.add(new TemplateExpressionLookupElement(this, elements[i], i)); + } + return result; + } + + ExpressionContext getCurrentExpressionContext() { + return createExpressionContext(mySegments.getSegmentStart(getCurrentSegmentNumber())); + } + + Expression getCurrentExpression() { + return myTemplate.getExpressionAt(myCurrentVariableNumber); + } + + private void runLookup(final List lookupItems, String advertisingText) { if (myEditor == null) return; final LookupManager lookupManager = LookupManager.getInstance(myProject); - final LookupImpl lookup = (LookupImpl)lookupManager.showLookup(myEditor, lookupItems); + final LookupImpl lookup = (LookupImpl)lookupManager.showLookup(myEditor, lookupItems.toArray(new LookupElement[lookupItems.size()])); if (lookup == null) return; if (CodeInsightSettings.getInstance().AUTO_POPUP_COMPLETION_LOOKUP && myEditor.getUserData(InplaceRefactoring.INPLACE_RENAMER) == null) { @@ -542,68 +567,21 @@ public class TemplateState implements Disposable { if (isFinished()) return; ourLookupShown = false; - TemplateState.this.itemSelected(event.getItem(), psiFile, currentSegmentNumber, event.getCompletionChar(), lookupItems); + LookupElement item = event.getItem(); + if (item instanceof TemplateExpressionLookupElement) { + ((TemplateExpressionLookupElement)item).handleTemplateInsert(lookupItems); + } } }); } - private void itemSelected(final LookupElement item, - final PsiFile psiFile, - final int currentSegmentNumber, - final char completionChar, - LookupElement[] elements) { - if (item != null) { - PsiDocumentManager.getInstance(myProject).commitAllDocuments(); - - final OffsetMap offsetMap = new OffsetMap(myDocument); - final InsertionContext context = new InsertionContext(offsetMap, (char)0, elements, psiFile, myEditor, false); - context.setTailOffset(myEditor.getCaretModel().getOffset()); - offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, context.getTailOffset() - item.getLookupString().length()); - offsetMap.addOffset(CompletionInitializationContext.SELECTION_END_OFFSET, context.getTailOffset()); - offsetMap.addOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET, context.getTailOffset()); - - final TemplateLookupSelectionHandler handler = - item instanceof LookupItem ? ((LookupItem)item).getAttribute(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM) : null; - if (handler != null) { - handler.itemSelected(item, psiFile, myDocument, mySegments.getSegmentStart(currentSegmentNumber), - mySegments.getSegmentEnd(currentSegmentNumber)); - } - else { - new WriteCommandAction(myProject) { - @Override - protected void run(com.intellij.openapi.application.Result result) throws Throwable { - item.handleInsert(context); - } - }.execute(); - } - Disposer.dispose(offsetMap); - - if (completionChar == '.') { - EditorModificationUtil.insertStringAtCaret(myEditor, "."); - AutoPopupController.getInstance(myProject).autoPopupMemberLookup(myEditor, null); - return; - } - - if (!isFinished()) { - calcResults(true); - } - } - - new WriteCommandAction(myProject) { - @Override - protected void run(com.intellij.openapi.application.Result result) throws Throwable { - nextTab(); - } - }.execute(); - } - private void unblockDocument() { PsiDocumentManager.getInstance(myProject).commitDocument(myDocument); PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(myDocument); } // Hours spent fixing code : 1 - private void calcResults(final boolean isQuick) { + void calcResults(final boolean isQuick) { if (myProcessor != null && myCurrentVariableNumber >= 0) { final String variableName = myTemplate.getVariableNameAt(myCurrentVariableNumber); final TextResult value = getVariableValue(variableName); @@ -672,7 +650,7 @@ public class TemplateState implements Disposable { int end = mySegments.getSegmentEnd(segmentNumber); PsiDocumentManager.getInstance(myProject).commitDocument(myDocument); - PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); + PsiFile psiFile = getPsiFile(); PsiElement element = psiFile.findElementAt(start); ExpressionContext context = createExpressionContext(start); @@ -1012,7 +990,7 @@ public class TemplateState implements Disposable { } private void reformat(RangeMarker rangeMarkerToReformat) { - final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); + final PsiFile file = getPsiFile(); if (file != null) { CodeStyleManager style = CodeStyleManager.getInstance(myProject); for (TemplateOptionalProcessor optionalProcessor : Extensions.getExtensions(TemplateOptionalProcessor.EP_NAME)) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java index bdb13ea1b78e..df913f1e6dc7 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ExecutionManagerImpl.java @@ -282,7 +282,14 @@ public class ExecutionManagerImpl extends ExecutionManager implements ProjectCom return CommonBundle.message("dialog.options.do.not.show"); } }; - if (Messages.OK != Messages.showOkCancelDialog(ExecutionBundle.message("rerun.confirmation.message", configuration.getName()), + String message; + if (allHandlers.size() == 1 && handler != null) {//we restart single running configuration + message = ExecutionBundle.message("rerun.confirmation.message", configuration.getName()); + } + else { + message = ExecutionBundle.message("rerun.singleton.confirmation.message", configuration.getName()); + } + if (Messages.OK != Messages.showOkCancelDialog(message, ExecutionBundle.message("rerun.confirmation.title") + " (" + pair.getSecond().getId() + diff --git a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/WebProjectTemplate.java b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/WebProjectTemplate.java index 5ed5c2f7830f..cb8b3c7a489d 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/WebProjectTemplate.java +++ b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/WebProjectTemplate.java @@ -43,16 +43,12 @@ public abstract class WebProjectTemplate extends WebProjectGenerator imple } }; - @Override - public void generateProject(Module module) { - generateProject(module.getProject(), module.getProject().getBaseDir(), myPeer.getValue().getSettings(), module); - } - @Override public JComponent getSettingsPanel() { return myPeer.getValue().getComponent(); } + @NotNull @Override public ProjectBuilder createModuleBuilder() { final ModuleBuilder builder = WebModuleType.getInstance().createModuleBuilder(); @@ -62,7 +58,8 @@ public abstract class WebProjectTemplate extends WebProjectGenerator imple public List commit(Project project, ModifiableModuleModel model, ModulesProvider modulesProvider) { List modules = builder.commit(project, model, modulesProvider); if (modules != null && !modules.isEmpty()) { - generateProject(modules.get(0)); + Module module = modules.get(0); + generateProject(module.getProject(), module.getProject().getBaseDir(), myPeer.getValue().getSettings(), module); } return modules; } diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java index 506d9de50c47..0ce108c3906b 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java @@ -17,7 +17,6 @@ package com.intellij.openapi.projectRoots.impl; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.PathChooserDialog; @@ -33,11 +32,6 @@ import com.intellij.openapi.projectRoots.SdkType; import com.intellij.openapi.roots.ModuleRootModificationUtil; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.ui.popup.ListPopup; -import com.intellij.openapi.ui.popup.ListPopupStep; -import com.intellij.openapi.ui.popup.PopupStep; -import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; @@ -48,7 +42,6 @@ import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.util.*; /** @@ -166,7 +159,7 @@ public class SdkConfigurationUtil { e.getMessage() + ".\nPlease make sure that " + FileUtil.toSystemDependentName(homeDir.getPath()) + - " is a valid home path for this SDK type.", "Error configuring SDK"); + " is a valid home path for this SDK type.", "Error Configuring SDK"); } return null; } @@ -298,65 +291,6 @@ public class SdkConfigurationUtil { return LocalFileSystem.getInstance().findFileByPath(homepath); } - public static void suggestAndAddSdk(@Nullable final Project project, - final Sdk[] existingSdks, - JComponent popupOwner, - final Consumer callback, - final SdkType... sdkTypes) { - assert sdkTypes.length > 0; - final Map suggestedSdkHomes = new LinkedHashMap(); - for (SdkType sdkType : sdkTypes) { - final Collection sdkHomes = sdkType.suggestHomePaths(); - for (String sdkHome : filterExistingPaths(sdkType, sdkHomes, existingSdks)) { - suggestedSdkHomes.put(sdkHome, sdkType); - } - } - if (suggestedSdkHomes.size() > 0) { - suggestedSdkHomes.put(null, sdkTypes[0]); - showSuggestedHomesPopup(project, existingSdks, suggestedSdkHomes, sdkTypes, popupOwner, callback); - } - else { - createSdk(project, existingSdks, callback, sdkTypes); - } - } - - private static void showSuggestedHomesPopup(@Nullable final Project project, - final Sdk[] existingSdks, - final Map suggestedSdkHomes, - final SdkType[] sdkTypes, - final JComponent popupOwner, - final Consumer callback) { - final List list = new ArrayList(suggestedSdkHomes.keySet()); - ListPopupStep sdkHomesStep = new BaseListPopupStep("Select Interpreter Path", list) { - @NotNull - @Override - public String getTextFor(String value) { - return value == null ? "Specify Other..." : FileUtil.toSystemDependentName(value); - } - - @Override - public PopupStep onChosen(final String selectedValue, boolean finalChoice) { - final SdkType sdkType = suggestedSdkHomes.get(selectedValue); - if (selectedValue == null) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - createSdk(project, existingSdks, callback, sdkTypes); - } - }, ModalityState.current()); - } - else { - Sdk sdk = setupSdk(existingSdks, LocalFileSystem.getInstance().findFileByPath(selectedValue), - sdkType, false, null, null); - callback.consume(sdk); - } - return FINAL_CHOICE; - } - }; - final ListPopup popup = JBPopupFactory.getInstance().createListPopup(sdkHomesStep); - popup.showUnderneathOf(popupOwner); - } - public static List filterExistingPaths(SdkType sdkType, Collection sdkHomes, final Sdk[] sdks) { List result = new ArrayList(); for (String sdkHome : sdkHomes) { diff --git a/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java b/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java index 1c55471fa033..1163b5e073da 100644 --- a/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java +++ b/platform/lang-impl/src/com/intellij/platform/templates/github/ZipUtil.java @@ -11,18 +11,18 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.util.Enumeration; import java.util.concurrent.Callable; import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; /** * @author Sergey Simonchik */ -class ZipUtil { +public class ZipUtil { private static final Logger LOG = Logger.getInstance(ZipUtil.class); @@ -38,7 +38,8 @@ class ZipUtil { @Override public Boolean call() throws IOException { ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); - unzip(progress, zipArchive, extractToDir); + ZipInputStream stream = new ZipInputStream(new FileInputStream(zipArchive)); + unzip(progress, extractToDir, stream); return true; } }, @@ -60,21 +61,17 @@ class ZipUtil { } } - private static void unzip(@Nullable ProgressIndicator progress, - @NotNull File zipArchiveFile, - @NotNull File extractToDir) throws IOException { + public static void unzip(@Nullable ProgressIndicator progress, File extractToDir, ZipInputStream stream) throws IOException { if (progress != null) { progress.setText("Extracting..."); } - ZipFile zipFile = new ZipFile(zipArchiveFile); try { - boolean singleTopLevelDir = isSingleTopLevelDir(zipFile.entries()); - for (Enumeration e = zipFile.entries(); e.hasMoreElements();) { - ZipEntry zipEntry = e.nextElement(); - unzipEntryToDir(progress, zipFile, zipEntry, extractToDir, singleTopLevelDir); + ZipEntry entry; + while ((entry = stream.getNextEntry()) != null) { + unzipEntryToDir(progress, entry, extractToDir, stream); } } finally { - zipFile.close(); + stream.close(); } } @@ -99,12 +96,11 @@ class ZipUtil { } private static void unzipEntryToDir(@Nullable ProgressIndicator progress, - @NotNull final ZipFile zipFile, @NotNull final ZipEntry zipEntry, @NotNull final File extractToDir, - boolean singleTopLevelDir) throws IOException { + ZipInputStream stream) throws IOException { final char pathDelimiterChar = '/'; - String relativeExtractPath = createRelativeExtractPath(zipEntry, pathDelimiterChar, singleTopLevelDir); + String relativeExtractPath = createRelativeExtractPath(zipEntry, pathDelimiterChar, true); int ind = relativeExtractPath.lastIndexOf(pathDelimiterChar); final String relativeParentDir; final String name; @@ -129,13 +125,11 @@ class ZipUtil { } } File child = new File(parentDir, name); - InputStream stream = zipFile.getInputStream(zipEntry); FileOutputStream fileOutputStream = new FileOutputStream(child); try { FileUtil.copy(stream, fileOutputStream); } finally { fileOutputStream.close(); - stream.close(); } LOG.info("Extract: " + relativeExtractPath); } diff --git a/platform/platform-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java b/platform/platform-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java index 0d69d5d84ca5..597b20a86a5b 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactory.java @@ -16,12 +16,13 @@ package com.intellij.openapi.editor.highlighter; import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.fileTypes.SyntaxHighlighter; -import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author yole @@ -38,11 +39,11 @@ public abstract class EditorHighlighterFactory { public abstract EditorHighlighter createEditorHighlighter(final Project project, final FileType fileType); - public abstract EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile file, final EditorColorsScheme globalScheme, final Project project); + public abstract EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile file, final EditorColorsScheme globalScheme, @Nullable final Project project); public abstract EditorHighlighter createEditorHighlighter(final Project project, final VirtualFile file); public abstract EditorHighlighter createEditorHighlighter(final Project project, final String fileName); - public abstract EditorHighlighter createEditorHighlighter(final EditorColorsScheme settings, final String fileName, final Project project); + public abstract EditorHighlighter createEditorHighlighter(final EditorColorsScheme settings, final String fileName, @Nullable final Project project); } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java index cdc95b9e81ea..3796f59c0fb0 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java @@ -36,10 +36,26 @@ public abstract class SyntaxHighlighterFactory { } }; - public static SyntaxHighlighter getSyntaxHighlighter(Language lang, Project project, VirtualFile virtualFile) { + /** + * Returns syntax highlighter for the given language. + * @param lang a {@code Language} to get highlighter for + * @param project might be necessary to gather various project settings from + * @param virtualFile might be necessary to collect file specific settings + * @return {@code SyntaxHighlighter} interface implementation for the given file type + */ + public static SyntaxHighlighter getSyntaxHighlighter(@NotNull Language lang, @Nullable Project project, @Nullable final VirtualFile virtualFile) { return LANGUAGE_FACTORY.forLanguage(lang).getSyntaxHighlighter(project, virtualFile); } + /** + * Returns syntax highlighter for the given file type. + * Note: it is recommended to use {@link #getSyntaxHighlighter(Language, Project, VirtualFile)} in most cases, + * and use this method only when you are do not know the language you use. + * @param fileType a file type to use to select appropriate highlighter + * @param project might be necessary to gather various project settings from + * @param virtualFile might be necessary to collect file specific settings + * @return {@code SyntaxHighlighter} interface implementation for the given file type + */ @Nullable public static SyntaxHighlighter getSyntaxHighlighter(final FileType fileType, final @Nullable Project project, final @Nullable VirtualFile virtualFile) { return PROVIDER.getValue().create(fileType, project, virtualFile); @@ -57,5 +73,5 @@ public abstract class SyntaxHighlighterFactory { * @return SyntaxHighlighter interface implementation for this particular language. */ @NotNull - public abstract SyntaxHighlighter getSyntaxHighlighter(Project project, final VirtualFile virtualFile); + public abstract SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile); } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java index 5523416bb782..5c0472c9b58c 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/NamedItemsListEditor.java @@ -49,6 +49,7 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { private final Equality myComparer; private List myResultItems; private final List myOriginalItems; + private boolean myShowIcons; protected NamedItemsListEditor(Namer namer, Factory factory, @@ -160,6 +161,10 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { myNamer.setName(item, name); } + public void setShowIcons(boolean showIcons) { + myShowIcons = showIcons; + } + @Nullable protected UnnamedConfigurable getItemConfigurable(final T item) { final Ref result = new Ref(); @@ -213,6 +218,14 @@ public abstract class NamedItemsListEditor extends MasterDetailsComponent { return myNamer.getName(myItem); } + @Override + public Icon getIcon(boolean expanded) { + if (myShowIcons && myConfigurable instanceof Iconable) { + return ((Iconable)myConfigurable).getIcon(0); + } + return null; + } + public String getHelpTopic() { return null; } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java index 40e50923ce4a..a01f0fa3d6a1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/DiffPanelImpl.java @@ -100,6 +100,7 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid public void customize(DiffToolbar toolbar) { ActionManager actionManager = ActionManager.getInstance(); toolbar.addAction(actionManager.getAction("DiffPanel.Toolbar")); + toolbar.addAction(actionManager.getAction("ContextHelp")); } }; private boolean myDisposed = false; @@ -830,6 +831,9 @@ public class DiffPanelImpl implements DiffPanelEx, ContentChangeListener, TwoSid return new DiffNavigatable(currentSide); } } + if (PlatformDataKeys.HELP_ID.is(dataId)) { + return "reference.dialogs.diff.file"; + } return super.getData(dataId); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java index 27de1506dcc8..daee8d0e0e23 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/highlighter/EditorHighlighterFactoryImpl.java @@ -57,7 +57,7 @@ public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { } @Override - public EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile vFile, @NotNull final EditorColorsScheme settings, final Project project) { + public EditorHighlighter createEditorHighlighter(@NotNull final VirtualFile vFile, @NotNull final EditorColorsScheme settings, @Nullable final Project project) { final FileType fileType = vFile.getFileType(); if (fileType instanceof LanguageFileType) { LanguageFileType substFileType = substituteFileType(((LanguageFileType)fileType).getLanguage(), vFile, project); @@ -120,7 +120,7 @@ public class EditorHighlighterFactoryImpl extends EditorHighlighterFactory { } @Override - public EditorHighlighter createEditorHighlighter(final EditorColorsScheme settings, final String fileName, final Project project) { + public EditorHighlighter createEditorHighlighter(final EditorColorsScheme settings, final String fileName, @Nullable final Project project) { return createEditorHighlighter(new LightVirtualFile(fileName), settings, project); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/platform/ProjectTemplate.java b/platform/platform-impl/src/com/intellij/platform/ProjectTemplate.java index 8e25b4cfffea..1fabea513f6e 100644 --- a/platform/platform-impl/src/com/intellij/platform/ProjectTemplate.java +++ b/platform/platform-impl/src/com/intellij/platform/ProjectTemplate.java @@ -16,7 +16,8 @@ package com.intellij.platform; import com.intellij.ide.util.projectWizard.ProjectBuilder; -import com.intellij.openapi.module.Module; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -30,9 +31,9 @@ public interface ProjectTemplate { String getDescription(); - ProjectBuilder createModuleBuilder(); - + @Nullable JComponent getSettingsPanel(); - void generateProject(Module module); + @NotNull + ProjectBuilder createModuleBuilder(); } diff --git a/platform/platform-resources-en/src/messages/ExecutionBundle.properties b/platform/platform-resources-en/src/messages/ExecutionBundle.properties index d3995a102dfc..69bc59533e37 100644 --- a/platform/platform-resources-en/src/messages/ExecutionBundle.properties +++ b/platform/platform-resources-en/src/messages/ExecutionBundle.properties @@ -160,7 +160,8 @@ terminating.process.progress.kill=Kill process waiting.for.vm.detach.progress.text=Waiting for process detach restart.error.message.title=Restart Error rerun.configuration.action.name=Rerun ''{0}'' -rerun.confirmation.message=''{0}'' is single-instance run configuration.\nAre you sure you want to stop running one? +rerun.singleton.confirmation.message=''{0}'' is single-instance run configuration.\nAre you sure you want to stop running one? +rerun.confirmation.message=Are you sure you want to stop ''{0}''? rerun.confirmation.title=Stop Confirmation rerun.confirmation.checkbox=Confirm rerun with process termination run.configuration.dump.threads.action.name=Dump Threads diff --git a/platform/platform-resources-en/src/messages/VcsBundle.properties b/platform/platform-resources-en/src/messages/VcsBundle.properties index 3ccbf770ba6a..1e1d895e7620 100644 --- a/platform/platform-resources-en/src/messages/VcsBundle.properties +++ b/platform/platform-resources-en/src/messages/VcsBundle.properties @@ -323,9 +323,7 @@ changes.action.rollback.text=Rollback changes.action.rollback.description=Rollback changes changes.action.setdefaultchangelist.text=Set Active Changelist changes.action.setdefaultchangelist.description=Set changelist to which new changes are placed by default -create.patch.file.name.field=&Patch file name: -create.patch.commit.action.text=Create Patc_h... -create.patch.commit.action.description=Creates a patch from the selected changes +patch.apply.file.name.field=&Patch file name: create.patch.commit.action.title=Create Patch create.patch.error.title=Error creating patch: {0} patch.apply.dialog.title=Apply Patch @@ -424,7 +422,10 @@ changes.remove.active.prompt=Select the changelist to which the changes should b changes.remove.active.empty.prompt=Select the changelist to make active: changes.remove.active.title=Delete Active Changelist create.patch.loading.content.progress=Loading content revisions -create.patch.reverse.patch.checkbox=&Reverse patch +create.patch.reverse.checkbox=&Reverse patch +create.patch.base.revision=&Include base revision text(s) into patch file +create.patch.file.path=&Patch file: +create.patch.encoding=Encoding: committed.changes.refresh.progress=Refreshing VCS history cache.settings.dialog.title=VCS History Cache Settings diff.commit.message.title=Commit Message @@ -555,7 +556,6 @@ line.annotation.aspect.author=Author line.annotation.aspect.date=Date line.annotation.aspect.revision=Revision annotation.commit.number=Commit number -create.patch.file.path=&Patch file: todo.handler.only.skipped=TODO check has skipped {0,choice, 0#|1#one file|2#{0} files}.
\n\ No new, edited, or located in changed fragments TODO items found. todo.handler.only.added=There {0,choice, 0#|1#was one|2#were {0}} added or edited TODO {0,choice, 0#|1#item|2#items} found.
\ diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/util/text/StringUtilPerformanceTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/util/text/StringUtilPerformanceTest.java new file mode 100644 index 000000000000..513cb9e82a9b --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/openapi/util/text/StringUtilPerformanceTest.java @@ -0,0 +1,43 @@ +/* + * 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. + * 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.openapi.util.text; + +import com.intellij.testFramework.PlatformTestUtil; +import com.intellij.util.ThrowableRunnable; +import org.junit.Test; + +import java.util.Random; + +import static org.junit.Assert.assertTrue; + +public class StringUtilPerformanceTest { + private static final String TEST_STRING = "0123456789abcdefghijklmnopqrstuvwxyz"; + + @Test + public void containsAnyChar() throws Exception { + assertTrue(StringUtil.containsAnyChar(TEST_STRING, Integer.toString(new Random().nextInt()))); + + PlatformTestUtil.startPerformanceTest("StringUtil.containsAnyChar()", 200, new ThrowableRunnable() { + @Override + public void run() throws Throwable { + for (int i = 0; i < 1000000; i++) { + StringUtil.containsAnyChar(TEST_STRING, "XYZ"); + StringUtil.containsAnyChar("XYZ", TEST_STRING); + } + } + }).cpuBound().assertTiming(); + } +} diff --git a/platform/util-rt/src/com/intellij/util/Consumer.java b/platform/util-rt/src/com/intellij/util/Consumer.java index 2886971cec98..d00f829b117e 100644 --- a/platform/util-rt/src/com/intellij/util/Consumer.java +++ b/platform/util-rt/src/com/intellij/util/Consumer.java @@ -15,6 +15,8 @@ */ package com.intellij.util; +import org.jetbrains.annotations.Nullable; + public interface Consumer { Consumer EMPTY_CONSUMER = new Consumer() { public void consume(final Object t) { @@ -24,7 +26,7 @@ public interface Consumer { /** * @param t consequently takes value of each element of the set this processor is passed to for processing. */ - void consume(T t); + void consume(@Nullable T t); } 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 ec52a5636d1e..85ca5dd5ba00 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1331,7 +1331,12 @@ public class StringUtil extends StringUtilRt { } public static boolean containsAnyChar(@NotNull final String value, @NotNull final String chars) { - return containsAnyChar(value, chars, 0, value.length()); + if (chars.length() > value.length()) { + return containsAnyChar(value, chars, 0, value.length()); + } + else { + return containsAnyChar(chars, value, 0, chars.length()); + } } public static boolean containsAnyChar(@NotNull final String value, diff --git a/platform/util/src/com/intellij/util/BufferedListConsumer.java b/platform/util/src/com/intellij/util/BufferedListConsumer.java index cfb0e9eb8aae..6619dc554b7e 100644 --- a/platform/util/src/com/intellij/util/BufferedListConsumer.java +++ b/platform/util/src/com/intellij/util/BufferedListConsumer.java @@ -49,8 +49,8 @@ public class BufferedListConsumer implements Consumer> { if ((mySize <= myBuffer.size()) || (myInterval > 0) && ((ts - myInterval) > myTs)) { myConsumer.consume(new ArrayList(myBuffer)); myBuffer.clear(); + myTs = ts; } - myTs = ts; } public void flushPart() { diff --git a/platform/vcs-api/src/com/intellij/vcsUtil/VcsUtil.java b/platform/vcs-api/src/com/intellij/vcsUtil/VcsUtil.java index eb72f7f31adc..4fa62cb0ab61 100644 --- a/platform/vcs-api/src/com/intellij/vcsUtil/VcsUtil.java +++ b/platform/vcs-api/src/com/intellij/vcsUtil/VcsUtil.java @@ -37,7 +37,10 @@ import com.intellij.openapi.vcs.actions.VcsContextFactory; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ContentRevision; import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtilCore; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileVisitor; import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.wm.StatusBar; import org.jetbrains.annotations.NotNull; @@ -591,4 +594,8 @@ public class VcsUtil { } return idx > 0; } + + public static String getPathForProgressPresentation(@NotNull final File file) { + return file.getName() + " (" + file.getParent() + ")"; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java index fa756e694778..979949f29b81 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java @@ -390,7 +390,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { final GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0); - myPatchFileLabel = new JLabel(VcsBundle.message("create.patch.file.name.field")); + myPatchFileLabel = new JLabel(VcsBundle.message("patch.apply.file.name.field")); myPatchFileLabel.setLabelFor(myPatchFile); myCenterPanel.add(myPatchFileLabel, gb); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java index 0c9aa4e11379..b3b081c14089 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.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. @@ -150,16 +150,16 @@ public class CreatePatchConfigurationPanel { private void initMainPanel() { myFileNameField = new TextFieldWithBrowseButton(); - myReversePatchCheckbox = new JCheckBox(VcsBundle.message("create.patch.reverse.patch.checkbox")); + myReversePatchCheckbox = new JCheckBox(VcsBundle.message("create.patch.reverse.checkbox")); myEncoding = new JComboBox(); - myIncludeBaseRevisionTextCheckBox = new JCheckBox("Include base revision text(s) into patch file"); + myIncludeBaseRevisionTextCheckBox = new JCheckBox(VcsBundle.message("create.patch.base.revision")); myErrorLabel = new JLabel(); myMainPanel = FormBuilder.createFormBuilder() .addLabeledComponent(VcsBundle.message("create.patch.file.path"), myFileNameField) .addComponent(myReversePatchCheckbox) - .addLabeledComponent("Encoding:", myEncoding) .addComponent(myIncludeBaseRevisionTextCheckBox) + .addLabeledComponent(VcsBundle.message("create.patch.encoding"), myEncoding) .addComponent(myErrorLabel) .getPanel(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java index 8adad110695a..e9d5c2e90bd7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java @@ -15,7 +15,10 @@ */ package com.intellij.openapi.vcs.ui; +import com.intellij.notification.Notification; import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationListener; +import com.intellij.notification.NotificationType; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; @@ -23,11 +26,14 @@ import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.BalloonBuilder; import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.util.NamedRunnable; import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager; import com.intellij.ui.awt.RelativePoint; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.event.HyperlinkEvent; import java.awt.*; import java.util.concurrent.TimeUnit; @@ -43,32 +49,37 @@ public class VcsBalloonProblemNotifier implements Runnable { private final String myMessage; private final MessageType myMessageType; private final boolean myShowOverChangesView; + @Nullable private final NamedRunnable[] myNotificationListener; public VcsBalloonProblemNotifier(@NotNull final Project project, @NotNull final String message, final MessageType messageType) { - this(project, message, messageType, true); + this(project, message, messageType, true, null); } - public VcsBalloonProblemNotifier(@NotNull final Project project, @NotNull final String message, final MessageType messageType, boolean showOverChangesView) { + public VcsBalloonProblemNotifier(@NotNull final Project project, @NotNull final String message, final MessageType messageType, boolean showOverChangesView, + @Nullable final NamedRunnable[] notificationListener) { myProject = project; myMessage = message; myMessageType = messageType; myShowOverChangesView = showOverChangesView; + myNotificationListener = notificationListener; } - public static void showOverChangesView(@NotNull final Project project, @NotNull final String message, final MessageType type) { - show(project, message, type, true); + public static void showOverChangesView(@NotNull final Project project, @NotNull final String message, final MessageType type, + final NamedRunnable... notificationListener) { + show(project, message, type, true, notificationListener); } public static void showOverVersionControlView(@NotNull final Project project, @NotNull final String message, final MessageType type) { - show(project, message, type, false); + show(project, message, type, false, null); } - private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView) { + private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView, + @Nullable final NamedRunnable[] notificationListener) { final Application application = ApplicationManager.getApplication(); if (application.isHeadlessEnvironment()) return; final Runnable showErrorAction = new Runnable() { public void run() { - new VcsBalloonProblemNotifier(project, message, type, showOverChangesView).run(); + new VcsBalloonProblemNotifier(project, message, type, showOverChangesView, notificationListener).run(); } }; if (application.isDispatchThread()) { @@ -80,7 +91,40 @@ public class VcsBalloonProblemNotifier implements Runnable { } public void run() { - NOTIFICATION_GROUP.createNotification(myMessage, myMessageType).notify(myProject.isDefault() ? null : myProject); + final Notification notification; + if (myNotificationListener != null && myNotificationListener.length > 0) { + final NotificationType type = myMessageType.toNotificationType(); + final StringBuilder sb = new StringBuilder(myMessage); + for (NamedRunnable runnable : myNotificationListener) { + final String name = runnable.toString(); + sb.append("
").append(name).append(""); + } + notification = NOTIFICATION_GROUP.createNotification(type.name(), sb.toString(), myMessageType.toNotificationType(), + new NotificationListener() { + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + if (HyperlinkEvent.EventType.ACTIVATED.equals(event.getEventType())) { + if (myNotificationListener.length == 1) { + myNotificationListener[0].run(); + } else { + final String description = event.getDescription(); + if (description != null) { + for (NamedRunnable runnable : myNotificationListener) { + if (description.equals(runnable.toString())) { + runnable.run(); + break; + } + } + } + } + notification.expire(); + } + } + }); + } else { + notification = NOTIFICATION_GROUP.createNotification(myMessage, myMessageType); + } + notification.notify(myProject.isDefault() ? null : myProject); } public static void showBalloonForComponent(@NotNull JComponent component, @NotNull final String message, final MessageType type, diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java index c42901db8282..87834f74726e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java @@ -43,6 +43,7 @@ import com.intellij.util.EditSourceOnDoubleClickHandler; import com.intellij.util.EditSourceOnEnterKeyHandler; import com.intellij.util.PlatformIcons; import com.intellij.util.containers.Convertor; +import com.intellij.util.ui.StatusText; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -92,7 +93,7 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton implements Di UpdatedFiles updatedFiles, String rootName, ActionInfo actionInfo) { - super(contentManager, "reference.toolWindows.versionControl"); + super(contentManager, "reference.versionControl.toolwindow.update"); myActionInfo = actionInfo; myFileStatusListener = new FileStatusListener() { @@ -334,8 +335,9 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton implements Di myCommittedChangeLists = receivedChanges; myTreeBrowser.setItems(myCommittedChangeLists, CommittedChangesBrowserUseCase.UPDATE); if (hasEmptyCaches) { - myTreeBrowser.getEmptyText() - .appendText("Click ") + final StatusText statusText = myTreeBrowser.getEmptyText(); + statusText.clear(); + statusText.appendText("Click ") .appendText("Refresh", SimpleTextAttributes.LINK_ATTRIBUTES, new ActionListener() { public void actionPerformed(final ActionEvent e) { RefreshIncomingChangesAction.doRefresh(myProject); diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java index 96a73f7b6c0d..e23a7d31cf50 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidAdditionalRootProviderService.java @@ -4,8 +4,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.builders.AdditionalRootsProviderService; import org.jetbrains.jps.builders.BuildTarget; import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.incremental.ModuleBuildTarget; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import java.io.File; import java.util.ArrayList; @@ -15,17 +15,17 @@ import java.util.List; /** * @author Eugene.Kudelevsky */ -public class AndroidAdditionalRootProviderService extends AdditionalRootsProviderService { +public class AndroidAdditionalRootProviderService extends AdditionalRootsProviderService { public AndroidAdditionalRootProviderService() { super(Collections.singletonList(JavaModuleBuildTargetType.PRODUCTION)); } @NotNull @Override - public List getAdditionalRoots(@NotNull BuildTarget target, File dataStorageRoot) { + public List getAdditionalRoots(@NotNull BuildTarget target, File dataStorageRoot) { ModuleBuildTarget buildTarget = (ModuleBuildTarget)target; final File generatedSourcesRoot = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), dataStorageRoot); - final List result = new ArrayList(); + final List result = new ArrayList(); addRoot(result, buildTarget, new File(generatedSourcesRoot, AndroidJpsUtil.AAPT_GENERATED_SOURCE_ROOT_NAME)); addRoot(result, buildTarget, new File(generatedSourcesRoot, AndroidJpsUtil.AIDL_GENERATED_SOURCE_ROOT_NAME)); @@ -35,7 +35,7 @@ public class AndroidAdditionalRootProviderService extends AdditionalRootsProvide return result; } - private static void addRoot(List result, ModuleBuildTarget buildTarget, final File file) { - result.add(new RootDescriptor(file, buildTarget, true, false)); + private static void addRoot(List result, ModuleBuildTarget buildTarget, final File file) { + result.add(new JavaSourceRootDescriptor(file, buildTarget, true, false, "")); } } diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java index 8a4d0c304ee3..7684f661b890 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidDexBuilder.java @@ -110,7 +110,7 @@ public class AndroidDexBuilder extends TargetBuilder @NotNull AndroidFileSetStorage proguardStateStorage) throws IOException { boolean success = true; - for (JpsModule module : context.getProjectDescriptor().jpsProject.getModules()) { + for (JpsModule module : context.getProjectDescriptor().getProject().getModules()) { final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module); if (extension == null || extension.isLibrary()) { continue; @@ -344,7 +344,7 @@ public class AndroidDexBuilder extends TargetBuilder final JpsSdk> sdk = platform.getSdk(); final String jdkName = sdk.getSdkProperties().getData().getJdkName(); - final JpsLibrary javaSdk = context.getProjectDescriptor().jpsModel.getGlobal().getLibraryCollection().findLibrary(jdkName); + final JpsLibrary javaSdk = context.getProjectDescriptor().getModel().getGlobal().getLibraryCollection().findLibrary(jdkName); if (javaSdk == null || !javaSdk.getType().equals(JpsJavaSdkType.INSTANCE)) { context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.java.sdk.not.specified", jdkName))); return false; diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java index d27f6f8e213a..013a36f27553 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidLibraryPackagingBuilder.java @@ -8,8 +8,8 @@ import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.ProjectPaths; import org.jetbrains.jps.android.model.JpsAndroidModuleExtension; import org.jetbrains.jps.builders.DirtyFilesHolder; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.incremental.*; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.messages.ProgressMessage; import org.jetbrains.jps.model.module.JpsModule; @@ -28,7 +28,7 @@ public class AndroidLibraryPackagingBuilder extends ModuleLevelBuilder { } @Override - public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { + public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { if (chunk.containsTests() || !AndroidJpsUtil.containsAndroidFacet(chunk) || AndroidJpsUtil.isLightBuild(context)) { return ExitCode.NOTHING_DONE; } diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java index b2a634341f65..2421a9fca633 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidPackagingBuilder.java @@ -62,7 +62,7 @@ public class AndroidPackagingBuilder extends TargetBuilder modules = context.getProjectDescriptor().jpsProject.getModules(); + final Collection modules = context.getProjectDescriptor().getProject().getModules(); final Map resourcesStates = new HashMap(); final Map assetsStates = new HashMap(); final Map manifestFiles = new HashMap(); @@ -384,7 +384,7 @@ public class AndroidPackagingBuilder extends TargetBuilder additionalNativeLibs = extension.getAdditionalNativeLibs(); final AndroidFileSetState currentFileSetState = - buildCurrentApkBuilderState(context.getProjectDescriptor().jpsProject, resPackagePath, classesDexFilePath, nativeLibDirs, sourceRoots, + buildCurrentApkBuilderState(context.getProjectDescriptor().getProject(), resPackagePath, classesDexFilePath, nativeLibDirs, sourceRoots, externalJars, release); final AndroidApkBuilderConfigState currentApkBuilderConfigState = @@ -404,7 +404,7 @@ public class AndroidPackagingBuilder extends TargetBuilder> messages = AndroidApkBuilder .execute(resPackagePath, classesDexFilePath, sourceRoots, externalJars, nativeLibDirs, additionalNativeLibs, - outputApkPath, release, sdkPath, customKeyStorePath, new MyExcludedSourcesFilter(context.getProjectDescriptor().jpsProject)); + outputApkPath, release, sdkPath, customKeyStorePath, new MyExcludedSourcesFilter(context.getProjectDescriptor().getProject())); AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName()); final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty(); diff --git a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java index d5b7dd222055..fe40f735c8b4 100644 --- a/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java +++ b/plugins/android/jps-plugin/src/org/jetbrains/jps/android/AndroidSourceGeneratingBuilder.java @@ -23,9 +23,9 @@ import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.android.model.JpsAndroidModuleExtension; import org.jetbrains.jps.builders.DirtyFilesHolder; import org.jetbrains.jps.builders.FileProcessor; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.builders.storage.SourceToOutputMapping; import org.jetbrains.jps.incremental.*; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.java.FormsParsing; import org.jetbrains.jps.incremental.messages.BuildMessage; import org.jetbrains.jps.incremental.messages.CompilerMessage; @@ -75,7 +75,7 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder { @Override public ModuleLevelBuilder.ExitCode build(CompileContext context, ModuleChunk chunk, - DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { + DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { if (chunk.containsTests() || !AndroidJpsUtil.containsAndroidFacet(chunk)) { return ExitCode.NOTHING_DONE; } @@ -90,7 +90,7 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder { private static ModuleLevelBuilder.ExitCode doBuild(CompileContext context, ModuleChunk chunk, - DirtyFilesHolder dirtyFilesHolder) throws IOException { + DirtyFilesHolder dirtyFilesHolder) throws IOException { final Map moduleDataMap = computeModuleDatas(chunk.getModules(), context); if (moduleDataMap == null || moduleDataMap.size() == 0) { return ExitCode.ABORT; @@ -110,9 +110,9 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder { final Map idlFilesToCompile = new HashMap(); final Map rsFilesToCompile = new HashMap(); - dirtyFilesHolder.processDirtyFiles(new FileProcessor() { + dirtyFilesHolder.processDirtyFiles(new FileProcessor() { @Override - public boolean apply(ModuleBuildTarget target, File file, RootDescriptor sourceRoot) throws IOException { + public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException { final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(target.getModule()); if (extension == null) { @@ -905,7 +905,7 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder { @Nullable private static String getDependencyFolder(@NotNull CompileContext context, @NotNull File sourceFile, @NotNull File genFolder) { - final RootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, sourceFile); + final JavaSourceRootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, sourceFile); if (descriptor == null) { return null; } @@ -975,7 +975,7 @@ public class AndroidSourceGeneratingBuilder extends ModuleLevelBuilder { @Nullable private static String computePackageForFile(@NotNull CompileContext context, @NotNull File file) throws IOException { - final RootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); + final JavaSourceRootDescriptor descriptor = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, file); if (descriptor == null) { return null; } diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/DetailsCache.java b/plugins/git4idea/src/git4idea/history/wholeTree/DetailsCache.java index e141ce36d239..3c5a9bdf9a12 100644 --- a/plugins/git4idea/src/git4idea/history/wholeTree/DetailsCache.java +++ b/plugins/git4idea/src/git4idea/history/wholeTree/DetailsCache.java @@ -156,19 +156,20 @@ public class DetailsCache { public void run(@NotNull ProgressIndicator indicator) { if (!recheck.process(abstractHash)) return; if (getBranches(root, abstractHash) != null) return; - final List branches; + List branches; try { branches = new LowLevelAccessImpl(myProject, root).getBranchesWithCommit(abstractHash.getString()); } catch (VcsException e) { LOG.info(e); - return; + branches = Collections.singletonList("Can not load branches due to error: " + e.getMessage()); } putBranches(root, abstractHash, branches); + final List finalBranches = branches; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - continuation.consume(branches); + continuation.consume(finalBranches); } }); } diff --git a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java index 5783bdb9d192..c6a67bc14898 100644 --- a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java +++ b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java @@ -14,12 +14,12 @@ import org.jetbrains.jps.builders.BuildRootIndex; import org.jetbrains.jps.builders.DirtyFilesHolder; import org.jetbrains.jps.builders.FileProcessor; import org.jetbrains.jps.builders.java.JavaBuilderUtil; +import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor; import org.jetbrains.jps.builders.java.dependencyView.Callbacks; import org.jetbrains.jps.builders.java.dependencyView.Mappings; import org.jetbrains.jps.builders.storage.SourceToOutputMapping; import org.jetbrains.jps.cmdline.ClasspathBootstrap; import org.jetbrains.jps.incremental.*; -import org.jetbrains.jps.incremental.fs.RootDescriptor; import org.jetbrains.jps.incremental.java.ClassPostProcessor; import org.jetbrains.jps.incremental.java.JavaBuilder; import org.jetbrains.jps.incremental.messages.BuildMessage; @@ -67,7 +67,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { public ModuleLevelBuilder.ExitCode build(final CompileContext context, ModuleChunk chunk, - DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { + DirtyFilesHolder dirtyFilesHolder) throws ProjectBuildException { try { final List toCompile = collectChangedFiles(context, dirtyFilesHolder); if (toCompile.isEmpty()) { @@ -136,7 +136,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { final BuildRootIndex rootsIndex = context.getProjectDescriptor().getBuildRootIndex(); for (ModuleBuildTarget target : generationOutputs.keySet()) { File root = new File(generationOutputs.get(target)); - rootsIndex.associateTempRoot(context, target, new RootDescriptor(root, target, true, true)); + rootsIndex.associateTempRoot(context, target, new JavaSourceRootDescriptor(root, target, true, true, "")); } } @@ -206,7 +206,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { GroovycOSProcessHandler.OutputItem item, Map generationOutputs, String compilerOutput) throws IOException { if (chunk.getModules().size() > 1) { final BuildRootIndex rootsIndex = context.getProjectDescriptor().getBuildRootIndex(); - RootDescriptor descriptor = rootsIndex.getModuleAndRoot(context, new File(item.sourcePath)); + JavaSourceRootDescriptor descriptor = rootsIndex.getModuleAndRoot(context, new File(item.sourcePath)); if (descriptor != null) { ModuleBuildTarget srcTarget = descriptor.target; if (!srcTarget.equals(chunk.representativeTarget())) { @@ -238,12 +238,12 @@ public class GroovyBuilder extends ModuleLevelBuilder { } private static List collectChangedFiles(CompileContext context, - DirtyFilesHolder dirtyFilesHolder) throws IOException { + DirtyFilesHolder dirtyFilesHolder) throws IOException { final ResourcePatterns patterns = ResourcePatterns.KEY.get(context); assert patterns != null; final List toCompile = new ArrayList(); - dirtyFilesHolder.processDirtyFiles(new FileProcessor() { - public boolean apply(ModuleBuildTarget target, File file, RootDescriptor sourceRoot) throws IOException { + dirtyFilesHolder.processDirtyFiles(new FileProcessor() { + public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException { final String path = file.getPath(); if (isGroovyFile(path) && !patterns.isResourceFile(file, sourceRoot.root)) { //todo file type check toCompile.add(file); @@ -269,7 +269,7 @@ public class GroovyBuilder extends ModuleLevelBuilder { for (GroovycOSProcessHandler.OutputItem item : successfullyCompiled) { final String sourcePath = FileUtil.toSystemIndependentName(item.sourcePath); final String outputPath = FileUtil.toSystemIndependentName(item.outputPath); - final RootDescriptor moduleAndRoot = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, new File(sourcePath)); + final JavaSourceRootDescriptor moduleAndRoot = context.getProjectDescriptor().getBuildRootIndex().getModuleAndRoot(context, new File(sourcePath)); if (moduleAndRoot != null) { final ModuleBuildTarget target = moduleAndRoot.target; context.getProjectDescriptor().dataManager.getSourceToOutputMap(target).appendOutput(sourcePath, outputPath); @@ -313,7 +313,8 @@ public class GroovyBuilder extends ModuleLevelBuilder { private static Map buildClassToSourceMap(ModuleChunk chunk, CompileContext context, Set toCompilePaths, Map finalOutputs) throws IOException { final Map class2Src = new HashMap(); - JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(context.getProjectDescriptor().jpsProject); + JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration( + context.getProjectDescriptor().getProject()); for (ModuleBuildTarget target : chunk.getTargets()) { String moduleOutputPath = finalOutputs.get(target); final SourceToOutputMapping srcToOut = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java index 70fff2d294f6..1e823136398f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnAuthenticationNotifier.java @@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.util.NamedRunnable; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.impl.GenericNotifierImpl; @@ -33,6 +34,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.ui.awt.RelativePoint; +import com.intellij.util.Consumer; import com.intellij.util.ThreeState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -321,14 +323,37 @@ public class SvnAuthenticationNotifier extends GenericNotifierImpl() { + @Override + public void consume(String s) { + configuration.setConfigurationDirectory(s); + } + }, project, null); + } + }); + } + }, ModalityState.NON_MODAL, project.getDisposed()); } return false; /// !!!! any exception means user should be notified that authorization failed } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties index 9db0ae7d40f8..ba6e615f19ff 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties @@ -154,6 +154,7 @@ status.group.name.locked=Locked checkbox.configure.use.system.default.configuration.directory=&Use system default Subversion configuration directory label.configuration.configuration.directory=Subversion configuration &directory: dialog.title.select.configuration.directory=Select Configuration Directory +action.title.select.configuration.directory=Change Configuration Directory dialog.description.select.configuration.directory=Select Subversion configuration directory or create new one button.text.clear.authentication.cache=&Clear Auth Cache label.text.delete.stored.credentials=Delete all stored credentials for 'http', 'svn' and 'svn+ssh' protocols diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfigurable.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfigurable.java index f2eff8947c0e..2a07a18bccd1 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfigurable.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfigurable.java @@ -32,8 +32,11 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.ui.MultiLineTooltipUI; +import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.config.ConfigureProxiesListener; import javax.swing.*; @@ -93,37 +96,21 @@ public class SvnConfigurable implements Configurable { myClearAuthButton.addActionListener(new ActionListener(){ public void actionPerformed(final ActionEvent e) { - String path = myConfigurationDirectoryText.getText(); - if (path != null) { - int result = Messages.showYesNoDialog(myComponent, SvnBundle.message("confirmation.text.delete.stored.authentication.information"), - SvnBundle.message("confirmation.title.clear.authentication.cache"), - Messages.getWarningIcon()); - if (result == 0) { - SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - SvnConfiguration.getInstance(myProject).clearAuthenticationDirectory(myProject); - } - } - + clearAuthenticationCache(myProject, myComponent, myConfigurationDirectoryText.getText()); } }); - final FileChooserDescriptor descriptor = createFileDescriptor(); myConfigurationDirectoryText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @NonNls String path = myConfigurationDirectoryText.getText().trim(); - path = "file://" + path.replace(File.separatorChar, '/'); - VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(path); - - String oldValue = PropertiesComponent.getInstance().getValue("FileChooser.showHiddens"); - PropertiesComponent.getInstance().setValue("FileChooser.showHiddens", Boolean.TRUE.toString()); - VirtualFile file = FileChooser.chooseFile(descriptor, myComponent, myProject, root); - PropertiesComponent.getInstance().setValue("FileChooser.showHiddens", oldValue); - if (file == null) { - return; - } - myConfigurationDirectoryText.setText(file.getPath().replace('/', File.separatorChar)); + selectConfigirationDirectory(path, new Consumer() { + @Override + public void consume(String s) { + myConfigurationDirectoryText.setText(s); + } + }, myProject, myComponent); } }); myConfigurationDirectoryText.setEditable(false); @@ -150,6 +137,42 @@ public class SvnConfigurable implements Configurable { myJavaHLInfo.setVisible(internal); } + public static void selectConfigirationDirectory(@NotNull String path, @NotNull final Consumer dirConsumer, + final Project project, @Nullable final Component component) { + final FileChooserDescriptor descriptor = createFileDescriptor(); + path = "file://" + path.replace(File.separatorChar, '/'); + VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(path); + + String oldValue = PropertiesComponent.getInstance().getValue("FileChooser.showHiddens"); + PropertiesComponent.getInstance().setValue("FileChooser.showHiddens", Boolean.TRUE.toString()); + VirtualFile file = FileChooser.chooseFile(descriptor, component, project, root); + PropertiesComponent.getInstance().setValue("FileChooser.showHiddens", oldValue); + if (file == null) { + return; + } + final String resultPath = file.getPath().replace('/', File.separatorChar); + dirConsumer.consume(resultPath); + } + + public static void clearAuthenticationCache(@NotNull final Project project, final Component component, final String configDirPath) { + if (configDirPath != null) { + int result; + if (component == null) { + result = Messages.showYesNoDialog(project, SvnBundle.message("confirmation.text.delete.stored.authentication.information"), + SvnBundle.message("confirmation.title.clear.authentication.cache"), + Messages.getWarningIcon()); + } else { + result = Messages.showYesNoDialog(component, SvnBundle.message("confirmation.text.delete.stored.authentication.information"), + SvnBundle.message("confirmation.title.clear.authentication.cache"), + Messages.getWarningIcon()); + } + if (result == 0) { + SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); + SvnConfiguration.getInstance(project).clearAuthenticationDirectory(project); + } + } + } + private static FileChooserDescriptor createFileDescriptor() { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setShowFileSystemRoots(true); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfiguration.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfiguration.java index 4a2d3639c9cb..e4e98fde84aa 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfiguration.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnConfiguration.java @@ -488,7 +488,7 @@ public class SvnConfiguration implements PersistentStateComponent { public static class AuthStorage implements ISVNAuthenticationStorage { - private final Map myStorage = new Hashtable(); + private final Map myStorage = Collections.synchronizedMap(new HashMap()); public void clear() { myStorage.clear(); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java index 74fb6ad2e98e..e02861a0646f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java @@ -185,12 +185,13 @@ public class SvnVcs extends AbstractVcs { } static { - SVNJNAUtil.setJNAEnabled(true); - SvnHttpAuthMethodsDefaultChecker.check(); - //noinspection UseOfArchaicSystemPropertyAccessors final JavaSVNDebugLogger logger = new JavaSVNDebugLogger(Boolean.getBoolean(LOG_PARAMETER_NAME), LOG); SVNDebugLog.setDefaultLog(logger); + + SVNJNAUtil.setJNAEnabled(true); + SvnHttpAuthMethodsDefaultChecker.check(); + SVNAdminAreaFactory.setSelector(new SvnFormatSelector()); DAVRepositoryFactory.setup(); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SvnFormatWorker.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SvnFormatWorker.java index 2e7acdecdb05..f1310cdd7fd9 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SvnFormatWorker.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SvnFormatWorker.java @@ -26,6 +26,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vcs.changes.LocalChangeList; +import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.svn.SvnBundle; import org.jetbrains.idea.svn.SvnUtil; @@ -35,6 +36,7 @@ import org.tmatesoft.svn.core.SVNCancelException; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.wc.ISVNEventHandler; import org.tmatesoft.svn.core.wc.SVNEvent; +import org.tmatesoft.svn.core.wc.SVNEventAction; import org.tmatesoft.svn.core.wc.SVNWCClient; import java.io.File; @@ -124,10 +126,14 @@ public class SvnFormatWorker extends Task.Backgroundable { wcClient.setEventHandler(new ISVNEventHandler() { @Override public void handleEvent(SVNEvent event, double progress) throws SVNException { + if (SVNEventAction.UPGRADED_PATH.equals(event.getAction()) && event.getFile() != null) { + indicator.setText2("Upgraded path " + VcsUtil.getPathForProgressPresentation(event.getFile())); + } } + @Override public void checkCancelled() throws SVNCancelException { - if (indicator.isCanceled()) throw new SVNCancelException(); + indicator.checkCanceled(); } }); try { diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index 87defe6bb3a2..13e43d7f7ccb 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -297,7 +297,7 @@ - +