<commit_before>/*
 * Copyright 2002-2006 the original author or authors.
 * 
 * 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.
 */
package org.springframework.osgi.test;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

import junit.framework.TestCase;
import junit.framework.TestResult;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.osgi.test.platform.EquinoxPlatform;
import org.springframework.osgi.test.platform.FelixPlatform;
import org.springframework.osgi.test.platform.KnopflerfishPlatform;
import org.springframework.osgi.test.platform.OsgiPlatform;
import org.springframework.util.Assert;

/**
 *
 * Base teste for OSGi environments. It will start the OSGi platform, install
 * the given bundles and then delegate the execution to a test copy which
 * executes inside OSGi.
 *
 * @author <NAME>
 *
 */
public abstract class AbstractOsgiTests extends TestCase implements OsgiJUnitTest {

	// JVM shutdown hook
	private static Thread shutdownHook;

	// the OSGi fixture
	private static OsgiPlatform osgiPlatform;
	private static BundleContext context;
	private static Bundle[] bundles;

	// JUnit Service
	private static Object service;
	// JUnitService trigger
	private static Method serviceTrigger;

	private ObjectInputStream inputStream;
	private ObjectOutputStream outputStream;

	// the test results used by the triggering test runner
	private TestResult originalResult;

    // The OSGi BundleContext
    private BundleContext bundleContext;

    private static final String ACTIVATOR_REFERENCE = "org.springframework.osgi.test.JUnitTestActivator";

	public static final String EQUINOX_PLATFORM = "equinox";
	public static final String KNOPFLERFISH_PLATFORM = "knopflerfish";
	public static final String FELIX_PLATFORM = "felix";

	public static final String OSGI_FRAMEWORK_SELECTOR = "org.springframework.osgi.test.framework";

	protected final Log log = LogFactory.getLog(getClass());

	private static String getSpringOSGiTestBundleUrl() {
		return localMavenArtifact("org.springframework.osgi.test", "1.0-SNAPSHOT");
	}

	private static String getSpringCoreBundleUrl() {
		return localMavenArtifact("spring-core", "2.1-SNAPSHOT");
	}

	private static String getLog4jLibUrl() {
		return localMavenArtifact("log4j.osgi", "1.2.13-SNAPSHOT");
	}

	private static String getCommonsLoggingLibUrl() {
		return localMavenArtifact("commons-logging.osgi", "1.1-SNAPSHOT");
	}
	
	private static String getJUnitLibUrl() {
		return localMavenArtifact("junit.osgi", "3.8.1-SNAPSHOT");
	}



    /**
     * Answer the url string of the indicated bundle in the local Maven repository
     *
     * @param groupId - the groupId of the organization supplying the bundle
     * @param artifact - the artifact id of the bundle
     * @param version - the version of the bundle
     * @return the String representing the URL location of this bundle
     */
    public static String localMavenBundle(String groupId, String artifact, String version) {
		File userHome = new File(System.getProperty("user.home"));
		File repositoryHome = new File(userHome, ".m2/repository");
        String location = groupId.replace('.', '/');
        location += '/';
        location += artifact;
        location += '/';
        location += version;
        location += '/';
        location += artifact;
        location += '-';
        location += version;
        location += ".jar";
        return "file:" + new File(repositoryHome, location).getAbsolutePath();
    }
    
    public static String localMavenArtifact(String artifactId, String version) {
    	try {
    		File found = new MavenPackagedArtifactFinder(artifactId,version).findPackagedArtifact(new File("."));
    		return found.toURL().toExternalForm();
    	} catch (IOException ioEx) {
    		throw new IllegalStateException(
    			"Artifact " + artifactId + "-" + version + ".jar" + 
    			" could not be found",ioEx);
    	}
    }

	/**
	 * Bundles that should be installed before the test execution.
	 *
	 * @return the array of bundles to install
	 */
	protected String[] getBundleLocations() {
		return new String[] {};
	}

