fix: 🐛 Fix running on macos

This commit is contained in:
Andreas Fahrecker 2024-05-19 20:45:14 +02:00
parent 8755904ca5
commit c478bfec45
3 changed files with 146 additions and 2 deletions

View File

@ -0,0 +1,8 @@
package com.fahrecker.gradle
import org.gradle.api.Project
class FlutterExtension {
public FlutterExtension(Project project) {
}
}

View File

@ -0,0 +1,117 @@
package com.fahrecker.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
class FlutterGradlePlugin implements Plugin<Project> {
void apply(Project project) {
FlutterExtension extension = project.extensions.create("flutter", FlutterExtension, project)
project.task("flutterDoctor") {
group = "flutter"
doLast {
project.exec {
commandLine flutterCommand("doctor")
}
}
}
project.task("flutterVersion") {
group = "flutter"
doLast {
project.exec {
commandLine flutterCommand("--version")
}
}
}
project.task("dartBuildRunner") {
group = "flutter"
doLast {
project.exec {
commandLine dartCommand("run", "build_runner", "build", "--delete-conflicting-outputs")
}
}
}
project.task("flutterBuildApk") {
group = "flutter"
doLast {
project.exec {
commandLine flutterCommand("build", "apk")
}
}
}
project.task("flutterBuildWeb") {
group = "flutter"
doLast {
project.exec {
commandLine flutterCommand("build", "web")
}
}
}
project.task("flutterBuildWindows") {
group = "flutter"
doLast {
project.exec {
commandLine flutterCommand("build", "windows")
}
}
}
project.task("flutterRunChrome") {
group = "flutter"
doLast {
project.exec {
commandLine flutterCommand("run", "-d", "chrome")
}
}
}
project.task("flutterRunWindows") {
group = "flutter"
doLast {
project.exec {
commandLine flutterCommand("run", "-d", "windows")
}
}
}
}
List<String> dartCommand(String... args) {
String osName = System.getProperty('os.name').toLowerCase();
if (osName.contains('windows')) {
return ['cmd', '/c', 'dart'] + args.toList()
} else if (osName.contains('mac')) {
String dartPath = new ByteArrayOutputStream().withStream { os ->
exec {
commandLine 'which', 'dart'
standardOutput = os
}
os.toString().trim()
return [dartPath] + args.toList()
}
} else {
return ['dart'] + args.toList()
}
}
List<String> flutterCommand(String... args) {
String osName = System.getProperty('os.name').toLowerCase();
if (osName.contains('windows')) {
return ['cmd', '/c', 'flutter'] + args.toList()
} else if (osName.contains('mac')) {
String flutterPath = new ByteArrayOutputStream().withStream { os ->
exec {
commandLine 'which', 'flutter'
standardOutput = os
}
os.toString().trim()
return [flutterPath] + args.toList()
} else {
return ['flutter'] + args.toList()
}
}
}

View File

@ -81,16 +81,35 @@ class FlutterGradlePlugin implements Plugin<Project> {
} }
List<String> dartCommand(String... args) { List<String> dartCommand(String... args) {
if (System.getProperty('os.name').toLowerCase().contains('windows')) { String osName = System.getProperty('os.name').toLowerCase();
if (osName.contains('windows')) {
return ['cmd', '/c', 'dart'] + args.toList() return ['cmd', '/c', 'dart'] + args.toList()
} else if (osName.contains('mac')) {
String dartPath = new ByteArrayOutputStream().withStream { os ->
exec {
commandLine 'which', 'dart'
standardOutput = os
}
os.toString().trim()
return [dartPath] + args.toList()
}
} else { } else {
return ['dart'] + args.toList() return ['dart'] + args.toList()
} }
} }
List<String> flutterCommand(String... args) { List<String> flutterCommand(String... args) {
if (System.getProperty('os.name').toLowerCase().contains('windows')) { String osName = System.getProperty('os.name').toLowerCase();
if (osName.contains('windows')) {
return ['cmd', '/c', 'flutter'] + args.toList() return ['cmd', '/c', 'flutter'] + args.toList()
} else if (osName.contains('mac')) {
String flutterPath = new ByteArrayOutputStream().withStream { os ->
exec {
commandLine 'which', 'flutter'
standardOutput = os
}
os.toString().trim()
return [flutterPath] + args.toList()
} else { } else {
return ['flutter'] + args.toList() return ['flutter'] + args.toList()
} }