PortablePipelineJarCreator implements PortablePipelineRunner { @VisibleForTesting Manifest createManifest(Class mainClass, String defaultJobName) { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); boolean classHasMainMethod = false; try { Class returnType = mainClass.getMethod("main", String[].class).getReturnType(); if (returnType == Void.TYPE) { classHasMainMethod = true; } else { LOG.warn( "No Main-Class will be set in jar because main method in {} returns {}, expected void", mainClass, returnType); } } catch (NoSuchMethodException e) { LOG.warn("No Main-Class will be set in jar because {} lacks a main method.", mainClass); } if (classHasMainMethod) { manifest.getMainAttributes().put(Name.MAIN_CLASS, mainClass.getName()); } return manifest; } PortablePipelineJarCreator(Class mainClass); @Override PortablePipelineResult run(Pipeline pipeline, JobInfo jobInfo);  }
@Test public void testCreateManifest_withMainMethod() { Manifest manifest = jarCreator.createManifest(FakePipelineRunnner.class, "job"); assertEquals( FakePipelineRunnner.class.getName(), manifest.getMainAttributes().getValue(Name.MAIN_CLASS)); }
@Test public void testCreateManifest_withoutMainMethod() { Manifest manifest = jarCreator.createManifest(EmptyPipelineRunner.class, "job"); assertNull(manifest.getMainAttributes().getValue(Name.MAIN_CLASS)); }
@Test public void testCreateManifest_withInvalidMainMethod() { Manifest manifest = jarCreator.createManifest(EvilPipelineRunner.class, "job"); assertNull(manifest.getMainAttributes().getValue(Name.MAIN_CLASS)); }