<commit_before>/*
Copyright 2016, <NAME> (Fraunhofer IOSB)

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.
 */

/*
 * This class holds variables to use as out parameters.
 */
package de.fraunhofer.iosb.ivct;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Semaphore;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import nato.ivct.commander.BadgeDescription;
import nato.ivct.commander.CmdListBadges;
import nato.ivct.commander.CmdListSuT;
import nato.ivct.commander.CmdQuit;
import nato.ivct.commander.CmdSetLogLevel;
import nato.ivct.commander.CmdSetLogLevel.LogLevel;
import nato.ivct.commander.CmdStartTc;
import nato.ivct.commander.Factory;
import nato.ivct.commander.SutDescription;

public final class RuntimeParameters {
    private static Logger LOGGER = LoggerFactory.getLogger(RuntimeParameters.class);
	private static boolean abortTestScheduleBool = false;
	private boolean testCaseRunningBool = false;
	private boolean testScheduleRunningBool = false;
	private boolean testSuiteNameNew = true;
	private int countSemaphore = 0;
	private CmdListBadges cmdListBadges = null;
	private CmdListSuT sutList = null;
	private PrintStream printStream = new PrintStream(System.out);
	private static Semaphore semaphore = new Semaphore(0);
	private static String testCaseName = null;
	private static String testScheduleName = null;
	private String testSuiteName = null;

    public RuntimeParameters () {
    }

    public void acquireSemaphore() {
        try {
            countSemaphore++;
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
            LOGGER.error("acquireSemaphore: ", e);
        }
    }

    public void releaseSemaphore() {
        if (countSemaphore > 0) {
            semaphore.release();
            countSemaphore--;
        }
    }

    /*
     * Check if a test case or test schedule are running.
     *
     * @param theCaller name of the calling method
     * @param out the calling method
     *
     * @return whether a critical task is running
     */
    protected boolean checkCtTcTsRunning(final String theCaller) {
        if (theCaller == null) {
            printStream.println("checkCtTcTsRunning: theCaller: null pointer found");
            return true;
        }
        if (testCaseRunningBool) {
            printStream.println(theCaller + ": Warning test case is running - command not allowed");
            return true;
        }
        if (testScheduleRunningBool) {
            printStream.println(theCaller + ": Warning test schedule is running - command not allowed");
            return true;
        }
        return false;
    }

	protected String getFullTestcaseName(final String testsuite, final String testCase) {
		getTestSuiteNames();
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			if (testSuiteNameTmp.equals(testsuite)) {
				for (int i = 0; i < s.getValue().requirements.length; i++) {
					String tc = s.getValue().requirements[i].TC.substring(s.getValue().requirements[i].TC.lastIndexOf(".") + 1);
					if(tc.equals(testCase)) {
						return s.getValue().requirements[i].TC;
					}
				}
			}
		}
		
