Skip to content

Commit

Permalink
feat: handle the case of only have one root-project(no subprojects) case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacksgong committed Sep 12, 2018
1 parent 713a9d4 commit 1b69f5d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
39 changes: 23 additions & 16 deletions src/main/groovy/com/liulishuo/okcheck/OkCheckPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OkCheckPlugin implements Plugin<Project> {
if (project == project.rootProject) CleanOkCheckDiffTask.addTask(project)

// lint, ktlint, checkstyle, unitTest, pmd, findbugs
if (project != project.rootProject) {
if (project != project.rootProject || project.rootProject.subprojects.size() <= 0) {
project.afterEvaluate {
OkLint.inspectLint(project, okCheckExtension.lint)
if (okCheckExtension.checkStyle.enabled) OkCheckStyleTask.addTask(project, okCheckExtension.checkStyle)
Expand All @@ -62,24 +62,31 @@ class OkCheckPlugin implements Plugin<Project> {
if (project == project.rootProject) {
// root project
setupOkCheckDiff(project)
if (project.subprojects.size() <= 0) {
distributeOkCheckTask(project)
}
} else {
// changed module list
final List<String> changedModuleList = BuildConfig.getChangedModuleList(project)
project.afterEvaluate {
if (!Util.hasAndroidPlugin(project) && !Util.hasLibraryPlugin(project)) {
Util.printLog("Pass ${project.name} directly because it isn't android/library project.")
BuildConfig.addToPassedModuleFile(project)
return
}
distributeOkCheckTask(project)
}
}

boolean isChangedModule = changedModuleList.contains(project.name)
if (isChangedModule) {
Util.printLog("Enable check for ${project.name} because of file changed on it")
OkCheckTask.addValidTask(project, changedModuleList, okCheckExtension)
} else {
Util.printLog("NO CHANGED CODE FOUND FOR ${project.name}")
OkCheckTask.addMockTask(project)
}
private void distributeOkCheckTask(Project project) {
final List<String> changedModuleList = BuildConfig.getChangedModuleList(project)
project.afterEvaluate {
if (!Util.hasAndroidPlugin(project) && !Util.hasLibraryPlugin(project)) {
Util.printLog("Pass ${project.name} directly because it isn't android/library project.")
BuildConfig.addToPassedModuleFile(project)
return
}

boolean isChangedModule = changedModuleList.contains(project.name)
if (isChangedModule) {
Util.printLog("Enable check for ${project.name} because of file changed on it")
OkCheckTask.addValidTask(project, changedModuleList, okCheckExtension)
} else {
Util.printLog("NO CHANGED CODE FOUND FOR ${project.name}")
OkCheckTask.addMockTask(project)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/com/liulishuo/okcheck/OkCheckTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OkCheckTask extends DefaultTask {

@TaskAction
void setupOkcheck() {
if (project == project.rootProject) {
if (project == project.rootProject && project.subprojects.size() > 0) {
Util.printLog("Finish root okcheck task!")
} else if (!isMock) {
Util.printLog("Finish ${project.name} okcheck task!")
Expand Down
21 changes: 16 additions & 5 deletions src/main/groovy/com/liulishuo/okcheck/util/ChangeModule.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,29 @@ class ChangeModule {

static List<String> getAllModuleList(Project project) {
final List<String> moduleNameList = new ArrayList<>()
project.subprojects {
moduleNameList.add(it.name)

if (project.subprojects.size() <= 0) {
moduleNameList.add(project.name)
} else {
project.subprojects {
moduleNameList.add(it.name)
}
}

return moduleNameList
}

static List<String> getChangedModuleList(Project project, List<String> changedFilePaths) {
final List<PathModule> pathModuleList = new ArrayList<>()
File rootDir = project.rootProject.rootDir
project.subprojects {
String relativePath = rootDir.toURI().relativize(it.projectDir.toURI()).getPath()
pathModuleList.add(new PathModule(relativePath, it.name))
if (project.subprojects.size() <= 0) {
String relativePath = rootDir.toURI().relativize(project.projectDir.toURI()).getPath()
pathModuleList.add(new PathModule(relativePath, project.name))
} else {
project.subprojects {
String relativePath = rootDir.toURI().relativize(it.projectDir.toURI()).getPath()
pathModuleList.add(new PathModule(relativePath, it.name))
}
}

final List<String> changedModuleNameList = new ArrayList<>()
Expand Down

0 comments on commit 1b69f5d

Please sign in to comment.