apache / pulsar

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org/
Apache License 2.0
14.14k stars 3.57k forks source link

Incorrect detection of NAR files #16397

Open cbornet opened 2 years ago

cbornet commented 2 years ago

Describe the bug In several parts of the code (org.apache.pulsar.common.nar.FileUtils, NarClassLoader, ...), the type of the archive (NAR or JAR) is detected by looking at the existence of the META-INF/bundled-dependencies directory. But this directory doesn't necessarily exist in a NAR archive. For instance, if all the dependencies of the artifact are set as provided because they already exist in Pulsar. In that case the archive gets wrongly detected as a JAR.

To Reproduce Steps to reproduce the behavior:

  1. Create new maven project ExclamationFunction
    public class ExclamationFunction implements Function<String, String> {
    @Override
    public String process(String input, Context context) {
        return String.format("%s!", input);
    }
    }
  2. Write pom including nifi-nar-maven-plugin

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>com.example</groupId>
    <artifactId>exclamation-function</artifactId>
    <version>1.0-SNAPSHOT</version>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.nifi</groupId>
                <artifactId>nifi-nar-maven-plugin</artifactId>
                <version>1.2.0</version>
                <extensions>true</extensions>
                <configuration>
                    <finalName>${project.artifactId}-${project.version}</finalName>
                </configuration>
                <executions>
                    <execution>
                        <id>default-nar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>nar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    </project>
  3. Package
    mvn clean package
  4. Inspect the generated NAR --> There is no META-INF/bundled-dependencies directory

Expected behavior Another way to detect if the archive is a NAR should be used. Eg. checking if the MANIFEST.MF file contains the string Nar-Id:

shibd commented 2 years ago

Have a question: If all dependency scope is provided, My test result is that there will be a jar package(function itself).

image

@gaozhangmin @cbornet cc

github-actions[bot] commented 2 years ago

The issue had no activity for 30 days, mark with Stale label.

cbornet commented 1 year ago

@shibd Is that the NAR built in pulsar-functions-api-examples-builtin? In that case, the artifact pulls pulsar-functions-api-examples as a dependency. This is not the way people generally build a NAR.

github-actions[bot] commented 1 year ago

The issue had no activity for 30 days, mark with Stale label.