embulk 0.8.25-java → 0.8.26-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/build.gradle +16 -1
  3. data/embulk-cli/src/main/java/org/embulk/cli/EmbulkMigrate.java +6 -3
  4. data/embulk-core/build.gradle +7 -0
  5. data/embulk-core/src/main/java/org/embulk/EmbulkService.java +2 -0
  6. data/embulk-core/src/main/java/org/embulk/plugin/InjectedPluginSource.java +1 -1
  7. data/embulk-core/src/main/java/org/embulk/plugin/MavenPluginType.java +21 -6
  8. data/embulk-core/src/main/java/org/embulk/plugin/PluginClassLoader.java +42 -2
  9. data/embulk-core/src/main/java/org/embulk/plugin/PluginSourceNotMatchException.java +6 -0
  10. data/embulk-core/src/main/java/org/embulk/plugin/PluginType.java +2 -1
  11. data/embulk-core/src/main/java/org/embulk/plugin/jar/InvalidJarPluginException.java +14 -0
  12. data/embulk-core/src/main/java/org/embulk/plugin/jar/JarPluginLoader.java +205 -0
  13. data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenArtifactFinder.java +134 -0
  14. data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenArtifactNotFoundException.java +20 -0
  15. data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenPluginSource.java +187 -0
  16. data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenPluginSourceModule.java +22 -0
  17. data/embulk-core/src/main/java/org/embulk/plugin/maven/MavenRepositoryNotFoundException.java +31 -0
  18. data/embulk-core/src/main/resources/embulk/parent_first_packages.properties +3 -1
  19. data/embulk-core/src/main/resources/embulk/parent_first_resources.properties +2 -1
  20. data/embulk-core/src/test/java/org/embulk/EmbulkTestRuntime.java +8 -0
  21. data/embulk-core/src/test/java/org/embulk/plugin/TestPluginType.java +24 -0
  22. data/embulk-core/src/test/java/org/embulk/plugin/TestPluginTypeSerDe.java +17 -0
  23. data/embulk-core/src/test/java/org/embulk/plugin/jar/ExampleJarSpiV0.java +9 -0
  24. data/embulk-core/src/test/java/org/embulk/plugin/jar/JarBuilder.java +101 -0
  25. data/embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java +60 -0
  26. data/embulk-core/src/test/java/org/embulk/plugin/maven/TestMavenArtifactFinder.java +41 -0
  27. data/embulk-core/src/test/resources/m2.test/.gitignore +1 -0
  28. data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.jar +0 -0
  29. data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.jar.sha1 +1 -0
  30. data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.pom +9 -0
  31. data/embulk-core/src/test/resources/m2.test/org/embulk/example/embulk-example-maven-artifact/0.1.2/embulk-example-maven-artifact-0.1.2.pom.sha1 +1 -0
  32. data/embulk-docs/src/built-in.rst +26 -9
  33. data/embulk-docs/src/release.rst +1 -0
  34. data/embulk-docs/src/release/release-0.8.26.rst +16 -0
  35. data/embulk-standards/src/main/java/org/embulk/standards/ConfigInputPlugin.java +170 -0
  36. data/embulk-standards/src/main/java/org/embulk/standards/StandardPluginModule.java +1 -0
  37. data/lib/embulk/version.rb +1 -1
  38. metadata +58 -29
