Github user mmiklavc commented on a diff in the pull request: https://github.com/apache/metron/pull/785#discussion_r143549913 --- Diff: metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/topology/MergeAndShadeTransformer.java --- @@ -0,0 +1,90 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.metron.parsers.topology; + +import com.google.common.base.Splitter; +import org.apache.storm.daemon.JarTransformer; +import org.apache.storm.hack.StormShadeTransformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.lang.invoke.MethodHandles; +import java.util.HashSet; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.jar.JarOutputStream; + +/** + * This is a storm jar transformer that will add in additional jars pulled from an + * environment variable. The jars will be merged with the main uber jar and then + * the resulting jar will be shaded and relocated according to the StormShadeTransformer. + * + */ +public class MergeAndShadeTransformer implements JarTransformer { + public static final String EXTRA_JARS_ENV = "EXTRA_JARS"; + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + StormShadeTransformer _underlyingTransformer = new StormShadeTransformer(); + @Override + public void transform(InputStream input, OutputStream output) throws IOException { + String extraJars = System.getenv().get(EXTRA_JARS_ENV); + if(extraJars == null || extraJars.length() == 0) { + _underlyingTransformer.transform(input, output); + return; + } + File tmpFile = File.createTempFile("metron", "jar"); + tmpFile.deleteOnExit(); + Set<String> entries = new HashSet<>(); + try (JarOutputStream jout = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tmpFile)))) { + try (JarInputStream jin = new JarInputStream(new BufferedInputStream(input))){ + copy(jin, jout, entries); --- End diff -- Can you document that this method has side effects on the set "entries", or modify the method to return a modified `Set<String>` to make this more explicit?
---