1 /******************************************************************************* 2 * Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Marc R. Hoffmann - initial API and implementation 10 * 11 *******************************************************************************/ 12 package org.jacoco.agent.rt.internal; 13 14 import java.lang.instrument.Instrumentation; 15 16 import org.jacoco.core.runtime.AgentOptions; 17 import org.jacoco.core.runtime.IRuntime; 18 import org.jacoco.core.runtime.ModifiedSystemClassRuntime; 19 20 /** 21 * The agent which is referred as the <code>Premain-Class</code>. The agent 22 * configuration is provided with the agent parameters in the command line. 23 */ 24 public final class PreMain { 25 PreMain()26 private PreMain() { 27 // no instances 28 } 29 30 /** 31 * This method is called by the JVM to initialize Java agents. 32 * 33 * @param options 34 * agent options 35 * @param inst 36 * instrumentation callback provided by the JVM 37 * @throws Exception 38 * in case initialization fails 39 */ premain(final String options, final Instrumentation inst)40 public static void premain(final String options, final Instrumentation inst) 41 throws Exception { 42 43 final AgentOptions agentOptions = new AgentOptions(options); 44 45 final Agent agent = Agent.getInstance(agentOptions); 46 47 final IRuntime runtime = createRuntime(inst); 48 runtime.startup(agent.getData()); 49 inst.addTransformer(new CoverageTransformer(runtime, agentOptions, 50 IExceptionLogger.SYSTEM_ERR)); 51 } 52 createRuntime(final Instrumentation inst)53 private static IRuntime createRuntime(final Instrumentation inst) 54 throws Exception { 55 return ModifiedSystemClassRuntime.createFor(inst, "java/util/UUID"); 56 } 57 58 } 59