@@ -0,0 +1,134 @@
1
+ package org.embulk.plugin.maven;
2
+
3
+ import java.io.IOError;
4
+ import java.nio.file.Files;
5
+ import java.nio.file.NoSuchFileException;
6
+ import java.nio.file.NotDirectoryException;
7
+ import java.nio.file.Path;
8
+ import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
9
+ import org.eclipse.aether.DefaultRepositorySystemSession;
10
+ import org.eclipse.aether.RepositorySystem;
11
+ import org.eclipse.aether.RepositorySystemSession;
12
+ import org.eclipse.aether.artifact.Artifact;
13
+ import org.eclipse.aether.artifact.DefaultArtifact;
14
+ import org.eclipse.aether.impl.DefaultServiceLocator;
15
+ import org.eclipse.aether.repository.LocalRepository;
16
+ import org.eclipse.aether.resolution.ArtifactRequest;
17
+ import org.eclipse.aether.resolution.ArtifactResolutionException;
18
+ import org.eclipse.aether.resolution.ArtifactResult;
19
+
20
+ public class MavenArtifactFinder
21
+ {
22
+ private MavenArtifactFinder(final Path givenLocalMavenRepositoryPath,
23
+ final Path absoluteLocalMavenRepositoryPath,
24
+ final RepositorySystem repositorySystem,
25
+ final RepositorySystemSession repositorySystemSession)
26
+ {
27
+ this.givenLocalMavenRepositoryPath = givenLocalMavenRepositoryPath;
28
+ this.absoluteLocalMavenRepositoryPath = absoluteLocalMavenRepositoryPath;
29
+ this.repositorySystem = repositorySystem;
30
+ this.repositorySystemSession = repositorySystemSession;
31
+ }
32
+
33
+ public static MavenArtifactFinder create(final Path localMavenRepositoryPath)
34
+ throws MavenRepositoryNotFoundException
35
+ {
36
+ final Path absolutePath;
37
+ try {
38
+ absolutePath = localMavenRepositoryPath.normalize().toAbsolutePath();
39
+ }
40
+ catch (IOError ex) {
41
+ throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex);
42
+ }
43
+ catch (SecurityException ex) {
44
+ throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex);
45
+ }
46
+
47
+ if (!Files.exists(absolutePath)) {
48
+ throw new MavenRepositoryNotFoundException(localMavenRepositoryPath,
49
+ absolutePath,
50
+ new NoSuchFileException(absolutePath.toString()));
51
+ }
52
+ if (!Files.isDirectory(absolutePath)) {
53
+ throw new MavenRepositoryNotFoundException(localMavenRepositoryPath,
54
+ absolutePath,
55
+ new NotDirectoryException(absolutePath.toString()));
56
+ }
57
+
58
+ final RepositorySystem repositorySystem = createRepositorySystem();
59
+
60
+ return new MavenArtifactFinder(localMavenRepositoryPath,
61
+ absolutePath,
62
+ repositorySystem,
63
+ createRepositorySystemSession(repositorySystem, absolutePath));
64
+ }
65
+
66
+ public final Path findMavenArtifactJar(
67
+ final String groupId,
68
+ final String artifactId,
69
+ final String classifier,
70
+ final String version)
71
+ throws MavenArtifactNotFoundException
72
+ {
73
+ return findMavenArtifact(groupId, artifactId, classifier, "jar", version);
74
+ }
75
+
76
+ public Path findMavenArtifact(
77
+ final String groupId,
78
+ final String artifactId,
79
+ final String classifier,
80
+ final String extension,
81
+ final String version)
82
+ throws MavenArtifactNotFoundException
83
+ {
84
+ final ArtifactResult result;
85
+ try {
86
+ result = resolveMavenArtifact(groupId, artifactId, classifier, extension, version);
87
+ }
88
+ catch (ArtifactResolutionException ex) {
89
+ throw new MavenArtifactNotFoundException(groupId, artifactId, classifier, version,
90
+ this.givenLocalMavenRepositoryPath,
91
+ this.absoluteLocalMavenRepositoryPath,
92
+ ex);
93
+ }
94
+ return result.getArtifact().getFile().toPath();
95
+ }
96
+
97
+ private ArtifactResult resolveMavenArtifact(
98
+ final String groupId,
99
+ final String artifactId,
100
+ final String classifier,
101
+ final String extension,
102
+ final String version)
103
+ throws ArtifactResolutionException
104
+ {
105
+ // |classifier| can be null for |org.eclipse.aether.artifact.DefaultArtifact|.
106
+ final ArtifactRequest artifactRequest = new ArtifactRequest().setArtifact(
107
+ new DefaultArtifact(groupId, artifactId, classifier, extension, version));
108
+
109
+ return this.repositorySystem.resolveArtifact(this.repositorySystemSession, artifactRequest);
110
+ }
111
+
112
+ private static RepositorySystem createRepositorySystem()
113
+ {
114
+ final DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
115
+ return locator.getService(RepositorySystem.class);
116
+ }
117
+
118
+ private static RepositorySystemSession createRepositorySystemSession(
119
+ final RepositorySystem repositorySystem, final Path localRepositoryPath)
120
+ {
121
+ final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
122
+
123
+ final LocalRepository repository = new LocalRepository(localRepositoryPath.toString());
124
+ session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, repository));
125
+ return session;
126
+ }
127
+
128
+ // Paths are kept just for hinting in Exceptions.
129
+ private final Path givenLocalMavenRepositoryPath;
130
+ private final Path absoluteLocalMavenRepositoryPath;
131
+
132
+ private final RepositorySystem repositorySystem;
133
+ private final RepositorySystemSession repositorySystemSession;
134
+ }
@@ -0,0 +1,20 @@
1
+ package org.embulk.plugin.maven;
2
+
3
+ import java.nio.file.Path;
4
+
5
+ public class MavenArtifactNotFoundException
6
+ extends Exception {
7
+ public MavenArtifactNotFoundException(final String groupId,
8
+ final String artifactId,
9
+ final String classifier,
10
+ final String version,
11
+ final Path givenRepositoryPath,
12
+ final Path absoluteRepositoryPath,
13
+ final Throwable cause)
14
+ {
15
+ super("Maven artifact \"" + groupId + ":" + artifactId + ":" + version +
16
+ (classifier != null ? (":" + classifier) : "") + "\" is not found: at \"" +
17
+ givenRepositoryPath.toString() + "\" (\"" + absoluteRepositoryPath.toString() + "\").",
18
+ cause);
19
+ }
20
+ }
@@ -0,0 +1,187 @@
1
+ package org.embulk.plugin.maven;
2
+
3
+ import com.google.inject.Inject;
4
+ import com.google.inject.Injector;
5
+ import java.nio.file.Path;
6
+ import java.nio.file.Paths;
7
+ import org.embulk.plugin.MavenPluginType;
8
+ import org.embulk.plugin.PluginClassLoaderFactory;
9
+ import org.embulk.plugin.PluginSource;
10
+ import org.embulk.plugin.PluginSourceNotMatchException;
11
+ import org.embulk.plugin.PluginType;
12
+ import org.embulk.plugin.jar.JarPluginLoader;
13
+ import org.embulk.plugin.jar.InvalidJarPluginException;
14
+ import org.embulk.spi.DecoderPlugin;
15
+ import org.embulk.spi.EncoderPlugin;
16
+ import org.embulk.spi.ExecutorPlugin;
17
+ import org.embulk.spi.FileInputPlugin;
18
+ import org.embulk.spi.FileInputRunner;
19
+ import org.embulk.spi.FileOutputPlugin;
20
+ import org.embulk.spi.FileOutputRunner;
21
+ import org.embulk.spi.FilterPlugin;
22
+ import org.embulk.spi.FormatterPlugin;
23
+ import org.embulk.spi.GuessPlugin;
24
+ import org.embulk.spi.InputPlugin;
25
+ import org.embulk.spi.OutputPlugin;
26
+ import org.embulk.spi.ParserPlugin;
27
+
28
+ public class MavenPluginSource
29
+ implements PluginSource
30
+ {
31
+ @Inject
32
+ public MavenPluginSource(Injector injector)
33
+ {
34
+ this.injector = injector;
35
+ }
36
+
37
+ @Override
38
+ public <T> T newPlugin(Class<T> pluginInterface, PluginType pluginType)
39
+ throws PluginSourceNotMatchException
40
+ {
41
+ final String category;
42
+ if (InputPlugin.class.isAssignableFrom(pluginInterface)) {
43
+ category = "input";
44
+ } else if (OutputPlugin.class.isAssignableFrom(pluginInterface)) {
45
+ category = "output";
46
+ } else if (ParserPlugin.class.isAssignableFrom(pluginInterface)) {
47
+ category = "parser";
48
+ } else if (FormatterPlugin.class.isAssignableFrom(pluginInterface)) {
49
+ category = "formatter";
50
+ } else if (DecoderPlugin.class.isAssignableFrom(pluginInterface)) {
51
+ category = "decoder";
52
+ } else if (EncoderPlugin.class.isAssignableFrom(pluginInterface)) {
53
+ category = "encoder";
54
+ } else if (FilterPlugin.class.isAssignableFrom(pluginInterface)) {
55
+ category = "filter";
56
+ } else if (GuessPlugin.class.isAssignableFrom(pluginInterface)) {
57
+ category = "guess";
58
+ } else if (ExecutorPlugin.class.isAssignableFrom(pluginInterface)) {
59
+ category = "executor";
60
+ } else {
61
+ // unsupported plugin category
62
+ throw new PluginSourceNotMatchException("Plugin interface " + pluginInterface + " is not supported.");
63
+ }
64
+
65
+ if (pluginType.getSourceType() != PluginSource.Type.MAVEN) {
66
+ throw new PluginSourceNotMatchException();
67
+ }
68
+ final MavenPluginType mavenPluginType = (MavenPluginType) pluginType;
69
+
70
+ final PluginClassLoaderFactory pluginClassLoaderFactory =
71
+ this.injector.getInstance(PluginClassLoaderFactory.class);
72
+
73
+ final MavenArtifactFinder mavenArtifactFinder;
74
+ try {
75
+ mavenArtifactFinder = MavenArtifactFinder.create(getLocalMavenRepository());
76
+ }
77
+ catch (MavenRepositoryNotFoundException ex) {
78
+ throw new PluginSourceNotMatchException(ex);
79
+ }
80
+
81
+ final Path jarPath;
82
+ try {
83
+ jarPath = mavenArtifactFinder.findMavenArtifactJar(
84
+ mavenPluginType.getGroup(),
85
+ "embulk-" + category + "-" + mavenPluginType.getName(),
86
+ mavenPluginType.getClassifier(),
87
+ mavenPluginType.getVersion());
88
+ }
89
+ catch (MavenArtifactNotFoundException ex) {
90
+ throw new PluginSourceNotMatchException(ex);
91
+ }
92
+
93
+ final Class<?> pluginMainClass;
94
+ try (JarPluginLoader loader = JarPluginLoader.load(jarPath, pluginClassLoaderFactory)) {
95
+ pluginMainClass = loader.getPluginMainClass();
96
+ }
97
+ catch (InvalidJarPluginException ex) {
98
+ throw new PluginSourceNotMatchException(ex);
99
+ }
100
+
101
+ final Object pluginMainObject;
102
+ try {
103
+ // Unlike InjectedPluginSource and JRubyPluginSource,
104
+ // MavenPluginSource does not have "registration" before creating an instance of the plugin class.
105
+ // FileInputPlugin and FileOutputPlugin are wrapped with FileInputRunner and FileOutputRunner here.
106
+ if (FileInputPlugin.class.isAssignableFrom(pluginMainClass)) {
107
+ final FileInputPlugin fileInputPluginMainObject;
108
+ try {
109
+ fileInputPluginMainObject = (FileInputPlugin) this.injector.getInstance(pluginMainClass);
110
+ }
111
+ catch (ClassCastException ex) {
112
+ throw new PluginSourceNotMatchException(
113
+ "[FATAL/INTERNAL] Plugin class \"" + pluginMainClass.getName() + "\" is not file-input.", ex);
114
+ }
115
+ pluginMainObject = new FileInputRunner(fileInputPluginMainObject);
116
+ } else if (FileOutputPlugin.class.isAssignableFrom(pluginMainClass)) {
117
+ final FileOutputPlugin fileOutputPluginMainObject;
118
+ try {
119
+ fileOutputPluginMainObject = (FileOutputPlugin) this.injector.getInstance(pluginMainClass);
120
+ }
121
+ catch (ClassCastException ex) {
122
+ throw new PluginSourceNotMatchException(
123
+ "[FATAL/INTERNAL] Plugin class \"" + pluginMainClass.getName() + "\" is not file-output.", ex);
124
+ }
125
+ pluginMainObject = new FileOutputRunner(fileOutputPluginMainObject);
126
+ } else {
127
+ if (!pluginInterface.isAssignableFrom(pluginMainClass)) {
128
+ throw new PluginSourceNotMatchException(
129
+ "Plugin class \"" + pluginMainClass.getName() + "\" is not a valid " + category + " plugin.");
130
+ }
131
+ pluginMainObject = this.injector.getInstance(pluginMainClass);
132
+ }
133
+ }
134
+ catch (ExceptionInInitializerError ex) {
135
+ throw new PluginSourceNotMatchException(
136
+ "Plugin class \"" + pluginMainClass.getName() +
137
+ "\" is not instantiatable due to exception in initialization.", ex);
138
+ }
139
+ catch (SecurityException ex) {
140
+ throw new PluginSourceNotMatchException(
141
+ "Plugin class \"" + pluginMainClass.getName() +
142
+ "\" is not instantiatable due to security manager.", ex);
143
+ }
144
+
145
+ try {
146
+ return pluginInterface.cast(pluginMainObject);
147
+ }
148
+ catch (ClassCastException ex) {
149
+ throw new PluginSourceNotMatchException(
150
+ "[FATAL/INTERNAL] Plugin class \"" + pluginMainClass.getName() + "\" is not " + category + " actually.",
151
+ ex);
152
+ }
153
+ }
154
+
155
+ private Path getLocalMavenRepository()
156
+ throws PluginSourceNotMatchException
157
+ {
158
+ String env;
159
+ try {
160
+ env = System.getenv("M2_REPO");
161
+ }
162
+ catch (NullPointerException | SecurityException ex) {
163
+ // The Exceptions are just ignored, and the default local Maven repository is used.
164
+ // TODO: Log?
165
+ env = null;
166
+ }
167
+
168
+ if (env == null) {
169
+ return getEmbulkHome().resolve("m2").resolve("repository");
170
+ }
171
+
172
+ return Paths.get(env);
173
+ }
174
+
175
+ private Path getEmbulkHome()
176
+ throws PluginSourceNotMatchException
177
+ {
178
+ final String propertyHome = System.getProperty("user.home");
179
+ if (propertyHome == null) {
180
+ throw new PluginSourceNotMatchException();
181
+ }
182
+
183
+ return Paths.get(propertyHome, ".embulk");
184
+ }
185
+
186
+ private final Injector injector;
187
+ }
@@ -0,0 +1,22 @@
1
+ package org.embulk.plugin.maven;
2
+
3
+ import com.google.inject.Binder;
4
+ import com.google.inject.Module;
5
+ import com.google.inject.multibindings.Multibinder;
6
+ import org.embulk.config.ConfigSource;
7
+ import org.embulk.plugin.PluginSource;
8
+
9
+ public class MavenPluginSourceModule
10
+ implements Module
11
+ {
12
+ public MavenPluginSourceModule(ConfigSource systemConfig)
13
+ {
14
+ }
15
+
16
+ @Override
17
+ public void configure(Binder binder)
18
+ {
19
+ Multibinder<PluginSource> multibinder = Multibinder.newSetBinder(binder, PluginSource.class);
20
+ multibinder.addBinding().to(MavenPluginSource.class);
21
+ }
22
+ }
@@ -0,0 +1,31 @@
1
+ package org.embulk.plugin.maven;
2
+
3
+ import java.nio.file.Path;
4
+
5
+ public class MavenRepositoryNotFoundException
6
+ extends Exception {
7
+ public MavenRepositoryNotFoundException(final Path givenPath,
8
+ final Throwable cause)
9
+ {
10
+ super("Maven repository specified is not found at \"" + givenPath.toString() + "\".", cause);
11
+ }
12
+
13
+ public MavenRepositoryNotFoundException(final Path givenPath,
14
+ final Path absolutePath,
15
+ final Throwable cause)
16
+ {
17
+ super("Maven repository specified is not found at \"" + givenPath.toString() +
18
+ "\" (\"" + absolutePath.toString() + "\").",
19
+ cause);
20
+ }
21
+
22
+ public MavenRepositoryNotFoundException(final String message,
23
+ final Path givenPath,
24
+ final Path absolutePath,
25
+ final Throwable cause)
26
+ {
27
+ super("Maven repository specified is not found at \"" + givenPath.toString() +
28
+ "\" (\"" + absolutePath.toString() + "\"): " + message,
29
+ cause);
30
+ }
31
+ }
@@ -1,4 +1,4 @@
1
- # generated by './gradlew updateResources' at 2015-06-30 23:52:09 UTC
1
+ # generated by './gradlew updateResources' at 2017-06-24 00:47:26 UTC
2
2
  ch.qos.logback.classic
