private Configuration buildConfiguration(
      final ExporterAttributes attributes, ConsoleConfiguration cc, IWorkspaceRoot root) {
    final boolean reveng = attributes.isReverseEngineer();
    final String reverseEngineeringStrategy = attributes.getRevengStrategy();
    final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
    final IResource revengres = PathHelper.findMember(root, attributes.getRevengSettings());

    if (reveng) {
      Configuration configuration = null;
      if (cc.hasConfiguration()) {
        configuration = cc.getConfiguration();
      } else {
        configuration = cc.buildWith(null, false);
      }

      final JDBCMetaDataConfiguration cfg = new JDBCMetaDataConfiguration();
      Properties properties = configuration.getProperties();
      cfg.setProperties(properties);
      cc.buildWith(cfg, false);

      cfg.setPreferBasicCompositeIds(preferBasicCompositeids);

      cc.execute(
          new Command() { // need to execute in the consoleconfiguration to let it handle classpath
                          // stuff!

            public Object execute() {
              // todo: factor this setup of revengstrategy to core
              ReverseEngineeringStrategy res = new DefaultReverseEngineeringStrategy();

              OverrideRepository repository = null;

              if (revengres != null) {
                File file = PathHelper.getLocation(revengres).toFile();
                repository = new OverrideRepository();
                repository.addFile(file);
              }

              if (repository != null) {
                res = repository.getReverseEngineeringStrategy(res);
              }

              if (reverseEngineeringStrategy != null
                  && reverseEngineeringStrategy.trim().length() > 0) {
                res = loadreverseEngineeringStrategy(reverseEngineeringStrategy, res);
              }

              ReverseEngineeringSettings qqsettings =
                  new ReverseEngineeringSettings(res)
                      .setDefaultPackageName(attributes.getPackageName())
                      .setDetectManyToMany(attributes.detectManyToMany())
                      .setDetectOneToOne(attributes.detectOneToOne())
                      .setDetectOptimisticLock(attributes.detectOptimisticLock());

              res.setSettings(qqsettings);

              cfg.setReverseEngineeringStrategy(res);

              cfg.readFromJDBC();
              cfg.buildMappings();
              return null;
            }
          });

      return cfg;
    } else {
      cc.build();
      cc.buildMappings();
      return cc.getConfiguration();
    }
  }
  private ArtifactCollector runExporters(
      final ExporterAttributes attributes,
      final ExporterFactory[] exporterFactories,
      final Set<String> outputDirectories,
      final IProgressMonitor monitor)
      throws CoreException {

    monitor.beginTask(
        HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for
            + attributes.getConsoleConfigurationName(),
        exporterFactories.length + 1);

    if (monitor.isCanceled()) return null;

    ConsoleConfiguration cc =
        KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    if (attributes.isReverseEngineer()) {
      monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
    }
    final Configuration cfg =
        buildConfiguration(attributes, cc, ResourcesPlugin.getWorkspace().getRoot());

    monitor.worked(1);

    if (monitor.isCanceled()) return null;

    return (ArtifactCollector)
        cc.execute(
            new Command() {

              public Object execute() {
                ArtifactCollector artifactCollector = new ArtifactCollector();

                // Global properties
                Properties props = new Properties();
                props.put(
                    CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled()); // $NON-NLS-1$
                props.put(
                    CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled()); // $NON-NLS-1$

                for (int i = 0; i < exporterFactories.length; i++) {
                  monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());

                  Properties globalProperties = new Properties();
                  globalProperties.putAll(props);

                  Exporter exporter;
                  try {
                    exporter =
                        exporterFactories[i].createConfiguredExporter(
                            cfg,
                            attributes.getOutputPath(),
                            attributes.getTemplatePath(),
                            globalProperties,
                            outputDirectories,
                            artifactCollector);
                  } catch (CoreException e) {
                    throw new HibernateConsoleRuntimeException(
                        HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up
                            + exporterFactories[i].getExporterDefinition(),
                        e);
                  }

                  try {
                    exporter.start();
                  } catch (HibernateException he) {
                    throw new HibernateConsoleRuntimeException(
                        HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running
                            + exporterFactories[i].getExporterDefinition().getDescription(),
                        he);
                  }
                  monitor.worked(1);
                }
                return artifactCollector;
              }
            });
  }