Skip to content

Commit

Permalink
Add a gradle task to generate the UML images (#258)
Browse files Browse the repository at this point in the history
* Add a gradle task to generate the UML images
And generate existing UMLs

* Update buildSrc/src/main/java/com/microsoft/hydralab/compile/UMLImageGenerator.java

* Update agent/doc/UML/test_runner_design.puml

* Comments resolved
  • Loading branch information
hydraxman committed Feb 8, 2023
1 parent 51736a4 commit cbac726
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 8 deletions.
2 changes: 1 addition & 1 deletion agent/doc/UML/agent_device_management_design.puml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@startuml new_design
@startuml
'https://plantuml.com/class-diagram

class AgentManagementService {
Expand Down
6 changes: 3 additions & 3 deletions agent/doc/UML/logger_file_design.puml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@startuml
@startuml log_file_path
'https://plantuml.com/class-diagram

object DeviceLogger
Expand All @@ -16,6 +16,6 @@ TestRunLogger -u-|> DeviceLogger

@startuml loggers
EachTestDevice *--> DeviceLogger
EachTestTaskOnEachTargetDevice *--> TaskOnDeviceLogger
EachTestTaskOnEachTargetDevice *--> LogcatLogger
EachTestRun *--> TestRunLogger
AndroidDevice *--> LogcatLogger
@enduml
8 changes: 4 additions & 4 deletions agent/doc/UML/test_runner_design.puml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@startuml test_runners_classes
@startuml test_runner_class_relation
abstract class TestRunner {
#createTestRun(...)
#setUp(TestTask)
Expand Down Expand Up @@ -114,7 +114,7 @@ deactivate TaskCompletion
}
@endjson

@startuml design
@startuml test_runner_listener_design
abstract class Runner
interface TestRunnerListener {
onTestCaseStart()
Expand All @@ -128,7 +128,7 @@ interface TestRunnerListener {
Runner *--> TestRunnerListener
@enduml

@startuml test_objects
@startuml test_entities

entity (TestTaskSpec)
entity (TestTask)
Expand All @@ -141,7 +141,7 @@ TestTask *--> TestRun: contain a list of
TestRun *--> AndroidTestUnit: contain a list of
@enduml

@startuml test_objects
@startuml test_object_relationships

entity (TestTaskSpec)
entity (TestTask)
Expand Down
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,19 @@ task packageWindowsInstaller(type: Zip) {
from 'agent/agent_installer/Windows'
archiveName 'Hydra_Agent_Installer_Windows.zip'
destinationDir file('build/installer')
}
import com.microsoft.hydralab.compile.UMLImageGenerator

task generateUMLImage(group: 'documentation') {
doFirst {
def scanningDirList = ['agent/doc/UML']
def outputDir = new File(projectDir, 'docs/images/UML')

def generator = new UMLImageGenerator()
scanningDirList.each {
fileTree(new File(projectDir, it)).filter { it.name.endsWith(".puml") }.files.each {
generator.generateUMLImageFromFile(it.absoluteFile, outputDir)
}
}
}
}
10 changes: 10 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation gradleApi()
implementation 'net.sourceforge.plantuml:plantuml:1.2021.9'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
package com.microsoft.hydralab.compile;

import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.GeneratedImage;
import net.sourceforge.plantuml.SourceFileReader;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class UMLImageGenerator {
public void generateUMLImageFromFile(File source) throws IOException {
generateUMLImageFromFile(source, source.getAbsoluteFile().getParentFile(), false);
}

public void generateUMLImageFromFile(File source, File outputDir) throws IOException {
generateUMLImageFromFile(source, outputDir, false);
}

public void generateUMLImageFromFile(File source, File outputDir, boolean svg) throws IOException {
if (!source.exists()) throw new RuntimeException(source.getAbsolutePath() + " file doesn't exist");

SourceFileReader reader = svg ?
new SourceFileReader(source, outputDir, new FileFormatOption(FileFormat.SVG)) :
new SourceFileReader(source, outputDir);

List<GeneratedImage> list = reader.getGeneratedImages();
System.out.printf("Successfully generated %d UML images.\n", list.size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.microsoft.hydralab.compile;

import org.junit.Test;

public class TestUMLGeneration {
@Test
public void emptyTest() {
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/log_file_path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/loggers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/running_sequence.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/test_entities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/test_object_relationships.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/test_runner_class_relation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/test_runner_design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UML/test_runner_listener_design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cbac726

Please sign in to comment.