Add new Gradle with Kotlin DSL project wizard for Kotlin, KotlinJS, Java, Groovy
#KT-20308 Fixed Target Version 1.2
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||||
</content>
|
</content>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#if (${MODULE_GROUP} && ${MODULE_GROUP} != "")
|
#if (${MODULE_GROUP} && ${MODULE_GROUP} != "")
|
||||||
group '${MODULE_GROUP}'
|
group = "${MODULE_GROUP}"
|
||||||
#end
|
#end
|
||||||
#if (${MODULE_VERSION} && ${MODULE_VERSION} != "")
|
#if (${MODULE_VERSION} && ${MODULE_VERSION} != "")
|
||||||
version '${MODULE_VERSION}'
|
version = "${MODULE_VERSION}"
|
||||||
#end
|
#end
|
||||||
|
|||||||
@@ -14,4 +14,7 @@ include '${MODULE_PATH}'
|
|||||||
findProject(':${MODULE_PATH}')?.name = '${MODULE_NAME}'
|
findProject(':${MODULE_PATH}')?.name = '${MODULE_NAME}'
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
#if (${BUILD_FILE_NAME} && ${BUILD_FILE_NAME} != "")
|
||||||
|
rootProject.buildFileName = '${BUILD_FILE_NAME}'
|
||||||
|
#end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:JvmName("GradleKotlinDSLConstants")
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.kdsl
|
||||||
|
|
||||||
|
const val DEFAULT_SCRIPT_NAME = "build.gradle.kts"
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.gradle.service.project.wizard.GradleFrameworksWizardStep">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.gradle.kdsl.GradleFrameworksWizardStep">
|
||||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
|
|||||||
+5
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2015 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.plugins.gradle.service.project.wizard;
|
package org.jetbrains.kotlin.gradle.kdsl;
|
||||||
|
|
||||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||||
import com.intellij.ide.util.newProjectWizard.AddSupportForFrameworksPanel;
|
import com.intellij.ide.util.newProjectWizard.AddSupportForFrameworksPanel;
|
||||||
@@ -32,18 +32,14 @@ import com.intellij.openapi.util.text.StringUtil;
|
|||||||
import com.intellij.ui.components.JBLabel;
|
import com.intellij.ui.components.JBLabel;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.plugins.gradle.frameworkSupport.GradleFrameworkSupportProvider;
|
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleFrameworkSupportProvider;
|
||||||
import org.jetbrains.plugins.gradle.frameworkSupport.GradleJavaFrameworkSupportProvider;
|
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleJavaFrameworkSupportProvider;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Vladislav.Soroka
|
|
||||||
* @since 4/20/2015
|
|
||||||
*/
|
|
||||||
public class GradleFrameworksWizardStep extends ModuleWizardStep implements Disposable {
|
public class GradleFrameworksWizardStep extends ModuleWizardStep implements Disposable {
|
||||||
|
|
||||||
private JPanel myPanel;
|
private JPanel myPanel;
|
||||||
@@ -52,7 +48,7 @@ public class GradleFrameworksWizardStep extends ModuleWizardStep implements Disp
|
|||||||
private JPanel myOptionsPanel;
|
private JPanel myOptionsPanel;
|
||||||
@SuppressWarnings("unused") private JBLabel myFrameworksLabel;
|
@SuppressWarnings("unused") private JBLabel myFrameworksLabel;
|
||||||
|
|
||||||
public GradleFrameworksWizardStep(WizardContext context, final GradleModuleBuilder builder) {
|
public GradleFrameworksWizardStep(WizardContext context, final ModuleBuilder builder) {
|
||||||
|
|
||||||
Project project = context.getProject();
|
Project project = context.getProject();
|
||||||
final LibrariesContainer container = LibrariesContainerFactory.createContainer(context.getProject());
|
final LibrariesContainer container = LibrariesContainerFactory.createContainer(context.getProject());
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2017 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.plugins.gradle.service.project.wizard;
|
package org.jetbrains.kotlin.gradle.kdsl;
|
||||||
|
|
||||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||||
@@ -68,7 +68,8 @@ import org.gradle.util.GradleVersion;
|
|||||||
import org.jdom.JDOMException;
|
import org.jdom.JDOMException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder;
|
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.BuildScriptDataBuilder;
|
||||||
|
import org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.KotlinBuildScriptDataBuilder;
|
||||||
import org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl;
|
import org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl;
|
||||||
import org.jetbrains.plugins.gradle.settings.DistributionType;
|
import org.jetbrains.plugins.gradle.settings.DistributionType;
|
||||||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
|
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
|
||||||
@@ -79,18 +80,16 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
import static org.jetbrains.kotlin.gradle.kdsl.GradleKotlinDSLConstants.DEFAULT_SCRIPT_NAME;
|
||||||
* @author Denis Zhdanov
|
|
||||||
* @since 6/26/13 11:10 AM
|
|
||||||
*/
|
|
||||||
public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradleProjectSettings> {
|
public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradleProjectSettings> {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getInstance(GradleModuleBuilder.class);
|
private static final Logger LOG = Logger.getInstance(GradleModuleBuilder.class);
|
||||||
|
|
||||||
private static final String TEMPLATE_GRADLE_SETTINGS = "Gradle Settings.gradle";
|
private static final String TEMPLATE_GRADLE_SETTINGS = "Gradle Kotlin DSL Settings.gradle";
|
||||||
private static final String TEMPLATE_GRADLE_SETTINGS_MERGE = "Gradle Settings merge.gradle";
|
private static final String TEMPLATE_GRADLE_SETTINGS_MERGE = "Gradle Settings merge.gradle";
|
||||||
private static final String TEMPLATE_GRADLE_BUILD_WITH_WRAPPER = "Gradle Build Script with wrapper.gradle";
|
private static final String TEMPLATE_GRADLE_BUILD_WITH_WRAPPER = "Gradle Build Script with wrapper.gradle";
|
||||||
private static final String DEFAULT_TEMPLATE_GRADLE_BUILD = "Gradle Build Script.gradle";
|
private static final String DEFAULT_TEMPLATE_GRADLE_BUILD = "Gradle Kotlin DSL Build Script.gradle";
|
||||||
|
|
||||||
private static final String TEMPLATE_ATTRIBUTE_PROJECT_NAME = "PROJECT_NAME";
|
private static final String TEMPLATE_ATTRIBUTE_PROJECT_NAME = "PROJECT_NAME";
|
||||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_PATH = "MODULE_PATH";
|
private static final String TEMPLATE_ATTRIBUTE_MODULE_PATH = "MODULE_PATH";
|
||||||
@@ -99,8 +98,9 @@ public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradlePro
|
|||||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_GROUP = "MODULE_GROUP";
|
private static final String TEMPLATE_ATTRIBUTE_MODULE_GROUP = "MODULE_GROUP";
|
||||||
private static final String TEMPLATE_ATTRIBUTE_MODULE_VERSION = "MODULE_VERSION";
|
private static final String TEMPLATE_ATTRIBUTE_MODULE_VERSION = "MODULE_VERSION";
|
||||||
private static final String TEMPLATE_ATTRIBUTE_GRADLE_VERSION = "GRADLE_VERSION";
|
private static final String TEMPLATE_ATTRIBUTE_GRADLE_VERSION = "GRADLE_VERSION";
|
||||||
private static final Key<BuildScriptDataBuilder> BUILD_SCRIPT_DATA =
|
private static final String TEMPLATE_ATTRIBUTE_BUILD_FILE_NAME = "BUILD_FILE_NAME";
|
||||||
Key.create("gradle.module.buildScriptData");
|
private static final Key<KotlinBuildScriptDataBuilder> BUILD_SCRIPT_DATA =
|
||||||
|
Key.create("gradle.module.kotlinBuildScriptData");
|
||||||
|
|
||||||
private WizardContext myWizardContext;
|
private WizardContext myWizardContext;
|
||||||
|
|
||||||
@@ -115,6 +115,11 @@ public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradlePro
|
|||||||
super(GradleConstants.SYSTEM_ID, new GradleProjectSettings());
|
super(GradleConstants.SYSTEM_ID, new GradleProjectSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPresentableName() {
|
||||||
|
return "Gradle (Kotlin DSL)";
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
|
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
|
||||||
@@ -199,7 +204,7 @@ public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradlePro
|
|||||||
|
|
||||||
if (gradleBuildFile != null) {
|
if (gradleBuildFile != null) {
|
||||||
modifiableRootModel.getModule().putUserData(
|
modifiableRootModel.getModule().putUserData(
|
||||||
BUILD_SCRIPT_DATA, new BuildScriptDataBuilder(gradleBuildFile));
|
BUILD_SCRIPT_DATA, new KotlinBuildScriptDataBuilder(gradleBuildFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +314,7 @@ public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradlePro
|
|||||||
@Nullable
|
@Nullable
|
||||||
private VirtualFile setupGradleBuildFile(@NotNull VirtualFile modelContentRootDir)
|
private VirtualFile setupGradleBuildFile(@NotNull VirtualFile modelContentRootDir)
|
||||||
throws ConfigurationException {
|
throws ConfigurationException {
|
||||||
final VirtualFile file = getOrCreateExternalProjectConfigFile(modelContentRootDir.getPath(), GradleConstants.DEFAULT_SCRIPT_NAME);
|
final VirtualFile file = getOrCreateExternalProjectConfigFile(modelContentRootDir.getPath(), GradleKotlinDSLConstants.DEFAULT_SCRIPT_NAME);
|
||||||
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
final String templateName = getExternalProjectSettings().getDistributionType() == DistributionType.WRAPPED
|
final String templateName = getExternalProjectSettings().getDistributionType() == DistributionType.WRAPPED
|
||||||
@@ -343,6 +348,7 @@ public class GradleModuleBuilder extends AbstractExternalModuleBuilder<GradlePro
|
|||||||
attributes.put(TEMPLATE_ATTRIBUTE_PROJECT_NAME, projectName);
|
attributes.put(TEMPLATE_ATTRIBUTE_PROJECT_NAME, projectName);
|
||||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_PATH, moduleDirName);
|
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_PATH, moduleDirName);
|
||||||
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_NAME, moduleName);
|
attributes.put(TEMPLATE_ATTRIBUTE_MODULE_NAME, moduleName);
|
||||||
|
attributes.put(TEMPLATE_ATTRIBUTE_BUILD_FILE_NAME, DEFAULT_SCRIPT_NAME); // TODO: gradle > 4.0 doesn't need this
|
||||||
saveFile(file, TEMPLATE_GRADLE_SETTINGS, attributes);
|
saveFile(file, TEMPLATE_GRADLE_SETTINGS, attributes);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.gradle.service.project.wizard.GradleModuleWizardStep">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.gradle.kdsl.GradleModuleWizardStep">
|
||||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2015 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.plugins.gradle.service.project.wizard;
|
package org.jetbrains.kotlin.gradle.kdsl;
|
||||||
|
|
||||||
import com.intellij.ide.util.PropertiesComponent;
|
import com.intellij.ide.util.PropertiesComponent;
|
||||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||||
@@ -31,16 +31,13 @@ import com.intellij.openapi.util.text.StringUtil;
|
|||||||
import com.intellij.openapi.wm.IdeFocusManager;
|
import com.intellij.openapi.wm.IdeFocusManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.plugins.gradle.service.project.wizard.GradleParentProjectForm;
|
||||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Vladislav.Soroka
|
|
||||||
* @since 4/15/2015
|
|
||||||
*/
|
|
||||||
public class GradleModuleWizardStep extends ModuleWizardStep {
|
public class GradleModuleWizardStep extends ModuleWizardStep {
|
||||||
private static final Icon WIZARD_ICON = null;
|
private static final Icon WIZARD_ICON = null;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -13,14 +13,14 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle.kdsl
|
||||||
|
|
||||||
import com.intellij.openapi.externalSystem.service.project.wizard.AbstractExternalProjectImportProvider
|
import com.intellij.openapi.externalSystem.service.project.wizard.AbstractExternalProjectImportProvider
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder
|
import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder
|
||||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||||
|
|
||||||
class GradleKotlinDSLProjectImportProvider(builder: GradleProjectImportBuilder)
|
class GradleProjectImportProvider(builder: GradleProjectImportBuilder)
|
||||||
: AbstractExternalProjectImportProvider(builder, GradleConstants.SYSTEM_ID) {
|
: AbstractExternalProjectImportProvider(builder, GradleConstants.SYSTEM_ID) {
|
||||||
|
|
||||||
override fun canImportFromFile(file: VirtualFile): Boolean = file.name.endsWith(".${GradleConstants.EXTENSION}.kts")
|
override fun canImportFromFile(file: VirtualFile): Boolean = file.name.endsWith(".${GradleConstants.EXTENSION}.kts")
|
||||||
+2
-2
@@ -14,14 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle.kdsl
|
||||||
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder
|
import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectImportBuilder
|
||||||
import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectOpenProcessor
|
import org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectOpenProcessor
|
||||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||||
|
|
||||||
class GradleKotlinDSLProjectOpenProcessor(builder: GradleProjectImportBuilder) : GradleProjectOpenProcessor(builder) {
|
class GradleProjectOpenProcessor(builder: GradleProjectImportBuilder) : GradleProjectOpenProcessor(builder) {
|
||||||
override fun canOpenProject(file: VirtualFile): Boolean = when {
|
override fun canOpenProject(file: VirtualFile): Boolean = when {
|
||||||
!file.isDirectory -> file.name.endsWith(".gradle.kts")
|
!file.isDirectory -> file.name.endsWith(".gradle.kts")
|
||||||
supportedExtensions.any { file.findChild(it) != null } -> true
|
supportedExtensions.any { file.findChild(it) != null } -> true
|
||||||
+1
-5
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.plugins.gradle.frameworkSupport;
|
package org.jetbrains.kotlin.gradle.kdsl.frameworkSupport;
|
||||||
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
@@ -24,10 +24,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Vladislav.Soroka
|
|
||||||
* @since 4/24/2015
|
|
||||||
*/
|
|
||||||
public class BuildScriptDataBuilder {
|
public class BuildScriptDataBuilder {
|
||||||
@NotNull private final VirtualFile myBuildScriptFile;
|
@NotNull private final VirtualFile myBuildScriptFile;
|
||||||
private final Set<String> plugins = ContainerUtil.newTreeSet();
|
private final Set<String> plugins = ContainerUtil.newTreeSet();
|
||||||
|
|||||||
+4
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2017 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.plugins.gradle.frameworkSupport;
|
package org.jetbrains.kotlin.gradle.kdsl.frameworkSupport;
|
||||||
|
|
||||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
|
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
|
||||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||||
@@ -28,16 +28,12 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import static org.jetbrains.plugins.gradle.service.project.wizard.GradleModuleBuilder.getBuildScriptData;
|
import static org.jetbrains.kotlin.gradle.kdsl.GradleModuleBuilder.getBuildScriptData;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Vladislav.Soroka
|
|
||||||
* @since 4/23/2015
|
|
||||||
*/
|
|
||||||
public abstract class GradleFrameworkSupportProvider extends FrameworkSupportInModuleProvider {
|
public abstract class GradleFrameworkSupportProvider extends FrameworkSupportInModuleProvider {
|
||||||
|
|
||||||
public static final ExtensionPointName<GradleFrameworkSupportProvider> EP_NAME =
|
public static final ExtensionPointName<GradleFrameworkSupportProvider> EP_NAME =
|
||||||
ExtensionPointName.create("org.jetbrains.plugins.gradle.frameworkSupport");
|
ExtensionPointName.create("org.jetbrains.kotlin.gradleFrameworkSupport");
|
||||||
|
|
||||||
public abstract void addSupport(@NotNull Module module, @NotNull ModifiableRootModel rootModel,
|
public abstract void addSupport(@NotNull Module module, @NotNull ModifiableRootModel rootModel,
|
||||||
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
||||||
|
|||||||
+5
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2015 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.plugins.gradle.frameworkSupport;
|
package org.jetbrains.kotlin.gradle.kdsl.frameworkSupport;
|
||||||
|
|
||||||
import com.intellij.framework.FrameworkTypeEx;
|
import com.intellij.framework.FrameworkTypeEx;
|
||||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||||
@@ -25,10 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Vladislav.Soroka
|
|
||||||
* @since 4/24/2015
|
|
||||||
*/
|
|
||||||
public class GradleGroovyFrameworkSupportProvider extends GradleFrameworkSupportProvider {
|
public class GradleGroovyFrameworkSupportProvider extends GradleFrameworkSupportProvider {
|
||||||
|
|
||||||
public static final String ID = "groovy";
|
public static final String ID = "groovy";
|
||||||
@@ -63,9 +59,9 @@ public class GradleGroovyFrameworkSupportProvider extends GradleFrameworkSupport
|
|||||||
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
||||||
@NotNull BuildScriptDataBuilder buildScriptData) {
|
@NotNull BuildScriptDataBuilder buildScriptData) {
|
||||||
buildScriptData
|
buildScriptData
|
||||||
.addPluginDefinition("apply plugin: 'groovy'")
|
.addPluginDefinition("plugin(\"groovy\")")
|
||||||
.addRepositoriesDefinition("mavenCentral()")
|
.addRepositoriesDefinition("mavenCentral()")
|
||||||
.addDependencyNotation("compile 'org.codehaus.groovy:groovy-all:2.3.11'")
|
.addDependencyNotation("compile(\"org.codehaus.groovy:groovy-all:2.3.11\")")
|
||||||
.addDependencyNotation("testCompile group: 'junit', name: 'junit', version: '4.12'");
|
.addDependencyNotation("testCompile(\"junit\", \"junit\", \"4.12\")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-8
@@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jetbrains.plugins.gradle.frameworkSupport;
|
package org.jetbrains.kotlin.gradle.kdsl.frameworkSupport;
|
||||||
|
|
||||||
import com.intellij.framework.FrameworkTypeEx;
|
import com.intellij.framework.FrameworkTypeEx;
|
||||||
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
|
||||||
@@ -25,10 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Vladislav.Soroka
|
|
||||||
* @since 4/23/2015
|
|
||||||
*/
|
|
||||||
public class GradleJavaFrameworkSupportProvider extends GradleFrameworkSupportProvider {
|
public class GradleJavaFrameworkSupportProvider extends GradleFrameworkSupportProvider {
|
||||||
|
|
||||||
public static final String ID = "java";
|
public static final String ID = "java";
|
||||||
@@ -63,9 +59,10 @@ public class GradleJavaFrameworkSupportProvider extends GradleFrameworkSupportPr
|
|||||||
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
@NotNull ModifiableModelsProvider modifiableModelsProvider,
|
||||||
@NotNull BuildScriptDataBuilder buildScriptData) {
|
@NotNull BuildScriptDataBuilder buildScriptData) {
|
||||||
buildScriptData
|
buildScriptData
|
||||||
.addPluginDefinition("apply plugin: 'java'")
|
.addPluginDefinition("plugin(\"java\")")
|
||||||
.addPropertyDefinition("sourceCompatibility = 1.8")
|
// TODO: in gradle > 4.0 it is just 'java { ... }'
|
||||||
|
.addOther("configure<JavaPluginConvention> {\n sourceCompatibility = JavaVersion.VERSION_1_8\n}")
|
||||||
.addRepositoriesDefinition("mavenCentral()")
|
.addRepositoriesDefinition("mavenCentral()")
|
||||||
.addDependencyNotation("testCompile group: 'junit', name: 'junit', version: '4.12'");
|
.addDependencyNotation("testCompile(\"junit\", \"junit\", \"4.12\")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 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.kotlin.gradle.kdsl.frameworkSupport
|
||||||
|
|
||||||
|
import com.intellij.framework.FrameworkTypeEx
|
||||||
|
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider
|
||||||
|
import com.intellij.openapi.module.Module
|
||||||
|
import com.intellij.openapi.roots.ModifiableModelsProvider
|
||||||
|
import com.intellij.openapi.roots.ModifiableRootModel
|
||||||
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.*
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.KotlinBuildScriptManipulator.Companion.GSK_KOTLIN_VERSION_PROPERTY_NAME
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.KotlinBuildScriptManipulator.Companion.getCompileDependencySnippet
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.KotlinBuildScriptManipulator.Companion.getKotlinGradlePluginClassPathSnippet
|
||||||
|
import org.jetbrains.kotlin.idea.versions.MAVEN_JS_STDLIB_ID
|
||||||
|
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
|
||||||
|
import org.jetbrains.kotlin.idea.versions.getDefaultJvmTarget
|
||||||
|
import org.jetbrains.kotlin.idea.versions.getStdlibArtifactId
|
||||||
|
import javax.swing.Icon
|
||||||
|
|
||||||
|
abstract class GradleKotlinDSLKotlinFrameworkSupportProvider(
|
||||||
|
val frameworkTypeId: String,
|
||||||
|
val displayName: String,
|
||||||
|
val frameworkIcon: Icon
|
||||||
|
) : GradleFrameworkSupportProvider() {
|
||||||
|
override fun getFrameworkType(): FrameworkTypeEx = object : FrameworkTypeEx(frameworkTypeId) {
|
||||||
|
override fun getIcon(): Icon = frameworkIcon
|
||||||
|
override fun getPresentableName(): String = displayName
|
||||||
|
override fun createProvider(): FrameworkSupportInModuleProvider = this@GradleKotlinDSLKotlinFrameworkSupportProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addSupport(module: Module,
|
||||||
|
rootModel: ModifiableRootModel,
|
||||||
|
modifiableModelsProvider: ModifiableModelsProvider,
|
||||||
|
buildScriptData: BuildScriptDataBuilder) {
|
||||||
|
var kotlinVersion = bundledRuntimeVersion()
|
||||||
|
val additionalRepository = getRepositoryForVersion(kotlinVersion)
|
||||||
|
if (isSnapshot(bundledRuntimeVersion())) {
|
||||||
|
kotlinVersion = "1.1-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalRepository != null) {
|
||||||
|
val repository = additionalRepository.toKotlinRepositorySnippet()
|
||||||
|
buildScriptData.addBuildscriptRepositoriesDefinition(repository)
|
||||||
|
buildScriptData.addRepositoriesDefinition("mavenCentral()")
|
||||||
|
buildScriptData.addRepositoriesDefinition(repository)
|
||||||
|
}
|
||||||
|
|
||||||
|
buildScriptData
|
||||||
|
.addPropertyDefinition("val $GSK_KOTLIN_VERSION_PROPERTY_NAME: String by extra")
|
||||||
|
.addPluginDefinition(getPluginDefinition())
|
||||||
|
.addBuildscriptRepositoriesDefinition("mavenCentral()")
|
||||||
|
.addRepositoriesDefinition("mavenCentral()")
|
||||||
|
// TODO: in gradle > 4.1 this could be single declaration e.g. 'val kotlin_version: String by extra { "1.1.11" }'
|
||||||
|
.addBuildscriptPropertyDefinition("var $GSK_KOTLIN_VERSION_PROPERTY_NAME: String by extra\n$GSK_KOTLIN_VERSION_PROPERTY_NAME = \"$kotlinVersion\"")
|
||||||
|
.addDependencyNotation(getRuntimeLibrary(rootModel))
|
||||||
|
.addBuildscriptDependencyNotation(getKotlinGradlePluginClassPathSnippet())
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun getRuntimeLibrary(rootModel: ModifiableRootModel): String
|
||||||
|
|
||||||
|
protected abstract fun getPluginDefinition(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
class GradleKotlinDSLKotlinJavaFrameworkSupportProvider :
|
||||||
|
GradleKotlinDSLKotlinFrameworkSupportProvider("KOTLIN", "Kotlin (Java)", KotlinIcons.SMALL_LOGO) {
|
||||||
|
|
||||||
|
override fun getPluginDefinition() = "plugin(\"${KotlinGradleModuleConfigurator.KOTLIN}\")"
|
||||||
|
|
||||||
|
override fun getRuntimeLibrary(rootModel: ModifiableRootModel) =
|
||||||
|
getCompileDependencySnippet(KOTLIN_GROUP_ID, getStdlibArtifactId(rootModel.sdk, bundledRuntimeVersion()))
|
||||||
|
|
||||||
|
override fun addSupport(
|
||||||
|
module: Module,
|
||||||
|
rootModel: ModifiableRootModel,
|
||||||
|
modifiableModelsProvider: ModifiableModelsProvider,
|
||||||
|
buildScriptData: BuildScriptDataBuilder
|
||||||
|
) {
|
||||||
|
super.addSupport(module, rootModel, modifiableModelsProvider, buildScriptData)
|
||||||
|
val jvmTarget = getDefaultJvmTarget(rootModel.sdk, bundledRuntimeVersion())
|
||||||
|
if (jvmTarget != null) {
|
||||||
|
buildScriptData
|
||||||
|
.addImports("import org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
|
||||||
|
.addOther("tasks.withType<KotlinCompile> {\n kotlinOptions.jvmTarget = \"1.8\"\n}\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun BuildScriptDataBuilder.addImports(vararg import: String): BuildScriptDataBuilder = apply {
|
||||||
|
val text = VfsUtil.loadText(buildScriptFile)
|
||||||
|
VfsUtil.saveText(buildScriptFile, import.joinToString(separator = "\n") + "\n\n" + text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GradleKotlinDSLKotlinJSFrameworkSupportProvider :
|
||||||
|
GradleKotlinDSLKotlinFrameworkSupportProvider("KOTLIN_JS", "Kotlin (JavaScript)", KotlinIcons.JS) {
|
||||||
|
|
||||||
|
override fun getPluginDefinition(): String = "plugin(\"${KotlinJsGradleModuleConfigurator.KOTLIN_JS}\")"
|
||||||
|
|
||||||
|
override fun getRuntimeLibrary(rootModel: ModifiableRootModel) =
|
||||||
|
getCompileDependencySnippet(KOTLIN_GROUP_ID, MAVEN_JS_STDLIB_ID.removePrefix("kotlin-"))
|
||||||
|
}
|
||||||
+93
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 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.kotlin.gradle.kdsl.frameworkSupport
|
||||||
|
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.util.containers.ContainerUtil
|
||||||
|
|
||||||
|
class KotlinBuildScriptDataBuilder(buildScriptFile: VirtualFile) : BuildScriptDataBuilder(buildScriptFile) {
|
||||||
|
private val plugins: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
private val properties: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
private val repositories: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
private val dependencies: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
|
||||||
|
private val buildScriptProperties: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
private val buildScriptRepositories: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
private val buildScriptDependencies: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
private val other: MutableSet<String> = ContainerUtil.newTreeSet<String>()
|
||||||
|
|
||||||
|
override fun addPluginDefinition(definition: String): BuildScriptDataBuilder = apply { plugins.add(definition) }
|
||||||
|
|
||||||
|
override fun addRepositoriesDefinition(definition: String): BuildScriptDataBuilder = apply { repositories.add(definition) }
|
||||||
|
|
||||||
|
override fun addPropertyDefinition(definition: String): BuildScriptDataBuilder = apply { properties.add(definition) }
|
||||||
|
|
||||||
|
override fun addDependencyNotation(notation: String): BuildScriptDataBuilder = apply { dependencies.add(notation) }
|
||||||
|
|
||||||
|
override fun addBuildscriptPropertyDefinition(definition: String): BuildScriptDataBuilder = apply { buildScriptProperties.add(definition) }
|
||||||
|
|
||||||
|
override fun addBuildscriptRepositoriesDefinition(definition: String): BuildScriptDataBuilder = apply { buildScriptRepositories.add(definition) }
|
||||||
|
|
||||||
|
override fun addBuildscriptDependencyNotation(notation: String): BuildScriptDataBuilder = apply { buildScriptDependencies.add(notation) }
|
||||||
|
|
||||||
|
override fun addOther(definition: String): BuildScriptDataBuilder = apply { other.add(definition) }
|
||||||
|
|
||||||
|
override fun buildMainPart(): String = buildString {
|
||||||
|
|
||||||
|
appendlnIfNotNull(buildBuildScriptBlock())
|
||||||
|
|
||||||
|
appendlnIfNotNull(buildBlock("apply", plugins))
|
||||||
|
|
||||||
|
if (properties.isNotEmpty()) {
|
||||||
|
properties.forEach { appendln(it) }
|
||||||
|
appendln()
|
||||||
|
}
|
||||||
|
|
||||||
|
appendlnIfNotNull(buildBlock("repositories", repositories))
|
||||||
|
|
||||||
|
appendlnIfNotNull(buildBlock("dependencies", dependencies))
|
||||||
|
|
||||||
|
other.forEach { appendln(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildBuildScriptBlock(): String? = buildString {
|
||||||
|
if (buildScriptProperties.isEmpty() || buildScriptRepositories.isEmpty() || buildScriptDependencies.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
appendln("buildscript {")
|
||||||
|
buildScriptProperties.forEach { appendln(it.withMargin) }
|
||||||
|
appendln()
|
||||||
|
appendlnIfNotNull(buildBlock("repositories", buildScriptRepositories)?.withMargin)
|
||||||
|
appendlnIfNotNull(buildBlock("dependencies", buildScriptDependencies)?.withMargin)
|
||||||
|
appendln("}")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildBlock(name: String, lines: Set<String>): String? = buildString {
|
||||||
|
if (lines.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
appendln("$name {")
|
||||||
|
lines.forEach { appendln(it.withMargin) }
|
||||||
|
appendln("}")
|
||||||
|
}
|
||||||
|
|
||||||
|
private val String.withMargin: String
|
||||||
|
get() = lines().joinToString(separator = "\n") { " " + it }
|
||||||
|
|
||||||
|
private fun StringBuilder.appendlnIfNotNull(text: String?) = text?.let { appendln(it) }
|
||||||
|
}
|
||||||
+13
-12
@@ -125,15 +125,6 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
|
|||||||
private fun KtCallExpression.getBlock(): KtBlockExpression? =
|
private fun KtCallExpression.getBlock(): KtBlockExpression? =
|
||||||
(valueArguments.singleOrNull()?.getArgumentExpression() as? KtLambdaExpression)?.bodyExpression
|
(valueArguments.singleOrNull()?.getArgumentExpression() as? KtLambdaExpression)?.bodyExpression
|
||||||
|
|
||||||
private fun getCompileDependencySnippet(groupId: String, artifactId: String, compileScope: String = "compile", version: String? = null): String =
|
|
||||||
if (groupId == KOTLIN_GROUP_ID)
|
|
||||||
"$compileScope(${getKotlinModuleDependencySnippet(artifactId, version)})"
|
|
||||||
else
|
|
||||||
"$compileScope(\"$groupId:$artifactId:$version\")"
|
|
||||||
|
|
||||||
private fun getKotlinModuleDependencySnippet(artifactId: String, version: String? = null): String =
|
|
||||||
"kotlinModule(\"${artifactId.removePrefix("kotlin-")}\", ${version?.let { "\"$it\"" } ?: GSK_KOTLIN_VERSION_PROPERTY_NAME})"
|
|
||||||
|
|
||||||
private fun KtFile.getKotlinStdlibVersion(): String? {
|
private fun KtFile.getKotlinStdlibVersion(): String? {
|
||||||
return findScriptInitializer("dependencies")?.getBlock()?.let {
|
return findScriptInitializer("dependencies")?.getBlock()?.let {
|
||||||
val expression = it.findCompileStdLib()?.valueArguments?.firstOrNull()?.getArgumentExpression()
|
val expression = it.findCompileStdLib()?.valueArguments?.firstOrNull()?.getArgumentExpression()
|
||||||
@@ -233,8 +224,7 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun KtBlockExpression.addPluginToClassPathIfMissing(): KtCallExpression? =
|
private fun KtBlockExpression.addPluginToClassPathIfMissing(): KtCallExpression? =
|
||||||
addExpressionIfMissing("classpath(${getKotlinModuleDependencySnippet("gradle-plugin")})") as? KtCallExpression
|
addExpressionIfMissing(getKotlinGradlePluginClassPathSnippet()) as? KtCallExpression
|
||||||
|
|
||||||
|
|
||||||
private fun KtBlockExpression.addBlock(name: String): KtBlockExpression? {
|
private fun KtBlockExpression.addBlock(name: String): KtBlockExpression? {
|
||||||
return add(psiFactory.createExpression("$name {\n}"))
|
return add(psiFactory.createExpression("$name {\n}"))
|
||||||
@@ -313,6 +303,17 @@ class KotlinBuildScriptManipulator(private val kotlinScript: KtFile) : GradleBui
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val STDLIB_ARTIFACT_PREFIX = "org.jetbrains.kotlin:kotlin-stdlib"
|
private val STDLIB_ARTIFACT_PREFIX = "org.jetbrains.kotlin:kotlin-stdlib"
|
||||||
private val GSK_KOTLIN_VERSION_PROPERTY_NAME = "kotlin_version"
|
val GSK_KOTLIN_VERSION_PROPERTY_NAME = "kotlin_version"
|
||||||
|
|
||||||
|
fun getKotlinGradlePluginClassPathSnippet(): String = "classpath(${getKotlinModuleDependencySnippet("gradle-plugin")})"
|
||||||
|
|
||||||
|
fun getKotlinModuleDependencySnippet(artifactId: String, version: String? = null): String =
|
||||||
|
"kotlinModule(\"${artifactId.removePrefix("kotlin-")}\", ${version?.let { "\"$it\"" } ?: GSK_KOTLIN_VERSION_PROPERTY_NAME})"
|
||||||
|
|
||||||
|
fun getCompileDependencySnippet(groupId: String, artifactId: String, compileScope: String = "compile", version: String? = null): String =
|
||||||
|
if (groupId == KOTLIN_GROUP_ID)
|
||||||
|
"$compileScope(${Companion.getKotlinModuleDependencySnippet(artifactId, version)})"
|
||||||
|
else
|
||||||
|
"$compileScope(\"$groupId:$artifactId:$version\")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,5 +49,7 @@
|
|||||||
interface="org.jetbrains.kotlin.idea.completion.CompletionInformationProvider" />
|
interface="org.jetbrains.kotlin.idea.completion.CompletionInformationProvider" />
|
||||||
<extensionPoint name="moduleBuilder"
|
<extensionPoint name="moduleBuilder"
|
||||||
interface="com.intellij.ide.util.projectWizard.ModuleBuilder"/>
|
interface="com.intellij.ide.util.projectWizard.ModuleBuilder"/>
|
||||||
|
<extensionPoint name="gradleFrameworkSupport"
|
||||||
|
interface="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleFrameworkSupportProvider"/>
|
||||||
</extensionPoints>
|
</extensionPoints>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
@@ -2626,10 +2626,12 @@
|
|||||||
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.kotlin.idea.core.script.dependencies.ScriptDependencySourceNavigationPolicyForJavaClasses"/>
|
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.kotlin.idea.core.script.dependencies.ScriptDependencySourceNavigationPolicyForJavaClasses"/>
|
||||||
<resolveScopeProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.KotlinScriptResolveScopeProvider"/>
|
<resolveScopeProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.KotlinScriptResolveScopeProvider"/>
|
||||||
<resolveScopeProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.ScriptDependenciesResolveScopeProvider"/>
|
<resolveScopeProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.ScriptDependenciesResolveScopeProvider"/>
|
||||||
<projectOpenProcessor implementation="org.jetbrains.kotlin.gradle.GradleKotlinDSLProjectOpenProcessor"/>
|
<projectOpenProcessor implementation="org.jetbrains.kotlin.gradle.kdsl.GradleProjectOpenProcessor"/>
|
||||||
<projectImportProvider implementation="org.jetbrains.kotlin.gradle.GradleKotlinDSLProjectImportProvider"/>
|
<projectImportProvider implementation="org.jetbrains.kotlin.gradle.kdsl.GradleProjectImportProvider"/>
|
||||||
|
|
||||||
<codeInsight.intention.jvmCommonIntentionActionsFactory language="kotlin" implementationClass="org.jetbrains.kotlin.idea.intentions.KotlinCommonIntentionActionsFactory"/>
|
<codeInsight.intention.jvmCommonIntentionActionsFactory language="kotlin" implementationClass="org.jetbrains.kotlin.idea.intentions.KotlinCommonIntentionActionsFactory"/>
|
||||||
|
|
||||||
|
<moduleBuilder builderClass="org.jetbrains.kotlin.gradle.kdsl.GradleModuleBuilder" />
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="org.jetbrains.uast">
|
<extensions defaultExtensionNs="org.jetbrains.uast">
|
||||||
@@ -2657,6 +2659,11 @@
|
|||||||
<storageComponentContainerContributor implementation="org.jetbrains.kotlin.noarg.ide.IdeNoArgComponentContainerContributor"/>
|
<storageComponentContainerContributor implementation="org.jetbrains.kotlin.noarg.ide.IdeNoArgComponentContainerContributor"/>
|
||||||
<defaultErrorMessages implementation="org.jetbrains.kotlin.noarg.diagnostic.DefaultErrorMessagesNoArg"/>
|
<defaultErrorMessages implementation="org.jetbrains.kotlin.noarg.diagnostic.DefaultErrorMessagesNoArg"/>
|
||||||
<versionInfoProvider implementation="org.jetbrains.kotlin.idea.facet.KotlinVersionInfoProviderByModuleDependencies"/>
|
<versionInfoProvider implementation="org.jetbrains.kotlin.idea.facet.KotlinVersionInfoProviderByModuleDependencies"/>
|
||||||
|
|
||||||
|
<gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleJavaFrameworkSupportProvider" />
|
||||||
|
<gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleKotlinDSLKotlinJavaFrameworkSupportProvider" />
|
||||||
|
<gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleKotlinDSLKotlinJSFrameworkSupportProvider" />
|
||||||
|
<gradleFrameworkSupport implementation="org.jetbrains.kotlin.gradle.kdsl.frameworkSupport.GradleGroovyFrameworkSupportProvider" />
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
@@ -90,9 +90,9 @@ fun DependencyScope.toGradleCompileScope(isAndroidModule: Boolean) = when (this)
|
|||||||
else -> "compile"
|
else -> "compile"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun RepositoryDescription.toGroovyRepositorySnippet() = "maven {\nurl '$url'\n}"
|
fun RepositoryDescription.toGroovyRepositorySnippet() = "maven {\n url '$url'\n}"
|
||||||
|
|
||||||
fun RepositoryDescription.toKotlinRepositorySnippet() = "maven {\nsetUrl(\"$url\")\n}"
|
fun RepositoryDescription.toKotlinRepositorySnippet() = "maven {\n setUrl(\"$url\")\n}"
|
||||||
|
|
||||||
fun getRepositoryForVersion(version: String): RepositoryDescription? = when {
|
fun getRepositoryForVersion(version: String): RepositoryDescription? = when {
|
||||||
isSnapshot(version) -> SNAPSHOT_REPOSITORY
|
isSnapshot(version) -> SNAPSHOT_REPOSITORY
|
||||||
|
|||||||
Reference in New Issue
Block a user