1   package com.atlassian.maven.plugins.amps.codegen.prompter;
2   
3   import com.atlassian.maven.plugins.amps.codegen.annotations.asm.ModulePrompterAnnotationParser;
4   
5   import org.apache.commons.lang.StringUtils;
6   import org.apache.maven.plugin.logging.Log;
7   import org.codehaus.plexus.components.interactivity.Prompter;
8   
9   /**
10   * @since 3.5
11   */
12  public class PluginModulePrompterFactoryImpl implements PluginModulePrompterFactory
13  {
14      private final PluginModulePrompterRegistry prompterRegistry;
15      private final ModulePrompterAnnotationParser annotationParser;
16      private String basePackage;
17  
18      //injected by plexus
19      private Prompter prompter;
20  
21      private Log log;
22  
23      public PluginModulePrompterFactoryImpl() throws Exception
24      {
25          this("");
26      }
27  
28      public PluginModulePrompterFactoryImpl(String basePackage) throws Exception
29      {
30          this.prompterRegistry = new PluginModulePrompterRegistryImpl();
31          this.annotationParser = new ModulePrompterAnnotationParser(prompterRegistry);
32          this.basePackage = basePackage;
33  
34      }
35  
36      @Override
37      public void scanForPrompters() throws Exception
38      {
39          annotationParser.setLog(getLog());
40          annotationParser.setMavenPrompter(prompter);
41          doParse(basePackage);
42      }
43  
44      @Override
45      public PluginModulePrompter getPrompterForCreatorClass(Class clazz)
46      {
47          return prompterRegistry.getPrompterForCreatorClass(clazz);
48      }
49  
50      private void doParse(String packageName) throws Exception
51      {
52          if (StringUtils.isBlank(packageName))
53          {
54              annotationParser.parse();
55          } else
56          {
57              annotationParser.parse(packageName);
58          }
59      }
60  
61      public Log getLog()
62      {
63          return log;
64      }
65  
66      public void setLog(Log log)
67      {
68          this.log = log;
69      }
70  }