Home | History | Annotate | Download | only in ant
      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.ant;
     13 
     14 import java.io.File;
     15 import java.io.IOException;
     16 import java.io.UnsupportedEncodingException;
     17 import java.net.URLDecoder;
     18 
     19 import org.junit.Test;
     20 
     21 /**
     22  * Simple test target for Java applications ant JUnit4 tests. To assert
     23  * execution it creates an empty file <code>target.txt</code> in the working
     24  * directory.
     25  */
     26 public class TestTarget {
     27 
     28 	@Test
     29 	public void testNothing() throws IOException {
     30 		System.out.println("Target executed");
     31 	}
     32 
     33 	public static void main(String[] args) throws Exception {
     34 
     35 		// Load some class from the bootstrap classloader:
     36 		new java.sql.Timestamp(0);
     37 
     38 		System.out.println("Target executed");
     39 
     40 		// Wait for termination file to turn up
     41 		// This option puts the target in a pseudo 'server' mode
     42 		if (args.length == 1) {
     43 			final File termFile = new File(args[0]);
     44 
     45 			while (!termFile.exists()) {
     46 				Thread.sleep(100);
     47 			}
     48 		}
     49 	}
     50 
     51 	/**
     52 	 * @return location where this class is located
     53 	 */
     54 	public static String getClassPath() {
     55 		final String name = TestTarget.class.getName();
     56 		final String res = "/" + name.replace('.', '/') + ".class";
     57 		String loc = TestTarget.class.getResource(res).getFile();
     58 		try {
     59 			loc = URLDecoder.decode(loc, "UTF-8");
     60 		} catch (UnsupportedEncodingException e) {
     61 		}
     62 		return loc.substring(0, loc.length() - res.length());
     63 	}
     64 
     65 }
     66