~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeSyncedType.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// XcodeSyncedType.cs
3
 
//  
4
 
// Author:
5
 
//       Michael Hutchinson <mhutch@xamarin.com>
6
 
// 
7
 
// Copyright (c) 2011 Xamarin Inc. (http://xamarin.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.Linq;
29
 
using System.IO;
30
 
using System.Collections.Generic;
31
 
 
32
 
using MonoDevelop.Core;
33
 
using MonoDevelop.Projects;
34
 
using MonoDevelop.MacDev.ObjCIntegration;
35
 
using System.Threading.Tasks;
36
 
using MonoDevelop.MacDev.XcodeIntegration;
37
 
 
38
 
namespace MonoDevelop.MacDev.XcodeSyncing
39
 
{
40
 
        
41
 
        class XcodeSyncedType : XcodeSyncedItem
42
 
        {
43
 
                public NSObjectTypeInfo Type { get; set; }
44
 
                public string[] Frameworks { get; set; }
45
 
                
46
 
                public XcodeSyncedType (NSObjectTypeInfo type, string[] frameworks)
47
 
                {
48
 
                        Frameworks = frameworks;
49
 
                        Type = type;
50
 
                }
51
 
                
52
 
                public string GetObjCHeaderPath (XcodeSyncContext context)
53
 
                {
54
 
                        return context.ProjectDir.Combine (Type.ObjCName + ".h");
55
 
                }
56
 
                
57
 
                public override bool NeedsSyncOut (IProgressMonitor monitor, XcodeSyncContext context)
58
 
                {
59
 
                        //FIXME: types dep on other types on project, need better regeneration skipping
60
 
                        string h = Type.ObjCName + ".h";
61
 
                        
62
 
                        if (!File.Exists (GetObjCHeaderPath (context)))
63
 
                                return true;
64
 
                        
65
 
                        DateTime syncTime = context.GetSyncTime (h);
66
 
                        foreach (var path in Type.DefinedIn) {
67
 
                                if (File.GetLastWriteTime (path) > syncTime) {
68
 
                                        monitor.Log.WriteLine ("The {0} class has changed since last sync ({1}).", Type.CliName, Path.GetFileName (path));
69
 
                                        return true;
70
 
                                }
71
 
                        }
72
 
                        
73
 
                        return false;
74
 
                }
75
 
                
76
 
                public override void SyncOut (IProgressMonitor monitor, XcodeSyncContext context)
77
 
                {
78
 
                        monitor.Log.WriteLine ("Exporting Objective-C source code for the {0} class to Xcode.", Type.CliName);
79
 
                        Type.GenerateObjcType (context.ProjectDir, Frameworks);
80
 
                        
81
 
                        DateTime mtime = File.GetLastWriteTime (GetObjCHeaderPath (context));
82
 
                        context.SetSyncTime (Type.ObjCName + ".h", mtime);
83
 
                }
84
 
                
85
 
                public override bool NeedsSyncBack (IProgressMonitor monitor, XcodeSyncContext context)
86
 
                {
87
 
                        string path = GetObjCHeaderPath (context);
88
 
                        string h = Type.ObjCName + ".h";
89
 
                        
90
 
                        if (File.Exists (path) && File.GetLastWriteTime (path) > context.GetSyncTime (h)) {
91
 
                                monitor.Log.WriteLine ("{0} has changed since last sync.", h);
92
 
                                return true;
93
 
                        }
94
 
                        
95
 
                        return false;
96
 
                }
97
 
                
98
 
                public override void SyncBack (IProgressMonitor monitor, XcodeSyncBackContext context)
99
 
                {
100
 
                        monitor.Log.WriteLine ("Queueing sync-back of changes made to the {0} class from Xcode.", Type.CliName);
101
 
                        
102
 
                        var objcType = context.ProjectInfo.GetType (Type.ObjCName);
103
 
                        var hFile = GetObjCHeaderPath (context);
104
 
                        
105
 
                        if (objcType == null) {
106
 
                                context.ReportError ("Missing Objective-C type: {0}", Type.ObjCName);
107
 
                                return;
108
 
                        }
109
 
                        
110
 
                        if (!objcType.IsUserType) {
111
 
                                context.ReportError ("Parsed Objective-C type '{0}' is not a user type", objcType);
112
 
                                return;
113
 
                        }
114
 
                        
115
 
                        var parsed = NSObjectInfoService.ParseHeader (hFile);
116
 
                        
117
 
                        if (parsed == null) {
118
 
                                context.ReportError ("Error parsing Objective-C type: {0}", Type.ObjCName);
119
 
                                return;
120
 
                        }
121
 
                        
122
 
                        if (parsed.ObjCName != objcType.ObjCName) {
123
 
                                context.ReportError ("Parsed type name '{0}' does not match original: {1}",
124
 
                                        parsed.ObjCName, objcType.ObjCName);
125
 
                                return;
126
 
                        }
127
 
                        
128
 
                        parsed.MergeCliInfo (objcType);
129
 
                        
130
 
                        context.TypeSyncJobs.Add (XcodeSyncObjcBackJob.UpdateType (parsed, objcType.GetDesignerFile ()));
131
 
                }
132
 
                
133
 
                const string supportingFilesGroup = "Supporting Files";
134
 
                public override void AddToProject (XcodeProject project, FilePath syncProjectDir)
135
 
                {
136
 
                        project.AddSource (Type.ObjCName + ".h");
137
 
                        
138
 
                        var grp = project.GetGroup (supportingFilesGroup) ?? project.AddGroup (supportingFilesGroup);
139
 
                        project.AddSource (Type.ObjCName + ".m", grp);
140
 
                }
141
 
                
142
 
                public override string[] GetTargetRelativeFileNames ()
143
 
                {
144
 
                        return new string [] {
145
 
                                Type.ObjCName + ".h",
146
 
                                Type.ObjCName + ".m",
147
 
                        };
148
 
                }
149
 
        }
150
 
}