All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.jbang.source.sources.JavaSource Maven / Gradle / Ivy

There is a newer version: 0.121.0
Show newest version
package dev.jbang.source.sources;

import static dev.jbang.util.JavaUtil.resolveInJavaHome;

import java.util.List;
import java.util.function.Function;

import dev.jbang.source.*;
import dev.jbang.source.AppBuilder;
import dev.jbang.source.buildsteps.CompileBuildStep;

public class JavaSource extends Source {

	public JavaSource(String script, Function replaceProperties) {
		super(script, replaceProperties);
	}

	public JavaSource(ResourceRef script, Function replaceProperties) {
		super(script, replaceProperties);
	}

	protected JavaSource(ResourceRef ref, String script, Function replaceProperties) {
		super(ref, script, replaceProperties);
	}

	@Override
	protected List getCompileOptions() {
		return tagReader.collectOptions("JAVAC_OPTIONS", "COMPILE_OPTIONS");
	}

	@Override
	protected List getNativeOptions() {
		return tagReader.collectOptions("NATIVE_OPTIONS");
	}

	@Override
	protected List getRuntimeOptions() {
		return tagReader.collectOptions("JAVA_OPTIONS", "RUNTIME_OPTIONS");
	}

	@Override
	public Builder getBuilder(BuildContext ctx) {
		return new JavaAppBuilder(ctx);
	}

	public static class JavaAppBuilder extends AppBuilder {
		public JavaAppBuilder(BuildContext ctx) {
			super(ctx);
		}

		@Override
		protected Builder getCompileBuildStep() {
			return new JavaCompileBuildStep();
		}

		public class JavaCompileBuildStep extends CompileBuildStep {

			public JavaCompileBuildStep() {
				super(JavaAppBuilder.this.ctx);
			}

			@Override
			protected String getCompilerBinary(String requestedJavaVersion) {
				return resolveInJavaHome("javac", requestedJavaVersion);
			}

			@Override
			protected String getMainExtension() {
				return ".java";
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy