Sync Integ to Master
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / cli / SpringCLITool.java
1 package org.openecomp.sdc.asdctool.cli;
2
3 import org.apache.commons.cli.Options;
4 import org.openecomp.sdc.asdctool.configuration.ConfigurationUploader;
5 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
6
7 /**
8  * abstract class to extend when implementing a spring and sdc configuration based command line tool
9  */
10 public abstract class SpringCLITool extends CLITool {
11
12     @Override
13     public CLIToolData init(String[] args) {
14         CLIToolData cliToolData = super.init(args);
15         String appConfigDir = cliToolData.getCommandLine().getOptionValue(CLIUtils.CONFIG_PATH_SHORT_OPT);
16         ConfigurationUploader.uploadConfigurationFiles(appConfigDir);
17         AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(getSpringConfigurationClass());
18         cliToolData.setSpringApplicationContext(context);
19         return cliToolData;
20     }
21
22     @Override
23     protected Options buildCmdLineOptions() {
24         return new Options().addOption(CLIUtils.getConfigurationPathOption());
25     }
26
27     /**
28      *
29      * @return the {@code Class} which holds all the spring bean declaration needed by this cli tool
30      */
31     protected abstract Class<?> getSpringConfigurationClass();
32 }