-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get branch name from env var, refactor (#74)
- Loading branch information
Showing
3 changed files
with
37 additions
and
61 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 was deleted.
Oops, something went wrong.
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,29 @@ | ||
package com.gradle; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
import static com.gradle.Utils.execAndGetStdOut; | ||
|
||
class GitMetadataResolver { | ||
|
||
private final boolean isGitInstalled; | ||
|
||
GitMetadataResolver(boolean isGitInstalled) { | ||
this.isGitInstalled = isGitInstalled; | ||
} | ||
|
||
Optional<String> resolve(String... args) { | ||
return resolve( null, args); | ||
} | ||
|
||
Optional<String> resolve(Supplier<Optional<String>> fromEnv, String... args) { | ||
if (fromEnv != null) { | ||
return fromEnv.get(); | ||
} | ||
if (isGitInstalled && args != null) { | ||
return execAndGetStdOut(args); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |