embulk 0.8.18-java → 0.8.19-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/build.gradle +10 -3
- data/embulk-cli/build.gradle +2 -0
- data/embulk-cli/src/main/bat/selfrun.bat +98 -0
- data/embulk-cli/src/main/java/org/embulk/cli/EmbulkExample.java +82 -0
- data/embulk-cli/src/main/java/org/embulk/cli/EmbulkMigrate.java +458 -0
- data/embulk-cli/src/main/java/org/embulk/cli/EmbulkNew.java +419 -0
- data/embulk-cli/src/main/java/org/embulk/cli/EmbulkSelfUpdate.java +248 -0
- data/embulk-cli/src/main/sh/selfrun.sh +0 -103
- data/embulk-cli/src/test/java/org/embulk/cli/SelfrunTest.java +158 -143
- data/embulk-core/build.gradle +2 -2
- data/embulk-core/src/main/java/org/embulk/EmbulkVersion.java +109 -0
- data/embulk-core/src/main/java/org/embulk/exec/GuessExecutor.java +11 -0
- data/embulk-core/src/main/java/org/embulk/exec/PreviewExecutor.java +29 -3
- data/embulk-core/src/main/java/org/embulk/exec/SamplingParserPlugin.java +47 -13
- data/embulk-core/src/main/java/org/embulk/spi/FileInputRunner.java +6 -3
- data/embulk-core/src/main/java/org/embulk/spi/PageBuilder.java +385 -64
- data/embulk-core/src/main/java/org/embulk/spi/TempFileSpace.java +2 -1
- data/embulk-core/src/test/java/org/embulk/spi/TestPageBuilderReader.java +62 -0
- data/embulk-docs/src/built-in.rst +59 -21
- data/embulk-docs/src/customization.rst +8 -8
- data/embulk-docs/src/developers/index.rst +45 -0
- data/embulk-docs/src/index.rst +11 -7
- data/embulk-docs/src/recipe.rst +1 -1
- data/embulk-docs/src/recipe/{scheduled-csv-load-to-elasticsearch-kibana4.rst → scheduled-csv-load-to-elasticsearch-kibana5.rst} +26 -24
- data/embulk-docs/src/release.rst +1 -0
- data/embulk-docs/src/release/release-0.4.0.rst +1 -1
- data/embulk-docs/src/release/release-0.5.0.rst +1 -1
- data/embulk-docs/src/release/release-0.6.0.rst +1 -1
- data/embulk-docs/src/release/release-0.6.20.rst +1 -1
- data/embulk-docs/src/release/release-0.8.19.rst +43 -0
- data/embulk-standards/src/main/java/org/embulk/standards/CsvParserPlugin.java +2 -2
- data/embulk-standards/src/main/java/org/embulk/standards/LocalFileInputPlugin.java +30 -1
- data/embulk-standards/src/test/java/org/embulk/standards/guess/TestCsvGuessPlugin.java +10 -0
- data/embulk-standards/src/test/java/org/embulk/standards/preview/TestFilePreview.java +73 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/guess/csv/test/test_skip_suggest_if_empty_sample_records.csv +5 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/guess/csv/test/test_skip_suggest_if_empty_sample_records_guessed.yml +2 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/guess/csv/test/test_skip_suggest_if_empty_sample_records_seed.yml +1 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/preview/file/test/test_sample_buffer_bytes.csv +5 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/preview/file/test/test_sample_buffer_bytes_exec.yml +1 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/preview/file/test/test_sample_buffer_bytes_load.yml +19 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/preview/file/test/test_sample_buffer_bytes_previewed.csv +1 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/preview/file/test/test_simple.csv +5 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/preview/file/test/test_simple_load.yml +19 -0
- data/embulk-standards/src/test/resources/org/embulk/standards/preview/file/test/test_simple_previewed.csv +4 -0
- data/embulk-test/src/main/java/org/embulk/test/PreviewResultInputPlugin.java +65 -0
- data/embulk-test/src/main/java/org/embulk/test/TestingBulkLoader.java +5 -0
- data/embulk-test/src/main/java/org/embulk/test/TestingEmbulk.java +59 -2
- data/embulk.gemspec +2 -1
- data/lib/embulk/command/embulk_run.rb +11 -49
- data/lib/embulk/data/new/README.md.vm +106 -0
- data/lib/embulk/data/new/{gitignore.erb → gitignore.vm} +3 -3
- data/lib/embulk/data/new/java/{build.gradle.erb → build.gradle.vm} +8 -8
- data/lib/embulk/data/new/java/{decoder.java.erb → decoder.java.vm} +6 -4
- data/lib/embulk/data/new/java/{encoder.java.erb → encoder.java.vm} +7 -5
- data/lib/embulk/data/new/java/{file_input.java.erb → file_input.java.vm} +9 -7
- data/lib/embulk/data/new/java/{file_output.java.erb → file_output.java.vm} +7 -5
- data/lib/embulk/data/new/java/{filter.java.erb → filter.java.vm} +4 -3
- data/lib/embulk/data/new/java/{formatter.java.erb → formatter.java.vm} +5 -4
- data/lib/embulk/data/new/java/{input.java.erb → input.java.vm} +6 -4
- data/lib/embulk/data/new/java/{output.java.erb → output.java.vm} +7 -5
- data/lib/embulk/data/new/java/{parser.java.erb → parser.java.vm} +5 -4
- data/lib/embulk/data/new/java/plugin_loader.rb.vm +3 -0
- data/lib/embulk/data/new/java/test.java.vm +5 -0
- data/lib/embulk/data/new/ruby/decoder_guess.rb.vm +25 -0
- data/lib/embulk/data/new/ruby/{filter.rb.erb → filter.rb.vm} +2 -2
- data/lib/embulk/data/new/ruby/{formatter.rb.erb → formatter.rb.vm} +2 -2
- data/lib/embulk/data/new/ruby/gemspec.vm +20 -0
- data/lib/embulk/data/new/ruby/{input.rb.erb → input.rb.vm} +10 -10
- data/lib/embulk/data/new/ruby/{output.rb.erb → output.rb.vm} +7 -7
- data/lib/embulk/data/new/ruby/{parser.rb.erb → parser.rb.vm} +2 -2
- data/lib/embulk/data/new/ruby/parser_guess.rb.vm +65 -0
- data/lib/embulk/guess/csv.rb +5 -0
- data/lib/embulk/version.rb +22 -1
- metadata +55 -35
- data/lib/embulk/command/embulk_example.rb +0 -33
- data/lib/embulk/command/embulk_generate_bin.rb +0 -62
- data/lib/embulk/command/embulk_migrate_plugin.rb +0 -244
- data/lib/embulk/command/embulk_new_plugin.rb +0 -126
- data/lib/embulk/command/embulk_selfupdate.rb +0 -121
- data/lib/embulk/data/new/README.md.erb +0 -111
- data/lib/embulk/data/new/java/plugin_loader.rb.erb +0 -3
- data/lib/embulk/data/new/java/test.java.erb +0 -5
- data/lib/embulk/data/new/ruby/decoder_guess.rb.erb +0 -25
- data/lib/embulk/data/new/ruby/gemspec.erb +0 -20
- data/lib/embulk/data/new/ruby/parser_guess.rb.erb +0 -65
@@ -1,33 +0,0 @@
|
|
1
|
-
module Embulk
|
2
|
-
def self.create_example(path)
|
3
|
-
require 'fileutils'
|
4
|
-
require 'zlib'
|
5
|
-
|
6
|
-
puts " Creating #{path}/"
|
7
|
-
FileUtils.mkdir_p File.join(path, 'csv')
|
8
|
-
puts " Creating #{path}/csv/"
|
9
|
-
|
10
|
-
puts " Creating #{path}/csv/sample_01.csv.gz"
|
11
|
-
Zlib::GzipWriter.open(File.join(path, 'csv', 'sample_01.csv.gz')) do |f|
|
12
|
-
f.write <<EOF
|
13
|
-
id,account,time,purchase,comment
|
14
|
-
1,32864,2015-01-27 19:23:49,20150127,embulk
|
15
|
-
2,14824,2015-01-27 19:01:23,20150127,embulk jruby
|
16
|
-
3,27559,2015-01-28 02:20:02,20150128,"Embulk ""csv"" parser plugin"
|
17
|
-
4,11270,2015-01-29 11:54:36,20150129,NULL
|
18
|
-
|
19
|
-
EOF
|
20
|
-
end
|
21
|
-
|
22
|
-
puts " Creating #{path}/seed.yml"
|
23
|
-
File.open(File.join(path, 'seed.yml'), 'w') do |f|
|
24
|
-
f.write <<EOF
|
25
|
-
in:
|
26
|
-
type: file
|
27
|
-
path_prefix: "#{File.expand_path File.join(path, 'csv', 'sample_')}"
|
28
|
-
out:
|
29
|
-
type: stdout
|
30
|
-
EOF
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Embulk
|
2
|
-
def self.generate_bin(options={})
|
3
|
-
jruby_jar_path = org.jruby.Main.java_class.protection_domain.code_source.location.to_s
|
4
|
-
if __FILE__ =~ /^(?:classpath|uri:classloader):/ || __FILE__.include?('!/')
|
5
|
-
resource_class = org.embulk.command.Runner.java_class
|
6
|
-
ruby_script_path = resource_class.resource("/embulk/command/embulk.rb").to_s
|
7
|
-
else
|
8
|
-
ruby_script_path = File.join(File.dirname(__FILE__), 'embulk.rb')
|
9
|
-
end
|
10
|
-
java_home = java.lang.System.properties['java.home']
|
11
|
-
|
12
|
-
generate_bin_data(jruby_jar_path, ruby_script_path, options.merge(java_home: java_home))
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.generate_bin_data(jruby_jar_path, ruby_script_path, options={})
|
16
|
-
if java_home = options[:java_home]
|
17
|
-
java_home_script = %{export JAVA_HOME='#{java_home}'}
|
18
|
-
java_path = %{"$JAVA_HOME"/bin/java}
|
19
|
-
else
|
20
|
-
java_home_script = %{}
|
21
|
-
java_path = %{java}
|
22
|
-
end
|
23
|
-
|
24
|
-
# TODO parse -D options to set them to java
|
25
|
-
shell_script = <<EOF
|
26
|
-
#!/bin/sh
|
27
|
-
=begin 2>/dev/null
|
28
|
-
#{java_home_script}
|
29
|
-
exec #{java_path} -classpath "$0" org.jruby.Main "$0" "$@"
|
30
|
-
exit 127
|
31
|
-
=end
|
32
|
-
EOF
|
33
|
-
|
34
|
-
if options[:bundle_path] == :here
|
35
|
-
bundle_path_script = %{ENV['EMBULK_BUNDLE_PATH'] = File.expand_path('..', File.dirname(__FILE__))}
|
36
|
-
elsif path = options[:bundle_path]
|
37
|
-
bundle_path_script = %{ENV['EMBULK_BUNDLE_PATH'] = '#{path}'}
|
38
|
-
else
|
39
|
-
bundle_path_script = b ''
|
40
|
-
end
|
41
|
-
|
42
|
-
ruby_init_script = b <<EOF
|
43
|
-
#{bundle_path_script}
|
44
|
-
ENV.delete 'GEM_HOME'
|
45
|
-
ENV.delete 'GEM_PATH'
|
46
|
-
EOF
|
47
|
-
|
48
|
-
ruby_script = b(File.read(ruby_script_path))
|
49
|
-
if i = ruby_script.index(b("\n__END__\n"))
|
50
|
-
# delete contents after __END__
|
51
|
-
ruby_script = ruby_script[0, i]
|
52
|
-
end
|
53
|
-
|
54
|
-
jruby_jar = b(File.read(jruby_jar_path))
|
55
|
-
|
56
|
-
data = shell_script << ruby_init_script + ruby_script << b("\n__END__\n") << jruby_jar
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.b(s)
|
60
|
-
s.force_encoding('ASCII-8BIT')
|
61
|
-
end
|
62
|
-
end
|
@@ -1,244 +0,0 @@
|
|
1
|
-
module Embulk
|
2
|
-
def self.migrate_plugin(path)
|
3
|
-
migrator = Migrator.new(path)
|
4
|
-
|
5
|
-
if ms = migrator.match("**/build.gradle", /org\.embulk:embulk-core:([\d\.\+]+)?/)
|
6
|
-
lang = :java
|
7
|
-
from_ver = version(ms[0][1].gsub(/\++/, '0')) # replaces "0.8.+" to "0.8.0"
|
8
|
-
puts "Detected Java plugin for Embulk #{from_ver}..."
|
9
|
-
|
10
|
-
elsif ms = migrator.match("**/*.gemspec", /add_(?:development_)?dependency\s+\W+embulk\W+\s+([\d\.]+)\W+/)
|
11
|
-
lang = :ruby
|
12
|
-
from_ver = version(ms[0][1])
|
13
|
-
puts "Detected Ruby plugin for Embulk #{from_ver}..."
|
14
|
-
|
15
|
-
elsif ms = migrator.match("**/*.gemspec", /embulk-/)
|
16
|
-
lang = :ruby
|
17
|
-
from_ver = version("0.1.0")
|
18
|
-
puts "Detected Ruby plugin for unknown Embulk version..."
|
19
|
-
|
20
|
-
else
|
21
|
-
raise "Failed to detect plugin language and dependency version"
|
22
|
-
end
|
23
|
-
|
24
|
-
case lang
|
25
|
-
when :java
|
26
|
-
migrate_java_plugin(migrator, from_ver)
|
27
|
-
when :ruby
|
28
|
-
migrate_ruby_plugin(migrator, from_ver)
|
29
|
-
end
|
30
|
-
|
31
|
-
if migrator.modified_files.empty?
|
32
|
-
puts "Done. No files are modified."
|
33
|
-
else
|
34
|
-
puts "Done. Please check modifieid files."
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.migrate_java_plugin(migrator, from_ver)
|
39
|
-
if from_ver < version("0.7.0")
|
40
|
-
# rename CommitReport to TaskReport
|
41
|
-
migrator.replace("**/*.java", /(CommitReport)/, "TaskReport")
|
42
|
-
migrator.replace("**/*.java", /(commitReport)/, "taskReport")
|
43
|
-
end
|
44
|
-
|
45
|
-
# upgrade gradle version
|
46
|
-
if migrator.match("gradle/wrapper/gradle-wrapper.properties", /gradle-[23]\.\d+(\.\d+)?-/)
|
47
|
-
# gradle < 3.2.1
|
48
|
-
require 'embulk/data/package_data'
|
49
|
-
data = PackageData.new("new", migrator.path)
|
50
|
-
migrator.write "gradle/wrapper/gradle-wrapper.properties", data.content("java/gradle/wrapper/gradle-wrapper.properties")
|
51
|
-
migrator.write "gradle/wrapper/gradle-wrapper.jar", data.bincontent("java/gradle/wrapper/gradle-wrapper.jar")
|
52
|
-
end
|
53
|
-
|
54
|
-
# add jsonColumn method
|
55
|
-
if !migrator.match("**/*.java", /void\s+jsonColumn/) && ms = migrator.match("**/*.java", /^(\W+).*?void\s+timestampColumn/)
|
56
|
-
indent = ms.first[1]
|
57
|
-
replace = <<EOF
|
58
|
-
|
59
|
-
#{indent}public void jsonColumn(Column column) {
|
60
|
-
#{indent} throw new UnsupportedOperationException("This plugin doesn't support json type. Please try to upgrade version of the plugin using 'embulk gem update' command. If the latest version still doesn't support json type, please contact plugin developers, or change configuration of input plugin not to use json type.");
|
61
|
-
#{indent}}
|
62
|
-
|
63
|
-
#{indent}@Override
|
64
|
-
EOF
|
65
|
-
migrator.replace("**/*.java", /(\r?\n)(\W+).*?void\s+timestampColumn/, replace)
|
66
|
-
end
|
67
|
-
|
68
|
-
# add sourceCompatibility and targetCompatibility
|
69
|
-
unless migrator.match("build.gradle", /targetCompatibility/)
|
70
|
-
migrator.insert_line("build.gradle", /^([ \t]*)dependencies\s*{/) {|m|
|
71
|
-
"#{m[1]}targetCompatibility = 1.7\n"
|
72
|
-
}
|
73
|
-
end
|
74
|
-
unless migrator.match("build.gradle", /sourceCompatibility/)
|
75
|
-
migrator.insert_line("build.gradle", /^([ \t]*)targetCompatibility/) {|m|
|
76
|
-
"#{m[1]}sourceCompatibility = 1.7"
|
77
|
-
}
|
78
|
-
end
|
79
|
-
|
80
|
-
# add checkstyle
|
81
|
-
unless migrator.match("build.gradle", /id\s+(?<quote>["'])checkstyle\k<quote>/)
|
82
|
-
migrator.insert_line("build.gradle", /^([ \t]*)id( +)(["'])java["']/) {|m|
|
83
|
-
"#{m[1]}id#{m[2]}#{m[3]}checkstyle#{m[3]}"
|
84
|
-
}
|
85
|
-
migrator.write "config/checkstyle/checkstyle.xml", migrator.new_data.content("java/config/checkstyle/checkstyle.xml")
|
86
|
-
end
|
87
|
-
|
88
|
-
unless migrator.match("build.gradle", /checkstyle\s+{/)
|
89
|
-
migrator.write "config/checkstyle/default.xml", migrator.new_data.content("java/config/checkstyle/default.xml")
|
90
|
-
migrator.insert_line("build.gradle", /^([ \t]*)task\s+gem\W.*{/) {|m|
|
91
|
-
<<-EOF
|
92
|
-
#{m[1]}checkstyle {
|
93
|
-
#{m[1]} configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml")
|
94
|
-
#{m[1]} toolVersion = '6.14.1'
|
95
|
-
#{m[1]}}
|
96
|
-
#{m[1]}checkstyleMain {
|
97
|
-
#{m[1]} configFile = file("${project.rootDir}/config/checkstyle/default.xml")
|
98
|
-
#{m[1]} ignoreFailures = true
|
99
|
-
#{m[1]}}
|
100
|
-
#{m[1]}checkstyleTest {
|
101
|
-
#{m[1]} configFile = file("${project.rootDir}/config/checkstyle/default.xml")
|
102
|
-
#{m[1]} ignoreFailures = true
|
103
|
-
#{m[1]}}
|
104
|
-
#{m[1]}task checkstyle(type: Checkstyle) {
|
105
|
-
#{m[1]} classpath = sourceSets.main.output + sourceSets.test.output
|
106
|
-
#{m[1]} source = sourceSets.main.allJava + sourceSets.test.allJava
|
107
|
-
#{m[1]}}
|
108
|
-
EOF
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
#
|
113
|
-
# add rules...
|
114
|
-
##
|
115
|
-
|
116
|
-
# update version at the end
|
117
|
-
migrator.replace("**/build.gradle", /org\.embulk:embulk-(?:core|standards):([\d\.\+]+)?/, Embulk::VERSION)
|
118
|
-
end
|
119
|
-
|
120
|
-
def self.migrate_ruby_plugin(migrator, from_ver)
|
121
|
-
#
|
122
|
-
# add rules...
|
123
|
-
##
|
124
|
-
|
125
|
-
migrator.write(".ruby-version", "jruby-9.1.5.0")
|
126
|
-
|
127
|
-
# update version at the end
|
128
|
-
if from_ver <= version("0.1.0")
|
129
|
-
# add add_development_dependency
|
130
|
-
migrator.insert_line("**/*.gemspec", /([ \t]*\w+)\.add_development_dependency/) {|m|
|
131
|
-
"#{m[1]}.add_development_dependency 'embulk', ['>= #{Embulk::VERSION}']"
|
132
|
-
}
|
133
|
-
else
|
134
|
-
unless migrator.replace("**/*.gemspec", /add_(?:development_)?dependency\s+\W+embulk\W+\s*(\~\>\s*[\d\.]+)\W+/, ">= #{Embulk::VERSION}")
|
135
|
-
migrator.replace("**/*.gemspec", /add_(?:development_)?dependency\s+\W+embulk\W+\s*([\d\.]+)\W+/, Embulk::VERSION)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
private
|
141
|
-
|
142
|
-
def self.version(str)
|
143
|
-
Gem::Version.new(str)
|
144
|
-
end
|
145
|
-
|
146
|
-
class Migrator
|
147
|
-
def initialize(path)
|
148
|
-
@path = path
|
149
|
-
@modified_files = {}
|
150
|
-
|
151
|
-
require 'fileutils'
|
152
|
-
require 'embulk/data/package_data'
|
153
|
-
@new_data = PackageData.new("new", path)
|
154
|
-
end
|
155
|
-
|
156
|
-
attr_reader :path
|
157
|
-
attr_reader :new_data
|
158
|
-
|
159
|
-
def modified_files
|
160
|
-
@modified_files.keys
|
161
|
-
end
|
162
|
-
|
163
|
-
def match(glob, pattern)
|
164
|
-
ms = Dir[File.join(@path, glob)].map do |file|
|
165
|
-
read(file).match(pattern)
|
166
|
-
end.compact
|
167
|
-
return nil if ms.empty?
|
168
|
-
ms
|
169
|
-
end
|
170
|
-
|
171
|
-
def replace(glob, pattern, text=nil)
|
172
|
-
ms = Dir[File.join(@path, glob)].map do |file|
|
173
|
-
data = read(file)
|
174
|
-
first = nil
|
175
|
-
pos = 0
|
176
|
-
while pos < data.length
|
177
|
-
m = data.match(pattern, pos)
|
178
|
-
break unless m
|
179
|
-
first ||= m
|
180
|
-
replace = text || yield(m)
|
181
|
-
data = m.pre_match + data[m.begin(0)..(m.begin(1)-1)] + replace + data[m.end(1)..(m.end(0)-1)] + m.post_match
|
182
|
-
pos = m.begin(1) + replace.length + (m.end(0) - m.end(1))
|
183
|
-
end
|
184
|
-
if first
|
185
|
-
modify(file, data)
|
186
|
-
end
|
187
|
-
first
|
188
|
-
end.compact
|
189
|
-
return nil if ms.empty?
|
190
|
-
ms
|
191
|
-
end
|
192
|
-
|
193
|
-
def insert_line(glob, pattern, text: nil)
|
194
|
-
ms = Dir[File.join(@path, glob)].map do |file|
|
195
|
-
data = read(file)
|
196
|
-
if m = data.match(pattern)
|
197
|
-
ln = m.pre_match.split("\n").count
|
198
|
-
replace = text || yield(m)
|
199
|
-
lines = data.split("\n", -1) # preserve the last empty line
|
200
|
-
lines.insert(ln + 1, replace)
|
201
|
-
data = lines.join("\n")
|
202
|
-
modify(file, data)
|
203
|
-
m
|
204
|
-
end
|
205
|
-
end.compact
|
206
|
-
return nil if ms.empty?
|
207
|
-
ms
|
208
|
-
end
|
209
|
-
|
210
|
-
def data(file)
|
211
|
-
read(File.join(@path, file))
|
212
|
-
end
|
213
|
-
|
214
|
-
def write(file, data)
|
215
|
-
dst = File.join(@path, file)
|
216
|
-
FileUtils.mkdir_p File.dirname(dst)
|
217
|
-
modify(dst, data)
|
218
|
-
end
|
219
|
-
|
220
|
-
private
|
221
|
-
|
222
|
-
def modify(path, data)
|
223
|
-
orig = read(path) rescue nil
|
224
|
-
if orig != data
|
225
|
-
File.write(path, data)
|
226
|
-
unless @modified_files.has_key?(path)
|
227
|
-
if orig
|
228
|
-
puts " Modified #{path.sub(/^#{Regexp.escape(@path)}/, '')}"
|
229
|
-
else
|
230
|
-
puts " Created #{path.sub(/^#{Regexp.escape(@path)}/, '')}"
|
231
|
-
end
|
232
|
-
@modified_files[path] = true
|
233
|
-
end
|
234
|
-
end
|
235
|
-
nil
|
236
|
-
end
|
237
|
-
|
238
|
-
def read(path)
|
239
|
-
# external_encoding: assumes source code is written in UTF-8.
|
240
|
-
# internal_encoding: process files using UTF-8 so that modified data (data written to the file) becomes UTF-8.
|
241
|
-
File.read(path, external_encoding: 'UTF-8', internal_encoding: 'UTF-8')
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
module Embulk
|
2
|
-
def self.new_plugin(name, language, category)
|
3
|
-
require 'embulk/data/package_data'
|
4
|
-
require 'embulk/version'
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
embulk_category = category
|
8
|
-
embulk_category = :input if category == :file_input
|
9
|
-
embulk_category = :output if category == :file_output
|
10
|
-
|
11
|
-
name = name.gsub(/[^a-zA-Z0-9_]+/, '_') # replace '-' to '_'
|
12
|
-
|
13
|
-
full_project_name = "embulk-#{embulk_category}-#{name}"
|
14
|
-
plugin_dir = "lib/embulk"
|
15
|
-
plugin_path = "#{plugin_dir}/#{embulk_category}/#{name}.rb"
|
16
|
-
|
17
|
-
if File.exist?(full_project_name)
|
18
|
-
raise "./#{full_project_name} already exists. Please delete it first."
|
19
|
-
end
|
20
|
-
FileUtils.mkdir_p(full_project_name)
|
21
|
-
|
22
|
-
puts "Creating #{full_project_name}/"
|
23
|
-
|
24
|
-
success = false
|
25
|
-
begin
|
26
|
-
#
|
27
|
-
# Generate gemspec
|
28
|
-
#
|
29
|
-
author = `git config user.name`.strip rescue ""
|
30
|
-
author = "YOUR_NAME" if author.empty?
|
31
|
-
email = `git config user.email`.strip rescue ""
|
32
|
-
email = "YOUR_NAME" if email.empty?
|
33
|
-
|
34
|
-
# variables used in erb templates
|
35
|
-
ruby_class_name = name.split('_').map {|a| a.capitalize }.join
|
36
|
-
java_iface_name = category.to_s.split('_').map {|a| a.capitalize }.join
|
37
|
-
java_class_name = name.split('_').map {|a| a.capitalize }.join + java_iface_name + "Plugin"
|
38
|
-
java_package_name = "org.embulk.#{embulk_category}.#{name}"
|
39
|
-
display_name = name.split('_').map {|a| a.capitalize }.join(' ')
|
40
|
-
display_category = category.to_s.gsub('_', ' ')
|
41
|
-
|
42
|
-
extra_guess_erb = {}
|
43
|
-
|
44
|
-
case category
|
45
|
-
when :input
|
46
|
-
description = %[Loads records from #{display_name}.]
|
47
|
-
when :file_input
|
48
|
-
description = %[Reads files stored on #{display_name}.]
|
49
|
-
when :parser
|
50
|
-
description = %[Parses #{display_name} files read by other file input plugins.]
|
51
|
-
extra_guess_erb["ruby/parser_guess.rb.erb"] = "#{plugin_dir}/guess/#{name}.rb"
|
52
|
-
when :decoder
|
53
|
-
description = %[Decodes #{display_name}-encoded files read by other file input plugins.]
|
54
|
-
extra_guess_erb["ruby/decoder_guess.rb.erb"] = "#{plugin_dir}/guess/#{name}.rb"
|
55
|
-
when :output
|
56
|
-
description = %[Dumps records to #{display_name}.]
|
57
|
-
when :file_output
|
58
|
-
description = %[Stores files on #{display_name}.]
|
59
|
-
when :formatter
|
60
|
-
description = %[Formats #{display_name} files for other file output plugins.]
|
61
|
-
when :encoder
|
62
|
-
description = %[Encodes files using #{display_name} for other file output plugins.]
|
63
|
-
when :filter
|
64
|
-
description = %[#{display_name}]
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
# Generate project repository
|
69
|
-
#
|
70
|
-
pkg = Embulk::PackageData.new("new", full_project_name, binding())
|
71
|
-
|
72
|
-
pkg.cp_erb("README.md.erb", "README.md")
|
73
|
-
pkg.cp("LICENSE.txt", "LICENSE.txt")
|
74
|
-
pkg.cp_erb("gitignore.erb", ".gitignore")
|
75
|
-
|
76
|
-
case language
|
77
|
-
when :ruby
|
78
|
-
pkg.cp("ruby/Rakefile", "Rakefile")
|
79
|
-
pkg.cp("ruby/Gemfile", "Gemfile")
|
80
|
-
pkg.cp("ruby/.ruby-version", ".ruby-version")
|
81
|
-
pkg.cp_erb("ruby/gemspec.erb", "#{full_project_name}.gemspec")
|
82
|
-
pkg.cp_erb("ruby/#{category}.rb.erb", plugin_path)
|
83
|
-
|
84
|
-
when :java
|
85
|
-
pkg.cp("java/gradle/wrapper/gradle-wrapper.jar", "gradle/wrapper/gradle-wrapper.jar")
|
86
|
-
pkg.cp("java/gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.properties")
|
87
|
-
pkg.cp("java/gradlew.bat", "gradlew.bat")
|
88
|
-
pkg.cp("java/gradlew", "gradlew")
|
89
|
-
pkg.set_executable("gradlew")
|
90
|
-
pkg.cp("java/config/checkstyle/checkstyle.xml","config/checkstyle/checkstyle.xml")
|
91
|
-
pkg.cp("java/config/checkstyle/default.xml","config/checkstyle/default.xml")
|
92
|
-
pkg.cp_erb("java/build.gradle.erb", "build.gradle")
|
93
|
-
pkg.cp_erb("java/plugin_loader.rb.erb", plugin_path)
|
94
|
-
pkg.cp_erb("java/#{category}.java.erb", "src/main/java/#{java_package_name.gsub(/\./, '/')}/#{java_class_name}.java")
|
95
|
-
pkg.cp_erb("java/test.java.erb", "src/test/java/#{java_package_name.gsub(/\./, '/')}/Test#{java_class_name}.java")
|
96
|
-
end
|
97
|
-
|
98
|
-
extra_guess_erb.each_pair do |erb,dest|
|
99
|
-
pkg.cp_erb(erb, dest)
|
100
|
-
end
|
101
|
-
|
102
|
-
puts ""
|
103
|
-
puts "Plugin template is successfully generated."
|
104
|
-
|
105
|
-
case language
|
106
|
-
when :ruby
|
107
|
-
puts "Next steps:"
|
108
|
-
puts ""
|
109
|
-
puts " $ cd #{full_project_name}"
|
110
|
-
puts " $ bundle install # install one using rbenv & rbenv-build"
|
111
|
-
puts " $ bundle exec rake # build gem to be released"
|
112
|
-
puts " $ bundle exec embulk run config.yml # you can run plugin using this command"
|
113
|
-
when :java
|
114
|
-
puts "Next steps:"
|
115
|
-
puts ""
|
116
|
-
puts " $ cd #{full_project_name}"
|
117
|
-
puts " $ ./gradlew package"
|
118
|
-
end
|
119
|
-
|
120
|
-
success = true
|
121
|
-
puts ""
|
122
|
-
ensure
|
123
|
-
FileUtils.rm_rf full_project_name unless success
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|