mirror of
https://github.com/jlengrand/jreleaser.git
synced 2026-03-10 08:31:24 +00:00
[assemble] allow additional files to be packaged with native image. Resolves #222
This commit is contained in:
@@ -128,6 +128,8 @@ public class NativeImageAssemblerProcessor extends AbstractAssemblerProcessor<Na
|
||||
try {
|
||||
Path tempDirectory = Files.createTempDirectory("jreleaser");
|
||||
Files.copy(image, tempDirectory.resolve(image.getFileName()));
|
||||
context.getLogger().debug("copying files to {}", context.relativizeToBasedir(tempDirectory));
|
||||
copyFiles(context, tempDirectory);
|
||||
|
||||
Path imageZip = assembleDirectory.resolve(assembler.getName() + "-" + context.getModel().getProject().getResolvedVersion() + ".zip");
|
||||
FileUtils.zip(tempDirectory, imageZip);
|
||||
@@ -186,7 +188,7 @@ public class NativeImageAssemblerProcessor extends AbstractAssemblerProcessor<Na
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Path> copyJars(JReleaserContext context, Path libDirectory) throws AssemblerProcessingException {
|
||||
private Set<Path> copyJars(JReleaserContext context, Path destination) throws AssemblerProcessingException {
|
||||
Set<Path> paths = new LinkedHashSet<>();
|
||||
|
||||
// resolve all first
|
||||
@@ -199,13 +201,37 @@ public class NativeImageAssemblerProcessor extends AbstractAssemblerProcessor<Na
|
||||
|
||||
// copy all next
|
||||
try {
|
||||
Files.createDirectories(libDirectory);
|
||||
Files.createDirectories(destination);
|
||||
for (Path path : paths) {
|
||||
context.getLogger().debug("copying {}", path.getFileName());
|
||||
Files.copy(path, libDirectory.resolve(path.getFileName()), REPLACE_EXISTING);
|
||||
Files.copy(path, destination.resolve(path.getFileName()), REPLACE_EXISTING);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AssemblerProcessingException("Unexpected error when copying JAR files", e);
|
||||
throw new AssemblerProcessingException("Unexpected error when copying files", e);
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
private Set<Path> copyFiles(JReleaserContext context, Path destination) throws AssemblerProcessingException {
|
||||
Set<Path> paths = new LinkedHashSet<>();
|
||||
|
||||
// resolve all first
|
||||
for (Glob glob : assembler.getFiles()) {
|
||||
glob.getResolvedPaths(context).stream()
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach(paths::add);
|
||||
}
|
||||
|
||||
// copy all next
|
||||
try {
|
||||
Files.createDirectories(destination);
|
||||
for (Path path : paths) {
|
||||
context.getLogger().debug("copying {}", path.getFileName());
|
||||
Files.copy(path, destination.resolve(path.getFileName()), REPLACE_EXISTING);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new AssemblerProcessingException("Unexpected error when copying files", e);
|
||||
}
|
||||
|
||||
return paths;
|
||||
|
||||
@@ -35,6 +35,7 @@ public class NativeImage extends AbstractAssembler {
|
||||
private final Artifact graal = new Artifact();
|
||||
private final Artifact mainJar = new Artifact();
|
||||
private final List<Glob> jars = new ArrayList<>();
|
||||
private final List<Glob> files = new ArrayList<>();
|
||||
|
||||
public NativeImage() {
|
||||
super(NAME);
|
||||
@@ -51,6 +52,7 @@ public class NativeImage extends AbstractAssembler {
|
||||
setMainJar(nativeImage.mainJar);
|
||||
setArgs(nativeImage.args);
|
||||
setJars(nativeImage.jars);
|
||||
setFiles(nativeImage.files);
|
||||
}
|
||||
|
||||
public Artifact getGraal() {
|
||||
@@ -113,6 +115,25 @@ public class NativeImage extends AbstractAssembler {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Glob> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public void setFiles(List<Glob> files) {
|
||||
this.files.clear();
|
||||
this.files.addAll(files);
|
||||
}
|
||||
|
||||
public void addFiles(List<Glob> files) {
|
||||
this.files.addAll(files);
|
||||
}
|
||||
|
||||
public void addFile(Glob file) {
|
||||
if (null != file) {
|
||||
this.files.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void asMap(boolean full, Map<String, Object> props) {
|
||||
props.put("graal", graal.asMap(full));
|
||||
@@ -122,5 +143,10 @@ public class NativeImage extends AbstractAssembler {
|
||||
mappedJars.put("glob " + i, jars.get(i).asMap(full));
|
||||
}
|
||||
props.put("jars", mappedJars);
|
||||
Map<String, Map<String, Object>> mappedFiles = new LinkedHashMap<>();
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
mappedFiles.put("glob " + i, files.get(i).asMap(full));
|
||||
}
|
||||
props.put("files", mappedFiles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,13 @@ interface NativeImage extends Assembler {
|
||||
|
||||
void jars(Action<? super Glob> action)
|
||||
|
||||
void files(Action<? super Glob> action)
|
||||
|
||||
void graal(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Artifact) Closure<Void> action)
|
||||
|
||||
void mainJar(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Artifact) Closure<Void> action)
|
||||
|
||||
void jars(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Glob) Closure<Void> action)
|
||||
|
||||
void files(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Glob) Closure<Void> action)
|
||||
}
|
||||
@@ -48,6 +48,7 @@ class NativeImageImpl extends AbstractAssembler implements NativeImage {
|
||||
private final ArtifactImpl graal
|
||||
private final ArtifactImpl mainJar
|
||||
private final NamedDomainObjectContainer<GlobImpl> jars
|
||||
private final NamedDomainObjectContainer<GlobImpl> files
|
||||
|
||||
@Inject
|
||||
NativeImageImpl(ObjectFactory objects) {
|
||||
@@ -65,6 +66,14 @@ class NativeImageImpl extends AbstractAssembler implements NativeImage {
|
||||
glob
|
||||
}
|
||||
})
|
||||
files = objects.domainObjectContainer(GlobImpl, new NamedDomainObjectFactory<GlobImpl>() {
|
||||
@Override
|
||||
GlobImpl create(String name) {
|
||||
GlobImpl glob = objects.newInstance(GlobImpl, objects)
|
||||
glob.name = name
|
||||
glob
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,6 +98,11 @@ class NativeImageImpl extends AbstractAssembler implements NativeImage {
|
||||
action.execute(jars.maybeCreate("jars-${jars.size()}".toString()))
|
||||
}
|
||||
|
||||
@Override
|
||||
void files(Action<? super Glob> action) {
|
||||
action.execute(files.maybeCreate("files-${files.size()}".toString()))
|
||||
}
|
||||
|
||||
@Override
|
||||
void graal(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Artifact) Closure<Void> action) {
|
||||
ConfigureUtil.configure(action, graal)
|
||||
@@ -104,6 +118,11 @@ class NativeImageImpl extends AbstractAssembler implements NativeImage {
|
||||
ConfigureUtil.configure(action, jars.maybeCreate("jars-${jars.size()}".toString()))
|
||||
}
|
||||
|
||||
@Override
|
||||
void files(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Glob) Closure<Void> action) {
|
||||
ConfigureUtil.configure(action, files.maybeCreate("files-${files.size()}".toString()))
|
||||
}
|
||||
|
||||
@Override
|
||||
void setActive(String str) {
|
||||
if (isNotBlank(str)) {
|
||||
@@ -122,6 +141,9 @@ class NativeImageImpl extends AbstractAssembler implements NativeImage {
|
||||
for (GlobImpl glob : jars) {
|
||||
nativeImage.addJar(glob.toModel())
|
||||
}
|
||||
for (GlobImpl glob : files) {
|
||||
nativeImage.addFile(glob.toModel())
|
||||
}
|
||||
nativeImage
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ package org.jreleaser.maven.plugin;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* @author Andres Almiray
|
||||
* @since 0.2.0
|
||||
@@ -31,6 +29,7 @@ public class NativeImage extends AbstractAssembler {
|
||||
private final Artifact graal = new Artifact();
|
||||
private final Artifact mainJar = new Artifact();
|
||||
private final List<Glob> jars = new ArrayList<>();
|
||||
private final List<Glob> files = new ArrayList<>();
|
||||
|
||||
void setAll(NativeImage nativeImage) {
|
||||
super.setAll(nativeImage);
|
||||
@@ -38,6 +37,7 @@ public class NativeImage extends AbstractAssembler {
|
||||
setMainJar(nativeImage.mainJar);
|
||||
setArgs(nativeImage.args);
|
||||
setJars(nativeImage.jars);
|
||||
setFiles(nativeImage.files);
|
||||
}
|
||||
|
||||
public Artifact getGraal() {
|
||||
@@ -65,22 +65,6 @@ public class NativeImage extends AbstractAssembler {
|
||||
this.args.addAll(args);
|
||||
}
|
||||
|
||||
public void addArgs(List<String> args) {
|
||||
this.args.addAll(args);
|
||||
}
|
||||
|
||||
public void addArg(String arg) {
|
||||
if (isNotBlank(arg)) {
|
||||
this.args.add(arg.trim());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeArg(String arg) {
|
||||
if (isNotBlank(arg)) {
|
||||
this.args.remove(arg.trim());
|
||||
}
|
||||
}
|
||||
|
||||
public List<Glob> getJars() {
|
||||
return jars;
|
||||
}
|
||||
@@ -90,13 +74,12 @@ public class NativeImage extends AbstractAssembler {
|
||||
this.jars.addAll(jars);
|
||||
}
|
||||
|
||||
public void addJars(List<Glob> jars) {
|
||||
this.jars.addAll(jars);
|
||||
public List<Glob> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public void addJar(Glob jar) {
|
||||
if (null != jar) {
|
||||
this.jars.add(jar);
|
||||
}
|
||||
public void setFiles(List<Glob> files) {
|
||||
this.files.clear();
|
||||
this.files.addAll(files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,6 +604,8 @@ public final class JReleaserModelConverter {
|
||||
a.setTemplateDirectory(nativeImage.getTemplateDirectory());
|
||||
a.setGraal(convertArtifact(nativeImage.getGraal()));
|
||||
a.setMainJar(convertArtifact(nativeImage.getMainJar()));
|
||||
a.setJars(convertGlobs(nativeImage.getJars()));
|
||||
a.setFiles(convertGlobs(nativeImage.getFiles()));
|
||||
a.setArgs(nativeImage.getArgs());
|
||||
return a;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user