private void preparePaths()

in src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java [427:525]


    private void preparePaths()
    {
        boolean hasModuleDescriptor = false;

        // Assuming that the module-info.java is already compiled by compiler plugin so only
        // check if the module-info.class file exists.
        File moduleInfo = new File( targetClassesDirectory, "module-info.class" );

        if ( moduleInfo.exists() && moduleInfo.isFile() )
        {
            getLog().debug( "We have found a module-info.class file." );
            hasModuleDescriptor = true;
        }

        Collection<File> dependencyArtifacts = getCompileClasspathElements( getProject() );

        if ( hasModuleDescriptor )
        {
            // For now only allow named modules. Once we can create a graph with ASM we can specify exactly the modules
            // and we can detect if auto modules are used. In that case, MavenProject.setFile() should not be used, so
            // you cannot depend on this project and so it won't be distributed.

            modulepathElements = new ArrayList<String>();
            classpathElements = new ArrayList<String>();

            ResolvePathsResult<File> resolvePathsResult;
            try
            {

                ResolvePathsRequest<File> request =
                    ResolvePathsRequest.ofFiles( dependencyArtifacts ).setMainModuleDescriptor( moduleInfo );

                Toolchain toolchain = getToolchain();
                if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
                {
                    request.setJdkHome( new File( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ) );
                }

                resolvePathsResult = locationManager.resolvePaths( request );

                JavaModuleDescriptor moduleDescriptor = resolvePathsResult.getMainModuleDescriptor();

                for ( Map.Entry<File, ModuleNameSource> entry : resolvePathsResult.getModulepathElements().entrySet() )
                {
                    getLog().debug( "File: " + entry.getKey().getAbsolutePath() + " " + entry.getValue().name() );
                    if ( ModuleNameSource.FILENAME.equals( entry.getValue() ) )
                    {
                        final String message = "Required filename-based automodules detected. "
                            + "Please don't publish this project to a public artifact repository!";

                        if ( moduleDescriptor.exports().isEmpty() )
                        {
                            // application
                            getLog().info( message );
                        }
                        else
                        {
                            // library
                            writeBoxedWarning( message );
                        }
                        break;
                    }
                }

                for ( File file : resolvePathsResult.getClasspathElements() )
                {
                    getLog().debug( "classpathElements: File: " + file.getPath() );
                    classpathElements.add( file.getPath() );
                }

                for ( File file : resolvePathsResult.getModulepathElements().keySet() )
                {
                    getLog().debug( "modulepathElements: File: " + file.getPath() );
                    if ( file.isDirectory() )
                    {
                        modulepathElements.add( file.getPath() );
                    }
                    else
                    {
                        modulepathElements.add( file.getParent() );
                    }
                }
            }
            catch ( IOException e )
            {
                getLog().warn( e.getMessage() );
            }
        }
        else
        {
            modulepathElements = Collections.emptyList();

            classpathElements = new ArrayList<String>();
            for ( File file : dependencyArtifacts )
            {
                classpathElements.add( file.getPath() );
            }
        }
    }