		return null;
	}

	/*
	 * 
	 */
	protected boolean startTestCase(final String sutName, final SutDescription sutDescription, final String theTestSuiteName, final String testCase) {
	    
		CmdStartTc cmdStartTc = Factory.createCmdStartTc(sutName, theTestSuiteName, testCase, sutDescription.settingsDesignator, sutDescription.federation);
		setTestCaseRunningBool(true);
		cmdStartTc.execute();
		return false;
	}

	/*
	 * Check if the test case name occurs in the test schedule.
	 */
	protected boolean checkTestCaseNameKnown(final String testsuite, final String testCase) {
		getTestSuiteNames();
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			if (testSuiteNameTmp.equals(testsuite)) {
				for (int i = 0; i < s.getValue().requirements.length; i++) {
					if(s.getValue().requirements[i].TC.equals(testCase)) {
						return false;
					}
				}
			}
		}

		return true;
	}
	
	/*
	 * Check if the test suite name changed since last check.
	 */
	protected boolean checkTestSuiteNameNew() {
		return testSuiteNameNew;
	}

	public static boolean getAbortTestScheduleBool() {
		return abortTestScheduleBool;
	}

	public static void setAbortTestScheduleBool(boolean b) {
		abortTestScheduleBool = b;
	}

	public boolean getTestCaseRunningBool() {
		return testCaseRunningBool;
	}

	public void setTestCaseRunningBool(boolean b) {
		testCaseRunningBool = b;
	}

	public boolean getTestScheduleRunningBool() {
		return testScheduleRunningBool;
	}

	public void setTestScheduleRunningBool(boolean b) {
		testScheduleRunningBool = b;
	}
	
	public void setTestSuiteNameUsed() {
		testSuiteNameNew = false;
	}
	
	public List<String> getTestcases(final String testsuite) {
		List<String> ls = new ArrayList<String>();

		getTestSuiteNames();
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			if (testSuiteNameTmp.equals(testsuite)) {
				for (int i = 0; i < s.getValue().requirements.length; i++) {
					int ind = ls.indexOf(s.getValue().requirements[i].TC);
					if (ind < 0) {
						ls.add(s.getValue().requirements[i].TC);
					}
				}
			}
		}

		return ls;
	}

	public List<String> getTestSuiteNames() {

		cmdListBadges = Factory.createCmdListBadges();
		cmdListBadges.execute();
		List<String> ls = new ArrayList<String>();

		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			ls.add(testSuiteNameTmp);
		}

		return ls;
	}
    
	protected List<String> getSutBadges(final String theSutName, final boolean recursive) {
		List<String> badges = new ArrayList<String>();
		listSUTs();
		for (String it: sutList.sutMap.keySet()) {
			if (it.equals(theSutName)) {
				getTestSuiteNames();
				for (String entry : sutList.sutMap.get(it).badges) {
					int ind = badges.indexOf(entry);
					if (ind < 0) {
						badges.add(entry);
					}
					if (recursive) {
						if (getRecursiveBadges(badges, entry)) {
							return badges;
						}
					}
				}
				return badges;
			}
		}
		return badges;
	}
	
	private boolean getRecursiveBadges(List<String> badges, final String currentBadge) {
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			BadgeDescription bd = s.getValue();
			if (bd.ID.equals(currentBadge)) {
				for (int j = 0; j < s.getValue().dependency.length; j++) {
					int indd = badges.indexOf(s.getValue().dependency[j]);
					if (indd < 0) {
						badges.add(s.getValue().dependency[j]);
						getRecursiveBadges(badges, s.getValue().dependency[j]);
					}
				}
			}
		}
		return false;
	}
	
	private void listSUTs() {
		sutList = Factory.createCmdListSut();
		sutList.execute();
	}

	protected void resetSut() {
		// Reset values.
		testCaseName = null;
		testScheduleName = null;
		testSuiteName = null;
	}

	protected SutDescription getSutDescription(final String sutName) {
		listSUTs();
		return sutList.sutMap.get(sutName);
	}

	protected static String getTestCaseName() {
		return testCaseName;
	}

	protected static void setTestCaseName(String theTestCaseName) {
		testScheduleName = null;
		testCaseName = theTestCaseName;
	}

	protected static String getTestScheduleName() {
		return testScheduleName;
	}

	protected static void setTestScheduleName(String theTestScheduleName) {
		testCaseName = null;
		testScheduleName = theTestScheduleName;
	}

	protected String getTestSuiteName() {
		return testSuiteName;
	}

	protected void setTestSuiteName(String testSuiteName) {
		if (this.testSuiteName != null) {
			if (this.testSuiteName.equals(testSuiteName) == false) {
				this.testSuiteNameNew = true;
			}
		}
		this.testSuiteName = testSuiteName;
	}
	
	protected CmdSetLogLevel createCmdSetLogLevel(final String level) {
		String levelUpper = level.toUpperCase();
		LogLevel logLevel = LogLevel.valueOf(levelUpper);
		return Factory.createCmdSetLogLevel(logLevel);
	}
	
	protected CmdQuit createCmdQuit() {
		return Factory.createCmdQuit();
	}
}
<commit_msg>SutFederateName added<commit_after>/*
Copyright 2016, <NAME> (Fraunhofer IOSB)

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.
 */

/*
 * This class holds variables to use as out parameters.
 */
