-
Notifications
You must be signed in to change notification settings - Fork 208
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
f1a56ff
commit 2fcea78
Showing
9 changed files
with
165 additions
and
256 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
repositories { | ||
mavenCentral() | ||
google() | ||
} | ||
|
||
dependencies { | ||
implementation libs.plugin.android | ||
implementation libs.plugin.kotlin | ||
} |
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,9 @@ | ||
rootProject.name = 'build-support' | ||
|
||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files('../gradle/libs.versions.toml')) | ||
} | ||
} | ||
} |
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,114 @@ | ||
import com.android.build.gradle.internal.publishing.AndroidArtifacts | ||
import org.gradle.api.artifacts.transform.TransformParameters | ||
import org.gradle.api.internal.artifacts.transform.UnzipTransform | ||
import org.gradle.work.DisableCachingByDefault | ||
import java.nio.file.Files | ||
import java.util.zip.ZipFile | ||
|
||
configurations { | ||
unzip { | ||
attributes.attribute(AndroidArtifacts.ARTIFACT_TYPE, ArtifactTypeDefinition.DIRECTORY_TYPE) | ||
} | ||
} | ||
|
||
configureAarAsJarForConfiguration("compileOnly") | ||
configureAarAsJarForConfiguration("testImplementation") | ||
|
||
dependencies { | ||
registerTransform(UnzipTransform) { | ||
from.attribute(AndroidArtifacts.ARTIFACT_TYPE, ArtifactTypeDefinition.JAR_TYPE) | ||
to.attribute(AndroidArtifacts.ARTIFACT_TYPE, ArtifactTypeDefinition.DIRECTORY_TYPE) | ||
} | ||
registerTransform(IdentityTransform) { | ||
from.attribute(AndroidArtifacts.ARTIFACT_TYPE, "jar") | ||
to.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") | ||
} | ||
registerTransform(ExtractClassesJarTransform) { | ||
from.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aar") | ||
to.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") | ||
} | ||
} | ||
|
||
def configureAarAsJarForConfiguration(String configuration) { | ||
def aarAsJar = project.configurations | ||
.create("${configuration}AarAsJar") { | ||
canBeResolved = true | ||
attributes.attribute( | ||
AndroidArtifacts.ARTIFACT_TYPE, | ||
"release" | ||
) | ||
attributes.attribute( | ||
Usage.USAGE_ATTRIBUTE, | ||
project.getObjects().named(Usage, Usage.JAVA_API) | ||
) | ||
}.incoming | ||
.artifactView { viewConfiguration -> | ||
viewConfiguration.attributes.attribute(AndroidArtifacts.ARTIFACT_TYPE, "aarAsJar") | ||
} | ||
.files | ||
|
||
project.configurations | ||
.getByName(configuration) | ||
.dependencies | ||
.add(project.dependencies.create(aarAsJar)) | ||
} | ||
|
||
@DisableCachingByDefault | ||
abstract class IdentityTransform implements TransformAction<TransformParameters.None> { | ||
@PathSensitive(PathSensitivity.ABSOLUTE) | ||
@InputArtifact | ||
abstract Provider<FileSystemLocation> getInputArtifact() | ||
|
||
@Override | ||
void transform(TransformOutputs transformOutputs) { | ||
def input = getInputArtifact().get().asFile | ||
if (input.isDirectory()) { | ||
transformOutputs.dir(input) | ||
} else if (input.isFile()) { | ||
transformOutputs.file(input) | ||
} else { | ||
throw new IllegalArgumentException( | ||
"File/directory does not exist: ${input.absolutePath}" | ||
) | ||
} | ||
} | ||
} | ||
|
||
@DisableCachingByDefault | ||
abstract class ExtractClassesJarTransform implements TransformAction<TransformParameters.None> { | ||
@PathSensitive(PathSensitivity.NAME_ONLY) | ||
@InputArtifact | ||
abstract Provider<FileSystemLocation> getPrimaryInput() | ||
|
||
@Override | ||
void transform(TransformOutputs outputs) { | ||
ZipFile zip = null | ||
try { | ||
def file = getPrimaryInput().get().asFile | ||
def aarFilename = file.name.substring(0, file.name.lastIndexOf('.')) | ||
zip = new ZipFile(file) | ||
def entries = zip.entries() | ||
while (entries.hasMoreElements()) { | ||
def item = entries.nextElement() | ||
if (item.isDirectory()) continue | ||
|
||
if (item.name == "classes.jar") { | ||
def output = outputs.file(aarFilename + "-" + item.name) | ||
def inputStream = null | ||
try { | ||
inputStream = zip.getInputStream(item) | ||
Files.copy(inputStream, output.toPath()) | ||
} finally { | ||
if (inputStream != null) { | ||
inputStream.close() | ||
} | ||
} | ||
} | ||
} | ||
} finally { | ||
if (zip != null) { | ||
zip.close() | ||
} | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
paparazzi-annotations/src/main/java/app/cash/paparazzi/annotations/PaparazziPreviewData.kt
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,31 @@ | ||
package app.cash.paparazzi.annotations | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
public sealed interface PaparazziPreviewData { | ||
|
||
public data class Default( | ||
val snapshotName: String, | ||
val composable: @Composable () -> Unit | ||
) : PaparazziPreviewData { | ||
override fun toString(): String = snapshotName | ||
} | ||
|
||
public data class Provider<T>( | ||
val snapshotName: String, | ||
val composable: @Composable (T) -> Unit | ||
) : PaparazziPreviewData { | ||
override fun toString(): String = snapshotName | ||
} | ||
|
||
public data object Empty : PaparazziPreviewData { | ||
override fun toString(): String = "Empty" | ||
} | ||
|
||
public data class Error( | ||
val snapshotName: String, | ||
val message: String | ||
) : PaparazziPreviewData { | ||
override fun toString(): String = snapshotName | ||
} | ||
} |
82 changes: 0 additions & 82 deletions
82
paparazzi-annotations/src/main/java/app/cash/paparazzi/annotations/PreviewModels.kt
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
paparazzi-annotations/src/main/java/app/cash/paparazzi/annotations/PreviewUtils.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.