Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlantUml Plugin #551

Merged
merged 12 commits into from Jun 18, 2022
Merged
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -209,3 +209,6 @@ gradle-app.setting
**/build/

# End of https://www.gitignore.io/api/IntelliJ,macOS,osx,linux,windows,Gradle,java,gradle,lombok

lombok.config
**/gen/
17 changes: 17 additions & 0 deletions examples/plantuml/build.gradle
@@ -0,0 +1,17 @@
import io.freefair.gradle.plugins.plantuml.PlantumlTask

plugins {
id "io.freefair.plantuml"
}

plantUml {
fileFormat = "PNG"
outputDirectory = layout.buildDirectory.dir("dist")
}

tasks.register("plantUml2", PlantumlTask) {
source("src/plantuml2")
includePattern = "**/*.tuml"
fileFormat = "SVG"
outputDirectory = layout.buildDirectory.dir("dist2")
}
3 changes: 3 additions & 0 deletions examples/plantuml/src/plantuml/include/test-i.iuml
@@ -0,0 +1,3 @@
@startuml

@enduml
9 changes: 9 additions & 0 deletions examples/plantuml/src/plantuml/test.puml
@@ -0,0 +1,9 @@
@startuml
!include include/test-i.iuml

Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response

Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml
7 changes: 7 additions & 0 deletions examples/plantuml/src/plantuml2/test2.tuml
@@ -0,0 +1,7 @@
@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response

Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml
1 change: 1 addition & 0 deletions examples/settings.gradle
Expand Up @@ -42,3 +42,4 @@ include ":code-generator:generator"
include ":test-maven-plugin"

include 'quicktype'
include 'plantuml'
Empty file added plantuml-plugin/README.md
Empty file.
26 changes: 26 additions & 0 deletions plantuml-plugin/build.gradle
@@ -0,0 +1,26 @@
apply plugin: "maven-publish"
apply plugin: "java-gradle-plugin"
apply plugin: "com.gradle.plugin-publish"

description = "Gradle Plugin for PlantUML"

dependencies {
//noinspection GradlePackageUpdate
compileOnly 'net.sourceforge.plantuml:plantuml:1.2022.5'

}

gradlePlugin {
plugins {
plantuml {
id = "io.freefair.plantuml"
implementationClass = "io.freefair.gradle.plugins.plantuml.PlantumlPlugin"
displayName = "PlantUML Plugin"
description = "PlantUML Plugin"
}
}
}

pluginBundle {
tags = ["plantuml"]
}
@@ -0,0 +1,32 @@
package io.freefair.gradle.plugins.plantuml;

import lombok.SneakyThrows;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceFileReader;
import org.gradle.workers.WorkAction;

/**
* @author Lars Grefer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MissingSummary: A summary line is required on public/protected Javadocs.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

*/
public abstract class PlantumlAction implements WorkAction<PlantumlParameters> {

@SneakyThrows
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SameNameButDifferent: The name @SneakyThrows refers to [java.lang.Throwable, lombok.Lombok] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignore

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've recorded this as ignored for this pull request. If you change your mind, just comment @sonatype-lift unignore.

@Override
public void execute() {

FileFormat fileFormat = getParameters().getFileFormat()
.map(String::toUpperCase)
.map(FileFormat::valueOf)
.getOrElse(FileFormat.PNG);

FileFormatOption fileFormatOption = new FileFormatOption(fileFormat, getParameters().getWithMetadata().get());
SourceFileReader sourceFileReader = new SourceFileReader(
getParameters().getInputFile().getAsFile().get(),
getParameters().getOutputDirectory().getAsFile().get(),
fileFormatOption
);

sourceFileReader.getGeneratedImages();
}
}
@@ -0,0 +1,20 @@
package io.freefair.gradle.plugins.plantuml;

import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.workers.WorkParameters;

/**
* @author Lars Grefer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MissingSummary: A summary line is required on public/protected Javadocs.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

*/
public interface PlantumlParameters extends WorkParameters {

RegularFileProperty getInputFile();

DirectoryProperty getOutputDirectory();

Property<String> getFileFormat();

Property<Boolean> getWithMetadata();
}
@@ -0,0 +1,30 @@
package io.freefair.gradle.plugins.plantuml;


import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;

/**
* @author Lars Grefer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MissingSummary: A summary line is required on public/protected Javadocs.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

*/
public class PlantumlPlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
Configuration plantuml = project.getConfigurations().create("plantuml");