package de.fraunhofer.iosb.ivct;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Semaphore;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import nato.ivct.commander.BadgeDescription;
import nato.ivct.commander.CmdListBadges;
import nato.ivct.commander.CmdListSuT;
import nato.ivct.commander.CmdQuit;
import nato.ivct.commander.CmdSetLogLevel;
import nato.ivct.commander.CmdSetLogLevel.LogLevel;
import nato.ivct.commander.CmdStartTc;
import nato.ivct.commander.Factory;
import nato.ivct.commander.SutDescription;

public final class RuntimeParameters {
    private static Logger LOGGER = LoggerFactory.getLogger(RuntimeParameters.class);
	private static boolean abortTestScheduleBool = false;
	private boolean testCaseRunningBool = false;
	private boolean testScheduleRunningBool = false;
	private boolean testSuiteNameNew = true;
	private int countSemaphore = 0;
	private CmdListBadges cmdListBadges = null;
	private CmdListSuT sutList = null;
	private PrintStream printStream = new PrintStream(System.out);
	private static Semaphore semaphore = new Semaphore(0);
	private static String testCaseName = null;
	private static String testScheduleName = null;
	private String testSuiteName = null;

    public RuntimeParameters () {
    }

    public void acquireSemaphore() {
        try {
            countSemaphore++;
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
            LOGGER.error("acquireSemaphore: ", e);
        }
    }

    public void releaseSemaphore() {
        if (countSemaphore > 0) {
            semaphore.release();
            countSemaphore--;
        }
    }

    /*
     * Check if a test case or test schedule are running.
     *
     * @param theCaller name of the calling method
     * @param out the calling method
     *
     * @return whether a critical task is running
     */
    protected boolean checkCtTcTsRunning(final String theCaller) {
        if (theCaller == null) {
            printStream.println("checkCtTcTsRunning: theCaller: null pointer found");
            return true;
        }
        if (testCaseRunningBool) {
            printStream.println(theCaller + ": Warning test case is running - command not allowed");
            return true;
        }
        if (testScheduleRunningBool) {
            printStream.println(theCaller + ": Warning test schedule is running - command not allowed");
            return true;
        }
        return false;
    }

	protected String getFullTestcaseName(final String testsuite, final String testCase) {
		getTestSuiteNames();
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			if (testSuiteNameTmp.equals(testsuite)) {
				for (int i = 0; i < s.getValue().requirements.length; i++) {
					String tc = s.getValue().requirements[i].TC.substring(s.getValue().requirements[i].TC.lastIndexOf(".") + 1);
					if(tc.equals(testCase)) {
						return s.getValue().requirements[i].TC;
					}
				}
			}
		}
		
