<commit_before>package net.sf.iwant.wsdef;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import net.sf.iwant.api.core.ScriptGenerated;
import net.sf.iwant.api.model.Path;
import net.sf.iwant.api.model.Source;
import net.sf.iwant.api.model.Target;
import net.sf.iwant.api.model.TargetEvaluationContext;
import net.sf.iwant.entry.Iwant;

public class Descripted extends Target {

	private final Source doc;
	private final Source descript;
	private final Path maybeIwantWsroot;
	private final Source abstractArticle;
	private final Descripted maybeInitialState;
	private final Path tutorialWsdefSrc;
	private final String titleText;
	private final String docName;

	public Descripted(String namePrefix, String docName, String titleText,
			Path tutorialWsdefSrc, Path maybeIwantWsroot,
			Descripted maybeInitialState) {
		super(namePrefix + docName + ".html");
		this.docName = docName;
		this.titleText = titleText;
		this.tutorialWsdefSrc = tutorialWsdefSrc;
		this.maybeIwantWsroot = maybeIwantWsroot;
		this.maybeInitialState = maybeInitialState;
		this.doc = Source
				.underWsroot("private/iwant-docs/src/main/descript/tutorial/"
						+ docName + ".sh");
		this.abstractArticle = Source
				.underWsroot("private/iwant-docs/src/main/descript/tutorial/abstract-article.sh");
		this.descript = Source.underWsroot("iwant-lib-descript/descript.sh");
	}

	public String titleText() {
		return titleText;
	}

	public String docName() {
		return docName;
	}

	@Override
	public InputStream content(TargetEvaluationContext ctx) throws Exception {
		throw new UnsupportedOperationException("TODO test and implement");
	}

	@Override
	public boolean supportsParallelism() {
		// TODO return true when known to work
		return false;
	}

	@Override
	public List<Path> ingredients() {
		List<Path> ingredients = new ArrayList<>();
		ingredients.add(doc);
		ingredients.add(abstractArticle);
		ingredients.add(descript);
		ingredients.add(tutorialWsdefSrc);
		if (maybeIwantWsroot != null) {
			ingredients.add(maybeIwantWsroot);
		}
		if (maybeInitialState != null) {
			ingredients.add(maybeInitialState);
		}
		ingredients.add(Source
				.underWsroot("as-iwant-developer/i-have/wsdef/src/main/java/"
						+ "net/sf/iwant/wsdef/Descripted.java"));
		return ingredients;
	}

