001package gu.sql2java.generator;
002
003import static gu.sql2java.generator.GeneratorConstants.*;
004
005import java.io.File;
006import java.util.List;
007
008import org.apache.maven.plugin.AbstractMojo;
009
010import org.apache.maven.plugin.MojoExecutionException;
011import org.apache.maven.plugin.MojoFailureException;
012import org.apache.maven.plugins.annotations.Mojo;
013import org.apache.maven.plugins.annotations.Parameter;
014
015import com.google.common.base.Joiner;
016import com.google.common.collect.Lists;
017
018/**
019 * maven 插件<br>
020 * 根据提供的配置文件,生成数据库操作代码(java),等同于执行{@link gu.sql2java.generator.Generator#main(String[])}
021 * 
022 * @author guyadong
023 *
024 */
025@Mojo(name = "generate", requiresProject = false)
026public class RunMojo extends AbstractMojo {
027        /**
028         * properties file path for configuration
029         */
030        @Parameter(property = "sql2java.propfile",required=true)
031        private File propFile;
032
033        /**
034         * class path for lookup JDBC driver,split by ';'  on Windows or ':' on Linux
035         */
036        @Parameter(property = "sql2java.classpath",defaultValue="")
037        private List<String> classpath;
038        public RunMojo() {
039        }
040
041        @Override
042        public void execute() throws MojoExecutionException, MojoFailureException {
043                List<String> args = Lists.newLinkedList();
044                args.add("--" + PROPFILE_OPTION_LONG);
045                args.add(propFile.getAbsolutePath());
046                if(!classpath.isEmpty()){
047                        args.add("--" + CLASSPATH_OPTION_LONG);
048                        args.add(Joiner.on(';').join(classpath));
049                }
050                Generator.main(args.toArray(new String[args.size()]));
051        }
052}