简体   繁体   中英

ArrayOutOfBounds compiling maven plugin on netbeans

I'm trying to compile a very simple maven plugin, that essentially copies the contents from one folder to another, but an ArrayOutOfBoundsException keeps being thrown at compile time by some class that (I guess) process the annotations. I'll paste below the logs from the compiler, the plugin class and the POM.
Do you think that could be a bug in the tool?
How could I solve this?

compiler logs

mvn -X clean deploy
...
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy', parentClassName='org.codehaus.plexus.classworlds.strategy.AbstractStrategy', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.Strategy:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.Strategy', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
MojoClassVisitor#visit
found MojoAnnotatedClass:org.codehaus.plexus.classworlds.strategy.StrategyFactory:MojoAnnotatedClass{className='org.codehaus.plexus.classworlds.strategy.StrategyFactory', parentClassName='java.lang.Object', mojo=null, execute=null, parameters=null, components=null}
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.869 s
Finished at: 2019-01-03T14:37:45-02:00
Final Memory: 15M/54M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project MinifierPlugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 49272
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 49272
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scanDirectory(DefaultMojoAnnotationsScanner.java:204)
    at org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:95)
    at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:125)
    at org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:104)
    at org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:108)
    at org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:233)
    at org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:92)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more

the plugin class

@Mojo(name = "backup")
public class Backup extends AbstractMojo {

    private Log log;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {

        log = getLog();

        File destination = generateFile("backup"),
                source = generateFile("src", "main", "webapp", "files");

        log.info(destination.getAbsolutePath());
        log.info(Boolean.toString(destination.exists()));
        if (destination.exists()) {
            log.info("removing pre-encountered ./backup folder");

            try {
                Files.walk(destination.toPath())
                        .sorted(Comparator.reverseOrder())
                        .map(Path::toFile)
                        .forEach(File::delete);
                if (!destination.delete()) {
                    throw new IOException("Impossible to delete folder.");
                }
            } catch (IOException ex) {
                log.error("Error deleting previous backup folder");
                throw new MojoExecutionException("Impossible to delete previous backup folder.", ex);
            }
        }

        log.debug("attempting to create ./backup dir");

        if (destination.mkdir()) {
            try {
                log.info("Beginning backup.");
                recursiveCopy(source, destination);
            } catch (IOException ex) {
                log.error("error copying files", ex);
                throw new MojoExecutionException("Error copying files", ex);
            }
        } else {
            log.error("unable to create ./backup directory");
            throw new MojoExecutionException("unable to create ./backup directory");
        }

        log.debug("backup finished");
    }

    private void recursiveCopy(File source, File destination) throws IOException {
        for (File file : source.listFiles()) {
            if (file.isDirectory()) {

                log.debug(generateString("creating folder ", file.getName()));                
                File newDest = generateFile(destination.getPath(), file.getName());

                if (newDest.mkdir()) {
                    recursiveCopy(file, newDest);
                } else {
                    String error = generateString("Unable to create folder ", file.getPath());
                    log.error(error);
                    throw new IOException(error);
                }
            } else {
                log.debug(generateString("copying ", file.getPath()));
                Files.copy(file.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }

    static String generateString(String... sts) {
        StringBuilder out = new StringBuilder();
        Arrays.stream(sts).forEach(out::append);
        return out.toString();
    }

    static File generateFile(String... paths) {
        String paths2[] = new String[paths.length * 2 - 1];

        paths2[0] = paths[0];

        for (int i = 1, j = 1; i < paths2.length; i++, j++) {
            paths2[i] = File.separator;
            paths2[++i] = paths[j];
        }

        return new File(generateString(paths2));
    }

}

in case you're wondering why I did those stupid methods at the bottom, its because some how they were avoiding this error (using direct string concatenation was one of the causes I foud)

and my POM

... version, id and stuff ...
<packaging>maven-plugin</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.6.0</version>
    </dependency>
     <dependency>
         <groupId>org.apache.maven.plugin-tools</groupId>
         <artifactId>maven-plugin-annotations</artifactId>
         <version>3.6.0</version>
         <scope>provided</scope>
     </dependency>
</dependencies>

solved by explicitly adding a run for the maven-plugin-plugin::descriptor to the POM

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
        <execution>
            <goals>
                <goal>descriptor</goal>
            </goals>
        </execution>
    </executions>
</plugin>

not sure why...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM