Browse Source

Add ant and jdk root to Android Build Settings and preferences

Josh Engebretson 10 years ago
parent
commit
bce41ad892

+ 25 - 8
Data/AtomicEditor/Resources/EditorData/AtomicEditor/editor/ui/buildsettings_android.tb.txt

@@ -22,21 +22,38 @@ TBLayout: axis: y, distribution: gravity, position: left
 				lp: min-width: 220
 				lp: min-width: 220
 	TBSeparator: gravity: left right, skin: AESeparator
 	TBSeparator: gravity: left right, skin: AESeparator
 	TBLayout: axis: y, position: left, distribution: gravity
 	TBLayout: axis: y, position: left, distribution: gravity
-		TBTextField: text: "Android SDK Path:"
+		TBTextField: text: "Android SDK Path:", skin: DarkGrayText
 		TBLayout: gravity: left right, distribution-position: right bottom
 		TBLayout: gravity: left right, distribution-position: right bottom
 			TBEditField: id: sdk_path, autofocus: 0
 			TBEditField: id: sdk_path, autofocus: 0
 				lp: min-width: 250
 				lp: min-width: 250
 			TBButton: text: "Choose" id: choose_sdk_path
 			TBButton: text: "Choose" id: choose_sdk_path
 	TBLayout: axis: y, position: left, distribution: gravity
 	TBLayout: axis: y, position: left, distribution: gravity
-		TBTextField: text: "Android API Level:"
+		TBTextField: text: "Android API Level:", skin: DarkGrayText
 		TBLayout: gravity: left right, distribution-position: right bottom
 		TBLayout: gravity: left right, distribution-position: right bottom
 			TBSelectDropdown: id: sdk_target_select
 			TBSelectDropdown: id: sdk_target_select
 				lp: min-width: 250
 				lp: min-width: 250
 			TBButton: text: "Refresh" id: refresh_sdk_targets
 			TBButton: text: "Refresh" id: refresh_sdk_targets
+	TBLayout: axis: y, position: left, distribution: gravity
+		TBTextField: text: "Ant Path:" id: ant_path_text, skin: DarkGrayText
+		TBLayout: gravity: left right, distribution-position: right bottom
+			TBEditField: id: ant_path, autofocus: 0
+				lp: min-width: 250
+			TBButton: text: "Choose" id: choose_ant_path
+	TBLayout: axis: y, position: left, distribution: gravity
+		TBTextField: text: "JDK Root:" id: jdk_root_text, skin: DarkGrayText
+		TBLayout: gravity: left right, distribution-position: right bottom
+			TBEditField: id: jdk_root, autofocus: 0
+				lp: min-width: 250
+			TBButton: text: "Choose" id: choose_jdk_root
 	TBSeparator: gravity: left right, skin: AESeparator
 	TBSeparator: gravity: left right, skin: AESeparator
-	TBTextField: text: "Icon:"
-	TBLayout: gravity: left right, distribution-position: right bottom
-		TBSkinImage: skin: LogoAtomic64
-	TBTextField: text: "Splash Screen:"
-	TBLayout: gravity: left right, distribution-position: right bottom
-		TBSkinImage: skin: LogoAtomic64
+	TBLayout:
+		TBLayout: axis: y
+			TBTextField: text: "Icon:"
+			TBLayout: gravity: left right, distribution-position: right bottom
+				TBSkinImage: skin: LogoAtomic64
+					lp: min-width: 64, min-height:64
+		TBLayout: axis: y
+			TBTextField: text: "Splash Screen:"
+			TBLayout: gravity: left right, distribution-position: right bottom
+				TBSkinImage: skin: LogoAtomic64
+					lp: min-width: 64, min-height:64

+ 14 - 0
Source/AtomicEditor/Source/AEPreferences.cpp

@@ -92,6 +92,14 @@ void AEPreferences::Read()
     if (android_sdk_path && android_sdk_path->value.IsString())
     if (android_sdk_path && android_sdk_path->value.IsString())
         androidSDKPath_ = android_sdk_path->value.GetString();
         androidSDKPath_ = android_sdk_path->value.GetString();
 
 
