Search in sources :

Example 11 with BuildTask

use of org.gradle.testkit.runner.BuildTask in project liferay-blade-samples by liferay.

the class BladeSamplesTest method testServiceWrapperGradleTemplate.

@Test
public void testServiceWrapperGradleTemplate() throws Exception {
    File projectPath = BladeCLIUtil.createProject(_testDir, "service-wrapper", "serviceoverride", "-s", "com.liferay.portal.kernel.service.UserLocalServiceWrapper");
    BuildTask buildtask = GradleRunnerUtil.executeGradleRunner(projectPath, "build");
    GradleRunnerUtil.verifyGradleRunnerOutput(buildtask);
    File buildOutput = new File(projectPath + "/build/libs/serviceoverride-1.0.0.jar");
    Assert.assertTrue(buildOutput.exists());
    String bundleID = BladeCLIUtil.installBundle(buildOutput);
    BladeCLIUtil.startBundle(bundleID);
    BladeCLIUtil.uninstallBundle(bundleID);
}
Also used : BuildTask(org.gradle.testkit.runner.BuildTask) File(java.io.File) Test(org.junit.Test)

Example 12 with BuildTask

use of org.gradle.testkit.runner.BuildTask in project liferay-blade-samples by liferay.

the class BladeSamplesTest method testServiceBuilderGradleTemplate.

@Test
public void testServiceBuilderGradleTemplate() throws Exception {
    File projectPath = BladeCLIUtil.createProject(_testDir, "service-builder", "guestbook", "-p", "com.liferay.docs.guestbook");
    BuildTask buildService = GradleRunnerUtil.executeGradleRunner(projectPath, "buildService");
    GradleRunnerUtil.verifyGradleRunnerOutput(buildService);
    BuildTask buildtask = GradleRunnerUtil.executeGradleRunner(projectPath, "build");
    GradleRunnerUtil.verifyGradleRunnerOutput(buildtask);
    File buildApiOutput = new File(projectPath + "/guestbook-api/build/libs" + "/com.liferay.docs.guestbook.api-1.0.0.jar");
    File buildServiceOutput = new File(projectPath + "/guestbook-service/build/libs" + "/com.liferay.docs.guestbook.service-1.0.0.jar");
    Assert.assertTrue(buildApiOutput.exists());
    Assert.assertTrue(buildServiceOutput.exists());
    String bundleIDApi = BladeCLIUtil.installBundle(buildApiOutput);
    String bundleIDService = BladeCLIUtil.installBundle(buildServiceOutput);
    BladeCLIUtil.startBundle(bundleIDApi);
    BladeCLIUtil.startBundle(bundleIDService);
    BladeCLIUtil.uninstallBundle(bundleIDApi, bundleIDService);
}
Also used : BuildTask(org.gradle.testkit.runner.BuildTask) File(java.io.File) Test(org.junit.Test)

Example 13 with BuildTask

use of org.gradle.testkit.runner.BuildTask in project jib by google.

the class JibPluginIntegrationTest method buildAndRun.

private static String buildAndRun(TestProject testProject, String imageReference) throws IOException, InterruptedException {
    BuildResult buildResult = testProject.build();
    BuildTask jibTask = buildResult.task(":jib");
    Assert.assertNotNull(jibTask);
    Assert.assertEquals(TaskOutcome.SUCCESS, jibTask.getOutcome());
    Assert.assertThat(buildResult.getOutput(), CoreMatchers.containsString("Built and pushed image as " + imageReference));
    new Command("docker", "pull", imageReference).run();
    return new Command("docker", "run", imageReference).run();
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) BuildTask(org.gradle.testkit.runner.BuildTask) Command(com.google.cloud.tools.jib.Command)

Example 14 with BuildTask

use of org.gradle.testkit.runner.BuildTask in project gradle by gradle.

the class ToolingApiGradleExecutor method run.

