Skip to content

Commit 46eed6f

Browse files
committed
Configuration for EAP versions
1 parent c5ef562 commit 46eed6f

File tree

13 files changed

+396
-35
lines changed

13 files changed

+396
-35
lines changed

idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ import org.jetbrains.kotlin.idea.util.projectStructure.allModules
3030
import org.jetbrains.kotlin.idea.versions.getKotlinRuntimeMarkerClass
3131
import org.jetbrains.kotlin.utils.ifEmpty
3232

33+
data class RepositoryDescription(val id: String, val name: String, val url: String, val isSnapshot: Boolean)
34+
35+
@JvmField
36+
val SNAPSHOT_REPOSITORY = RepositoryDescription(
37+
"sonatype.oss.snapshots",
38+
"Sonatype OSS Snapshot Repository",
39+
"http://oss.sonatype.org/content/repositories/snapshots",
40+
isSnapshot = true)
41+
42+
@JvmField
43+
val EAP_REPOSITORY = RepositoryDescription(
44+
"bintray.kotlin.eap",
45+
"Bintray Kotlin EAP Repository",
46+
"http://dl.bintray.com/kotlin/kotlin-eap",
47+
isSnapshot = false)
48+
3349
fun isProjectConfigured(project: Project): Boolean {
3450
val modules = getModulesWithKotlinFiles(project)
3551
return modules.all { isModuleConfigured(it) }
@@ -119,3 +135,12 @@ fun hasKotlinFilesOnlyInTests(module: Module): Boolean {
119135
fun hasKotlinFilesInSources(module: Module): Boolean {
120136
return FileTypeIndex.containsFileOfType(KotlinFileType.INSTANCE, module.getModuleScope(false))
121137
}
138+
139+
fun isSnapshot(version: String): Boolean {
140+
return version.contains("SNAPSHOT")
141+
}
142+
143+
fun isEap(version: String): Boolean {
144+
return version.contains("rc") || version.contains("eap")
145+
}
146+

idea/src/org/jetbrains/kotlin/idea/configuration/GradleKotlinJavaFrameworkSupportProvider.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,26 @@ class GradleKotlinJavaFrameworkSupportProvider() : GradleFrameworkSupportProvide
4141
modifiableModelsProvider: ModifiableModelsProvider,
4242
buildScriptData: BuildScriptDataBuilder) {
4343
var kotlinVersion = bundledRuntimeVersion()
44-
if (kotlinVersion == "@snapshot@") {
45-
kotlinVersion = "0.1-SNAPSHOT"
4644

47-
val snapshotRepository = KotlinWithGradleConfigurator.SNAPSHOT_REPOSITORY.replace('\n', ' ')
48-
buildScriptData.addBuildscriptRepositoriesDefinition(snapshotRepository)
45+
val additionalRepository: String? = when {
46+
kotlinVersion == "@snapshot@" -> {
47+
kotlinVersion = "0.1-SNAPSHOT"
48+
KotlinWithGradleConfigurator.SNAPSHOT_REPOSITORY
49+
}
50+
isEap(kotlinVersion) -> {
51+
KotlinWithGradleConfigurator.EAP_REPOSITORY
52+
}
53+
else -> {
54+
null
55+
}
56+
}
57+
58+
if (additionalRepository != null) {
59+
val oneLineRepository = additionalRepository.replace('\n', ' ')
60+
buildScriptData.addBuildscriptRepositoriesDefinition(oneLineRepository)
4961

5062
buildScriptData.addRepositoriesDefinition("mavenCentral()")
51-
buildScriptData.addRepositoriesDefinition(snapshotRepository)
63+
buildScriptData.addRepositoriesDefinition(oneLineRepository)
5264
}
5365

5466
buildScriptData

idea/src/org/jetbrains/kotlin/idea/configuration/KotlinMavenConfigurator.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.jetbrains.idea.maven.dom.model.*;
4444
import org.jetbrains.idea.maven.project.MavenProjectsManager;
4545
import org.jetbrains.jps.model.java.JavaSourceRootType;
46-
import org.jetbrains.kotlin.cli.common.KotlinVersion;
4746
import org.jetbrains.kotlin.idea.KotlinPluginUtil;
4847
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion;
4948

@@ -56,7 +55,6 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat
5655
private static final String GROUP_ID = "org.jetbrains.kotlin";
5756
private static final String MAVEN_PLUGIN_ID = "kotlin-maven-plugin";
5857
private static final String KOTLIN_VERSION_PROPERTY = "kotlin.version";
59-
private static final String SNAPSHOT_REPOSITORY_ID = "sonatype.oss.snapshots";
6058

6159
private static final String PROCESS_TEST_SOURCES_PHASE = "process-test-sources";
6260
private static final String PROCESS_SOURCES_PHASE = "process-sources";
@@ -161,9 +159,14 @@ protected void changePomFile(
161159
protected void run(@NotNull Result result) {
162160
addKotlinVersionPropertyIfNeeded(domModel, version);
163161

164-
if (isSnapshot(version)) {
165-
addPluginRepositoryIfNeeded(domModel);
166-
addLibraryRepositoryIfNeeded(domModel);
162+
if (ConfigureKotlinInProjectUtilsKt.isSnapshot(version)) {
163+
addPluginRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.SNAPSHOT_REPOSITORY);
164+
addLibraryRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.SNAPSHOT_REPOSITORY);
165+
}
166+
167+
if (ConfigureKotlinInProjectUtilsKt.isEap(version)) {
168+
addPluginRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.EAP_REPOSITORY);
169+
addLibraryRepositoryIfNeeded(domModel, ConfigureKotlinInProjectUtilsKt.EAP_REPOSITORY);
167170
}
168171

169172
addPluginIfNeeded(domModel, module, virtualFile);
@@ -251,19 +254,19 @@ private static void addKotlinVersionPropertyIfNeeded(MavenDomProjectModel domMod
251254
createTagIfNeeded(domModel.getProperties(), KOTLIN_VERSION_PROPERTY, version);
252255
}
253256

254-
private static void addLibraryRepositoryIfNeeded(MavenDomProjectModel domModel) {
257+
private static void addLibraryRepositoryIfNeeded(MavenDomProjectModel domModel, RepositoryDescription description) {
255258
MavenDomRepositories repositories = domModel.getRepositories();
256-
if (!isRepositoryConfigured(repositories.getRepositories())) {
259+
if (!isRepositoryConfigured(repositories.getRepositories(), description.getId())) {
257260
MavenDomRepository newPluginRepository = repositories.addRepository();
258-
configureRepository(newPluginRepository);
261+
configureRepository(newPluginRepository, description);
259262
}
260263
}
261264

262-
private static void addPluginRepositoryIfNeeded(MavenDomProjectModel domModel) {
265+
private static void addPluginRepositoryIfNeeded(MavenDomProjectModel domModel, RepositoryDescription description) {
263266
MavenDomPluginRepositories pluginRepositories = domModel.getPluginRepositories();
264-
if (!isRepositoryConfigured(pluginRepositories.getPluginRepositories())) {
267+
if (!isRepositoryConfigured(pluginRepositories.getPluginRepositories(), description.getId())) {
265268
MavenDomRepository newPluginRepository = pluginRepositories.addPluginRepository();
266-
configureRepository(newPluginRepository);
269+
configureRepository(newPluginRepository, description);
267270
}
268271
}
269272

@@ -294,21 +297,25 @@ private void addPluginIfNeeded(MavenDomProjectModel domModel, Module module, Vir
294297
createExecutions(virtualFile, kotlinPlugin, module);
295298
}
296299

297-
private static boolean isRepositoryConfigured(List<MavenDomRepository> pluginRepositories) {
300+
private static boolean isRepositoryConfigured(List<MavenDomRepository> pluginRepositories, String repositoryId) {
298301
for (MavenDomRepository repository : pluginRepositories) {
299-
if (SNAPSHOT_REPOSITORY_ID.equals(repository.getId().getStringValue())) {
302+
if (repositoryId.equals(repository.getId().getStringValue())) {
300303
return true;
301304
}
302305
}
303306
return false;
304307
}
305308

306-
private static void configureRepository(@NotNull MavenDomRepository repository) {
307-
repository.getId().setStringValue(SNAPSHOT_REPOSITORY_ID);
308-
repository.getName().setStringValue("Sonatype OSS Snapshot Repository");
309-
repository.getUrl().setStringValue("http://oss.sonatype.org/content/repositories/snapshots");
310-
createTagIfNeeded(repository.getReleases(), "enabled", "false");
311-
createTagIfNeeded(repository.getSnapshots(), "enabled", "true");
309+
private static void configureRepository(
310+
@NotNull MavenDomRepository repository,
311+
@NotNull RepositoryDescription repositoryDescription
312+
) {
313+
repository.getId().setStringValue(repositoryDescription.getId());
314+
repository.getName().setStringValue(repositoryDescription.getName());
315+
repository.getUrl().setStringValue(repositoryDescription.getUrl());
316+
317+
createTagIfNeeded(repository.getReleases(), "enabled", Boolean.toString(!repositoryDescription.isSnapshot()));
318+
createTagIfNeeded(repository.getSnapshots(), "enabled", Boolean.toString(repositoryDescription.isSnapshot()));
312319
}
313320

314321
@NotNull
@@ -337,10 +344,6 @@ private static PsiFile findModulePomFile(@NotNull Module module) {
337344
return null;
338345
}
339346

340-
private static boolean isSnapshot(@NotNull String version) {
341-
return version.contains("SNAPSHOT");
342-
}
343-
344347
@NotNull
345348
private static XmlTag createTagIfNeeded(@NotNull DomElement parent, @NotNull String tagName, @NotNull String value) {
346349
XmlTag parentTag = parent.ensureTagExists();

idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
5858
private static final String VERSION_TEMPLATE = "$VERSION$";
5959

6060
protected static final String CLASSPATH = "classpath \"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version\"";
61-
protected static final String SNAPSHOT_REPOSITORY = "maven {\nurl 'http://oss.sonatype.org/content/repositories/snapshots'\n}";
61+
62+
protected static final String SNAPSHOT_REPOSITORY = "maven {\nurl '" + ConfigureKotlinInProjectUtilsKt.SNAPSHOT_REPOSITORY.getUrl() + "'\n}";
63+
protected static final String EAP_REPOSITORY = "maven {\nurl '" + ConfigureKotlinInProjectUtilsKt.EAP_REPOSITORY.getUrl() + "'\n}";
64+
6265
private static final String MAVEN_CENTRAL = "mavenCentral()\n";
6366
private static final String JCENTER = "jcenter()\n";
6467
public static final String LIBRARY = "compile \"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version\"";
@@ -219,9 +222,12 @@ protected static boolean addElementsToProjectFile(@NotNull GroovyFile file, @Not
219222
wasModified = addFirstExpressionInBlockIfNeeded(VERSION.replace(VERSION_TEMPLATE, version), buildScriptBlock);
220223

221224
GrClosableBlock buildScriptRepositoriesBlock = getBuildScriptRepositoriesBlock(file);
222-
if (isSnapshot(version)) {
225+
if (ConfigureKotlinInProjectUtilsKt.isSnapshot(version)) {
223226
wasModified |= addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, buildScriptRepositoriesBlock);
224227
}
228+
else if (ConfigureKotlinInProjectUtilsKt.isEap(version)) {
229+
wasModified |= addLastExpressionInBlockIfNeeded(EAP_REPOSITORY, buildScriptRepositoriesBlock);
230+
}
225231
else if (!isRepositoryConfigured(buildScriptRepositoriesBlock)) {
226232
wasModified |= addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, buildScriptRepositoriesBlock);
227233
}
@@ -262,9 +268,12 @@ protected boolean addElementsToModuleFile(@NotNull GroovyFile file, @NotNull Str
262268
}
263269

264270
GrClosableBlock repositoriesBlock = getRepositoriesBlock(file);
265-
if (isSnapshot(version)) {
271+
if (ConfigureKotlinInProjectUtilsKt.isSnapshot(version)) {
266272
wasModified |= addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, repositoriesBlock);
267273
}
274+
else if (ConfigureKotlinInProjectUtilsKt.isEap(version)) {
275+
wasModified |= addLastExpressionInBlockIfNeeded(EAP_REPOSITORY, repositoriesBlock);
276+
}
268277
else if (!isRepositoryConfigured(repositoriesBlock)) {
269278
wasModified |= addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, repositoriesBlock);
270279
}
@@ -332,10 +341,6 @@ private static String getModuleFilePath(@NotNull Module module) {
332341
return null;
333342
}
334343

335-
private static boolean isSnapshot(@NotNull String version) {
336-
return version.contains("SNAPSHOT");
337-
}
338-
339344
protected boolean changeGradleFile(
340345
@NotNull final GroovyFile groovyFile,
341346
final boolean isTopLevelProjectFile,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'java'
2+
apply plugin: 'kotlin'
3+
4+
sourceCompatibility = 1.5
5+
version = '1.0'
6+
7+
repositories {
8+
mavenCentral()
9+
maven {
10+
url 'http://dl.bintray.com/kotlin/kotlin-eap'
11+
}
12+
}
13+
14+
dependencies {
15+
testCompile group: 'junit', name: 'junit', version: '4.11'
16+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
17+
}
18+
buildscript {
19+
ext.kotlin_version = '$VERSION$'
20+
repositories {
21+
maven {
22+
url 'http://dl.bintray.com/kotlin/kotlin-eap'
23+
}
24+
}
25+
dependencies {
26+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
27+
}
28+
}
29+
sourceSets {
30+
main.java.srcDirs += 'src/main/kotlin'
31+
}
32+
33+
// VERSION: $VERSION$
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apply plugin: 'java'
2+
3+
sourceCompatibility = 1.5
4+
version = '1.0'
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
testCompile group: 'junit', name: 'junit', version: '4.11'
12+
}
13+
14+
// VERSION: 1.0.2-eap-14-IJ143-14
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'java'
2+
apply plugin: 'kotlin'
3+
4+
sourceCompatibility = 1.5
5+
version = '1.0'
6+
7+
repositories {
8+
mavenCentral()
9+
maven {
10+
url 'http://dl.bintray.com/kotlin/kotlin-eap'
11+
}
12+
}
13+
14+
dependencies {
15+
testCompile group: 'junit', name: 'junit', version: '4.11'
16+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
17+
}
18+
buildscript {
19+
ext.kotlin_version = '$VERSION$'
20+
repositories {
21+
maven {
22+
url 'http://dl.bintray.com/kotlin/kotlin-eap'
23+
}
24+
}
25+
dependencies {
26+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
27+
}
28+
}
29+
sourceSets {
30+
main.java.srcDirs += 'src/main/kotlin'
31+
}
32+
33+
// VERSION: $VERSION$
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apply plugin: 'java'
2+
3+
sourceCompatibility = 1.5
4+
version = '1.0'
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
testCompile group: 'junit', name: 'junit', version: '4.11'
12+
}
13+
14+
// VERSION: 1.0.1-rc-26-IJ143-42
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>maventest</groupId>
8+
<artifactId>maventest</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
</project>
13+
<!--
14+
// VERSION: 1.0.2-eap-1
15+
-->

0 commit comments

Comments
 (0)