+    const Value::Member* jdk_root_path = document.FindMember("jdk_root_path");
+    if (jdk_root_path && jdk_root_path->value.IsString())
+        jdkRootPath_ = jdk_root_path->value.GetString();
+
+    const Value::Member* ant_path = document.FindMember("ant_path");
+    if (ant_path && ant_path->value.IsString())
+        antPath_ = ant_path->value.GetString();
+
     UpdateRecentFiles(false);
     UpdateRecentFiles(false);
 
 
 }
 }
@@ -134,6 +142,12 @@ void AEPreferences::Write()
     writer.String("android_sdk_path");
     writer.String("android_sdk_path");
     writer.String(androidSDKPath_.CString());
     writer.String(androidSDKPath_.CString());
 
 
+    writer.String("jdk_root_path");
+    writer.String(jdkRootPath_.CString());
+
+    writer.String("ant_path");
+    writer.String(antPath_.CString());
+
     writer.String("window_pos_x");
     writer.String("window_pos_x");
     writer.Int(pos.x_);
     writer.Int(pos.x_);
     writer.String("window_pos_y");
     writer.String("window_pos_y");

+ 7 - 0
Source/AtomicEditor/Source/AEPreferences.h

@@ -35,7 +35,12 @@ public:
     const Vector<String>& GetRecentProjects() { return recentProjects_; }
     const Vector<String>& GetRecentProjects() { return recentProjects_; }
 
 
     void SetAndroidSDKPath(const String& path) { androidSDKPath_ = path; Write(); }
     void SetAndroidSDKPath(const String& path) { androidSDKPath_ = path; Write(); }
+    void SetAntPath(const String& path) { antPath_ = path; Write(); }
+    void SetJDKRootPath(const String& path) { jdkRootPath_ = path; Write(); }
+
     String GetAndroidSDKPath() { return AddTrailingSlash(androidSDKPath_); }
     String GetAndroidSDKPath() { return AddTrailingSlash(androidSDKPath_); }
+    String GetJDKRootPath() { return AddTrailingSlash(jdkRootPath_); }
+    String GetAntPath() { return AddTrailingSlash(antPath_); }
 
 
     void Read();
     void Read();
     void Write();
     void Write();
@@ -52,6 +57,8 @@ private:
     String GetPreferencesFullPath();
     String GetPreferencesFullPath();
 
 
     String androidSDKPath_;
     String androidSDKPath_;
+    String jdkRootPath_;
+    String antPath_;
 
 
     String lastProjectFullPath_;
     String lastProjectFullPath_;
     Vector<String> recentProjects_;    
     Vector<String> recentProjects_;    

+ 7 - 3
Source/AtomicEditor/Source/Build/BuildAndroid.cpp

