Changeset 986
- Timestamp:
- 08/31/10 21:21:38 (17 months ago)
- Location:
- AnalyzerBeans/trunk
- Files:
-
- 1 added
- 4 edited
-
pom.xml (modified) (3 diffs)
-
src/main/java/org/eobjects/analyzer/cli/Main.java (modified) (4 diffs)
-
src/main/java/org/eobjects/analyzer/descriptors/AbstractBeanDescriptor.java (modified) (2 diffs)
-
src/main/java/org/eobjects/analyzer/descriptors/ClasspathScanDescriptorProvider.java (modified) (1 diff)
-
src/main/resources/log4j.properties (added)
Legend:
- Unmodified
- Added
- Removed
-
AnalyzerBeans/trunk/pom.xml
r984 r986 6 6 <name>AnalyzerBeans</name> 7 7 <version>1.0-SNAPSHOT</version> 8 <properties> 9 <slf4j.version>1.6.1</slf4j.version> 10 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 11 </properties> 8 12 <scm> 9 13 <connection> … … 140 144 </dependency> 141 145 <dependency> 142 <groupId>org.slf4j</groupId>143 <artifactId>slf4j-api</artifactId>144 <version>1.6.1</version>145 </dependency>146 <dependency>147 146 <groupId>args4j</groupId> 148 147 <artifactId>args4j</artifactId> … … 151 150 <dependency> 152 151 <groupId>org.slf4j</groupId> 153 <artifactId>slf4j-jcl</artifactId> 154 <version>1.6.1</version> 155 <scope>test</scope> 152 <artifactId>slf4j-api</artifactId> 153 <version>${slf4j.version}</version> 154 </dependency> 155 <dependency> 156 <groupId>org.slf4j</groupId> 157 <artifactId>slf4j-log4j12</artifactId> 158 <version>${slf4j.version}</version> 159 </dependency> 160 <dependency> 161 <groupId>log4j</groupId> 162 <artifactId>log4j</artifactId> 163 <version>1.2.16</version> 156 164 </dependency> 157 165 <dependency> -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/cli/Main.java
r983 r986 2 2 3 3 import java.io.File; 4 import java.util.Collection; 4 5 import java.util.List; 6 import java.util.Set; 5 7 6 8 import org.eobjects.analyzer.configuration.AnalyzerBeansConfiguration; 7 9 import org.eobjects.analyzer.configuration.JaxbConfigurationFactory; 10 import org.eobjects.analyzer.connection.Datastore; 11 import org.eobjects.analyzer.descriptors.AnalyzerBeanDescriptor; 12 import org.eobjects.analyzer.descriptors.BeanDescriptor; 13 import org.eobjects.analyzer.descriptors.ConfiguredPropertyDescriptor; 14 import org.eobjects.analyzer.descriptors.TransformerBeanDescriptor; 8 15 import org.eobjects.analyzer.job.AnalysisJobBuilder; 9 16 import org.eobjects.analyzer.job.JaxbJobFactory; 10 import org.eobjects.analyzer.job.concurrent.TaskRunner;11 17 import org.eobjects.analyzer.job.runner.AnalysisRunnerImpl; 12 18 import org.eobjects.analyzer.result.AnalyzerResult; … … 14 20 import org.kohsuke.args4j.CmdLineParser; 15 21 import org.kohsuke.args4j.Option; 22 import org.slf4j.Logger; 23 import org.slf4j.LoggerFactory; 24 25 import dk.eobjects.metamodel.DataContext; 26 import dk.eobjects.metamodel.schema.Schema; 27 import dk.eobjects.metamodel.schema.Table; 16 28 17 29 public final class Main { 18 30 19 @Option(name = "-job", usage = "XML file describing the analysis job", required = true) 31 public static enum ListType { 32 ANALYZERS, TRANSFORMERS, DATASTORES, SCHEMAS, TABLES, COLUMNS 33 } 34 35 private final static Logger logger = LoggerFactory.getLogger(Main.class); 36 37 @Option(name = "-conf", aliases = { "-configuration", 38 "--configuration-file" }, usage = "XML file describing the configuration of AnalyzerBeans", required = true) 39 private File configurationFile; 40 41 @Option(name = "-job", aliases = { "--job-file" }, usage = "An analysis job XML file to execute") 20 42 private File jobFile; 21 43 22 @Option(name = "-configuration", usage = "XML file describing the configuration of AnalyzerBeans", required = true) 23 private File configurationFile; 44 @Option(name = "-list", usage = "Used to print a list of various elements available in the configuration") 45 private ListType listType; 46 47 @Option(name = "-ds", aliases = { "-datastore", "--datastore-name" }, usage = "Name of datastore when printing a list of schemas, tables or columns") 48 private String datastoreName; 49 50 @Option(name = "-s", aliases = { "-schema", "--schema-name" }, usage = "Name of schema when printing a list of tables or columns") 51 private String schemaName; 52 53 @Option(name = "-t", aliases = { "-table", "--table-name" }, usage = "Name of table when printing a list of columns") 54 private String tableName; 24 55 25 56 public static void main(String[] args) { … … 30 61 main.run(); 31 62 } catch (CmdLineException e) { 32 e.printStackTrace();63 parser.setUsageWidth(120); 33 64 parser.printUsage(System.out); 34 65 } … … 39 70 .create(configurationFile); 40 71 try { 41 AnalysisJobBuilder analysisJobBuilder = new JaxbJobFactory( 42 configuration).create(jobFile); 43 44 List<AnalyzerResult> results = new AnalysisRunnerImpl(configuration) 45 .run(analysisJobBuilder.toAnalysisJob()).getResults(); 46 47 for (AnalyzerResult analyzerResult : results) { 48 System.out.println("\nRESULT:"); 49 System.out.println(analyzerResult); 50 } 72 if (jobFile != null) { 73 runJob(configuration); 74 } else if (listType != null) { 75 switch (listType) { 76 case ANALYZERS: 77 printAnalyzers(configuration); 78 break; 79 case TRANSFORMERS: 80 printTransformers(configuration); 81 break; 82 case DATASTORES: 83 printDatastores(configuration); 84 break; 85 case SCHEMAS: 86 printSchemas(configuration); 87 break; 88 case TABLES: 89 printTables(configuration); 90 break; 91 case COLUMNS: 92 printColumns(configuration); 93 break; 94 default: 95 throw new IllegalArgumentException("Unknown list type: " 96 + listType); 97 } 98 } else { 99 throw new IllegalArgumentException( 100 "Neither --job-file nor --list-type is specified. Try running with -usage to see usage help."); 101 } 102 } catch (Exception e) { 103 logger.error("Exception thrown in {}", e, this); 104 System.err.println("Error: " + e.getMessage()); 51 105 } finally { 52 TaskRunner taskRunner = configuration.getTaskRunner(); 53 taskRunner.shutdown(); 54 } 106 configuration.getTaskRunner().shutdown(); 107 } 108 } 109 110 private void printColumns(AnalyzerBeansConfiguration configuration) { 111 if (datastoreName == null) { 112 System.err.println("You need to specify the datastore name!"); 113 } else if (tableName == null) { 114 System.err.println("You need to specify a table name!"); 115 } else { 116 Datastore ds = configuration.getDatastoreCatalog().getDatastore( 117 datastoreName); 118 if (ds == null) { 119 System.err.println("No such datastore: " + datastoreName); 120 } else { 121 DataContext dc = ds.getDataContextProvider().getDataContext(); 122 Schema schema; 123 if (schemaName == null) { 124 schema = dc.getDefaultSchema(); 125 } else { 126 schema = dc.getSchemaByName(schemaName); 127 } 128 if (schema == null) { 129 System.err.println("No such schema: " + schemaName); 130 } else { 131 Table table = schema.getTableByName(tableName); 132 if (table == null) { 133 System.out.println("No such table: " + tableName); 134 } else { 135 String[] columnNames = table.getColumnNames(); 136 System.out.println("Columns:"); 137 System.out.println("--------"); 138 for (String columnName : columnNames) { 139 System.out.println(columnName); 140 } 141 } 142 } 143 } 144 } 145 } 146 147 private void printTables(AnalyzerBeansConfiguration configuration) { 148 if (datastoreName == null) { 149 System.err.println("You need to specify the datastore name!"); 150 } else { 151 Datastore ds = configuration.getDatastoreCatalog().getDatastore( 152 datastoreName); 153 if (ds == null) { 154 System.err.println("No such datastore: " + datastoreName); 155 } else { 156 DataContext dc = ds.getDataContextProvider().getDataContext(); 157 Schema schema; 158 if (schemaName == null) { 159 schema = dc.getDefaultSchema(); 160 } else { 161 schema = dc.getSchemaByName(schemaName); 162 } 163 if (schema == null) { 164 System.err.println("No such schema: " + schemaName); 165 } else { 166 String[] tableNames = schema.getTableNames(); 167 if (tableNames == null || tableNames.length == 0) { 168 System.err.println("No tables in schema!"); 169 } else { 170 System.out.println("Tables:"); 171 System.out.println("-------"); 172 for (String tableName : tableNames) { 173 System.out.println(tableName); 174 } 175 } 176 } 177 } 178 } 179 } 180 181 private void printSchemas(AnalyzerBeansConfiguration configuration) { 182 if (datastoreName == null) { 183 System.err.println("You need to specify the datastore name!"); 184 } else { 185 Datastore ds = configuration.getDatastoreCatalog().getDatastore( 186 datastoreName); 187 if (ds == null) { 188 System.err.println("No such datastore: " + datastoreName); 189 } else { 190 String[] schemaNames = ds.getDataContextProvider() 191 .getDataContext().getSchemaNames(); 192 if (schemaNames == null || schemaNames.length == 0) { 193 System.out.println("No schemas in datastore!"); 194 } else { 195 System.out.println("Schemas:"); 196 System.out.println("--------"); 197 for (String schemaName : schemaNames) { 198 System.out.println(schemaName); 199 } 200 } 201 } 202 } 203 } 204 205 private void printDatastores(AnalyzerBeansConfiguration configuration) { 206 String[] datastoreNames = configuration.getDatastoreCatalog() 207 .getDatastoreNames(); 208 if (datastoreNames == null || datastoreNames.length == 0) { 209 System.out.println("No datastores configured!"); 210 } else { 211 System.out.println("Datastores:"); 212 System.out.println("-----------"); 213 for (String datastoreName : datastoreNames) { 214 System.out.println(datastoreName); 215 } 216 } 217 } 218 219 protected void runJob(AnalyzerBeansConfiguration configuration) { 220 AnalysisJobBuilder analysisJobBuilder = new JaxbJobFactory( 221 configuration).create(jobFile); 222 223 List<AnalyzerResult> results = new AnalysisRunnerImpl(configuration) 224 .run(analysisJobBuilder.toAnalysisJob()).getResults(); 225 226 for (AnalyzerResult analyzerResult : results) { 227 System.out.println("\nRESULT:"); 228 System.out.println(analyzerResult); 229 } 230 } 231 232 protected void printAnalyzers(AnalyzerBeansConfiguration configuration) { 233 Collection<AnalyzerBeanDescriptor<?>> descriptors = configuration 234 .getDescriptorProvider().getAnalyzerBeanDescriptors(); 235 if (descriptors == null || descriptors.isEmpty()) { 236 System.out.println("No analyzers configured!"); 237 } else { 238 System.out.println("Analyzers:"); 239 System.out.println("----------"); 240 printBeanDescriptors(descriptors); 241 } 242 } 243 244 private void printTransformers(AnalyzerBeansConfiguration configuration) { 245 Collection<TransformerBeanDescriptor<?>> descriptors = configuration 246 .getDescriptorProvider().getTransformerBeanDescriptors(); 247 if (descriptors == null || descriptors.isEmpty()) { 248 System.out.println("No transformers configured!"); 249 } else { 250 System.out.println("Transformers:"); 251 System.out.println("-------------"); 252 printBeanDescriptors(descriptors); 253 } 254 } 255 256 protected void printBeanDescriptors( 257 Collection<? extends BeanDescriptor<?>> descriptors) { 258 for (BeanDescriptor<?> descriptor : descriptors) { 259 System.out.println("name: " + descriptor.getDisplayName()); 260 ConfiguredPropertyDescriptor propertyForInput = descriptor 261 .getConfiguredPropertyForInput(); 262 if (propertyForInput != null) { 263 if (propertyForInput.isArray()) { 264 System.out.println(" - Consumes multiple input columns"); 265 } else { 266 System.out.println(" - Consumes a single input column"); 267 } 268 } 269 Set<ConfiguredPropertyDescriptor> properties = descriptor 270 .getConfiguredProperties(); 271 for (ConfiguredPropertyDescriptor property : properties) { 272 if (property != propertyForInput) { 273 System.out.println(" - Property: name=" 274 + property.getName() + ", type=" 275 + property.getBaseType().getSimpleName() 276 + ", required=" + property.isRequired()); 277 } 278 } 279 } 280 } 281 282 @Override 283 public String toString() { 284 return "Main[configurationFile=" 285 + (configurationFile == null ? "null" : configurationFile 286 .getName()) + ", jobFile=" 287 + (jobFile == null ? "null" : jobFile.getName()) 288 + ", listType=" + listType + ", datastoreName=" + datastoreName 289 + ", schemaName=" + schemaName + ", tableName=" + tableName 290 + "]"; 55 291 } 56 292 } -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/descriptors/AbstractBeanDescriptor.java
r975 r986 63 63 if (configuredAnnotation != null) { 64 64 if (!field.isAnnotationPresent(Inject.class)) { 65 logger. warn(65 logger.info( 66 66 "No @Inject annotation found for @Configured field: {}", 67 67 field); … … 73 73 if (providedAnnotation != null) { 74 74 if (!field.isAnnotationPresent(Inject.class)) { 75 logger. warn(75 logger.info( 76 76 "No @Inject annotation found for @Provided field: {}", 77 77 field); -
AnalyzerBeans/trunk/src/main/java/org/eobjects/analyzer/descriptors/ClasspathScanDescriptorProvider.java
r982 r986 93 93 scanInputStream(inputStream); 94 94 } else { 95 logger. info("Omitting recursive JAR file entry: {}",95 logger.debug("Omitting recursive JAR file entry: {}", 96 96 entryName); 97 97 } 98 98 } 99 99 } else { 100 logger. info("Omitting JAR file entry: {}", entryName);100 logger.debug("Omitting JAR file entry: {}", entryName); 101 101 } 102 102 }
Note: See TracChangeset
for help on using the changeset viewer.
