private void initClassLoader()

in src/main/java/org/apache/sling/maven/jspc/JspcMojo.java [555:606]


    private void initClassLoader() throws IOException,
            DependencyResolutionRequiredException {
        List<URL> classPath = new ArrayList<URL>();
        // add output directory to classpath
        final String targetDirectory = project.getBuild().getOutputDirectory();
        classPath.add(new File(targetDirectory).toURI().toURL());


        jspcCompileArtifacts = new ArrayList<>();

        if (featureSupport != null) {
            if (feature.dependencies != null) {
                for (Dependency dependency : feature.dependencies) {
                    Artifact artifact = getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, new ArtifactId(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getClassifier(), dependency.getType()));
                    classPath.add(artifact.getFile().toURI().toURL());
                    jspcCompileArtifacts.add(artifact);
                }
            }
            featureSupport.getFeature().getBundles().stream()
                    .map(bundle -> bundle.getId())
                    .map(dependency -> getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, new ArtifactId(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getClassifier(), dependency.getType())))
                    .forEachOrdered(jspcCompileArtifacts::add);

            loader = new TrackingClassLoader(classPath.toArray(new URL[classPath.size()]), featureSupport.getClassLoader());
        } else {
            // add artifacts from project
            Set<Artifact> artifacts = project.getArtifacts().stream().filter(artifact -> "jar".equalsIgnoreCase(artifact.getType())).collect(
                    Collectors.toSet());
            for (Artifact a: artifacts) {
                final String scope = a.getScope();
                if ("provided".equals(scope) || "runtime".equals(scope) || "compile".equals(scope)) {
                    // we need to exclude the javax.servlet.jsp API, otherwise the taglib parser causes problems (see note below)
                    if (containsProblematicPackage(a.getFile())) {
                        continue;
                    }
                    classPath.add(a.getFile().toURI().toURL());
                    jspcCompileArtifacts.add(a);
                }
            }

            if (getLog().isDebugEnabled()) {
                getLog().debug("Compiler classpath:");
                for (URL u: classPath) {
                    getLog().debug("  " + u);
                }
            }
            // this is dangerous to use this classloader as parent as the compilation will depend on the classes provided
            // in the plugin dependencies. but if we omit this, we get errors by not being able to load the TagExtraInfo classes.
            // this is because this plugin uses classes from the javax.servlet.jsp that are also loaded via the TLDs.
            loader = new TrackingClassLoader(classPath.toArray(new URL[classPath.size()]), this.getClass().getClassLoader());
        }
    }