@@ -253,17 +253,21 @@ void BuildAndroid::RunADBListDevices()
 void BuildAndroid::RunAntDebug()
 void BuildAndroid::RunAntDebug()
 {
 {
     Editor* editor = GetSubsystem<Editor>();
     Editor* editor = GetSubsystem<Editor>();
+    AEPreferences* prefs = editor->GetPreferences();
     SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();
     SubprocessSystem* subs = GetSubsystem<SubprocessSystem>();
 
 
-    //TODO: ensure ant is on path, also JAVA_HOME env variable needs to be set jdk root on Windows
+     Poco::Process::Env env;
+
 #ifdef ATOMIC_PLATFORM_OSX
 #ifdef ATOMIC_PLATFORM_OSX
     String antCommand = "/usr/local/bin/ant";
     String antCommand = "/usr/local/bin/ant";
     Vector<String> args;
     Vector<String> args;
     args.Push("debug");
     args.Push("debug");
 #else
 #else
+     // C:\ProgramData\Oracle\Java\javapath;
     Vector<String> args;
     Vector<String> args;
     String antCommand = "cmd";
     String antCommand = "cmd";
-    String antPath = "C:\\Dev\\apache-ant-1.9.4\\bin\\ant.bat";
+    String antPath = prefs->GetAntPath() + "/ant.bat";
+    env["JAVA_HOME"] = prefs->GetJDKRootPath().CString();
     // ant is a batch file on windows, so have to run with cmd /c
     // ant is a batch file on windows, so have to run with cmd /c
     args.Push("/c");
     args.Push("/c");
     args.Push("\"" + antPath + "\"");
     args.Push("\"" + antPath + "\"");
@@ -271,7 +275,7 @@ void BuildAndroid::RunAntDebug()
 #endif
 #endif
 
 
     currentBuildPhase_ = AntBuildDebug;
     currentBuildPhase_ = AntBuildDebug;
-    Subprocess* subprocess = subs->Launch(antCommand, args, buildPath_);
+    Subprocess* subprocess = subs->Launch(antCommand, args, buildPath_, env);
 
 
     if (!subprocess)
     if (!subprocess)
     {
     {

+ 54 - 0
Source/AtomicEditor/Source/Project/ProjectUtils.cpp

@@ -116,6 +116,60 @@ String ProjectUtils::GetAndroidSDKPath(const String& defaultPath)
 
 
 }
 }
 
 
+String ProjectUtils::GetAntPath(const String& defaultPath)
+{
+    String antPath;
+
+    nfdchar_t *outPath = NULL;
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+    String msg = "Please select the folder which contains ant.bat";
+#else
+     String msg = "Please select the folder which contains the ant executable";
+#endif
+
+    nfdresult_t result = NFD_ChooseDirectory( msg.CString(),
+                                defaultPath.Length() ? defaultPath.CString() : NULL,
+                                &outPath);
+
+    if (outPath && result == NFD_OKAY)
+    {
+        antPath = outPath;
+    }
+
+    if (outPath)
+        free(outPath);
+
+    GetSubsystem<Graphics>()->RaiseWindow();
+
+    return GetInternalPath(antPath);
+}
+
+String ProjectUtils::GetJDKRootPath(const String& defaultPath)
+{
+    String jdkPath;
+
+    nfdchar_t *outPath = NULL;
+
+    nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder of your JDK",
+                                defaultPath.Length() ? defaultPath.CString() : NULL,
+                                &outPath);
+
+    if (outPath && result == NFD_OKAY)
+    {
+        jdkPath = outPath;
+    }
+
+    if (outPath)
+        free(outPath);
+
+    GetSubsystem<Graphics>()->RaiseWindow();
+
+    return GetInternalPath(jdkPath);
+
+}
+
+
 
 
 String ProjectUtils::NewProjectFileDialog()
 String ProjectUtils::NewProjectFileDialog()
 {
 {

+ 2 - 0
Source/AtomicEditor/Source/Project/ProjectUtils.h

@@ -21,6 +21,8 @@ class ProjectUtils : public Object
 
 
     String GetBuildPath(const String& defaultPath);
     String GetBuildPath(const String& defaultPath);
     String GetAndroidSDKPath(const String& defaultPath);
     String GetAndroidSDKPath(const String& defaultPath);
+    String GetAntPath(const String& defaultPath);
+    String GetJDKRootPath(const String& defaultPath);
     String GetMobileProvisionPath();
     String GetMobileProvisionPath();
 
 
 public:
 public:

+ 40 - 2
Source/AtomicEditor/Source/UI/Modal/UIBuildSettingsAndroid.cpp

@@ -45,6 +45,16 @@ UIBuildSettingsAndroid::UIBuildSettingsAndroid(Context* context) :
 
 
     sdkTargetSelect_ = delegate_->GetWidgetByIDAndType<TBSelectDropdown>(TBIDC("sdk_target_select"));
     sdkTargetSelect_ = delegate_->GetWidgetByIDAndType<TBSelectDropdown>(TBIDC("sdk_target_select"));
     assert(sdkTargetSelect_);
     assert(sdkTargetSelect_);
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+    TBTextField* jdk_root_text = delegate_->GetWidgetByIDAndType<TBTextField>(TBIDC("jdk_root_text"));
+    assert(jdk_root_text);
+    jdk_root_text->SetText("JDK Root: (Ex. C:\\Program Files\\Java\\jdk1.8.0_31)");
+
+    TBTextField* ant_path_text = delegate_->GetWidgetByIDAndType<TBTextField>(TBIDC("ant_path_text"));
+    assert(ant_path_text);
+    ant_path_text->SetText("Ant Path: (The folder that contains ant.bat)");
+#endif
 }
 }
 
 
 UIBuildSettingsAndroid::~UIBuildSettingsAndroid()
 UIBuildSettingsAndroid::~UIBuildSettingsAndroid()
@@ -173,8 +183,16 @@ void UIBuildSettingsAndroid::Refresh()
 {
 {
     Editor* editor = context_->GetSubsystem<Editor>();
     Editor* editor = context_->GetSubsystem<Editor>();
 
 
+    AEPreferences* prefs = editor->GetPreferences();
+
     TBEditField* sdk_path = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("sdk_path"));
     TBEditField* sdk_path = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("sdk_path"));
-    sdk_path->SetText(editor->GetPreferences()->GetAndroidSDKPath().CString());
+    sdk_path->SetText(prefs->GetAndroidSDKPath().CString());
+
+    TBEditField* ant_path = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("ant_path"));
+    ant_path->SetText(prefs->GetAntPath().CString());
+
+    TBEditField* jdk_root = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("jdk_root"));
+    jdk_root->SetText(prefs->GetJDKRootPath().CString());
 
 
     BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
     BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
     const AndroidBuildSettings& settings = buildSystem->GetBuildSettings()->GetAndroidSettings();
     const AndroidBuildSettings& settings = buildSystem->GetBuildSettings()->GetAndroidSettings();
