Skip to content

Commit fa7fca8

Browse files
author
Andreas Sinz
committed
Added new function to determine the package of a file
1 parent 8eb7b52 commit fa7fca8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/ro/redeul/google/go/sdk/GoSdkUtil.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,31 @@ public static String[] computeGoBuildCommand(String goExecName, String goBuilder
977977
return computeGoCommand(goExecName, goArgs);
978978
}
979979

980+
/**
981+
* Returns the Package, which the file belongs to
982+
* @param projectRoot Folder, where the project is located
983+
* @param file The file, which package we want to find out
984+
* @return
985+
*/
986+
public static String getPackageOfFile(String projectRoot, String file) {
987+
String pkg = null;
988+
989+
if(file.startsWith(projectRoot)) {
990+
String src = File.separator + "src" + File.separator;
991+
992+
String fileFolder = new File(file).getParent();
993+
994+
String relativePath = fileFolder.substring(projectRoot.length());
995+
if(relativePath.startsWith(src)) {
996+
pkg = relativePath.substring(src.length());
997+
} else {
998+
pkg = relativePath;
999+
}
1000+
}
1001+
1002+
return pkg;
1003+
}
1004+
9801005
public static String[] computeGoRunCommand(String goExecName, String goBuilderArgs, String goMainFile, String appArgs) {
9811006
String goArgs = String.format(
9821007
"%s %s %s %s",

0 commit comments

Comments
 (0)