Ejemplo n.º 1
0
  /** @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#configureWebApplication() */
  public void configureWebApplication() throws Exception {
    super.configureWebApplication();

    // Set up the location of the webapp.
    // There are 2 parts to this: setWar() and setBaseResource(). On standalone jetty,
    // the former could be the location of a packed war, while the latter is the location
    // after any unpacking. With this mojo, you are running an unpacked, unassembled webapp,
    // so the two locations should be equal.
    Resource webAppSourceDirectoryResource =
        Resource.newResource(webAppSourceDirectory.getCanonicalPath());
    if (webApp.getWar() == null) webApp.setWar(webAppSourceDirectoryResource.toString());

    if (webApp.getBaseResource() == null) webApp.setBaseResource(webAppSourceDirectoryResource);

    if (classesDirectory != null) webApp.setClasses(classesDirectory);
    if (useTestScope && (testClassesDirectory != null)) webApp.setTestClasses(testClassesDirectory);

    webApp.setWebInfLib(getDependencyFiles());

    // get copy of a list of war artifacts
    Set<Artifact> matchedWarArtifacts = new HashSet<Artifact>();

    // make sure each of the war artifacts is added to the scanner
    for (Artifact a : getWarArtifacts()) extraScanTargets.add(a.getFile());

    // process any overlays and the war type artifacts
    List<Overlay> overlays = new ArrayList<Overlay>();
    for (OverlayConfig config : warPluginInfo.getMavenWarOverlayConfigs()) {
      // overlays can be individually skipped
      if (config.isSkip()) continue;

      // an empty overlay refers to the current project - important for ordering
      if (config.isCurrentProject()) {
        Overlay overlay = new Overlay(config, null);
        overlays.add(overlay);
        continue;
      }

      // if a war matches an overlay config
      Artifact a = getArtifactForOverlay(config, getWarArtifacts());
      if (a != null) {
        matchedWarArtifacts.add(a);
        SelectiveJarResource r =
            new SelectiveJarResource(
                new URL("jar:" + Resource.toURL(a.getFile()).toString() + "!/"));
        r.setIncludes(config.getIncludes());
        r.setExcludes(config.getExcludes());
        Overlay overlay = new Overlay(config, r);
        overlays.add(overlay);
      }
    }

    // iterate over the left over war artifacts and unpack them (without include/exclude processing)
    // as necessary
    for (Artifact a : getWarArtifacts()) {
      if (!matchedWarArtifacts.contains(a)) {
        Overlay overlay =
            new Overlay(
                null,
                Resource.newResource(
                    new URL("jar:" + Resource.toURL(a.getFile()).toString() + "!/")));
        overlays.add(overlay);
      }
    }

    webApp.setOverlays(overlays);

    // if we have not already set web.xml location, need to set one up
    if (webApp.getDescriptor() == null) {
      // Has an explicit web.xml file been configured to use?
      if (webXml != null) {
        Resource r = Resource.newResource(webXml);
        if (r.exists() && !r.isDirectory()) {
          webApp.setDescriptor(r.toString());
        }
      }

      // Still don't have a web.xml file: try the resourceBase of the webapp, if it is set
      if (webApp.getDescriptor() == null && webApp.getBaseResource() != null) {
        Resource r = webApp.getBaseResource().addPath("WEB-INF/web.xml");
        if (r.exists() && !r.isDirectory()) {
          webApp.setDescriptor(r.toString());
        }
      }

      // Still don't have a web.xml file: finally try the configured static resource directory if
      // there is one
      if (webApp.getDescriptor() == null && (webAppSourceDirectory != null)) {
        File f = new File(new File(webAppSourceDirectory, "WEB-INF"), "web.xml");
        if (f.exists() && f.isFile()) {
          webApp.setDescriptor(f.getCanonicalPath());
        }
      }
    }
    getLog().info("web.xml file = " + webApp.getDescriptor());
    getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath());
  }
Ejemplo n.º 2
0
 /** @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#execute() */
 @Override
 public void execute() throws MojoExecutionException, MojoFailureException {
   warPluginInfo = new WarPluginInfo(project);
   super.execute();
 }