<commit_before>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 <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.
 */

// default package

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;

/** Set various version values to the one of this program's first argument. */
public class Version {

  private static final Path PROPERTIES = Path.of(".bach/project.properties");

  public static void main(String... args) throws Exception {
    if (args.length == 0) {
      var properties = new Properties();
      try (var reader = Files.newBufferedReader(PROPERTIES)) {
        properties.load(reader);
      }
      var version = properties.getProperty("version");
      if (version == null) throw new Error("Key 'version' not found in: " + PROPERTIES.toUri());
      System.out.println(version);
      return;
    }

    if (args.length > 1) {
      throw new Error("Exactly one argument, the new version, expected! args=" + List.of(args));
    }
    var version = args[0];
    var readmeMd = Path.of("README.md");
    var mavenPom = Path.of("src/de.sormuras.bach/main/maven/pom.xml");
    var bachJava = Path.of("src/bach/Bach.java");
    // var mergedBach = Path.of("src/bach/MergedBach.java");

    sed(PROPERTIES, "version=.+", "version=" + version);
    sed(readmeMd, "# Bach.java .+ -", "# Bach.java " + version + " -");
    sed(mavenPom, "<version>.+</version>", "<version>" + version + "</version>");
    sed(bachJava, "String VERSION = \".+\";", "String VERSION = \"" + version + "\";");
    // mergedBach.toFile().setWritable(true);
    // sed(mergedBach, "String VERSION = \".+\";", "String VERSION = \"" + version + "\";");
    // mergedBach.toFile().setWritable(false);
  }

  private static void sed(Path path, String regex, String replacement) throws Exception {
    Files.writeString(path, Files.readString(path).replaceAll(regex, replacement));
  }
}<commit_msg>Set version in Bach.jsh script<commit_after>/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 <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.
 */

// default package

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;

/** Set various version values to the one of this program's first argument. */
public class Version {

  private static final Path PROPERTIES = Path.of(".bach/project.properties");

  public static void main(String... args) throws Exception {
    if (args.length == 0) {
      var properties = new Properties();
      try (var reader = Files.newBufferedReader(PROPERTIES)) {
        properties.load(reader);
      }
      var version = properties.getProperty("version");
      if (version == null) throw new Error("Key 'version' not found in: " + PROPERTIES.toUri());
      System.out.println(version);
      return;
    }

    if (args.length > 1) {
      throw new Error("Exactly one argument, the new version, expected! args=" + List.of(args));
    }
    var version = args[0];
    var readmeMd = Path.of("README.md");
    var mavenPom = Path.of("src/de.sormuras.bach/main/maven/pom.xml");
    var bachJava = Path.of("src/bach/Bach.java");
    var bachJsh = Path.of("src/bach/Bach.jsh");
    // var mergedBach = Path.of("src/bach/MergedBach.java");

    sed(PROPERTIES, "version=.+", "version=" + version);
    sed(readmeMd, "# Bach.java .+ -", "# Bach.java " + version + " -");
    sed(mavenPom, "<version>.+</version>", "<version>" + version + "</version>");
    sed(bachJava, "String VERSION = \".+\";", "String VERSION = \"" + version + "\";");
    sed(bachJsh, "raw/.+/src", "raw/" + (version.endsWith("-ea") ? "master" : version) + "/src");
    // mergedBach.toFile().setWritable(true);
    // sed(mergedBach, "String VERSION = \".+\";", "String VERSION = \"" + version + "\";");
    // mergedBach.toFile().setWritable(false);
  }

  private static void sed(Path path, String regex, String replacement) throws Exception {
    Files.writeString(path, Files.readString(path).replaceAll(regex, replacement));
  }
}
{'fraction_non_alphanumeric': 0.15144941826069808, 'fraction_numerical': 0.004338394793926247, 'mean_word_length': 3.395147313691508, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1740048', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1516, 'n_words': 460}