View Javadoc
1   package com.wakaleo.schemaspy;
2   
3   import org.schemaspy.LayoutFolder;
4   import org.schemaspy.SchemaAnalyzer;
5   import org.schemaspy.cli.CommandLineArgumentParser;
6   import org.schemaspy.cli.CommandLineArguments;
7   import org.schemaspy.input.dbms.service.DatabaseServiceFactory;
8   import org.schemaspy.input.dbms.service.SqlService;
9   import org.schemaspy.output.OutputProducer;
10  import org.schemaspy.output.xml.dom.XmlProducerUsingDOM;
11  
12  import java.io.IOException;
13  import java.sql.SQLException;
14  import java.util.List;
15  import java.util.Objects;
16  
17  /**
18   * Wrapper around the {@link SchemaAnalyzer} to hide the initialization details from the {@link SchemaSpyReport}
19   * maven mojo.
20   */
21  public class MavenSchemaAnalyzer {
22      private SchemaAnalyzer analyzer;
23  
24      private CommandLineArguments cliArgs;
25  
26      /**
27       * Adds the schemaspy plugin configuration properties. This is necessary before calling {@link #analyze()}.
28       * @param argList a list of property-value pairs.
29       */
30      public void applyConfiguration(List<String> argList) {
31          String[] args = argList.toArray(new String[0]);
32          CommandLineArgumentParser parser = new CommandLineArgumentParser(new CommandLineArguments(), null);
33          cliArgs = parser.parse(args);
34      }
35  
36      /**
37       * Executes the schemaspy analyzer process.
38       */
39      public void analyze() throws SQLException, IOException {
40          cliArgs = Objects.requireNonNull(cliArgs, "The field 'commandLineArguments' need to reference an instance. Call 'applyConfiguration(...) to initiate command line arguments");
41          SqlService sqlService = new SqlService();
42          DatabaseServiceFactory databaseServiceFactory = new DatabaseServiceFactory(sqlService);
43          OutputProducer outputProducer = new XmlProducerUsingDOM();
44          LayoutFolder layoutFolder = new LayoutFolder(SchemaAnalyzer.class.getClassLoader());
45          analyzer = new SchemaAnalyzer(sqlService, databaseServiceFactory, cliArgs, outputProducer, layoutFolder);
46          analyzer.analyze();
47      }
48  }