<commit_before>/*
 *
 * Derby - Class org.apache.derbyTesting.junit.SecurityManagerSetup
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.derbyTesting.junit;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.Policy;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Enumeration;
import java.util.Properties;
import junit.extensions.TestSetup;
import junit.framework.Test;
import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;

/**
 * Configures the wrapped test to be run with the specified security policy.
 * <p>
 * This setup class normally installs the default policy file. This can be
 * overridden by specifying {@literal java.security.policy=<NONE>} (see
 * {@linkplain #NO_POLICY}), and can also be overridden by installing a
 * security manager explicitly before the default security manager is installed.
 * <p>
 * Individual tests/suites can be configured to be run without a security
 * manager, with a specific policy file, or with a specific policy file merged
 * with the default policy file. The last option is useful when you only need
 * to extend the default policy with a few extra permissions to run a test.
 */
public final class SecurityManagerSetup extends TestSetup {

    /** Constant used to indicate that no security policy is to be installed. */
    static final String NO_POLICY = "<NONE>";

    /**
     * Does the JVM support Subjects for
     * authorization through Java security manager.
     * J2ME/CDC/Foundation 1.1 does not support Subjects.
     */
    public static final boolean JVM_HAS_SUBJECT_AUTHORIZATION;
    static {
        JVM_HAS_SUBJECT_AUTHORIZATION = JDBC.haveClass("javax.security.auth.Subject");
    }
    
	
	private static final Properties classPathSet = new Properties();
    
    /**
     * True if the classes are loaded from jars.
     */
    static boolean isJars;
	
	/**
	 * True if a security manager was installed outside of the
	 * control of this class and BaseTestCase.
	 */
	private static final boolean externalSecurityManagerInstalled;
	
	static {
		// Determine what the set of properties
		// describing the environment is.
		externalSecurityManagerInstalled = determineClasspath();
        
	}

    static {
        // Work around bug in weme6.2 (DERBY-5558 and DERBY-6079).
        if (BaseTestCase.isJ9Platform()) {
            BaseTestCase.setSystemProperty("emma.active", "");
            BaseTestCase.setSystemProperty("jacoco.active", "");
        }
    }

    static final boolean jacocoEnabled = checkIfJacocoIsRunning();
    private static boolean checkIfJacocoIsRunning() {
        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                public Boolean run() {
                    try {
                        Class.forName("org.jacoco.agent.rt.RT");
                        return true;<commit_msg>DERBY-6736: The jacoco-junit target fails to store coverage data for some sub-suites<commit_after>/*
 *
 * Derby - Class org.apache.derbyTesting.junit.SecurityManagerSetup
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.derbyTesting.junit;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.Policy;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Enumeration;
import java.util.Properties;
import junit.extensions.TestSetup;
import junit.framework.Test;
import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;

/**
 * Configures the wrapped test to be run with the specified security policy.
 * <p>
 * This setup class normally installs the default policy file. This can be
 * overridden by specifying {@literal java.security.policy=<NONE>} (see
 * {@linkplain #NO_POLICY}), and can also be overridden by installing a
 * security manager explicitly before the default security manager is installed.
 * <p>
 * Individual tests/suites can be configured to be run without a security
 * manager, with a specific policy file, or with a specific policy file merged
 * with the default policy file. The last option is useful when you only need
 * to extend the default policy with a few extra permissions to run a test.
 */
public final class SecurityManagerSetup extends TestSetup {

    /** Constant used to indicate that no security policy is to be installed. */
    static final String NO_POLICY = "<NONE>";

    /**
     * Does the JVM support Subjects for
     * authorization through Java security manager.
     * J2ME/CDC/Foundation 1.1 does not support Subjects.
     */
    public static final boolean JVM_HAS_SUBJECT_AUTHORIZATION;
    static {
        JVM_HAS_SUBJECT_AUTHORIZATION = JDBC.haveClass("javax.security.auth.Subject");
    }
    
	
	private static final Properties classPathSet = new Properties();
    
    /**
     * True if the classes are loaded from jars.
     */
    static boolean isJars;
	
	/**
	 * True if a security manager was installed outside of the
	 * control of this class and BaseTestCase.
	 */
	private static final boolean externalSecurityManagerInstalled;
	
	static {
		// Determine what the set of properties
		// describing the environment is.
		externalSecurityManagerInstalled = determineClasspath();
        
	}

    static {
        // Work around bug in weme6.2 (DERBY-5558 and DERBY-6079).
        if (BaseTestCase.isJ9Platform()) {
            BaseTestCase.setSystemProperty("emma.active", "");
            BaseTestCase.setSystemProperty("jacoco.active", "");
        }
    }

    static final boolean jacocoEnabled = checkIfJacocoIsRunning();
    private static boolean checkIfJacocoIsRunning() {
        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                public Boolean run() {
                    try {
                        // Check if some arbitrary class from jacocoagent.jar
                        // is available.
                        Class.forName("org.jacoco.agent.rt.RT");

                        // If we got here, it means the tests are running
                        // under JaCoCo. Set the jacoco.active property to
                        // the empty string in order to activate the
                        // JaCoCo-specific permissions in derby_tests.policy,
                        // and return true.
                        System.setProperty("jacoco.active", "");
                        return true;
{'fraction_non_alphanumeric': 0.0740873299928418, 'fraction_numerical': 0.004772130756382725, 'mean_word_length': 3.115365733922435, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5452328', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2081, 'n_words': 824}