Search in sources :

Example 1 with LogServiceImpl

use of org.apache.felix.ipojo.junit4osgi.plugin.log.LogServiceImpl in project felix by apache.

the class Junit4osgiPlugin method execute.

/**
 * Executes the plug-in.
 * @throws MojoFailureException when the test execution failed.
 * @see org.apache.maven.plugin.AbstractMojo#execute()
 */
public void execute() throws MojoFailureException {
    if (skip) {
        getLog().info("Tests are skipped");
        return;
    }
    List bundles = parseBundleList();
    bundles.addAll(getTestBundle());
    List activators = new ArrayList();
    m_logService = new LogServiceImpl();
    if (m_logEnable) {
        // Starts the log service if enabled
        activators.add(m_logService);
    } else {
        getLog().info("Log Service disabled");
    }
    activators.add(new Installer(m_pluginArtifacts, bundles, m_project, m_deployProjectArtifact));
    felixConf = new HashMap();
    felixConf.put("felix.systembundle.activators", activators);
    felixConf.put("org.osgi.framework.storage.clean", "onFirstInit");
    felixConf.put("ipojo.log.level", "WARNING");
    // Use a boot delagation to share classes between the host and the embedded Felix.
    // The cobertura package is used during code coverage collection
    // felixConf.put("org.osgi.framework.bootdelegation", "net.sourceforge.cobertura.coveragedata");
    felixConf.put("org.osgi.framework.system.packages.extra", "org.osgi.service.log;version=1.3, junit.framework;version=1.3");
    // felixConf.put("org.osgi.framework.system.packages.extra", "org.osgi.service.log, junit.framework");
    felixConf.put("org.osgi.framework.storage", m_targetDir.getAbsolutePath() + "/felix-cache");
    felixConf.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK);
    if (configuration != null) {
        felixConf.putAll(configuration);
    // Check boot delegation
    // String bd = (String) felixConf.get("org.osgi.framework.bootdelegation");
    // //            if (bd.indexOf("junit.framework") == -1) {
    // //                bd.concat(", junit.framework");
    // //            }
    // //            if (bd.indexOf("org.osgi.service.log") == -1) {
    // //                bd.concat(", org.osgi.service.log");
    // //            }
    // if (bd.indexOf("net.sourceforge.cobertura.coveragedata") == -1) {
    // bd.concat(", net.sourceforge.cobertura.coveragedata");
    // }
    }
    System.out.println("");
    System.out.println("-------------------------------------------------------");
    System.out.println(" T E S T S");
    System.out.println("-------------------------------------------------------");
    Felix felix = new Felix(felixConf);
    try {
        felix.start();
    } catch (BundleException e) {
        e.printStackTrace();
    }
    getLog().info("Felix started - Waiting for stability");
    waitForStability(felix.getBundleContext());
    getLog().info("Bundle Stability Reached - Waiting for runner service");
    Object runner = waitForRunnerService(felix.getBundleContext());
    if (runner == null) {
        throw new MojoFailureException("Cannot intialize the testing framework");
    }
    getLog().info("Runner Service available");
    invokeRun(runner, felix.getBundleContext());
    try {
        felix.stop();
        felix.waitForStop(5000);
        // Delete felix-cache
        File cache = new File(m_targetDir.getAbsolutePath() + "/felix-cache");
        cache.delete();
    } catch (Exception e) {
        getLog().error(e);
    }
    if (m_totalErrors > 0 || m_totalFailures > 0) {
        if (!testFailureIgnore) {
            throw new MojoFailureException("There are test failures. \n\n" + "Please refer to " + m_reportsDirectory.getAbsolutePath() + " for the individual test results.");
        } else {
            getLog().warn("There are test failures. \n\n" + "Please refer to " + m_reportsDirectory.getAbsolutePath() + " for the individual test results.");
        }
    }
}
Also used : LogServiceImpl(org.apache.felix.ipojo.junit4osgi.plugin.log.LogServiceImpl) HashMap(java.util.HashMap) Felix(org.apache.felix.framework.Felix) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) List(java.util.List) BundleException(org.osgi.framework.BundleException) JarFile(java.util.jar.JarFile) File(java.io.File) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MalformedURLException(java.net.MalformedURLException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 JarFile (java.util.jar.JarFile)1 Felix (org.apache.felix.framework.Felix)1 LogServiceImpl (org.apache.felix.ipojo.junit4osgi.plugin.log.LogServiceImpl)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 BundleException (org.osgi.framework.BundleException)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1