plantuml.defaultDependencies(s -> {
s.add(project.getDependencies().create("net.sourceforge.plantuml:plantuml:1.2022.5"));
});

project.getTasks().withType(PlantumlTask.class).configureEach(plantumlTask -> {
plantumlTask.getPlantumlClasspath().from(plantuml);
plantumlTask.getOutputDirectory().convention(project.getLayout().getBuildDirectory().dir("plantuml"));
});

project.getTasks().register("plantUml", PlantumlTask.class, plantumlTask -> {
plantumlTask.source("src/plantuml");
});
}
}
@@ -0,0 +1,66 @@
package io.freefair.gradle.plugins.plantuml;

import lombok.Getter;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.*;
import org.gradle.workers.WorkerExecutor;

import javax.inject.Inject;
import java.io.File;

/**
* @author Lars Grefer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MissingSummary: A summary line is required on public/protected Javadocs.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

*/
public class PlantumlTask extends SourceTask {

private final WorkerExecutor workerExecutor;

@Getter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SameNameButDifferent: The name @Getter refers to [java.lang.SuppressWarnings, lombok.Generated, org.gradle.api.file.ConfigurableFileCollection, org.gradle.api.file.DirectoryProperty, org.gradle.api.provider.Property, java.lang.String, java.lang.Boolean] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignore

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've recorded this as ignored for this pull request. If you change your mind, just comment @sonatype-lift unignore.

@Classpath
private final ConfigurableFileCollection plantumlClasspath = getProject().files();

@Getter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SameNameButDifferent: The name @Getter refers to [java.lang.SuppressWarnings, lombok.Generated, org.gradle.api.file.ConfigurableFileCollection, org.gradle.api.file.DirectoryProperty, org.gradle.api.provider.Property, java.lang.String, java.lang.Boolean] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignore

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've recorded this as ignored for this pull request. If you change your mind, just comment @sonatype-lift unignore.

@OutputDirectory
private final DirectoryProperty outputDirectory = getProject().getObjects().directoryProperty();

@Getter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SameNameButDifferent: The name @Getter refers to [java.lang.SuppressWarnings, lombok.Generated, org.gradle.api.file.ConfigurableFileCollection, org.gradle.api.file.DirectoryProperty, org.gradle.api.provider.Property, java.lang.String, java.lang.Boolean] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignore

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've recorded this as ignored for this pull request. If you change your mind, just comment @sonatype-lift unignore.

@Input
@Optional
private final Property<String> fileFormat = getProject().getObjects().property(String.class);

@Getter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SameNameButDifferent: The name @Getter refers to [java.lang.SuppressWarnings, lombok.Generated, org.gradle.api.file.ConfigurableFileCollection, org.gradle.api.file.DirectoryProperty, org.gradle.api.provider.Property, java.lang.String, java.lang.Boolean] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.

Reply with "@sonatype-lift help" for more info.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignore

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've recorded this as ignored for this pull request. If you change your mind, just comment @sonatype-lift unignore.

@Input
private final Property<Boolean> withMetadata = getProject().getObjects().property(Boolean.class).convention(true);

@Getter
@Input
private final Property<String> includePattern = getProject().getObjects().property(String.class).convention("**/*.puml");

@Inject
public PlantumlTask(WorkerExecutor workerExecutor) {
this.setGroup("plantuml");
this.workerExecutor = workerExecutor;
}

@TaskAction
public void execute() {

getProject().delete(outputDirectory);

for (File file : getSource().matching(p -> p.include(includePattern.get()))) {
workerExecutor
.processIsolation(iso -> {
iso.getClasspath().from(plantumlClasspath);
iso.getForkOptions().systemProperty("java.awt.headless", true);
})
.submit(PlantumlAction.class, params -> {
params.getInputFile().set(file);
params.getOutputDirectory().set(outputDirectory);
params.getFileFormat().set(fileFormat);
params.getWithMetadata().set(withMetadata);
});
}
}
}
@@ -0,0 +1,20 @@
package io.freefair.gradle.plugins.plantuml;

import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

class PlantumlPluginTest {

@Test
void apply() {
Project project = ProjectBuilder.builder().build();

project.getPlugins().apply(PlantumlPlugin.class);

assertThat(project.getTasks().getNames()).contains("plantUml");
}
}
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -20,3 +20,4 @@ include "okhttp-plugin"
include "git-plugin"
include "mkdocs-plugin"
include "quicktype-plugin"
include "plantuml-plugin"