diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java
index d12245605d4..60f122de194 100644
--- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java
+++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java
@@ -42,7 +42,7 @@ import org.jetbrains.jet.modules.xml.AbstractModuleXmlParserTest;
import org.jetbrains.jet.plugin.codeInsight.moveUpDown.AbstractCodeMoverTest;
import org.jetbrains.jet.plugin.codeInsight.surroundWith.AbstractSurroundWithTest;
import org.jetbrains.jet.plugin.codeInsight.unwrap.AbstractUnwrapRemoveTest;
-import org.jetbrains.jet.plugin.configuration.AbstractConfigureGradleProjectTest;
+import org.jetbrains.jet.plugin.configuration.AbstractConfigureProjectByChangingFileTest;
import org.jetbrains.jet.plugin.folding.AbstractKotlinFoldingTest;
import org.jetbrains.jet.plugin.hierarchy.AbstractHierarchyTest;
import org.jetbrains.jet.plugin.highlighter.AbstractDeprecatedHighlightingTest;
@@ -176,7 +176,8 @@ public class GenerateTests {
"LoadJavaTestGenerated",
AbstractLoadJavaTest.class,
testModel("compiler/testData/loadJava/compiledJavaCompareWithKotlin", true, "java", "doTest"),
- testModel("compiler/testData/loadJava/compiledJavaIncludeObjectMethods", true, "java", "doTestCompiledJavaIncludeObjectMethods"),
+ testModel("compiler/testData/loadJava/compiledJavaIncludeObjectMethods", true, "java",
+ "doTestCompiledJavaIncludeObjectMethods"),
testModel("compiler/testData/loadJava/compiledJava", true, "java", "doTestCompiledJava"),
testModel("compiler/testData/loadJava/sourceJava", true, "java", "doTestSourceJava"),
testModel("compiler/testData/loadJava/javaAgainstKotlin", true, "txt", "doTestJavaAgainstKotlin")
@@ -316,7 +317,8 @@ public class GenerateTests {
"idea/tests/",
"QuickFixMultiFileTestGenerated",
AbstractQuickFixMultiFileTest.class,
- new SimpleTestClassModel(new File("idea/testData/quickfix"), true, Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), "doTestWithExtraFile")
+ new SimpleTestClassModel(new File("idea/testData/quickfix"), true, Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"),
+ "doTestWithExtraFile")
);
generateTest(
@@ -459,10 +461,11 @@ public class GenerateTests {
generateTest(
"idea/tests/",
- "ConfigureGradleProjectTestGenerated",
- AbstractConfigureGradleProjectTest.class,
+ "ConfigureProjectByChangingFileTestGenerated",
+ AbstractConfigureProjectByChangingFileTest.class,
new SimpleTestClassModel(new File("idea/testData/configuration/android-gradle"), true, Pattern.compile("(\\w+)_before\\.gradle$"), "doTestAndroidGradle"),
- new SimpleTestClassModel(new File("idea/testData/configuration/gradle"), true, Pattern.compile("(\\w+)_before\\.gradle$"), "doTestGradle")
+ new SimpleTestClassModel(new File("idea/testData/configuration/gradle"), true, Pattern.compile("(\\w+)_before\\.gradle$"), "doTestGradle"),
+ testModelWithDirectories("idea/testData/configuration/maven", "doTestWithMaven")
);
}
@@ -479,11 +482,15 @@ public class GenerateTests {
}
private static SimpleTestClassModel testModelWithDirectories(@NotNull String rootPath, @NotNull String methodName) {
- return new SimpleTestClassModel(new File(rootPath), false, Pattern.compile("^(.+)$"), methodName);
+ return new SimpleTestClassModel(new File(rootPath), false, Pattern.compile("^(.+)$"), methodName);
}
- private static SimpleTestClassModel testModelWithPattern(@NotNull String rootPath, @NotNull String pattern, @NotNull String methodName) {
- return new SimpleTestClassModel(new File(rootPath), true, Pattern.compile(pattern), methodName);
+ private static SimpleTestClassModel testModelWithPattern(
+ @NotNull String rootPath,
+ @NotNull String pattern,
+ @NotNull String methodName
+ ) {
+ return new SimpleTestClassModel(new File(rootPath), true, Pattern.compile(pattern), methodName);
}
private static SimpleTestClassModel testModel(
diff --git a/idea/src/META-INF/maven.xml b/idea/src/META-INF/maven.xml
index 8b695f0ed14..e1038e035a6 100644
--- a/idea/src/META-INF/maven.xml
+++ b/idea/src/META-INF/maven.xml
@@ -1,4 +1,5 @@
-
+
+
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinMavenConfigurator.java b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinMavenConfigurator.java
new file mode 100644
index 00000000000..1899820d306
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinMavenConfigurator.java
@@ -0,0 +1,277 @@
+/*
+ * Copyright 2010-2013 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 org.jetbrains.jet.plugin.configuration;
+
+import com.intellij.codeInsight.CodeInsightUtilCore;
+import com.intellij.ide.highlighter.JavaFileType;
+import com.intellij.openapi.application.Result;
+import com.intellij.openapi.command.WriteCommandAction;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleUtilCore;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.ContentEntry;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.SourceFolder;
+import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.vfs.VfsUtilCore;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.WritingAccessProvider;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiManager;
+import com.intellij.psi.search.FileTypeIndex;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.xml.XmlTag;
+import com.intellij.util.xml.DomElement;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.idea.maven.dom.MavenDomUtil;
+import org.jetbrains.idea.maven.dom.model.*;
+import org.jetbrains.idea.maven.project.MavenProjectsManager;
+import org.jetbrains.jet.plugin.JetPluginUtil;
+import org.jetbrains.jet.plugin.framework.ui.ConfigureDialogWithModulesAndVersion;
+
+import java.util.List;
+
+public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
+ private static final String[] KOTLIN_VERSIONS = {"0.6.179", "0.1-SNAPSHOT"};
+
+ public static final String NAME = "maven";
+
+ private static final String STD_LIB_ID = "kotlin-stdlib";
+ private static final String MAVEN_PLUGIN_ID = "kotlin-maven-plugin";
+ private static final String KOTLIN_VERSION_PROPERTY = "kotlin.version";
+ private static final String SNAPSHOT_REPOSITORY_ID = "sonatype.oss.snapshots";
+
+ @Override
+ public boolean isApplicable(@NotNull Module module) {
+ return JetPluginUtil.isMavenModule(module);
+ }
+
+ @Override
+ public boolean isConfigured(@NotNull Module module) {
+ PsiFile pomFile = findModulePomFile(module);
+ if (pomFile == null) return false;
+ String text = pomFile.getText();
+ return text.contains("" + MAVEN_PLUGIN_ID + "") &&
+ text.contains("" + STD_LIB_ID + "");
+ }
+
+ @Override
+ public void configure(Project project) {
+ List nonConfiguredModules = ConfigureKotlinInProjectUtils.getNonConfiguredModules(project, this);
+
+ ConfigureDialogWithModulesAndVersion dialog =
+ new ConfigureDialogWithModulesAndVersion(project, nonConfiguredModules, KOTLIN_VERSIONS);
+
+ dialog.show();
+ if (!dialog.isOK()) return;
+
+ for (Module module : dialog.getModulesToConfigure()) {
+ PsiFile file = findModulePomFile(module);
+ if (file != null && canConfigureFile(file)) {
+ changePomFile(module, file, dialog.getKotlinVersion());
+ }
+ else {
+ showErrorMessage(project, "Cannot find pom.xml for module " + module.getName());
+ }
+ }
+ }
+
+ protected static void changePomFile(@NotNull final Module module, final @NotNull PsiFile file, @NotNull final String version) {
+ final VirtualFile virtualFile = file.getVirtualFile();
+ assert virtualFile != null : "Virtual file should exists for psi file " + file.getName();
+ final MavenDomProjectModel domModel = MavenDomUtil.getMavenDomProjectModel(module.getProject(), virtualFile);
+ if (domModel == null) {
+ showErrorMessage(module.getProject(), null);
+ return;
+ }
+ new WriteCommandAction(file.getProject()) {
+ @Override
+ protected void run(Result result) {
+ addKotlinVersionPropertyIfNeeded(domModel, version);
+
+ if (isSnapshot(version)) {
+ addPluginRepositoryIfNeeded(domModel);
+ addLibraryRepositoryIfNeeded(domModel);
+ }
+
+ addPluginIfNeeded(domModel, module, virtualFile);
+ addLibraryDependencyIfNeeded(domModel);
+
+ CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(file);
+ }
+ }.execute();
+
+ ConfigureKotlinInProjectUtils.showInfoNotification(virtualFile.getPath() + " was modified");
+ }
+
+ private static void addKotlinVersionPropertyIfNeeded(MavenDomProjectModel domModel, String version) {
+ createTagIfNeeded(domModel.getProperties(), KOTLIN_VERSION_PROPERTY, version);
+ }
+
+ private static void addLibraryRepositoryIfNeeded(MavenDomProjectModel domModel) {
+ MavenDomRepositories repositories = domModel.getRepositories();
+ if (!isRepositoryConfigured(repositories.getRepositories())) {
+ MavenDomRepository newPluginRepository = repositories.addRepository();
+ configureRepository(newPluginRepository);
+ }
+ }
+
+ private static void addPluginRepositoryIfNeeded(MavenDomProjectModel domModel) {
+ MavenDomPluginRepositories pluginRepositories = domModel.getPluginRepositories();
+ if (!isRepositoryConfigured(pluginRepositories.getPluginRepositories())) {
+ MavenDomRepository newPluginRepository = pluginRepositories.addPluginRepository();
+ configureRepository(newPluginRepository);
+ }
+ }
+
+ private static void addLibraryDependencyIfNeeded(MavenDomProjectModel domModel) {
+ for (MavenDomDependency dependency : domModel.getDependencies().getDependencies()) {
+ if (STD_LIB_ID.equals(dependency.getArtifactId().getStringValue())) {
+ return;
+ }
+ }
+
+ MavenDomDependency dependency = MavenDomUtil.createDomDependency(domModel, null);
+ dependency.getGroupId().setStringValue("org.jetbrains.kotlin");
+ dependency.getArtifactId().setStringValue(STD_LIB_ID);
+ dependency.getVersion().setStringValue("${" + KOTLIN_VERSION_PROPERTY + "}");
+ }
+
+ private static void addPluginIfNeeded(MavenDomProjectModel domModel, Module module, VirtualFile virtualFile) {
+ MavenDomPlugins plugins = domModel.getBuild().getPlugins();
+ for (MavenDomPlugin plugin : plugins.getPlugins()) {
+ if (MAVEN_PLUGIN_ID.equals(plugin.getArtifactId().getStringValue())) {
+ return;
+ }
+ }
+ MavenDomPlugin kotlinPlugin = plugins.addPlugin();
+ kotlinPlugin.getArtifactId().setStringValue("kotlin-maven-plugin");
+ kotlinPlugin.getGroupId().setStringValue("org.jetbrains.kotlin");
+ kotlinPlugin.getVersion().setStringValue("${" + KOTLIN_VERSION_PROPERTY + "}");
+ createExecution(virtualFile, kotlinPlugin, module, false);
+ createExecution(virtualFile, kotlinPlugin, module, true);
+ }
+
+ private static boolean isRepositoryConfigured(List pluginRepositories) {
+ for (MavenDomRepository repository : pluginRepositories) {
+ if (SNAPSHOT_REPOSITORY_ID.equals(repository.getId().getStringValue())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static void configureRepository(@NotNull MavenDomRepository repository) {
+ repository.getId().setStringValue(SNAPSHOT_REPOSITORY_ID);
+ repository.getName().setStringValue("Sonatype OSS Snapshot Repository");
+ repository.getUrl().setStringValue("http://oss.sonatype.org/content/repositories/snapshots");
+ createTagIfNeeded(repository.getReleases(), "enabled", "false");
+ createTagIfNeeded(repository.getSnapshots(), "enabled", "true");
+ }
+
+ private static void createExecution(
+ @NotNull VirtualFile virtualFile,
+ @NotNull MavenDomPlugin kotlinPlugin,
+ @NotNull Module module,
+ boolean isTest
+ ) {
+ MavenDomPluginExecution execution = kotlinPlugin.getExecutions().addExecution();
+ String tagValue = isTest ? "test-compile" : "compile";
+ execution.getId().setStringValue(tagValue);
+ if (hasJavaFiles(module)) {
+ execution.getPhase().setStringValue(isTest ? "process-test-sources" : "process-sources");
+ }
+ else {
+ execution.getPhase().setStringValue(tagValue);
+ }
+ createTagIfNeeded(execution.getGoals(), "goal", tagValue);
+
+ XmlTag sourcesTag = createTagIfNeeded(execution.getConfiguration(), "sourceDirs", "");
+
+ for (ContentEntry contentEntry : ModuleRootManager.getInstance(module).getContentEntries()) {
+ SourceFolder[] folders = contentEntry.getSourceFolders();
+ for (SourceFolder sourceFolder : folders) {
+ if (isTest && sourceFolder.isTestSource() || !isTest && !sourceFolder.isTestSource()) {
+ VirtualFile sourceFolderFile = sourceFolder.getFile();
+ if (sourceFolderFile != null) {
+ String relativePath = VfsUtilCore.getRelativePath(sourceFolderFile, virtualFile.getParent(), '/');
+ XmlTag newTag = sourcesTag.createChildTag("source", sourcesTag.getNamespace(), relativePath, false);
+ sourcesTag.addSubTag(newTag, true);
+ }
+ }
+ }
+ }
+ }
+
+ private static boolean hasJavaFiles(@NotNull Module module) {
+ return !FileTypeIndex.getFiles(JavaFileType.INSTANCE, GlobalSearchScope.moduleScope(module)).isEmpty();
+ }
+
+ @Nullable
+ private static PsiFile findModulePomFile(@NotNull Module module) {
+ List files = MavenProjectsManager.getInstance(module.getProject()).getProjectsFiles();
+ for (VirtualFile file : files) {
+ Module fileModule = ModuleUtilCore.findModuleForFile(file, module.getProject());
+ if (!module.equals(fileModule)) continue;
+ PsiFile psiFile = PsiManager.getInstance(module.getProject()).findFile(file);
+ if (psiFile == null) continue;
+ if (!MavenDomUtil.isProjectFile(psiFile)) continue;
+ return psiFile;
+ }
+ return null;
+ }
+
+ private static boolean isSnapshot(@NotNull String version) {
+ return version.contains("SNAPSHOT");
+ }
+
+ @NotNull
+ private static XmlTag createTagIfNeeded(@NotNull DomElement parent, @NotNull String tagName, @NotNull String value) {
+ XmlTag parentTag = parent.ensureTagExists();
+ XmlTag tagWithGivenName = parentTag.findFirstSubTag(tagName);
+ if (tagWithGivenName != null) {
+ return tagWithGivenName;
+ }
+ XmlTag newTag = parentTag.createChildTag(tagName, parentTag.getNamespace(), value, false);
+ return parentTag.addSubTag(newTag, true);
+ }
+
+ @NotNull
+ @Override
+ public String getPresentableText() {
+ return "As Maven project";
+ }
+
+ @NotNull
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ private static boolean canConfigureFile(@NotNull PsiFile file) {
+ return WritingAccessProvider.isPotentiallyWritable(file.getVirtualFile(), null);
+ }
+
+ protected static void showErrorMessage(@NotNull Project project, @Nullable String message) {
+ Messages.showErrorDialog(project,
+ "Couldn't configure kotlin-maven plugin automatically.
" +
+ (message != null ? message : "") +
+ "See manual installation instructions here",
+ "Configure Kotlin-Maven Plugin");
+ }
+}
diff --git a/idea/testData/configuration/maven/libraryMissed/pom.xml b/idea/testData/configuration/maven/libraryMissed/pom.xml
new file mode 100644
index 00000000000..4439705ba0c
--- /dev/null
+++ b/idea/testData/configuration/maven/libraryMissed/pom.xml
@@ -0,0 +1,40 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+
+ $VERSION$
+
+
+
+
\ No newline at end of file
diff --git a/idea/testData/configuration/maven/libraryMissed/pom_after.xml b/idea/testData/configuration/maven/libraryMissed/pom_after.xml
new file mode 100644
index 00000000000..e1d3c6f429f
--- /dev/null
+++ b/idea/testData/configuration/maven/libraryMissed/pom_after.xml
@@ -0,0 +1,47 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+ $VERSION$
+
+
+
+
\ No newline at end of file
diff --git a/idea/testData/configuration/maven/pluginMissed/pom.xml b/idea/testData/configuration/maven/pluginMissed/pom.xml
new file mode 100644
index 00000000000..34d3f6a5e6a
--- /dev/null
+++ b/idea/testData/configuration/maven/pluginMissed/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+ $VERSION$
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+
+
\ No newline at end of file
diff --git a/idea/testData/configuration/maven/pluginMissed/pom_after.xml b/idea/testData/configuration/maven/pluginMissed/pom_after.xml
new file mode 100644
index 00000000000..7a854a6a48c
--- /dev/null
+++ b/idea/testData/configuration/maven/pluginMissed/pom_after.xml
@@ -0,0 +1,55 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+
+
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+
+
+
+
+ $VERSION$
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+
+
\ No newline at end of file
diff --git a/idea/testData/configuration/maven/simpleProject/pom.xml b/idea/testData/configuration/maven/simpleProject/pom.xml
new file mode 100644
index 00000000000..b53b01dacca
--- /dev/null
+++ b/idea/testData/configuration/maven/simpleProject/pom.xml
@@ -0,0 +1,12 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+
+
\ No newline at end of file
diff --git a/idea/testData/configuration/maven/simpleProject/pom_after.xml b/idea/testData/configuration/maven/simpleProject/pom_after.xml
new file mode 100644
index 00000000000..f38d4f528a7
--- /dev/null
+++ b/idea/testData/configuration/maven/simpleProject/pom_after.xml
@@ -0,0 +1,55 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+
+
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+ $VERSION$
+
+
+
+
\ No newline at end of file
diff --git a/idea/testData/configuration/maven/simpleProjectSnapshot/pom.xml b/idea/testData/configuration/maven/simpleProjectSnapshot/pom.xml
new file mode 100644
index 00000000000..9663ae6eb61
--- /dev/null
+++ b/idea/testData/configuration/maven/simpleProjectSnapshot/pom.xml
@@ -0,0 +1,15 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+
+
+
diff --git a/idea/testData/configuration/maven/simpleProjectSnapshot/pom_after.xml b/idea/testData/configuration/maven/simpleProjectSnapshot/pom_after.xml
new file mode 100644
index 00000000000..122ee2f2a96
--- /dev/null
+++ b/idea/testData/configuration/maven/simpleProjectSnapshot/pom_after.xml
@@ -0,0 +1,84 @@
+
+
+ 4.0.0
+
+ maventest
+ maventest
+ 1.0-SNAPSHOT
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+
+
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+ true
+
+ sonatype.oss.snapshots
+ Sonatype OSS Snapshot Repository
+ http://oss.sonatype.org/content/repositories/snapshots
+
+
+
+
+
+ false
+
+
+ true
+
+ sonatype.oss.snapshots
+ Sonatype OSS Snapshot Repository
+ http://oss.sonatype.org/content/repositories/snapshots
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+
+ $VERSION$
+
+
+
+
+
\ No newline at end of file
diff --git a/idea/tests/org/jetbrains/jet/plugin/configuration/AbstractConfigureGradleProjectTest.java b/idea/tests/org/jetbrains/jet/plugin/configuration/AbstractConfigureProjectByChangingFileTest.java
similarity index 51%
rename from idea/tests/org/jetbrains/jet/plugin/configuration/AbstractConfigureGradleProjectTest.java
rename to idea/tests/org/jetbrains/jet/plugin/configuration/AbstractConfigureProjectByChangingFileTest.java
index a411ba7ba6f..6a39e55a134 100644
--- a/idea/tests/org/jetbrains/jet/plugin/configuration/AbstractConfigureGradleProjectTest.java
+++ b/idea/tests/org/jetbrains/jet/plugin/configuration/AbstractConfigureProjectByChangingFileTest.java
@@ -18,30 +18,40 @@ package org.jetbrains.jet.plugin.configuration;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.idea.maven.model.MavenConstants;
import org.jetbrains.jet.InTextDirectivesUtils;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
-public abstract class AbstractConfigureGradleProjectTest extends LightCodeInsightTestCase {
+public abstract class AbstractConfigureProjectByChangingFileTest extends LightCodeInsightTestCase {
private static final String DEFAULT_VERSION = "default_version";
+ public void doTestWithMaven(@NotNull String path) throws Exception {
+ String pathWithFile = path + "/" + MavenConstants.POM_XML;
+ doTest(pathWithFile, pathWithFile.replace("pom", "pom_after"), new KotlinMavenConfigurator());
+ }
+
public void doTestAndroidGradle(@NotNull String path) throws Exception {
- doTest(path, new KotlinAndroidGradleModuleConfigurator());
+ doTest(path, path.replace("before", "after"), new KotlinAndroidGradleModuleConfigurator());
}
public void doTestGradle(@NotNull String path) throws Exception {
- doTest(path, new KotlinGradleModuleConfigurator());
+ doTest(path, path.replace("before", "after"), new KotlinGradleModuleConfigurator());
}
- private void doTest(@NotNull String path, @NotNull KotlinWithGradleConfigurator configurator) throws Exception {
- configureByFile(path);
- GroovyFile groovyFile = (GroovyFile) getFile();
+ private void doTest(@NotNull String beforeFile, @NotNull String afterFile, @NotNull KotlinProjectConfigurator configurator) throws Exception {
+ configureByFile(beforeFile);
- String versionFromFile = InTextDirectivesUtils.findStringWithPrefixes(groovyFile.getText(), "// VERSION:");
+ String versionFromFile = InTextDirectivesUtils.findStringWithPrefixes(getFile().getText(), "// VERSION:");
String version = versionFromFile != null ? versionFromFile : DEFAULT_VERSION;
- configurator.changeGradleFile(groovyFile, version);
+ if (configurator instanceof KotlinWithGradleConfigurator) {
+ ((KotlinWithGradleConfigurator) configurator).changeGradleFile((GroovyFile) getFile(), version);
+ }
+ else if (configurator instanceof KotlinMavenConfigurator) {
+ KotlinMavenConfigurator.changePomFile(getModule(), getFile(), version);
+ }
- assertSameLinesWithFile(path.replace("before", "after"), groovyFile.getText().replace(version, "$VERSION$"));
+ assertSameLinesWithFile(afterFile, getFile().getText().replace(version, "$VERSION$"));
}
@NotNull
diff --git a/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureGradleProjectTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureProjectByChangingFileTestGenerated.java
similarity index 81%
rename from idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureGradleProjectTestGenerated.java
rename to idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureProjectByChangingFileTestGenerated.java
index eea657b5a94..6731a5b2515 100644
--- a/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureGradleProjectTestGenerated.java
+++ b/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureProjectByChangingFileTestGenerated.java
@@ -26,15 +26,15 @@ import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
-import org.jetbrains.jet.plugin.configuration.AbstractConfigureGradleProjectTest;
+import org.jetbrains.jet.plugin.configuration.AbstractConfigureProjectByChangingFileTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
-@InnerTestClasses({ConfigureGradleProjectTestGenerated.Android_gradle.class, ConfigureGradleProjectTestGenerated.Gradle.class})
-public class ConfigureGradleProjectTestGenerated extends AbstractConfigureGradleProjectTest {
+@InnerTestClasses({ConfigureProjectByChangingFileTestGenerated.Android_gradle.class, ConfigureProjectByChangingFileTestGenerated.Gradle.class, ConfigureProjectByChangingFileTestGenerated.Maven.class})
+public class ConfigureProjectByChangingFileTestGenerated extends AbstractConfigureProjectByChangingFileTest {
@TestMetadata("idea/testData/configuration/android-gradle")
@InnerTestClasses({Android_gradle.GradleExamples.class})
- public static class Android_gradle extends AbstractConfigureGradleProjectTest {
+ public static class Android_gradle extends AbstractConfigureProjectByChangingFileTest {
public void testAllFilesPresentInAndroid_gradle() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/configuration/android-gradle"), Pattern.compile("(\\w+)_before\\.gradle$"), true);
}
@@ -95,7 +95,7 @@ public class ConfigureGradleProjectTestGenerated extends AbstractConfigureGradle
}
@TestMetadata("idea/testData/configuration/android-gradle/gradleExamples")
- public static class GradleExamples extends AbstractConfigureGradleProjectTest {
+ public static class GradleExamples extends AbstractConfigureProjectByChangingFileTest {
public void testAllFilesPresentInGradleExamples() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/configuration/android-gradle/gradleExamples"), Pattern.compile("(\\w+)_before\\.gradle$"), true);
}
@@ -156,7 +156,7 @@ public class ConfigureGradleProjectTestGenerated extends AbstractConfigureGradle
}
@TestMetadata("idea/testData/configuration/gradle")
- public static class Gradle extends AbstractConfigureGradleProjectTest {
+ public static class Gradle extends AbstractConfigureProjectByChangingFileTest {
public void testAllFilesPresentInGradle() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/configuration/gradle"), Pattern.compile("(\\w+)_before\\.gradle$"), true);
}
@@ -173,10 +173,39 @@ public class ConfigureGradleProjectTestGenerated extends AbstractConfigureGradle
}
+ @TestMetadata("idea/testData/configuration/maven")
+ public static class Maven extends AbstractConfigureProjectByChangingFileTest {
+ public void testAllFilesPresentInMaven() throws Exception {
+ JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/configuration/maven"), Pattern.compile("^(.+)$"), false);
+ }
+
+ @TestMetadata("libraryMissed")
+ public void testLibraryMissed() throws Exception {
+ doTestWithMaven("idea/testData/configuration/maven/libraryMissed");
+ }
+
+ @TestMetadata("pluginMissed")
+ public void testPluginMissed() throws Exception {
+ doTestWithMaven("idea/testData/configuration/maven/pluginMissed");
+ }
+
+ @TestMetadata("simpleProject")
+ public void testSimpleProject() throws Exception {
+ doTestWithMaven("idea/testData/configuration/maven/simpleProject");
+ }
+
+ @TestMetadata("simpleProjectSnapshot")
+ public void testSimpleProjectSnapshot() throws Exception {
+ doTestWithMaven("idea/testData/configuration/maven/simpleProjectSnapshot");
+ }
+
+ }
+
public static Test suite() {
- TestSuite suite = new TestSuite("ConfigureGradleProjectTestGenerated");
+ TestSuite suite = new TestSuite("ConfigureProjectByChangingFileTestGenerated");
suite.addTest(Android_gradle.innerSuite());
suite.addTestSuite(Gradle.class);
+ suite.addTestSuite(Maven.class);
return suite;
}
}