<commit_before>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://www.inria.fr/oasis/ProActive/contacts.html
 *  Contributor(s):
 *
 * ################################################################
 */
package testsuite.xml;

import java.io.File;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator;
import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
import org.objectweb.proactive.core.xml.io.Attributes;
import org.xml.sax.SAXException;

import testsuite.exception.BrowsePackageException;
import testsuite.group.Group;
import testsuite.manager.AbstractManager;
import testsuite.test.AbstractTest;


/**
 * @author <NAME>
 *
 */
public class GroupHandler {
    //-----------------------------------------------------------------------------------------------------------
    public static class SimpleGroupHandler extends AbstractUnmarshallerDecorator
        implements ManagerDescriptorConstants {
        private Group group = null;
        private AbstractManager manager = null;

        SimpleGroupHandler(AbstractManager manager) {
            super();
            this.manager = manager;
            addHandler(UNIT_TEST_TAG, new UnitTestHandler(manager));
        }

        public Object getResultObject() throws org.xml.sax.SAXException {
            return group;
        }

        public void startContextElement(String name, Attributes attributes)
            throws org.xml.sax.SAXException {
            group = new Group();
            String groupName = attributes.getValue("name");
            if (checkNonEmpty(groupName)) {
                group.setName(groupName);
            }
            String description = attributes.getValue("description");
            if (checkNonEmpty(description)) {
                group.setDescription(description);
            }
            manager.add(group);
        }

        protected void notifyEndActiveHandler(String name,
            UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
            if (name.equalsIgnoreCase(UNIT_TEST_TAG)) {
                group.add((AbstractTest) activeHandler.getResultObject());
            }
        }
    }

    //-----------------------------------------------------------------------------------------------------------
    public static class PackageGroupHandler
        extends AbstractUnmarshallerDecorator
        implements ManagerDescriptorConstants {
        private Group group = null;
        private AbstractManager manager = null;
        private static Vector excludesTests = new Vector();

        PackageGroupHandler(AbstractManager manager) {
            super();
            this.manager = manager;
            addHandler(UNIT_TEST_TAG, new UnitTestHandler(manager));
        }

        public Object getResultObject() throws org.xml.sax.SAXException {
            return group;
        }

        private int indexGlobal = 0;

        public void startContextElement(String name, Attributes attributes)
            throws org.xml.sax.SAXException {
            String dir = attributes.getValue("dir");
            String packageName = attributes.getValue("packageName");
            if (!checkNonEmpty(dir) && !checkNonEmpty(packageName)) {
                throw new SAXException(
                    "dir and packageName attributes must be fixed in packageGroup node");
            }
            File dirFile = new File(dir);
            try {
                group = new Group(dirFile, packageName, null, false,
                        this.manager);
                indexGlobal = 0;
            } catch (BrowsePackageException e) {
                logger.warn("Can't create a package group");
                throw new SAXException("Can't create a package group", e);
            }
            String groupName = attributes.getValue("name");
            if (checkNonEmpty(groupName)) {
                group.setName(groupName);
            }
            String description = attributes.getValue("description");
            if (checkNonEmpty(description)) {
                group.setDescription(description);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Group " + group.getName() + " added");
            }
            manager.add(group);
        }

        protected void notifyEndActiveHandler(String name,
            UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
            if (name.equalsIgnoreCase(UNIT_TEST_TAG)) {
                AbstractTest test = (AbstractTest) activeHandler.getResultObject();
                if (excludesTests.contains(test)) {
                    // Rmove the test
                    group.remove(group.indexOf(test));
                    return;
                }
                int index = group.indexOf(test);
                if (index < group.size()) {
                    //group.add(index, group.get(this.indexGlobal));
                    group.add(this.indexGlobal, test);
                    group.remove(index + 1);
                    //group.remove(this.indexGlobal);
                    this.indexGlobal++;
                }
            }
        }
    }

    //-----------------------------------------------------------------------------------------------------------
    private static class UnitTestHandler extends AbstractUnmarshallerDecorator {
        private AbstractTest test = null;
        private AbstractManager manager = null;

        UnitTestHandler(AbstractManager manager) {
            super();
            this.manager = manager;
        }

        public Object getResultObject() throws org.xml.sax.SAXException {
            return test;
        }

        public void startContextElement(String name, Attributes attributes)
            throws org.xml.sax.SAXException {
            Logger logger = manager.getLogger();
            String className = attributes.getValue("class");
            String excludeFlag = attributes.getValue("exclude");

            if (checkNonEmpty(className)) {
                try {
                    Class c = this.getClass().getClassLoader().loadClass(className);
                    test = (AbstractTest) c.newInstance();
                    test.setManager(this.manager);
                } catch (ClassNotFoundException e) {
                    logger.fatal("Can't found " + className, e);
                } catch (InstantiationException e) {
                    logger.fatal("Can't create a new instance of " + className,
                        e);
                } catch (IllegalAccessException e) {
                    logger.fatal("Can't access " + className, e);
                }
            }

            // Exclude this test or not ?
            if (checkNonEmpty(excludeFlag)) {
                if (excludeFlag.toUpperCase().compareTo("YES") == 0) {
                    PackageGroupHandler.excludesTests.add(test);
                    logger.debug("The test " + test + " is exclude");
                }
            }
        }

        protected void notifyEndActiveHandler(String name,
            UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
        }
    }
}<commit_msg>Fixed for testing  test that doesn't exist<commit_after>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
 * Contact: <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://www.inria.fr/oasis/ProActive/contacts.html
 *  Contributor(s):
 *
 * ################################################################
 */
package testsuite.xml;

