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.");
}
}
}
Aggregations