@@ -204,7 +222,27 @@ bool UIBuildSettingsAndroid::OnEvent(const TBWidgetEvent &ev)
             }
             }
             return true;
             return true;
         }
         }
-        if (ev.target->GetID() == TBIDC("refresh_sdk_targets"))
+        else if (ev.target->GetID() == TBIDC("choose_ant_path"))
+        {
+            String path = utils->GetAntPath("");
+            if (path.Length())
+            {
+                editor->GetPreferences()->SetAntPath(path);
+                Refresh();
+            }
+            return true;
+        }
+        else if (ev.target->GetID() == TBIDC("choose_jdk_root"))
+        {
+            String path = utils->GetJDKRootPath("");
+            if (path.Length())
+            {
+                editor->GetPreferences()->SetJDKRootPath(path);
+                Refresh();
+            }
+            return true;
+        }
+        else if (ev.target->GetID() == TBIDC("refresh_sdk_targets"))
         {
         {
             RefreshAndroidTargets();
             RefreshAndroidTargets();
         }
         }

+ 13 - 0
Source/AtomicEditor/Vendor/nativefiledialog/nfd_win.cpp

@@ -627,6 +627,12 @@ nfdresult_t NFD_ChooseDirectory(const nfdchar_t *prompt, const nfdchar_t *defaul
     HRESULT result = ::CoInitializeEx(NULL,
     HRESULT result = ::CoInitializeEx(NULL,
                                       ::COINIT_APARTMENTTHREADED |
                                       ::COINIT_APARTMENTTHREADED |
                                       ::COINIT_DISABLE_OLE1DDE );
                                       ::COINIT_DISABLE_OLE1DDE );
+
+    wchar_t *promptW = {0};
+    if (prompt && strlen(prompt))
+        CopyNFDCharToWChar( prompt, &promptW );
+
+
     if ( !SUCCEEDED(result))
     if ( !SUCCEEDED(result))
     {
     {
         NFDi_SetError("Could not initialize COM.");
         NFDi_SetError("Could not initialize COM.");
@@ -658,6 +664,9 @@ nfdresult_t NFD_ChooseDirectory(const nfdchar_t *prompt, const nfdchar_t *defaul
         goto end;
         goto end;
     }
     }
 
 
+    fileOpenDialog->SetTitle(promptW);
+
+
     // Show the dialog.
     // Show the dialog.
     result = fileOpenDialog->Show(NULL);
     result = fileOpenDialog->Show(NULL);
     if ( SUCCEEDED(result) )
     if ( SUCCEEDED(result) )
@@ -700,6 +709,10 @@ nfdresult_t NFD_ChooseDirectory(const nfdchar_t *prompt, const nfdchar_t *defaul
     }
     }
 
 
  end:
  end:
+
+    if (prompt && strlen(prompt));
+        NFDi_Free( promptW );
+
     ::CoUninitialize();
     ::CoUninitialize();
 
 
     return nfdResult;
     return nfdResult;