Beispiel #1
0
        private void Install(UnityPluginDetector.InstallationInfo installationInfo)
        {
            if (!installationInfo.ShouldInstallPlugin)
            {
                Assertion.Assert(false, "Should not be here if installation is not required.");
                return;
            }

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                myLogger.Verbose("Installation already done.");
                return;
            }

            myLogger.Info("Installing Rider Unity editor plugin: {0}", installationInfo.InstallReason);

            if (!TryCopyFiles(installationInfo, out var installedPath))
            {
                myLogger.Warn("Plugin was not installed");
            }
            else
            {
                string userTitle;
                string userMessage;

                switch (installationInfo.InstallReason)
                {
                case UnityPluginDetector.InstallReason.FreshInstall:
                    userTitle   = "Unity: plugin installed";
                    userMessage =
                        $@"Rider plugin v{myCurrentVersion} for the Unity Editor was automatically installed for the project '{mySolution.Name}' and can be found at:
    {installedPath.MakeRelativeTo(mySolution.SolutionFilePath)}.
    Please switch back to Unity to load the plugin.";
                    break;

                case UnityPluginDetector.InstallReason.Update:
                    userTitle   = "Unity: plugin updated";
                    userMessage = $"Editor plugin was successfully updated to version {myCurrentVersion}";
                    break;

                case UnityPluginDetector.InstallReason.ForceUpdateForDebug:
                    userTitle   = "Unity: plugin updated (debug build)";
                    userMessage = $"Editor plugin was successfully updated to version {myCurrentVersion}";
                    break;

                default:
                    myLogger.Error("Unexpected install reason: {0}", installationInfo.InstallReason);
                    return;
                }

                myLogger.Info(userTitle);

                var notification = new RdNotificationEntry(userTitle, userMessage, true, RdNotificationEntryType.INFO);

                myShellLocks.ExecuteOrQueueEx(myLifetime, "UnityPluginInstaller.Notify", () => myNotifications.Notification.Fire(notification));
            }
        }
Beispiel #2
0
        private void InstallPluginIfRequired(Lifetime lifetime, [NotNull] IProject project)
        {
            if (!IsPluginNeeded(project))
            {
                return;
            }

            myLogger.LogMessage(LoggingLevel.INFO, "Unity -> Rider plugin missing, installing");

            if (TryInstall(project))
            {
                myLogger.LogMessage(LoggingLevel.INFO, "Plugin installed");

                var notification = new RdNotificationEntry("Plugin installed", "Unity -> Rider plugin was added to Unity project", true, RdNotificationEntryType.INFO);
                myNotifications.Notification.Fire(notification);
            }
            else
            {
                myLogger.LogMessage(LoggingLevel.WARN, "Plugin was not installed");
            }
        }
        private void Install(UnityPluginDetector.InstallationInfo installationInfo)
        {
            if (!installationInfo.ShouldInstallPlugin)
            {
                Assertion.Assert(false, "Should not be here if installation is not required.");
                return;
            }

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                myLogger.Verbose("Installation already done.");
                return;
            }

            var currentVersion = typeof(UnityPluginInstaller).Assembly.GetName().Version;

            if (currentVersion <= installationInfo.Version)
            {
                myLogger.Verbose($"Plugin v{installationInfo.Version} already installed.");
                return;
            }

            var isFreshInstall = installationInfo.Version == UnityPluginDetector.ZeroVersion;

            if (isFreshInstall)
            {
                myLogger.Info("Fresh install");
            }

            FileSystemPath installedPath;

            if (!TryCopyFiles(installationInfo, out installedPath))
            {
                myLogger.Warn("Plugin was not installed");
            }
            else
            {
                string userTitle;
                string userMessage;

                if (isFreshInstall)
                {
                    userTitle   = "Unity: plugin installed";
                    userMessage =
                        $@"Rider plugin v{
                                currentVersion
                            } for the Unity Editor was automatically installed for the project '{mySolution.Name}'
This allows better integration between the Unity Editor and Rider IDE.
The plugin file can be found on the following path:
{installedPath.MakeRelativeTo(mySolution.SolutionFilePath)}.
Please switch back to Unity to make plugin file appear in the solution.";
                }
                else
                {
                    userTitle   = "Unity: plugin updated";
                    userMessage = $"Rider plugin was succesfully upgraded to version {currentVersion}";
                }

                myLogger.Info(userTitle);

                var notification = new RdNotificationEntry(userTitle,
                                                           userMessage, true,
                                                           RdNotificationEntryType.INFO);

                myShellLocks.ExecuteOrQueueEx(myLifetime, "UnityPluginInstaller.Notify", () => myNotifications.Notification.Fire(notification));
            }
        }
