Esempio n. 1
0
  /** Executes the task. */
  public void execute() throws BuildException {
    checkParameters();

    reportFilesMap = new HashMap<String, String>();

    AntClassLoader classLoader = null;
    if (classpath != null) {
      jasperReportsContext.setProperty(
          JRCompiler.COMPILER_CLASSPATH,
          String.valueOf(classpath)); // FIXMECONTEXT is this needed? what about class loader below/

      ClassLoader parentClassLoader = getClass().getClassLoader();
      classLoader = new AntClassLoader(parentClassLoader, getProject(), classpath, true);
      classLoader.setThreadContextLoader();
    }

    try {
      /*   */
      scanSrc();
      /*   */
      decompile();
    } finally {
      if (classLoader != null) {
        classLoader.resetThreadContextLoader();
      }
    }
  }
Esempio n. 2
0
  public Runnable createTargetInstance(Target target, Properties localProperties, Logger logger) {
    //        System.out.println("DefaultProjectModel.createTargetInstance");
    AntClassLoader loader = null;
    DefaultResources resources;

    try {
      org.apache.tools.ant.types.Path classPath = toAntPath(resolvePathGroup(target, "classpath"));

      // Allow additional classes to added to the plugin classpath. This is primarily designed to
      // allow the additional of instrumented testing classes and libraries for code coverage of
      // integration
      // tests with Cobertura
      String key = "quokka.classpath." + target.getPlugin().getArtifact().getId().getGroup();

      if (log.isDebugEnabled()) {
        log.debug("Searching for additional classpath with key: " + key);
      }

      String additionalPath = System.getProperty(key);

      if ((additionalPath != null) && !additionalPath.trim().equals("")) {
        org.apache.tools.ant.types.Path existing = classPath;
        classPath = new org.apache.tools.ant.types.Path(antProject, additionalPath);
        log.verbose("Prefixing classpath with: " + classPath);
        classPath.append(existing); // Make sure additions override existing
      }

      if ("true".equals(antProject.getProperty("quokka.project.debugclassloaders"))) {
        loader =
            new QuokkaLoader(target, antProject.getClass().getClassLoader(), antProject, classPath);
      } else {
        loader = antProject.createClassLoader(classPath);
      }

      loader.setParent(antProject.getCoreLoader());
      loader.setParentFirst(true);
      loader.setIsolated(false);
      loader.setThreadContextLoader();

      // Initialise this plugin
      Plugin plugin = target.getPlugin();
      loader.forceLoadClass(plugin.getClassName());

      Class pluginClass = Class.forName(plugin.getClassName(), true, loader);
      ws.quokka.core.plugin_spi.Plugin actualPlugin =
          (ws.quokka.core.plugin_spi.Plugin) pluginClass.newInstance();

      if (actualPlugin instanceof MetadataAware) {
        ((MetadataAware) actualPlugin).setMetadata(getMetadata());
      }

      if (actualPlugin instanceof ResourcesAware) {
        resources = new DefaultResources(this, target, antProject, logger);
        ((ResourcesAware) actualPlugin).setResources(resources);
      }

      if (actualPlugin instanceof RepositoryAware) {
        ((RepositoryAware) actualPlugin).setRepository(getRepository());
      }

      if (actualPlugin instanceof RepositoryFactoryAware) {
        ((RepositoryFactoryAware) actualPlugin)
            .setRepositoryFactory(
                (RepositoryFactory) antProject.getReference(ProjectHelper.REPOSITORY_FACTORY));
      }

      if (actualPlugin instanceof ResolverAware) {
        ((ResolverAware) actualPlugin).setResolver(pathResolver);
      }

      if (actualPlugin instanceof ModelFactoryAware) {
        ((ModelFactoryAware) actualPlugin).setModelFactory(getModelFactory());
      }

      actualPlugin.initialise();

      return actualPlugin.getTarget(
          (target.getTemplateName() != null) ? target.getTemplateName() : target.getName());
    } catch (Exception e) {
      throw new BuildException(e);
    } finally {
      if (loader != null) {
        loader.resetThreadContextLoader();
        loader.cleanup();
      }
    }
  }
  public void execute() {
    AntClassLoader loader;
    MergeFileSystemAndClassPathXMLApplicationContext mergeContext;
    try {
      ConfigurationOnlyState state = new ConfigurationOnlyState();
      state.setConfigurationOnly(true);
      ConfigurationOnlyState.setState(state);

      loader = getProject().createClassLoader(classPath);
      ClassLoader classLoader = this.getClass().getClassLoader();
      loader.setParent(
          classLoader); // if this is not set, classes from the taskdef cannot be found - which is
                        // crucial for e.g. annotations.
      loader.setThreadContextLoader();
      // launch the service merge application context to get the entity configuration for the entire
      // framework
      String[] contexts =
          StandardConfigLocations.retrieveAll(StandardConfigLocations.TESTCONTEXTTYPE);
      String[] otherContexts = new String[classPathApplicationContexts.size()];
      for (int j = 0; j < otherContexts.length; j++) {
        otherContexts[j] = classPathApplicationContexts.get(j).getPath();
      }
      contexts = (String[]) ArrayUtils.addAll(contexts, otherContexts);

      String[] fileSystemItems = new String[fileSystemApplicationContexts.size()];
      for (int j = 0; j < fileSystemItems.length; j++) {
        fileSystemItems[j] = fileSystemApplicationContexts.get(j).getPath();
      }
      mergeContext =
          new MergeFileSystemAndClassPathXMLApplicationContext(contexts, fileSystemItems);
    } catch (Exception e) {
      throw new BuildException(e, getLocation());
    } finally {
      ConfigurationOnlyState.setState(null);
    }
    int count = 1;
    ExporterTask generatorTask = null;
    try {
      for (Object configuration : configurationTasks) {
        JPAConfigurationTask configurationTask = (JPAConfigurationTask) configuration;
        log("Executing Hibernate Tool with a " + configurationTask.getDescription());
        @SuppressWarnings("rawtypes")
        Iterator iterator = generators.iterator();
        while (iterator.hasNext()) {
          generatorTask = (ExporterTask) iterator.next();
          log(count++ + ". task: " + generatorTask.getName());
          generatorTask.setOutputFileName(
              configurationTask.getDialect()
                  + "_"
                  + configurationTask.getPersistenceUnit()
                  + ".sql");
          generatorTask.setDestdir(destDir);
          generatorTask.setConfiguration(configurationTask.createConfiguration(mergeContext));
          generatorTask.execute();
        }
      }
    } catch (RuntimeException re) {
      reportException(re, count, generatorTask);
    } finally {
      if (loader != null) {
        loader.resetThreadContextLoader();
        loader.cleanup();
      }
    }
    try {
      if (combinePersistenceUnits) {
        ArrayList<File> combine = new ArrayList<File>();
        for (Object configuration : configurationTasks) {
          JPAConfigurationTask configurationTask = (JPAConfigurationTask) configuration;
          File[] sqlFiles = destDir.listFiles(new SqlFileFilter());
          for (File file : sqlFiles) {
            if (file.getName().startsWith(configurationTask.getDialect())) {
              combine.add(file);
            }
          }
          combineFiles(combine);
          combine.clear();
        }
      }
      if (refineFileNames) {
        File[] sqlFiles = destDir.listFiles(new SqlFileFilter());
        for (File file : sqlFiles) {
          String filename = file.getName();
          String[] starters = {"org.hibernate.dialect.", "org.broadleafcommerce.profile.util.sql."};
          for (String starter : starters) {
            if (filename.startsWith(starter)) {
              String newFileName = filename.substring(starter.length(), filename.length());
              file.renameTo(new File(destDir, newFileName));
            }
          }
        }
      }
    } catch (Exception e) {
      throw new BuildException(e, getLocation());
    }
  }