예제 #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"));
  }
예제 #2
0
  private void addDependenciesToAptPath(
      RepositoryManager repositoryManager,
      ModuleSpec moduleSpec,
      Set<ModuleSpec> visited,
      StatusPrinterAptProgressListener progressListener) {
    if (!visited.add(moduleSpec)) return;

    String ns = ModuleUtil.getNamespaceFromUri(moduleSpec.getName());
    String name = ModuleUtil.getModuleNameFromUri(moduleSpec.getName());
    ArtifactContext context =
        new ArtifactContext(
            ns, name, moduleSpec.getVersion(), ArtifactContext.JAR, ArtifactContext.CAR);
    if (progressListener != null) progressListener.retrievingModuleArtifact(moduleSpec, context);
    ArtifactResult result = repositoryManager.getArtifactResult(context);
    if (progressListener != null) {
      if (result == null) {
        progressListener.retrievingModuleArtifactFailed(moduleSpec, context);
      } else {
        progressListener.retrievingModuleArtifactSuccess(moduleSpec, result);
      }
    }
    ceylonEnter.addModuleToAptPath(moduleSpec, result);

    for (ArtifactResult dep : result.dependencies()) {
      if (JDKUtils.isJDKModule(dep.name()) || JDKUtils.isOracleJDKModule(dep.name())) {
        continue;
      }
      // we are running deps, so we need compile/provided/runtime, but not test
      if (dep.moduleScope() == ModuleScope.TEST) continue;
      ModuleSpec depSpec = new ModuleSpec(dep.namespace(), dep.name(), dep.version());
      addDependenciesToAptPath(repositoryManager, depSpec, visited, progressListener);
    }
  }
예제 #3
0
 private static String getVersionFromFilename(String moduleName, String name) {
   if (!ModuleUtil.isDefaultModule(moduleName)) {
     String type = ArtifactContext.getSuffixFromFilename(name);
     return name.substring(moduleName.length() + 1, name.length() - type.length());
   } else {
     return "";
   }
 }
예제 #4
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();
  }
예제 #5
0
 void loadModule(
     String name,
     String version,
     boolean optional,
     boolean inCurrentClassLoader,
     ModuleGraph.Module dependent)
     throws IOException {
   ArtifactContext artifactContext =
       new ArtifactContext(name, version, ArtifactContext.CAR, ArtifactContext.JAR);
   Overrides overrides = repositoryManager.getOverrides();
   if (overrides != null) {
     if (overrides.isRemoved(artifactContext)) return;
     ArtifactContext replacement = overrides.replace(artifactContext);
     if (replacement != null) {
       artifactContext = replacement;
       name = replacement.getName();
       version = replacement.getVersion();
     }
     if (overrides.isVersionOverridden(artifactContext)) {
       version = overrides.getVersionOverride(artifactContext);
       artifactContext.setVersion(version);
     }
   }
   // skip JDK modules
   if (JDKUtils.isJDKModule(name) || JDKUtils.isOracleJDKModule(name)) return;
   ModuleGraph.Module loadedModule = moduleGraph.findModule(name);
   if (loadedModule != null) {
     String loadedVersion = loadedModule.version;
     // we loaded the module already, but did we load it with the same version?
     if (!Objects.equals(version, loadedVersion)) {
       if (MavenVersionComparator.compareVersions(version, loadedModule.version) > 0) {
         // we want a newer version, keep going
         if (verbose) log("Replacing " + loadedModule + " with newer version " + version);
       } else {
         // we want an older version, just keep the one we have and ignore that
         addDependency(dependent, loadedModule);
         // already resolved and same version, we're good
         return;
       }
     } else if (loadedModule.artifact == null) {
       // now we're sure the version was the same
       // it was resolved to null so it was optional, but perhaps it's required now?
       if (!optional) {
         throw new ModuleNotFoundException(
             "Could not find module: " + ModuleUtil.makeModuleName(name, version));
       }
       addDependency(dependent, loadedModule);
       // already resolved and same version, we're good
       return;
     } else {
       addDependency(dependent, loadedModule);
       // already resolved and same version, we're good
       return;
     }
   }
   if (verbose) log("Resolving " + name + "/" + version);
   ArtifactResult result = repositoryManager.getArtifactResult(artifactContext);
   if (!optional
       && (result == null || result.artifact() == null || !result.artifact().exists())) {
     throw new ModuleNotFoundException(
         "Could not find module: " + ModuleUtil.makeModuleName(name, version));
   }
   // save even missing optional modules as nulls to not re-resolve them
   ModuleGraph.Module mod;
   if (dependent == null) mod = moduleGraph.addRoot(name, version);
   else mod = dependent.addDependency(name, version);
   if (loadedModule != null) loadedModule.replace(mod);
   mod.artifact = result;
   if (result != null) {
     // everything we know should be in the current class loader
     // plus everything from flat repositories
     if (inCurrentClassLoader || result.repository() instanceof FlatRepository) {
       mod.inCurrentClassLoader = true;
     }
     for (ArtifactResult dep : result.dependencies()) {
       // stop if we get removed at any point
       if (mod.replaced) break;
       loadModule(
           dep.name(),
           dep.version(),
           dep.importType() == ImportType.OPTIONAL,
           inCurrentClassLoader,
           mod);
     }
   }
 }