3
3
  ch.qos.logback.core
4
4
  com.fasterxml.jackson.annotation
@@ -65,6 +65,8 @@ org.jcodings
65
65
  org.joda.time
66
66
  org.joni
67
67
  org.jruby
68
+ org.msgpack.core
69
+ org.msgpack.value
68
70
  org.slf4j
69
71
  org.yaml.snakeyaml
70
72
  org.yecht
@@ -1,4 +1,4 @@
1
- # generated by './gradlew updateResources' at 2015-06-30 23:52:09 UTC
1
+ # generated by './gradlew updateResources' at 2017-06-24 00:47:26 UTC
2
2
  ch/qos/logback/classic/boolex
3
3
  ch/qos/logback/classic/db/script
4
4
  com/ibm/icu
@@ -18,6 +18,7 @@ jni/x86_64-Linux
18
18
  jni/x86_64-SunOS
19
19
  jni/x86_64-Windows
20
20
  jruby
21
+ msgpack
21
22
  net/jcip/annotations
22
23
  okay
23
24
  org/apache/bval/jsr303
@@ -13,6 +13,8 @@ import org.embulk.exec.SystemConfigModule;
13
13
  import org.embulk.exec.ExecModule;
14
14
  import org.embulk.exec.ExtensionServiceLoaderModule;
