Skip to content

Commit

Permalink
Add release / distribute support. (linkedin#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
efeg authored May 9, 2018
1 parent ef70e47 commit 4f83a21
Show file tree
Hide file tree
Showing 30 changed files with 360 additions and 100 deletions.
29 changes: 27 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
version: 2



jobs:

build:
Expand Down Expand Up @@ -31,3 +29,30 @@ jobs:
- store_artifacts:
path: build/libs

publish:
working_directory: ~/workspace
docker:
- image: circleci/openjdk:8-jdk
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "build.gradle" }}
- run:
command: ./gradlew distributeBuild

workflows:
version: 2
build-and-publish:
jobs:
- build:
filters:
tags:
only: /.*/
- publish:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+$/
147 changes: 140 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,68 @@
* Copyright 2017 LinkedIn Corp. Licensed under the BSD 2-Clause License (the "License"). See License in the project root for license information.
*/

plugins {
id "com.jfrog.artifactory"
id "idea"
}

group = 'com.linkedin.cruisecontrol'

project.ext {
pomConfig = {
url "https://github.com/linkedin/cruise-control"
licenses {
license {
name "BSD 2-CLAUSE LICENSE"
url "https://opensource.org/licenses/BSD-2-Clause"
}
}
developers {
developer {
name "Adem Efe Gencer"
email "[email protected]"
}
developer {
name "Jiangjie (Becket) Qin"
email "[email protected]"
}
developer {
name "Sir Joel Koshy"
email "[email protected]"
}
}
scm {
url "https://github.com/linkedin/cruise-control"
}
}
}


allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'

repositories {
mavenCentral()
jcenter()
}

//wrapper generation task
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
}
}

