パッケージ com.kazurayam.unittest

クラス CodeSourcePathElementsUnderProjectDirectory

java.lang.Object
com.kazurayam.unittest.CodeSourcePathElementsUnderProjectDirectory

public final class CodeSourcePathElementsUnderProjectDirectory extends Object
This class gives a categorical name to the part "build/classes/java/test/" in a URL string of CodeSource object of a Java class, like "file:/Users/kazurayam/github/unittest-helper/preliminary-study/build/classes/java/test/". The CodeSourcePathElementUnderProjectDirectory (CSPEUPD for short) is dependent on the environment in which the class runs.

 import java.net.URL;
 import java.security.CodeSource;
 import java.security.ProjectionDomain;
 import org.testng.annotation.Test;

 public class S3FindingCodeSource() {
     @Test
     public void getLocationWhereTisClassIsFound() {
         ProtectionDomain pd = this.getClass().getProtectionDomain();
         CodeSource cs = pd.getCodeSource();
         URL url = cs.getLocation();
         System.out.println("codeSource URL=" + url.toString());
     }
 }
 
This will print something like this:

 codeSource URL=file:/Users/kazurayam/github/unittest-helper/preliminary-study/build/classes/java/test/
 
I call file:/Users/kazurayam/github/unittest-helper/preliminary-study/ as the "Project Directory", build/classes/java/test/ as the "CodeSource Path Elements Under Project Directory".