<commit_before>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach.task;

import de.sormuras.bach.Project;
import de.sormuras.bach.Task;
import java.lang.System.Logger.Level;

/** Print information about all compiled modules. */
public /*static*/ class PrintModules extends Task {

  private final Project project;

  public PrintModules(Project project) {
    super("Print modules");
    this.project = project;
  }

  @Override
  public void execute(Execution execution) {
    var workspace = execution.getBach().getWorkspace();
    var realm = project.structure().toMainRealm().orElseThrow();
    for (var unit : realm.units()) {
      var jar = workspace.module(realm.name(), unit.name(), project.toModuleVersion(unit));
      var nameAndVersion = unit.descriptor().toNameAndVersion();
      execution.print(Level.INFO, "Module " + nameAndVersion, "\t-> " + jar.toUri());
    }
  }
}<commit_msg>Describe compiled modules using jar tool<commit_after>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach.task;

import de.sormuras.bach.Project;
import de.sormuras.bach.Task;
import java.io.PrintWriter;
import java.lang.System.Logger.Level;
import java.nio.file.Files;
import java.util.spi.ToolProvider;

/** Print information about all compiled modules. */
public /*static*/ class PrintModules extends Task {

  private final Project project;

  public PrintModules(Project project) {
    super("Print modules");
    this.project = project;
  }

  @Override
  public void execute(Execution execution) throws Exception {
    var workspace = execution.getBach().getWorkspace();
    var realm = project.structure().toMainRealm().orElseThrow();
    for (var unit : realm.units()) {
      var jar = workspace.module(realm.name(), unit.name(), project.toModuleVersion(unit));
      execution.print(Level.INFO, "file: " + jar.getFileName());
      execution.print(Level.INFO, "size: " + Files.size(jar));
      var out = execution.getOut();
      var err = execution.getErr();
      ToolProvider.findFirst("jar")
          .orElseThrow()
          .run(
              new PrintWriter(out),
              new PrintWriter(err),
              "--describe-module",
              "--file",
              jar.toString());
    }
  }
}
{'fraction_non_alphanumeric': 0.11296458882060287, 'fraction_numerical': 0.004682470002926544, 'mean_word_length': 3.3989703989703988, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2893949', 'n_tokens_mistral': 935, 'n_tokens_neox': 920, 'n_words': 319}