~ubuntu-branches/ubuntu/vivid/monodevelop/vivid-proposed

« back to all changes in this revision

Viewing changes to src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetExecutionHandler.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-10-09 14:09:23 UTC
  • mfrom: (10.3.5)
  • Revision ID: package-import@ubuntu.com-20141009140923-s0d22u5f9kg8jvds
Tags: 5.5.0.227-1
* [b2c8331] Imported Upstream version 5.5.0.227 (Closes: #754316)
* [d210995] Delete obsolete patches
* [1b59ae1] Clear patch fizz, via quilt refresh
* [3dd147d] Fix error in configure.in which applies for tarball builds but 
  not git builds when running autoreconf
* [21c2a57] Remove Metacity references for good
* [3331661] Ensure NUnit 2.6.3 is installed
* [fd85c88] Build-depend on NuGet
* [a1ae116] Add WebKit to build dependencies, for Xwt moduleref resolution
* [9b4cf12] Since the GDB addin is integrated now, declare it in 
  debian/control
* [6231562] Correct NUnit links
* [3d2b693] Fix NuGet addin, by copying libs locally
* [74bf9a8] Don't symlink unused Mocks NUnit assembly
* [ade52b2] Ensure IKVM.Reflection is built with default (4.5) profile

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// AspNetExecutionHandler.cs
3
 
//  
4
 
// Author:
5
 
//       Lluis Sanchez Gual <lluis@novell.com>
6
 
// 
7
 
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
8
 
// 
9
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
 
// of this software and associated documentation files (the "Software"), to deal
11
 
// in the Software without restriction, including without limitation the rights
12
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 
// copies of the Software, and to permit persons to whom the Software is
14
 
// furnished to do so, subject to the following conditions:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
19
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using System.Collections.Generic;
29
 
using MonoDevelop.Projects;
30
 
using MonoDevelop.Core;
31
 
using MonoDevelop.Core.Assemblies;
32
 
using MonoDevelop.Core.Execution;
33
 
using System.IO;
34
 
 
35
 
namespace MonoDevelop.AspNet
36
 
{
37
 
        public class AspNetExecutionHandler: IExecutionHandler
38
 
        {
39
 
                public static string GetXspName (AspNetExecutionCommand cmd)
40
 
                {
41
 
                        switch (cmd.ClrVersion) {
42
 
                        case ClrVersion.Net_1_1:
43
 
                                return "xsp1";
44
 
                        case ClrVersion.Net_2_0:
45
 
                                return "xsp2";
46
 
                        case ClrVersion.Net_4_0:
47
 
                                return "xsp4";
48
 
                        case ClrVersion.Net_4_5:
49
 
                                return "xsp4";
50
 
                        default:
51
 
                                LoggingService.LogError ("ASP.NET is not supported for unknown runtime version '{0}'.", cmd.ClrVersion);
52
 
                                throw new UserException (GettextCatalog.GetString (
53
 
                                        "ASP.NET is not supported for unknown runtime version '{0}'.", cmd.ClrVersion));
54
 
                        }
55
 
                }
56
 
                
57
 
                public static FilePath GetXspPath (AspNetExecutionCommand cmd)
58
 
                {
59
 
                        var xspName = GetXspName (cmd);
60
 
                        
61
 
                        FilePath xspPath = cmd.TargetRuntime.GetToolPath (cmd.TargetFramework, xspName);
62
 
                        
63
 
                        if (xspPath.IsNullOrEmpty && cmd.ClrVersion == ClrVersion.Net_1_1)
64
 
                                xspPath = cmd.TargetRuntime.GetToolPath (cmd.TargetFramework, "xsp");
65
 
                        
66
 
                        //if the current runtime doesn't provide XSP, look for an exe (not script) bundled alongside the addin
67
 
                        if (xspPath.IsNullOrEmpty) {
68
 
                                FilePath addinPath = typeof (AspNetExecutionHandler).Assembly.Location;
69
 
                                xspPath = addinPath.ParentDirectory.Combine (xspName + ".exe");
70
 
                        }
71
 
 
72
 
                        if (File.Exists (xspPath))
73
 
                                return xspPath;
74
 
 
75
 
                        //if xsp wasn't found there, check beside the entrypoint exe too
76
 
                        FilePath rootExe = System.Reflection.Assembly.GetEntryAssembly ().Location;
77
 
                        xspPath = rootExe.ParentDirectory.Combine (xspName + ".exe");
78
 
 
79
 
                        if (File.Exists (xspPath))
80
 
                                return xspPath;
81
 
 
82
 
                        LoggingService.LogError ("Did not find web server {0}", xspName);
83
 
                        throw new UserException (GettextCatalog.GetString (
84
 
                                "The {0} web server cannot be found. Please ensure that it is installed.", xspName), null);
85
 
                }
86
 
                
87
 
                public bool CanExecute (ExecutionCommand command)
88
 
                {
89
 
                        var cmd = command as AspNetExecutionCommand;
90
 
                        return cmd != null && !string.IsNullOrEmpty (GetXspName (cmd));
91
 
                }
92
 
                
93
 
                public IProcessAsyncOperation Execute (ExecutionCommand command, IConsole console)
94
 
                {
95
 
                        var cmd = (AspNetExecutionCommand) command;
96
 
                        var xspPath = GetXspPath (cmd);
97
 
 
98
 
                        var evars = new Dictionary<string, string>(cmd.EnvironmentVariables);
99
 
 
100
 
                        foreach (var v in cmd.TargetRuntime.GetToolsExecutionEnvironment (cmd.TargetFramework).Variables)
101
 
                        {
102
 
                                if (!evars.ContainsKey (v.Key))
103
 
                                        evars.Add (v.Key, v.Value);
104
 
                        }
105
 
 
106
 
                        //if it's a script, use a native execution handler
107
 
                        if (xspPath.Extension != ".exe") {
108
 
                                //set mono debug mode if project's in debug mode
109
 
                                if (cmd.DebugMode) {
110
 
                                        evars ["MONO_OPTIONS"] = "--debug";
111
 
                                }
112
 
                                
113
 
                                var ncmd = new NativeExecutionCommand (
114
 
                                        xspPath, cmd.XspParameters.GetXspParameters () + " --nonstop",
115
 
                                        cmd.BaseDirectory, evars);
116
 
                                
117
 
                                return Runtime.ProcessService.GetDefaultExecutionHandler (ncmd).Execute (ncmd, console);
118
 
                        }
119
 
 
120
 
                        // Set DEVPATH when running on Windows (notice that this has no effect unless
121
 
                        // <developmentMode developerInstallation="true" /> is set in xsp2.exe.config
122
 
 
123
 
                        if (cmd.TargetRuntime is MsNetTargetRuntime)
124
 
                                evars["DEVPATH"] = Path.GetDirectoryName (xspPath);
125
 
                        
126
 
                        var netCmd = new DotNetExecutionCommand (
127
 
                                xspPath, cmd.XspParameters.GetXspParameters () + " --nonstop",
128
 
                                cmd.BaseDirectory, evars);
129
 
                        netCmd.DebugMode = cmd.DebugMode;
130
 
                        
131
 
                        return cmd.TargetRuntime.GetExecutionHandler ().Execute (netCmd, console);
132
 
                }
133
 
        }
134
 
}