-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d90841
commit deaf060
Showing
5 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/groovy/wooga/gradle/unitysonar/tasks/DotnetWindowsInstall.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package wooga.gradle.unitysonar.tasks | ||
|
||
import com.wooga.gradle.ArgumentsSpec | ||
import com.wooga.gradle.io.ExecSpec | ||
import com.wooga.gradle.io.ProcessExecutor | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.process.ExecResult | ||
import wooga.gradle.dotnetsonar.tasks.internal.Downloader | ||
|
||
class DotnetWindowsInstall extends DefaultTask implements ArgumentsSpec, ExecSpec { | ||
|
||
@InputFile | ||
final RegularFileProperty dotnetInstallScript = objects.fileProperty() | ||
@Input | ||
final Property<String> version = objects.property(String) | ||
@InputDirectory | ||
final DirectoryProperty installDir = objects.directoryProperty() | ||
@OutputFile | ||
final RegularFileProperty dotnetExecutable = objects.fileProperty() | ||
|
||
Provider<String> dotnetExecutable() { | ||
return dotnetExecutable.map { | ||
it.asFile.absolutePath | ||
} | ||
} | ||
|
||
DotnetWindowsInstall() { | ||
dotnetInstallScript.convention(layout.file(project.provider { | ||
def installer = File.createTempFile("dotnet-install", ".ps1") | ||
new Downloader().download("https://dot.net/v1/dotnet-install.ps1".toURL(), installer) | ||
return installer | ||
})) | ||
executableName.convention(dotnetInstallScript.asFile.map {it.absolutePath}) | ||
internalArguments = version.zip(installDir) { version, installDir -> | ||
["-Version", version, "-InstallDir", installDir.asFile.absolutePath, "-NoPath"] | ||
} | ||
dotnetExecutable.set(installDir.file("dotnet.exe")) | ||
onlyIf { | ||
def noDotnetExecutable = !installDir.file("dotnet").map {it.asFile.file }.getOrElse(false) | ||
if(!noDotnetExecutable) { | ||
logger.info("Dotnet executable already present in " + | ||
"${dotnetExecutable.get().asFile.absolutePath}, skipping...") | ||
} | ||
} | ||
} | ||
|
||
@TaskAction | ||
def install() { | ||
ExecResult execResult = ProcessExecutor.from(this) | ||
.withArguments(this) | ||
.withWorkingDirectory(workingDirectory.getOrNull()) | ||
.ignoreExitValue() | ||
.execute() | ||
execResult.assertNormalExitValue() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters