-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feature/android support #17
base: master
Are you sure you want to change the base?
Changes from all commits
da5de10
0ea6074
af7c171
6e54361
bd92f80
0b5b22e
838209d
30f9d66
2634b23
08ac0d7
c46ea09
1b0827e
51ecd02
e9d4a66
d96c27b
bf1b6e3
011595f
a75513f
efcf738
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 |
---|---|---|
|
@@ -24,3 +24,4 @@ build | |
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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) | ||
} | ||
|
||
static boolean isAndroidApplication(Project project) { | ||
return project.pluginManager.hasPlugin("com.android.application") | ||
} | ||
|
||
static boolean isAndroidLibrary(Project project) { | ||
return project.pluginManager.hasPlugin("com.android.library") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.roroche.plantuml.urls | ||
|
||
import org.gradle.api.Project | ||
|
||
import static com.github.roroche.plantuml.android.AndroidProjectType.* | ||
|
||
/** | ||
* Factory for creating the correct classpath based on the type of a project | ||
*/ | ||
class CompileClasspathUrlsFactory { | ||
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. Pretty much the same comment, for these reasons:
So you can move the logic to the |
||
static Urls.Wrap createCompileClasspathUrls(Project project) { | ||
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. Please use the high-level type, which is |
||
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") | ||
} | ||
} | ||
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. so this logic will also go to the dedicated Android's |
||
|
||
classpath.addAll(debugVariant.javaCompileProvider.get().classpath.files) | ||
|
||
return new CompileClasspathUrls(new FilesUrls(classpath.toSet())) | ||
} else { | ||
return new CompileClasspathUrls(project) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.roroche.plantuml.urls | ||
|
||
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) { | ||
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. So this logic can go to a class KotlinProject(private val project: Project): SupportedProject {
fun sourceUrls(): Urls {
def debugTask = project.tasks.find {
it.name.contains("compile") && it.name.contains("DebugKotlin")
}
return new MainOutputUrls(
new FilesUrls(
[debugTask.destinationDir].toSet()
)
)
}
}
class AndroidApplication(project: Project): SupportedProject.Wrap(
delegate = KotlinProject(project)
) {
fun sourceUrls(): Urls {
val ktSrcUrls = super.sourceUrls()
// return the specific list + ktSrcUrls
}
} |
||
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) | ||
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. this logic goes to the default |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
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 think we can reproduce the mechanism found here: https://github.com/RoRoche/plantuml-gradle-plugin/blob/master/src/test/groovy/com/github/roroche/plantuml/BuiltProject.groovy I suggest a new interface such as: interface TestableProject {
fun toProject(): Project
} and then you can put the logic to prepare a project such as: class TestableAndroidApplication: TestableProject {
fun toProject(): Project {
ProjectBuilder.builder().build()
project.apply plugin: "com.android.application"
project.android {
compileSdkVersion 21
}
project.evaluate()
return project
}
} This will remove duplicate code in test. |
||
|
||
assert AndroidProjectType.isAndroidProject(project) | ||
assert AndroidProjectType.isAndroidApplication(project) | ||
assert !AndroidProjectType.isAndroidLibrary(project) | ||
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. These testing concerns must go to a dedicated The project is based on this library: https://github.com/pragmatic-objects/oo-tests Here is an example: https://github.com/RoRoche/plantuml-gradle-plugin/blob/master/src/test/groovy/com/github/roroche/plantuml/BuildClassDiagramTaskTest.groovy 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. But maybe these tests are not worth considering now and we should focus the effort on the next ones (those about Urls generation) |
||
} | ||
|
||
@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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
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.
I target to don't have any static method in the codebase. Here is why: https://www.yegor256.com/2017/02/07/private-method-is-new-class.html
But looking at the source code you suggest, I guess that we could try something: