Skip to content

Commit 39b066e

Browse files
author
Andreas Rossbacher
committed
Manifest generation: fail on write errors, clean up logging
- ManifestGenerator: throw DeepLinkProcessorException on IOException instead of swallowing as a diagnostic warning (a missing manifest would otherwise fail silently in a confusing downstream place). Catch scoped to IOException so processor bugs aren't hidden. - RelocateDeepLinkManifestTask: use orNull instead of get() on the @optional kspManifestFile property (get() NPEs when unset), replace println with logger.warn, collapse empty else-if branch, fix typos. - GenerateManifestIntentFiltersForDeeplinkDispatchTask: replace println with logger.warn (respects --quiet) and switch error(...) calls to throw GradleException for idiomatic build-failure output.
1 parent 4f94747 commit 39b066e

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

deeplinkdispatch-gradle-plugin/src/main/java/com/airbnb/deeplinkdispatch/gradleplugin/GenerateManifestIntentFiltersForDeeplinkDispatchTask.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.android.manifmerger.ManifestMerger2
55
import com.android.manifmerger.MergingReport
66
import com.android.utils.StdLogger
77
import org.gradle.api.DefaultTask
8+
import org.gradle.api.GradleException
89
import org.gradle.api.file.DirectoryProperty
910
import org.gradle.api.file.RegularFileProperty
1011
import org.gradle.api.provider.Property
@@ -82,12 +83,12 @@ abstract class GenerateManifestIntentFiltersForDeeplinkDispatchTask : DefaultTas
8283
generatedManifestFile.length() > 0
8384

8485
if (!hasGeneratedManifest) {
85-
println(
86+
logger.warn(
8687
"No DeepLinkDispatch generated manifest found or manifest is empty. Copying input" +
87-
" manifest to output without modifications. You might have applied the" +
88-
" deep link dispatch gradle plugin to a module that does not have deep" +
89-
" links defined or you forgot the set the `activityClassFqn` on your deep" +
90-
" links."
88+
" manifest to output without modifications. You might have applied the" +
89+
" deep link dispatch gradle plugin to a module that does not have deep" +
90+
" links defined or you forgot to set the `activityClassFqn` on your deep" +
91+
" links.",
9192
)
9293
inputManifest.copyTo(outputManifest, overwrite = true)
9394
return
@@ -112,7 +113,7 @@ abstract class GenerateManifestIntentFiltersForDeeplinkDispatchTask : DefaultTas
112113
val merge = invoker.merge()
113114
if (merge.result.isSuccess) {
114115
val mergedDocument = merge.getMergedDocument(MergingReport.MergedManifestKind.MERGED)
115-
?: error("Failed to get merged document")
116+
?: throw GradleException("DeepLinkDispatch: failed to get merged manifest document")
116117
outputManifest.writeText(mergedDocument)
117118
} else {
118119
val errorMessage = buildString {
@@ -121,7 +122,7 @@ abstract class GenerateManifestIntentFiltersForDeeplinkDispatchTask : DefaultTas
121122
appendLine(" ${record.severity}: ${record.message}")
122123
}
123124
}
124-
error(errorMessage)
125+
throw GradleException(errorMessage)
125126
}
126127
}
127128

deeplinkdispatch-gradle-plugin/src/main/java/com/airbnb/deeplinkdispatch/gradleplugin/RelocateDeepLinkManifestTask.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,18 @@ abstract class RelocateDeepLinkManifestTask : DefaultTask() {
4141
// 2. Gradle's up-to-date check only compares content, not file existence
4242
// 3. The task deletes the source file, which needs to happen every time
4343
outputs.upToDateWhen {
44-
// Task is only up-to-date if source file doesn't exist
45-
!kspManifestFile.get().asFile.exists()
44+
val source = kspManifestFile.orNull?.asFile
45+
source == null || !source.exists()
4646
}
4747
}
4848

4949
@TaskAction
5050
fun taskAction() {
51-
val sourceFile = kspManifestFile.get().asFile
51+
val sourceFile = kspManifestFile.orNull?.asFile
5252
val destFile = safeManifestFile.get().asFile
5353

54-
if (sourceFile.exists()) {
55-
// Ensure parent directory exists
54+
if (sourceFile != null && sourceFile.exists()) {
5655
destFile.parentFile?.mkdirs()
57-
// Copy to safe location
5856
sourceFile.copyTo(destFile, overwrite = true)
5957
// Delete from KSP resources to prevent Java resource merge conflict
6058
if (sourceFile.delete()) {
@@ -70,14 +68,13 @@ abstract class RelocateDeepLinkManifestTask : DefaultTask() {
7068
parentDir = nextParent
7169
}
7270
}
73-
} else if (destFile.exists()) {
74-
// Source doesn't exist but dest does - this can happen on incremental builds
75-
// where KSP was UP-TO-DATE and we already moved the file previously.
76-
// The dest file is still valid, so nothing to do.
77-
} else {
78-
// Neither file exists - no manifest was generated
79-
println("No DeepLinkDispatch manifest found to relocate in ${project.name}. If this module has no deep links, consider" +
80-
"removing the DeepLinkDispatch gradle plugin from it's gradle file.")
71+
} else if (!destFile.exists()) {
72+
logger.warn(
73+
"No DeepLinkDispatch manifest found to relocate in ${project.name}. " +
74+
"If this module has no deep links, consider removing the DeepLinkDispatch " +
75+
"gradle plugin from its gradle file.",
76+
)
8177
}
78+
// If source is gone but dest exists, a previous run already relocated it — nothing to do.
8279
}
8380
}

deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/metadata/ManifestGenerator.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import androidx.room.compiler.processing.XFiler
55
import androidx.room.compiler.processing.XMessager
66
import androidx.room.compiler.processing.XProcessingEnv
77
import com.airbnb.deeplinkdispatch.DeepLinkAnnotatedElement
8+
import com.airbnb.deeplinkdispatch.DeepLinkProcessorException
89
import com.airbnb.deeplinkdispatch.base.ManifestGeneration
910
import com.airbnb.deeplinkdispatch.metadata.writers.ManifestWriter
1011
import com.airbnb.deeplinkdispatch.metadata.writers.Writer
12+
import java.io.IOException
1113
import java.io.PrintWriter
1214
import java.io.StringWriter
1315
import java.nio.file.Path
@@ -108,10 +110,10 @@ internal class ManifestGenerator(
108110
Diagnostic.Kind.NOTE,
109111
"Manifest generation: Generated at KSP resource output: ${ManifestGeneration.MANIFEST_RESOURCE_PATH}",
110112
)
111-
} catch (e: Exception) {
112-
messager.printMessage(
113-
Diagnostic.Kind.ERROR,
114-
"Manifest generation failed: ${e.message}",
113+
} catch (e: IOException) {
114+
throw DeepLinkProcessorException(
115+
"Manifest generation failed: could not write " +
116+
"${ManifestGeneration.MANIFEST_RESOURCE_PATH}: ${e.message}",
115117
)
116118
}
117119
}

0 commit comments

Comments
 (0)