	@Override
	public void path(TargetEvaluationContext ctx) throws Exception {
		File dest = ctx.cached(this);
		dest.mkdirs();

		File htmlHeader = newHtmlHeaderFile(dest);
		File htmlFooter = newHtmlFooterFile(dest);
		File htmlBodyContent = new File(dest, "body-content.html");
		File fullHtml = new File(dest, "doc.html");

		File iwantWsRoot = maybeIwantWsroot == null ? null : ctx
				.cached(maybeIwantWsroot);

		StringBuilder sh = new StringBuilder();
		sh.append("#!/bin/bash\n");
		sh.append("set -eu\n");
		sh.append("export IWANT_TUTORIAL_WSDEF_SRC="
				+ ctx.cached(tutorialWsdefSrc) + "\n");
		if (iwantWsRoot != null) {
			sh.append("export LOCAL_IWANT_WSROOT=" + iwantWsRoot + "\n");
		} else {
			sh.append("export REV_TO_TEST=775\n");
		}
		if (maybeInitialState != null) {
			File initialState = new File(ctx.cached(maybeInitialState),
					"final-state.tar");
			sh.append("export INITIAL_STATE=" + initialState + "\n");
			sh.append("export INIT_STATE_PAGE=" + maybeInitialState.docName
					+ ".html\n");
			sh.append("export INIT_STATE_TITLE='" + maybeInitialState.titleText
					+ "'\n");
		}
		sh.append("DOC=combined.sh\n");
		sh.append("cat " + ctx.cached(abstractArticle) + " " + ctx.cached(doc)
				+ " > \"$DOC\"\n");
		sh.append("echo \"export PAGETITLE='" + titleText + "'\" >> \"$DOC\"\n");
		sh.append("'" + ctx.cached(descript) + "' \"$DOC\" '" + htmlBodyContent
				+ "' false\n");
		sh.append("cat '" + htmlHeader + "' '" + htmlBodyContent + "' '"<commit_msg>upgraded rev for remote tutorial<commit_after>package net.sf.iwant.wsdef;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import net.sf.iwant.api.core.ScriptGenerated;
import net.sf.iwant.api.model.Path;
import net.sf.iwant.api.model.Source;
import net.sf.iwant.api.model.Target;
import net.sf.iwant.api.model.TargetEvaluationContext;
import net.sf.iwant.entry.Iwant;

public class Descripted extends Target {

	private final Source doc;
	private final Source descript;
	private final Path maybeIwantWsroot;
	private final Source abstractArticle;
	private final Descripted maybeInitialState;
	private final Path tutorialWsdefSrc;
	private final String titleText;
	private final String docName;

	public Descripted(String namePrefix, String docName, String titleText,
			Path tutorialWsdefSrc, Path maybeIwantWsroot,
			Descripted maybeInitialState) {
		super(namePrefix + docName + ".html");
		this.docName = docName;
		this.titleText = titleText;
		this.tutorialWsdefSrc = tutorialWsdefSrc;
		this.maybeIwantWsroot = maybeIwantWsroot;
		this.maybeInitialState = maybeInitialState;
		this.doc = Source
				.underWsroot("private/iwant-docs/src/main/descript/tutorial/"
						+ docName + ".sh");
		this.abstractArticle = Source
				.underWsroot("private/iwant-docs/src/main/descript/tutorial/abstract-article.sh");
		this.descript = Source.underWsroot("iwant-lib-descript/descript.sh");
	}

	public String titleText() {
		return titleText;
	}

	public String docName() {
		return docName;
	}

	@Override
	public InputStream content(TargetEvaluationContext ctx) throws Exception {
		throw new UnsupportedOperationException("TODO test and implement");
	}

	@Override
	public boolean supportsParallelism() {
		// TODO return true when known to work
		return false;
	}

	@Override
	public List<Path> ingredients() {
		List<Path> ingredients = new ArrayList<>();
		ingredients.add(doc);
		ingredients.add(abstractArticle);
		ingredients.add(descript);
		ingredients.add(tutorialWsdefSrc);
		if (maybeIwantWsroot != null) {
			ingredients.add(maybeIwantWsroot);
		}
		if (maybeInitialState != null) {
			ingredients.add(maybeInitialState);
		}
		ingredients.add(Source
				.underWsroot("as-iwant-developer/i-have/wsdef/src/main/java/"
						+ "net/sf/iwant/wsdef/Descripted.java"));
		return ingredients;
	}

	@Override
	public void path(TargetEvaluationContext ctx) throws Exception {
		File dest = ctx.cached(this);
		dest.mkdirs();

		File htmlHeader = newHtmlHeaderFile(dest);
		File htmlFooter = newHtmlFooterFile(dest);
		File htmlBodyContent = new File(dest, "body-content.html");
		File fullHtml = new File(dest, "doc.html");

		File iwantWsRoot = maybeIwantWsroot == null ? null : ctx
				.cached(maybeIwantWsroot);

		StringBuilder sh = new StringBuilder();
		sh.append("#!/bin/bash\n");
		sh.append("set -eu\n");
		sh.append("export IWANT_TUTORIAL_WSDEF_SRC="
				+ ctx.cached(tutorialWsdefSrc) + "\n");
		if (iwantWsRoot != null) {
			sh.append("export LOCAL_IWANT_WSROOT=" + iwantWsRoot + "\n");
		} else {
			sh.append("export REV_TO_TEST=796\n");
		}
		if (maybeInitialState != null) {
			File initialState = new File(ctx.cached(maybeInitialState),
					"final-state.tar");
			sh.append("export INITIAL_STATE=" + initialState + "\n");
			sh.append("export INIT_STATE_PAGE=" + maybeInitialState.docName
					+ ".html\n");
			sh.append("export INIT_STATE_TITLE='" + maybeInitialState.titleText
					+ "'\n");
		}
		sh.append("DOC=combined.sh\n");
		sh.append("cat " + ctx.cached(abstractArticle) + " " + ctx.cached(doc)
				+ " > \"$DOC\"\n");
		sh.append("echo \"export PAGETITLE='" + titleText + "'\" >> \"$DOC\"\n");
		sh.append("'" + ctx.cached(descript) + "' \"$DOC\" '" + htmlBodyContent
				+ "' false\n");
		sh.append("cat '" + htmlHeader + "' '" + htmlBodyContent + "' '"
{'fraction_non_alphanumeric': 0.13761587674631154, 'fraction_numerical': 0.0007833920877399138, 'mean_word_length': 4.398167723749119, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2408060', 'n_tokens_mistral': 2870, 'n_tokens_neox': 2529, 'n_words': 502}