dev.jbang.source.SourceSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbang-cli Show documentation
Show all versions of jbang-cli Show documentation
JBang Command Line Interface
package dev.jbang.source;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import dev.jbang.dependencies.DependencyResolver;
import dev.jbang.util.Util;
/**
* This class combines source files, resources and dependencies that are
* considered to be a single unit. Together with the information in a
* Project
and possibly other SourceSets
it can be
* turned into something that can be executed.
*/
public class SourceSet {
private final List sources = new ArrayList<>();
private final List resources = new ArrayList<>();
private final List dependencies = new ArrayList<>();
private final List classPaths = new ArrayList<>();
private final List compileOptions = new ArrayList<>();
private final List nativeOptions = new ArrayList<>();
@Nonnull
public List getSources() {
return Collections.unmodifiableList(sources);
}
@Nonnull
public SourceSet addSource(ResourceRef source) {
sources.add(source);
return this;
}
@Nonnull
public SourceSet addSources(Collection sources) {
this.sources.addAll(sources);
return this;
}
@Nonnull
public List getResources() {
return Collections.unmodifiableList(resources);
}
@Nonnull
public SourceSet addResource(RefTarget resource) {
resources.add(resource);
return this;
}
@Nonnull
public SourceSet addResources(Collection resources) {
this.resources.addAll(resources);
return this;
}
@Nonnull
public List getDependencies() {
return Collections.unmodifiableList(dependencies);
}
@Nonnull
public SourceSet addDependency(String dependency) {
dependencies.add(dependency);
return this;
}
@Nonnull
public SourceSet addDependencies(Collection dependencies) {
this.dependencies.addAll(dependencies);
return this;
}
@Nonnull
public List getClassPaths() {
return Collections.unmodifiableList(classPaths);
}
@Nonnull
public SourceSet addClassPath(String classPath) {
classPaths.add(classPath);
return this;
}
@Nonnull
public SourceSet addClassPaths(Collection classPaths) {
this.classPaths.addAll(classPaths);
return this;
}
@Nonnull
public List getCompileOptions() {
return Collections.unmodifiableList(compileOptions);
}
@Nonnull
public SourceSet addCompileOption(String option) {
compileOptions.add(option);
return this;
}
@Nonnull
public SourceSet addCompileOptions(Collection options) {
compileOptions.addAll(options);
return this;
}
@Nonnull
public List getNativeOptions() {
return Collections.unmodifiableList(nativeOptions);
}
@Nonnull
public SourceSet addNativeOption(String option) {
nativeOptions.add(option);
return this;
}
@Nonnull
public SourceSet addNativeOptions(Collection options) {
nativeOptions.addAll(options);
return this;
}
@Nonnull
public DependencyResolver updateDependencyResolver(DependencyResolver resolver) {
return resolver.addDependencies(dependencies).addClassPaths(classPaths);
}
public void copyResourcesTo(Path dest) {
for (RefTarget file : resources) {
file.copy(dest);
}
}
protected Stream getStableIdInfo() {
Stream srcs = sources.stream().map(src -> Util.readFileContent(src.getFile()));
Stream ress = resources.stream().map(res -> Util.readFileContent(res.getSource().getFile()));
return Stream.concat(srcs, ress);
}
}