1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.tools.traces.io
18 
19 import android.tools.Timestamp
20 import android.tools.io.Artifact
21 import android.tools.io.RunStatus
22 import android.tools.io.TransitionTimeRange
23 
24 /**
25  * Contents of a flicker run (e.g. files, status, event log)
26  *
27  * @param _artifact Path to the artifact file
28  * @param _transitionTimeRange Transition start and end time
29  * @param _executionError Transition execution error (if any)
30  */
31 open class ResultData(
32     _artifact: Artifact,
33     _transitionTimeRange: TransitionTimeRange,
34     _executionError: Throwable?
35 ) : IResultData {
36     final override val artifact: Artifact = _artifact
37     final override val transitionTimeRange: TransitionTimeRange = _transitionTimeRange
38     final override val executionError: Throwable? = _executionError
39     final override val runStatus: RunStatus
40         get() = artifact.runStatus
41 
42     /** {@inheritDoc} */
<lambda>null43     override fun slice(startTimestamp: Timestamp, endTimestamp: Timestamp) = apply {
44         require(startTimestamp.hasAllTimestamps) {
45             "startTimestamp ($startTimestamp) has missing timestamps"
46         }
47         require(endTimestamp.hasAllTimestamps) {
48             "endTimestamp ($endTimestamp) has missing timestamps"
49         }
50         return ResultData(
51             artifact,
52             TransitionTimeRange(startTimestamp, endTimestamp),
53             executionError
54         )
55     }
56 
<lambda>null57     override fun toString(): String = buildString {
58         append(artifact)
59         append(" (status=")
60         append(runStatus)
61         executionError?.let {
62             append(", error=")
63             append(it.message)
64         }
65         append(") ")
66     }
67 
68     /** {@inheritDoc} */
<lambda>null69     override fun updateStatus(newStatus: RunStatus) = apply { artifact.updateStatus(newStatus) }
70 }
71