Configuration for EAP versions

This commit is contained in:
Nikolay Krasko
2016-04-12 15:41:04 +03:00
committed by Nikolay Krasko
parent c5ef562f54
commit 46eed6fa4d
13 changed files with 396 additions and 35 deletions
@@ -30,6 +30,22 @@ import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.idea.versions.getKotlinRuntimeMarkerClass
import org.jetbrains.kotlin.utils.ifEmpty
data class RepositoryDescription(val id: String, val name: String, val url: String, val isSnapshot: Boolean)
@JvmField
val SNAPSHOT_REPOSITORY = RepositoryDescription(
"sonatype.oss.snapshots",
"Sonatype OSS Snapshot Repository",
"http://oss.sonatype.org/content/repositories/snapshots",
isSnapshot = true)
@JvmField
val EAP_REPOSITORY = RepositoryDescription(
"bintray.kotlin.eap",
"Bintray Kotlin EAP Repository",
"http://dl.bintray.com/kotlin/kotlin-eap",
isSnapshot = false)
fun isProjectConfigured(project: Project): Boolean {
val modules = getModulesWithKotlinFiles(project)
return modules.all { isModuleConfigured(it) }
@@ -119,3 +135,12 @@ fun hasKotlinFilesOnlyInTests(module: Module): Boolean {
fun hasKotlinFilesInSources(module: Module): Boolean {
return FileTypeIndex.containsFileOfType(KotlinFileType.INSTANCE, module.getModuleScope(false))
}
fun isSnapshot(version: String): Boolean {
return version.contains("SNAPSHOT")
}
fun isEap(version: String): Boolean {
return version.contains("rc") || version.contains("eap")
}
@@ -41,14 +41,26 @@ class GradleKotlinJavaFrameworkSupportProvider() : GradleFrameworkSupportProvide
modifiableModelsProvider: ModifiableModelsProvider,
buildScriptData: BuildScriptDataBuilder) {
var kotlinVersion = bundledRuntimeVersion()
if (kotlinVersion == "@snapshot@") {
kotlinVersion = "0.1-SNAPSHOT"
val snapshotRepository = KotlinWithGradleConfigurator.SNAPSHOT_REPOSITORY.replace('\n', ' ')
buildScriptData.addBuildscriptRepositoriesDefinition(snapshotRepository)
val additionalRepository: String? = when {
kotlinVersion == "@snapshot@" -> {
kotlinVersion = "0.1-SNAPSHOT"
KotlinWithGradleConfigurator.SNAPSHOT_REPOSITORY
}
isEap(kotlinVersion) -> {
KotlinWithGradleConfigurator.EAP_REPOSITORY
}
else -> {
null
}
}
if (additionalRepository != null) {
val oneLineRepository = additionalRepository.replace('\n', ' ')
buildScriptData.addBuildscriptRepositoriesDefinition(oneLineRepository)
buildScriptData.addRepositoriesDefinition("mavenCentral()")
buildScriptData.addRepositoriesDefinition(snapshotRepository)
buildScriptData.addRepositoriesDefinition(oneLineRepository)
}
buildScriptData
@@ -43,7 +43,6 @@ import org.jetbrains.idea.maven.dom.MavenDomUtil;
import org.jetbrains.idea.maven.dom.model.*;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.jps.model.java.JavaSourceRootType;
import org.jetbrains.kotlin.cli.common.KotlinVersion;
import org.jetbrains.kotlin.idea.KotlinPluginUtil;
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion;
@@ -56,7 +55,6 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat
private static final String GROUP_ID = "org.jetbrains.kotlin";
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";
private static final String PROCESS_TEST_SOURCES_PHASE = "process-test-sources";
private static final String PROCESS_SOURCES_PHASE = "process-sources";
@@ -161,9 +159,14 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat
protected void run(@NotNull Result result) {
addKotlinVersionPropertyIfNeeded(domModel, version);
if (isSnapshot(version)) {
addPluginRepositoryIfNeeded(domModel);
addLibraryRepositoryIfNeeded(domModel);
if (ConfigureKotlinInProjectUtilsKt.isSnapshot(version)) {
addPluginRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.SNAPSHOT_REPOSITORY);
addLibraryRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.SNAPSHOT_REPOSITORY);
}
if (ConfigureKotlinInProjectUtilsKt.isEap(version)) {
addPluginRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.EAP_REPOSITORY);
addLibraryRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.EAP_REPOSITORY);
}
addPluginIfNeeded(domModel, module, virtualFile);
@@ -251,19 +254,19 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat
createTagIfNeeded(domModel.getProperties(), KOTLIN_VERSION_PROPERTY, version);
}
private static void addLibraryRepositoryIfNeeded(MavenDomProjectModel domModel) {
private static void addLibraryRepositoryIfNeeded(MavenDomProjectModel domModel, RepositoryDescription description) {
MavenDomRepositories repositories = domModel.getRepositories();
if (!isRepositoryConfigured(repositories.getRepositories())) {
if (!isRepositoryConfigured(repositories.getRepositories(), description.getId())) {
MavenDomRepository newPluginRepository = repositories.addRepository();
configureRepository(newPluginRepository);
configureRepository(newPluginRepository, description);
}
}
private static void addPluginRepositoryIfNeeded(MavenDomProjectModel domModel) {
private static void addPluginRepositoryIfNeeded(MavenDomProjectModel domModel, RepositoryDescription description) {
MavenDomPluginRepositories pluginRepositories = domModel.getPluginRepositories();
if (!isRepositoryConfigured(pluginRepositories.getPluginRepositories())) {
if (!isRepositoryConfigured(pluginRepositories.getPluginRepositories(), description.getId())) {
MavenDomRepository newPluginRepository = pluginRepositories.addPluginRepository();
configureRepository(newPluginRepository);
configureRepository(newPluginRepository, description);
}
}
@@ -294,21 +297,25 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat
createExecutions(virtualFile, kotlinPlugin, module);
}
private static boolean isRepositoryConfigured(List<MavenDomRepository> pluginRepositories) {
private static boolean isRepositoryConfigured(List<MavenDomRepository> pluginRepositories, String repositoryId) {
for (MavenDomRepository repository : pluginRepositories) {
if (SNAPSHOT_REPOSITORY_ID.equals(repository.getId().getStringValue())) {
if (repositoryId.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 configureRepository(
@NotNull MavenDomRepository repository,
@NotNull RepositoryDescription repositoryDescription
) {
repository.getId().setStringValue(repositoryDescription.getId());
repository.getName().setStringValue(repositoryDescription.getName());
repository.getUrl().setStringValue(repositoryDescription.getUrl());
createTagIfNeeded(repository.getReleases(), "enabled", Boolean.toString(!repositoryDescription.isSnapshot()));
createTagIfNeeded(repository.getSnapshots(), "enabled", Boolean.toString(repositoryDescription.isSnapshot()));
}
@NotNull
@@ -337,10 +344,6 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat
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();
@@ -58,7 +58,10 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
private static final String VERSION_TEMPLATE = "$VERSION$";
protected static final String CLASSPATH = "classpath \"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version\"";
protected static final String SNAPSHOT_REPOSITORY = "maven {\nurl 'http://oss.sonatype.org/content/repositories/snapshots'\n}";
protected static final String SNAPSHOT_REPOSITORY = "maven {\nurl '" + ConfigureKotlinInProjectUtilsKt.SNAPSHOT_REPOSITORY.getUrl() + "'\n}";
protected static final String EAP_REPOSITORY = "maven {\nurl '" + ConfigureKotlinInProjectUtilsKt.EAP_REPOSITORY.getUrl() + "'\n}";
private static final String MAVEN_CENTRAL = "mavenCentral()\n";
private static final String JCENTER = "jcenter()\n";
public static final String LIBRARY = "compile \"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version\"";
@@ -219,9 +222,12 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
wasModified = addFirstExpressionInBlockIfNeeded(VERSION.replace(VERSION_TEMPLATE, version), buildScriptBlock);
GrClosableBlock buildScriptRepositoriesBlock = getBuildScriptRepositoriesBlock(file);
if (isSnapshot(version)) {
if (ConfigureKotlinInProjectUtilsKt.isSnapshot(version)) {
wasModified |= addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, buildScriptRepositoriesBlock);
}
else if (ConfigureKotlinInProjectUtilsKt.isEap(version)) {
wasModified |= addLastExpressionInBlockIfNeeded(EAP_REPOSITORY, buildScriptRepositoriesBlock);
}
else if (!isRepositoryConfigured(buildScriptRepositoriesBlock)) {
wasModified |= addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, buildScriptRepositoriesBlock);
}
@@ -262,9 +268,12 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
}
GrClosableBlock repositoriesBlock = getRepositoriesBlock(file);
if (isSnapshot(version)) {
if (ConfigureKotlinInProjectUtilsKt.isSnapshot(version)) {
wasModified |= addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, repositoriesBlock);
}
else if (ConfigureKotlinInProjectUtilsKt.isEap(version)) {
wasModified |= addLastExpressionInBlockIfNeeded(EAP_REPOSITORY, repositoriesBlock);
}
else if (!isRepositoryConfigured(repositoriesBlock)) {
wasModified |= addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, repositoriesBlock);
}
@@ -332,10 +341,6 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
return null;
}
private static boolean isSnapshot(@NotNull String version) {
return version.contains("SNAPSHOT");
}
protected boolean changeGradleFile(
@NotNull final GroovyFile groovyFile,
final boolean isTopLevelProjectFile,
@@ -0,0 +1,33 @@
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
buildscript {
ext.kotlin_version = '$VERSION$'
repositories {
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
// VERSION: $VERSION$
@@ -0,0 +1,14 @@
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
// VERSION: 1.0.2-eap-14-IJ143-14
@@ -0,0 +1,33 @@
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
buildscript {
ext.kotlin_version = '$VERSION$'
repositories {
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap'
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
// VERSION: $VERSION$
@@ -0,0 +1,14 @@
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
// VERSION: 1.0.1-rc-26-IJ143-42
@@ -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: 1.0.2-eap-1
-->
@@ -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>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray.kotlin.eap</id>
<name>Bintray Kotlin EAP Repository</name>
<url>http://dl.bintray.com/kotlin/kotlin-eap</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray.kotlin.eap</id>
<name>Bintray Kotlin EAP Repository</name>
<url>http://dl.bintray.com/kotlin/kotlin-eap</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$
-->
@@ -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: 1.0.1-rc-20
-->
@@ -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>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray.kotlin.eap</id>
<name>Bintray Kotlin EAP Repository</name>
<url>http://dl.bintray.com/kotlin/kotlin-eap</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray.kotlin.eap</id>
<name>Bintray Kotlin EAP Repository</name>
<url>http://dl.bintray.com/kotlin/kotlin-eap</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$
-->
@@ -43,6 +43,12 @@ public class ConfigureProjectByChangingFileTestGenerated extends AbstractConfigu
doTestGradle(fileName);
}
@TestMetadata("eapVersion_before.gradle")
public void testEapVersion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/eapVersion_before.gradle");
doTestGradle(fileName);
}
@TestMetadata("missedLibrary_before.gradle")
public void testMissedLibrary() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/missedLibrary_before.gradle");
@@ -54,6 +60,12 @@ public class ConfigureProjectByChangingFileTestGenerated extends AbstractConfigu
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/plugin_present_before.gradle");
doTestGradle(fileName);
}
@TestMetadata("rcVersion_before.gradle")
public void testRcVersion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/rcVersion_before.gradle");
doTestGradle(fileName);
}
}
@TestMetadata("idea/testData/configuration/maven")
@@ -82,6 +94,18 @@ public class ConfigureProjectByChangingFileTestGenerated extends AbstractConfigu
doTestWithMaven(fileName);
}
@TestMetadata("simpleProjectEAP")
public void testSimpleProjectEAP() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/maven/simpleProjectEAP/");
doTestWithMaven(fileName);
}
@TestMetadata("simpleProjectRc")
public void testSimpleProjectRc() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/maven/simpleProjectRc/");
doTestWithMaven(fileName);
}
@TestMetadata("simpleProjectSnapshot")
public void testSimpleProjectSnapshot() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/maven/simpleProjectSnapshot/");