private ClassLoader createClassLoader()

in winegrower-extension/winegrower-build/winegrower-maven-plugin/src/main/java/org/apache/winegrower/extension/build/maven/PourMojo.java [121:163]


    private ClassLoader createClassLoader(final ClassLoader parent) {
        final List<File> jars = Stream.concat(
                collectLibs(),
                Stream.concat(project.getArtifacts().stream()
                                .filter(a -> !((dependencyScopes == null && !(Artifact.SCOPE_COMPILE.equals(
                                        a.getScope()) || Artifact.SCOPE_RUNTIME.equals(
                                        a.getScope()))) || (dependencyScopes != null && !dependencyScopes.contains(
                                        a.getScope()))))
                                .map(Artifact::getFile),
                        Stream.of(project.getBuild().getOutputDirectory()).map(File::new).filter(File::exists)))
                .collect(toList());
        final List<URL> urls = jars.stream().map(file -> {
            try {
                return file.toURI().toURL();
            } catch (final MalformedURLException e) {
                throw new IllegalArgumentException(e);
            }
        }).collect(toList());
        if (getLog().isDebugEnabled()) {
            getLog().debug("Startup classpath: " + jars);
        }
        final boolean excludeOsgi = jars.stream()
                .anyMatch(it -> it.getName().startsWith("org.osgi.") || it.getName().startsWith("osgi."));
        final boolean hasWinegrower = jars.stream()
                .anyMatch(it -> it.getName().startsWith("winegrower-core"));
        if (excludeOsgi) {
            // add build-common
            final File buildCommon = Files.toFile(parent.getResource("org/apache/winegrower/extension/build/common/Run.class"));
            try {
                urls.add(buildCommon.toURI().toURL());
            } catch (final MalformedURLException e) {
                throw new IllegalArgumentException(e);
            }
        }
        final ClassLoader workaroundMaven = new WorkAroundMavenClassLoader(parent);
        final ClassLoader parentLoader = !excludeOsgi || !hasWinegrower ? workaroundMaven : new IgnoreWinegrowerckClassLoader(workaroundMaven);
        return urls.isEmpty() ? workaroundMaven : new URLClassLoader(urls.toArray(new URL[0]), parentLoader) {
            @Override
            public boolean equals(final Object obj) {
                return super.equals(obj) || parent.equals(obj);
            }
        };
    }