@Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    ClojureMetaData metaData = deploymentUnit.getAttachment(ClojureMetaData.ATTACHMENT_KEY);

    if (metaData == null) {
      return;
    }

    Timer t = new Timer("reading full app config");
    ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    File root;
    File descriptor = deploymentUnit.getAttachment(ClojureMetaData.DESCRIPTOR_FILE);
    try {
      root = resourceRoot.getRoot().getPhysicalFile();
      metaData.setConfig(ApplicationBootstrapUtils.readFullAppConfig(descriptor, root));
      deploymentUnit.putAttachment(
          ClojureMetaData.FULL_APP_CONFIG,
          ApplicationBootstrapUtils.readFullAppConfigAsString(descriptor, root));
      deploymentUnit.putAttachment(
          ClojureMetaData.LEIN_PROJECT,
          ApplicationBootstrapUtils.readProjectAsString(descriptor, root));
    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }
    t.done();
  }
  @SuppressWarnings("unchecked")
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit unit = phaseContext.getDeploymentUnit();

    ClojureMetaData metaData = unit.getAttachment(ClojureMetaData.ATTACHMENT_KEY);
    if (metaData == null && !ArchivedDeploymentMarker.isMarked(unit)) {
      return;
    }

    File root = metaData.getRoot();

    JarMountMap mountMap = new JarMountMap();
    unit.putAttachment(JarMountMap.ATTACHMENT_KEY, mountMap);

    try {
      List<File> dependencyJars =
          ApplicationBootstrapUtils.getDependencies(
              root, metaData.resolveDependencies(), metaData.getLeinProfiles());

      boolean clojureProvided = false;

      for (File each : dependencyJars) {
        if (each.getName().matches("^clojure(-\\d.\\d.\\d)?\\.jar$")) {
          clojureProvided = true;
        }
        mount(each, unit, mountMap);
      }

      if (!clojureProvided) {
        Immutant immutant =
            (Immutant)
                phaseContext.getServiceRegistry().getService(CoreServices.IMMUTANT).getValue();

        log.warn(
            "No clojure.jar found within "
                + metaData.getApplicationName()
                + ", Using built-in clojure.jar (v"
                + immutant.getClojureVersion()
                + ")");

        // borrow the shipped clojure.jar
        String jarPath =
            System.getProperty("jboss.home.dir") + "/modules/org/immutant/core/main/clojure.jar";
        mount(new File(jarPath), unit, mountMap);
      }

      // mount the runtime jar
      String runtimePath =
          System.getProperty("jboss.home.dir")
              + "/modules/org/immutant/core/main/immutant-runtime-impl.jar";
      mount(new File(runtimePath), unit, mountMap);

      for (String each : ApplicationBootstrapUtils.resourceDirs(root, metaData.getLeinProfiles())) {
        final ResourceRoot childResource = new ResourceRoot(VFS.getChild(each), null);
        ModuleRootMarker.mark(childResource);
        unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
      }

    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }

    // disable the annotation index, since we're not an EE app and it spits nasty WARNs to the log
    // if
    // ring is included as an app dep in relation to some jetty classes
    unit.putAttachment(Attachments.COMPUTE_COMPOSITE_ANNOTATION_INDEX, false);
    // AS let's us disable the index, but then assumes it's always there, so we give it an empty one
    unit.putAttachment(
        Attachments.COMPOSITE_ANNOTATION_INDEX, new CompositeIndex(Collections.EMPTY_LIST));
  }