From 2581208c8b1622b3dd74824959edeed2cfa3fa03 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 21 Nov 2017 14:56:47 +0300 Subject: [PATCH] [grails] use gradle init script to log test events (IDEA-162555) --- .../test/runner/GradleConsoleProperties.java | 23 +++----- .../execution/GradleExecutionHelper.java | 53 +++++++++---------- 2 files changed, 31 insertions(+), 45 deletions(-) diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleConsoleProperties.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleConsoleProperties.java index 0576fa536533..7a8b420d8f09 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleConsoleProperties.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleConsoleProperties.java @@ -1,21 +1,8 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.gradle.execution.test.runner; import com.intellij.execution.Executor; +import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties; import com.intellij.openapi.actionSystem.DefaultActionGroup; @@ -41,7 +28,11 @@ public class GradleConsoleProperties extends SMTRunnerConsoleProperties { @Nullable private File gradleTestReport; public GradleConsoleProperties(final ExternalSystemRunConfiguration configuration, Executor executor) { - super(configuration, configuration.getSettings().getExternalSystemId().getReadableName(), executor); + this(configuration, configuration.getSettings().getExternalSystemId().getReadableName(), executor); + } + + public GradleConsoleProperties(@NotNull RunConfiguration config, @NotNull String testFrameworkName, @NotNull Executor executor) { + super(config, testFrameworkName, executor); } public void setGradleTestReport(@Nullable File gradleTestReport) { diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleExecutionHelper.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleExecutionHelper.java index b836134fa717..036e74782156 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleExecutionHelper.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/execution/GradleExecutionHelper.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.gradle.service.execution; import com.intellij.execution.configurations.GeneralCommandLine; @@ -508,22 +494,31 @@ public class GradleExecutionHelper { } buf.append(']'); - InputStream stream = Init.class.getResourceAsStream("/org/jetbrains/plugins/gradle/tooling/internal/init/testFilterInit.gradle"); - try { - if (stream == null) { - LOG.warn("Can't get test filter init script template"); - return; - } - String script = FileUtil.loadTextAndClose(stream).replaceFirst(Pattern.quote("${TEST_NAME_INCLUDES}"), Matcher.quoteReplacement(buf.toString())); - final File tempFile = writeToFileGradleInitScript(script, "ijtestinit"); - ContainerUtil.addAll(args, GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath()); + String path = renderInitScript(buf.toString()); + if (path != null) { + ContainerUtil.addAll(args, GradleConstants.INIT_SCRIPT_CMD_OPTION, path); } - catch (Exception e) { - LOG.warn("Can't generate IJ gradle test filter init script", e); - } - finally { - StreamUtil.closeStream(stream); + } + } + + @Nullable + public static String renderInitScript(@NotNull String testArgs) { + InputStream stream = Init.class.getResourceAsStream("/org/jetbrains/plugins/gradle/tooling/internal/init/testFilterInit.gradle"); + try { + if (stream == null) { + LOG.error("Can't get test filter init script template"); + return null; } + String script = FileUtil.loadTextAndClose(stream).replaceFirst(Pattern.quote("${TEST_NAME_INCLUDES}"), Matcher.quoteReplacement(testArgs)); + final File tempFile = writeToFileGradleInitScript(script, "ijtestinit"); + return tempFile.getAbsolutePath(); + } + catch (Exception e) { + LOG.warn("Can't generate IJ gradle test filter init script", e); + return null; + } + finally { + StreamUtil.closeStream(stream); } }