001/*
002 * Copyright (C) 2015-2021 KeepSafe Software
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package com.getkeepsafe.dexcount.treegen;
017
018import com.getkeepsafe.dexcount.treegen.workers.LegacyWorker;
019import org.gradle.api.file.FileCollection;
020import org.gradle.api.file.RegularFileProperty;
021import org.gradle.api.provider.Property;
022import org.gradle.api.tasks.CacheableTask;
023import org.gradle.api.tasks.InputFile;
024import org.gradle.api.tasks.InputFiles;
025import org.gradle.api.tasks.Optional;
026import org.gradle.api.tasks.PathSensitive;
027import org.gradle.api.tasks.PathSensitivity;
028
029import java.io.File;
030
031@CacheableTask
032public abstract class LegacyGeneratePackageTreeTask extends BaseGeneratePackageTreeTask<LegacyWorker.Params, LegacyWorker> {
033    /**
034     * The output of the 'package' task; will be either an APK or an AAR.
035     */
036    @InputFile
037    @PathSensitive(PathSensitivity.RELATIVE)
038    public abstract RegularFileProperty getInputFileProperty();
039
040    @Optional
041    @InputFiles
042    @PathSensitive(PathSensitivity.RELATIVE)
043    public abstract Property<FileCollection> getMappingFileProvider();
044
045    @Override
046    protected Class<LegacyWorker> getWorkerClass() {
047        return LegacyWorker.class;
048    }
049
050    @Override
051    protected void configureParams(LegacyWorker.Params params) {
052        super.configureParams(params);
053
054        File mappingFile = null;
055        FileCollection maybeMappingFiles = getMappingFileProvider().getOrNull();
056        if (maybeMappingFiles != null && !maybeMappingFiles.isEmpty()) {
057            mappingFile = maybeMappingFiles.getSingleFile();
058        }
059
060        params.getInputFile().set(getInputFileProperty());
061        params.getMappingFile().set(mappingFile);
062    }
063}