Giter VIP home page Giter VIP logo

stalker's Introduction

Stalker Build Status

Stalker detects affected Java classes given a set of changed Java source files. It does this by examining bytecode and completing the closure on dependencies.

Usage

build.gradle

buildscript {
  repositories {
      mavenCentral()
  }
  dependencies {
      classpath "com.vandalsoftware.tools.gradle:stalker:0.4.+"
  }
}

Configuration

build.gradle

apply plugin: 'stalker'

stalker uses a project's source files and classpaths for detecting changes and provides a default configuration for these.

For java projects, the default configuration looks like:

stalker {
  srcRoot "src/main/java"
  srcRoot "src/test/java"
  srcClassPath "$buildDir/classes/main"
  srcClassPath "$buildDir/classes/test"
  targetClassPath "$buildDir/classes/test"
}

For android projects, the default configuration looks like:

stalker {
  srcRoot "src/main/java"
  srcRoot "src/androidTest/java"
  srcClassPath "$buildDir/classes/debug"
  srcClassPath "$buildDir/classes/release"
  targetClassPath "$buildDir/classes/test/debug"
  targetClassPath "$buildDir/classes/test/release"
}

For android projects that define productFlavors, the default configuration looks like:

stalker {
  srcRoot "src/main/java"
  srcRoot "src/androidTest/java"
  srcRoot "src/flavor1/java"
  srcClassPath "$buildDir/classes/flavor1/debug"
  srcClassPath "$buildDir/classes/flavor1/release"
  targetClassPath "$buildDir/classes/test/flavor1/debug"
  targetClassPath "$buildDir/classes/test/flavor1/release"
}

If you need to provide your own source files and classpaths, you may do so using the stalker extension.

stalker {
  srcRoot "src/main/java"
  srcClassPath "$buildDir/classes/main"
  targetClassPath "$buildDir/classes/test"
}

Currently, stalker obtains a list of changed files by relying on Git. To use it, you must be tracking a git repository in your working directory:

$ git init

By default, it will use HEAD as its reference. You can configure this by setting the revision property.

For example:

stalker {
  ...
  revison = project.has("rev") ? rev : "HEAD"
}

You might then run stalker like this...

$ ./gradlew stalk -Prev=a34dfef0 --info

...which outputs something along these lines.

com.vandalsoftware.android.common.IoUtils used by build/classes/test/com/vandalsoftware/android/common/IoUtilsTests.class
com.vandalsoftware.android.common.IoUtilsTests

That's pretty interesting but not particularly useful since the output is stuck on the command line. However, Stalker allows you to direct output anywhere you want.

build.gradle

stalker {
  standardOutput = new FileOutputStream(new File("out.txt"))
}

out.txt

com.vandalsoftware.android.common.IoUtilsTests

We can now take the output of this file and input it into any script we write to execute the tests. For example, in this imaginary Python script I wrote.

$ cat out.txt | test_runner.py -s mycooldevice

Taking it one step further, we can append a closure to the stalk task to run after it completes:

build.gradle

stalk << {
    affectedClasses.each() {
        println "adb shell am instrument -w -e class " + it + " com.vandalsoftware.android.tests/android.test.InstrumentationTestRunner"
    }
}

Which produces some output:

adb shell am instrument -w -e class com.vandalsoftware.android.common.IoUtilsTests com.vandalsoftware.android.tests/android.test.InstrumentationTestRunner

License

Apache License, Version 2.0

stalker's People

Contributors

jle avatar lien avatar

Stargazers

Eric Frohnhoefer avatar Sean Kenny avatar Nabil Hachicha avatar Jing Li avatar James Little avatar Israel Ferrer Camacho avatar David Lichtenberg avatar neodaoist avatar Daniel Velazco avatar Morrison Cole avatar Hajime Morrita avatar Vijay Sharma avatar Kai Liao avatar Mateusz Buczek avatar Louie de la Rosa avatar Jerzy Chałupski avatar haocheng avatar Jonathan Yee avatar Artur Termenji avatar Łukasz Milewski avatar Imanol Pérez Iriarte avatar Avram Lyon avatar Michael Evans avatar Stefano avatar Michael Furtak avatar Gethin James avatar Max Borghino avatar Wade avatar Sarp Centel avatar

Watchers

Max Borghino avatar Sara Beykpour avatar  avatar James Cloos avatar Steve Kojder avatar

stalker's Issues

Scrub input logs

The plugin should print info level logs on what it uses as inputs so the user can identify what is being used for inspection at a glance.

For example:

Source root:
  /src/main/java/
  /src/test/java/
Target classpath:
  /build/classes/test/
Source classspath:
  /build/classes/main/
  /build/classes/test/

Integrate JGit

Instead of using the Exec task, use JGit for tighter integration with Git SCM

Add default configuration for Java projects

Instead of having the user configure srcRoot and srcClassPath manually, those options should be overrides.

The defaults should be detected based on what plugin was applied:

apply plugin: 'java'
apply plugin: 'stalker'

Should generate:

stalk {
    srcRoot "src/main/java"
    srcRoot "src/test/java"
    srcClassPath "$buildDir/classes/main"
    srcClassPath "$buildDir/classes/test"
    targetClassPath "$buildDir/classes/test"
}

This way, the typical user only needs to apply the plugin and it "just works."

Run tests against changes not staged for commit

Or at least give an option to do so.

It feels weird to commit changes every time you want to trigger stalker, and it does not guarantee that you commit on the green (yeah, you can rebase, but... really?).

I plan on using this plugin in combination with (our test plugin)[https://github.com/novoda/gradle-android-test-plugin]. Using gradle -Dtest.single= for running single unit tests we might be able to do something that resembles TDD on Android.

👍 keep up the good work

Have a sample project that showcases what you can do with the plugin

And keep it up to date ;)

When I follow the instruction on the README I get the error Could not find method srcClassPath() for arguments "$buildDir/classes/main". Your sample test-projects contradicts the README specifying ""${buildDir}/classes/main" both for srcClassPath and targetClassPath, I'm not sure if that's what you want.

Anyway, if you can use Maven snapshots instead of maven local at least we can try your nightly builds :shipit:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.