Skip to content

Commit

Permalink
Changed BatchComponentScanner to output error log.
Browse files Browse the repository at this point in the history
  • Loading branch information
223kazuki authored and seki-seki committed Apr 10, 2017
1 parent 602450a commit 8889d32
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/clj/job_streamer/control_bus/component/apps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@
classpaths))
proc (.exec (Runtime/getRuntime) cmd)]
(log/debug (clojure.string/join " " cmd))
(letfn [(print-err []
(with-open [rdr (io/reader (.getErrorStream proc))]
(->> (line-seq rdr)
(map #(log/error %))
doall)))]
(.start (Thread. print-err)))
(with-open [rdr (io/reader (.getInputStream proc))]
(->> (line-seq rdr)
(map #(clojure.string/split % #":" 2))
(map (fn [[category class-name]]
{(keyword "batch-component" category) class-name}))
(let [c {(keyword "batch-component" category) class-name}]
(log/debugf "%s was scaned." (pr-str c)) c)))
(reduce #(merge-with conj %1 %2)
{:batch-component/batchlet []
:batch-component/item-reader []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Set<String> jarEntryNames(File zipFile) throws IOException {
}

String decideRefName(Class<?> clazz) {
System.err.println(clazz);
System.err.println(clazz.getAnnotations());
System.err.println("decideRefName: clazz: " + clazz);
System.err.println("decideRefName: annotation: " + clazz.getAnnotations());
Annotation[] annotations = clazz.getDeclaredAnnotations();
for (Annotation annotation : annotations) {
if (annotation instanceof Named && !Strings.isNullOrEmpty(((Named) annotation).value())) {
Expand All @@ -83,29 +83,41 @@ void pickOverBatchComponent(String resourcePath, ClassLoader cl) {
String className = resourcePath
.substring(0, resourcePath.lastIndexOf(".class"))
.replace('/', '.').replace('\\', '.');
System.err.println("className: " + className);
if (className.startsWith("java.")
|| className.startsWith("javax.")
|| className.startsWith("com.sun.")
|| className.startsWith("sun.")
|| className.startsWith("clojure.")) {
System.err.println("This is ignored with wrong package name");
return;
}
try {
Class<?> clazz = cl.loadClass(className);
if (Batchlet.class.isAssignableFrom(clazz)) {
container.batchlets.add(decideRefName(clazz));
System.err.println(" This clazz is Batchlet");
container.batchlets.add(decideRefName(clazz));
} else if (ItemReader.class.isAssignableFrom(clazz)) {
container.itemReaders.add(decideRefName(clazz));
System.err.println(" This clazz is ItemReader");
container.itemReaders.add(decideRefName(clazz));
} else if (ItemWriter.class.isAssignableFrom(clazz)) {
container.itemWriters.add(decideRefName(clazz));
System.err.println(" This clazz is ItemWriter");
container.itemWriters.add(decideRefName(clazz));
} else if (ItemProcessor.class.isAssignableFrom(clazz)) {
container.itemProcessors.add(decideRefName(clazz));
System.err.println(" This clazz is ItemProcessor");
container.itemProcessors.add(decideRefName(clazz));
} else if (isListener(clazz)) {
container.listeners.add(decideRefName(clazz));
System.err.println(" This clazz is Listener");
container.listeners.add(decideRefName(clazz));
} else if (Throwable.class.isAssignableFrom(clazz)) {
container.throwables.add(decideRefName(clazz));
System.err.println(" This clazz is Throwable");
container.throwables.add(decideRefName(clazz));
} else {
System.err.println(" This clazz is ignored");
}
} catch (ClassNotFoundException | NoClassDefFoundError e) {
System.err.println(" This clazz is ignored with Exception");
e.printStackTrace();
// ignore
}
}
Expand Down

0 comments on commit 8889d32

Please sign in to comment.