/*
 * 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.formats.avro;

import org.apache.flink.client.program.PackagedProgram;
import org.apache.flink.core.fs.Path;
import org.apache.flink.formats.avro.testjar.AvroExternalJarProgram;
import org.apache.flink.runtime.minicluster.MiniCluster;
import org.apache.flink.runtime.minicluster.MiniClusterConfiguration;
import org.apache.flink.test.util.TestEnvironment;
import org.apache.flink.util.TestLogger;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;
import java.util.Collections;

/**
 * IT case for the {@link AvroExternalJarProgram}.
 */
public class AvroExternalJarProgramITCase extends TestLogger {

	private static final String JAR_FILE = "maven-test-jar.jar";

	private static final String TEST_DATA_FILE = "/testdata.avro";

	private static final int PARALLELISM = 4;

	private static final MiniCluster MINI_CLUSTER = new MiniCluster(
		new MiniClusterConfiguration.Builder()
			.setNumTaskManagers(1)
			.setNumSlotsPerTaskManager(PARALLELISM)
			.build());

	@BeforeClass
	public static void setUp() throws Exception {
		MINI_CLUSTER.start();
	}

	@AfterClass
	public static void tearDown() {
		TestEnvironment.unsetAsContext();
		MINI_CLUSTER.closeAsync();
	}

	@Test
	public void testExternalProgram() throws Exception {
		TestEnvironment.setAsContext(
			MINI_CLUSTER,
			PARALLELISM,
			Collections.singleton(new Path(JAR_FILE)),
			Collections.emptyList());

		String testData = getClass().getResource(TEST_DATA_FILE).toString();

		PackagedProgram program = new PackagedProgram(new File(JAR_FILE), new String[]{testData});

		program.invokeInteractiveModeForExecution();
	}
}

@@ -840,16 +840,68 @@
 .avro;%0A%0A
+import org.apache.flink.client.program.JobWithJars;%0A
 import o
@@ -940,32 +940,32 @@
 ackagedProgram;%0A
-
 import org.apach
@@ -1379,16 +1379,44 @@
 o.File;%0A
+import java.io.IOException;%0A
 import j
@@ -2189,16 +2189,209 @@
 ption %7B%0A
+%0A%09%09String jarFile = JAR_FILE;%0A%09%09try %7B%0A%09%09%09JobWithJars.checkJarFile(new File(jarFile).getAbsoluteFile().toURI().toURL());%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09jarFile = %22target/%22.concat(jarFile);%0A%09%09%7D%0A%0A
 %09%09TestEn
@@ -2481,24 +2481,23 @@
 ew Path(
-JAR_FILE
+jarFile
 )),%0A%09%09%09C
@@ -2651,24 +2651,23 @@
 ew File(
-JAR_FILE
+jarFile
 ), new S

fix the external jar path config error for AvroExternalJarProgramITCase.