-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from benbitrise/bb/fix_config_cache
Access git info via ValueSource for Gradle Configuration Cache Compatibility
- Loading branch information
Showing
17 changed files
with
244 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ out | |
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
.vscode/ | ||
bin/ |
Binary file not shown.
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
24 changes: 21 additions & 3 deletions
24
src/main/java/org/shipkit/auto/version/AutoVersionPlugin.java
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 |
---|---|---|
@@ -1,17 +1,35 @@ | ||
package org.shipkit.auto.version; | ||
|
||
import java.io.File; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.provider.ProviderFactory; | ||
|
||
/** | ||
* The plugin, ideally with zero business logic, but only the Gradle integration code | ||
* The plugin, ideally with zero business logic, but only the Gradle integration | ||
* code | ||
*/ | ||
public class AutoVersionPlugin implements Plugin<Project> { | ||
|
||
private final ProviderFactory providerFactory; | ||
|
||
@Inject | ||
public AutoVersionPlugin(ProviderFactory providerFactory) { | ||
this.providerFactory = providerFactory; | ||
} | ||
|
||
public void apply(Project project) { | ||
DeducedVersion version = new AutoVersion(project.getProjectDir()).deduceVersion(project.getVersion().toString()); | ||
File versionFile = new File(project.getProjectDir(), "version.properties"); | ||
GitValueSourceProviderFactory gitValueSourceProviderFactory = new GitValueSourceProviderFactory(project.getProjectDir(), providerFactory); | ||
AutoVersion autoVersion = new AutoVersion(gitValueSourceProviderFactory, versionFile); | ||
DeducedVersion version = autoVersion.deduceVersion(project.getVersion().toString()); | ||
|
||
project.allprojects(p -> p.setVersion(version.getVersion())); | ||
project.getExtensions().getExtraProperties().set("shipkit-auto-version.previous-version", version.getPreviousVersion()); | ||
project.getExtensions().getExtraProperties().set("shipkit-auto-version.previous-version", | ||
version.getPreviousVersion()); | ||
project.getExtensions().getExtraProperties().set("shipkit-auto-version.previous-tag", version.getPreviousTag()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/shipkit/auto/version/GitValueSource.java
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,59 @@ | ||
package org.shipkit.auto.version; | ||
|
||
import static java.lang.String.join; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.provider.ValueSource; | ||
import org.gradle.process.ExecOperations; | ||
import org.gradle.process.ExecResult; | ||
|
||
public abstract class GitValueSource implements ValueSource<String, GitValueSourceParameters> { | ||
|
||
private final ExecOperations execOperations; | ||
|
||
@Inject | ||
public GitValueSource(ExecOperations execOperations) { | ||
this.execOperations = execOperations; | ||
} | ||
|
||
@Override | ||
public String obtain() { | ||
File workDir = getParameters().getWorkingDirectory().get(); | ||
|
||
String[] commands = getParameters().getCommands().get(); | ||
String[] commandsArray = new String[commands.length + 1]; | ||
commandsArray[0] = "git"; | ||
System.arraycopy(commands, 0, commandsArray, 1, commands.length); | ||
|
||
int exitValue; | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
ExecResult result; | ||
|
||
try { | ||
result = execOperations.exec(execSpec -> { | ||
execSpec.commandLine((Object[]) commandsArray); | ||
execSpec.workingDir(workDir); | ||
execSpec.setStandardOutput(outputStream); | ||
execSpec.setErrorOutput(outputStream); | ||
}); | ||
} catch (Exception e) { | ||
String cmdLine = join(" ", commandsArray); | ||
throw new ShipkitAutoVersionException("Problems executing command:\n " + cmdLine, e); | ||
} | ||
|
||
String output = outputStream.toString(); | ||
exitValue = result.getExitValue(); | ||
|
||
if (exitValue != 0) { | ||
String cmdLine = join(" ", commandsArray); | ||
throw new ShipkitAutoVersionException( | ||
"Problems executing command (exit code: " + exitValue + "): " + cmdLine + "\n" + | ||
"Output:\n" + output); | ||
} | ||
|
||
return output; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/shipkit/auto/version/GitValueSourceParameters.java
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,10 @@ | ||
package org.shipkit.auto.version; | ||
|
||
import java.io.File; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.provider.ValueSourceParameters; | ||
|
||
public interface GitValueSourceParameters extends ValueSourceParameters { | ||
Property<File> getWorkingDirectory(); | ||
Property<String[]> getCommands(); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/shipkit/auto/version/GitValueSourceProviderFactory.java
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,27 @@ | ||
package org.shipkit.auto.version; | ||
|
||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.provider.ProviderFactory; | ||
|
||
import java.io.File; | ||
|
||
public class GitValueSourceProviderFactory { | ||
|
||
private final File workingDirectory; | ||
private final ProviderFactory providerFactory; | ||
|
||
public GitValueSourceProviderFactory(File workingDirectory, ProviderFactory providerFactory) { | ||
this.workingDirectory = workingDirectory; | ||
this.providerFactory = providerFactory; | ||
} | ||
|
||
Provider<String> getProvider(String[] params) { | ||
return providerFactory.of(GitValueSource.class, spec -> { | ||
spec.parameters(parameters -> { | ||
parameters.getCommands().set(params); | ||
parameters.getWorkingDirectory().set(workingDirectory); | ||
}); | ||
}); | ||
} | ||
|
||
} |
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
Oops, something went wrong.