Search in sources :

Example 1 with MinimalJavadocOptions

use of org.gradle.external.javadoc.MinimalJavadocOptions in project crnk-framework by crnk-project.

the class DocletPlugin method apply.

@Override
public void apply(final Project project) {
    Configuration config = project.getConfigurations().create("crnkJavaDocToXml");
    project.getDependencies().add("crnkJavaDocToXml", "com.github.markusbernhardt:xml-doclet:1.0.5");
    Javadoc task = project.getTasks().create(TASK_NAME, Javadoc.class);
    task.setTitle(null);
    task.setDestinationDir(new File(project.getBuildDir(), "crnk-xml-docs"));
    MinimalJavadocOptions options = task.getOptions();
    options.setDoclet("com.github.markusbernhardt.xmldoclet.XmlDoclet");
    options.setMemberLevel(JavadocMemberLevel.PRIVATE);
    options.setDocletpath(new ArrayList<>(config.getFiles()));
    SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
    SourceSet mainSourceSet = sourceSets.getByName("main");
    task.source(mainSourceSet.getAllJava());
    task.setClasspath(mainSourceSet.getCompileClasspath());
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) MinimalJavadocOptions(org.gradle.external.javadoc.MinimalJavadocOptions) File(java.io.File) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 2 with MinimalJavadocOptions

use of org.gradle.external.javadoc.MinimalJavadocOptions in project gradle-plugins by freefair.

the class ResolveJavadocLinks method addLink.

private void addLink(String link) {
    MinimalJavadocOptions options = javadoc.getOptions();
    if (options instanceof StandardJavadocDocletOptions) {
        StandardJavadocDocletOptions docletOptions = (StandardJavadocDocletOptions) options;
        List<String> links = docletOptions.getLinks();
        if (links == null || !links.contains(link)) {
            logger.debug("Adding '{}' to {}", link, javadoc);
            docletOptions.links(link);
        } else {
            logger.info("Not adding '{}' to {} because it's already present", link, javadoc);
        }
    }
}
Also used : MinimalJavadocOptions(org.gradle.external.javadoc.MinimalJavadocOptions) StandardJavadocDocletOptions(org.gradle.external.javadoc.StandardJavadocDocletOptions)

Example 3 with MinimalJavadocOptions

use of org.gradle.external.javadoc.MinimalJavadocOptions in project gradle-baseline by palantir.

the class BaselineModuleJvmArgs method apply.

