package aQute.bnd.exporter.executable;

import java.util.AbstractMap.SimpleEntry;
import java.util.Map;
import java.util.Map.Entry;

import aQute.bnd.annotation.plugin.BndPlugin;
import aQute.bnd.build.Project;
import aQute.bnd.build.ProjectLauncher;
import aQute.bnd.osgi.Jar;
import aQute.bnd.osgi.JarResource;
import aQute.bnd.osgi.Resource;
import aQute.bnd.service.export.Exporter;
import aQute.lib.converter.Converter;

@BndPlugin(name = "exporter.executablejar")
public class ExecutableJarExporter implements Exporter {
	public static final String EXECUTABLE_JAR = "bnd.executablejar";

	interface Configuration {
		boolean keep();
	}

	public ExecutableJarExporter() {}

	@Override
	public String[] getTypes() {
		return new String[] {
			EXECUTABLE_JAR
		};
	}

	@Override
	public Entry<String, Resource> export(String type, Project project, Map<String, String> options) throws Exception {
		Configuration configuration = Converter.cnv(Configuration.class, options);
		project.prepare();
		try (ProjectLauncher launcher = project.getProjectLauncher()) {
			launcher.setKeep(configuration.keep());
			Jar jar = launcher.executable();
			project.getInfo(launcher);
			return new SimpleEntry<>(jar.getName(), new JarResource(jar, true));
		}
	}
}

@@ -240,24 +240,57 @@
 ctLauncher;%0A
+import aQute.bnd.osgi.Constants;%0A
 import aQute
@@ -450,16 +450,50 @@
 nverter;
+%0Aimport aQute.lib.strings.Strings;
 %0A%0A@BndPl
@@ -1231,16 +1231,261 @@
 uncher);
+%0A%0A%09%09%09String name = jar.getName();%0A%09%09%09String%5B%5D baseext = Strings.extension(name);%0A%09%09%09if (baseext != null && (%22bnd%22.equals(baseext%5B1%5D) %7C%7C %22bndrun%22.equals(baseext%5B1%5D))) %7B%0A%09%09%09%09name = baseext%5B0%5D;%0A%09%09%09%7D%0A%09%09%09name = name + Constants.DEFAULT_JAR_EXTENSION;
 %0A%09%09%09retu
@@ -1505,29 +1505,20 @@
 Entry%3C%3E(
-jar.getN
+n
 ame
-()
 , new Ja

Set name in result to the desired output name