<commit_before>// <copyright file="PBXFileReference.cs" company="<NAME>">
//  Opus package
// </copyright>
// <summary>XcodeBuilder package</summary>
// <author><NAME></author>
namespace XcodeBuilder
{
    public sealed class PBXFileReference : XCodeNodeData, IWriteableNode
    {
        public enum EType
        {
            ApplicationBundle,
            Executable,
            DynamicLibrary,
            StaticLibrary,
            SourceFile,
            HeaderFile,
            Framework
        }

        public PBXFileReference(string name, EType type, string path, System.Uri rootPath)
            : base(name)
        {
            this.Type = type;
            this.ShortPath = CalculateShortPath(type, path);
            if (EType.Framework == type)
            {
                // TODO: this is a hack, as I don't know the SDK at this stage
                // there might need to be more options added here
                this.RelativePath = "Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/" + this.ShortPath;
            }
            else
            {
                var relative = Opus.Core.RelativePathUtilities.GetPath(path, rootPath);
                this.RelativePath = relative;
            }
        }

        public static string CalculateShortPath(EType type, string path)
        {
            var shortPath = System.IO.Path.GetFileName(path);
            if (EType.Framework == type)
            {
                shortPath += ".framework";
            }
            else if (EType.ApplicationBundle == type)
            {
                shortPath += ".app";
            }
            return shortPath;
        }

        public string ShortPath
        {
            get;
            private set;
        }

        private string RelativePath
        {
            get;
            set;
        }

        public EType Type
        {
            get;
            private set;
        }

#region IWriteableNode implementation

        void IWriteableNode.Write(System.IO.TextWriter writer)
        {
            switch (this.Type)
            {
            case EType.ApplicationBundle:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = {1}; sourceTree = TARGET_BUILD_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.Executable:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = \"compiled.mach-o.executable\"; includeInIndex = 0; path = {1}; sourceTree = TARGET_BUILD_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.DynamicLibrary:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = \"compiled.mach-o.dylib\"; includeInIndex = 0; path = {1}; sourceTree = TARGET_BUILD_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.StaticLibrary:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = {1}; sourceTree = TARGET_BUILD_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.SourceFile:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = {1}; path = {2}; sourceTree = SOURCE_ROOT; }};", this.UUID, this.ShortPath, this.RelativePath);
                break;

            case EType.HeaderFile:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = {1}; path = {2}; sourceTree = SOURCE_ROOT; }};", this.UUID, this.ShortPath, this.RelativePath);
                break;

            case EType.Framework:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = {1}; path = {2}; sourceTree = DEVELOPER_DIR; }};", this.UUID, this.ShortPath, this.RelativePath);
                break;

            default:
                throw new Opus.Core.Exception("Unknown PBXFileReference type");
            }<commit_msg>[xcode] Xcode seems to prefer BUILT_PRODUCTS_DIR, rather than TARGET_BUILD_DIR<commit_after>// <copyright file="PBXFileReference.cs" company="<NAME>">
//  Opus package
// </copyright>
// <summary>XcodeBuilder package</summary>
// <author><NAME></author>
namespace XcodeBuilder
{
    public sealed class PBXFileReference : XCodeNodeData, IWriteableNode
    {
        public enum EType
        {
            ApplicationBundle,
            Executable,
            DynamicLibrary,
            StaticLibrary,
            SourceFile,
            HeaderFile,
            Framework
        }

        public PBXFileReference(string name, EType type, string path, System.Uri rootPath)
            : base(name)
        {
            this.Type = type;
            this.ShortPath = CalculateShortPath(type, path);
            if (EType.Framework == type)
            {
                // TODO: this is a hack, as I don't know the SDK at this stage
                // there might need to be more options added here
                this.RelativePath = "Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/" + this.ShortPath;
            }
            else
            {
                var relative = Opus.Core.RelativePathUtilities.GetPath(path, rootPath);
                this.RelativePath = relative;
            }
        }

        public static string CalculateShortPath(EType type, string path)
        {
            var shortPath = System.IO.Path.GetFileName(path);
            if (EType.Framework == type)
            {
                shortPath += ".framework";
            }
            else if (EType.ApplicationBundle == type)
            {
                shortPath += ".app";
            }
            return shortPath;
        }

        public string ShortPath
        {
            get;
            private set;
        }

        private string RelativePath
        {
            get;
            set;
        }

        public EType Type
        {
            get;
            private set;
        }

#region IWriteableNode implementation

        void IWriteableNode.Write(System.IO.TextWriter writer)
        {
            switch (this.Type)
            {
            case EType.ApplicationBundle:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = {1}; sourceTree = BUILT_PRODUCTS_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.Executable:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = \"compiled.mach-o.executable\"; includeInIndex = 0; path = {1}; sourceTree = BUILT_PRODUCTS_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.DynamicLibrary:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = \"compiled.mach-o.dylib\"; includeInIndex = 0; path = {1}; sourceTree = BUILT_PRODUCTS_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.StaticLibrary:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = {1}; sourceTree = BUILT_PRODUCTS_DIR; }};", this.UUID, this.ShortPath);
                break;

            case EType.SourceFile:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = {1}; path = {2}; sourceTree = SOURCE_ROOT; }};", this.UUID, this.ShortPath, this.RelativePath);
                break;

            case EType.HeaderFile:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = {1}; path = {2}; sourceTree = SOURCE_ROOT; }};", this.UUID, this.ShortPath, this.RelativePath);
                break;

            case EType.Framework:
                writer.WriteLine("\t\t{0} /* {1} */ = {{isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = {1}; path = {2}; sourceTree = DEVELOPER_DIR; }};", this.UUID, this.ShortPath, this.RelativePath);
                break;

            default:
                throw new Opus.Core.Exception("Unknown PBXFileReference type");
            }
{'fraction_non_alphanumeric': 0.11971748087110065, 'fraction_numerical': 0.007298410829899941, 'mean_word_length': 1.791981597108117, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4148929', 'n_tokens_mistral': 2457, 'n_tokens_neox': 2302, 'n_words': 518}