<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.colar.netbeans.fan.wizard;

import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.LinkedHashSet;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.swing.event.ChangeListener;
import net.colar.netbeans.fan.FanUtilities;
import net.colar.netbeans.fan.project.FanProjectProperties;
import net.colar.netbeans.fan.templates.TemplateUtils;
import net.colar.netbeans.fan.templates.TemplateView;
import net.jot.logger.JOTLogger;
import net.jot.web.views.JOTLightweightView;
import org.netbeans.spi.project.ui.support.ProjectChooser;
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
import org.netbeans.spi.project.ui.templates.support.Templates;
import org.openide.WizardDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;

/**
 * Generated by NB "New wizard"
 * Iterator for new fan project/pod wizard
 * @author tcolar
 */
public final class FanPodWizardIterator implements WizardDescriptor.InstantiatingIterator
{

	private int index;
	private WizardDescriptor wizard;
	private WizardDescriptor.Panel[] panels;
	/**
	 * Initialize panels representing individual wizard's steps and sets
	 * various properties for them influencing wizard appearance.
	 */
	private WizardDescriptor.Panel packageChooserPanel;

	private WizardDescriptor.Panel[] getPanels()
	{
		if (panels == null)
		{
			panels = new WizardDescriptor.Panel[]
				{
					new FanPodWizardPanel1(System.getProperty("user.dir")),
				};
		}
		return panels;
	}

	public FanPodWizardPanel1 getPanel()
	{
		return (FanPodWizardPanel1) panels[0];
	}

