Skip to content

Commit

Permalink
add build-gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
dalinaum committed Jul 7, 2015
1 parent 71b2d4c commit c48b4c7
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 0.1.0 - First Release
* Add `build-gradle`
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2015 <Your name here>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# atom-android
# Atom Android

Android development package
11 changes: 11 additions & 0 deletions keymaps/android.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Keybindings require three things to be fully defined: A selector that is
# matched against the focused element, the keystroke and the command to
# execute.
#
# Below is a basic keybinding which registers on all platforms by applying to
# the root workspace element.

# For more detailed documentation see
# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
'atom-workspace':
'ctrl-f9': 'android:build-gradle'
52 changes: 52 additions & 0 deletions lib/android.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
LogView = require './log-view'
{CompositeDisposable} = require 'atom'
{spawn} = require 'child_process'
AnsiHtmlStream = require 'ansi-html-stream'

module.exports = Android =
subscriptions: null
logView: null

activate: (state) ->
@logView = new LogView

# Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
@subscriptions = new CompositeDisposable

# Register command that toggles this view
@subscriptions.add atom.commands.add 'atom-workspace', 'android:build-gradle': => @buildGradle()

deactivate: ->
@subscriptions.dispose()
@logView.destroy()

buildGradle: ->
@logView.open()

editor = atom.workspace.getActiveTextEditor()
rootDirs = atom.project.rootDirectories

for i in [0...rootDirs.length]
if rootDirs[i].contains editor.getPath()
currentRootDir = rootDirs[i].path
break

options =
cwd: currentRootDir
env: process.env
build = spawn "gradle", ["assembleDebug", "--console=rich"], options

ansiHtmlStream = AnsiHtmlStream()

ansiHtmlStream.on 'data', (data) =>
@logView.addLine data

build.stdout.pipe ansiHtmlStream

build.stderr.on 'data', (data) ->
console.log "stderr: #{data}"

build.on 'close', (code) ->
alert "Build completed successfully." if code is 0
alert "Build faield. code #{code}" if code is not 0
console.log "child process exited with code: #{code}"
27 changes: 27 additions & 0 deletions lib/log-view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ScrollView} = require 'atom-space-pen-views'

module.exports =
class LogView extends ScrollView
@content: ->
@div class: "log-view", =>
@button "Close", click: 'close'
@div class: "detail", overflow: "auto", outlet: "container"

initialize: ->
super

open: ->
atom.workspace.addBottomPanel(item: this) unless @hasParent()

close: ->
@detach()

toggle: ->
if @hasParent()
@close()
else
@open()

addLine: (line) ->
@container.append "<p>#{line}</p>"
@container.scrollTop 99999
22 changes: 22 additions & 0 deletions menus/android.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details
'context-menu':
'atom-text-editor': [
{
'label': 'Toggle android'
'command': 'android:toggle'
}
]
'menu': [
{
'label': 'Packages'
'submenu': [
'label': 'android'
'submenu': [
{
'label': 'Build debug'
'command': 'android:build-debug'
}
]
]
}
]
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "android",
"main": "./lib/android",
"version": "0.0.0",
"description": "Android development package for Atom",
"keywords": [
"android",
"atom"
],
"activationCommands": {
"atom-workspace": "android:build-gradle"
},
"repository": "https://github.com/dalinaum/atom-android",
"license": "MIT",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {
"ansi-html-stream": "^0.0.3",
"atom-space-pen-views": "^2.0.3"
}
}
62 changes: 62 additions & 0 deletions spec/android-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Android = require '../lib/android'

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block.

describe "Android", ->
[workspaceElement, activationPromise] = []

beforeEach ->
workspaceElement = atom.views.getView(atom.workspace)
activationPromise = atom.packages.activatePackage('android')

describe "when the android:toggle event is triggered", ->
it "hides and shows the modal panel", ->
# Before the activation event the view is not on the DOM, and no panel
# has been created
expect(workspaceElement.querySelector('.android')).not.toExist()

# This is an activation event, triggering it will cause the package to be
# activated.
atom.commands.dispatch workspaceElement, 'android:toggle'

waitsForPromise ->
activationPromise

runs ->
expect(workspaceElement.querySelector('.android')).toExist()

androidElement = workspaceElement.querySelector('.android')
expect(androidElement).toExist()

androidPanel = atom.workspace.panelForItem(androidElement)
expect(androidPanel.isVisible()).toBe true
atom.commands.dispatch workspaceElement, 'android:toggle'
expect(androidPanel.isVisible()).toBe false

it "hides and shows the view", ->
# This test shows you an integration test testing at the view level.

# Attaching the workspaceElement to the DOM is required to allow the
# `toBeVisible()` matchers to work. Anything testing visibility or focus
# requires that the workspaceElement is on the DOM. Tests that attach the
# workspaceElement to the DOM are generally slower than those off DOM.
jasmine.attachToDOM(workspaceElement)

expect(workspaceElement.querySelector('.android')).not.toExist()

# This is an activation event, triggering it causes the package to be
# activated.
atom.commands.dispatch workspaceElement, 'android:toggle'

waitsForPromise ->
activationPromise

runs ->
# Now we can test for view visibility
androidElement = workspaceElement.querySelector('.android')
expect(androidElement).toBeVisible()
atom.commands.dispatch workspaceElement, 'android:toggle'
expect(androidElement).not.toBeVisible()
5 changes: 5 additions & 0 deletions spec/android-view-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AndroidView = require '../lib/android-view'

describe "AndroidView", ->
it "has one valid test", ->
expect("life").toBe "easy"
16 changes: 16 additions & 0 deletions styles/android.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// The ui-variables file is provided by base themes provided by Atom.
//
// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less
// for a full listing of what's available.
@import "ui-variables";

.android {

}

.log-view {
.detail {
max-height: 100px;
overflow: scroll;
}
}

0 comments on commit c48b4c7

Please sign in to comment.