Ejemplo n.º 1
0
        public static void RemoveOldNdk(IFileSystem fs, AbsoluteDirectoryPath ndkPath)
        {
            try
            {
                var oldBasePath = Platform.OperatingSystem == OS.Mac
                                        ? PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.Personal)
                                  / new DirectoryName("Library")
                                  / new DirectoryName("Application Support")
                                  / new DirectoryName("Fusetools")
                                  / new DirectoryName("Fuse")
                                  / new DirectoryName("Android")
                                        : PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.LocalApplicationData)
                                  / new DirectoryName("Fusetools")
                                  / new DirectoryName("Fuse")
                                  / new DirectoryName("Android");

                if (ndkPath.IsRootedIn(oldBasePath) && fs.Exists(ndkPath))
                {
                    fs.Delete(ndkPath);
                }
            }
            catch (Exception)
            {
                // We don't care about errors.
            }
        }
Ejemplo n.º 2
0
        public static IEnumerable <AbsoluteDirectoryPath> GetAndroidSDKSearchPaths(IObserver <string> warnings)
        {
            var androidSdkManager = LocateExceutable.TryFindExecutableInPath("SDK Manager", warnings).Select(path => path.ContainingDirectory);
            var adb = LocateExceutable.TryFindExecutableInPath("adb", warnings).Select(path => path.ContainingDirectory.ContainingDirectory);

            if (Platform.OperatingSystem == OS.Windows)
            {
                return(new[]
                {
                    androidSdkManager,
                    adb,
                    PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.LocalApplicationData)
                    / new DirectoryName("Android")
                    / new DirectoryName("sdk")
                }.NotNone());
            }
            else if (Platform.OperatingSystem == OS.Mac)
            {
                return(new[]
                {
                    androidSdkManager,
                    adb,
                    PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.Personal)
                    / new DirectoryName("Library")
                    / new DirectoryName("Android")
                    / new DirectoryName("sdk")
                }.NotNone());
            }

            throw new PlatformNotSupportedException();
        }
Ejemplo n.º 3
0
        public IEnumerable <AbsoluteDirectoryPath> GetJdkSearchPaths(IFileSystem fs)
        {
            var defaultInstallLocations = Enumerable.Empty <AbsoluteDirectoryPath>();

            if (Platform.OperatingSystem == OS.Windows)
            {
                var defaultSearchLocation = PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.ProgramFiles)
                                            / new DirectoryName("Java");

                if (fs.Exists(defaultSearchLocation))
                {
                    defaultInstallLocations = fs.GetDirectories(defaultSearchLocation, "jdk*").Reverse();
                }

                return(defaultInstallLocations);
            }
            else if (Platform.OperatingSystem == OS.Mac)
            {
                var javaHome = Environment
                               .GetEnvironmentVariable("JAVA_HOME")
                               .ToOptional()
                               .SelectMany(AbsoluteDirectoryPath.TryParse);

                var defaultSearchLocation = AbsoluteDirectoryPath.Parse("/Library/Java/JavaVirtualMachines");
                if (fs.Exists(defaultSearchLocation))
                {
                    var jdkBaseDirectories = fs.GetDirectories(defaultSearchLocation, "jdk*").Reverse();
                    defaultInstallLocations = jdkBaseDirectories.Select(
                        dir =>
                        dir / new DirectoryName("Contents") / new DirectoryName("Home"));
                }

                return(new[]
                {
                    javaHome,
                }
                       .NotNone()
                       .Concat(defaultInstallLocations));
            }

            throw new PlatformNotSupportedException();
        }
Ejemplo n.º 4
0
        void Install(OptionalSdkConfigOptions config, InstallOptions opts)
        {
            // Remove old NDK installation
            config.AndroidNdkDirectory.Do(ndkPath => BackwardCompatibility.RemoveOldNdk(_fs, ndkPath));

            if (config.JavaJdkDirectory.HasValue == false)
            {
                var javaValidator = new JavaValidator(_fs);
                config.JavaJdkDirectory = TryToFindJdk(_fs, javaValidator, _progress)
                                          .Or(() => opts.Noninteractive ? Optional.None() : AskUserToProvidePath("Java Development Kit", javaValidator, _progress));
            }

            if (config.AndroidSdkDirectory.HasValue == false)
            {
                var androidSdkValidator = new AndroidSDKValidator(_fs);
                config.AndroidSdkDirectory = TryToFindAndroidSdk(androidSdkValidator, _progress)
                                             .Or(() => opts.Noninteractive ? Optional.None() : AskUserToProvidePath("Android SDK", androidSdkValidator, _progress));
            }

            // Then install based on configuration
            config.JavaJdkDirectory = config.JavaJdkDirectory.MatchWith(
                _ => _,
                () =>
            {
                var defaultPath = Platform.OperatingSystem == OS.Windows
                                                ? PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.ProgramFiles)
                                  / new DirectoryName("Java")
                                  / new DirectoryName("jdk1.8.0_40")
                                                : AbsoluteDirectoryPath.Parse("/Library/Java/JavaVirtualMachines")
                                  / new DirectoryName("jdk1.8.0_40.jdk")
                                  / new DirectoryName("Contents")
                                  / new DirectoryName("Home");

                var installer = new JavaInstaller(_fs);
                installer.Install(CancellationToken.None, _dialog, _progress, opts);
                return(defaultPath);
            });

            config.JavaJdkDirectory.Do(jdk => Environment.SetEnvironmentVariable("JAVA_HOME", jdk.NativePath, EnvironmentVariableTarget.Process));

            config.AndroidSdkDirectory = config.AndroidSdkDirectory.MatchWith(
                _ => _,
                () =>
            {
                var defaultPath = Platform.OperatingSystem == OS.Mac
                                                ? PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.Personal)
                                  / new DirectoryName("Library")
                                  / new DirectoryName("Android")
                                  / new DirectoryName("sdk")
                                                : PathExtensions.GetEnvironmentPath(Environment.SpecialFolder.LocalApplicationData)
                                  / new DirectoryName("Fusetools")
                                  / new DirectoryName("Fuse")
                                  / new DirectoryName("Android")
                                  / new DirectoryName("AndroidSDK");

                var installer = new AndroidSDKInstaller(defaultPath, _fs);
                installer.Install(CancellationToken.None, _dialog, _progress, opts);
                return(defaultPath);
            });

            config.AndroidSdkDirectory.Do(
                androidRoot =>
            {
                if (config.HaveAllSdkPackages &&
                    config.AndroidNdkDirectory.HasValue)
                {
                    return;
                }

                var installer = new AndroidSDKPackageInstaller(
                    _fs,
                    androidRoot,
                    Platform.OperatingSystem == OS.Windows
                                                        ? androidRoot / new DirectoryName("tools") / new FileName("android.bat")
                                                        : androidRoot / new DirectoryName("tools") / new FileName("android"),
                    Platform.OperatingSystem == OS.Windows
                                                        ? androidRoot / new DirectoryName("tools") / new DirectoryName("bin") / new FileName("sdkmanager.bat")
                                                        : androidRoot / new DirectoryName("tools") / new DirectoryName("bin") / new FileName("sdkmanager"));

                var result = installer.Install(CancellationToken.None, _dialog, _progress);

                config.AndroidNdkDirectory = result.NdkBundle;
            });
        }