ksclarke/jiiify-presentation

Build failure in freelib-maven-plugins

Closed this issue · 7 comments

adjam commented

Howdy! I'm trying to build the v3 version on a Fedora 37 system using the OS-packaged maven, and OpenJDK 11, and the freelib-maven-plugins portion of the build is failing; it's failing at line 186 in MediaTypeMojo -- let me know if you'd rather I post it there, but I have no idea where the values being processed are coming from.

Maven home: /usr/share/maven
Java version: 11.0.18, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-1.fc37.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.1.13-200.fc37.x86_64", arch: "amd64", family: "unix"

Stack trace (mvn -X install)

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal info.freelibrary:freelib-maven-plugins:0.4.5:generate-mediatype (generate-media-types) on project jiiify-presentation-v3: Execution generate-media-types of goal info.freelibrary:freelib-maven-plugins:0.4.5:generate-mediatype failed: begin 0, end -2, length 0
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:306)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:211)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:165)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:157)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:121)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:127)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution generate-media-types of goal info.freelibrary:freelib-maven-plugins:0.4.5:generate-mediatype failed: begin 0, end -2, length 0
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:301)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:211)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:165)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:157)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:121)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:127)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end -2, length 0
    at java.lang.String.checkBoundsBeginEnd (String.java:3319)
    at java.lang.String.substring (String.java:1874)
    at info.freelibrary.maven.MediaTypeMojo.lambda$writeSource$0 (MediaTypeMojo.java:186)
    at java.util.ArrayList.forEach (ArrayList.java:1541)
    at info.freelibrary.maven.MediaTypeMojo.writeSource (MediaTypeMojo.java:182)
    at info.freelibrary.maven.MediaTypeMojo.execute (MediaTypeMojo.java:118)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:301)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:211)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:165)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:157)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:121)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:127)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException```

Thanks, will check this out tonight. I think I know the problem. I've not tested on Fedora so it's probably not handling a change in location for a file system file well. Sorry for the delay in seeing this.

@adjam Hmm, I'm having trouble reproducing. I used the Fedora 37 Docker image with JDK 11 and the package installed Maven.

[root@0be68bec610e jiiify-presentation-3]# mvn -v
Apache Maven 3.8.5 (Red Hat 3.8.5-3)
Maven home: /usr/share/maven
Java version: 11.0.18, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-1.fc37.x86_64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "6.0.12-76060006-generic", arch: "amd64", family: "unix"
[root@0be68bec610e jiiify-presentation-3]# mvn info.freelibrary:freelib-maven-plugins:0.4.5:generate-mediatype
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< info.freelibrary:jiiify-presentation-v3 >---------------
[INFO] Building jiiify-presentation 0.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- freelib-maven-plugins:0.4.5:generate-mediatype (default-cli) @ jiiify-presentation-v3 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.623 s
[INFO] Finished at: 2023-03-09T03:20:50Z
[INFO] ------------------------------------------------------------------------

Would you try running just the media-type mojo like: mvn info.freelibrary:freelib-maven-plugins:0.4.5:generate-mediatype and let me know the output?

The source with the error is https://github.com/ksclarke/freelib-maven-plugins/blob/56fb75efd7c0302a02c0e76a1f81a7c318fe3049/src/main/java/info/freelibrary/maven/MediaTypeMojo.java#L186 which looks like there is a line in one of the mime.types files that doesn't have an extension that's causing it to choke. My Docker Fedora 37 image doesn't have files at /etc/mime.types or ~/.mime.types (so it's just using the file that comes packaged in the jar file). Do you have a file at either of those locations? If so, could you attach it/them here?

adjam commented

Thanks for looking into this! After I posted the issue I did a bit more digging on my own. I extracted the parser code into a separate class and initially ran it over the bundled mime.types, but didn't find anything. I ran it over /etc/mime.types looking for lines that would cause an issue. The "money" code is:

reader.lines().forEach(line -> {
            // We only care about the media types that have extensions and skip those that are commented out
            if (line.contains(" ") && line.trim().charAt(0) != '#') {
                final String[] parts = line.split("\\s+");
                final String[] exts = Arrays.copyOfRange(parts, 1, parts.length);
                if ( exts.length < 1 ) {
                    System.err.printf("<<%s>> is cruisin' for a bruisin'%n", line);
                }
            } // ignore everything else...
        });

when run on /etc/mime.types on my system it yields:

<<application/opc-nodeset+xml     >> is cruisin' for a bruisin'
<<application/vnd.3gpp.5gnas              >> is cruisin' for a bruisin'

Further system info:

``

$ rpm -qf /etc/mime.types 
mailcap-2.1.53-4.fc37.noarch

(gzip of that is attached)

I'm willing to believe that a docker container might not ship mailcap's mime types =)
mime.types.gz

Thanks! Yes, looks like I've made the bad assumption that if there is a space, there is an extension (I'm not accounting for end of line spaces with no following extension). I'll fix that tonight and push a new version of the plugin (and update jiiify-presentation to use that new version). Thanks for reporting and digging into it!

@adjam I updated the v3 branch with the updated mojo. If you get the chance, try building it and see if the build problem is resolved. Thanks!

adjam commented

the v3 branch at 34b31a8 now builds on my system. Thanks!