Vankka/DependencyDownload

Possible bug with repository address

Closed this issue · 4 comments

Hi, I got this error when I added a new dependency that's downloaded - it seems that a second / was added after the repository URL

java.lang.RuntimeException: Failed to download dependency com.github.seancfoley:ipaddress:5.4.0
        at plan.dev.vankka.dependencydownload.DependencyManager.lambda$download$1(DependencyManager.java:206) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.lambda$forEachDependency$8(DependencyManager.java:397) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.forEachDependency(DependencyManager.java:404) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.download(DependencyManager.java:205) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.downloadAll(DependencyManager.java:190) ~[Plan-5.5-SNAPSHOT.jar:?]
        at com.djrapitops.plan.delivery.webserver.configuration.IpAllowListMatcher.downloadLibrary(IpAllowListMatcher.java:95) ~[Plan-5.5-SNAPSHOT.jar:?]
        ... 19 more
Caused by: java.lang.RuntimeException: All provided repositories failed to download dependency
        at plan.dev.vankka.dependencydownload.DependencyManager.downloadDependency(DependencyManager.java:436) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.lambda$download$0(DependencyManager.java:205) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.lambda$forEachDependency$8(DependencyManager.java:393) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.forEachDependency(DependencyManager.java:404) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.download(DependencyManager.java:205) ~[Plan-5.5-SNAPSHOT.jar:?]
        at plan.dev.vankka.dependencydownload.DependencyManager.downloadAll(DependencyManager.java:190) ~[Plan-5.5-SNAPSHOT.jar:?]
        at com.djrapitops.plan.delivery.webserver.configuration.IpAllowListMatcher.downloadLibrary(IpAllowListMatcher.java:95) ~[Plan-5.5-SNAPSHOT.jar:?]
        ... 19 more
        Suppressed: java.io.FileNotFoundException: https://repo1.maven.org/maven2//com/github/seancfoley/ipaddress/5.4.0/ipaddress-5.4.0.jar
                at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1993) ~[?:?]
                at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589) ~[?:?]
                at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224) ~[?:?]
                at plan.dev.vankka.dependencydownload.DependencyManager.downloadFromRepository(DependencyManager.java:467) ~[Plan-5.5-SNAPSHOT.jar:?]
                at plan.dev.vankka.dependencydownload.DependencyManager.downloadDependency(DependencyManager.java:440) ~[Plan-5.5-SNAPSHOT.jar:?]
                at plan.dev.vankka.dependencydownload.DependencyManager.lambda$download$0(DependencyManager.java:205) ~[Plan-5.5-SNAPSHOT.jar:?]
                at plan.dev.vankka.dependencydownload.DependencyManager.lambda$forEachDependency$8(DependencyManager.java:393) ~[Plan-5.5-SNAPSHOT.jar:?]
                at plan.dev.vankka.dependencydownload.DependencyManager.forEachDependency(DependencyManager.java:404) ~[Plan-5.5-SNAPSHOT.jar:?]
                at plan.dev.vankka.dependencydownload.DependencyManager.download(DependencyManager.java:205) ~[Plan-5.5-SNAPSHOT.jar:?]
                at plan.dev.vankka.dependencydownload.DependencyManager.downloadAll(DependencyManager.java:190) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.delivery.webserver.configuration.IpAllowListMatcher.downloadLibrary(IpAllowListMatcher.java:95) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.delivery.webserver.configuration.IpAllowListMatcher.prepare(IpAllowListMatcher.java:73) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.delivery.webserver.auth.AllowedIpList.prepare(AllowedIpList.java:52) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.delivery.webserver.http.JettyWebserver.enable(JettyWebserver.java:148) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.delivery.webserver.WebServerSystem.enable(WebServerSystem.java:65) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.PlanSystem.enableSystems(PlanSystem.java:225) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.PlanSystem.enableOtherThanCommands(PlanSystem.java:182) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.PlanSystem.enable(PlanSystem.java:220) ~[Plan-5.5-SNAPSHOT.jar:?]
                at com.djrapitops.plan.Plan.onEnable(Plan.java:82) ~[Plan-5.5-SNAPSHOT.jar:?]
                at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
                at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
                at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
                at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugin(CraftServer.java:564) ~[paper-1.18.1.jar:git-Paper-175]
                at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugins(CraftServer.java:478) ~[paper-1.18.1.jar:git-Paper-175]
                at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:727) ~[paper-1.18.1.jar:git-Paper-175]
                at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:503) ~[paper-1.18.1.jar:git-Paper-175]
                at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:313) ~[paper-1.18.1.jar:git-Paper-175]
                at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1202) ~[paper-1.18.1.jar:git-Paper-175]
                at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.1.jar:git-Paper-175]
                at java.lang.Thread.run(Thread.java:833) ~[?:?]

Code:

            DependencyManager dependencyManager = new DependencyManager(files.getDataDirectory().resolve("libraries"));
            dependencyManager.loadFromResource(getDependencyResource());
            try {
                dependencyManager.downloadAll(null, List.of(
                        new StandardRepository("https://repo1.maven.org/maven2/")
                )).get();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }

            IsolatedClassLoader classLoader = new IsolatedClassLoader();
            dependencyManager.load(null, classLoader);
            this.libraryClassLoader = classLoader;
configurations {
    // Runtime downloading scopes
    ...
    ipAddressMatcher
    testImplementation.extendsFrom ..., ipAddressMatcher
    compileOnly.extendsFrom ..., ipAddressMatcher
}

task generateResourceForIpAddressMatcher(type: GenerateDependencyDownloadResourceTask) {
    var conf = configurations.ipAddressMatcher
    configuration = conf
    file = "assets/plan/dependencies/" + conf.name + ".txt"
    // Not necessary to include in the resource
    includeShadowJarRelocations = false
}

dependencies {
    ...
    ipAddressMatcher "com.github.seancfoley:ipaddress:$ipAddressMatcherVersion"
}


processResources {
    ...
    dependsOn generateResourceForIpAddressMatcher
}

Contents of ipAddressMatcher.txt in the jar

===ALGORITHM SHA-256
com.github.seancfoley:ipaddress:5.4.0 950f0e31febad43e7c1bc58f76549a8f909465ec8f984223bc030f565a79d26f

dependencyDownloadVersion = "1.3.0"

It stopped when I removed the / from the end of the URL, but there's another spot where I use

    private static final List<Repository> DRIVER_REPOSITORIES = Arrays.asList(
            new StandardRepository("https://papermc.io/repo/repository/maven-public/"),
            new StandardRepository("https://repo1.maven.org/maven2/")
    );

and it is not erroring, so I opened this ticket in case it's some sort of bug

It should always be adding a slash between the repository and dependency, but I think removing the slash from the end of the repository here is reasonable

I see what happened here, the papermc.io repository automatically removes/ignores double slashes so both of the following urls work:

https://papermc.io/repo/repository/maven-public//org/xerial/sqlite-jdbc/3.41.2.1/sqlite-jdbc-3.41.2.1.jar
https://papermc.io/repo/repository/maven-public/org/xerial/sqlite-jdbc/3.41.2.1/sqlite-jdbc-3.41.2.1.jar

But maven central does not, so only the bottom url here works:

https://repo1.maven.org/maven2//com/github/seancfoley/ipaddress/5.4.0/ipaddress-5.4.0.jar
https://repo1.maven.org/maven2/com/github/seancfoley/ipaddress/5.4.0/ipaddress-5.4.0.jar

so if the other repositories-block tried to download from maven central it would fail, until I get around to publishing a update with the above commit

Aha, interesting. Thanks for looking into it :)

Published, 1.3.1