forked from QuiltMC/quilt-mappings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ArtifactFileProducingTask and implement it on CompressTinyTask
- Loading branch information
1 parent
bbfee5e
commit 6f3bcc0
Showing
7 changed files
with
96 additions
and
18 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
78 changes: 78 additions & 0 deletions
78
buildSrc/src/main/java/quilt/internal/tasks/ArtifactFileProducingTask.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,78 @@ | ||
package quilt.internal.tasks; | ||
|
||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.file.RegularFile; | ||
import org.gradle.api.model.ObjectFactory; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.publish.maven.MavenPublication; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Internal; | ||
import org.gradle.api.tasks.Optional; | ||
import org.gradle.api.tasks.OutputFile; | ||
|
||
import javax.inject.Inject; | ||
|
||
// TODO would it be screwy to implement PublishArtifact on this? | ||
// It would allow passing the task itself to MavenPublication#artifact, instead of artifactFile. | ||
|
||
/** | ||
* A task that produces an {@link #getArtifactFile() artifactFile}. | ||
* <p> | ||
* The path to the {@link #getArtifactFile() artifactFile} is built from the task's name and destination properties, | ||
* and {@link MavenPublication#artifact(Object)} can interpolate artifact metadata from the name's format. | ||
*/ | ||
public interface ArtifactFileProducingTask extends MappingsTask { | ||
@Inject | ||
ObjectFactory getObjects(); | ||
|
||
@Input | ||
Property<String> getArtifactBaseName(); | ||
|
||
@Optional | ||
@Input | ||
Property<String> getArtifactAppendix(); | ||
|
||
@Optional | ||
@Input | ||
Property<String> getArtifactVersion(); | ||
|
||
@Optional | ||
@Input | ||
Property<String> getArtifactClassifier(); | ||
|
||
@Input | ||
Property<String> getArtifactExtension(); | ||
|
||
/** | ||
* Required | ||
*/ | ||
@Internal("Represented as part of artifactFile") | ||
DirectoryProperty getDestinationDirectory(); | ||
|
||
/** | ||
* The artifact produced by this task. | ||
* <p> | ||
* The path to the file takes the form:<br> | ||
* {@code [destination]/[baseName]-[appendix]-[version]-[classifier].[extension]} | ||
* <p> | ||
* This standard format allows {@link MavenPublication#artifact(Object)} to interpolate the | ||
* {@linkplain #getArtifactClassifier() classifier} and the {@linkplain #getArtifactExtension() extension}. | ||
*/ | ||
@OutputFile | ||
default Provider<RegularFile> getArtifactFile() { | ||
// zzzzzip | ||
return this.getArtifactBaseName() | ||
.zip(this.getArtifactAppendix().orElse(""), ArtifactFileProducingTask::dashJoin) | ||
.zip(this.getArtifactVersion().orElse(""), ArtifactFileProducingTask::dashJoin) | ||
.zip(this.getArtifactClassifier().orElse(""), ArtifactFileProducingTask::dashJoin) | ||
.zip(this.getArtifactExtension(), (name, ext) -> name + "." + ext) | ||
.zip(this.getDestinationDirectory(), (name, dest) -> dest.file(name)); | ||
} | ||
|
||
private static String dashJoin(String left, String right) { | ||
return right.isEmpty() | ||
? left | ||
: left + "-" + right; | ||
} | ||
} |
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