All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.cobertura.util.ShutdownHooks Maven / Gradle / Ivy

Go to download

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.

The newest version!
package net.sourceforge.cobertura.util;
import net.sourceforge.cobertura.coveragedata.*;
public class ShutdownHooks {

	public static void saveGlobalProjectDataWithTomcatInits() {
		// Hack for Tomcat - by saving project data right now we force loading
		// of classes involved in this process (like ObjectOutputStream)
		// so that it won't be necessary to load them on JVM shutdown
		if (System.getProperty("catalina.home") != null) {
			ProjectData.saveGlobalProjectData();
			// Force the class loader to load some classes that are
			// required by our JVM shutdown hook.
			// TODO: Use ClassLoader.loadClass("whatever"); instead
			ClassData.class.toString();
			CoverageData.class.toString();
			CoverageDataContainer.class.toString();
			FileLocker.class.toString();
			LineData.class.toString();
			PackageData.class.toString();
			SourceFileData.class.toString();
		}

		// Add a hook to save the data when the JVM exits
		Runtime.getRuntime().addShutdownHook(new Thread(new SaveTimer()));
		// Possibly also save the coverage data every x seconds?
		//Timer timer = new Timer(true);
		//timer.schedule(saveTimer, 100);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy