Home | History | Annotate | Download | only in build
      1 /*
      2  * Copyright (C) 2010 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 com.android.tradefed.build;
     18 
     19 import com.android.tradefed.util.FileUtil;
     20 
     21 import java.io.File;
     22 import java.io.IOException;
     23 import java.util.ArrayList;
     24 import java.util.List;
     25 
     26 /**
     27  * A {@link IBuildInfo} that represents an Android application and its test package(s).
     28  */
     29 public class AppBuildInfo extends BuildInfo implements IAppBuildInfo {
     30 
     31     private static final long serialVersionUID = BuildSerializedVersion.VERSION;
     32     private List<VersionedFile> mAppPackageFiles = new ArrayList<VersionedFile>();
     33 
     34     /**
     35      * Creates a {@link AppBuildInfo}.
     36      *
     37      * @param buildId the unique build id
     38      * @param buildName the build name
     39      */
     40     public AppBuildInfo(String buildId, String buildName) {
     41         super(buildId, buildName);
     42     }
     43 
     44     /**
     45      * @see BuildInfo#BuildInfo(BuildInfo)
     46      */
     47     public AppBuildInfo(BuildInfo buildToCopy) {
     48         super(buildToCopy);
     49     }
     50 
     51     /**
     52      * {@inheritDoc}
     53      */
     54     @Override
     55     public List<VersionedFile> getAppPackageFiles() {
     56         List<VersionedFile> listCopy = new ArrayList<VersionedFile>(mAppPackageFiles.size());
     57         listCopy.addAll(mAppPackageFiles);
     58         return listCopy;
     59     }
     60 
     61     /**
     62      * {@inheritDoc}
     63      */
     64     @Override
     65     public void addAppPackageFile(File appPackageFile, String version) {
     66         mAppPackageFiles.add(new VersionedFile(appPackageFile, version));
     67     }
     68 
     69     /**
     70      * Removes all temporary files
     71      */
     72     @Override
     73     public void cleanUp() {
     74         for (VersionedFile appPackageFile : mAppPackageFiles) {
     75             appPackageFile.getFile().delete();
     76         }
     77         mAppPackageFiles.clear();
     78     }
     79 
     80     /**
     81      * {@inheritDoc}
     82      */
     83     @Override
     84     public IBuildInfo clone() {
     85         AppBuildInfo copy = new AppBuildInfo(getBuildId(), getBuildTargetName());
     86         copy.addAllBuildAttributes(this);
     87         try {
     88             for (VersionedFile origVerFile : mAppPackageFiles) {
     89                 // Only using createTempFile to create a unique dest filename
     90                 File origFile = origVerFile.getFile();
     91                 File copyFile = FileUtil.createTempFile(FileUtil.getBaseName(origFile.getName()),
     92                         FileUtil.getExtension(origFile.getName()));
     93                 copyFile.delete();
     94                 FileUtil.hardlinkFile(origFile, copyFile);
     95                 copy.addAppPackageFile(copyFile, origVerFile.getVersion());
     96             }
     97         } catch (IOException e) {
     98             throw new RuntimeException(e);
     99         }
    100         copy.setBuildBranch(getBuildBranch());
    101         copy.setBuildFlavor(getBuildFlavor());
    102 
    103         return copy;
    104     }
    105 }
    106