Add Maven Configurator
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||
<projectConfigurator implementation="org.jetbrains.jet.plugin.configuration.KotlinMavenConfigurator"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -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("<artifactId>" + MAVEN_PLUGIN_ID + "</artifactId>") &&
|
||||
text.contains("<artifactId>" + STD_LIB_ID + "</artifactId>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Project project) {
|
||||
List<Module> 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<MavenDomRepository> 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<VirtualFile> 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,
|
||||
"<html>Couldn't configure kotlin-maven plugin automatically.<br/>" +
|
||||
(message != null ? message : "") +
|
||||
"See manual installation instructions <a href=\"http://confluence.jetbrains.com/display/Kotlin/Kotlin+Build+Tools#KotlinBuildTools-Maven\">here</a></html>",
|
||||
"Configure Kotlin-Maven Plugin");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<kotlin.version>$VERSION$</kotlin.version>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<kotlin.version>$VERSION$</kotlin.version>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<kotlin.version>$VERSION$</kotlin.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<source></source>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs></sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<kotlin.version>$VERSION$</kotlin.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<source></source>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs></sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<kotlin.version>$VERSION$</kotlin.version>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
|
||||
</project>
|
||||
<!--
|
||||
// VERSION: 0.1-SNAPSHOT
|
||||
-->
|
||||
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<source></source>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs></sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<id>sonatype.oss.snapshots</id>
|
||||
<name>Sonatype OSS Snapshot Repository</name>
|
||||
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<id>sonatype.oss.snapshots</id>
|
||||
<name>Sonatype OSS Snapshot Repository</name>
|
||||
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<kotlin.version>$VERSION$</kotlin.version>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
||||
<!--
|
||||
// VERSION: $VERSION$
|
||||
-->
|
||||
+19
-9
@@ -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
|
||||
+36
-7
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user