	/**
	 * Mandator bundles (part of the test setup).
	 *
	 * @return the array of mandatory bundle names
	 */
	private String[] getMandatoryBundles() {
		return new String[] { 
				getJUnitLibUrl(),<commit_msg>+ removed static modified on some methods + changed getMandatoryBundles from private to protected<commit_after>/*
 * Copyright 2002-2006 the original author or authors.
 * 
 * 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.
 */
package org.springframework.osgi.test;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

import junit.framework.TestCase;
import junit.framework.TestResult;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.osgi.test.platform.EquinoxPlatform;
import org.springframework.osgi.test.platform.FelixPlatform;
import org.springframework.osgi.test.platform.KnopflerfishPlatform;
import org.springframework.osgi.test.platform.OsgiPlatform;
import org.springframework.util.Assert;

/**
 *
 * Base teste for OSGi environments. It will start the OSGi platform, install
 * the given bundles and then delegate the execution to a test copy which
 * executes inside OSGi.
 *
 * @author <NAME>
 *
 */
public abstract class AbstractOsgiTests extends TestCase implements OsgiJUnitTest {

	// JVM shutdown hook
	private static Thread shutdownHook;

	// the OSGi fixture
	private static OsgiPlatform osgiPlatform;
	private static BundleContext context;
	private static Bundle[] bundles;

	// JUnit Service
	private static Object service;
	// JUnitService trigger
	private static Method serviceTrigger;

	private ObjectInputStream inputStream;
	private ObjectOutputStream outputStream;

	// the test results used by the triggering test runner
	private TestResult originalResult;

    // The OSGi BundleContext
    private BundleContext bundleContext;

    private static final String ACTIVATOR_REFERENCE = "org.springframework.osgi.test.JUnitTestActivator";

	public static final String EQUINOX_PLATFORM = "equinox";
	public static final String KNOPFLERFISH_PLATFORM = "knopflerfish";
	public static final String FELIX_PLATFORM = "felix";

	public static final String OSGI_FRAMEWORK_SELECTOR = "org.springframework.osgi.test.framework";

	protected final Log log = LogFactory.getLog(getClass());

	private String getSpringOSGiTestBundleUrl() {
		return localMavenArtifact("org.springframework.osgi.test", "1.0-SNAPSHOT");
	}

	private String getSpringCoreBundleUrl() {
		return localMavenArtifact("spring-core", "2.1-SNAPSHOT");
	}

	private String getLog4jLibUrl() {
		return localMavenArtifact("log4j.osgi", "1.2.13-SNAPSHOT");
	}

	private String getCommonsLoggingLibUrl() {
		return localMavenArtifact("commons-logging.osgi", "1.1-SNAPSHOT");
	}
	
	private String getJUnitLibUrl() {
		return localMavenArtifact("junit.osgi", "3.8.1-SNAPSHOT");
	}



    /**
     * Answer the url string of the indicated bundle in the local Maven repository
     *
     * @param groupId - the groupId of the organization supplying the bundle
     * @param artifact - the artifact id of the bundle
     * @param version - the version of the bundle
     * @return the String representing the URL location of this bundle
     */
    public static String localMavenBundle(String groupId, String artifact, String version) {
		File userHome = new File(System.getProperty("user.home"));
		File repositoryHome = new File(userHome, ".m2/repository");
        String location = groupId.replace('.', '/');
        location += '/';
        location += artifact;
        location += '/';
        location += version;
        location += '/';
        location += artifact;
        location += '-';
        location += version;
        location += ".jar";
        return "file:" + new File(repositoryHome, location).getAbsolutePath();
    }
    
    public static String localMavenArtifact(String artifactId, String version) {
    	try {
    		File found = new MavenPackagedArtifactFinder(artifactId,version).findPackagedArtifact(new File("."));
    		return found.toURL().toExternalForm();
    	} catch (IOException ioEx) {
    		throw new IllegalStateException(
    			"Artifact " + artifactId + "-" + version + ".jar" + 
    			" could not be found",ioEx);
    	}
    }

	/**
	 * Bundles that should be installed before the test execution.
	 *
	 * @return the array of bundles to install
	 */
	protected String[] getBundleLocations() {
		return new String[] {};
	}

	/**
	 * Mandator bundles (part of the test setup).
	 *
	 * @return the array of mandatory bundle names
	 */
	protected String[] getMandatoryBundles() {
		return new String[] { 
				getJUnitLibUrl(),
{'fraction_non_alphanumeric': 0.09432736050505988, 'fraction_numerical': 0.0051991458546096, 'mean_word_length': 4.012563983248023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '146779', 'n_tokens_mistral': 3129, 'n_tokens_neox': 2962, 'n_words': 926}