Beispiel #4
0
        private void InstallPluginIfRequired(Lifetime lifetime, [NotNull] IProject project)
        {
            if (!myBoundSettingsStore.GetValue((UnityPluginSettings s) => s.InstallUnity3DRiderPlugin))
            {
                return;
            }

            if (myPluginInstallations.Contains(project.ProjectFileLocation))
            {
                return;
            }

            var installationInfo = myDetector.GetInstallationInfo(project);

            if (!installationInfo.ShouldInstallPlugin)
            {
                return;
            }

            var currentVersion = typeof(UnityPluginInstaller).Assembly.GetName().Version;

            if (currentVersion <= installationInfo.Version)
            {
                return;
            }

            var isFreshInstall = installationInfo.Version == new Version();

            if (isFreshInstall)
            {
                myLogger.LogMessage(LoggingLevel.INFO, "Fresh install");
            }

            lock (mySyncObj)
            {
                if (myPluginInstallations.Contains(project.ProjectFileLocation))
                {
                    return;
                }

                FileSystemPath installedPath;

                if (!TryInstall(installationInfo, out installedPath))
                {
                    myLogger.LogMessage(LoggingLevel.WARN, "Plugin was not installed");
                }
                else
                {
                    string userTitle;
                    string userMessage;

                    if (isFreshInstall)
                    {
                        userTitle   = "Unity: plugin installed";
                        userMessage =
                            $@"Rider plugin v{currentVersion} for the Unity Editor was automatically installed for the project '{mySolution.Name}'
This allows better integration between the Unity Editor and Rider IDE.
The plugin file can be found on the following path:
{installedPath.MakeRelativeTo(mySolution.SolutionFilePath)}";
                    }
                    else
                    {
                        userTitle   = "Unity: plugin updated";
                        userMessage = $"Rider plugin was succesfully upgraded from version {installationInfo.Version} to {currentVersion}";
                    }

                    myLogger.LogMessage(LoggingLevel.INFO, userTitle);

                    var notification = new RdNotificationEntry(userTitle,
                                                               userMessage, true,
                                                               RdNotificationEntryType.INFO);
                    myNotifications.Notification.Fire(notification);
                }

                myPluginInstallations.Add(project.ProjectFileLocation);
            }
        }
Beispiel #5
0
        Task IUnitTestRunStrategy.Run(IUnitTestRun run)
        {
            var key = run.Launch.GetData(ourLaunchedInUnityKey);

            if (key != null)
            {
                return(Task.FromResult(false));
            }

            var hostId = run.HostController.HostId;

            if (hostId == WellKnownHostProvidersIds.DebugProviderId)
            {
                run.Launch.Output.Error(
                    "Starting Unity tests from 'Debug' is currently unsupported. Please attach to editor and use 'Run'.");
                return(Task.FromResult(false));
            }

            if (hostId != WellKnownHostProvidersIds.RunProviderId)
            {
                run.Launch.Output.Error(
                    $"Starting Unity tests from '{hostId}' is currently unsupported. Please use `Run`.");
                return(Task.FromResult(false));
            }

            var tcs = new TaskCompletionSource <bool>();

            run.Launch.PutData(ourLaunchedInUnityKey, "smth");
            run.PutData(ourCompletionSourceKey, tcs);

            // todo: Refresh Assets DB before running tests #558
            // You can check EditorApplication.isCompiling after the refresh and if it is true, then a refresh will happen if there are no compile errors.
            // You can also hook into these event, this will tell you when compilation of assemblies started/finished.
            // https://docs.unity3d.com/ScriptReference/Compilation.CompilationPipeline-assemblyCompilationFinished.html
            // https://docs.unity3d.com/ScriptReference/Compilation.CompilationPipeline-assemblyCompilationStarted.html
            // Note that those events are only available for Unity 5.6+
            myLogger.Verbose("Before calling Refresh.");
            Refresh(mySolution.Locks, run.Lifetime).GetAwaiter().OnCompleted(() =>
            {
                mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "Check compilation", () =>
                {
                    if (myEditorProtocol.UnityModel.Value == null)
                    {
                        myLogger.Verbose("Unity Editor connection unavailable.");
                        tcs.SetException(new Exception("Unity Editor connection unavailable."));
                        return;
                    }

                    var task = myEditorProtocol.UnityModel.Value.GetCompilationResult.Start(RdVoid.Instance);
                    task.Result.AdviseNotNull(run.Lifetime, result =>
                    {
                        if (!result.Result)
                        {
                            tcs.SetException(new Exception("There are errors during compilation in Unity."));

                            mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "RunViaUnityEditorStrategy compilation failed", () =>
                            {
                                var notification = new RdNotificationEntry("Compilation failed", "Script compilation in Unity failed, so tests were not started.", true, RdNotificationEntryType.INFO);
                                myNotificationsModel.Notification.Fire(notification);
                            });
                            myUnityHost.PerformModelAction(model => model.ActivateUnityLogView.Fire());
                        }
                        else
                        {
                            var launch = SetupLaunch(run);
                            mySolution.Locks.ExecuteOrQueueEx(run.Lifetime, "ExecuteRunUT", () =>
                            {
                                if (myEditorProtocol.UnityModel.Value == null)
                                {
                                    tcs.SetException(new Exception("Unity Editor connection unavailable."));
                                    return;
                                }

                                myEditorProtocol.UnityModel.ViewNotNull(run.Lifetime, (lt, model) =>
                                {
                                    // recreate UnitTestLaunch in case of AppDomain.Reload, which is the case with PlayMode tests
                                    model.UnitTestLaunch.SetValue(launch);
                                    SubscribeResults(run, lt, tcs, launch);
                                });

                                myEditorProtocol.UnityModel.Value.RunUnitTestLaunch.Fire(RdVoid.Instance);
                            });
                        }
                    });
                });
            });

            return(tcs.Task);
        }