public void testSimpleEar() throws Exception {
   System.setProperty("java.naming.factory.initial", MockInitialContextFactory.class.getName());
   VirtualFile ear = VFS.getChild("multiplefiles-top-level.ear");
   createAssembledDirectory(ear).addPath("multiplefiles");
   VFSDeploymentUnit unit = assertDeploy(ear);
   assertNotNull(NonSerializableFactory.lookup("TestContext1"));
   assertNotNull(NonSerializableFactory.lookup("TestContext2"));
   undeploy(unit);
   assertNull(NonSerializableFactory.lookup("TestContext1"));
   assertNull(NonSerializableFactory.lookup("TestContext2"));
 }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (deploymentUnit.hasAttachment(ClojureMetaData.ATTACHMENT_KEY)) {
      return;
    }

    Timer t = new Timer("parsing deployment descriptor");
    String deploymentName = deploymentUnit.getName();

    try {
      VirtualFile descriptor = getDescriptorFile(deploymentUnit);
      if (descriptor == null) {
        return;
      }

      ClojureMetaData appMetaData =
          new ClojureMetaData(deploymentName, ClojureMetaData.parse(descriptor.getPhysicalFile()));

      appMetaData.attachTo(deploymentUnit);

      File root = appMetaData.getRoot();

      if (root == null) {
        throw new DeploymentUnitProcessingException("No application root specified.");
      }

      if (!root.exists()) {
        throw new DeploymentUnitProcessingException(
            "Application root does not exist: " + root.getAbsolutePath());
      }

      VirtualFile virtualRoot = VFS.getChild(root.toURI());
      MountHandle mountHandle = null;

      if (!root.isDirectory()) {
        // Expand the referenced root if it's not a directory (ie .ima archive)
        mountHandle =
            new MountHandle(
                VFS.mountZipExpanded(virtualRoot, virtualRoot, TempFileProviderService.provider()));
      }

      deploymentUnit.putAttachment(
          Attachments.DEPLOYMENT_ROOT, new ResourceRoot(virtualRoot, mountHandle));
      deploymentUnit.putAttachment(ClojureMetaData.DESCRIPTOR_FILE, descriptor.getPhysicalFile());

    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }
    t.done();
  }
  private void mount(File file, DeploymentUnit unit, JarMountMap mountMap) throws IOException {
    VirtualFile mountPath =
        VFS.getChild(File.createTempFile(file.getName(), ".jar", tmpMountDir(unit)).toURI());
    log.debug(unit.getName() + ": mounting " + file);
    final ResourceRoot childResource =
        new ResourceRoot(
            mountPath,
            new MountHandle(VFS.mountZip(file, mountPath, TempFileProviderService.provider())));
    ModuleRootMarker.mark(childResource);
    unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);

    mountMap.put(mountPath.toURL().toExternalForm(), file.toURI().toURL().toExternalForm());
  }
Exemplo n.º 4
0
  public void setRoot(String path) {
    if (path != null) {
      String sanitizedPath = null;

      if (path.indexOf("\\\\") >= 0) {
        sanitizedPath = path.replaceAll("\\\\\\\\", "/");
        sanitizedPath = sanitizedPath.replaceAll("\\\\", "");
      } else {
        sanitizedPath = path.replaceAll("\\\\", "/");
      }
      VirtualFile root = VFS.getChild(sanitizedPath);
      setRoot(root);
    }
  }
Exemplo n.º 5
0
  /** {@inheritDoc} */
  public Collection<String> getPaths() {
    final List<String> index = new ArrayList<String>();
    // First check for an index file
    final VirtualFile indexFile = VFS.getChild(root.getPathName() + ".index");
    if (indexFile.exists()) {
      try {
        final BufferedReader r = new BufferedReader(new InputStreamReader(indexFile.openStream()));
        try {
          String s;
          while ((s = r.readLine()) != null) {
            index.add(s.trim());
          }
          return index;
        } finally {
          // if exception is thrown, undo index creation
          r.close();
        }
      } catch (IOException e) {
        index.clear();
      }
    }

    FilterVirtualFileVisitor visitor =
        new FilterVirtualFileVisitor(
            new VirtualFileFilter() {
              @Override
              public boolean accepts(VirtualFile file) {
                return file.isDirectory();
              }
            },
            VisitorAttributes.RECURSE);
    try {
      root.visit(visitor);
    } catch (IOException e) {
      index.clear();
    }

    index.add("");
    for (VirtualFile dir : visitor.getMatched()) {
      index.add(dir.getPathNameRelativeTo(root));
    }

    return index;
  }
  @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));
  }
Exemplo n.º 7
0
 @Override
 public VirtualFile getContent(byte[] hash) {
   if (hash == null) throw DeploymentRepositoryMessages.MESSAGES.nullVar("hash");
   return VFS.getChild(getDeploymentContentFile(hash, true).toURI());
 }