public void importCommandBuilders(Collection<String> importSpecs) { if (commandBuilders == Collections.EMPTY_MAP) { // intentionally effective no more than once commandBuilders = Maps.newHashMap(); if (LOG.isDebugEnabled()) { LOG.debug("Importing commands from Java classpath: {}", System.getProperty("java.class.path")); } else { LOG.info("Importing commands"); } Collection<Class<CommandBuilder>> builderClasses = getTopLevelClasses(importSpecs, CommandBuilder.class); for (Class<CommandBuilder> builderClass : builderClasses) { try { CommandBuilder builder = builderClass.newInstance(); for (String builderName : builder.getNames()) { LOG.debug("Importing command: {} from class: {}", builderName, builderClass.getName()); if (builderName.contains(".")) { LOG.warn("Command name should not contain a period character: " + builderName); } commandBuilders.put(builderName, builderClass); } } catch (Exception e) { throw new MorphlineRuntimeException(e); } } LOG.info("Done importing commands"); } }
public void importCommandBuilders(Collection<String> importSpecs) { if (commandBuilders == Collections.EMPTY_MAP) { // intentionally effective no more than once commandBuilders = Maps.newHashMap(); if (LOG.isDebugEnabled()) { LOG.debug("Importing commands from Java classpath: {}", System.getProperty("java.class.path")); } else { LOG.info("Importing commands"); } Collection<Class<CommandBuilder>> builderClasses = getTopLevelClasses(importSpecs, CommandBuilder.class); for (Class<CommandBuilder> builderClass : builderClasses) { try { CommandBuilder builder = builderClass.newInstance(); for (String builderName : builder.getNames()) { LOG.debug("Importing command: {} from class: {}", builderName, builderClass.getName()); if (builderName.contains(".")) { LOG.warn("Command name should not contain a period character: " + builderName); } commandBuilders.put(builderName, builderClass); } } catch (Exception e) { throw new MorphlineRuntimeException(e); } } LOG.info("Done importing commands"); } }
@Test @Ignore public void testHugeImportSpecs() { long start = System.currentTimeMillis(); List<String> importSpecs = Arrays.asList("com.**", "org.**", "net.*", getClass().getName()); for (Class clazz : new MorphlineContext().getTopLevelClasses(importSpecs, CommandBuilder.class)) { System.out.println("found " + clazz); } float secs = (System.currentTimeMillis() - start) / 1000.0f; System.out.println("secs=" + secs); }
@Test public void testImportSpecs() { List<String> importSpecs = Arrays.asList("org.kitesdk.**", "org.apache.solr.**", "net.*", getClass().getName()); for (Class clazz : new MorphlineContext().getTopLevelClasses(importSpecs, CommandBuilder.class)) { //System.out.println("found " + clazz); } MorphlineContext ctx = new MorphlineContext.Builder().build(); ctx.importCommandBuilders(importSpecs); ctx.importCommandBuilders(importSpecs); }
@Test public void testImportSpecsWithOnlyFQCNs() { List<String> importSpecs = Arrays.asList(getClass().getName()); for (Class clazz : new MorphlineContext().getTopLevelClasses(importSpecs, CommandBuilder.class)) { //System.out.println("found " + clazz); } MorphlineContext ctx = new MorphlineContext.Builder().build(); ctx.importCommandBuilders(importSpecs); ctx.importCommandBuilders(importSpecs); }