• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.ant;
18 
19 import org.apache.tools.ant.Task;
20 
21 /**
22  * Base class for tasks that should exec when the build type change.
23  */
24 public abstract class BuildTypedTask extends Task {
25 
26     private String mPreviousBuildType;
27     private String mBuildType;
28 
29     /** Sets the current build type */
setBuildType(String buildType)30     public void setBuildType(String buildType) {
31         mBuildType = buildType;
32     }
33 
34     /** Sets the previous build type */
setPreviousBuildType(String previousBuildType)35     public void setPreviousBuildType(String previousBuildType) {
36         mPreviousBuildType = previousBuildType;
37     }
38 
getBuildType()39     protected String getBuildType() {
40         return mBuildType;
41     }
42 
43     /**
44      * Returns if it is a new build. If the build type is not input
45      * from the XML, this always returns true.
46      * A build type is defined by having an empty previousBuildType.
47      */
isNewBuild()48     protected boolean isNewBuild() {
49         return mBuildType == null || mPreviousBuildType.length() == 0;
50     }
51 
52     /**
53      * Returns true if the build type changed.
54      */
hasBuildTypeChanged()55     protected boolean hasBuildTypeChanged() {
56         // no build type? return false as the feature is simply not used
57         if (mBuildType == null && mPreviousBuildType == null) {
58             return false;
59         }
60 
61         return mBuildType.equals(mPreviousBuildType) == false;
62     }
63 }
64