<commit_before>/*
 * Copyright 1&1 Internet AG, https://github.com/1and1/
 *
 * 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
 *
 *     http://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 net.oneandone.stool.templates;

import net.oneandone.inline.ArgumentException;
import net.oneandone.inline.Console;
import net.oneandone.stool.cli.Main;
import net.oneandone.stool.configuration.StageConfiguration;
import net.oneandone.stool.stage.Stage;
import net.oneandone.stool.util.Ports;
import net.oneandone.stool.util.Session;
import net.oneandone.stool.util.Vhost;
import net.oneandone.sushi.fs.file.FileNode;
import net.oneandone.sushi.launcher.Launcher;
import net.oneandone.sushi.util.Separator;
import net.oneandone.sushi.util.Strings;
import net.oneandone.sushi.util.Substitution;
import net.oneandone.sushi.util.SubstitutionException;
import net.oneandone.sushi.xml.XmlException;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Tomcat {
    private final Stage stage;
    private final FileNode context;
    private final StageConfiguration configuration;
    private final Session session;
    private final Console console;
    private final Ports ports;

    public Tomcat(Stage stage, FileNode context, Session session, Ports ports) {
        this.stage = stage;
        this.context = context;
        this.configuration = stage.config();
        this.session = session;
        this.console = session.console;
        this.ports = ports;
    }

    //-- public interface

    /** null for disabled */
    public String major(String version) {
        return version.substring(0, version.indexOf('.'));
    }

        /** null for disabled */
    public String fault() throws IOException {
        Launcher launcher;
        List<String> projects;
        FileNode token;
        FileNode list;

        list = session.world.getTemp().createTempFile();
        launcher = context.launcher("fault", "resolve", "-output", list.getAbsolute());
        for (String p : stage.faultProjects()) {
            launcher.arg(p);
        }
        launcher.getBuilder().inheritIO();
        launcher.exec();
        projects = list.readLines();
        if (projects.isEmpty()) {
            return "";
        }
        token = context.join(".fault-token");
        token.writeString("");
        session.world.onShutdown().deleteAtExit(token);
        token.setPermissions("rw-------");
        token.appendString(session.world.getHome().join(token.getName()).readString());
        return Separator.SPACE.join(projects);
    }

    /* also checks sha1 digest - https://run-jira.tool.1and1.com/browse/CISOOPS-2406 */
    public void download(String downloadUrl, String version) throws IOException {
        FileNode download;
        FileNode dest;

        download = session.downloads().join(tomcatName(version) + ".tar.gz");
        if (!download.exists()) {
            downloadFile(subst(downloadUrl, version), download);
            download.checkFile();
        }<commit_msg>some verbose output for fault<commit_after>/*
 * Copyright 1&1 Internet AG, https://github.com/1and1/
 *
 * 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
 *
 *     http://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 net.oneandone.stool.templates;

import net.oneandone.inline.ArgumentException;
import net.oneandone.inline.Console;
import net.oneandone.stool.cli.Main;
import net.oneandone.stool.configuration.StageConfiguration;
import net.oneandone.stool.stage.Stage;
import net.oneandone.stool.util.Ports;
import net.oneandone.stool.util.Session;
import net.oneandone.stool.util.Vhost;
import net.oneandone.sushi.fs.file.FileNode;
import net.oneandone.sushi.launcher.Launcher;
import net.oneandone.sushi.util.Separator;
import net.oneandone.sushi.util.Strings;
import net.oneandone.sushi.util.Substitution;
import net.oneandone.sushi.util.SubstitutionException;
import net.oneandone.sushi.xml.XmlException;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Tomcat {
    private final Stage stage;
    private final FileNode context;
    private final StageConfiguration configuration;
    private final Session session;
    private final Console console;
    private final Ports ports;

    public Tomcat(Stage stage, FileNode context, Session session, Ports ports) {
        this.stage = stage;
        this.context = context;
        this.configuration = stage.config();
        this.session = session;
        this.console = session.console;
        this.ports = ports;
    }

    //-- public interface

    /** null for disabled */
    public String major(String version) {
        return version.substring(0, version.indexOf('.'));
    }

        /** null for disabled */
    public String fault() throws IOException {
        Launcher launcher;
        List<String> projects;
        FileNode token;
        FileNode list;

        list = session.world.getTemp().createTempFile();
        launcher = context.launcher("fault");
        if (console.getVerbose()) {
            launcher.arg("-v");
        }
        launcher.arg("resolve", "-output", list.getAbsolute());
        for (String p : stage.faultProjects()) {
            launcher.arg(p);
        }
        launcher.getBuilder().inheritIO();
        console.verbose.println("exec " + launcher);
        launcher.exec();
        projects = list.readLines();
        if (projects.isEmpty()) {
            return "";
        }
        token = context.join(".fault-token");
        token.writeString("");
        session.world.onShutdown().deleteAtExit(token);
        token.setPermissions("rw-------");
        token.appendString(session.world.getHome().join(token.getName()).readString());
        return Separator.SPACE.join(projects);
    }

    /* also checks sha1 digest - https://run-jira.tool.1and1.com/browse/CISOOPS-2406 */
    public void download(String downloadUrl, String version) throws IOException {
        FileNode download;
        FileNode dest;

        download = session.downloads().join(tomcatName(version) + ".tar.gz");
        if (!download.exists()) {
            downloadFile(subst(downloadUrl, version), download);
            download.checkFile();
        }
{'fraction_non_alphanumeric': 0.11367064308240779, 'fraction_numerical': 0.0043877690936514465, 'mean_word_length': 3.0477247502774696, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4439675', 'n_tokens_mistral': 2070, 'n_tokens_neox': 2022, 'n_words': 523}