2020import org .gradle .api .tasks .SourceSet ;
2121import org .gradle .api .tasks .SourceSetContainer ;
2222import org .gradle .jvm .tasks .Jar ;
23+ import org .gradle .language .jvm .tasks .ProcessResources ;
2324
2425import javax .inject .Inject ;
2526
27+ import java .io .File ;
28+ import java .io .IOException ;
29+ import java .io .UncheckedIOException ;
30+ import java .util .Optional ;
31+ import java .util .jar .JarEntry ;
32+ import java .util .jar .JarFile ;
33+
2634import static java .util .stream .Collectors .toList ;
2735
2836/**
@@ -60,6 +68,8 @@ public void apply(final Project project) {
6068
6169 SourceSetContainer sourceSets = project .getExtensions ().getByType (SourceSetContainer .class );
6270
71+ // TODO: we no longer care about descriptor remove as inputs
72+ // TODO: we no longer care about policy-yaml file remove as inputs
6373 var testBuildInfoTask = project .getTasks ().register ("generateTestBuildInfo" , GenerateTestBuildInfoTask .class , task -> {
6474 var pluginProperties = project .getTasks ().withType (GeneratePluginPropertiesTask .class ).named ("pluginProperties" );
6575 task .getDescriptorFile ().set (pluginProperties .flatMap (GeneratePluginPropertiesTask ::getOutputFile ));
@@ -69,12 +79,31 @@ public void apply(final Project project) {
6979 if (policy .getAsFile ().exists ()) {
7080 task .getPolicyFile ().set (policy );
7181 }
72- task .getCodeLocations ().set (
73- project .getConfigurations ()
82+ // TODO: get first class of each location in deterministic order
83+ // TODO: filter META_INF and module-info.class out of these
84+ for (File file : project .getConfigurations ()
85+ .getByName ("runtimeClasspath" )
86+ .minus (project .getConfigurations ().getByName (CompileOnlyResolvePlugin .RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME ))
87+ .plus (sourceSets .getByName (SourceSet .MAIN_SOURCE_SET_NAME ).getOutput ().getClassesDirs ()).getFiles ()) {
88+ project .getLogger ().lifecycle ("HELLO: " + file .getAbsolutePath () + " - " + file .isDirectory ());
89+ if (file .getName ().endsWith (".jar" )) {
90+ try (JarFile jarFile = new JarFile (file )) {
91+ Optional <JarEntry > jarEntry = jarFile .stream ()
92+ .filter (je -> je .getName ().startsWith ("META-INF" ) || je .getName ().endsWith ("module-info.class" ) || je .getName ().endsWith (".class" ) == false ).findFirst ();
93+ if (jarEntry .isPresent ()) {
94+ project .getLogger ().lifecycle ("ENTRY: " + jarEntry .get ().getName ());
95+ }
96+ //project.getLogger().lifecycle("LIST: " + jarFile.stream().toList());
97+ } catch (IOException ioe ) {
98+ throw new UncheckedIOException (ioe );
99+ }
100+ }
101+ }
102+
103+ task .getCodeLocations ().set (project .getConfigurations ()
74104 .getByName ("runtimeClasspath" )
75105 .minus (project .getConfigurations ().getByName (CompileOnlyResolvePlugin .RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME ))
76106 .plus (sourceSets .getByName (SourceSet .MAIN_SOURCE_SET_NAME ).getOutput ().getClassesDirs ())
77- .plus (sourceSets .getByName (SourceSet .TEST_SOURCE_SET_NAME ).getOutput ().getClassesDirs ())
78107 );
79108
80109 Provider <Directory > directory = project .getLayout ()
@@ -87,11 +116,12 @@ public void apply(final Project project) {
87116 sourceSet .getResources ().srcDir (testBuildInfoTask );
88117 });
89118
90- // TODO: get the jar task
91- // TODO: configure on this task
92- // TODO: task.from()
93- //project.getLogger().lifecycle(
94- // "HELLO: " + project.getTasks().withType(Jar.class).getByName("jar").getArchiveFile().get().getAsFile().getAbsolutePath());
119+ project .getTasks ().withType (ProcessResources .class ).named ("processResources" ).configure (task -> {
120+ // TODO: this is a copy task
121+ // TODO: do this for descriptor and policy-yaml file
122+ // TODO: use child copy spec
123+ //task.into()
124+ });
95125 }
96126
97127}
0 commit comments