Skip to content

Commit

Permalink
Merge pull request linkedin#48 from linkedin/gradle
Browse files Browse the repository at this point in the history
Merge Gradle branch to master
  • Loading branch information
drewhannay authored Dec 7, 2016
2 parents 7cd6af5 + a6a0387 commit 6ad8dfc
Show file tree
Hide file tree
Showing 306 changed files with 766 additions and 58,046 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
*.iml
.DS_Store
.idea
target
.gradle
build/
reports/
local.properties
external/
*.ipr
*.iws
*.svn
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: android
android:
components:
- tools
- platform-tools
- android-25
- build-tools-25.0.0
- extra-android-m2repository
- extra-android-support

jdk:
- oraclejdk8

script:
- ./gradlew clean build

branches:
except:
- gh-pages

notifications:
email: false

sudo: false

cache:
directories:
- $HOME/.gradle
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Change Log

## Current Snapshot

- Project ownership transferred to LinkedIn
- Updated dx dependency to latest tag release from AOSP (7.1.0_r7) and switched from copied source to [Jake Wharton's repackaged artifact](https://github.com/JakeWharton/dalvik-dx)
- Converted tests to run as Android tests rather than in Vogar
- Fixed monitorExit instructions being added as monitorEnter
- Updated Mockito dependency to version 1.10.19
- Fixed transitive dependency configuration [#22](https://github.com/linkedin/dexmaker/issues/22)

## Version 1.4 (2015-07-23

## Version 1.3 (2015-06-22)
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributing

If you would like to contribute to Dexmaker you can do so through Github by forking the repository and sending a pull request.

When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible.

## Bugs

Please [create an issue](https://github.com/linkedin/dexmaker/issues/new) and include enough information to reproduce the issue you are seeing.
Be sure to include which Android version you're using as well.

## Feature requests

Please [create an issue](https://github.com/linkedin/dexmaker/issues/new) to describe the feature and why you think it would be useful.

## Reporting security issues

Please report security issues to [[email protected]](mailto:[email protected]) with a subject line of this format:

`GitHub linkedin/dexmaker - [summary of issue]`
File renamed without changes.
7 changes: 7 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2016 LinkedIn Corp.
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.
89 changes: 30 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# Dexmaker
[![Build Status](https://travis-ci.org/linkedin/dexmaker.svg?branch=master)](https://travis-ci.org/linkedin/dexmaker)

A Java-language API for doing compile time or runtime code generation targeting the Dalvik VM. Unlike
[cglib](http://cglib.sourceforge.net/) or [ASM](http://asm.ow2.org/), this library creates Dalvik `.dex`
files instead of Java `.class` files.

It has a small, close-to-the-metal API. This API mirrors the
[Dalvik bytecode specification](http://source.android.com/tech/dalvik/dalvik-bytecode.html) giving you tight
[Dalvik bytecode specification](http://source.android.com/devices/tech/dalvik/dalvik-bytecode.html) giving you tight
control over the bytecode emitted. Code is generated instruction-by-instruction; you bring your own abstract
syntax tree if you need one. And since it uses Dalvik's `dx` tool as a backend, you get efficient register
allocation and regular/wide instruction selection for free.

Class Proxies
-------------

Dexmaker includes a stock code generator for [class proxies](https://github.com/crittercism/dexmaker/blob/master/dexmaker/src/main/java/com/android/dx/stock/ProxyBuilder.java).
If you just want to do AOP or class mocking, you don't need to mess around with bytecodes.

Mockito Mocks
-------------
## What does it do?

Dexmaker includes class proxy support for [Mockito](https://github.com/mockito/mockito). Add the mockito
and the dexmaker `.jar` files to your Android test project's `libs/` directory and you can use Mockito
in your Android unit tests.
### Mockito Mocks
Dexmaker lets you use the [Mockito](https://github.com/mockito/mockito) mocking library in your
Android projects by generating Dalvik bytecode class proxies. Just add an
`androidTestCompile` dependency on `dexmaker-mockito` and you can use Mockito in your Android Instrumentation tests.

This requires Mockito 1.10.5 or newer.
Dexmaker currently targets Mockito 1.10.19.

Runtime Code Generation
-----------------------
### Class Proxies
Dexmaker includes a stock code generator for [class proxies](https://github.com/crittercism/dexmaker/blob/master/dexmaker/src/main/java/com/android/dx/stock/ProxyBuilder.java).
If you just want to do AOP or class mocking, you don't need to mess around with bytecodes.

### Runtime Code Generation
This example generates a class and a method. It then loads that class into the current process and invokes its method.

``` java
Expand Down Expand Up @@ -105,51 +104,23 @@ public final class HelloWorldMaker {
}
```

Use it in your app
------------------

Maven users can get dexmaker from Sonatype's central repository. The Mockito dependency is optional.

``` xml
<dependency>
<groupId>com.crittercism.dexmaker</groupId>
<artifactId>dexmaker</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.crittercism.dexmaker</groupId>
<artifactId>dexmaker-dx</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.crittercism.dexmaker</groupId>
<artifactId>dexmaker-mockito</artifactId>
<version>1.4</version>
</dependency>
```

Gradle users can import the project this way:

testCompile "com.crittercism.dexmaker:dexmaker:1.4"
testCompile "com.crittercism.dexmaker:dexmaker-dx:1.4"
testCompile "com.crittercism.dexmaker:dexmaker-mockito:1.4"


Download [dexmaker-1.4.jar](https://oss.sonatype.org/service/local/repositories/releases/content/com/crittercism/dexmaker/dexmaker/1.4/dexmaker-1.4.jar), [dexmaker-dx-1.4.jar](https://oss.sonatype.org/service/local/repositories/releases/content/com/crittercism/dexmaker/dexmaker-dx/1.4/dexmaker-dx-1.4.jar)
and [dexmaker-mockito-1.4.jar](https://oss.sonatype.org/service/local/repositories/releases/content/com/crittercism/dexmaker/dexmaker-mockito/1.4/dexmaker-mockito-1.4.jar).
## Download

Run the Unit Tests
------------------

The unit tests for dexmaker must be run on a dalvikvm. In order to do this, you can use [Vogar](https://android.googlesource.com/platform/external/vogar/) in the following fashion:
For Mockito support, download the latest .jar via Maven:
```xml
<dependency>
<groupId>com.linkedin.dexmaker</groupId>
<artifactId>dexmaker-mockito</artifactId>
<version>1.5.0</version>
<type>pom</type>
</dependency>
```

``` bash
$ java -jar vogar.jar \
--mode device \
--sourcepath /path/to/dexmaker/dexmaker/src/test/java \
--sourcepath /path/to/dexmaker/dexmaker/src/main/java \
--sourcepath /path/to/dexmaker/dx/src/main/java \
--device-dir /data/dexmaker /path/to/dexmaker/dexmaker/src/test/
or Gradle:
```
androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito:1.5.0'
```

_Note: The dependency on Mockito will be transitively included, so there's no need to specify both Mockito AND dexmaker-mockito_

Download [vogar.jar](https://vogar.googlecode.com/files/vogar.jar).
You can also download the files manually from [Bintray](https://bintray.com/linkedin/maven/dexmaker/) if you prefer.
22 changes: 22 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Releasing
========

1. Change the version in `gradle.properties` to a non-SNAPSHOT version.
2. Update the `CHANGELOG.md` for the impending release.
3. Update the `README.md` with the new version.
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
5. `git tag -a X.Y.Z -m "Version X.Y.Z"` (where X.Y.Z is the new version)
6. `./gradlew clean artifactory distributeBuild`
7. Update the `gradle.properties` to the next SNAPSHOT version.
8. `git commit -am "Prepare next development version."`
9. `git push && git push --tags`
10. Create a new release in the releases tab on GitHub


Prerequisites
-------------

Set the following environment variables:

* `ARTIFACTORY_USER` - LinkedIn Artifactory username for releasing to `com.linkedin.dexmaker`.
* `ARTIFACTORY_KEY` - LinkedIn Artifactory API key for releasing to `com.linkedin.dexmaker`.
41 changes: 41 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import com.linkedin.gradle.DistributeTask

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.0"
}
}

apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

allprojects {
group = GROUP_ID
}

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

defaults {
publications 'lib'
}

publishArtifacts = true
}
clientConfig.setIncludeEnvVars(false)
}

task distributeBuild(type: DistributeTask) {
dependsOn ':artifactoryPublish', 'dexmaker:artifactoryPublish', 'dexmaker-mockito:artifactoryPublish'
}
19 changes: 19 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id 'groovy'
}

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.4.0') {
exclude module: 'groovy-all'
}
}
39 changes: 39 additions & 0 deletions buildSrc/src/main/groovy/com/linkedin/gradle/DistributeTask.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.linkedin.gradle

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

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

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

def content = Request.Post("$context/api/build/distribute/$buildName/$buildNumber")
.bodyString(bodyString, ContentType.APPLICATION_JSON)
.addHeader("X-JFrog-Art-Api", password)
.execute()
.returnContent()

logger.lifecycle("Distribute Response: {}", content.asString())
}
}
70 changes: 70 additions & 0 deletions dexmaker-mockito/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

version = VERSION_NAME

targetCompatibility = '1.7'
sourceCompatibility = '1.7'

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

// TODO: fix javadoc errors and then remove this
javadoc.failOnError = false

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

publishing {
publications {
lib(MavenPublication) {
from components.java

artifact sourcesJar
artifact javadocJar

pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
description = "Implementation of the Mockito API for use on the Android Dalvik VM"
url 'https://github.com/linkedin/dexmaker'
scm {
url 'https://github.com/linkedin/dexmaker'
connection 'scm:git:git://github.com/linkedin/dexmaker.git'
developerConnection 'https://github.com/linkedin/dexmaker.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/license/LICENSE-2.0.txt'
distribution 'repo'
}
}

developers {
developer {
id 'com.linkedin'
name 'LinkedIn Corp'
email ''
}
}
}
}
}
}
}

repositories {
jcenter()
}

dependencies {
compile project(":dexmaker")

compile 'org.mockito:mockito-core:1.10.19'
}
Loading

0 comments on commit 6ad8dfc

Please sign in to comment.