Skip to content

Commit

Permalink
make ArtifactDescriptor.file lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
siordache committed Sep 11, 2020
1 parent 82bb0f0 commit d2a279e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
26 changes: 20 additions & 6 deletions src/main/groovy/org/moditect/gradleplugin/ModitectExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import org.moditect.gradleplugin.generate.GenerateModuleInfoTask
import org.moditect.gradleplugin.image.CreateRuntimeImageTask
import org.moditect.model.DependencyDescriptor

import java.lang.module.FindException
import java.util.function.Supplier

import static org.moditect.gradleplugin.Util.createDirectoryProperty

@CompileStatic
Expand Down Expand Up @@ -102,20 +105,31 @@ class ModitectExtension {

Set<ArtifactDescriptor> descriptors = []
cfg.resolvedConfiguration.resolvedArtifacts.each { artifact ->
String autoModuleName = DependencyDescriptor.getAutoModuleNameFromInputJar(artifact.file.toPath(), null);
String autoModuleName = null
try {
autoModuleName = DependencyDescriptor.getAutoModuleNameFromInputJar(artifact.file.toPath(), null)
} catch (NoClassDefFoundError ncdfe) {
if(ncdfe.message?.contains('FindException')) {
LOGGER.info "Cannot get AutoModuleName of $artifact.file.name using Java < 9"
} else {
throw ncdfe
}
}
def info = artifact.moduleVersion.id
File inputJar
Supplier<File> inputJarProvider
if (autoModuleName != null) {
inputJar = artifact.file
inputJarProvider = { artifact.file }
} else {
String moduleName = assignedNamesByModules.get(new ModuleId(info.group, info.name))
inputJar = GenerateModuleInfo.createCopyWithAutoModuleNameManifestHeader(
inputJarProvider = {
GenerateModuleInfo.createCopyWithAutoModuleNameManifestHeader(
workingDirectory.get().asFile.toPath(),
artifact.file.toPath(),
moduleName
).toFile()
).toFile()
}
}
descriptors.add(new ArtifactDescriptor(info.group, info.name, inputJar))
descriptors.add(new ArtifactDescriptor(info.group, info.name, inputJarProvider))
}
LOGGER.info "assignedNamesByModules: ${assignedNamesByModules.collect {'\n\t' + it}}"
LOGGER.info "artifactDescriptors: ${descriptors.collect {'\n\t' + it}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
package org.moditect.gradleplugin.common

import groovy.transform.Canonical
import groovy.transform.ToString

import java.util.function.Supplier

@Canonical
@ToString(excludes = ['file', 'fileProvider'])
class ArtifactDescriptor {
String group
String name
File file
final String group
final String name
final Supplier<File> fileProvider
@Lazy volatile File file = { fileProvider.get() }()

ArtifactDescriptor(String group, String name, Supplier<File> fileProvider) {
this.group = group
this.name = name
this.fileProvider = fileProvider
}

boolean equals(o) {
if (this.is(o)) return true
Expand Down

0 comments on commit d2a279e

Please sign in to comment.