From da5de1056daaca1938479d33df4e811501a0ea23 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Thu, 27 Aug 2020 10:11:21 +0200 Subject: [PATCH 01/19] First prototype of Android support --- .../plantuml/tasks/BuildClassDiagramTask.groovy | 11 ++++++++++- .../roroche/plantuml/urls/CompileClasspathUrls.groovy | 3 ++- .../roroche/plantuml/urls/MainOutputUrls.groovy | 10 ++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy b/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy index 96fd778..9b2b962 100644 --- a/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy @@ -5,10 +5,12 @@ import com.github.roroche.plantuml.diagrams.ClassDiagram import com.github.roroche.plantuml.diagrams.Diagram import com.github.roroche.plantuml.diagrams.DiagramWithLog import com.github.roroche.plantuml.urls.CompileClasspathUrls +import com.github.roroche.plantuml.urls.FilesUrls import com.github.roroche.plantuml.urls.LoggableUrls import com.github.roroche.plantuml.urls.MainOutputUrls import com.github.roroche.plantuml.urls.MergedUrls import org.gradle.api.DefaultTask +import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction @@ -78,6 +80,7 @@ class BuildClassDiagramTask extends DefaultTask implements CustomTask { new ClassDiagram(classes), logger ) + diagram.print(extension.outputFile) } @@ -86,11 +89,17 @@ class BuildClassDiagramTask extends DefaultTask implements CustomTask { return new URLClassLoader( new MergedUrls( Arrays.asList( - new LoggableUrls( + new LoggableUrls( new CompileClasspathUrls(project), "CompileClasspath", logger ), + new LoggableUrls( + new CompileClasspathUrls( + new FilesUrls(project.android.libraryVariants[0].javaCompile.classpath.files)), + "CompileClasspath", + logger + ), new LoggableUrls( new MainOutputUrls(project), "MainOutput", diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy index 0aeeef6..4a05e96 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy @@ -23,7 +23,8 @@ class CompileClasspathUrls extends Urls.Wrap { CompileClasspathUrls(final Project project) { this( new FilesUrls( - project.configurations["compileClasspath"].files +// project.configurations["compileClasspath"].files + [project.android.getBootClasspath()[0]].toSet() ) ) } diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy index 4a3838c..ed6b8ca 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy @@ -23,8 +23,14 @@ class MainOutputUrls extends Urls.Wrap { * @param project The Project where to find output main. */ MainOutputUrls(final Project project) { - this( - project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() +// this( +// project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() +// ) + this ( + new FilesUrls( +// project.fileTree(dir: project.tasks["compileDebugKotlin"].destinationDir, excludes: ["**/META-INF"]).files + [project.tasks["compileDebugKotlin"].destinationDir].toSet() + ) ) } From 0ea60740730a5807a92fb14bb7bc26685e3aa218 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Wed, 9 Sep 2020 18:42:36 +0200 Subject: [PATCH 02/19] Code refactoring --- build.gradle | 3 ++ .../tasks/BuildClassDiagramTask.groovy | 17 +++--- .../plantuml/urls/CompileClasspathUrls.groovy | 3 +- .../urls/CompileClasspathUrlsFactory.groovy | 49 +++++++++++++++++ .../plantuml/urls/MainOutputUrls.groovy | 10 +--- .../urls/MainOutputUrlsFactory.groovy | 34 ++++++++++++ .../CompileClasspathUrlsFactoryTest.groovy | 54 +++++++++++++++++++ 7 files changed, 152 insertions(+), 18 deletions(-) create mode 100644 src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy create mode 100644 src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy create mode 100644 src/test/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactoryTest.groovy diff --git a/build.gradle b/build.gradle index 779db48..689a708 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,8 @@ if (project.hasProperty('newVersion')) { repositories { mavenCentral() mavenLocal() + google() + jcenter() } dependencies { @@ -36,6 +38,7 @@ dependencies { testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2") testImplementation gradleTestKit() testImplementation 'org.assertj:assertj-core:3.15.0' + testImplementation("com.android.tools.build:gradle:4.0.1") } test { diff --git a/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy b/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy index 9b2b962..3a59271 100644 --- a/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/tasks/BuildClassDiagramTask.groovy @@ -5,9 +5,11 @@ import com.github.roroche.plantuml.diagrams.ClassDiagram import com.github.roroche.plantuml.diagrams.Diagram import com.github.roroche.plantuml.diagrams.DiagramWithLog import com.github.roroche.plantuml.urls.CompileClasspathUrls +import com.github.roroche.plantuml.urls.CompileClasspathUrlsFactory import com.github.roroche.plantuml.urls.FilesUrls import com.github.roroche.plantuml.urls.LoggableUrls import com.github.roroche.plantuml.urls.MainOutputUrls +import com.github.roroche.plantuml.urls.MainOutputUrlsFactory import com.github.roroche.plantuml.urls.MergedUrls import org.gradle.api.DefaultTask import org.gradle.api.plugins.JavaPluginConvention @@ -81,6 +83,11 @@ class BuildClassDiagramTask extends DefaultTask implements CustomTask { logger ) + def outputFileParent = extension.outputFile.parentFile + if (!outputFileParent.exists()) { + outputFileParent.mkdirs() + } + diagram.print(extension.outputFile) } @@ -90,18 +97,12 @@ class BuildClassDiagramTask extends DefaultTask implements CustomTask { new MergedUrls( Arrays.asList( new LoggableUrls( - new CompileClasspathUrls(project), - "CompileClasspath", - logger - ), - new LoggableUrls( - new CompileClasspathUrls( - new FilesUrls(project.android.libraryVariants[0].javaCompile.classpath.files)), + CompileClasspathUrlsFactory.createCompileClasspathUrls(project), "CompileClasspath", logger ), new LoggableUrls( - new MainOutputUrls(project), + MainOutputUrlsFactory.createMainOutputUrls(project), "MainOutput", logger ) diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy index 4a05e96..84ef61d 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrls.groovy @@ -23,8 +23,7 @@ class CompileClasspathUrls extends Urls.Wrap { CompileClasspathUrls(final Project project) { this( new FilesUrls( -// project.configurations["compileClasspath"].files - [project.android.getBootClasspath()[0]].toSet() + project.configurations["compileClasspath"].files ) ) } diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy new file mode 100644 index 0000000..1c55ff0 --- /dev/null +++ b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy @@ -0,0 +1,49 @@ +package com.github.roroche.plantuml.urls + +import org.gradle.api.Project + +/** + * Utility class to build Urls with compileClasspath configuration from Project. + */ +class CompileClasspathUrlsFactory { + public static Urls.Wrap createCompileClasspathUrls(Project project) { + if (isAndroidProject(project)) { + def classpath = [] + + project.android.getBootClasspath().each { + classpath.add(it) + } + + def debugVariant + + if (isAndroidLibrary(project)) { + debugVariant = project.android.libraryVariants.find { + it.name.contains("debug") || it.name.contains("Debug") + } + } else { + debugVariant = project.android.applicationVariants.find { + it.name.contains("debug") || it.name.contains("Debug") + } + } + + classpath.addAll(debugVariant.javaCompileProvider.get().classpath.files) + + return new CompileClasspathUrls(new FilesUrls(classpath.toSet())) + } else { + return new CompileClasspathUrls(project) + } + } + + private static boolean isAndroidProject(Project project) { + return isAndroidApplication(project) || isAndroidLibrary(project) + } + + private static boolean isAndroidApplication(Project project) { + return project.pluginManager.hasPlugin("com.android.application") + } + + private static boolean isAndroidLibrary(Project project) { + return project.pluginManager.hasPlugin("com.android.library") + } + +} diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy index ed6b8ca..4a3838c 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrls.groovy @@ -23,14 +23,8 @@ class MainOutputUrls extends Urls.Wrap { * @param project The Project where to find output main. */ MainOutputUrls(final Project project) { -// this( -// project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() -// ) - this ( - new FilesUrls( -// project.fileTree(dir: project.tasks["compileDebugKotlin"].destinationDir, excludes: ["**/META-INF"]).files - [project.tasks["compileDebugKotlin"].destinationDir].toSet() - ) + this( + project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets() ) } diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy new file mode 100644 index 0000000..cd287f8 --- /dev/null +++ b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy @@ -0,0 +1,34 @@ +package com.github.roroche.plantuml.urls + +import org.gradle.api.Project +import org.gradle.api.tasks.SourceSetContainer + +class MainOutputUrlsFactory { + public static Urls.Wrap createMainOutputUrls(Project project) { + if (isAndroidProject(project)) { + def debugTask = project.tasks.find { + it.name.contains("compile") && it.name.contains("DebugKotlin") + } + + return new MainOutputUrls( + new FilesUrls( + [debugTask.destinationDir].toSet() + ) + ) + } else { + return new MainOutputUrls(project) + } + } + + private static boolean isAndroidProject(Project project) { + return isAndroidApplication(project) || isAndroidLibrary(project) + } + + private static boolean isAndroidApplication(Project project) { + return project.pluginManager.hasPlugin("com.android.application") + } + + private static boolean isAndroidLibrary(Project project) { + return project.pluginManager.hasPlugin("com.android.library") + } +} diff --git a/src/test/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactoryTest.groovy b/src/test/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactoryTest.groovy new file mode 100644 index 0000000..e598e40 --- /dev/null +++ b/src/test/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactoryTest.groovy @@ -0,0 +1,54 @@ +package com.github.roroche.plantuml.urls + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import org.junit.jupiter.api.Test + +class CompileClasspathUrlsFactoryTest { + + Project project + + CompileClasspathUrlsFactoryTest() { + project = ProjectBuilder.builder().build() + } + + @Test + void testJavaProjectShouldReturnCorrectClassPathForAndroidAppProject() { + project.apply plugin: "com.android.application" + project.android { + compileSdkVersion 21 + } + project.evaluate() + + Urls.Wrap urls = CompileClasspathUrlsFactory.createCompileClasspathUrls(project) + + def files = [] + + urls.toList().each { url -> + files.add(new File(url.toURI()).getName()) + } + + assert files.contains("android.jar") + assert files.contains("R.jar") + } + + @Test + void testJavaProjectShouldReturnCorrectClassPathForAndroidLibraryProject() { + project.apply plugin: "com.android.library" + project.android { + compileSdkVersion 21 + } + project.evaluate() + + Urls.Wrap urls = CompileClasspathUrlsFactory.createCompileClasspathUrls(project) + + def files = [] + + urls.toList().each { url -> + files.add(new File(url.toURI()).getName()) + } + + assert files.contains("android.jar") + assert files.contains("R.jar") + } +} From af7c1719827ecf14928c8dc0e2d6c9fba6e21278 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Wed, 9 Sep 2020 19:25:12 +0200 Subject: [PATCH 03/19] Add tests for MainOutputUrlsFactory --- .gitignore | 2 + build.gradle | 3 +- .../urls/CompileClasspathUrlsFactory.groovy | 2 +- .../urls/MainOutputUrlsFactoryTest.groovy | 88 +++++++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/test/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactoryTest.groovy diff --git a/.gitignore b/.gitignore index b9dd9a3..25e4f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ build # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +local.properties diff --git a/build.gradle b/build.gradle index 689a708..f74e59f 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,8 @@ dependencies { testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2") testImplementation gradleTestKit() testImplementation 'org.assertj:assertj-core:3.15.0' - testImplementation("com.android.tools.build:gradle:4.0.1") + testRuntimeOnly("com.android.tools.build:gradle:4.0.1") + testRuntimeOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72") } test { diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy index 1c55ff0..b7dbcfe 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy @@ -6,7 +6,7 @@ import org.gradle.api.Project * Utility class to build Urls with compileClasspath configuration from Project. */ class CompileClasspathUrlsFactory { - public static Urls.Wrap createCompileClasspathUrls(Project project) { + static Urls.Wrap createCompileClasspathUrls(Project project) { if (isAndroidProject(project)) { def classpath = [] diff --git a/src/test/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactoryTest.groovy b/src/test/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactoryTest.groovy new file mode 100644 index 0000000..1b0e34e --- /dev/null +++ b/src/test/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactoryTest.groovy @@ -0,0 +1,88 @@ +package com.github.roroche.plantuml.urls + +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import org.junit.jupiter.api.Test + +class MainOutputUrlsFactoryTest { + + Project project + + MainOutputUrlsFactoryTest() { + project = ProjectBuilder.builder().build() + } + + @Test + void testCreateMainOutputUrlsShouldReturnCorrectClassPathForAndroidAppProject() { + project.apply plugin: "com.android.application" + project.apply plugin: "kotlin-android" + project.android { + compileSdkVersion 21 + } + project.evaluate() + + Urls.Wrap urls = MainOutputUrlsFactory.createMainOutputUrls(project) + + File result = new File(urls.toList()[0].toURI()) + assert result == project.tasks.compileDebugKotlin.destinationDir + } + + @Test + void testCreateMainOutputUrlsShouldReturnCorrectClassPathForAndroidAppProjectWithBuildFlavors() { + project.apply plugin: "com.android.application" + project.apply plugin: "kotlin-android" + project.android { + compileSdkVersion 21 + + flavorDimensions "client" + productFlavors { + free { + dimension "client" + } + } + } + project.evaluate() + + Urls.Wrap urls = MainOutputUrlsFactory.createMainOutputUrls(project) + + File result = new File(urls.toList()[0].toURI()) + assert result == project.tasks.compileFreeDebugKotlin.destinationDir + } + + @Test + void testCreateMainOutputUrlsShouldReturnCorrectClassPathForAndroidLibraryProject() { + project.apply plugin: "com.android.library" + project.apply plugin: "kotlin-android" + project.android { + compileSdkVersion 21 + } + project.evaluate() + + Urls.Wrap urls = MainOutputUrlsFactory.createMainOutputUrls(project) + + File result = new File(urls.toList()[0].toURI()) + assert result == project.tasks.compileDebugKotlin.destinationDir + } + + @Test + void testCreateMainOutputUrlsShouldReturnCorrectClassPathForAndroidLibraryProjectWithBuildFlavors() { + project.apply plugin: "com.android.library" + project.apply plugin: "kotlin-android" + project.android { + compileSdkVersion 21 + + flavorDimensions "client" + productFlavors { + free { + dimension "client" + } + } + } + project.evaluate() + + Urls.Wrap urls = MainOutputUrlsFactory.createMainOutputUrls(project) + + File result = new File(urls.toList()[0].toURI()) + assert result == project.tasks.compileFreeDebugKotlin.destinationDir + } +} From 6e54361d8e4822d3be161a52d517d9874e7a3fda Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Wed, 9 Sep 2020 21:41:19 +0200 Subject: [PATCH 04/19] Refactor Android project type checks to reduce code duplication --- .../android/AndroidProjectType.groovy | 17 +++++++ .../urls/CompileClasspathUrlsFactory.groovy | 15 +------ .../urls/MainOutputUrlsFactory.groovy | 17 ++----- .../android/AndroidProjectTypeTest.groovy | 44 +++++++++++++++++++ 4 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy create mode 100644 src/test/groovy/com/github/roroche/plantuml/android/AndroidProjectTypeTest.groovy diff --git a/src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy b/src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy new file mode 100644 index 0000000..b0ad6e6 --- /dev/null +++ b/src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy @@ -0,0 +1,17 @@ +package com.github.roroche.plantuml.android + +import org.gradle.api.Project + +class AndroidProjectType { + static boolean isAndroidProject(Project project) { + return isAndroidApplication(project) || isAndroidLibrary(project) + } + + static boolean isAndroidApplication(Project project) { + return project.pluginManager.hasPlugin("com.android.application") + } + + static boolean isAndroidLibrary(Project project) { + return project.pluginManager.hasPlugin("com.android.library") + } +} diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy index b7dbcfe..c4ceaf1 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy @@ -2,6 +2,8 @@ package com.github.roroche.plantuml.urls import org.gradle.api.Project +import static com.github.roroche.plantuml.android.AndroidProjectType.* + /** * Utility class to build Urls with compileClasspath configuration from Project. */ @@ -33,17 +35,4 @@ class CompileClasspathUrlsFactory { return new CompileClasspathUrls(project) } } - - private static boolean isAndroidProject(Project project) { - return isAndroidApplication(project) || isAndroidLibrary(project) - } - - private static boolean isAndroidApplication(Project project) { - return project.pluginManager.hasPlugin("com.android.application") - } - - private static boolean isAndroidLibrary(Project project) { - return project.pluginManager.hasPlugin("com.android.library") - } - } diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy index cd287f8..9c7e2c4 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy @@ -1,10 +1,11 @@ package com.github.roroche.plantuml.urls import org.gradle.api.Project -import org.gradle.api.tasks.SourceSetContainer + +import static com.github.roroche.plantuml.android.AndroidProjectType.* class MainOutputUrlsFactory { - public static Urls.Wrap createMainOutputUrls(Project project) { + static Urls.Wrap createMainOutputUrls(Project project) { if (isAndroidProject(project)) { def debugTask = project.tasks.find { it.name.contains("compile") && it.name.contains("DebugKotlin") @@ -19,16 +20,4 @@ class MainOutputUrlsFactory { return new MainOutputUrls(project) } } - - private static boolean isAndroidProject(Project project) { - return isAndroidApplication(project) || isAndroidLibrary(project) - } - - private static boolean isAndroidApplication(Project project) { - return project.pluginManager.hasPlugin("com.android.application") - } - - private static boolean isAndroidLibrary(Project project) { - return project.pluginManager.hasPlugin("com.android.library") - } } diff --git a/src/test/groovy/com/github/roroche/plantuml/android/AndroidProjectTypeTest.groovy b/src/test/groovy/com/github/roroche/plantuml/android/AndroidProjectTypeTest.groovy new file mode 100644 index 0000000..f46be68 --- /dev/null +++ b/src/test/groovy/com/github/roroche/plantuml/android/AndroidProjectTypeTest.groovy @@ -0,0 +1,44 @@ +package com.github.roroche.plantuml.android + +import com.github.roroche.plantuml.urls.MainOutputUrlsFactory +import com.github.roroche.plantuml.urls.Urls +import org.gradle.api.Project +import org.gradle.testfixtures.ProjectBuilder +import org.junit.jupiter.api.Test + +class AndroidProjectTypeTest { + private final Project project = ProjectBuilder.builder().build() + + @Test + void testProjectIsAndroidApplication() { + project.apply plugin: "com.android.application" + project.android { + compileSdkVersion 21 + } + project.evaluate() + + assert AndroidProjectType.isAndroidProject(project) + assert AndroidProjectType.isAndroidApplication(project) + assert !AndroidProjectType.isAndroidLibrary(project) + } + + @Test + void testProjectIsAndroidLibrary() { + project.apply plugin: "com.android.library" + project.android { + compileSdkVersion 21 + } + project.evaluate() + + assert AndroidProjectType.isAndroidProject(project) + assert !AndroidProjectType.isAndroidApplication(project) + assert AndroidProjectType.isAndroidLibrary(project) + } + + @Test + void testProjectIsNotAndroid() { + assert !AndroidProjectType.isAndroidProject(project) + assert !AndroidProjectType.isAndroidApplication(project) + assert !AndroidProjectType.isAndroidLibrary(project) + } +} From bd92f80d05ebf7e8493758036780c80566c9b615 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Wed, 9 Sep 2020 21:46:39 +0200 Subject: [PATCH 05/19] Upgrade to gradle 6.1.1 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c6de046..f0695de 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Fri May 01 20:33:27 CEST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists From 0b5b22ea3856e1c26122d08e3593472e0d3d0b99 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Thu, 10 Sep 2020 08:51:30 +0200 Subject: [PATCH 06/19] Update Javadoc for the new classes --- .../roroche/plantuml/android/AndroidProjectType.groovy | 7 +++++++ .../plantuml/urls/CompileClasspathUrlsFactory.groovy | 2 +- .../roroche/plantuml/urls/MainOutputUrlsFactory.groovy | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy b/src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy index b0ad6e6..932c7d4 100644 --- a/src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/android/AndroidProjectType.groovy @@ -2,7 +2,14 @@ package com.github.roroche.plantuml.android import org.gradle.api.Project +/*** + * Class to determine if a project has an Android plugin applied + */ class AndroidProjectType { + private AndroidProjectType() { + + } + static boolean isAndroidProject(Project project) { return isAndroidApplication(project) || isAndroidLibrary(project) } diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy index c4ceaf1..33159e8 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/CompileClasspathUrlsFactory.groovy @@ -5,7 +5,7 @@ import org.gradle.api.Project import static com.github.roroche.plantuml.android.AndroidProjectType.* /** - * Utility class to build Urls with compileClasspath configuration from Project. + * Factory for creating the correct classpath based on the type of a project */ class CompileClasspathUrlsFactory { static Urls.Wrap createCompileClasspathUrls(Project project) { diff --git a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy index 9c7e2c4..b9606cb 100644 --- a/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy +++ b/src/main/groovy/com/github/roroche/plantuml/urls/MainOutputUrlsFactory.groovy @@ -4,6 +4,9 @@ import org.gradle.api.Project import static com.github.roroche.plantuml.android.AndroidProjectType.* +/*** + * Factory for creating the correct output URLs based on the type of a project + */ class MainOutputUrlsFactory { static Urls.Wrap createMainOutputUrls(Project project) { if (isAndroidProject(project)) { From 838209dc220d3adad87867c86de489003dbf0b50 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Thu, 10 Sep 2020 21:19:40 +0200 Subject: [PATCH 07/19] Print gradle version by Travis For debugging failing tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0358557..0a73447 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ cache: - $HOME/.gradle/wrapper/ script: + - ./gradlew -PnewVersion="$TRAVIS_TAG" --version - ./gradlew -PnewVersion="$TRAVIS_TAG" clean - ./gradlew -PnewVersion="$TRAVIS_TAG" build - ./gradlew -PnewVersion="$TRAVIS_TAG" check From 30f9d66fa52541a9f625b0c9a94837fb8f1f6bc4 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Thu, 10 Sep 2020 21:43:22 +0200 Subject: [PATCH 08/19] Enforce java 1.8 compiler To hopefully fix the Travis build --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index f74e59f..1d0fe75 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,11 @@ if (project.hasProperty('newVersion')) { project.version = '1.0.33-SNAPSHOT' } +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + repositories { mavenCentral() mavenLocal() From 2634b231c26ff1994394fb7a4183149e98ae7338 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Thu, 10 Sep 2020 21:46:53 +0200 Subject: [PATCH 09/19] Use dist Xenial To hopefully fix the Travis build. See: https://travis-ci.community/t/using-jdk-openjdk8-brings-javac-9-0-1/3371 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0a73447..17ed36f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ --- os: linux -dist: trusty +dist: xenial language: java jdk: - openjdk8 From 08ac0d73f72b512471af6d8101613c5b83d41ab1 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Thu, 10 Sep 2020 22:09:39 +0200 Subject: [PATCH 10/19] Fixing EvalIssueException --- .gitignore | 1 - local.properties | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 local.properties diff --git a/.gitignore b/.gitignore index 25e4f9e..0971c96 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,3 @@ build # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -local.properties diff --git a/local.properties b/local.properties new file mode 100644 index 0000000..20129d5 --- /dev/null +++ b/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Wed Sep 09 19:02:40 CEST 2020 +sdk.dir=. From c46ea09cf21f23097632fedbf359ae3770617650 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Thu, 10 Sep 2020 22:10:48 +0200 Subject: [PATCH 11/19] Revert "Use dist Xenial" This reverts commit 2634b231c26ff1994394fb7a4183149e98ae7338. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 17ed36f..0a73447 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ --- os: linux -dist: xenial +dist: trusty language: java jdk: - openjdk8 From 1b0827e0d6b167f9ff2a64e4ca3148026775114c Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Fri, 18 Sep 2020 17:39:26 +0200 Subject: [PATCH 12/19] Add ANDROID_HOME env variable --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0a73447..8cea41c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ jdk: - openjdk8 install: true +env: + - ANDROID_HOME=$HOME/android-sdk + before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ From 51ecd025f7ca737207a20a8ce7fa5eacea906d0f Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Fri, 18 Sep 2020 17:47:17 +0200 Subject: [PATCH 13/19] Make the ANDROID_HOME dir --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 8cea41c..6db7153 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ cache: - $HOME/.gradle/wrapper/ script: + - mkdir -p $ANDROID_HOME - ./gradlew -PnewVersion="$TRAVIS_TAG" --version - ./gradlew -PnewVersion="$TRAVIS_TAG" clean - ./gradlew -PnewVersion="$TRAVIS_TAG" build From e9d4a66334f837fc1b917ee68a4fc16c8ce8ef7d Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Fri, 18 Sep 2020 17:59:52 +0200 Subject: [PATCH 14/19] Dynamically add local.properties during travis build --- .travis.yml | 1 + local.properties | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 local.properties diff --git a/.travis.yml b/.travis.yml index 6db7153..7bd464e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ cache: script: - mkdir -p $ANDROID_HOME + - echo "sdk.dir=$ANDROID_HOME" > local.properties - ./gradlew -PnewVersion="$TRAVIS_TAG" --version - ./gradlew -PnewVersion="$TRAVIS_TAG" clean - ./gradlew -PnewVersion="$TRAVIS_TAG" build diff --git a/local.properties b/local.properties deleted file mode 100644 index 20129d5..0000000 --- a/local.properties +++ /dev/null @@ -1,8 +0,0 @@ -## This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Wed Sep 09 19:02:40 CEST 2020 -sdk.dir=. From d96c27bb28e081e1f2cfb8a9577cb0529d9c1414 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Fri, 18 Sep 2020 18:05:50 +0200 Subject: [PATCH 15/19] Print the generated local.properties file content --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7bd464e..e186199 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ cache: script: - mkdir -p $ANDROID_HOME - echo "sdk.dir=$ANDROID_HOME" > local.properties + - cat local.properties - ./gradlew -PnewVersion="$TRAVIS_TAG" --version - ./gradlew -PnewVersion="$TRAVIS_TAG" clean - ./gradlew -PnewVersion="$TRAVIS_TAG" build From bf1b6e3d1c966b1a11b1f62cb6967e5af34d173e Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Mon, 21 Sep 2020 20:02:22 +0200 Subject: [PATCH 16/19] Accept Android SDK licenses --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e186199..a2365ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,11 +16,13 @@ cache: directories: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ + - $ANDROID_HOME script: - mkdir -p $ANDROID_HOME - echo "sdk.dir=$ANDROID_HOME" > local.properties - - cat local.properties + - mkdir $ANDROID_HOME/licenses + - echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > $ANDROID_HOME/licenses/android-sdk-license - ./gradlew -PnewVersion="$TRAVIS_TAG" --version - ./gradlew -PnewVersion="$TRAVIS_TAG" clean - ./gradlew -PnewVersion="$TRAVIS_TAG" build From 011595fc3fe87885afccaa8efcb13d3309171419 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Fri, 25 Sep 2020 17:10:50 +0200 Subject: [PATCH 17/19] Don't prepare android home when it already exists Because it is cached --- .travis.yml | 5 +---- prepareAndroidHome.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 prepareAndroidHome.sh diff --git a/.travis.yml b/.travis.yml index a2365ac..91ddaa8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,7 @@ cache: - $ANDROID_HOME script: - - mkdir -p $ANDROID_HOME - - echo "sdk.dir=$ANDROID_HOME" > local.properties - - mkdir $ANDROID_HOME/licenses - - echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > $ANDROID_HOME/licenses/android-sdk-license + - prepareAndroidHome.sh - ./gradlew -PnewVersion="$TRAVIS_TAG" --version - ./gradlew -PnewVersion="$TRAVIS_TAG" clean - ./gradlew -PnewVersion="$TRAVIS_TAG" build diff --git a/prepareAndroidHome.sh b/prepareAndroidHome.sh new file mode 100644 index 0000000..feea5b4 --- /dev/null +++ b/prepareAndroidHome.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ ! -d $ANDROID_HOME ]; then + mkdir -p $ANDROID_HOME + echo "sdk.dir=$ANDROID_HOME" > local.properties + + mkdir $ANDROID_HOME/licenses + echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > $ANDROID_HOME/licenses/android-sdk-license +fi From a75513f50b455a7d2683c82d8baf3fb19a4c95a9 Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Sat, 26 Sep 2020 00:41:10 +0200 Subject: [PATCH 18/19] Execute the shell script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 91ddaa8..a258e4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ cache: - $ANDROID_HOME script: - - prepareAndroidHome.sh + - ./prepareAndroidHome.sh - ./gradlew -PnewVersion="$TRAVIS_TAG" --version - ./gradlew -PnewVersion="$TRAVIS_TAG" clean - ./gradlew -PnewVersion="$TRAVIS_TAG" build From efcf738cbf21370d56602231578f4f2a264cd73d Mon Sep 17 00:00:00 2001 From: Coen Houtman Date: Sat, 26 Sep 2020 09:18:28 +0200 Subject: [PATCH 19/19] Make script executable --- prepareAndroidHome.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 prepareAndroidHome.sh diff --git a/prepareAndroidHome.sh b/prepareAndroidHome.sh old mode 100644 new mode 100755