forked from hibernate/hibernate-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.gradle
25 lines (22 loc) · 1017 Bytes
/
utilities.gradle
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
apply plugin: UtilitiesPlugin
class UtilitiesPlugin implements Plugin<Project> {
def void apply(Project project) {
project.convention.plugins.utilities = new UtilitiesPluginDef()
}
}
class UtilitiesPluginDef {
public String determinePackageName(SourceDirectorySet sourceDirectorySet, File javaFile) {
final javaFileAbsolutePath = javaFile.absolutePath;
for ( File sourceDirectory : sourceDirectorySet.srcDirs ) {
final String sourceDirectoryAbsolutePath = sourceDirectory.absolutePath;
if ( javaFileAbsolutePath.startsWith( sourceDirectoryAbsolutePath ) ) {
final String javaFileRelativePath = javaFileAbsolutePath.substring(
sourceDirectoryAbsolutePath.length() + 1,
javaFileAbsolutePath.lastIndexOf( File.separator )
);
return javaFileRelativePath.replace( File.separator, "." );
}
}
throw new RuntimeException( "ugh" );
}
}