-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add PlantUml Plugin #551
Changes from 8 commits
cd36602
7bc8ed1
4edb338
6d97667
4953f73
4ef883c
063e9c9
4cf5748
e91c91f
6f180df
4e52447
4a5ac9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@startuml | ||
|
||
@enduml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@startuml | ||
Alice -> Bob: Authentication Request | ||
Bob --> Alice: Authentication Response | ||
|
||
Alice -> Bob: Another authentication Request | ||
Alice <-- Bob: another authentication Response | ||
@enduml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ include ":code-generator:generator" | |
include ":test-maven-plugin" | ||
|
||
include 'quicktype' | ||
include 'plantuml' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
*/ | ||
public abstract class PlantumlAction implements WorkAction<PlantumlParameters> { | ||
|
||
@SneakyThrows | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SameNameButDifferent: The name Reply with "@sonatype-lift help" for more info. 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
@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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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? |
||
*/ | ||
public interface PlantumlParameters extends WorkParameters { | ||
|
||
RegularFileProperty getInputFile(); | ||
|
||
DirectoryProperty getOutputDirectory(); | ||
|
||
Property<String> getFileFormat(); | ||
|
||
Property<Boolean> getWithMetadata(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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? |
||
*/ | ||
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"); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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? |
||
*/ | ||
public class PlantumlTask extends SourceTask { | ||
|
||
private final WorkerExecutor workerExecutor; | ||
|
||
@Getter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SameNameButDifferent: The name Reply with "@sonatype-lift help" for more info. 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
@Classpath | ||
private final ConfigurableFileCollection plantumlClasspath = getProject().files(); | ||
|
||
@Getter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SameNameButDifferent: The name Reply with "@sonatype-lift help" for more info. 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
@OutputDirectory | ||
private final DirectoryProperty outputDirectory = getProject().getObjects().directoryProperty(); | ||
|
||
@Getter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SameNameButDifferent: The name Reply with "@sonatype-lift help" for more info. 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
@Input | ||
@Optional | ||
private final Property<String> fileFormat = getProject().getObjects().property(String.class); | ||
|
||
@Getter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SameNameButDifferent: The name Reply with "@sonatype-lift help" for more info. 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
@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); | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
There was a problem hiding this comment.
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 ]