import java.io.File;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator;
import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler;
import org.objectweb.proactive.core.xml.io.Attributes;
import org.xml.sax.SAXException;

import testsuite.exception.BrowsePackageException;
import testsuite.group.Group;
import testsuite.manager.AbstractManager;
import testsuite.test.AbstractTest;


/**
 * @author <NAME>
 *
 */
public class GroupHandler {
    //-----------------------------------------------------------------------------------------------------------
    public static class SimpleGroupHandler extends AbstractUnmarshallerDecorator
        implements ManagerDescriptorConstants {
        private Group group = null;
        private AbstractManager manager = null;

        SimpleGroupHandler(AbstractManager manager) {
            super();
            this.manager = manager;
            addHandler(UNIT_TEST_TAG, new UnitTestHandler(manager));
        }

        public Object getResultObject() throws org.xml.sax.SAXException {
            return group;
        }

        public void startContextElement(String name, Attributes attributes)
            throws org.xml.sax.SAXException {
            group = new Group();
            String groupName = attributes.getValue("name");
            if (checkNonEmpty(groupName)) {
                group.setName(groupName);
            }
            String description = attributes.getValue("description");
            if (checkNonEmpty(description)) {
                group.setDescription(description);
            }
            manager.add(group);
        }

        protected void notifyEndActiveHandler(String name,
            UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
            if (name.equalsIgnoreCase(UNIT_TEST_TAG)) {
                group.add((AbstractTest) activeHandler.getResultObject());
            }
        }
    }

    //-----------------------------------------------------------------------------------------------------------
    public static class PackageGroupHandler
        extends AbstractUnmarshallerDecorator
        implements ManagerDescriptorConstants {
        private Group group = null;
        private AbstractManager manager = null;
        private static Vector excludesTests = new Vector();

        PackageGroupHandler(AbstractManager manager) {
            super();
            this.manager = manager;
            addHandler(UNIT_TEST_TAG, new UnitTestHandler(manager));
        }

        public Object getResultObject() throws org.xml.sax.SAXException {
            return group;
        }

        private int indexGlobal = 0;

        public void startContextElement(String name, Attributes attributes)
            throws org.xml.sax.SAXException {
            String dir = attributes.getValue("dir");
            String packageName = attributes.getValue("packageName");
            if (!checkNonEmpty(dir) && !checkNonEmpty(packageName)) {
                throw new SAXException(
                    "dir and packageName attributes must be fixed in packageGroup node");
            }
            File dirFile = new File(dir);
            try {
                group = new Group(dirFile, packageName, null, false,
                        this.manager);
                indexGlobal = 0;
            } catch (BrowsePackageException e) {
                logger.warn("Can't create a package group");
                throw new SAXException("Can't create a package group", e);
            }
            String groupName = attributes.getValue("name");
            if (checkNonEmpty(groupName)) {
                group.setName(groupName);
            }
            String description = attributes.getValue("description");
            if (checkNonEmpty(description)) {
                group.setDescription(description);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Group " + group.getName() + " added");
            }
            manager.add(group);
        }

        protected void notifyEndActiveHandler(String name,
            UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
            if (name.equalsIgnoreCase(UNIT_TEST_TAG)) {
                AbstractTest test = (AbstractTest) activeHandler.getResultObject();
                if (excludesTests.contains(test)) {
                    // Rmove the test
                    group.remove(group.indexOf(test));
                    return;
                }
                int index = group.indexOf(test);
                if (index < group.size()) {
                    //group.add(index, group.get(this.indexGlobal));
                    group.add(this.indexGlobal, test);
                    group.remove(index + 1);
                    //group.remove(this.indexGlobal);
                    this.indexGlobal++;
                }
            }
        }
    }

    //-----------------------------------------------------------------------------------------------------------
    private static class UnitTestHandler extends AbstractUnmarshallerDecorator {
        private AbstractTest test = null;
        private AbstractManager manager = null;

        UnitTestHandler(AbstractManager manager) {
            super();
            this.manager = manager;
        }

        public Object getResultObject() throws org.xml.sax.SAXException {
            return test;
        }

        public void startContextElement(String name, Attributes attributes)
            throws org.xml.sax.SAXException {
            Logger logger = manager.getLogger();
            String className = attributes.getValue("class");
            String excludeFlag = attributes.getValue("exclude");

            if (checkNonEmpty(className)) {
                try {
                    Class c = this.getClass().getClassLoader().loadClass(className);
                    test = (AbstractTest) c.newInstance();
                    test.setManager(this.manager);
                } catch (ClassNotFoundException e) {
                    logger.fatal("Can't found " + className, e);
                    throw new RuntimeException(e);
                } catch (InstantiationException e) {
                    logger.fatal("Can't create a new instance of " + className,
                        e);
                    throw new RuntimeException(e);
                } catch (IllegalAccessException e) {
                    logger.fatal("Can't access " + className, e);
                    throw new RuntimeException(e);
                }
            }

            // Exclude this test or not ?
            if (checkNonEmpty(excludeFlag)) {
                if (excludeFlag.toUpperCase().compareTo("YES") == 0) {
                    PackageGroupHandler.excludesTests.add(test);
                    logger.debug("The test " + test + " is exclude");
                }
            }
        }

        protected void notifyEndActiveHandler(String name,
            UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException {
        }
    }
}
{'fraction_non_alphanumeric': 0.13459930729726502, 'fraction_numerical': 0.003463513674907441, 'mean_word_length': 1.7832807046701014, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 28}, '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': '1768490', 'n_tokens_mistral': 3954, 'n_tokens_neox': 3762, 'n_words': 1005}