@Override
public GradleExecutionResult run(GradleExecutionParameters parameters) {
    final StreamByteBuffer outputBuffer = new StreamByteBuffer();
    final OutputStream syncOutput = new SynchronizedOutputStream(outputBuffer.getOutputStream());
    final List<BuildTask> tasks = new ArrayList<BuildTask>();
    maybeRegisterCleanup();
    GradleConnector gradleConnector = buildConnector(parameters.getGradleUserHome(), parameters.getProjectDir(), parameters.isEmbedded(), parameters.getGradleProvider());
    ProjectConnection connection = null;
    GradleVersion targetGradleVersion = null;
    try {
        connection = gradleConnector.connect();
        targetGradleVersion = determineTargetGradleVersion(connection);
        if (targetGradleVersion.compareTo(TestKitFeature.RUN_BUILDS.getSince()) < 0) {
            throw new UnsupportedFeatureException(String.format("The version of Gradle you are using (%s) is not supported by TestKit. TestKit supports all Gradle versions 2.6 and later.", targetGradleVersion.getVersion()));
        }
        DefaultBuildLauncher launcher = (DefaultBuildLauncher) connection.newBuild();
        launcher.setStandardOutput(new NoCloseOutputStream(teeOutput(syncOutput, parameters.getStandardOutput())));
        launcher.setStandardError(new NoCloseOutputStream(teeOutput(syncOutput, parameters.getStandardError())));
        if (parameters.getStandardInput() != null) {
            launcher.setStandardInput(parameters.getStandardInput());
        }
        launcher.addProgressListener(new TaskExecutionProgressListener(tasks), OperationType.TASK);
        launcher.withArguments(parameters.getBuildArgs().toArray(new String[0]));
        launcher.setJvmArguments(parameters.getJvmArgs().toArray(new String[0]));
        launcher.setEnvironmentVariables(parameters.getEnvironment());
        if (!parameters.getInjectedClassPath().isEmpty()) {
            if (targetGradleVersion.compareTo(TestKitFeature.PLUGIN_CLASSPATH_INJECTION.getSince()) < 0) {
                throw new UnsupportedFeatureException("support plugin classpath injection", targetGradleVersion, TestKitFeature.PLUGIN_CLASSPATH_INJECTION.getSince());
            }
            launcher.withInjectedClassPath(parameters.getInjectedClassPath());
        }
        launcher.run();
    } catch (UnsupportedVersionException e) {
        throw new InvalidRunnerConfigurationException("The build could not be executed due to a feature not being supported by the target Gradle version", e);
    } catch (BuildException t) {
        return new GradleExecutionResult(new BuildOperationParameters(targetGradleVersion, parameters.isEmbedded()), outputBuffer.readAsString(), tasks, t);
    } catch (GradleConnectionException t) {
        StringBuilder message = new StringBuilder("An error occurred executing build with ");
        if (parameters.getBuildArgs().isEmpty()) {
            message.append("no args");
        } else {
            message.append("args '");
            message.append(CollectionUtils.join(" ", parameters.getBuildArgs()));
            message.append("'");
        }
        message.append(" in directory '").append(parameters.getProjectDir().getAbsolutePath()).append("'");
        String capturedOutput = outputBuffer.readAsString();
        if (!capturedOutput.isEmpty()) {
            message.append(". Output before error:").append(SystemProperties.getInstance().getLineSeparator()).append(capturedOutput);
        }
        throw new IllegalStateException(message.toString(), t);
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
    return new GradleExecutionResult(new BuildOperationParameters(targetGradleVersion, parameters.isEmbedded()), outputBuffer.readAsString(), tasks);
}
Also used : BuildTask(org.gradle.testkit.runner.BuildTask) UnsupportedFeatureException(org.gradle.testkit.runner.UnsupportedFeatureException) GradleConnectionException(org.gradle.tooling.GradleConnectionException) SynchronizedOutputStream(org.gradle.testkit.runner.internal.io.SynchronizedOutputStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) NoCloseOutputStream(org.gradle.testkit.runner.internal.io.NoCloseOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ProjectConnection(org.gradle.tooling.ProjectConnection) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) InvalidRunnerConfigurationException(org.gradle.testkit.runner.InvalidRunnerConfigurationException) DefaultBuildLauncher(org.gradle.tooling.internal.consumer.DefaultBuildLauncher) GradleConnector(org.gradle.tooling.GradleConnector) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) SynchronizedOutputStream(org.gradle.testkit.runner.internal.io.SynchronizedOutputStream) BuildException(org.gradle.tooling.BuildException) GradleVersion(org.gradle.util.GradleVersion) NoCloseOutputStream(org.gradle.testkit.runner.internal.io.NoCloseOutputStream) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException)

Aggregations

BuildTask (org.gradle.testkit.runner.BuildTask)14 Test (org.junit.Test)11 File (java.io.File)9 BuildResult (org.gradle.testkit.runner.BuildResult)4 ArrayList (java.util.ArrayList)2 TaskOutcome (org.gradle.testkit.runner.TaskOutcome)2 Command (com.google.cloud.tools.jib.Command)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 OutputStream (java.io.OutputStream)1 Writer (java.io.Writer)1 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)1 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)1 GradleRunner (org.gradle.testkit.runner.GradleRunner)1 InvalidRunnerConfigurationException (org.gradle.testkit.runner.InvalidRunnerConfigurationException)1 UnsupportedFeatureException (org.gradle.testkit.runner.UnsupportedFeatureException)1 NoCloseOutputStream (org.gradle.testkit.runner.internal.io.NoCloseOutputStream)1 SynchronizedOutputStream (org.gradle.testkit.runner.internal.io.SynchronizedOutputStream)1 BuildException (org.gradle.tooling.BuildException)1