	/**
	 * Called when "finish" is pressed
	 * @return
	 * @throws IOException
	 */
	public Set instantiate() throws IOException
	{
		FanPodWizardPanel1 panel = getPanel();
		String podFolder = panel.getProjectFolder();
		String podName = panel.getPodName();
		String podDesc = panel.getPodDesc();
		boolean createBuildFile = panel.getCreateBuildFile();

		// create project
		File pf = FileUtil.normalizeFile(new File(podFolder));
		pf.mkdirs();
		FileObject pfFo = FileUtil.toFileObject(pf);
		// fan sources folder
		File fan = FileUtil.normalizeFile(new File(pf, "fan"));
		fan.mkdirs();
		File test = FileUtil.normalizeFile(new File(pf, "test"));
		test.mkdirs();
		//build.fan
		FileObject fanFo = FileUtil.toFileObject(fan);
		FileObject testFo = FileUtil.toFileObject(test);
		FileObject buildFo = null;
		FileObject buildTemplate = Templates.getTemplate(wizard);

		// Create main class
		if (panel.getMainClassName() != null)
		{
			String name = panel.getMainClassName();
			File mainFile = new File(fan, name + ".fan");
			JOTLightweightView view = new TemplateView(buildTemplate, name);
			view.addVariable("doClass", Boolean.TRUE);
			view.addVariable("doMain", Boolean.TRUE);
			FileObject license = FanUtilities.getRelativeFileObject(buildTemplate, "../../Licenses/FanDefaultLicense.txt");
			view.addVariable("license", license.asText());
			FileObject newTemplate = FanUtilities.getRelativeFileObject(buildTemplate, "../../Fantom/FantomFile");
			String templateText = newTemplate.asText();
			//open it in editor
			TemplateUtils.createFromTemplate(view, templateText, mainFile);
			FanUtilities.openFileInEditor(mainFile);
			// save main class in props
			File props = new File(pf.getAbsolutePath() + File.separator + FanProjectProperties.PROJ_PROPS_PATH);
			props.getParentFile().mkdirs();
			Hashtable<String, String> map = new Hashtable<String, String>();
			map.put(FanProjectProperties.MAIN_METHOD, name + ".main");
			FanProjectProperties.createFromScratch(map, props);
		}


		// Create the build file LAST, because as soon as that is created,
		// NB will recognize this as a project, so we want everything(props) to be ready by then
		if (createBuildFile)
		{
			JOTLightweightView view = new TemplateView(buildTemplate, podName);

			view.addVariable("desc", podDesc);

			File buildFile = new File(pf, "build.fan");

			buildFo = FileUtil.toFileObject(buildFile);

			FileObject license = FanUtilities.getRelativeFileObject(buildTemplate, "../../Licenses/FanDefaultLicense.txt");
			view.addVariable("license", license.asText());

			String buildText = buildTemplate.asText();

			// create build.fan
			TemplateUtils.createFromTemplate(view, buildText, buildFile);

		}

		// Look for nested projects to open as well:
		LinkedHashSet resultSet = new LinkedHashSet();
		resultSet.add(pfFo);
		resultSet.add(fanFo);
		resultSet.add(testFo);
		if (buildFo != null)
		{
			resultSet.add(buildFo);
		}

		File parent = pf.getParentFile();
		// Always open top dir as a project:
		if (parent != null && parent.exists())
		{
			ProjectChooser.setProjectsFolder(parent);
		}<commit_msg>Handle getting of new properties from PodPanel<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.colar.netbeans.fan.wizard;

import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.LinkedHashSet;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.swing.event.ChangeListener;
import net.colar.netbeans.fan.FanUtilities;
import net.colar.netbeans.fan.project.FanProjectProperties;
import net.colar.netbeans.fan.templates.TemplateUtils;
import net.colar.netbeans.fan.templates.TemplateView;
import net.jot.web.views.JOTLightweightView;
import org.netbeans.spi.project.ui.support.ProjectChooser;
import org.netbeans.spi.project.ui.templates.support.Templates;
import org.openide.WizardDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

/**
 * Generated by NB "New wizard"
 * Iterator for new fan project/pod wizard
 * @author tcolar
 */
public final class FanPodWizardIterator implements WizardDescriptor.InstantiatingIterator
{

	private int index;
	private WizardDescriptor wizard;
	private WizardDescriptor.Panel[] panels;
	/**
	 * Initialize panels representing individual wizard's steps and sets
	 * various properties for them influencing wizard appearance.
	 */
	private WizardDescriptor.Panel packageChooserPanel;

	private WizardDescriptor.Panel[] getPanels()
	{
		if (panels == null)
		{
			panels = new WizardDescriptor.Panel[]
                        {
                            new FanPodWizardPanel1(System.getProperty("user.dir")),
                        };
		}
		return panels;
	}

	public FanPodWizardPanel1 getPanel()
	{
		return (FanPodWizardPanel1) panels[0];
	}

	/**
	 * Called when "finish" is pressed
	 * @return
	 * @throws IOException
	 */
	public Set instantiate() throws IOException
	{
		FanPodWizardPanel1 panel = getPanel();
		String podFolder = panel.getProjectFolder();
		String podName = panel.getPodName();
		String podDesc = panel.getPodDesc();
                String podVersion = panel.getPodVersion();
                String dependencies = panel.getDependencies();
                String metas = panel.getMeta();
                String indexes = panel.getIndex();
                String outDir = panel.getOutDir();
		boolean createBuildFile = panel.getCreateBuildFile();
                boolean docApi = panel.getDocApi();
                boolean docSrc = panel.getDocSrc();
                
		// create project
		File pf = FileUtil.normalizeFile(new File(podFolder));
		pf.mkdirs();
		FileObject pfFo = FileUtil.toFileObject(pf);
		// fan sources folder
		File fan = FileUtil.normalizeFile(new File(pf, "fan"));
		fan.mkdirs();
		File test = FileUtil.normalizeFile(new File(pf, "test"));
		test.mkdirs();
                File out = FileUtil.normalizeFile(new File(pf, "out"));
                out.mkdirs();
		//build.fan
		FileObject fanFo = FileUtil.toFileObject(fan);
		FileObject testFo = FileUtil.toFileObject(test);
                FileObject outFo = FileUtil.toFileObject(out);
		FileObject buildFo = null;
		FileObject buildTemplate = Templates.getTemplate(wizard);

		// Create main class
		if (panel.getMainClassName() != null)
		{
			String name = panel.getMainClassName();
			File mainFile = new File(fan, name + ".fan");
			JOTLightweightView view = new TemplateView(buildTemplate, name);
			view.addVariable("doClass", Boolean.TRUE);
			view.addVariable("doMain", Boolean.TRUE);
			FileObject license = FanUtilities.getRelativeFileObject(buildTemplate, "../../Licenses/FanDefaultLicense.txt");
			view.addVariable("license", license.asText());
			FileObject newTemplate = FanUtilities.getRelativeFileObject(buildTemplate, "../../Fantom/FantomFile");
			String templateText = newTemplate.asText();
			//open it in editor
			TemplateUtils.createFromTemplate(view, templateText, mainFile);
			FanUtilities.openFileInEditor(mainFile);
			// save main class in props
			File props = new File(pf.getAbsolutePath() + File.separator + FanProjectProperties.PROJ_PROPS_PATH);
			props.getParentFile().mkdirs();
			Hashtable<String, String> map = new Hashtable<String, String>();
			map.put(FanProjectProperties.MAIN_METHOD, name + ".main");
			FanProjectProperties.createFromScratch(map, props);
		}


		// Create the build file LAST, because as soon as that is created,
		// NB will recognize this as a project, so we want everything(props) to be ready by then
		if (createBuildFile)
		{
			JOTLightweightView view = new TemplateView(buildTemplate, podName);

			view.addVariable("desc", podDesc);
                        view.addVariable("version", podVersion);
                        view.addVariable("dependencies", dependencies);
                        // TODO Must not be hard-coded
                        view.addVariable("srcDirs", "`fan/`, `test`");
                        view.addVariable("outDir", outDir);
                        view.addVariable("indexes", indexes);
                        view.addVariable("metas", metas);
                        view.addVariable("docSrc", Boolean.toString(docSrc));
                        view.addVariable("docApi", Boolean.toString(docApi));
			File buildFile = new File(pf, "build.fan");

			buildFo = FileUtil.toFileObject(buildFile);

			FileObject license = FanUtilities.getRelativeFileObject(buildTemplate, "../../Licenses/FanDefaultLicense.txt");
			view.addVariable("license", license.asText());

			String buildText = buildTemplate.asText();
                        Pattern p = Pattern.compile("^.*\\[\\]$", Pattern.MULTILINE);
                        Matcher m = p.matcher(buildText);
                        buildText = m.replaceAll("");
                        p = Pattern.compile("^.*= $", Pattern.MULTILINE);
                        m = p.matcher(buildText);
                        buildText = m.replaceAll("");
                        p = Pattern.compile("^.*= \"\"$", Pattern.MULTILINE);
                        m = p.matcher(buildText);
                        buildText = m.replaceAll("");
                        p = Pattern.compile("^.*= Version.fromStr\\(\"\"\\)$", Pattern.MULTILINE);
                        m = p.matcher(buildText);
                        buildText = m.replaceAll("");

			// create build.fan
			TemplateUtils.createFromTemplate(view, buildText, buildFile);

		}

		// Look for nested projects to open as well:
		LinkedHashSet<FileObject> resultSet = new LinkedHashSet<FileObject>();
		resultSet.add(pfFo);
		resultSet.add(fanFo);
		resultSet.add(testFo);
		if (buildFo != null)
		{
			resultSet.add(buildFo);
		}

		File parent = pf.getParentFile();
		// Always open top dir as a project:
		if (parent != null && parent.exists())
		{
			ProjectChooser.setProjectsFolder(parent);
		}
{'fraction_non_alphanumeric': 0.11687537268932618, 'fraction_numerical': 0.0008518613169775961, 'mean_word_length': 3.4436033308099923, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5934270', 'n_tokens_mistral': 3750, 'n_tokens_neox': 3341, 'n_words': 781}