1 /******************************************************************************* 2 * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 * This program and the accompanying materials are made available under 4 * the terms of the Eclipse Public License 2.0 which is available at 5 * http://www.eclipse.org/legal/epl-2.0 6 * 7 * SPDX-License-Identifier: EPL-2.0 8 * 9 * Contributors: 10 * Marc R. Hoffmann - initial API and implementation 11 * 12 *******************************************************************************/ 13 package org.jacoco.ant; 14 15 import java.io.File; 16 import java.io.IOException; 17 import java.io.UnsupportedEncodingException; 18 import java.net.URLDecoder; 19 20 import org.junit.Test; 21 22 /** 23 * Simple test target for Java applications ant JUnit4 tests. To assert 24 * execution it creates an empty file <code>target.txt</code> in the working 25 * directory. 26 */ 27 public class TestTarget { 28 29 @Test testNothing()30 public void testNothing() throws IOException { 31 System.out.println("Target executed"); 32 } 33 main(String[] args)34 public static void main(String[] args) throws Exception { 35 36 // Load some class from the bootstrap classloader: 37 new java.sql.Timestamp(0); 38 39 System.out.println("Target executed"); 40 41 // Wait for termination file to turn up 42 // This option puts the target in a pseudo 'server' mode 43 if (args.length == 1) { 44 final File termFile = new File(args[0]); 45 46 while (!termFile.exists()) { 47 Thread.sleep(100); 48 } 49 } 50 } 51 52 /** 53 * @return location where this class is located 54 */ getClassPath()55 public static String getClassPath() { 56 final String name = TestTarget.class.getName(); 57 final String res = "/" + name.replace('.', '/') + ".class"; 58 String loc = TestTarget.class.getResource(res).getFile(); 59 try { 60 loc = URLDecoder.decode(loc, "UTF-8"); 61 } catch (UnsupportedEncodingException e) { 62 } 63 return loc.substring(0, loc.length() - res.length()); 64 } 65 66 } 67