zentol commented on a change in pull request #7717: [FLINK-11533] [container] Add option parse JAR manifest for jobClassName URL: https://github.com/apache/flink/pull/7717#discussion_r260723741
########## File path: flink-container/src/main/java/org/apache/flink/container/entrypoint/JarManifestParser.java ########## @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.container.entrypoint; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.client.program.PackagedProgram; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + +/** + * Utility that parses JAR manifest attributes. + */ +class JarManifestParser { + + /** + * Returns the entry class as specified in the manifest of a single JAR file. + * + * @param jarFiles JAR files to parse + * + * @throws NoSuchElementException if no JAR file contains an entry class attribute + * @throws IllegalArgumentException if multiple JAR files contain an entry class manifest attribute + */ + static String findOnlyEntryClass(Iterable<File> jarFiles) throws IOException { + List<String> entryClasses = new ArrayList<>(); + for (File jarFile : jarFiles) { + findEntryClass(jarFile).ifPresent(entryClasses::add); + } + int size = entryClasses.size(); + if (size == 0) { + throw new NoSuchElementException("No JAR with manifest attribute for entry class"); + } + if (size == 1) { + return entryClasses.get(0); + } + // else: size > 1 + throw new IllegalArgumentException("Multiple JARs with manifest attribute for entry class"); Review comment: include jar paths in error message; you also also list all available manifest entries for convenience ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
