Search in sources :

Example 1 with HtmlJavadocProvider

use of org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider in project sts4 by spring-projects.

the class GradleProjectClasspath method getBaseIndices.

@Override
protected JandexIndex[] getBaseIndices() {
    return new JandexIndex[] { new JandexIndex(getJreLibs().map(path -> path.toFile()).collect(Collectors.toList()), jarFile -> findIndexFile(jarFile), (classpathResource) -> {
        try {
            String javaVersion = getJavaRuntimeMinorVersion();
            if (javaVersion == null) {
                javaVersion = "8";
            }
            URL javadocUrl = new URL("https://docs.oracle.com/javase/" + javaVersion + "/docs/api/");
            return new HtmlJavadocProvider((type) -> SourceUrlProviderFromSourceContainer.JAVADOC_FOLDER_URL_SUPPLIER.sourceUrl(javadocUrl, type.getFullyQualifiedName()));
        } catch (MalformedURLException e) {
            Log.log(e);
            return null;
        }
    }) };
}
Also used : MalformedURLException(java.net.MalformedURLException) JandexIndex(org.springframework.ide.vscode.commons.jandex.JandexIndex) HtmlJavadocProvider(org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider) URL(java.net.URL)

Example 2 with HtmlJavadocProvider

use of org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider in project sts4 by spring-projects.

the class MavenProjectClasspath method createHtmlJavdocProvider.

@Override
protected IJavadocProvider createHtmlJavdocProvider(File classpathResource) {
    if (cachedData == null) {
        return null;
    }
    if (classpathResource.isDirectory()) {
        if (classpathResource.toString().startsWith(cachedData.outputDirectory)) {
            return new HtmlJavadocProvider(type -> {
                return SourceUrlProviderFromSourceContainer.JAVADOC_FOLDER_URL_SUPPLIER.sourceUrl(new File(cachedData.reportingOutputDirectory, "apidocs").toURI().toURL(), type.getFullyQualifiedName());
            });
        } else if (classpathResource.toString().startsWith(cachedData.testOutputDirectory)) {
            return new HtmlJavadocProvider(type -> {
                return SourceUrlProviderFromSourceContainer.JAVADOC_FOLDER_URL_SUPPLIER.sourceUrl(new File(cachedData.reportingOutputDirectory, "apidocs").toURI().toURL(), type.getFullyQualifiedName());
            });
        } else {
            throw new IllegalArgumentException("Cannot find source folder for " + classpathResource);
        }
    } else {
        // Assume it's a JAR file
        return new HtmlJavadocProvider(type -> {
            try {
                Artifact artifact = cachedData.artifacts.stream().filter(a -> classpathResource.equals(a.getFile())).findFirst().get();
                URL sourceContainer = maven.getJavadoc(artifact, cachedData.remoteArtifactRepositories).getFile().toURI().toURL();
                return SourceUrlProviderFromSourceContainer.JAR_JAVADOC_URL_PROVIDER.sourceUrl(sourceContainer, type.getFullyQualifiedName());
            } catch (MavenException e) {
                Log.log("Failed to find sources JAR for " + classpathResource, e);
            } catch (MalformedURLException e) {
                Log.log("Invalid URL for sources JAR for " + classpathResource, e);
            }
            return null;
        });
    }
}
Also used : Arrays(java.util.Arrays) HtmlJavadocProvider(org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider) URL(java.net.URL) IJavadocProvider(org.springframework.ide.vscode.commons.java.IJavadocProvider) JandexClasspath(org.springframework.ide.vscode.commons.jandex.JandexClasspath) ImmutableList(com.google.common.collect.ImmutableList) MavenProject(org.apache.maven.project.MavenProject) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) JandexIndex(org.springframework.ide.vscode.commons.jandex.JandexIndex) Objects(com.google.common.base.Objects) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) MavenException(org.springframework.ide.vscode.commons.maven.MavenException) MavenCore(org.springframework.ide.vscode.commons.maven.MavenCore) Log(org.springframework.ide.vscode.commons.util.Log) MalformedURLException(java.net.MalformedURLException) Set(java.util.Set) SourceUrlProviderFromSourceContainer(org.springframework.ide.vscode.commons.javadoc.SourceUrlProviderFromSourceContainer) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) Collections(java.util.Collections) ClasspathData(org.springframework.ide.vscode.commons.java.ClasspathData) MalformedURLException(java.net.MalformedURLException) MavenException(org.springframework.ide.vscode.commons.maven.MavenException) HtmlJavadocProvider(org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) URL(java.net.URL)

Aggregations

MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 JandexIndex (org.springframework.ide.vscode.commons.jandex.JandexIndex)2 HtmlJavadocProvider (org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider)2 Objects (com.google.common.base.Objects)1 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 MavenProject (org.apache.maven.project.MavenProject)1 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)1