Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[wtp-dev] Re: WTP modules, facets and extensability

Gunnar Wagenknecht wrote:
> Naci Dai wrote:
>> *<wb-resource source-path="/JUPWebContent" deploy-path="/"/>*
> 
> Can anybody give me a good reference which API I should use to add such
> an entry to the ".component" file of a project?

I found some useful snippets in WebFacetInstallDelegate and
WebLibDependencyPropertiesPage. I could manage to work with public API
except for one tiny little constant.

VirtualArchiveComponent.VARARCHIVETYPE

Is there a constant in an public API package available? Should I create
the constant myself? If yes then the value must be documented somewhere.
I couldn't find the doc.

Anyway, here is the code snippet just for the archive and the search
engine. ;)

--snip--
final IProject project = ...;
final IPath deployPath = ...;
final IPath outputPath = ...;
WorkspaceJob updateFlexProjectJob =
  new WorkspaceJob("Configuring Web Project...") {

  @Override
  public IStatus runInWorkspace(IProgressMonitor monitor)
         throws CoreException {
    monitor = ProgressUtil.monitor(monitor);
    try {
      monitor.beginTask(
        NLS.bind("Configuring Web Project {0}", project.getName()),
        10);

      // get the flex project component
      final IVirtualComponent flexProject =
        ComponentCore.createComponent(project);
      if (!flexProject.exists())
        flexProject.create(IResource.FORCE, null);

      // link the deployment folder to the build output folder
      final IVirtualFolder deployFolder =
        flexProject.getRootFolder().getFolder(deployPath);
      if(deployFolder.exists())
        deployFolder.delete(
          IResource.FORCE,
          ProgressUtil.subProgressMonitor(monitor, 1));
      deployFolder.createLink(
          outputPath,
          IResource.FORCE,
          ProgressUtil.subProgressMonitor(monitor, 1));

      // get current references
      List<IVirtualReference> references =
        new ArrayList<IVirtualReference>();
      IVirtualReference[] currentReferences =
        flexProject.getReferences();
      for (IVirtualReference reference : currentReferences) {
        references.add(reference);
      }

      // gwt-user.jar
      String type = VirtualArchiveComponent.VARARCHIVETYPE
        + IPath.SEPARATOR;
      IVirtualComponent archive =
        ComponentCore.createArchiveComponent(
          project,
          type + Util.getGwtUserLibPath().toString());
      IVirtualReference gwtUserJarReference =
        ComponentCore.createReference(
          flexProject,
          archive,
          new Path("/WEB-INF/lib"));
      if(!references.contains(gwtUserJarReference))
        references.add(gwtUserJarReference);

      // apply references
      flexProject.setReferences(
        references.toArray(new IVirtualReference[references.size()]));
    } finally {
      monitor.done();
    }

    return Status.OK_STATUS;
  }
flexProjectJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().createRule(project));
flexProjectJob.setUser(true);
flexProjectJob.schedule();
--/snip--

Cu, Gunnar

-- 
Gunnar Wagenknecht
gunnar@xxxxxxxxxxxxxxx
http://wagenknecht.org/



Back to the top