5
// Michael Hutchinson <mhutch@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc. (http://xamarin.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
30
using System.Collections.Generic;
32
using MonoDevelop.Core;
33
using MonoDevelop.Projects;
34
using MonoDevelop.MacDev.ObjCIntegration;
35
using System.Threading.Tasks;
36
using MonoDevelop.MacDev.XcodeIntegration;
38
namespace MonoDevelop.MacDev.XcodeSyncing
41
class XcodeSyncedType : XcodeSyncedItem
43
public NSObjectTypeInfo Type { get; set; }
44
public string[] Frameworks { get; set; }
46
public XcodeSyncedType (NSObjectTypeInfo type, string[] frameworks)
48
Frameworks = frameworks;
52
public string GetObjCHeaderPath (XcodeSyncContext context)
54
return context.ProjectDir.Combine (Type.ObjCName + ".h");
57
public override bool NeedsSyncOut (IProgressMonitor monitor, XcodeSyncContext context)
59
//FIXME: types dep on other types on project, need better regeneration skipping
60
string h = Type.ObjCName + ".h";
62
if (!File.Exists (GetObjCHeaderPath (context)))
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));
76
public override void SyncOut (IProgressMonitor monitor, XcodeSyncContext context)
78
monitor.Log.WriteLine ("Exporting Objective-C source code for the {0} class to Xcode.", Type.CliName);
79
Type.GenerateObjcType (context.ProjectDir, Frameworks);
81
DateTime mtime = File.GetLastWriteTime (GetObjCHeaderPath (context));
82
context.SetSyncTime (Type.ObjCName + ".h", mtime);
85
public override bool NeedsSyncBack (IProgressMonitor monitor, XcodeSyncContext context)
87
string path = GetObjCHeaderPath (context);
88
string h = Type.ObjCName + ".h";
90
if (File.Exists (path) && File.GetLastWriteTime (path) > context.GetSyncTime (h)) {
91
monitor.Log.WriteLine ("{0} has changed since last sync.", h);
98
public override void SyncBack (IProgressMonitor monitor, XcodeSyncBackContext context)
100
monitor.Log.WriteLine ("Queueing sync-back of changes made to the {0} class from Xcode.", Type.CliName);
102
var objcType = context.ProjectInfo.GetType (Type.ObjCName);
103
var hFile = GetObjCHeaderPath (context);
105
if (objcType == null) {
106
context.ReportError ("Missing Objective-C type: {0}", Type.ObjCName);
110
if (!objcType.IsUserType) {
111
context.ReportError ("Parsed Objective-C type '{0}' is not a user type", objcType);
115
var parsed = NSObjectInfoService.ParseHeader (hFile);
117
if (parsed == null) {
118
context.ReportError ("Error parsing Objective-C type: {0}", Type.ObjCName);
122
if (parsed.ObjCName != objcType.ObjCName) {
123
context.ReportError ("Parsed type name '{0}' does not match original: {1}",
124
parsed.ObjCName, objcType.ObjCName);
128
parsed.MergeCliInfo (objcType);
130
context.TypeSyncJobs.Add (XcodeSyncObjcBackJob.UpdateType (parsed, objcType.GetDesignerFile ()));
133
const string supportingFilesGroup = "Supporting Files";
134
public override void AddToProject (XcodeProject project, FilePath syncProjectDir)
136
project.AddSource (Type.ObjCName + ".h");
138
var grp = project.GetGroup (supportingFilesGroup) ?? project.AddGroup (supportingFilesGroup);
139
project.AddSource (Type.ObjCName + ".m", grp);
142
public override string[] GetTargetRelativeFileNames ()
144
return new string [] {
145
Type.ObjCName + ".h",
146
Type.ObjCName + ".m",