@Override
@SuppressWarnings("checkstyle:MethodLength")
public void apply(Project project) {
    project.getPluginManager().withPlugin("java", unused -> {
        BaselineModuleJvmArgsExtension extension = project.getExtensions().create(EXTENSION_NAME, BaselineModuleJvmArgsExtension.class, project);
        // javac isn't provided `--add-exports` args for the time being due to
        // https://github.com/gradle/gradle/issues/18824
        // However, we set sourceCompatibility in BaselineJavaVersion to opt out of the '--release' flag.
        project.getExtensions().getByType(SourceSetContainer.class).configureEach(sourceSet -> {
            TaskProvider<JavaCompile> javaCompileProvider = project.getTasks().named(sourceSet.getCompileJavaTaskName(), JavaCompile.class);
            javaCompileProvider.configure(javaCompile -> {
                javaCompile.getOptions().getCompilerArgumentProviders().add(new CommandLineArgumentProvider() {

                    @Override
                    public Iterable<String> asArguments() {
                        // The '--release' flag is set when BaselineJavaVersion is not used.
                        if (!project.getPlugins().hasPlugin(BaselineJavaVersion.class)) {
                            project.getLogger().debug("BaselineModuleJvmArgs not applying args to compilation task " + "{} on {} due to lack of BaselineJavaVersion", javaCompile.getName(), project);
                            return ImmutableList.of();
                        }
                        ImmutableList<String> arguments = collectCompilationArgs(project, extension, sourceSet);
                        project.getLogger().debug("BaselineModuleJvmArgs compiling {} on {} with exports: {}", javaCompile.getName(), project, arguments);
                        return arguments;
                    }
                });
            });
            TaskProvider<Task> javadocTaskProvider = null;
            try {
                javadocTaskProvider = project.getTasks().named(sourceSet.getJavadocTaskName());
            } catch (UnknownTaskException e) {
            // skip
            }
            if (javadocTaskProvider != null) {
                javadocTaskProvider.configure(javadocTask -> {
                    javadocTask.doFirst(new Action<Task>() {

                        @Override
                        public void execute(Task task) {
                            // The '--release' flag is set when BaselineJavaVersion is not used.
                            if (!project.getPlugins().hasPlugin(BaselineJavaVersion.class)) {
                                project.getLogger().debug("BaselineModuleJvmArgs not applying args to compilation task " + "{} on {} due to lack of BaselineJavaVersion", task.getName(), project);
                                return;
                            }
                            Javadoc javadoc = (Javadoc) task;
                            MinimalJavadocOptions options = javadoc.getOptions();
                            if (options instanceof CoreJavadocOptions) {
                                CoreJavadocOptions coreOptions = (CoreJavadocOptions) options;
                                ImmutableList<JarManifestModuleInfo> info = collectClasspathInfo(project, sourceSet);
                                List<String> exportValues = Stream.concat(// Compilation only supports exports, so we union with opens.
                                Stream.concat(extension.exports().get().stream(), extension.opens().get().stream()), info.stream().flatMap(item -> Stream.concat(item.exports().stream(), item.opens().stream()))).distinct().sorted().map(item -> item + "=ALL-UNNAMED").collect(ImmutableList.toImmutableList());
                                project.getLogger().debug("BaselineModuleJvmArgs building {} on {} " + "with exports: {}", javadoc.getName(), project, exportValues);
                                if (!exportValues.isEmpty()) {
                                    coreOptions.addMultilineStringsOption("-add-exports").setValue(exportValues);
                                }
                            } else {
                                project.getLogger().error("MinimalJavadocOptions implementation was " + "not CoreJavadocOptions, rather '{}'", options.getClass().getName());
                            }
                        }
                    });
                });
            }
        });
        project.getTasks().withType(Test.class).configureEach(new Action<Test>() {

            @Override
            public void execute(Test test) {
                test.getJvmArgumentProviders().add(new CommandLineArgumentProvider() {

                    @Override
                    public Iterable<String> asArguments() {
                        ImmutableList<String> arguments = collectClasspathArgs(project, extension, test.getClasspath(), OpensMode.RUNTIME);
                        project.getLogger().debug("BaselineModuleJvmArgs executing {} on {} with exports: {}", test.getName(), project, arguments);
                        return arguments;
                    }
                });
            }
        });
        project.getTasks().withType(JavaExec.class).configureEach(new Action<JavaExec>() {

            @Override
            public void execute(JavaExec javaExec) {
                javaExec.getJvmArgumentProviders().add(new CommandLineArgumentProvider() {

                    @Override
                    public Iterable<String> asArguments() {
                        ImmutableList<String> arguments = collectClasspathArgs(project, extension, javaExec.getClasspath(), OpensMode.RUNTIME);
                        project.getLogger().debug("BaselineModuleJvmArgs executing {} on {} with exports: {}", javaExec.getName(), project, arguments);
                        return arguments;
                    }
                });
            }
        });
        project.getTasks().withType(Jar.class).configureEach(new Action<Jar>() {

            @Override
            public void execute(Jar jar) {
                jar.doFirst(new Action<Task>() {

                    @Override
                    public void execute(Task task) {
                        jar.manifest(new Action<Manifest>() {

                            @Override
                            public void execute(Manifest manifest) {
                                addManifestAttribute(jar, manifest, ADD_EXPORTS_ATTRIBUTE, extension.exports());
                                addManifestAttribute(jar, manifest, ADD_OPENS_ATTRIBUTE, extension.opens());
                            }
                        });
                    }
                });
            }
        });
    });
}
Also used : Task(org.gradle.api.Task) Action(org.gradle.api.Action) ImmutableList(com.google.common.collect.ImmutableList) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) JavaExec(org.gradle.api.tasks.JavaExec) Test(org.gradle.api.tasks.testing.Test) MinimalJavadocOptions(org.gradle.external.javadoc.MinimalJavadocOptions) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Manifest(org.gradle.api.java.archives.Manifest) UnknownTaskException(org.gradle.api.UnknownTaskException) BaselineModuleJvmArgsExtension(com.palantir.baseline.extensions.BaselineModuleJvmArgsExtension) CommandLineArgumentProvider(org.gradle.process.CommandLineArgumentProvider) Jar(org.gradle.jvm.tasks.Jar) JavaCompile(org.gradle.api.tasks.compile.JavaCompile)

Aggregations

MinimalJavadocOptions (org.gradle.external.javadoc.MinimalJavadocOptions)3 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)2 Javadoc (org.gradle.api.tasks.javadoc.Javadoc)2 ImmutableList (com.google.common.collect.ImmutableList)1 BaselineModuleJvmArgsExtension (com.palantir.baseline.extensions.BaselineModuleJvmArgsExtension)1 File (java.io.File)1 List (java.util.List)1 Action (org.gradle.api.Action)1 Task (org.gradle.api.Task)1 UnknownTaskException (org.gradle.api.UnknownTaskException)1 Configuration (org.gradle.api.artifacts.Configuration)1 Manifest (org.gradle.api.java.archives.Manifest)1 JavaExec (org.gradle.api.tasks.JavaExec)1 SourceSet (org.gradle.api.tasks.SourceSet)1 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)1 Test (org.gradle.api.tasks.testing.Test)1 CoreJavadocOptions (org.gradle.external.javadoc.CoreJavadocOptions)1 StandardJavadocDocletOptions (org.gradle.external.javadoc.StandardJavadocDocletOptions)1 Jar (org.gradle.jvm.tasks.Jar)1 CommandLineArgumentProvider (org.gradle.process.CommandLineArgumentProvider)1