From d11da0075eb14e05df6e3291941f393a8a3c498f Mon Sep 17 00:00:00 2001 From: taktos9 Date: Fri, 17 Oct 2008 01:50:10 +0000 Subject: [PATCH] =?utf8?q?s2jdbc-gen=E3=81=AEAnt=E3=83=A9=E3=83=B3?= =?utf8?q?=E3=83=81=E3=83=A3=E3=83=BC=E3=82=92=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.sourceforge.jp/svnroot/ea2ddl/trunk/ea2ddl@27 136db618-7844-41ca-8ac1-fb3fd040db1d --- ea2ddl-common/pom.xml | 5 + .../seasar/extension/jdbc/gen/command/Command.java | 35 +++ .../extension/jdbc/gen/command/CommandAdapter.java | 63 ++++++ .../extension/jdbc/gen/command/CommandInvoker.java | 32 +++ .../exception/CommandFailedRuntimeException.java | 55 +++++ .../jdbc/gen/internal/arg/ArgumentsBuilder.java | 87 ++++++++ .../jdbc/gen/internal/arg/ArgumentsParser.java | 91 ++++++++ .../jdbc/gen/internal/argtype/ArgumentType.java | 45 ++++ .../gen/internal/argtype/ArgumentTypeRegistry.java | 145 ++++++++++++ .../jdbc/gen/internal/argtype/BooleanType.java | 41 ++++ .../jdbc/gen/internal/argtype/CharacterType.java | 45 ++++ .../jdbc/gen/internal/argtype/ClassType.java | 44 ++++ .../jdbc/gen/internal/argtype/EnumType.java | 56 +++++ .../jdbc/gen/internal/argtype/FileType.java | 47 ++++ .../jdbc/gen/internal/argtype/ListType.java | 236 ++++++++++++++++++++ .../jdbc/gen/internal/argtype/NumberType.java | 59 +++++ .../jdbc/gen/internal/argtype/StringType.java | 42 ++++ .../jdbc/gen/internal/command/AbstractCommand.java | 177 +++++++++++++++ .../gen/internal/command/CommandInvokerImpl.java | 31 +++ .../exception/ClassUnmatchRuntimeException.java | 69 ++++++ .../SystemPropertyNotFoundRuntimeException.java | 52 +++++ .../jdbc/gen/internal/util/ArgumentUtil.java | 79 +++++++ .../extension/jdbc/gen/internal/util/EnvUtil.java | 64 ++++++ .../extension/jdbc/gen/internal/util/FileUtil.java | 247 +++++++++++++++++++++ .../jdbc/gen/internal/util/ReflectUtil.java | 53 +++++ .../util/SingletonS2ContainerFactorySupport.java | 74 ++++++ .../extension/jdbc/gen/task/AbstractTask.java | 184 +++++++++++++++ 27 files changed, 2158 insertions(+) create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/Command.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandAdapter.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandInvoker.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/exception/CommandFailedRuntimeException.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsBuilder.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsParser.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentTypeRegistry.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/BooleanType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/CharacterType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ClassType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/EnumType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/FileType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ListType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/NumberType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/StringType.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/AbstractCommand.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/CommandInvokerImpl.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/ClassUnmatchRuntimeException.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/SystemPropertyNotFoundRuntimeException.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ArgumentUtil.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/EnvUtil.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/FileUtil.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ReflectUtil.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/SingletonS2ContainerFactorySupport.java create mode 100644 ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/task/AbstractTask.java diff --git a/ea2ddl-common/pom.xml b/ea2ddl-common/pom.xml index e4a4ab1..8858574 100644 --- a/ea2ddl-common/pom.xml +++ b/ea2ddl-common/pom.xml @@ -38,5 +38,10 @@ org.apache.geronimo.specs geronimo-jta_1.1_spec + + + org.apache.ant + ant + \ No newline at end of file diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/Command.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/Command.java new file mode 100644 index 0000000..6a404d1 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/Command.java @@ -0,0 +1,35 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.command; + +import org.seasar.extension.jdbc.gen.exception.CommandFailedRuntimeException; + +/** + * 繧ウ繝槭Φ繝峨r陦ィ縺吶う繝ウ繧ソ繝輔ぉ繝シ繧ケ縺ァ縺吶� + * + * @author taedium + */ +public interface Command { + + /** + * 螳溯。後@縺セ縺吶� + * + * @throws CommandFailedRuntimeException + * 繧ウ繝槭Φ繝峨�螳溯。後↓螟ア謨励@縺溷�蜷� + */ + void execute() throws CommandFailedRuntimeException; + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandAdapter.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandAdapter.java new file mode 100644 index 0000000..dc05317 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandAdapter.java @@ -0,0 +1,63 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.command; + +import org.seasar.extension.jdbc.gen.internal.arg.ArgumentsParser; +import org.seasar.extension.jdbc.gen.internal.exception.SystemPropertyNotFoundRuntimeException; +import org.seasar.extension.jdbc.gen.internal.util.ReflectUtil; + +/** + * {@link Command}のアダプタとなるクラスです。 + *

+ * コマンドラインの情報を元に{@link Command}を組み立て実行します。 + *

+ * + * @author taedium + */ +public class CommandAdapter { + + /** コマンドクラスのキー */ + public static String COMMAND_KEY = Command.class.getName(); + + /** コマンド呼び出しクラスのキー */ + public static String COMMAND_INVOKER_KEY = CommandInvoker.class.getName(); + + /** + * システムプロパティに登録された{@link Command}をシステムプロパティに登録された{@link CommandInvoker} + * で実行します。 + * + * @param args + * 引数の配列 + */ + public static void main(String[] args) { + String commandName = System.getProperty(COMMAND_KEY); + if (commandName == null) { + throw new SystemPropertyNotFoundRuntimeException(COMMAND_KEY); + } + String invokerName = System.getProperty(COMMAND_INVOKER_KEY); + if (invokerName == null) { + throw new SystemPropertyNotFoundRuntimeException( + COMMAND_INVOKER_KEY); + } + Command command = ReflectUtil.newInstance(Command.class, commandName); + ArgumentsParser parser = new ArgumentsParser(command); + parser.parse(args); + + CommandInvoker invoker = ReflectUtil.newInstance(CommandInvoker.class, + invokerName); + invoker.invoke(command); + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandInvoker.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandInvoker.java new file mode 100644 index 0000000..4e17e89 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/command/CommandInvoker.java @@ -0,0 +1,32 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.command; + +/** + * コマンドを呼び出すインタフェースです。 + * + * @author taedium + */ +public interface CommandInvoker { + + /** + * コマンドを呼び出します。 + * + * @param command + * コマンド + */ + void invoke(Command command); +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/exception/CommandFailedRuntimeException.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/exception/CommandFailedRuntimeException.java new file mode 100644 index 0000000..73400c7 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/exception/CommandFailedRuntimeException.java @@ -0,0 +1,55 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.exception; + +import org.seasar.framework.exception.SRuntimeException; + +/** + * コマンドの実行が失敗した場合にスローされる例外です。 + * + * @author taedium + */ +public class CommandFailedRuntimeException extends SRuntimeException { + + private static final long serialVersionUID = 1L; + + /** コマンドのクラス名 */ + protected String commandClassName; + + /** + * インスタンスを構築します。 + * + * @param cause + * 原因 + * @param commandClassName + * コマンドのクラス名 + */ + public CommandFailedRuntimeException(Throwable cause, + String commandClassName) { + super("ES2JDBCGen0005", new Object[] { commandClassName, cause }, cause); + this.commandClassName = commandClassName; + } + + /** + * コマンドのクラス名を返します。 + * + * @return コマンドのクラス名 + */ + public String getCommandClassName() { + return commandClassName; + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsBuilder.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsBuilder.java new file mode 100644 index 0000000..a42501e --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsBuilder.java @@ -0,0 +1,87 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.arg; + +import java.util.ArrayList; +import java.util.List; + +import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentType; +import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentTypeRegistry; +import org.seasar.framework.beans.BeanDesc; +import org.seasar.framework.beans.PropertyDesc; +import org.seasar.framework.beans.factory.BeanDescFactory; +import org.seasar.framework.log.Logger; + +/** + * コマンドライン用の引数を組み立てるクラスです。 + *

+ * JavaBeanのプロパティと値の組を「=」で連結し1つの引数とします。 + *

+ * + * @author taedium + */ +public class ArgumentsBuilder { + + /** ロガー */ + protected static Logger logger = Logger.getLogger(ArgumentsBuilder.class); + + /** JavaBeanのインスタンス */ + protected Object bean; + + /** Bean記述 */ + protected BeanDesc beanDesc; + + /** + * インスタンスを構築します。 + * + * @param bean + * JavaBeanのインスタンス + */ + public ArgumentsBuilder(Object bean) { + if (bean == null) { + throw new NullPointerException("bean"); + } + this.bean = bean; + beanDesc = BeanDescFactory.getBeanDesc(bean.getClass()); + } + + /** + * 引数を組み立てます。 + * + * @return 引数のリスト + */ + public List build() { + ArrayList args = new ArrayList(); + for (int i = 0; i < beanDesc.getPropertyDescSize(); i++) { + PropertyDesc propertyDesc = beanDesc.getPropertyDesc(i); + if (!propertyDesc.hasReadMethod()) { + continue; + } + ArgumentType argumentType = ArgumentTypeRegistry + .getArgumentType(propertyDesc); + if (argumentType == null) { + logger.log("WS2JDBCGEN0001", new Object[] { + bean.getClass().getName(), + propertyDesc.getPropertyName() }); + continue; + } + String name = propertyDesc.getPropertyName(); + Object value = propertyDesc.getValue(bean); + args.add(name + "=" + argumentType.toText(value)); + } + return args; + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsParser.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsParser.java new file mode 100644 index 0000000..ebd5049 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/arg/ArgumentsParser.java @@ -0,0 +1,91 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.arg; + +import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentType; +import org.seasar.extension.jdbc.gen.internal.argtype.ArgumentTypeRegistry; +import org.seasar.framework.beans.BeanDesc; +import org.seasar.framework.beans.PropertyDesc; +import org.seasar.framework.beans.factory.BeanDescFactory; +import org.seasar.framework.log.Logger; + +/** + * コマンドラインの引数を解析するクラスです。 + *

+ * それぞれの引数は「=」で連結されたキーと値の組である必要があります。 このクラスは、キーに対応するJavaBeanのプロパティに値を設定します。 + *

+ * + * @author taedium + */ +public class ArgumentsParser { + + /** ロガー */ + protected static Logger logger = Logger.getLogger(ArgumentsParser.class); + + /** JavaBeanのインスタンス */ + protected Object bean; + + /** Bean記述 */ + protected BeanDesc beanDesc; + + /** + * インスタンスを構築します。 + * + * @param bean + * JavaBeanのインスタンス + */ + public ArgumentsParser(Object bean) { + if (bean == null) { + throw new NullPointerException("bean"); + } + this.bean = bean; + beanDesc = BeanDescFactory.getBeanDesc(bean.getClass()); + } + + /** + * 解析します。 + * + * @param args + */ + public void parse(String[] args) { + for (String arg : args) { + int pos = arg.indexOf("="); + if (pos < 0) { + throw new IllegalArgumentException(arg); + } + String key = arg.substring(0, pos); + String value = arg.substring(pos + 1, arg.length()); + if (!beanDesc.hasPropertyDesc(key)) { + continue; + } + PropertyDesc propertyDesc = beanDesc.getPropertyDesc(key); + if (!propertyDesc.hasWriteMethod()) { + continue; + } + ArgumentType argumentType = ArgumentTypeRegistry + .getArgumentType(propertyDesc); + if (argumentType == null) { + logger.log("WS2JDBCGEN0001", new Object[] { + bean.getClass().getName(), + propertyDesc.getPropertyName() }); + continue; + } + Object propertyValue = argumentType.toObject(value); + propertyDesc.setValue(bean, propertyValue); + } + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentType.java new file mode 100644 index 0000000..fc0389f --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentType.java @@ -0,0 +1,45 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +/** + * コマンドラインの引数の値の型を表すインタフェースです。 + * + * @author taedium + * @param + * 引数の値の型 + */ +public interface ArgumentType { + + /** + * 引数の値の文字列を適切な型のオブジェクトに変換します。 + * + * @param value + * 引数の文字列 + * @return オブジェクト + */ + T toObject(String value); + + /** + * 引数の値のオブジェクトを文字列に変換します。 + * + * @param value + * 引数のオブジェクト + * @return 文字列 + */ + String toText(T value); + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentTypeRegistry.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentTypeRegistry.java new file mode 100644 index 0000000..7e16bf6 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ArgumentTypeRegistry.java @@ -0,0 +1,145 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.seasar.framework.beans.PropertyDesc; +import org.seasar.framework.util.ClassUtil; +import org.seasar.framework.util.tiger.ReflectionUtil; + +/** + * {@link ArgumentType}を管理するクラスです。 + * + * @author taedium + */ +public class ArgumentTypeRegistry { + + /** 引数の値のクラスをキー、 {@link ArgumentType}のコンストラクタを値とするマップ */ + protected static Map, Constructor>> argTypeMap = new ConcurrentHashMap, Constructor>>(); + static { + argTypeMap.put(Boolean.class, ReflectionUtil.getConstructor( + BooleanType.class, null)); + argTypeMap.put(Character.class, ReflectionUtil.getConstructor( + CharacterType.class, null)); + argTypeMap.put(String.class, ReflectionUtil.getConstructor( + StringType.class, null)); + argTypeMap.put(File.class, ReflectionUtil.getConstructor( + FileType.class, null)); + argTypeMap.put(Class.class, ReflectionUtil.getConstructor( + ClassType.class, null)); + } + + /** + * {@link ArgumentType}を返します。 + * + * @param + * 引数の値の型 + * @param propertyDesc + * プロパティ記述 + * @return {@link ArgumentType} + */ + public static ArgumentType getArgumentType(PropertyDesc propertyDesc) { + Class propertyType = propertyDesc.getPropertyType(); + if (propertyDesc.isParameterized() + && Collection.class.isAssignableFrom(propertyType)) { + Class elementClass = propertyDesc.getElementClassOfCollection(); + return getCollectionArgumentType(propertyType, elementClass); + } + return getArgumentType(propertyType); + } + + /** + * {@link ArgumentType}を返します。 + * + * @param + * 引数の値の型 + * @param clazz + * 引数の値のクラス + * @return {@link ArgumentType} + */ + @SuppressWarnings("unchecked") + protected static ArgumentType getArgumentType(Class clazz) { + clazz = ClassUtil.getWrapperClassIfPrimitive(clazz); + if (argTypeMap.containsKey(clazz)) { + Constructor> constructor = argTypeMap + .get(clazz); + return (ArgumentType) ReflectionUtil.newInstance(constructor, + null); + } + if (Number.class.isAssignableFrom(clazz)) { + return new NumberType(clazz); + } + if (Enum.class.isAssignableFrom(clazz)) { + return new EnumType(clazz); + } + return null; + } + + /** + * {@link ArgumentType}を返します。 + * + * @param + * 引数の値の型 + * @param collectioinClass + * コレクションのクラス + * @param elementClass + * コレクションの要素のクラス + * @return {@link ArgumentType}を返します。 + */ + @SuppressWarnings("unchecked") + protected static ArgumentType getCollectionArgumentType( + Class collectioinClass, Class elementClass) { + ArgumentType argumentType = getArgumentType(elementClass); + if (List.class.isAssignableFrom(collectioinClass)) { + return new ListType(argumentType); + } + return null; + } + + /** + * {@link ArgumentType}を登録します。 + * + * @param clazz + * 引数の値のクラス + */ + protected static void register(Class> clazz) { + if (clazz == null) { + throw new NullPointerException("clazz"); + } + Constructor> constructor = ReflectionUtil + .getConstructor(clazz, null); + argTypeMap.put(clazz, constructor); + } + + /** + * {@link ArgumentType}を削除します。 + * + * @param clazz + * 引数の値のクラス + */ + protected static void deregister(Class> clazz) { + if (clazz == null) { + throw new NullPointerException("clazz"); + } + argTypeMap.remove(clazz); + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/BooleanType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/BooleanType.java new file mode 100644 index 0000000..2eef9a5 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/BooleanType.java @@ -0,0 +1,41 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import org.seasar.framework.util.StringUtil; + +/** + * {@link Boolean}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + */ +public class BooleanType implements ArgumentType { + + public Boolean toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + return Boolean.valueOf(value); + } + + public String toText(Boolean value) { + if (value == null) { + return ""; + } + return value.toString(); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/CharacterType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/CharacterType.java new file mode 100644 index 0000000..63b3afe --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/CharacterType.java @@ -0,0 +1,45 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import org.seasar.framework.util.StringConversionUtil; +import org.seasar.framework.util.StringUtil; + +/** + * {@link Character}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + */ +public class CharacterType implements ArgumentType { + + public Character toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + String s = value.replace("\\u", ""); + int ch = Integer.valueOf(s); + return (char) ch; + } + + public String toText(Character value) { + if (value == null) { + return ""; + } + char ch = value.charValue(); + return "\\u" + StringConversionUtil.toString((int) ch, "0000"); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ClassType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ClassType.java new file mode 100644 index 0000000..76265b3 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ClassType.java @@ -0,0 +1,44 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import org.seasar.framework.util.StringUtil; +import org.seasar.framework.util.tiger.ReflectionUtil; + +/** + * {@link Class}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + * @param + * クラスの型 + */ +public class ClassType implements ArgumentType> { + + public Class toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + return ReflectionUtil.forName(value); + } + + public String toText(Class value) { + if (value == null) { + return ""; + } + return value.getName(); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/EnumType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/EnumType.java new file mode 100644 index 0000000..df7235d --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/EnumType.java @@ -0,0 +1,56 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import org.seasar.framework.util.StringUtil; + +/** + * {@link Enum}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + * @param + * {@link Enum}のサブタイプ + */ +public class EnumType> implements ArgumentType { + + /** 列挙型のクラス */ + protected Class enumClass; + + /** + * インスタンスを構築します。 + * + * @param enumClass + * 列挙型のクラス + */ + public EnumType(Class enumClass) { + this.enumClass = enumClass; + } + + public T toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + return Enum.valueOf(enumClass, value); + } + + public String toText(T value) { + if (value == null) { + return ""; + } + return value.name(); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/FileType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/FileType.java new file mode 100644 index 0000000..6e7b9ac --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/FileType.java @@ -0,0 +1,47 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import java.io.File; + +import org.seasar.extension.jdbc.gen.internal.util.ArgumentUtil; +import org.seasar.extension.jdbc.gen.internal.util.FileUtil; +import org.seasar.framework.util.StringUtil; + +/** + * {@link File}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + */ +public class FileType implements ArgumentType { + + public File toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + String s = ArgumentUtil.decode(value); + return new File(s); + } + + public String toText(File value) { + if (value == null) { + return ""; + } + String path = FileUtil.getCanonicalPath(value); + return ArgumentUtil.encode(path); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ListType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ListType.java new file mode 100644 index 0000000..8dad176 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/ListType.java @@ -0,0 +1,236 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import java.util.ArrayList; +import java.util.List; + +import org.seasar.extension.jdbc.gen.internal.util.ArgumentUtil; +import org.seasar.framework.util.StringUtil; + +import static org.seasar.extension.jdbc.gen.internal.argtype.ListType.TokenType.*; + +/** + * {@link List}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + * @param + * リストの要素の型 + */ +public class ListType implements ArgumentType> { + + /** 開き角括弧 */ + protected static String OPEN_BRACKET = "["; + + /** 閉じ角括弧 */ + protected static String CLOSE_BRACKET = "]"; + + /** リストの要素に対応する{@link ArgumentType} */ + protected ArgumentType argumentType; + + /** + * @param argumentType + */ + public ListType(ArgumentType argumentType) { + this.argumentType = argumentType; + } + + public List toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + List list = new ArrayList(); + String s = StringUtil.ltrim(value, OPEN_BRACKET); + s = StringUtil.rtrim(s, CLOSE_BRACKET); + Tokenizer tokenizer = new Tokenizer(s); + nextTokenLoop: for (;;) { + switch (tokenizer.nextToken()) { + case QUOTED_VALUE: + case VALUE: + String token = tokenizer.getToken(); + list.add(argumentType.toObject(token)); + break; + case END: + break nextTokenLoop; + } + } + return list; + } + + public String toText(List value) { + if (value == null) { + return ""; + } + StringBuilder buf = new StringBuilder(); + buf.append(OPEN_BRACKET); + for (T o : value) { + buf.append(argumentType.toText(o)); + buf.append(","); + } + if (value.size() > 0) { + buf.setLength(buf.length() - 1); + } + buf.append(CLOSE_BRACKET); + return buf.toString(); + } + + /** + * トークンのタイプです。 + * + * @author taedium + */ + protected static enum TokenType { + /** クォートされた値 */ + QUOTED_VALUE, + /** クォートされていない値 */ + VALUE, + /** 区切り文字 */ + DELIMITER, + /** トークンの最後 */ + END + } + + /** + * リストの引数の値を区切るクラスです。 + * + * @author taedium + */ + protected static class Tokenizer { + + /** 区切り文字 */ + protected char delimiter = ArgumentUtil.DELIMITER_CHAR; + + /** 引用句 */ + protected char quote = ArgumentUtil.QUOTE_CHAR; + + /** 値 */ + protected String value; + + /** 長さ */ + protected int length; + + /** 位置 */ + protected int pos; + + /** 次の位置 */ + protected int nextPos; + + /** トークン */ + protected String token; + + /** トークンのタイプ */ + protected TokenType type; + + /** + * インスタンスを構築します。 + * + * @param value + * 値 + */ + protected Tokenizer(String value) { + + this.value = value; + this.length = value.length(); + peek(0); + } + + /** + * 次のトークンを前もって調べます。 + * + * @param index + * インデックス + */ + protected void peek(int index) { + if (index < length) { + char c = value.charAt(index); + if (c == delimiter) { + type = DELIMITER; + pos = index; + nextPos = index + 1; + } else if (c == quote) { + type = QUOTED_VALUE; + pos = index; + nextPos = index + 1; + } else { + type = VALUE; + pos = index; + nextPos = index; + } + } else { + type = TokenType.END; + } + } + + /** + * 次のトークンを返します。 + * + * @return 次のトークン + */ + protected TokenType nextToken() { + switch (type) { + case QUOTED_VALUE: + for (int i = nextPos; i < length; i++) { + char c = value.charAt(i); + if (c == quote) { + i++; + if (i >= length) { + token = value.substring(pos, i); + type = END; + return QUOTED_VALUE; + } else if (value.charAt(i) == delimiter) { + token = value.substring(pos, i); + peek(i); + return QUOTED_VALUE; + } + } + } + token = value.substring(pos, length); + type = END; + return QUOTED_VALUE; + case VALUE: + for (int i = nextPos; i < length; i++) { + char c = value.charAt(i); + if (c == delimiter) { + token = value.substring(pos, i); + peek(i); + return VALUE; + } + } + token = value.substring(pos, length); + type = END; + return QUOTED_VALUE; + case DELIMITER: + token = value.substring(pos, nextPos); + peek(nextPos); + return DELIMITER; + case END: + token = null; + return END; + } + throw new IllegalStateException("type"); + } + + /** + * トークンを返します。 + * + * @return トークン + */ + protected String getToken() { + return token; + } + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/NumberType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/NumberType.java new file mode 100644 index 0000000..fb77878 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/NumberType.java @@ -0,0 +1,59 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import org.seasar.framework.util.NumberConversionUtil; +import org.seasar.framework.util.StringConversionUtil; +import org.seasar.framework.util.StringUtil; + +/** + * {@link Number}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + * @param + * {@link Number}のサブタイプ + */ +public class NumberType implements ArgumentType { + + /** 数値を表すクラス */ + protected Class numberClass; + + /** + *インスタンスを構築します。 + * + * @param numberClass + * 数値を表すクラス + */ + public NumberType(Class numberClass) { + this.numberClass = numberClass; + } + + public T toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + Object number = NumberConversionUtil.convertNumber(numberClass, value); + return numberClass.cast(number); + } + + public String toText(T value) { + if (value == null) { + return ""; + } + return StringConversionUtil.toString(value); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/StringType.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/StringType.java new file mode 100644 index 0000000..cf3b704 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/argtype/StringType.java @@ -0,0 +1,42 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.argtype; + +import org.seasar.extension.jdbc.gen.internal.util.ArgumentUtil; +import org.seasar.framework.util.StringUtil; + +/** + * {@link String}を扱う{@link ArgumentType}の実装クラスです。 + * + * @author taedium + */ +public class StringType implements ArgumentType { + + public String toObject(String value) { + if (StringUtil.isEmpty(value)) { + return null; + } + return ArgumentUtil.decode(value); + } + + public String toText(String value) { + if (value == null) { + return ""; + } + return ArgumentUtil.encode(value); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/AbstractCommand.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/AbstractCommand.java new file mode 100644 index 0000000..69aaeb7 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/AbstractCommand.java @@ -0,0 +1,177 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.command; + +import org.seasar.extension.jdbc.gen.command.Command; +import org.seasar.extension.jdbc.gen.exception.CommandFailedRuntimeException; +import org.seasar.extension.jdbc.gen.internal.util.SingletonS2ContainerFactorySupport; +import org.seasar.framework.beans.BeanDesc; +import org.seasar.framework.beans.PropertyDesc; +import org.seasar.framework.beans.factory.BeanDescFactory; +import org.seasar.framework.container.factory.SingletonS2ContainerFactory; +import org.seasar.framework.log.Logger; + +/** + * コマンドの抽象クラスです。 + * + * @author taedium + */ +public abstract class AbstractCommand implements Command { + + /** 設定ファイルのパス */ + protected String configPath = "s2jdbc.dicon"; + + /** 環境名 */ + protected String env = "ut"; + + /** {@link SingletonS2ContainerFactory}のサポート */ + protected SingletonS2ContainerFactorySupport containerFactorySupport; + + /** + * インスタンスを構築します。 + */ + public AbstractCommand() { + } + + /** + * 設定ファイルのパスを返します。 + * + * @return 設定ファイルのパス + */ + public String getConfigPath() { + return configPath; + } + + /** + * 設定ファイルのパスを設定します。 + * + * @param configPath + * 設定ファイルのパス + */ + public void setConfigPath(String configPath) { + this.configPath = configPath; + } + + /** + * 環境名を返します。 + * + * @return 環境名 + */ + public String getEnv() { + return env; + } + + /** + * 環境名を設定します。 + * + * @param env + * 環境名 + */ + public void setEnv(String env) { + this.env = env; + } + + public final void execute() { + String commandClassName = getClass().getName(); + getLogger().log("DS2JDBCGen0003", new Object[] { commandClassName }); + logWritableProperties(); + validate(); + init(); + try { + doExecute(); + } catch (Throwable t) { + throw new CommandFailedRuntimeException(t, commandClassName); + } finally { + destroy(); + } + getLogger().log("DS2JDBCGen0008", new Object[] { commandClassName }); + } + + /** + * 設定可能なプロパティの値をログ出力します。 + */ + protected void logWritableProperties() { + BeanDesc beanDesc = BeanDescFactory.getBeanDesc(getClass()); + for (int i = 0; i < beanDesc.getPropertyDescSize(); i++) { + PropertyDesc propertyDesc = beanDesc.getPropertyDesc(i); + if (propertyDesc.hasWriteMethod() && propertyDesc.hasReadMethod()) { + getLogger().info(propertyDesc.getPropertyName()); + getLogger().info(propertyDesc.getWriteMethod()); + getLogger().log( + "DS2JDBCGen0001", + new Object[] { propertyDesc.getPropertyName(), + propertyDesc.getValue(this) }); + } + } + } + + /** + * 検証します。 + */ + protected final void validate() { + doValidate(); + } + + /** + * 初期化します。 + */ + protected final void init() { + containerFactorySupport = new SingletonS2ContainerFactorySupport( + configPath, env); + containerFactorySupport.init(); + doInit(); + } + + /** + * 破棄します。 + */ + protected final void destroy() { + doDestroy(); + if (containerFactorySupport != null) { + containerFactorySupport.destory(); + } + } + + /** + * サブクラスで検証します。 + */ + protected abstract void doValidate(); + + /** + * サブクラスで初期化します。 + */ + protected abstract void doInit(); + + /** + * サブクラスで実行します。 + * + * @throws Throwable + */ + protected abstract void doExecute() throws Throwable; + + /** + * サブクラスで破棄します。 + */ + protected abstract void doDestroy(); + + /** + * ロガーを返します。 + * + * @return ロガー + */ + protected abstract Logger getLogger(); + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/CommandInvokerImpl.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/CommandInvokerImpl.java new file mode 100644 index 0000000..dbdd03e --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/command/CommandInvokerImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.command; + +import org.seasar.extension.jdbc.gen.command.Command; +import org.seasar.extension.jdbc.gen.command.CommandInvoker; + +/** + * {@link CommandInvoker}の実装クラスです。 + * + * @author taedium + */ +public class CommandInvokerImpl implements CommandInvoker { + + public void invoke(Command command) { + command.execute(); + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/ClassUnmatchRuntimeException.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/ClassUnmatchRuntimeException.java new file mode 100644 index 0000000..b435651 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/ClassUnmatchRuntimeException.java @@ -0,0 +1,69 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.exception; + +import org.seasar.framework.exception.SRuntimeException; + +/** + * ある型を期待する型でキャストできない場合にスローされる例外です。 + * + * @author taedium + */ +public class ClassUnmatchRuntimeException extends SRuntimeException { + + private static final long serialVersionUID = 1L; + + /** 期待するクラス */ + protected Class expectedClass; + + /** 実際のクラス */ + protected Class actualClass; + + /** + * インスタンスを構築します。 + * + * @param expectedClass + * 期待するクラス + * @param actualClass + * 実際のクラス + */ + public ClassUnmatchRuntimeException(Class expectedClass, + Class actualClass) { + super("ES2JDBCGen0023", new Object[] { actualClass.getName(), + expectedClass.getName(), }); + this.expectedClass = expectedClass; + this.actualClass = actualClass; + } + + /** + * 期待するクラスを返します。 + * + * @return 期待するクラス + */ + public Class getExpectedClass() { + return expectedClass; + } + + /** + * 実際のクラスを返します。 + * + * @return 実際のクラス + */ + public Class getActualClass() { + return actualClass; + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/SystemPropertyNotFoundRuntimeException.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/SystemPropertyNotFoundRuntimeException.java new file mode 100644 index 0000000..ad31a63 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/exception/SystemPropertyNotFoundRuntimeException.java @@ -0,0 +1,52 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.exception; + +import org.seasar.framework.exception.SRuntimeException; + +/** + * システムプロパティが見つからない場合にスローされる例外です。 + * + * @author taedium + */ +public class SystemPropertyNotFoundRuntimeException extends SRuntimeException { + + private static final long serialVersionUID = 1L; + + /** プロパティ名 */ + protected String propertyName; + + /** + * インスタンスを構築します。 + * + * @param propertyName + * プロパティ名 + */ + public SystemPropertyNotFoundRuntimeException(String propertyName) { + super("ES2JDBCGen0018", new Object[] { propertyName }); + this.propertyName = propertyName; + } + + /** + * プロパティ名を返します。 + * + * @return プロパティ名 + */ + public String getPropertyName() { + return propertyName; + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ArgumentUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ArgumentUtil.java new file mode 100644 index 0000000..a3c3d82 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ArgumentUtil.java @@ -0,0 +1,79 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.util; + +import org.seasar.framework.util.StringUtil; + +/** + * 引数に関するユーティリティクラスです。 + * + * @author taedium + */ +public class ArgumentUtil { + + /** 引用符 */ + public static String QUOTE = "'"; + + /** char型としての引用符 */ + public static char QUOTE_CHAR = '\''; + + /** エスケープされた引用符 */ + public static String ESCAPED_QUOTE = "'"; + + /** 区切り文字 */ + public static String DELIMITER = ","; + + /** char型としての区切り文字 */ + public static char DELIMITER_CHAR = ','; + + /** + * + */ + protected ArgumentUtil() { + } + + /** + * エンコードします。 + * + * @param value + * 値 + * @return エンコードされた値 + */ + public static String encode(String value) { + if (value == null) { + throw new NullPointerException("value"); + } + String s = value.replace(QUOTE, ESCAPED_QUOTE); + return QUOTE + s + QUOTE; + } + + /** + * デコードします。 + * + * @param value + * 値 + * @return デコードされた値 + */ + public static String decode(String value) { + if (value == null) { + throw new NullPointerException("value"); + } + String s = StringUtil.ltrim(value, QUOTE); + s = StringUtil.rtrim(s, QUOTE); + return s.replace(ESCAPED_QUOTE, QUOTE); + } + +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/EnvUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/EnvUtil.java new file mode 100644 index 0000000..deaa997 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/EnvUtil.java @@ -0,0 +1,64 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.util; + +import java.lang.reflect.Field; + +import org.seasar.framework.env.Env; +import org.seasar.framework.util.tiger.ReflectionUtil; + +/** + * {@link Env}に関するユーティリティクラスです。 + * + * @author taedium + */ +public class EnvUtil { + + /** 環境名と環境名以外の区切り文字 */ + public static char DELIMITER = '#'; + + /** {@link Env}の環境名を保持するフィールド */ + protected static Field VALUE_FIELD; + static { + VALUE_FIELD = ReflectionUtil.getDeclaredField(Env.class, "value"); + VALUE_FIELD.setAccessible(true); + } + + /** + * + */ + protected EnvUtil() { + } + + /** + * 環境名を返します。 + * + * @return 環境名 + */ + public static String getValue() { + return ReflectionUtil.getStaticValue(VALUE_FIELD); + } + + /** + * 環境名を設定します。 + * + * @param value + * 環境名 + */ + public static void setValue(String value) { + ReflectionUtil.setStaticValue(VALUE_FIELD, value); + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/FileUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/FileUtil.java new file mode 100644 index 0000000..80d79fe --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/FileUtil.java @@ -0,0 +1,247 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.util; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Comparator; + +import org.seasar.framework.exception.IORuntimeException; +import org.seasar.framework.util.FileInputStreamUtil; +import org.seasar.framework.util.FileOutputStreamUtil; +import org.seasar.framework.util.InputStreamUtil; +import org.seasar.framework.util.OutputStreamUtil; + +/** + * {@link File}に関するユーティリティクラスです。 + * + * @author taedium + */ +public class FileUtil { + + /** + * + */ + protected FileUtil() { + } + + /** + * ディレクトリをコピーします。 + * + * @param srcDir + * コピー元ディレクトリ + * @param destDir + * コピー先ディレクトリ + * @param filter + * フィルタ + */ + public static void copyDirectory(File srcDir, File destDir, + FilenameFilter filter) { + if (!srcDir.isDirectory()) { + throw new IllegalArgumentException("srcDir"); + } + if (!getCanonicalPath(srcDir).equals(getCanonicalPath(srcDir)) + && getCanonicalPath(srcDir) + .startsWith(getCanonicalPath(srcDir))) { + throw new IllegalArgumentException("destDir"); + } + copyDir(srcDir, destDir, filter); + } + + /** + * ディレクトリを再帰的にコピーします。 + * + * @param srcDir + * コピー元ディレクトリ + * @param destDir + * コピー先ディレクトリ + * @param filter + * フィルタ + */ + protected static void copyDir(File srcDir, File destDir, + FilenameFilter filter) { + destDir.mkdirs(); + File[] srcFiles = srcDir.listFiles(filter); + for (File src : srcFiles) { + File dest = new File(destDir, src.getName()); + if (src.isDirectory()) { + copyDir(src, dest, filter); + } else { + copyFile(src, dest); + } + } + } + + /** + * ファイルをコピーします。 + * + * @param src + * コピー元ファイル + * @param dest + * コピー先ファイル + */ + protected static void copyFile(File src, File dest) { + BufferedInputStream in = null; + BufferedOutputStream out = null; + try { + in = new BufferedInputStream(FileInputStreamUtil.create(src)); + out = new BufferedOutputStream(FileOutputStreamUtil.create(dest)); + byte[] buf = new byte[1024]; + int length; + while (-1 < (length = in.read(buf))) { + out.write(buf, 0, length); + out.flush(); + } + } catch (IOException e) { + throw new IORuntimeException(e); + } finally { + InputStreamUtil.close(in); + OutputStreamUtil.close(out); + } + } + + /** + * ディレクトリを削除します。 + * + * @param dir + * ディレクトリ + */ + public static void deleteDirectory(File dir) { + if (!dir.isDirectory()) { + throw new IllegalArgumentException("dir"); + } + if (!dir.exists()) { + throw new IllegalArgumentException("dir"); + } + deleteDir(dir); + } + + /** + * ディレクトリを再帰的に削除します。 + * + * @param dir + * ディレクトリ + */ + protected static void deleteDir(File dir) { + for (File file : dir.listFiles()) { + if (file.isDirectory()) { + deleteDir(file); + file.delete(); + } else { + file.delete(); + } + } + dir.delete(); + } + + /** + * この抽象パス名の正規のパス名文字列を返します。 + * + * @param file + * ファイル + * @return この抽象パス名と同じファイルまたはディレクトリを示す正規パス名文字列 + */ + public static String getCanonicalPath(File file) { + try { + return file.getCanonicalPath(); + } catch (IOException e) { + throw new IORuntimeException(e); + } + } + + /** + * この抽象パス名の正規の形式を返します。 + * + * @param file + * ファイル + * @return この抽象パス名と同じファイルまたはディレクトリを示す正規の形式 + */ + public static File getCanonicalFile(File file) { + try { + return file.getCanonicalFile(); + } catch (IOException e) { + throw new IORuntimeException(e); + } + } + + /** + * ディレクトリを横断します。 + * + * @param dir + * @param filter + * @param comparator + * @param handler + */ + public static void traverseDirectory(File dir, FilenameFilter filter, + Comparator comparator, FileHandler handler) { + if (!dir.exists()) { + return; + } + File[] files = dir.listFiles(filter); + if (files == null) { + return; + } + Arrays.sort(files, comparator); + for (File file : files) { + if (file.isDirectory()) { + traverseDirectory(file, filter, comparator, handler); + } + handler.handle(file); + } + } + + /** + * Javaファイルを作成します。 + * + * @param baseDir + * ベースディレクトリ + * @param packageName + * パッケージ名 + * @param shortClassName + * クラスの単純名 + * @return Javaファイル + */ + public static File createJavaFile(File baseDir, String packageName, + String shortClassName) { + File packageDir; + if (packageName == null) { + packageDir = baseDir; + } else { + packageDir = new File(baseDir, packageName.replace('.', + File.separatorChar)); + } + return new File(packageDir, shortClassName + ".java"); + } + + /** + * ファイルを扱うインタフェースです・ + * + * @author taedium + */ + public interface FileHandler { + + /** + * 処理します。 + * + * @param file + */ + void handle(File file); + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ReflectUtil.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ReflectUtil.java new file mode 100644 index 0000000..6622e6f --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/ReflectUtil.java @@ -0,0 +1,53 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.util; + +import org.seasar.extension.jdbc.gen.internal.exception.ClassUnmatchRuntimeException; +import org.seasar.framework.util.ClassUtil; + +/** + * リフレクションに関するユーティリティクラスです。 + * + * @author taedium + */ +public class ReflectUtil { + + /** + * + */ + protected ReflectUtil() { + } + + /** + * インスタンス化します。 + * + * @param + * 期待するクラスの型 + * @param expectedClass + * 期待するクラス + * @param className + * インスタンス化対象のクラス名 + * @return 期待するクラスのインスタンス + */ + public static T newInstance(Class expectedClass, String className) { + Class actualClass = ClassUtil.forName(className); + Object obj = ClassUtil.newInstance(actualClass); + if (expectedClass.isInstance(obj)) { + return expectedClass.cast(obj); + } + throw new ClassUnmatchRuntimeException(expectedClass, actualClass); + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/SingletonS2ContainerFactorySupport.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/SingletonS2ContainerFactorySupport.java new file mode 100644 index 0000000..a5c8070 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/internal/util/SingletonS2ContainerFactorySupport.java @@ -0,0 +1,74 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.internal.util; + +import org.seasar.framework.container.factory.SingletonS2ContainerFactory; + +/** + * {@link SingletonS2ContainerFactory}の初期化と破棄をサポートするクラスです。 + * + * @author taedium + */ +public class SingletonS2ContainerFactorySupport { + + /** 設定ファイルのパス */ + protected String configPath; + + /** 環境名 */ + protected String env; + + /** 元の環境名 */ + protected String originalEnv; + + /** 初期化された場合{@code true} */ + protected boolean initialized; + + /** + * インスタンスを構築します。 + * + * @param configPath + * 設定ファイルのパス + * @param env + * 環境名 + */ + public SingletonS2ContainerFactorySupport(String configPath, String env) { + this.configPath = configPath; + this.env = env; + } + + /** + * 初期化します。 + */ + public void init() { + if (!SingletonS2ContainerFactory.hasContainer()) { + initialized = true; + originalEnv = EnvUtil.getValue(); + EnvUtil.setValue(env); + SingletonS2ContainerFactory.setConfigPath(configPath); + SingletonS2ContainerFactory.init(); + } + } + + /** + * 破棄します。 + */ + public void destory() { + if (initialized) { + SingletonS2ContainerFactory.destroy(); + EnvUtil.setValue(originalEnv); + } + } +} diff --git a/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/task/AbstractTask.java b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/task/AbstractTask.java new file mode 100644 index 0000000..d781695 --- /dev/null +++ b/ea2ddl-common/src/main/java/org/seasar/extension/jdbc/gen/task/AbstractTask.java @@ -0,0 +1,184 @@ +/* + * Copyright 2004-2008 the Seasar Foundation and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.seasar.extension.jdbc.gen.task; + +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Environment; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; +import org.seasar.extension.jdbc.gen.command.Command; +import org.seasar.extension.jdbc.gen.command.CommandAdapter; +import org.seasar.extension.jdbc.gen.internal.arg.ArgumentsBuilder; +import org.seasar.extension.jdbc.gen.internal.command.CommandInvokerImpl; + +/** + * {@link Task}の抽象クラスです。 + * + * @author taedium + */ +public abstract class AbstractTask extends Task { + + /** JavaタスクのresultPropertyのサフィックス */ + protected static String RESULT_PROPERTY_NAME_SUFFIX = "_result"; + + /** JavaタスクのerrorPropertyのサフィックス */ + protected static String ERROR_PROPERTY_NAME_SUFFIX = "_error"; + + /** Javaタスク */ + protected Java java = new Java(); + + /** JVMのコマンドライン */ + protected Commandline jvmCommandline = new Commandline(); + + /** コマンドを呼び出すクラスの名前 */ + protected String commandInvokerClassName = CommandInvokerImpl.class + .getName(); + + /** クラスパス */ + protected Path classpath; + + /** + * JVMの引数を作成します。 + * + * @return JVMの引数 + */ + public Commandline.Argument createJvmarg() { + return jvmCommandline.createArgument(); + } + + /** + * コマンドを呼び出すクラスの名前を返します。 + * + * @return コマンドを呼び出すクラスの名前 + */ + public String getCommandInvokerClassName() { + return commandInvokerClassName; + } + + /** + * コマンドを呼び出すクラスの名前を設定します。 + * + * @param commandInvokerClassName + * コマンドを呼び出すクラスの名前 + */ + public void setCommandInvokerClassName(String commandInvokerClassName) { + this.commandInvokerClassName = commandInvokerClassName; + } + + /** + * クラスパスを設定します。 + * + * @param classpath + * クラスパス + */ + public void setClasspath(Path classpath) { + createClasspath().append(classpath); + } + + /** + * クラスパスの参照を設定します。 + * + * @param reference + * クラスパスの参照 + */ + public void setClasspathRef(Reference reference) { + createClasspath().setRefid(reference); + } + + /** + * クラスパスを作成します。 + * + * @return クラスパス + */ + public Path createClasspath() { + if (classpath == null) { + classpath = new Path(getProject()); + } + return classpath.createPath(); + } + + @Override + public void execute() throws BuildException { + if (classpath == null) { + throw new BuildException("classpath is not specified for '" + + getTaskName() + "' task"); + } + if (classpath.list().length == 0) { + throw new BuildException("classpath is empty for '" + getTaskName() + + "' task"); + } + executeCommand(); + } + + /** + * コマンドを実行します。 + */ + protected void executeCommand() { + Command command = getCommand(); + String commandName = command.getClass().getName(); + + ArgumentsBuilder builder = new ArgumentsBuilder(command); + List args = builder.build(); + + Environment.Variable commandProperty = new Environment.Variable(); + commandProperty.setKey(CommandAdapter.COMMAND_KEY); + commandProperty.setValue(commandName); + + Environment.Variable commandInvokerProperty = new Environment.Variable(); + commandInvokerProperty.setKey(CommandAdapter.COMMAND_INVOKER_KEY); + commandInvokerProperty.setValue(commandInvokerClassName); + + long time = System.currentTimeMillis(); + String resultPropertyName = commandName + time + + RESULT_PROPERTY_NAME_SUFFIX; + String errorPropertyName = commandName + time + + ERROR_PROPERTY_NAME_SUFFIX; + + java.bindToOwner(this); + java.addSysproperty(commandProperty); + java.addSysproperty(commandInvokerProperty); + for (String arg : args) { + java.createArg().setValue(arg); + } + for (String arg : jvmCommandline.getArguments()) { + java.createJvmarg().setValue(arg); + } + java.setClasspath(classpath); + java.setClassname(CommandAdapter.class.getName()); + java.setResultProperty(resultPropertyName); + java.setErrorProperty(errorPropertyName); + java.setFork(true); + java.execute(); + + String result = getProject().getProperty(resultPropertyName); + if (!"0".equals(result)) { + throw new BuildException(getProject() + .getProperty(errorPropertyName)); + } + } + + /** + * コマンドを返します。 + * + * @return コマンド + */ + protected abstract Command getCommand(); +} -- 2.11.0