You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2018/11/12 22:42:15 UTC

[beam] branch master updated: [BEAM-3608] Vendor guava 20.0 (#6809)

This is an automated email from the ASF dual-hosted git repository.

lcwik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new c41e4fb  [BEAM-3608] Vendor guava 20.0 (#6809)
c41e4fb is described below

commit c41e4fbbeb6ec622a0072e01afcba95428faafb9
Author: Kenn Knowles <ke...@kennknowles.com>
AuthorDate: Mon Nov 12 15:42:06 2018 -0700

    [BEAM-3608] Vendor guava 20.0 (#6809)
    
    * [BEAM-3608] Vendor Guava 20.0
    
    * [BEAM-] Add VendorJavaPlugin
    
    An initial pass on a plugin to create vendored dependencies. It does not
    vendor transitive deps or have any subtle intelligence.
---
 .../org/apache/beam/gradle/BeamModulePlugin.groovy |  52 +------
 .../org/apache/beam/gradle/Repositories.groovy     |  79 +++++++++++
 .../org/apache/beam/gradle/VendorJavaPlugin.groovy | 149 +++++++++++++++++++++
 settings.gradle                                    |   2 +
 vendor/guava-20_0/build.gradle                     |  32 +++++
 5 files changed, 264 insertions(+), 50 deletions(-)

diff --git a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
index 783522d..e2e3a0f 100644
--- a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
+++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
@@ -271,34 +271,8 @@ class BeamModulePlugin implements Plugin<Project> {
       project.version += '-SNAPSHOT'
     }
 
-    project.repositories {
-      maven { url project.offlineRepositoryRoot }
-
-      // To run gradle in offline mode, one must first invoke
-      // 'updateOfflineRepository' to create an offline repo
-      // inside the root project directory. See the application
-      // of the offline repo plugin within build_rules.gradle
-      // for further details.
-      if (project.gradle.startParameter.isOffline()) {
-        return
-      }
-
-      mavenCentral()
-      mavenLocal()
-      jcenter()
-
-      // Spring for resolving pentaho dependency.
-      maven { url "https://repo.spring.io/plugins-release/" }
-
-      // Release staging repository
-      maven { url "https://oss.sonatype.org/content/repositories/staging/" }
-
-      // Apache nightly snapshots
-      maven { url "https://repository.apache.org/snapshots" }
-
-      // Apache release snapshots
-      maven { url "https://repository.apache.org/content/repositories/releases" }
-    }
+    // Register all Beam repositories and configuration tweaks
+    Repositories.register(project)
 
     // Apply a plugin which enables configuring projects imported into Intellij.
     project.apply plugin: "idea"
@@ -614,28 +588,6 @@ class BeamModulePlugin implements Plugin<Project> {
       }
       project.artifacts.archives project.packageTests
 
-      // Apply a plugin which provides the 'updateOfflineRepository' task that creates an offline
-      // repository. This offline repository satisfies all Gradle build dependencies and Java
-      // project dependencies. The offline repository is placed within $rootDir/offline-repo
-      // but can be overridden by specifying '-PofflineRepositoryRoot=/path/to/repo'.
-      // Note that parallel build must be disabled when executing 'updateOfflineRepository'
-      // by specifying '--no-parallel', see
-      // https://github.com/mdietrichstein/gradle-offline-dependencies-plugin/issues/3
-      project.apply plugin: "io.pry.gradle.offline_dependencies"
-      project.offlineDependencies {
-        repositories {
-          mavenLocal()
-          mavenCentral()
-          jcenter()
-          maven { url "https://plugins.gradle.org/m2/" }
-          maven { url "http://repo.spring.io/plugins-release" }
-          maven { url project.offlineRepositoryRoot }
-        }
-        includeSources = false
-        includeJavadocs = false
-        includeIvyXmls = false
-      }
-
       // Configures annotation processing for commonly used annotation processors
       // across all Java projects.
       project.apply plugin: "net.ltgt.apt"
diff --git a/buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy b/buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy
new file mode 100644
index 0000000..8840d4c
--- /dev/null
+++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.beam.gradle
+
+import org.gradle.api.Project
+
+class Repositories {
+
+  static void register(Project project) {
+
+    project.repositories {
+      maven { url project.offlineRepositoryRoot }
+
+      // To run gradle in offline mode, one must first invoke
+      // 'updateOfflineRepository' to create an offline repo
+      // inside the root project directory. See the application
+      // of the offline repo plugin within build_rules.gradle
+      // for further details.
+      if (project.gradle.startParameter.isOffline()) {
+        return
+      }
+
+      mavenCentral()
+      mavenLocal()
+      jcenter()
+
+      // Spring for resolving pentaho dependency.
+      maven { url "https://repo.spring.io/plugins-release/" }
+
+      // Release staging repository
+      maven { url "https://oss.sonatype.org/content/repositories/staging/" }
+
+      // Apache nightly snapshots
+      maven { url "https://repository.apache.org/snapshots" }
+
+      // Apache release snapshots
+      maven { url "https://repository.apache.org/content/repositories/releases" }
+    }
+
+    // Apply a plugin which provides the 'updateOfflineRepository' task that creates an offline
+    // repository. This offline repository satisfies all Gradle build dependencies and Java
+    // project dependencies. The offline repository is placed within $rootDir/offline-repo
+    // but can be overridden by specifying '-PofflineRepositoryRoot=/path/to/repo'.
+    // Note that parallel build must be disabled when executing 'updateOfflineRepository'
+    // by specifying '--no-parallel', see
+    // https://github.com/mdietrichstein/gradle-offline-dependencies-plugin/issues/3
+    project.apply plugin: "io.pry.gradle.offline_dependencies"
+    project.offlineDependencies {
+      repositories {
+        mavenLocal()
+        mavenCentral()
+        jcenter()
+        maven { url "https://plugins.gradle.org/m2/" }
+        maven { url "http://repo.spring.io/plugins-release" }
+        maven { url project.offlineRepositoryRoot }
+      }
+      includeSources = false
+      includeJavadocs = false
+      includeIvyXmls = false
+    }
+  }
+}
+
diff --git a/buildSrc/src/main/groovy/org/apache/beam/gradle/VendorJavaPlugin.groovy b/buildSrc/src/main/groovy/org/apache/beam/gradle/VendorJavaPlugin.groovy
new file mode 100644
index 0000000..d668f09
--- /dev/null
+++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/VendorJavaPlugin.groovy
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.beam.gradle
+
+import org.gradle.api.GradleException
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.file.FileTree
+import org.gradle.api.publish.maven.MavenPublication
+
+class VendorJavaPlugin implements Plugin<Project> {
+
+  static class VendorJavaPluginConfig {
+    String dependency
+    List<String> packagesToRelocate
+    String intoPackage
+    String groupId
+    String artifactId
+    String version
+  }
+
+  def isRelease(Project project) {
+    return project.hasProperty('isRelease')
+  }
+
+  void apply(Project project) {
+
+    // Deferred configuration so the extension is available; otherwise it
+    // needs to happen in a task, but not sure where to attach that
+    // task
+    project.ext.vendorJava = {
+      VendorJavaPluginConfig config = it ? it as VendorJavaPluginConfig : new VendorJavaPluginConfig()
+
+      project.apply plugin: 'com.github.johnrengelman.shadow'
+
+      project.apply plugin: 'java'
+
+      // Register all Beam repositories and configuration tweaks
+      Repositories.register(project)
+
+      // Apply a plugin which provides tasks for dependency / property / task reports.
+      // See https://docs.gradle.org/current/userguide/project_reports_plugin.html
+      // for further details. This is typically very useful to look at the "htmlDependencyReport"
+      // when attempting to resolve dependency issues.
+      project.apply plugin: "project-report"
+
+      project.dependencies { compile "${config.dependency}" }
+
+      project.shadowJar {
+        config.packagesToRelocate.each { srcNamespace ->
+          relocate(srcNamespace, "${config.intoPackage}.${srcNamespace}")
+        }
+        classifier = null
+        mergeServiceFiles()
+        zip64 true
+      }
+
+      project.task('validateVendoring', dependsOn: 'shadowJar') {
+        inputs.files project.configurations.shadow.artifacts.files
+        doLast {
+          project.configurations.shadow.artifacts.files.each {
+            FileTree exposedClasses = project.zipTree(it).matching {
+              include "**/*.class"
+              exclude "org/apache/beam/vendor/**"
+              // BEAM-5919: Exclude paths for Java 9 multi-release jars.
+              exclude "META-INF/versions/*/module-info.class"
+              exclude "META-INF/versions/*/org/apache/beam/vendor/**"
+            }
+            if (exposedClasses.files) {
+              throw new GradleException("$it exposed classes outside of org.apache.beam namespace: ${exposedClasses.files}")
+            }
+          }
+        }
+      }
+
+      project.apply plugin: 'maven-publish'
+
+      project.publishing {
+        repositories {
+          maven {
+            name "testPublicationLocal"
+            url "file://${project.rootProject.projectDir}/testPublication/"
+          }
+          maven {
+            url(project.properties['distMgmtSnapshotsUrl'] ?: isRelease(project)
+                    ? 'https://repository.apache.org/service/local/staging/deploy/maven2'
+                    : 'https://repository.apache.org/content/repositories/snapshots')
+
+            // We attempt to find and load credentials from ~/.m2/settings.xml file that a user
+            // has configured with the Apache release and snapshot staging credentials.
+            // <settings>
+            //   <servers>
+            //     <server>
+            //       <id>apache.releases.https</id>
+            //       <username>USER_TOKEN</username>
+            //       <password>PASS_TOKEN</password>
+            //     </server>
+            //     <server>
+            //       <id>apache.snapshots.https</id>
+            //       <username>USER_TOKEN</username>
+            //       <password>PASS_TOKEN</password>
+            //     </server>
+            //   </servers>
+            // </settings>
+            def settingsXml = new File(System.getProperty('user.home'), '.m2/settings.xml')
+            if (settingsXml.exists()) {
+              def serverId = (project.properties['distMgmtServerId'] ?: isRelease(project)
+                      ? 'apache.releases.https' : 'apache.snapshots.https')
+              def m2SettingCreds = new XmlSlurper().parse(settingsXml).servers.server.find { server -> serverId.equals(server.id.text()) }
+              if (m2SettingCreds) {
+                credentials {
+                  username m2SettingCreds.username.text()
+                  password m2SettingCreds.password.text()
+                }
+              }
+            }
+          }
+        }
+
+        publications {
+          mavenJava(MavenPublication) {
+            groupId = config.groupId
+            artifactId = config.artifactId
+            version = config.version
+            artifact project.shadowJar
+          }
+        }
+      }
+    }
+  }
+
+}
diff --git a/settings.gradle b/settings.gradle
index 6f5152e..a2a4941 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -186,6 +186,8 @@ include "beam-sdks-java-test-utils"
 project(":beam-sdks-java-test-utils").dir = file("sdks/java/testing/test-utils")
 include "beam-vendor-sdks-java-extensions-protobuf"
 project(":beam-vendor-sdks-java-extensions-protobuf").dir = file("vendor/sdks-java-extensions-protobuf")
+include "beam-vendor-guava-20_0"
+project(":beam-vendor-guava-20_0").dir = file("vendor/guava-20_0")
 include "beam-website"
 project(":beam-website").dir = file("website")
 include "beam-runners-google-cloud-dataflow-java-legacy-worker"
diff --git a/vendor/guava-20_0/build.gradle b/vendor/guava-20_0/build.gradle
new file mode 100644
index 0000000..d6bc6e4
--- /dev/null
+++ b/vendor/guava-20_0/build.gradle
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+apply plugin: org.apache.beam.gradle.VendorJavaPlugin
+
+description = "Apache Beam :: Vendored Dependencies :: Guava 20"
+
+group = "org.apache.beam"
+version = "0.1"
+
+
+vendorJava(
+  dependency: "com.google.guava:guava:20.0",
+  packagesToRelocate: ["com.google.common", "com.google.thirdparty"],
+  intoPackage: "org.apache.beam.guava.v20_0",
+  artifactId: "beam-vendor-guava-20_0"
+)