subprojects {
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'

test.dependsOn('checkstyleMain', 'checkstyleTest')

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

//code quality and inspections
checkstyle {
toolVersion = '7.5.1'
Expand Down Expand Up @@ -62,6 +104,8 @@ subprojects {
}

project(':cruise-control-core') {
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

configurations {
testOutput
Expand All @@ -75,6 +119,25 @@ project(':cruise-control-core') {
testOutput sourceSets.test.output
}

publishing {
publications {
java(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom.withXml {
def root = asNode()
root.appendNode('name', 'cruise-control-core')
root.appendNode('description', 'cruise control core related')
root.children().last() + rootProject.ext.pomConfig
}
}
}
}

artifactoryPublish.dependsOn assemble
artifactoryPublish.dependsOn publishToMavenLocal

sourceSets {
main {
java {
Expand All @@ -93,6 +156,8 @@ project(':cruise-control-core') {

project(':cruise-control') {
apply plugin: 'scala'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

//needed because our java classes depend on scala classes, so must be compiled by scala
sourceSets {
Expand Down Expand Up @@ -143,6 +208,25 @@ project(':cruise-control') {
testCompile 'commons-io:commons-io:2.5'
}

publishing {
publications {
java(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom.withXml {
def root = asNode()
root.appendNode('name', 'cruise-control')
root.appendNode('description', 'cruise control related')
root.children().last() + rootProject.ext.pomConfig
}
}
}
}

artifactoryPublish.dependsOn assemble
artifactoryPublish.dependsOn publishToMavenLocal

tasks.create(name: "copyDependantLibs", type: Copy) {
from (configurations.testRuntime) {
include('slf4j-log4j12*')
Expand All @@ -160,6 +244,8 @@ project(':cruise-control') {
}

project(':cruise-control-metrics-reporter') {
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

configurations {
testOutput
Expand All @@ -181,5 +267,52 @@ project(':cruise-control-metrics-reporter') {
testOutput sourceSets.test.output
}

publishing {
publications {
java(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom.withXml {
def root = asNode()
root.appendNode('name', 'cruise-control-metrics-reporter')
root.appendNode('description', 'cruise control metrics reporter related')
root.children().last() + rootProject.ext.pomConfig
}
}
}
}

artifactoryPublish.dependsOn assemble
artifactoryPublish.dependsOn publishToMavenLocal

}

artifactoryPublish.skip = true
artifactory {
contextUrl = 'https://linkedin.jfrog.io/linkedin'
publish {
repoKey = 'cruise-control'
username = System.getenv('ARTIFACTORY_USER')
password = System.getenv('ARTIFACTORY_KEY')

defaults {
publications ('java')
publishBuildInfo = true
publishArtifacts = true
publishPom = true
publishIvy = true
}
}
clientConfig.setIncludeEnvVars(false)
}

task distributeBuild(type: com.linkedin.gradle.build.DistributeTask) {
dependsOn ':artifactoryPublish', ':cruise-control:artifactoryPublish', ':cruise-control-core:artifactoryPublish', ':cruise-control-metrics-reporter:artifactoryPublish'
}

//wrapper generation task
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
distributionType = Wrapper.DistributionType.ALL
}
21 changes: 21 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id "java-gradle-plugin"
id "groovy"
id "idea"
}

repositories {
mavenLocal()
jcenter()
}

dependencies {
compile gradleApi()
compile localGroovy()

compile 'org.ajoberstar:gradle-git:1.2.0'
compile group: 'org.apache.httpcomponents', name: 'fluent-hc', version: '4.5.2'
compile('org.jfrog.buildinfo:build-info-extractor-gradle:4.5.4') {
exclude module: 'groovy-all'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.linkedin.gradle.build

import groovy.json.JsonBuilder
import org.apache.http.client.fluent.Request
import org.apache.http.entity.ContentType
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention

class DistributeTask extends DefaultTask {

@TaskAction
public void distributeBuild() {
ArtifactoryPluginConvention convention = project.convention.plugins.artifactory
def buildNumber = convention.clientConfig.info.buildNumber
def buildName = convention.clientConfig.info.buildName
def context = convention.clientConfig.publisher.contextUrl
def password = convention.clientConfig.publisher.password

if (password == null || password.equals("")) {
throw new IllegalArgumentException("password not set")
}

def body = [
"publish" : "true",
"overrideExistingFiles": "false",
"async" : "true",
"targetRepo" : "maven",
"sourceRepos" : ["cruise-control"],
"dryRun" : "false"
]

def bodyString = new JsonBuilder(body).toString()

def url = "$context/api/build/distribute/$buildName/$buildNumber"
logger.lifecycle("url {}", url)
def response = Request.Post(url)
.bodyString(bodyString, ContentType.APPLICATION_JSON)
.addHeader("X-JFrog-Art-Api", password)
.execute()
.returnResponse()

def bout = new ByteArrayOutputStream()
response.getEntity().writeTo(bout);
String errMsg = new String(bout.toByteArray());
logger.lifecycle("Distribute Response: {} {}", response, errMsg)

if (!Integer.toString(response.getStatusLine().getStatusCode()).startsWith("2")) {
throw new IOException("http post failed")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
* may change according to the values of other configurations. You can override {@link Recommender} to get valid
* values and set visibility of a configuration given the current configuration values.
*
* <p/>
* To use the class:
* <p/>
* <pre>
* ConfigDef defs = new ConfigDef();
*
Expand All @@ -42,7 +40,7 @@
* defs.define(&quot;config_with_dependents&quot;, Type.INT, &quot;Configuration with dependents.&quot;, &quot;group&quot;,
* 1, &quot;Config With Dependents&quot;, Arrays.asList(&quot;config_with_default&quot;,&quot;config_with_validator&quot;));
*
* Map&lt;String, String&gt; props = new HashMap&lt;&gt();
* Map&lt;String, String&gt; props = new HashMap&lt;&gt;();
* props.put(&quot;config_with_default&quot;, &quot;some value&quot;);
* props.put(&quot;config_with_dependents&quot;, &quot;some other value&quot;);
*
Expand All @@ -56,7 +54,6 @@
* List&lt;Config&gt; configs = defs.validate(props);
* The {@link Config} contains updated configuration information given the current configuration values.
* </pre>
* <p/>
* This class can be used standalone or in combination with {@link AbstractConfig} which provides some additional
* functionality for accessing configs.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* </ul>
* The validity of an entity is determined by its validity in all the windows. An entity is considered as invalid
* if there is an invalid window or there are too many windows with extrapolations.
* </p>
*
* <p>
* Furthermore, each entity belongs to an aggregation entity group. The aggregation entity group is only used
* for metric aggregation purpose. Users can specify the {@link AggregationOptions.Granularity} of the metric aggregation. The
Expand All @@ -65,7 +65,7 @@
* the entities in the same aggregation entity group.
* </li>
* </ul>
* </p>
*
* <p>
* From per window's perspective, for each window, there is a given set of <tt>valid</tt> entities and entity
* groups as described above. The validity of a window depends on the requirements specified in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,24 @@ public static Map<String, Object> getJsonStructure(ClusterModelStats clusterMode
}

/**
* Compare the given values. Return 1 if first > second, -1 if first < second, 0 otherwise.
* Compare the given values. Return 1 if first &gt; second, -1 if first &lt; second, 0 otherwise.
*
* @param d1 The first {@code double} to compare.
* @param d2 The second {@code double} to compare.
* @param resource the resource the current comparison is for.
* @return 1 if first > second, -1 if first < second, 0 otherwise.
* @return 1 if first &gt; second, -1 if first &lt; second, 0 otherwise.
*/
public static int compare(double d1, double d2, Resource resource) {
double epsilon = resource.epsilon(d1, d2);
return compare(d1, d2, epsilon);
}

/**
* Compare the given values. Return 1 if first > second, -1 if first < second, 0 otherwise.
* Compare the given values. Return 1 if first &gt; second, -1 if first &lt; second, 0 otherwise.
*
* @param d1 The first {@code double} to compare.
* @param d2 The second {@code double} to compare.
* @return 1 if first > second, -1 if first < second, 0 otherwise.
* @return 1 if first &gt; second, -1 if first &lt; second, 0 otherwise.
*/
public static int compare(double d1, double d2, double epsilon) {
if (d2 - d1 > epsilon) {
Expand Down
Loading

0 comments on commit 4f83a21

Please sign in to comment.