flergl-java_properties 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/properties2yaml +71 -0
- data/java_properties.gemspec +2 -2
- metadata +2 -1
data/bin/properties2yaml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-6-12.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
# NOTE: Adding gem lib dir to includes path
|
7
|
+
# This probably isn't the right way to do this, but until I know how
|
8
|
+
# this works.
|
9
|
+
$:.unshift "#{File.dirname(__FILE__)}/../lib/"
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'rubygems'
|
13
|
+
rescue LoadError
|
14
|
+
# no rubygems to load, so we fail silently
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'optparse'
|
18
|
+
require 'java_properties'
|
19
|
+
require 'yaml'
|
20
|
+
|
21
|
+
OPTIONS = {
|
22
|
+
:stdin => false
|
23
|
+
}
|
24
|
+
MANDATORY_OPTIONS = %w( )
|
25
|
+
|
26
|
+
parser = OptionParser.new do |opts|
|
27
|
+
opts.banner = <<BANNER
|
28
|
+
Converts a Java properties file to YAML.
|
29
|
+
|
30
|
+
Usage: #{File.basename($0)} [options] [INPUT] [OUTPUT]
|
31
|
+
|
32
|
+
Options are:
|
33
|
+
BANNER
|
34
|
+
opts.separator ""
|
35
|
+
opts.on("-s", "--stdin",
|
36
|
+
"Read input from standard input instead of an input file") { |OPTIONS[:path]| }
|
37
|
+
opts.on("-h", "--help",
|
38
|
+
"Show this help message.") { puts opts; exit }
|
39
|
+
opts.parse!(ARGV)
|
40
|
+
|
41
|
+
if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
|
42
|
+
puts opts; exit
|
43
|
+
end
|
44
|
+
if ARGV.empty? && !OPTIONS[:stdin]
|
45
|
+
puts opts; exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
infile = $stdin
|
50
|
+
outfile = $stdout
|
51
|
+
|
52
|
+
stdin = OPTIONS[:stdin] ? $stdin : false
|
53
|
+
|
54
|
+
begin
|
55
|
+
infilepath = ARGV.shift unless(ARGV.empty? || stdin)
|
56
|
+
infile = File.open(infilepath,'r') if infilepath
|
57
|
+
outfilepath = ARGV.shift unless(ARGV.empty?)
|
58
|
+
outfile = File.open(outfilepath,'w') if outfilepath
|
59
|
+
rescue
|
60
|
+
$stderr.puts "Error opening input properties file '#{infilepath}' for reading." unless infile.is_a? File
|
61
|
+
$stderr.puts "Error opening output YAML file '#{outfilepath}' for writing." if infile.is_a? File
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
|
65
|
+
props = {}
|
66
|
+
JavaProperties::Parser.parse( infile.read ).each do |key,value|
|
67
|
+
# Convert all of the keys in the properties file to strings
|
68
|
+
# so that they don't output as symbols in the to_yaml results
|
69
|
+
props[key.to_s] = value
|
70
|
+
end
|
71
|
+
outfile.puts props.to_yaml
|
data/java_properties.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "java_properties"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
s.date = "2008-06-14"
|
5
5
|
s.summary = "Simple gem for reading/writing Java properties files from Ruby."
|
6
6
|
s.email = "flergl@flergl.net"
|
@@ -14,7 +14,7 @@ be provided as Strings or Symbols, but internally they are Symbols."
|
|
14
14
|
"lib/java_properties.rb","lib/java_properties/delimiters.rb",
|
15
15
|
"lib/java_properties/encoding.rb","lib/java_properties/parser.rb",
|
16
16
|
"lib/java_properties/properties-files.rb","lib/java_properties/specialchars.rb",
|
17
|
-
"lib/java_properties/utf8.rb","lib/java_properties/version.rb",
|
17
|
+
"lib/java_properties/utf8.rb","lib/java_properties/version.rb","bin/properties2yaml",
|
18
18
|
"test/test_data.rb","test/test_helper.rb","test/test_java_properties.rb"]
|
19
19
|
s.test_files = ["test/test_data.rb","test/test_helper.rb","test/test_java_properties.rb"]
|
20
20
|
s.rdoc_options = ["--main", "README.txt"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flergl-java_properties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dwayne Kristjanson
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/java_properties/specialchars.rb
|
38
38
|
- lib/java_properties/utf8.rb
|
39
39
|
- lib/java_properties/version.rb
|
40
|
+
- bin/properties2yaml
|
40
41
|
- test/test_data.rb
|
41
42
|
- test/test_helper.rb
|
42
43
|
- test/test_java_properties.rb
|