Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 97710200C28 for ; Sun, 26 Feb 2017 23:47:26 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 96584160B82; Sun, 26 Feb 2017 22:47:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BDD97160B8B for ; Sun, 26 Feb 2017 23:47:24 +0100 (CET) Received: (qmail 2300 invoked by uid 500); 26 Feb 2017 22:47:24 -0000 Mailing-List: contact commits-help@polygene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@polygene.apache.org Delivered-To: mailing list commits@polygene.apache.org Received: (qmail 1949 invoked by uid 99); 26 Feb 2017 22:47:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Feb 2017 22:47:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A85C6DFFC2; Sun, 26 Feb 2017 22:47:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: paulmerlin@apache.org To: commits@polygene.apache.org Date: Sun, 26 Feb 2017 22:47:42 -0000 Message-Id: <695729af84c2439ba8661c4d9fedcad7@git.apache.org> In-Reply-To: <1d84b8ef2c1442f3bdbeaed8cbc396ed@git.apache.org> References: <1d84b8ef2c1442f3bdbeaed8cbc396ed@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [20/50] [abbrv] polygene-java git commit: build & docker-tests: revamp how Docker availability is detected archived-at: Sun, 26 Feb 2017 22:47:26 -0000 build & docker-tests: revamp how Docker availability is detected Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/431695a1 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/431695a1 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/431695a1 Branch: refs/heads/serialization-3.0 Commit: 431695a190496f6b94f31a3c423dc1a6b0b63b06 Parents: 5860c1e Author: Paul Merlin Authored: Sat Feb 25 15:12:48 2017 +0100 Committer: Paul Merlin Committed: Sat Feb 25 15:12:48 2017 +0100 ---------------------------------------------------------------------- .../polygene/gradle/code/CodePlugin.groovy | 22 ++++++++++-- .../internals/InternalDockerPlugin.groovy | 38 +++++++++++++++++--- internals/testsupport-internal/build.gradle | 3 +- .../polygene/test/internal/DockerRule.java | 8 ++--- 4 files changed, 60 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy b/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy index 1448341..eb605c9 100644 --- a/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy +++ b/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy @@ -22,9 +22,11 @@ import org.apache.polygene.gradle.BasePlugin import org.apache.polygene.gradle.TaskGroups import org.apache.polygene.gradle.dependencies.DependenciesDeclarationExtension import org.apache.polygene.gradle.dependencies.DependenciesPlugin +import org.gradle.api.Action import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.Task import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.plugins.osgi.OsgiManifest import org.gradle.api.tasks.bundling.AbstractArchiveTask @@ -38,6 +40,8 @@ import org.gradle.testing.jacoco.tasks.JacocoReport @CompileStatic class CodePlugin implements Plugin { + public static final String DOCKER_DISABLED_EXTRA_PROPERTY = 'dockerDisabled' + @Override void apply( Project project ) { @@ -91,7 +95,7 @@ class CodePlugin implements Plugin def maxTestWorkers = ( parallel ? project.gradle.startParameter.maxWorkerCount : 1 ) as int // The space in the directory name is intentional def allTestsDir = project.file "$project.buildDir/tmp/test files" - project.tasks.withType( Test ) { Test testTask -> + def testTasks = project.tasks.withType( Test ) { Test testTask -> testTask.onlyIf { !project.hasProperty( 'skipTests' ) } testTask.testLogging.info.exceptionFormat = TestExceptionFormat.FULL testTask.maxHeapSize = '1g' @@ -123,8 +127,22 @@ class CodePlugin implements Plugin project.delete testDir } } - testTask.inputs.property( 'polygeneTestSupportDockerHostEnv', System.getenv( 'DOCKER_HOST' ) ) } + // Configuration task to honor disabling Docker when unavailable + project.tasks.create( 'configureDockerForTest', { Task task -> + // TODO Untangle docker connectivity check & test task configuration + task.dependsOn ':internals:testsupport-internal:checkDockerConnectivity' + testTasks.each { it.dependsOn task } + task.inputs.property 'polygeneTestSupportDockerDisabled', + { project.findProperty( DOCKER_DISABLED_EXTRA_PROPERTY ) } + task.doLast { + boolean dockerDisabled = project.findProperty( DOCKER_DISABLED_EXTRA_PROPERTY ) + testTasks.each { testTask -> + testTask.inputs.property 'polygeneTestSupportDockerDisabled', dockerDisabled + testTask.systemProperty 'DOCKER_DISABLED', dockerDisabled + } + } + } as Action ) } private static void configureJar( Project project ) http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy index 898a075..cdfd95d 100644 --- a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy +++ b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy @@ -19,13 +19,17 @@ package org.apache.polygene.gradle.structure.internals import com.bmuschko.gradle.docker.DockerExtension import com.bmuschko.gradle.docker.DockerRemoteApiPlugin +import com.bmuschko.gradle.docker.tasks.DockerVersion import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage import groovy.transform.CompileStatic import org.apache.polygene.gradle.BasePlugin +import org.apache.polygene.gradle.code.CodePlugin import org.apache.polygene.gradle.code.PublishNaming import org.apache.polygene.gradle.dependencies.DependenciesPlugin +import org.gradle.api.Action import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.logging.LogLevel @CompileStatic class InternalDockerPlugin implements Plugin @@ -40,6 +44,7 @@ class InternalDockerPlugin implements Plugin project.plugins.apply BasePlugin project.plugins.apply DependenciesPlugin applyDockerPlugin( project ) + applyDockerSwitch( project ) applyDockerBuildImage( project ) } @@ -47,9 +52,29 @@ class InternalDockerPlugin implements Plugin { project.plugins.apply DockerRemoteApiPlugin def dockerExtension = project.extensions.getByType DockerExtension - dockerExtension.certPath = dockerCertPath ? - new File( dockerCertPath ) : - new File( System.getProperty( 'user.home' ), '.boot2docker/certs/boot2docker-vm' ) + // TLS support + if( dockerCertPath ) + { + dockerExtension.certPath = new File( dockerCertPath ) + } + } + + private void applyDockerSwitch( Project project ) + { + project.tasks.create( 'checkDockerConnectivity', DockerVersion, { DockerVersion task -> + task.onError = { ex -> + // Disable Docker for this build + project.rootProject.extensions.extraProperties.set( CodePlugin.DOCKER_DISABLED_EXTRA_PROPERTY, true ) + if( project.logger.isEnabled( LogLevel.INFO ) ) + { + project.logger.info 'Unable to connect to Docker, all Docker tasks will be SKIPPED', ex + } + else + { + project.logger.lifecycle "Unable to connect to Docker, all Docker tasks will be SKIPPED\n ${ ( ( Exception ) ex ).message }" + } + } + } as Action ) } private void applyDockerBuildImage( Project project ) @@ -62,7 +87,12 @@ class InternalDockerPlugin implements Plugin project.tasks.create( taskName, DockerBuildImage ) { DockerBuildImage task -> task.group = 'docker' task.description = "Build $dockerName Docker image" - task.onlyIf { dockerHost } + task.dependsOn 'checkDockerConnectivity' + task.onlyIf { + def extra = project.rootProject.extensions.extraProperties + !( extra.has( CodePlugin.DOCKER_DISABLED_EXTRA_PROPERTY ) && + extra.get( CodePlugin.DOCKER_DISABLED_EXTRA_PROPERTY ) ) + } task.inputs.property 'dockerMachineName', dockerMachineName task.inputs.property 'dockerHostEnv', dockerHost task.inputs.property 'dockerCertPath', dockerCertPath http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/internals/testsupport-internal/build.gradle ---------------------------------------------------------------------- diff --git a/internals/testsupport-internal/build.gradle b/internals/testsupport-internal/build.gradle index d65e648..fc70ba0 100644 --- a/internals/testsupport-internal/build.gradle +++ b/internals/testsupport-internal/build.gradle @@ -21,7 +21,8 @@ apply plugin: 'polygene-internal-docker' dependencies { api polygene.core.testsupport - api libraries.docker_junit + + implementation libraries.docker_junit runtimeOnly polygene.core.runtime } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java ---------------------------------------------------------------------- diff --git a/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java b/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java index cea44c8..dce7150 100644 --- a/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java +++ b/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java @@ -25,11 +25,11 @@ import org.junit.runners.model.Statement; import pl.domzal.junit.docker.rule.DockerRuleBuilder; import pl.domzal.junit.docker.rule.WaitFor; -import static org.junit.Assume.assumeNotNull; +import static org.junit.Assume.assumeFalse; public class DockerRule implements TestRule { - private final String dockerHost = System.getenv( "DOCKER_HOST" ); + private final boolean dockerDisabled = Boolean.valueOf( System.getProperty( "DOCKER_DISABLED", "false" ) ); private final pl.domzal.junit.docker.rule.DockerRule dockerRule; public DockerRule( String image, int... portsToWaitFor ) @@ -39,7 +39,7 @@ public class DockerRule implements TestRule public DockerRule( String image, Map environment, int... portsToWaitFor ) { - if( dockerHost == null ) + if( dockerDisabled ) { dockerRule = null; } @@ -58,7 +58,7 @@ public class DockerRule implements TestRule @Override public Statement apply( Statement base, Description description ) { - assumeNotNull( dockerHost ); + assumeFalse( dockerDisabled ); return dockerRule.apply( base, description ); }