15
15
  import org.embulk.plugin.BuiltinPluginSourceModule;
16
+ import org.embulk.plugin.PluginClassLoaderFactory;
17
+ import org.embulk.plugin.PluginClassLoaderModule;
16
18
  import org.embulk.jruby.JRubyScriptingModule;
17
19
  import org.embulk.spi.BufferAllocator;
18
20
  import org.embulk.spi.Exec;
@@ -40,6 +42,7 @@ public class EmbulkTestRuntime
40
42
  new ExtensionServiceLoaderModule(systemConfig).configure(binder);
41
43
  new BuiltinPluginSourceModule().configure(binder);
42
44
  new JRubyScriptingModule(systemConfig).configure(binder);
45
+ new PluginClassLoaderModule(systemConfig).configure(binder);
43
46
  new TestUtilityModule().configure(binder);
44
47
  new TestPluginSourceModule().configure(binder);
45
48
  }
@@ -75,6 +78,11 @@ public class EmbulkTestRuntime
75
78
  return getInstance(RandomManager.class).getRandom();
76
79
  }
77
80
 
81
+ public PluginClassLoaderFactory getPluginClassLoaderFactory()
82
+ {
83
+ return getInstance(PluginClassLoaderFactory.class);
84
+ }
85
+
78
86
  @Override
79
87
  public Statement apply(Statement base, Description description)
80
88
  {