		return null;
	}

	/*
	 * 
	 */
	protected boolean startTestCase(final String sutName, final SutDescription sutDescription, final String theTestSuiteName, final String testCase) {
	    
		CmdStartTc cmdStartTc = Factory.createCmdStartTc(sutName, theTestSuiteName, testCase, sutDescription.settingsDesignator, sutDescription.federation, sutDescription.sutFederateName);
		setTestCaseRunningBool(true);
		cmdStartTc.execute();
		return false;
	}

	/*
	 * Check if the test case name occurs in the test schedule.
	 */
	protected boolean checkTestCaseNameKnown(final String testsuite, final String testCase) {
		getTestSuiteNames();
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			if (testSuiteNameTmp.equals(testsuite)) {
				for (int i = 0; i < s.getValue().requirements.length; i++) {
					if(s.getValue().requirements[i].TC.equals(testCase)) {
						return false;
					}
				}
			}
		}

		return true;
	}
	
	/*
	 * Check if the test suite name changed since last check.
	 */
	protected boolean checkTestSuiteNameNew() {
		return testSuiteNameNew;
	}

	public static boolean getAbortTestScheduleBool() {
		return abortTestScheduleBool;
	}

	public static void setAbortTestScheduleBool(boolean b) {
		abortTestScheduleBool = b;
	}

	public boolean getTestCaseRunningBool() {
		return testCaseRunningBool;
	}

	public void setTestCaseRunningBool(boolean b) {
		testCaseRunningBool = b;
	}

	public boolean getTestScheduleRunningBool() {
		return testScheduleRunningBool;
	}

	public void setTestScheduleRunningBool(boolean b) {
		testScheduleRunningBool = b;
	}
	
	public void setTestSuiteNameUsed() {
		testSuiteNameNew = false;
	}
	
	public List<String> getTestcases(final String testsuite) {
		List<String> ls = new ArrayList<String>();

		getTestSuiteNames();
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			if (testSuiteNameTmp.equals(testsuite)) {
				for (int i = 0; i < s.getValue().requirements.length; i++) {
					int ind = ls.indexOf(s.getValue().requirements[i].TC);
					if (ind < 0) {
						ls.add(s.getValue().requirements[i].TC);
					}
				}
			}
		}

		return ls;
	}

	public List<String> getTestSuiteNames() {

		cmdListBadges = Factory.createCmdListBadges();
		cmdListBadges.execute();
		List<String> ls = new ArrayList<String>();

		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			String testSuiteNameTmp = s.getKey();
			ls.add(testSuiteNameTmp);
		}

		return ls;
	}
    
	protected List<String> getSutBadges(final String theSutName, final boolean recursive) {
		List<String> badges = new ArrayList<String>();
		listSUTs();
		for (String it: sutList.sutMap.keySet()) {
			if (it.equals(theSutName)) {
				getTestSuiteNames();
				for (String entry : sutList.sutMap.get(it).badges) {
					int ind = badges.indexOf(entry);
					if (ind < 0) {
						badges.add(entry);
					}
					if (recursive) {
						if (getRecursiveBadges(badges, entry)) {
							return badges;
						}
					}
				}
				return badges;
			}
		}
		return badges;
	}
	
	private boolean getRecursiveBadges(List<String> badges, final String currentBadge) {
		for (Map.Entry<String, BadgeDescription> s : cmdListBadges.badgeMap.entrySet()) {
			BadgeDescription bd = s.getValue();
			if (bd.ID.equals(currentBadge)) {
				for (int j = 0; j < s.getValue().dependency.length; j++) {
					int indd = badges.indexOf(s.getValue().dependency[j]);
					if (indd < 0) {
						badges.add(s.getValue().dependency[j]);
						getRecursiveBadges(badges, s.getValue().dependency[j]);
					}
				}
			}
		}
		return false;
	}
	
	private void listSUTs() {
		sutList = Factory.createCmdListSut();
		sutList.execute();
	}

	protected void resetSut() {
		// Reset values.
		testCaseName = null;
		testScheduleName = null;
		testSuiteName = null;
	}

	protected SutDescription getSutDescription(final String sutName) {
		listSUTs();
		return sutList.sutMap.get(sutName);
	}

	protected static String getTestCaseName() {
		return testCaseName;
	}

	protected static void setTestCaseName(String theTestCaseName) {
		testScheduleName = null;
		testCaseName = theTestCaseName;
	}

	protected static String getTestScheduleName() {
		return testScheduleName;
	}

	protected static void setTestScheduleName(String theTestScheduleName) {
		testCaseName = null;
		testScheduleName = theTestScheduleName;
	}

	protected String getTestSuiteName() {
		return testSuiteName;
	}

	protected void setTestSuiteName(String testSuiteName) {
		if (this.testSuiteName != null) {
			if (this.testSuiteName.equals(testSuiteName) == false) {
				this.testSuiteNameNew = true;
			}
		}
		this.testSuiteName = testSuiteName;
	}
	
	protected CmdSetLogLevel createCmdSetLogLevel(final String level) {
		String levelUpper = level.toUpperCase();
		LogLevel logLevel = LogLevel.valueOf(levelUpper);
		return Factory.createCmdSetLogLevel(logLevel);
	}
	
	protected CmdQuit createCmdQuit() {
		return Factory.createCmdQuit();
	}
}

{'fraction_non_alphanumeric': 0.10283968774748274, 'fraction_numerical': 0.002375834370403892, 'mean_word_length': 3.637722980062959, 'pattern_counts': {'":': 4, '<': 49, '<?xml version=': 0, '>': 37, 'https://': 0, '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': '5759634', 'n_tokens_mistral': 6114, 'n_tokens_neox': 5422, 'n_words': 1336}