forked from prebid/prebid-mobile-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildprebid.sh
executable file
·250 lines (219 loc) · 5.79 KB
/
buildprebid.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#! /bin/bash
# This script helps to build the Prebid products in the following steps:
# It will ask you the version you're releasing
# Check if it's the same as the one in the project's build.gradle
# If not, ask you to pick one, and update build.gradle if necessary
# Run unit tests
# Stop releasing if unit tests doesn't pass
# Package releases
# End
######################
# Helper Methods
######################
set -e
function echoX {
echo -e "PREBID BUILDLOG: $@"
}
spinner()
{
local pid=$1
local delay=0.75
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
# how to use?
# ( command ) & spinner $!
# Example: (sleep 2) & spinner $!
bold=$(tput bold)
normal=$(tput sgr0)
die() { echoX "$@" 1>&2 ; echoX "End Script"; exit 1; }
######################
# Build Settings
######################
# exit script if a command line fails
#set -e
# file paths
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUTDIR=$BASEDIR/out
LOGPATH=$OUTDIR/logs
AARPATH=build/outputs/aar
TEMPDIR=$BASEDIR/temp
LIBDIR=$BASEDIR/PrebidMobile
PREBIDCORE=("PrebidMobileCore")
DEMANDSOURCES=()
DEMANDSOURCES+=("PrebidServerAdapter")
# set the default release version to what's in the project's build.gradle file
RELEASE_VERSION=""
regex="prebidVersionName.*=.*\"(.*)\""
while read -r line;
do
if [[ $line =~ $regex ]];
then
RELEASE_VERSION=${BASH_REMATCH[1]};
fi
done < $LIBDIR/build.gradle
echoX "Start building Prebid Mobile version $RELEASE_VERSION"
###########################
# Prepare
###########################
echoX "Clean directories"
rm -rf $OUTDIR
mkdir $OUTDIR
mkdir $LOGPATH
rm -rf $TEMPDIR
mkdir $TEMPDIR
###########################
# Test and Build
###########################
echoX "Run unit tests"
cd $LIBDIR
(./gradlew -i --no-daemon clean test > $LOGPATH/testResults.log 2>&1) || (die "Unit tests failed, check log in $LOGPATH/testResults.log") &
PID=$!
spinner $PID &
wait $PID
echoX "Assemble builds"
cd $LIBDIR
# clean existing build results, exclude test task, and assemble new release build
(./gradlew -i --no-daemon -x test build > $LOGPATH/build.log 2>&1 || die "Build failed, check log in $LOGPATH/build.log" ) &
PID=$!
spinner $PID &
wait $PID
echoX "Start packaging product"
cd $TEMPDIR
mkdir output
echoX "Move library core to output"
cd $LIBDIR/$PREBIDCORE/$AARPATH
unzip -q -o $PREBIDCORE-release.aar
cd $TEMPDIR/output
jar xf $LIBDIR/$PREBIDCORE/$AARPATH/classes.jar
rm $LIBDIR/$PREBIDCORE/$AARPATH/classes.jar
# combine demand sources with the prebid core
echoX "Move demand library to output"
for i in "${DEMANDSOURCES[@]}";
do
cd $LIBDIR/$i/$AARPATH
unzip -q -o $i-release.aar
cd $TEMPDIR/output
jar xf $LIBDIR/$i/$AARPATH/classes.jar
rm $LIBDIR/$i/$AARPATH/classes.jar
done
cd $TEMPDIR/output
jar cf PrebidMobile.jar org*
mv PrebidMobile.jar $OUTDIR
# clean tmp dir
rm -r $TEMPDIR
echoX "Prepare Demo App"
APPNAME="DemoApp"
cp -r $LIBDIR/$APPNAME $OUTDIR/$APPNAME
# update build.gradle
cd $OUTDIR/$APPNAME
rm build.gradle
cat > build.gradle << EOL
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
jcenter()
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId 'org.prebid.mobile.demoapp'
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName '1.0'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
// For aaid
compile 'com.google.android.gms:play-services-ads:9.2.1'
// From MoPub Android SDK docs
compile('com.mopub:mopub-sdk:4.15.0@aar') {
transitive = true
}
// Build from compiled libs
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.apache.commons:commons-text:1.1'
}
EOL
if [ ! -d libs ]; then
mkdir libs
fi
# add libs
cp ../PrebidMobile.jar libs/
# move gradlew here
cp -r $LIBDIR/gradle .
cp -r $LIBDIR/gradlew .
cp -r $LIBDIR/gradlew.bat .
cp -r $LIBDIR/gradle.properties .
chmod +x gradlew
./gradlew clean >/dev/null
# TODO maybe launch the app with an emulator for developer to test directly
# javadoc
echoX "Prepare Javedoc"
# class paths
CORE_API_PATH="PrebidMobileCore/src/main/java/org/prebid/mobile/core"
CORE_CLASSES=()
CORE_CLASSES+=("AdSize.java")
CORE_CLASSES+=("AdType.java")
CORE_CLASSES+=("AdUnit.java")
CORE_CLASSES+=("BannerAdUnit.java")
CORE_CLASSES+=("BidManager.java")
CORE_CLASSES+=("BidResponse.java")
CORE_CLASSES+=("DemandAdapter.java")
CORE_CLASSES+=("ErrorCode.java")
CORE_CLASSES+=("InterstitialAdUnit.java")
CORE_CLASSES+=("LogUtil.java")
CORE_CLASSES+=("Prebid.java")
CORE_CLASSES+=("PrebidException.java")
CORE_CLASSES+=("TargetingParams.java")
PREBID_SERVER_PATH="PrebidServerAdapter/src/main/java/org/prebid/mobile/prebidserver"
PREBID_SERVER_CLASSES=()
PREBID_SERVER_CLASSES+=("PrebidServerAdapter.java")
FINAL_CLASSES=""
for classes in "${CORE_CLASSES[@]}"; do
FINAL_CLASSES="$FINAL_CLASSES $LIBDIR/$CORE_API_PATH/$classes"
done
for classes in "${PREBID_SERVER_CLASSES[@]}"; do
FINAL_CLASSES="$FINAL_CLASSES $LIBDIR/$PREBID_SERVER_PATH/$classes"
done
cd $OUTDIR
# disable Javadoc for illegal pacakge name error
javadoc -d Javadoc -protected $FINAL_CLASSES>$LOGPATH/javadoc.log 2>&1 || die "Build Javadoc failed, check log in $LOGPATH/javadoc.log"
#######
# End
#######
echoX "Please find Prebid Mobile product in $OUTDIR"
echoX "Build finished."