Beispiel #1
0
  protected void addLibEntries() throws MalformedURLException {
    final List<String> libs = new ArrayList<>();

    for (Map.Entry<String, ArtifactResult> entry : this.loadedModules.entrySet()) {
      ArtifactResult module = entry.getValue();
      if (module == null) {
        // it's an optional, missing module (likely java.*)
        continue;
      }

      final File artifact = module.artifact();
      final String moduleName = entry.getKey();

      // use "-" for the version separator
      // use ".jar" so they'll get loaded by the container classloader
      final String name =
          ModuleUtil.moduleName(moduleName) + "-" + ModuleUtil.moduleVersion(moduleName) + ".jar";
      if (name.contains("/") || name.contains("\\") || name.length() == 0) {
        throw new ToolUsageError(CeylonWarMessages.msg("module.name.illegal", name));
      }

      addSpec(new URLEntrySpec(artifact.toURI().toURL(), "WEB-INF/lib/" + name));
      libs.add(name);
    }

    // store the list of added libs so the WarInitializer knows what to copy out
    // to a repo if one has to be created
    final StringBuffer libList = new StringBuffer();
    for (String lib : libs) {
      libList.append(lib).append("\n");
    }
    addSpec(new StringEntrySpec(libList.toString(), "META-INF/libs.txt"));
  }
Beispiel #2
0
 protected void debug(String key, Object... args) {
   if (this.verbose != null && !this.verbose.equals("loader")) {
     try {
       append("Debug: ").append(CeylonWarMessages.msg(key, args)).newline();
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
 }
Beispiel #3
0
  @Override
  public void run() throws Exception {
    final String moduleName = ModuleUtil.moduleName(this.moduleNameOptVersion);
    final String moduleVersion = moduleVersion(this.moduleNameOptVersion);
    final Properties properties = new Properties();

    if (!loadModule(moduleName, moduleVersion)
        || !loadModule(WAR_MODULE, Versions.CEYLON_VERSION_NUMBER)) {
      throw new ToolUsageError(CeylonWarMessages.msg("abort.missing.modules"));
    }

    addLibEntries();

    properties.setProperty("moduleName", moduleName);
    properties.setProperty("moduleVersion", moduleVersion);

    addSpec(new PropertiesEntrySpec(properties, "META-INF/module.properties"));

    if (!addResources(entrySpecs)) {
      debug("adding.entry", "default web.xml");
      addSpec(
          new URLEntrySpec(
              CeylonWarTool.class
                  .getClassLoader()
                  .getResource("com/redhat/ceylon/tools/war/resources/default-web.xml"),
              "WEB-INF/web.xml"));
    }

    if (this.name == null) {
      this.name = String.format("%s-%s.war", moduleName, moduleVersion);
      debug("default.name", this.name);
    }

    final File jarFile =
        applyCwd(this.out == null ? new File(this.name) : new File(this.out, this.name));
    writeJarFile(jarFile);

    append(
        CeylonWarMessages.msg(
            "archive.created", moduleName, moduleVersion, jarFile.getAbsolutePath()));
    newline();
  }
Beispiel #4
0
  /**
   * Copies resources from the {@link #resourceRoot} to the WAR.
   *
   * @return true if a web.xml was added
   */
  protected boolean addResources(List<EntrySpec> entries) throws MalformedURLException {
    final File root;
    if (this.resourceRoot == null) {
      File defaultRoot = applyCwd(new File("web-content"));
      if (!defaultRoot.exists()) {
        return false;
      }
      root = defaultRoot;
    } else {
      root = applyCwd(new File(this.resourceRoot));
    }
    if (!root.exists()) {
      throw new ToolUsageError(
          CeylonWarMessages.msg("resourceRoot.missing", root.getAbsolutePath()));
    }
    if (!root.isDirectory()) {
      throw new ToolUsageError(
          CeylonWarMessages.msg("resourceRoot.nondir", root.getAbsolutePath()));
    }
    debug("adding.resources", root.getAbsolutePath());

    return addResources(root, "", entries);
  }
Beispiel #5
0
 @OptionArgument(argumentName = "moduleOrFile", shortName = 'x')
 @Description(
     "Excludes modules from the WAR file. Can be a module name or "
         + "a file containing module names. Can be specified multiple times. Note that "
         + "this excludes the module from the WAR file, but if your modules require that "
         + "module to be present at runtime it will still be required and may cause your "
         + "application to fail to start if it is not provided at runtime.")
 public void setExcludeModule(List<String> exclusions) {
   for (String each : exclusions) {
     File xFile = new File(each);
     if (xFile.exists() && xFile.isFile()) {
       try (BufferedReader reader = new BufferedReader(new FileReader(xFile))) {
         String line;
         while ((line = reader.readLine()) != null) {
           this.excludedModules.add(line);
         }
       } catch (IOException e) {
         throw new ToolUsageError(CeylonWarMessages.msg("exclude.file.failure", each), e);
       }
     } else {
       this.excludedModules.add(each);
     }
   }
 }