Cleanup 192 patchset files (KTI-315)
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
#if (${MODULE_GROUP} && ${MODULE_GROUP} != "")
|
||||
group = "${MODULE_GROUP}"
|
||||
#end
|
||||
#if (${MODULE_VERSION} && ${MODULE_VERSION} != "")
|
||||
version = "${MODULE_VERSION}"
|
||||
#end
|
||||
@@ -1,20 +0,0 @@
|
||||
#if (${PROJECT_NAME} && ${PROJECT_NAME} != "")
|
||||
#if (((!${MODULE_PATH} || ${MODULE_PATH} == "")) && (${MODULE_NAME} && ${MODULE_NAME} != ""))
|
||||
rootProject.name = '${MODULE_NAME}'
|
||||
#else
|
||||
rootProject.name = '${PROJECT_NAME}'
|
||||
#end
|
||||
#end
|
||||
#if (${MODULE_PATH} && ${MODULE_PATH} != "")
|
||||
#if (${MODULE_FLAT_DIR} == "true")includeFlat '${MODULE_PATH}'
|
||||
#else
|
||||
include '${MODULE_PATH}'
|
||||
#end
|
||||
#if (${MODULE_NAME} && ${MODULE_NAME} != "" && ${MODULE_PATH} != ${MODULE_NAME})
|
||||
findProject(':${MODULE_PATH}')?.name = '${MODULE_NAME}'
|
||||
#end
|
||||
#end
|
||||
#if (${BUILD_FILE_NAME} && ${BUILD_FILE_NAME} != "")
|
||||
rootProject.buildFileName = '${BUILD_FILE_NAME}'
|
||||
#end
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.actions
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.ide.actions.ShowFilePathAction
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.DumbAware
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.MessageType
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.openapi.wm.WindowManager
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.ui.BrowserHyperlinkListener
|
||||
import org.jetbrains.kotlin.idea.KotlinIdeaGradleBundle
|
||||
import java.io.File
|
||||
|
||||
class ShowKotlinGradleDslLogs : IntentionAction, AnAction(), DumbAware {
|
||||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
||||
openLogsDirIfPresent(project)
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
openLogsDirIfPresent(e.project)
|
||||
}
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?) = ShowFilePathAction.isSupported()
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
val presentation = e.presentation
|
||||
presentation.isVisible = ShowFilePathAction.isSupported()
|
||||
presentation.text = NAME
|
||||
}
|
||||
|
||||
private fun openLogsDirIfPresent(project: Project?) {
|
||||
val logsDir = findLogsDir()
|
||||
if (logsDir != null) {
|
||||
ShowFilePathAction.openDirectory(logsDir)
|
||||
} else {
|
||||
val parent = WindowManager.getInstance().getStatusBar(project)?.component
|
||||
?: WindowManager.getInstance().findVisibleFrame().rootPane
|
||||
JBPopupFactory.getInstance()
|
||||
.createHtmlTextBalloonBuilder(
|
||||
KotlinIdeaGradleBundle.message(
|
||||
"text.gradle.dsl.logs.cannot.be.found.automatically.see.how.to.find.logs",
|
||||
gradleTroubleshootingLink
|
||||
),
|
||||
MessageType.ERROR,
|
||||
BrowserHyperlinkListener.INSTANCE
|
||||
)
|
||||
.setFadeoutTime(5000)
|
||||
.createBalloon()
|
||||
.showInCenterOf(parent)
|
||||
}
|
||||
}
|
||||
|
||||
/** The way how to find Gradle logs is described here
|
||||
* @see org.jetbrains.kotlin.idea.actions.ShowKotlinGradleDslLogs.gradleTroubleshootingLink
|
||||
*/
|
||||
private fun findLogsDir(): File? {
|
||||
val userHome = System.getProperty("user.home")
|
||||
return when {
|
||||
SystemInfo.isMac -> File("$userHome/Library/Logs/gradle-kotlin-dsl")
|
||||
SystemInfo.isLinux -> File("$userHome/.gradle-kotlin-dsl/logs")
|
||||
SystemInfo.isWindows -> File("$userHome/AppData/Local/gradle-kotlin-dsl/log")
|
||||
else -> null
|
||||
}.takeIf { it?.exists() == true }
|
||||
}
|
||||
|
||||
override fun startInWriteAction() = false
|
||||
|
||||
override fun getText() = NAME
|
||||
|
||||
override fun getFamilyName() = NAME
|
||||
|
||||
companion object {
|
||||
private const val gradleTroubleshootingLink = "https://docs.gradle.org/current/userguide/kotlin_dsl.html#troubleshooting"
|
||||
|
||||
val NAME = KotlinIdeaGradleBundle.message("action.text.show.kotlin.gradle.dsl.logs.in", ShowFilePathAction.getFileManagerName())
|
||||
}
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.notification.Notification
|
||||
import com.intellij.notification.NotificationAction
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser
|
||||
import com.intellij.util.PlatformUtils
|
||||
import org.jetbrains.kotlin.idea.KotlinIdeaGradleBundle
|
||||
|
||||
const val NATIVE_DEBUG_ID = "com.intellij.nativeDebug"
|
||||
|
||||
fun suggestNativeDebug(projectPath: String) {
|
||||
if (!PlatformUtils.isIdeaUltimate() ||
|
||||
PluginManager.isPluginInstalled(PluginId.getId(NATIVE_DEBUG_ID))) {
|
||||
return
|
||||
}
|
||||
|
||||
val project = ProjectManager.getInstance().openProjects.firstOrNull { it.basePath == projectPath } ?: return
|
||||
|
||||
PluginsAdvertiser.NOTIFICATION_GROUP.createNotification(
|
||||
KotlinIdeaGradleBundle.message("title.plugin.suggestion"),
|
||||
KotlinIdeaGradleBundle.message("notification.text.native.debug.provides.debugger.for.kotlin.native"),
|
||||
NotificationType.INFORMATION, null
|
||||
).addAction(object : NotificationAction(KotlinIdeaGradleBundle.message("action.text.install")) {
|
||||
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
|
||||
PluginsAdvertiser.installAndEnablePlugins(setOf(NATIVE_DEBUG_ID)) { notification.expire() }
|
||||
}
|
||||
}).notify(project)
|
||||
}
|
||||
-366
@@ -1,366 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.gradle.execution;
|
||||
|
||||
import com.intellij.build.BuildViewManager;
|
||||
import com.intellij.compiler.impl.CompilerUtil;
|
||||
import com.intellij.execution.executors.DefaultRunExecutor;
|
||||
import com.intellij.openapi.compiler.ex.CompilerPathsEx;
|
||||
import com.intellij.openapi.externalSystem.model.DataNode;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectKeys;
|
||||
import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings;
|
||||
import com.intellij.openapi.externalSystem.model.project.ModuleData;
|
||||
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode;
|
||||
import com.intellij.openapi.externalSystem.task.TaskCallback;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootModificationTracker;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.task.*;
|
||||
import com.intellij.task.impl.JpsProjectTaskRunner;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.config.KotlinFacetSettings;
|
||||
import org.jetbrains.kotlin.idea.KotlinIdeaGradleBundle;
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet;
|
||||
import org.jetbrains.kotlin.platform.TargetPlatformKt;
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform;
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatformKt;
|
||||
import org.jetbrains.plugins.gradle.execution.build.CachedModuleDataFinder;
|
||||
import org.jetbrains.plugins.gradle.execution.build.GradleProjectTaskRunner;
|
||||
import org.jetbrains.plugins.gradle.service.project.GradleBuildSrcProjectsResolver;
|
||||
import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil;
|
||||
import org.jetbrains.plugins.gradle.service.task.GradleTaskManager;
|
||||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
|
||||
import org.jetbrains.plugins.gradle.settings.GradleSettings;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration.PROGRESS_LISTENER_KEY;
|
||||
import static com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.*;
|
||||
import static com.intellij.openapi.util.text.StringUtil.*;
|
||||
import static org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.resolveProjectPath;
|
||||
|
||||
/**
|
||||
* This is a modified copy of {@link GradleProjectTaskRunner} that allows building Kotlin Common and Kotlin Native modules
|
||||
* in IDEA by delegating to Gradle builder ("Delegate IDE build/run actions to gradle"). See #KT-27295, #KT-27296.
|
||||
*
|
||||
* TODO: Refactor this class to remove duplicated logic when {@link GradleProjectTaskRunner} will allow extending it to
|
||||
* collect custom Gradle tasks. See #IDEA-204372, #KT-28880.
|
||||
*/
|
||||
class KotlinMPPGradleProjectTaskRunner extends ProjectTaskRunner
|
||||
{
|
||||
|
||||
@Language("Groovy")
|
||||
private static final String FORCE_COMPILE_TASKS_INIT_SCRIPT_TEMPLATE = "projectsEvaluated { \n" +
|
||||
" rootProject.findProject('%s')?.tasks?.withType(AbstractCompile) { \n" +
|
||||
" outputs.upToDateWhen { false } \n" +
|
||||
" } \n" +
|
||||
"}\n";
|
||||
|
||||
@Override
|
||||
public void run(@NotNull Project project,
|
||||
@NotNull ProjectTaskContext context,
|
||||
@Nullable ProjectTaskNotification callback,
|
||||
@NotNull Collection<? extends ProjectTask> tasks) {
|
||||
MultiMap<String, String> buildTasksMap = MultiMap.createLinkedSet();
|
||||
MultiMap<String, String> cleanTasksMap = MultiMap.createLinkedSet();
|
||||
MultiMap<String, String> initScripts = MultiMap.createLinkedSet();
|
||||
|
||||
Map<Class<? extends ProjectTask>, List<ProjectTask>> taskMap = JpsProjectTaskRunner.groupBy(tasks);
|
||||
|
||||
List<Module> modules = addModulesBuildTasks(taskMap.get(ModuleBuildTask.class), buildTasksMap, initScripts);
|
||||
// TODO there should be 'gradle' way to build files instead of related modules entirely
|
||||
List<Module> modulesOfFiles = addModulesBuildTasks(taskMap.get(ModuleFilesBuildTask.class), buildTasksMap, initScripts);
|
||||
|
||||
// TODO send a message if nothing to build
|
||||
Set<String> rootPaths = buildTasksMap.keySet();
|
||||
AtomicInteger successCounter = new AtomicInteger();
|
||||
AtomicInteger errorCounter = new AtomicInteger();
|
||||
|
||||
TaskCallback taskCallback = callback == null ? null : new TaskCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
handle(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
handle(false);
|
||||
}
|
||||
|
||||
private void handle(boolean success) {
|
||||
int successes = success ? successCounter.incrementAndGet() : successCounter.get();
|
||||
int errors = success ? errorCounter.get() : errorCounter.incrementAndGet();
|
||||
if (successes + errors == rootPaths.size()) {
|
||||
if (!project.isDisposed()) {
|
||||
// refresh on output roots is required in order for the order enumerator to see all roots via VFS
|
||||
final List<Module> affectedModules = ContainerUtil.concat(modules, modulesOfFiles);
|
||||
// have to refresh in case of errors too, because run configuration may be set to ignore errors
|
||||
Collection<String> affectedRoots = ContainerUtil.newHashSet(
|
||||
CompilerPathsEx.getOutputPaths(affectedModules.toArray(Module.EMPTY_ARRAY)));
|
||||
if (!affectedRoots.isEmpty()) {
|
||||
CompilerUtil.refreshOutputRoots(affectedRoots);
|
||||
}
|
||||
}
|
||||
callback.finished(new ProjectTaskResult(false, errors, 0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// TODO compiler options should be configurable
|
||||
@Language("Groovy")
|
||||
String compilerOptionsInitScript = "allprojects {\n" +
|
||||
" tasks.withType(JavaCompile) {\n" +
|
||||
" options.compilerArgs += [\"-Xlint:deprecation\"]\n" +
|
||||
" }" +
|
||||
"}\n";
|
||||
|
||||
String gradleVmOptions = GradleSettings.getInstance(project).getGradleVmOptions();
|
||||
for (String rootProjectPath : rootPaths) {
|
||||
Collection<String> buildTasks = buildTasksMap.get(rootProjectPath);
|
||||
if (buildTasks.isEmpty()) continue;
|
||||
Collection<String> cleanTasks = cleanTasksMap.get(rootProjectPath);
|
||||
|
||||
ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
|
||||
|
||||
File projectFile = new File(rootProjectPath);
|
||||
final String projectName;
|
||||
if (projectFile.isFile()) {
|
||||
projectName = projectFile.getParentFile().getName();
|
||||
}
|
||||
else {
|
||||
projectName = projectFile.getName();
|
||||
}
|
||||
String executionName = KotlinIdeaGradleBundle.message("build.0.project", projectName);
|
||||
settings.setExecutionName(executionName);
|
||||
settings.setExternalProjectPath(rootProjectPath);
|
||||
settings.setTaskNames(ContainerUtil.collect(ContainerUtil.concat(cleanTasks, buildTasks).iterator()));
|
||||
//settings.setScriptParameters(scriptParameters);
|
||||
settings.setVmOptions(gradleVmOptions);
|
||||
settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
|
||||
|
||||
UserDataHolderBase userData = new UserDataHolderBase();
|
||||
userData.putUserData(PROGRESS_LISTENER_KEY, BuildViewManager.class);
|
||||
|
||||
Collection<String> scripts = initScripts.getModifiable(rootProjectPath);
|
||||
scripts.add(compilerOptionsInitScript);
|
||||
userData.putUserData(GradleTaskManager.INIT_SCRIPT_KEY, join(scripts, SystemProperties.getLineSeparator()));
|
||||
userData.putUserData(GradleTaskManager.INIT_SCRIPT_PREFIX_KEY, executionName);
|
||||
|
||||
ExternalSystemUtil.runTask(settings, DefaultRunExecutor.EXECUTOR_ID, project, GradleConstants.SYSTEM_ID,
|
||||
taskCallback, ProgressExecutionMode.IN_BACKGROUND_ASYNC, false, userData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRun(@NotNull ProjectTask projectTask) {
|
||||
if (projectTask instanceof ModuleBuildTask) {
|
||||
final ModuleBuildTask moduleBuildTask = (ModuleBuildTask) projectTask;
|
||||
final Module module = moduleBuildTask.getModule();
|
||||
|
||||
if (module.getProject().getPresentableUrl() == null || !GradleProjectSettings.isDelegatedBuildEnabled(module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) return false;
|
||||
|
||||
// ---------------------------------------- //
|
||||
// TODO BEGIN: Extract custom Kotlin logic. //
|
||||
// ---------------------------------------- //
|
||||
if (isProjectWithNativeSourceOrCommonProductionSourceModules(module.getProject())) return true;
|
||||
// ---------------------------------------- //
|
||||
// TODO END: Extract custom Kotlin logic. //
|
||||
// ---------------------------------------- //
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<Module> addModulesBuildTasks(@Nullable Collection<? extends ProjectTask> projectTasks,
|
||||
@NotNull MultiMap<String, String> buildTasksMap,
|
||||
@NotNull MultiMap<String, String> initScripts) {
|
||||
if (ContainerUtil.isEmpty(projectTasks)) return Collections.emptyList();
|
||||
|
||||
List<Module> affectedModules = new SmartList<>();
|
||||
Map<Module, String> rootPathsMap = FactoryMap.create(module -> notNullize(resolveProjectPath(module)));
|
||||
final CachedModuleDataFinder moduleDataFinder = new CachedModuleDataFinder();
|
||||
for (ProjectTask projectTask : projectTasks) {
|
||||
if (!(projectTask instanceof ModuleBuildTask)) continue;
|
||||
|
||||
ModuleBuildTask moduleBuildTask = (ModuleBuildTask)projectTask;
|
||||
Module module = moduleBuildTask.getModule();
|
||||
affectedModules.add(module);
|
||||
|
||||
final String rootProjectPath = rootPathsMap.get(module);
|
||||
if (isEmpty(rootProjectPath)) continue;
|
||||
|
||||
final String projectId = getExternalProjectId(module);
|
||||
if (projectId == null) continue;
|
||||
final String externalProjectPath = getExternalProjectPath(module);
|
||||
if (externalProjectPath == null || endsWith(externalProjectPath, "buildSrc")) continue;
|
||||
|
||||
final DataNode<? extends ModuleData> moduleDataNode = moduleDataFinder.findMainModuleData(module);
|
||||
if (moduleDataNode == null) continue;
|
||||
|
||||
// all buildSrc runtime projects will be built by gradle implicitly
|
||||
if (Boolean.parseBoolean(moduleDataNode.getData().getProperty(GradleBuildSrcProjectsResolver.BUILD_SRC_MODULE_PROPERTY))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
|
||||
if (gradlePath == null) continue;
|
||||
String taskPrefix = endsWithChar(gradlePath, ':') ? gradlePath : (gradlePath + ':');
|
||||
|
||||
List<String> gradleTasks = ContainerUtil.mapNotNull(
|
||||
findAll(moduleDataNode, ProjectKeys.TASK), node ->
|
||||
node.getData().isInherited() ? null : trimStart(node.getData().getName(), taskPrefix));
|
||||
|
||||
Collection<String> projectInitScripts = initScripts.getModifiable(rootProjectPath);
|
||||
Collection<String> buildRootTasks = buildTasksMap.getModifiable(rootProjectPath);
|
||||
final String moduleType = getExternalModuleType(module);
|
||||
|
||||
if (!moduleBuildTask.isIncrementalBuild()) {
|
||||
projectInitScripts.add(String.format(FORCE_COMPILE_TASKS_INIT_SCRIPT_TEMPLATE, gradlePath));
|
||||
}
|
||||
String assembleTask = "assemble";
|
||||
if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(moduleType)) {
|
||||
String sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
|
||||
String gradleTask = isEmpty(sourceSetName) || "main".equals(sourceSetName) ? "classes" : sourceSetName + "Classes";
|
||||
if (gradleTasks.contains(gradleTask)) {
|
||||
buildRootTasks.add(taskPrefix + gradleTask);
|
||||
}
|
||||
else if ("main".equals(sourceSetName) || "test".equals(sourceSetName)) {
|
||||
buildRootTasks.add(taskPrefix + assembleTask);
|
||||
}
|
||||
// ---------------------------------------- //
|
||||
// TODO BEGIN: Extract custom Kotlin logic. //
|
||||
// ---------------------------------------- //
|
||||
else if (isNativeSourceModule(module)) {
|
||||
// Add tasks for Kotlin/Native.
|
||||
buildRootTasks.addAll(addPrefix(findNativeGradleBuildTasks(gradleTasks, sourceSetName), taskPrefix));
|
||||
}
|
||||
else if (isCommonProductionSourceModule(module)) {
|
||||
// Add tasks for compiling metadata.
|
||||
buildRootTasks.addAll(addPrefix(findMetadataBuildTasks(gradleTasks, sourceSetName), taskPrefix));
|
||||
}
|
||||
// ---------------------------------------- //
|
||||
// TODO END: Extract custom Kotlin logic. //
|
||||
// ---------------------------------------- //
|
||||
}
|
||||
else {
|
||||
if (gradleTasks.contains("classes")) {
|
||||
buildRootTasks.add(taskPrefix + "classes");
|
||||
buildRootTasks.add(taskPrefix + "testClasses");
|
||||
}
|
||||
else if (gradleTasks.contains(assembleTask)) {
|
||||
buildRootTasks.add(taskPrefix + assembleTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
return affectedModules;
|
||||
}
|
||||
|
||||
// ---------------------------------------- //
|
||||
// TODO BEGIN: Extract custom Kotlin logic. //
|
||||
// ---------------------------------------- //
|
||||
private static boolean isProjectWithNativeSourceOrCommonProductionSourceModules(Project project) {
|
||||
return CachedValuesManager.getManager(project).getCachedValue(
|
||||
project,
|
||||
() -> new CachedValueProvider.Result<>(
|
||||
Arrays.stream(ModuleManager.getInstance(project).getModules()).anyMatch(
|
||||
module -> isNativeSourceModule(module) || isCommonProductionSourceModule(module)
|
||||
),
|
||||
ProjectRootModificationTracker.getInstance(project)
|
||||
));
|
||||
}
|
||||
|
||||
private static boolean isNativeSourceModule(Module module) {
|
||||
final KotlinFacet kotlinFacet = KotlinFacet.Companion.get(module);
|
||||
if (kotlinFacet == null) return false;
|
||||
|
||||
final TargetPlatform platform = kotlinFacet.getConfiguration().getSettings().getTargetPlatform();
|
||||
if (platform == null) return false;
|
||||
|
||||
return NativePlatformKt.isNative(platform);
|
||||
}
|
||||
|
||||
private static boolean isCommonProductionSourceModule(Module module) {
|
||||
final KotlinFacet kotlinFacet = KotlinFacet.Companion.get(module);
|
||||
if (kotlinFacet == null) return false;
|
||||
|
||||
final KotlinFacetSettings facetSettings = kotlinFacet.getConfiguration().getSettings();
|
||||
if (facetSettings.isTestModule()) return false;
|
||||
|
||||
final TargetPlatform platform = facetSettings.getTargetPlatform();
|
||||
if (platform == null) return false;
|
||||
|
||||
return TargetPlatformKt.isCommon(platform);
|
||||
}
|
||||
|
||||
private static Collection<String> findNativeGradleBuildTasks(Collection<String> gradleTasks, String sourceSetName) {
|
||||
// First, attempt to find Kotlin/Native convention Gradle task that unites all outputType-specific build tasks.
|
||||
final String conventionGradleTask = sourceSetName + "Binaries";
|
||||
if (gradleTasks.contains(conventionGradleTask)) {
|
||||
return Collections.singletonList(conventionGradleTask);
|
||||
}
|
||||
|
||||
// If convention task not found, then attempt to find all appropriate build tasks for the given source set.
|
||||
final Collection<String> linkPrefixes;
|
||||
final String targetName;
|
||||
if (sourceSetName.endsWith("Main")) {
|
||||
targetName = StringUtil.substringBeforeLast(sourceSetName,"Main");
|
||||
linkPrefixes = ContainerUtil.newArrayList("link", "linkMain");
|
||||
}
|
||||
else if (sourceSetName.endsWith("Test")) {
|
||||
targetName = StringUtil.substringBeforeLast(sourceSetName,"Test");
|
||||
linkPrefixes = Collections.singletonList("linkTest");
|
||||
}
|
||||
else {
|
||||
targetName = sourceSetName;
|
||||
linkPrefixes = Collections.singletonList("link");
|
||||
}
|
||||
|
||||
return linkPrefixes.stream()
|
||||
// get base task name (without disambiguation classifier)
|
||||
.map(linkPrefix -> linkPrefix + capitalize(targetName))
|
||||
// find all Gradle tasks that start with base task name
|
||||
.flatMap(nativeTaskName -> gradleTasks.stream().filter(taskName -> taskName.startsWith(nativeTaskName)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static Collection<String> findMetadataBuildTasks(Collection<String> gradleTasks, String sourceSetName) {
|
||||
if ("commonMain".equals(sourceSetName)) {
|
||||
final String metadataTaskName = "metadataMainClasses";
|
||||
if (gradleTasks.contains(metadataTaskName)) {
|
||||
return Collections.singletonList(metadataTaskName);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static Collection<String> addPrefix(Collection<String> tasks, String taskPrefix) {
|
||||
return tasks.stream().map(task -> taskPrefix + task).collect(Collectors.toList());
|
||||
}
|
||||
// ---------------------------------------- //
|
||||
// TODO END: Extract custom Kotlin logic. //
|
||||
// ---------------------------------------- //
|
||||
}
|
||||
-124
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.gradle.testing
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.ProjectKeys
|
||||
import com.intellij.openapi.externalSystem.model.project.ModuleData
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData
|
||||
import com.intellij.openapi.externalSystem.model.task.TaskData
|
||||
import com.intellij.openapi.externalSystem.util.Order
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.util.Consumer
|
||||
import org.gradle.tooling.model.idea.IdeaModule
|
||||
import org.jetbrains.kotlin.gradle.KotlinMPPGradleModel
|
||||
import org.jetbrains.kotlin.gradle.KotlinMPPGradleModelBuilder
|
||||
import org.jetbrains.kotlin.idea.configuration.getMppModel
|
||||
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
|
||||
|
||||
@Order(Int.MIN_VALUE)
|
||||
open class KotlinTestTasksResolver : AbstractProjectResolverExtension() {
|
||||
companion object {
|
||||
private const val ENABLED_REGISTRY_KEY = "kotlin.gradle.testing.enabled"
|
||||
}
|
||||
|
||||
private val LOG by lazy { Logger.getInstance(KotlinTestTasksResolver::class.java) }
|
||||
|
||||
override fun getToolingExtensionsClasses(): Set<Class<out Any>> {
|
||||
return setOf(KotlinMPPGradleModelBuilder::class.java, Unit::class.java)
|
||||
}
|
||||
|
||||
override fun populateModuleTasks(
|
||||
gradleModule: IdeaModule,
|
||||
ideModule: DataNode<ModuleData>,
|
||||
ideProject: DataNode<ProjectData>
|
||||
): MutableCollection<TaskData> {
|
||||
if (!Registry.`is`(ENABLED_REGISTRY_KEY))
|
||||
return super.populateModuleTasks(gradleModule, ideModule, ideProject)
|
||||
|
||||
val mppModel = resolverCtx.getMppModel(gradleModule)
|
||||
?: return super.populateModuleTasks(gradleModule, ideModule, ideProject)
|
||||
|
||||
return postprocessTaskData(mppModel, ideModule, nextResolver.populateModuleTasks(gradleModule, ideModule, ideProject))
|
||||
}
|
||||
|
||||
private fun postprocessTaskData(
|
||||
mppModel: KotlinMPPGradleModel,
|
||||
ideModule: DataNode<ModuleData>,
|
||||
originalTaskData: MutableCollection<TaskData>
|
||||
): MutableCollection<TaskData> {
|
||||
val testTaskNames = mutableSetOf<String>().apply {
|
||||
mppModel.targets.forEach { target ->
|
||||
target.testRunTasks.forEach { testTaskModel ->
|
||||
add(testTaskModel.taskName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun buildNewTaskDataMarkedAsTest(original: TaskData): TaskData =
|
||||
TaskData(original.owner, original.name, original.linkedExternalProjectPath, original.description).apply {
|
||||
group = original.group
|
||||
type = original.type
|
||||
isInherited = original.isInherited
|
||||
|
||||
isTest = true
|
||||
}
|
||||
|
||||
val replacementMap: Map<TaskData, TaskData> = mutableMapOf<TaskData, TaskData>().apply {
|
||||
originalTaskData.forEach {
|
||||
if (it.name in testTaskNames && !it.isTest) {
|
||||
put(it, buildNewTaskDataMarkedAsTest(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ideModule.children.filter { it.data in replacementMap }.forEach { it.clear(true) }
|
||||
replacementMap.values.forEach { ideModule.createChild(ProjectKeys.TASK, it) }
|
||||
|
||||
return originalTaskData.mapTo(arrayListOf<TaskData>()) { replacementMap[it] ?: it }
|
||||
}
|
||||
|
||||
override fun enhanceTaskProcessing(
|
||||
taskNames: MutableList<String>,
|
||||
jvmParametersSetup: String?,
|
||||
initScriptConsumer: Consumer<String>,
|
||||
testExecutionExpected: kotlin.Boolean
|
||||
) {
|
||||
if (!Registry.`is`(ENABLED_REGISTRY_KEY))
|
||||
return
|
||||
|
||||
if (testExecutionExpected) {
|
||||
try {
|
||||
val addTestListenerScript = javaClass
|
||||
.getResourceAsStream("/org/jetbrains/kotlin/idea/gradle/testing/addKotlinMppTestListener.groovy")
|
||||
.bufferedReader()
|
||||
.readText()
|
||||
initScriptConsumer.consume(addTestListenerScript)
|
||||
} catch (e: Exception) {
|
||||
LOG.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
enhanceTaskProcessing(taskNames, jvmParametersSetup, initScriptConsumer)
|
||||
}
|
||||
|
||||
override fun enhanceTaskProcessing(taskNames: MutableList<String>, jvmAgentSetup: String?, initScriptConsumer: Consumer<String>) {
|
||||
if (!Registry.`is`(ENABLED_REGISTRY_KEY))
|
||||
return
|
||||
|
||||
try {
|
||||
val testLoggerScript = javaClass
|
||||
.getResourceAsStream("/org/jetbrains/kotlin/idea/gradle/testing/KotlinMppTestLogger.groovy")
|
||||
.bufferedReader()
|
||||
.readText()
|
||||
|
||||
initScriptConsumer.consume(testLoggerScript)
|
||||
} catch (e: Exception) {
|
||||
LOG.error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.run
|
||||
|
||||
import com.intellij.execution.Location
|
||||
import com.intellij.execution.actions.ConfigurationFromContext
|
||||
import com.intellij.execution.junit.JUnitConfigurationProducer
|
||||
import com.intellij.execution.testframework.AbstractPatternBasedConfigurationProducer
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.openapi.extensions.PluginId.getId
|
||||
import com.intellij.openapi.util.component1
|
||||
import com.intellij.openapi.util.component2
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
|
||||
private val isJUnitEnabled by lazy { isPluginEnabled("JUnit") }
|
||||
private val isTestNgEnabled by lazy { isPluginEnabled("TestNG-J") }
|
||||
|
||||
private fun isPluginEnabled(id: String): Boolean {
|
||||
return PluginManager.isPluginInstalled(getId(id)) && id !in PluginManager.getDisabledPlugins()
|
||||
}
|
||||
|
||||
internal fun ConfigurationFromContext.isJpsJunitConfiguration(): Boolean {
|
||||
return isProducedBy(JUnitConfigurationProducer::class.java)
|
||||
|| isProducedBy(AbstractPatternBasedConfigurationProducer::class.java)
|
||||
}
|
||||
|
||||
internal fun canRunJvmTests() = isJUnitEnabled || isTestNgEnabled
|
||||
|
||||
internal fun getTestClassForJvm(location: Location<*>): PsiClass? {
|
||||
val leaf = location.psiElement ?: return null
|
||||
|
||||
if (leaf.language != KotlinLanguage.INSTANCE) return null
|
||||
|
||||
if (isJUnitEnabled) {
|
||||
KotlinJUnitRunConfigurationProducer.getTestClass(leaf)?.let { return it }
|
||||
}
|
||||
if (isTestNgEnabled) {
|
||||
KotlinTestNgConfigurationProducer.getTestClassAndMethod(leaf)?.let { (testClass, testMethod) ->
|
||||
return if (testMethod == null) testClass else null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
internal fun getTestMethodForJvm(location: Location<*>): PsiMethod? {
|
||||
val leaf = location.psiElement ?: return null
|
||||
|
||||
if (leaf.language != KotlinLanguage.INSTANCE) return null
|
||||
|
||||
if (isJUnitEnabled) {
|
||||
KotlinJUnitRunConfigurationProducer.getTestMethod(leaf)?.let { return it }
|
||||
}
|
||||
if (isTestNgEnabled) {
|
||||
KotlinTestNgConfigurationProducer.getTestClassAndMethod(leaf)?.second?.let { return it }
|
||||
}
|
||||
return null
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.scripting.gradle.importing
|
||||
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData
|
||||
import org.gradle.tooling.model.idea.IdeaProject
|
||||
import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel
|
||||
import org.jetbrains.kotlin.gradle.KotlinDslScriptAdditionalTask
|
||||
import org.jetbrains.kotlin.gradle.KotlinDslScriptModelProvider
|
||||
import org.jetbrains.kotlin.idea.scripting.gradle.kotlinDslScriptsModelImportSupported
|
||||
import org.jetbrains.plugins.gradle.model.ProjectImportModelProvider
|
||||
import org.jetbrains.plugins.gradle.model.ClassSetBuildImportModelProvider
|
||||
|
||||
class KotlinDslScriptModelResolver : KotlinDslScriptModelResolverCommon() {
|
||||
override fun requiresTaskRunning() = true
|
||||
|
||||
override fun getModelProvider() = KotlinDslScriptModelProvider()
|
||||
|
||||
override fun getProjectsLoadedModelProvider(): ProjectImportModelProvider? {
|
||||
return ClassSetBuildImportModelProvider(
|
||||
setOf(KotlinDslScriptAdditionalTask::class.java)
|
||||
)
|
||||
}
|
||||
|
||||
override fun populateProjectExtraModels(gradleProject: IdeaProject, ideProject: DataNode<ProjectData>) {
|
||||
super.populateProjectExtraModels(gradleProject, ideProject)
|
||||
|
||||
populateBuildModels(gradleProject, ideProject)
|
||||
|
||||
resolverCtx.models.includedBuilds.forEach { includedRoot ->
|
||||
populateBuildModels(includedRoot, ideProject)
|
||||
}
|
||||
}
|
||||
|
||||
private fun populateBuildModels(
|
||||
root: IdeaProject,
|
||||
ideProject: DataNode<ProjectData>
|
||||
) {
|
||||
root.modules.forEach {
|
||||
if (it.gradleProject.parent == null) {
|
||||
if (kotlinDslScriptsModelImportSupported(resolverCtx.projectGradleVersion)) {
|
||||
resolverCtx.getExtraProject(it, KotlinDslScriptsModel::class.java)?.let { model ->
|
||||
processScriptModel(resolverCtx, model, it.name)
|
||||
}
|
||||
}
|
||||
|
||||
saveGradleBuildEnvironment(resolverCtx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.scripting.gradle.settings
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
class StandaloneScriptsUIComponent(val project: Project) : StandaloneScriptsUIComponentCompat(project) {
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.codeInsight.gradle;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.task.ProjectTaskManager;
|
||||
|
||||
//BUNCH 193
|
||||
class ExternalSystemTestCaseBunch {
|
||||
|
||||
protected static boolean isDefaultRefreshCallback(Object callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static void build(Object[] buildableElements, Project myProject) {
|
||||
if (buildableElements instanceof Module[]) {
|
||||
ProjectTaskManager.getInstance(myProject).build((Module[])buildableElements);
|
||||
}
|
||||
else if (buildableElements instanceof Artifact[]) {
|
||||
ProjectTaskManager.getInstance(myProject).build((Artifact[])buildableElements);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user