12ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll@echo off
22ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Copyright (C) 2007 The Android Open Source Project
32ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem
42ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Licensed under the Apache License, Version 2.0 (the "License");
52ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem you may not use this file except in compliance with the License.
62ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem You may obtain a copy of the License at
72ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem
82ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem      http://www.apache.org/licenses/LICENSE-2.0
92ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem
102ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Unless required by applicable law or agreed to in writing, software
112ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem distributed under the License is distributed on an "AS IS" BASIS,
122ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem See the License for the specific language governing permissions and
142ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem limitations under the License.
152ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
162ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Useful links:
172ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Command-line reference:
182ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem   http://technet.microsoft.com/en-us/library/bb490890.aspx
192ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
202ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem don't modify the caller's environment
212ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollsetlocal
222ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
232ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Set up prog to be the path of this script, including following symlinks,
242ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem and set up progdir to be the fully-qualified pathname of its directory.
252ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollset prog=%~f0
262ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
272ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Grab current directory before we change it
282ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollset work_dir="%cd%"
292ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
302ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Change current directory and drive to where the script is, to avoid
312ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem issues with directories containing whitespaces.
322ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollcd /d %~dp0
332ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
342ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
352ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Check we have a valid Java.exe in the path.
362ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollset java_exe=
372ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollcall lib\find_java.bat
382ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollif not defined java_exe goto :EOF
392ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
402ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollset jar_path=lib\sdkmanager.jar;lib\swtmenubar.jar
412ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
422ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Set SWT.Jar path based on current architecture (x86 or x86_64)
432ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollfor /f %%a in ('%java_exe% -jar lib\archquery.jar') do set swt_path=lib\%%a
442ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
452ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll:MkTempCopy
462ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    rem Copy android.bat and its required libs to a temp dir.
472ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    rem This avoids locking the tool dir in case the user is trying to update it.
482ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
492ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    set tmp_dir=%TEMP%\temp-android-tool
502ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    xcopy %swt_path% %tmp_dir%\%swt_path% /I /E /C /G /R /Y /Q > nul
512ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\common.jar         %tmp_dir%\lib\        > nul
522ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\commons-codec*     %tmp_dir%\lib\        > nul
532ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\commons-compress*  %tmp_dir%\lib\        > nul
542ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\commons-logging*   %tmp_dir%\lib\        > nul
552ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\dvlib.jar          %tmp_dir%\lib\        > nul
562ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\guava*             %tmp_dir%\lib\        > nul
572ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\httpclient*        %tmp_dir%\lib\        > nul
582ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\httpcore*          %tmp_dir%\lib\        > nul
592ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\httpmime*          %tmp_dir%\lib\        > nul
60ac9a36e9ffcc9fbe7c55154d0c6abd549ba371a8Raphael Moll    copy /B /D /Y lib\layoutlib-api.jar  %tmp_dir%\lib\        > nul
615ceca33c09ffe352bf06b605214275914e626802Raphael Moll    copy /B /D /Y lib\org-eclipse-*      %tmp_dir%\lib\        > nul
622ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\sdk*               %tmp_dir%\lib\        > nul
632ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    copy /B /D /Y lib\swtmenubar.jar     %tmp_dir%\lib\        > nul
642ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
652ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
662ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    set tools_dir=%cd%
672ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    cd /d %tmp_dir%
682ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
692ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll:EndTempCopy
702ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
712ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem The global ANDROID_SWT always override the SWT.Jar path
722ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollif defined ANDROID_SWT set swt_path=%ANDROID_SWT%
732ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
742ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollif exist %swt_path% goto SetPath
752ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    echo ERROR: SWT folder '%swt_path%' does not exist.
762ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
772ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll    goto :EOF
782ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
792ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll:SetPath
802ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem Finally exec the java program and end here.
812ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael MollREM set REMOTE_DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
822ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollcall %java_exe% %REMOTE_DEBUG% -Dcom.android.sdkmanager.toolsdir="%tools_dir%" -Dcom.android.sdkmanager.workdir=%work_dir% -classpath "%jar_path%;%swt_path%\swt.jar" com.android.sdkmanager.Main %*
832ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Moll
842ecff7c9e52fb3fefa0311358fccbc668099cd7aRaphael Mollrem EOF
85