aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.ant.test/src/org/jacoco/ant/TestTarget.java
blob: a78218f76b76cfa9ba60473876ae5fe07d7d0703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*******************************************************************************
 * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Marc R. Hoffmann - initial API and implementation
 *    
 *******************************************************************************/
package org.jacoco.ant;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import org.junit.Test;

/**
 * Simple test target for Java applications ant JUnit4 tests. To assert
 * execution it creates an empty file <code>target.txt</code> in the working
 * directory.
 */
public class TestTarget {

	@Test
	public void testNothing() throws IOException {
		System.out.println("Target executed");
	}

	public static void main(String[] args) throws Exception {

		// Load some class from the bootstrap classloader:
		new java.sql.Timestamp(0);

		System.out.println("Target executed");

		// Wait for termination file to turn up
		// This option puts the target in a pseudo 'server' mode
		if (args.length == 1) {
			final File termFile = new File(args[0]);

			while (!termFile.exists()) {
				Thread.sleep(100);
			}
		}
	}

	/**
	 * @return location where this class is located
	 */
	public static String getClassPath() {
		final String name = TestTarget.class.getName();
		final String res = "/" + name.replace('.', '/') + ".class";
		String loc = TestTarget.class.getResource(res).getFile();
		try {
			loc = URLDecoder.decode(loc, "UTF-8");
		} catch (UnsupportedEncodingException e) {
		}
		return loc.substring(0, loc.length() - res.length());
	}

}