pindah 0.1.0.alpha → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -5,7 +5,15 @@ Rakefile
5
5
  bin/pindah
6
6
  lib/pindah.rb
7
7
  lib/pindah_cli.rb
8
- templates/initial_activity.mirah
8
+ templates/AndroidManifest.xml
9
9
  templates/build.xml
10
+ templates/main.xml
11
+ templates/strings.xml
12
+ templates/Rakefile
13
+ templates/initial_activity.mirah
14
+ templates/.gitignore
15
+ templates/res/drawable-mdpi/ic_launcher.png
16
+ templates/res/drawable-hdpi/ic_launcher.png
17
+ templates/res/drawable-ldpi/ic_launcher.png
10
18
  test/fixtures/HelloWorld.mirah
11
19
  test/pindah_cli_test.rb
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # pindah
1
+ # Pindah
2
2
 
3
3
  A tool for writing Android applications in [Mirah](http://mirah.org).
4
4
 
@@ -11,7 +11,7 @@ download "platform" packages corresponding with Android versions you
11
11
  wish to develop against. You'll need to install "Android SDK Platform
12
12
  tools" and at least one platform revision to get started. At the time
13
13
  of this writing, Android 2.1 (revision 7)
14
- [covers most of the market](http://developer.android.com/resources/dashboard/platform-versions.html)
14
+ [covers over 90% of the market](http://developer.android.com/resources/dashboard/platform-versions.html)
15
15
  and is a reasonable target for new applications. Once the platform
16
16
  tools are installed, place the SDK's <tt>platform-tools/</tt>
17
17
  directory on your $PATH as well.
@@ -24,16 +24,42 @@ and rake commands with jruby -S:
24
24
 
25
25
  ## Usage
26
26
 
27
- See [Garrett](http://github.com/technomancy/Garrett) for an example of
28
- basic usage.
29
-
30
- TODO: project template creation is not complete
27
+ The <tt>pindah</tt> executable will create a new project starting
28
+ point given a package name. A package is a namespace for your code
29
+ that is often derived from a domain name you own, but can be any
30
+ hierarchical identifier as long as it's unique.
31
31
 
32
- $ pindah hello.world hello_world [HelloActivity]
32
+ $ pindah create org.example.hello_world # optional path and activity name arguments
33
33
 
34
34
  $ cd hello_world && tree
35
-
36
- [TODO: project skeleton listing]
35
+ .
36
+ |-- AndroidManifest.xml
37
+ |-- libs
38
+ |-- Rakefile
39
+ |-- res
40
+ | |-- drawable-hdpi
41
+ | | `-- ic_launcher.png
42
+ | |-- drawable-ldpi
43
+ | | `-- ic_launcher.png
44
+ | |-- drawable-mdpi
45
+ | | `-- ic_launcher.png
46
+ | |-- layout
47
+ | | `-- main.xml
48
+ | `-- values
49
+ | `-- strings.xml
50
+ `-- src
51
+ `-- org
52
+ `-- example
53
+ `-- hello_world
54
+ `-- Start.mirah
55
+
56
+ 12 directories, 8 files
57
+
58
+ The <tt>res/</tt> directory contains application resources like icons,
59
+ layout descriptions, and strings. The <tt>AndroidManifest.xml</tt>
60
+ describes the contents and metadata of your application. The
61
+ <tt>src</tt> directory contains the source code inside your package
62
+ directory.
37
63
 
38
64
  $ rake -T
39
65
 
@@ -47,6 +73,29 @@ TODO: project template creation is not complete
47
73
  rake spec # Print the project spec
48
74
  rake uninstall # Uninstalls the application from a running emulator or dev...
49
75
 
76
+ $ rake debug
77
+
78
+ # [...]
79
+
80
+ $ ls -l bin/hello_world-debug.apk
81
+
82
+ -rw-r--r-- 1 user user 13222 Feb 7 23:16 bin/hello_world-debug.apk
83
+
84
+ This .apk file may be installed on a connected device or emulator with
85
+ <tt>rake install</tt>. It may even distributed for users to install
86
+ themselves, though stable versions should use the <tt>release</tt>
87
+ task.
88
+
89
+ The official documentation has
90
+ [more details on building](http://developer.android.com/guide/developing/other-ide.html#Building). The
91
+ main difference between Pindah and the standard Ant build is that the
92
+ Rakefile replaces build.xml as well as all the properties files. The
93
+ page above also explains how to get an emulator running for testing
94
+ your application.
95
+
96
+ See [Garrett](http://github.com/technomancy/Garrett) for an example of
97
+ a basic project.
98
+
50
99
  ## See Also
51
100
 
52
101
  If Mirah is just too low-level and you need something more dynamic,
data/bin/pindah CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'pindah_cli'))
4
+
4
5
  begin
5
- PindahCLI.create *ARGV
6
+ PindahCLI.send *ARGV
6
7
  rescue ArgumentError
7
- puts "Usage: #{File.basename(__FILE__)} org.mirah.HelloWorld ~/hello_world [HelloActivity]"
8
+ abort "Usage: #{File.basename($0)} create org.example.hello [/path/to/hello_world] [HelloActivity]"
8
9
  end
9
-
10
- abort "TODO: create project skeleton: rakefile, manifest, resources"
data/lib/pindah.rb CHANGED
@@ -12,7 +12,7 @@ end
12
12
  require "mirah"
13
13
 
14
14
  module Pindah
15
- VERSION = '0.1.0.alpha'
15
+ VERSION = '0.1.0'
16
16
 
17
17
  def self.infer_sdk_location(path)
18
18
  tools = path.split(":").detect {|p| File.exists? "#{p}/android" }
@@ -25,6 +25,9 @@ module Pindah
25
25
  :sdk => Pindah.infer_sdk_location(ENV["PATH"])
26
26
  }
27
27
 
28
+ TARGETS = { "1.5" => 3, "1.6" => 4,
29
+ "2.1" => 7, "2.2" => 8, "2.3" => 9 }
30
+
28
31
  ANT_TASKS = ["clean", "javac", "compile", "debug", "release",
29
32
  "install", "uninstall"]
30
33
 
@@ -43,15 +46,16 @@ module Pindah
43
46
  task :default => [:install]
44
47
 
45
48
  def self.spec=(spec)
46
- abort "Must provide :target version in Pindah.spec!" if !spec[:target]
49
+ abort "Must provide :target_version in Pindah.spec!" if !spec[:target_version]
47
50
  abort "Must provide :name in Pindah.spec!" if !spec[:name]
48
51
 
49
52
  @spec = DEFAULTS.merge(spec)
50
53
 
51
54
  @spec[:root] = File.expand_path "."
55
+ @spec[:target] ||= TARGETS[@spec[:target_version].to_s.sub(/android-/, '')]
52
56
  @spec[:classes] ||= "#{@spec[:output]}/classes"
53
57
  @spec[:classpath] << @spec[:classes]
54
- @spec[:classpath] << "#{@spec[:sdk]}/platforms/#{@spec[:target]}/android.jar"
58
+ @spec[:classpath] << "#{@spec[:sdk]}/platforms/android-#{@spec[:target]}/android.jar"
55
59
  @spec[:log_spec] ||= "ActivityManager:I #{@spec[:name]}:D " +
56
60
  "AndroidRuntime:E *:S"
57
61
 
@@ -68,8 +72,10 @@ module Pindah
68
72
  File.open(build, "w") { |f| f.puts build_template.result(binding) }
69
73
  at_exit { File.delete build }
70
74
 
71
- { "target" => @spec[:target],
72
- "target-version" => @spec[:target],
75
+ # TODO: add key signing config
76
+ { "target" => "android-#{@spec[:target]}",
77
+ "target-version" => "android-#{@spec[:target_version]}",
78
+ "src" => @spec[:src],
73
79
  "sdk.dir" => @spec[:sdk],
74
80
  "classes" => @spec[:classes],
75
81
  "classpath" => @spec[:classpath].join(Java::JavaLang::System::
@@ -78,7 +84,6 @@ module Pindah
78
84
  @ant.project.set_user_property(key, value)
79
85
  end
80
86
 
81
- # TODO: compile task execs mirahc instead of running inside current JVM
82
87
  Ant::ProjectHelper.configure_project(@ant.project, java.io.File.new(build))
83
88
 
84
89
  # Turn ant tasks into rake tasks
data/lib/pindah_cli.rb CHANGED
@@ -1,42 +1,72 @@
1
1
  require 'fileutils'
2
+ require 'erb'
2
3
 
3
4
  module PindahCLI
4
- DEFAULT_TARGET = 'android-7'
5
- DEFAULT_VERSION = 'android-2.1'
5
+ DEFAULT_TARGET_VERSION = '2.1'
6
6
 
7
- def self.log(msg)
8
- STDERR.puts msg
9
- end
10
-
11
- def self.create(namespace, location, activity_name=nil)
12
- segments = namespace.split('.')
7
+ def self.create(package, location=nil, activity_name="Start")
8
+ segments = package.split('.')
9
+ location ||= segments.last
13
10
  src_dir = File.join(location, 'src', *segments)
11
+
12
+ mkdir location, File.join('src', *segments)
13
+ mkdir location, 'libs'
14
+ mkdir location, 'res'
15
+ mkdir location, 'res/drawable-hdpi'
16
+ mkdir location, 'res/drawable-ldpi'
17
+ mkdir location, 'res/drawable-mdpi'
18
+ mkdir location, 'res/layout'
19
+ mkdir location, 'res/values'
20
+
21
+ name = location.split("/").last
22
+ app_name = name.split(/[-_]/).map{ |w| w.capitalize }.join(" ")
23
+
14
24
  FileUtils.mkdir_p src_dir
15
- log "Created '#{src_dir}'."
16
25
 
17
- spec_location = File.join(location, 'Pindah.spec')
18
- spec_template = File.read(File.join(File.dirname(__FILE__),
19
- '..', 'templates',
20
- 'Pindah.spec'))
26
+ create_templated("Rakefile", location, binding)
27
+ create_templated("AndroidManifest.xml", location, binding)
28
+ create_templated("main.xml", File.join(location, 'res', 'layout'), binding)
29
+ create_templated("strings.xml", File.join(location, 'res', 'values'), binding)
30
+ create_templated(".gitignore", location, binding)
21
31
 
22
- File.open(spec_location, 'w') do |f|
23
- f.puts spec_template.gsub(/PROJECT_NAME/, segments[-1]).
24
- gsub(/API_TARGET/, DEFAULT_TARGET).
25
- gsub(/API_VERSION/, DEFAULT_VERSION)
32
+ # Default icons of various sizes
33
+ ["hdpi", "mdpi", "ldpi"].each do |s|
34
+ FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'templates', "res",
35
+ "drawable-#{s}", "ic_launcher.png"),
36
+ File.join(location, "res", "drawable-#{s}", "ic_launcher.png"))
26
37
  end
27
- log "Created Pindah spec file in '#{spec_location}'."
38
+
39
+ log "Created project in #{location}."
28
40
 
41
+ activity_location = File.join(src_dir, "#{activity_name}.mirah")
42
+ activity_template = File.read(File.join(File.dirname(__FILE__),
43
+ '..', 'templates',
44
+ 'initial_activity.mirah'))
29
45
 
30
- if activity_name
31
- activity_location = File.join(src_dir, "#{activity_name}.mirah")
32
- activity_template = File.read(File.join(File.dirname(__FILE__),
33
- '..', 'templates',
34
- 'initial_activity.mirah'))
46
+ File.open(activity_location, 'w') do |f|
47
+ f.puts activity_template.gsub(/INITIAL_ACTIVITY/, activity_name)
48
+ end
49
+ log "Created Activity '#{activity_name}' in '#{activity_location}'."
50
+ end
35
51
 
36
- File.open(activity_location, 'w') do |f|
37
- f.puts activity_template.gsub(/INITIAL_ACTIVITY/, activity_name)
38
- end
39
- log "Created Activity '#{activity_name}' in '#{activity_location}'."
52
+ private
53
+ def self.log(msg)
54
+ STDERR.puts msg
55
+ end
56
+
57
+ def self.create_templated(name, project_location, scope)
58
+ location = File.join(project_location, name)
59
+ template = File.read(File.join(File.dirname(__FILE__),
60
+ '..', 'templates', name))
61
+
62
+ File.open(location, 'w') do |f|
63
+ f.puts ERB.new(template).result(scope)
40
64
  end
41
65
  end
66
+
67
+ def self.mkdir(base, directory)
68
+ location = File.join(base, directory)
69
+ FileUtils.mkdir_p location
70
+ log "Created '#{location}'."
71
+ end
42
72
  end
@@ -0,0 +1,2 @@
1
+ bin
2
+ gen
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ package="<%= package %>"
4
+ android:versionCode="1"
5
+ android:versionName="1.0">
6
+ <application android:label="@string/app_name"
7
+ android:debuggable="true"
8
+ android:icon="@drawable/ic_launcher" >
9
+ <% if activity_name %>
10
+ <activity android:name="<%= activity_name %>"
11
+ android:label="@string/app_name">
12
+ <intent-filter>
13
+ <action android:name="android.intent.action.MAIN" />
14
+ <category android:name="android.intent.category.LAUNCHER" />
15
+ </intent-filter>
16
+ </activity>
17
+ <% end %>
18
+ </application>
19
+ </manifest>
@@ -0,0 +1,7 @@
1
+ require "rubygems"
2
+ require "pindah"
3
+
4
+ Pindah.spec = {
5
+ :name => "<%= name %>",
6
+ :target_version => "<%= DEFAULT_TARGET_VERSION %>"
7
+ }
data/templates/build.xml CHANGED
@@ -10,13 +10,20 @@
10
10
  classname="com.android.ant.SetupTask"
11
11
  classpathref="android.antlibs" />
12
12
 
13
+ <taskdef name="mirahc" classname="org.mirah.ant.Compile" />
14
+
15
+ <!-- TODO: better support for mixed-source builds -->
13
16
  <target name="javac" description="Compiles R.java and other gen/ files.">
14
- <javac srcdir="gen" destdir="${classes}" includeantruntime="false" />
17
+ <javac srcdir="gen" destdir="${classes}"
18
+ includeantruntime="false" failonerror="true" />
15
19
  </target>
16
20
 
17
21
  <target name="compile" depends="-resource-src, -aidl, javac"
18
22
  description="Compiles project's .mirah files into .class files">
19
- <exec executable="mirahc" dir="src">
23
+ <!-- TODO: mirahc task doesn't infer package correctly.
24
+ <mirahc src="${src}" destdir="${classes}"
25
+ classpath="${classpath}" /> -->
26
+ <exec executable="mirahc" dir="src" failonerror="true">
20
27
  <arg line="-c ${classpath}" />
21
28
  <arg line="-d ${classes}" />
22
29
  <arg value="." />
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:orientation="vertical"
4
+ android:layout_width="fill_parent"
5
+ android:layout_height="fill_parent"
6
+ >
7
+ <TextView
8
+ android:layout_width="fill_parent"
9
+ android:layout_height="wrap_content"
10
+ android:text="Hello World, <%= name %>"
11
+ />
12
+ </LinearLayout>
13
+
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="app_name"><%= app_name %></string>
4
+ </resources>
@@ -1,50 +1,85 @@
1
1
  require 'test/unit'
2
- require 'tempfile'
2
+ require 'tmpdir'
3
3
  require 'fileutils'
4
4
  require 'rubygems'
5
5
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'pindah_cli'))
6
6
 
7
7
  class PindahCLITest < Test::Unit::TestCase
8
+ PWD = File.expand_path(File.dirname(__FILE__))
9
+
10
+ def fixture(name)
11
+ File.read(File.join(PWD, 'fixtures', name))
12
+ end
13
+
8
14
  def setup
9
- $local_pwd ||= File.expand_path(File.dirname(__FILE__))
10
- @project_path = File.expand_path(Tempfile.new('pindah').path + ".d")
11
- FileUtils.mkdir_p @project_path
12
- Dir.chdir @project_path
15
+ @temp = Dir.mktmpdir("pindah-")
16
+ @project_path = "#{@temp}/testapp"
17
+ FileUtils.mkdir_p File.dirname(@temp)
18
+ Dir.chdir File.dirname(@temp)
19
+ PindahCLI.create('tld.pindah.testapp', @project_path, 'HelloWorld')
13
20
  end
14
21
 
15
22
  def teardown
16
- FileUtils.rm_rf @project_path
23
+ FileUtils.rm_rf @temp
17
24
  end
18
25
 
19
26
  def test_create_should_create_basic_project_structure
20
27
  PindahCLI.create('tld.pindah.testapp', '.')
21
28
  assert File.directory?(File.join(@project_path, 'src', 'tld', 'pindah', 'testapp'))
29
+
30
+ directories = %w{ src/tld/pindah/testapp bin libs res
31
+ res/drawable-hdpi res/drawable-ldpi
32
+ res/drawable-mdpi res/layout res/values }
33
+
34
+ directories.each do |d|
35
+ expected = File.join(@project_path, d)
36
+ assert File.directory?(expected), "Expected #{expected.inspect} to be a directory."
37
+ end
22
38
  end
23
39
 
24
- def test_create_should_create_pindah_spec_file
25
- PindahCLI.create('tld.pindah.testapp', '.')
26
- assert File.exists?(File.join(@project_path, 'Pindah.spec'))
40
+ def test_create_should_create_rakefile
41
+ rake_path = File.join(@project_path, 'Rakefile')
27
42
 
28
- expected = File.read(File.join($local_pwd,
29
- 'fixtures',
30
- 'Pindah.spec'))
31
- actual = File.read(File.join(@project_path,
32
- 'Pindah.spec'))
33
- assert_equal expected, actual
43
+ assert File.exists?(rake_path)
44
+ assert_equal fixture("Rakefile"), File.read(rake_path)
34
45
  end
35
46
 
36
47
  def test_create_should_create_an_activity_if_desired
37
- PindahCLI.create('tld.pindah.testapp', '.', 'HelloWorld')
38
-
39
- expected = File.read(File.join($local_pwd,
40
- 'fixtures',
41
- 'HelloWorld.mirah'))
42
- actual = File.read(File.join(@project_path,
43
- 'src',
44
- 'tld',
45
- 'pindah',
46
- 'testapp',
47
- 'HelloWorld.mirah'))
48
- assert_equal expected, actual
48
+ actual = File.read(File.join(@project_path, 'src',
49
+ 'tld', 'pindah',
50
+ 'testapp', 'HelloWorld.mirah'))
51
+ assert_equal fixture('HelloWorld.mirah'), actual
52
+ end
53
+
54
+ def test_create_should_create_manifest
55
+ manifest_path = File.join(@project_path, 'AndroidManifest.xml')
56
+
57
+ assert File.exists?(manifest_path)
58
+ assert_equal fixture("AndroidManifest.xml").gsub(/\s+/, ' '), File.read(manifest_path).gsub(/\s+/, ' ')
59
+ end
60
+
61
+ def test_create_should_create_manifest_without_activity
62
+ @temp = Dir.mktmpdir("pindah-")
63
+ @project_path = "#{@temp}/testapp"
64
+ FileUtils.mkdir_p File.dirname(@temp)
65
+ Dir.chdir File.dirname(@temp)
66
+ PindahCLI.create('tld.pindah.testapp', @project_path)
67
+
68
+ manifest_path = File.join(@project_path, 'AndroidManifest.xml')
69
+
70
+ assert File.exists?(manifest_path)
71
+ assert_equal fixture("AndroidManifest.xml.no-activity").gsub(/\s+/, ' '), File.read(manifest_path).gsub(/\s+/, ' ')
72
+ end
73
+
74
+ def test_create_should_create_strings
75
+ path = File.join(@project_path, 'res', 'values', 'strings.xml')
76
+ assert File.exists?(path)
77
+ assert_equal fixture("strings.xml").strip, File.read(path).strip
78
+ end
79
+
80
+ def test_create_should_create_layout
81
+ path = File.join(@project_path, 'res', 'layout', 'main.xml')
82
+ assert File.exists?(path)
83
+ assert_equal fixture("main.xml").strip, File.read(path).strip
49
84
  end
50
85
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pindah
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 0.1.0.alpha
4
+ prerelease:
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Phil Hagelberg
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-02 00:00:00 -08:00
13
+ date: 2011-02-08 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -53,8 +53,16 @@ files:
53
53
  - bin/pindah
54
54
  - lib/pindah.rb
55
55
  - lib/pindah_cli.rb
56
- - templates/initial_activity.mirah
56
+ - templates/AndroidManifest.xml
57
57
  - templates/build.xml
58
+ - templates/main.xml
59
+ - templates/strings.xml
60
+ - templates/Rakefile
61
+ - templates/initial_activity.mirah
62
+ - templates/.gitignore
63
+ - templates/res/drawable-mdpi/ic_launcher.png
64
+ - templates/res/drawable-hdpi/ic_launcher.png
65
+ - templates/res/drawable-ldpi/ic_launcher.png
58
66
  - test/fixtures/HelloWorld.mirah
59
67
  - test/pindah_cli_test.rb
60
68
  has_rdoc: true
@@ -76,9 +84,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
84
  required_rubygems_version: !ruby/object:Gem::Requirement
77
85
  none: false
78
86
  requirements:
79
- - - ">"
87
+ - - ">="
80
88
  - !ruby/object:Gem::Version
81
- version: 1.3.1
89
+ version: "0"
82
90
  requirements: []
83
91
 
84
92
  rubyforge_project: pindah