classdef (Hidden = true) IDEProjectWriter < coder.make.Writer & coder.make.internal.IDEProjectMixIn
    % This is default Writer for Project that uses the Project Tool defined
    % in the toolchain
    
    % Copyright 2012-2020 The MathWorks, Inc.
    
    methods
        
        % -------------------------------------------------------------------------
        % Writer::Writer
        % -------------------------------------------------------------------------
        function h = IDEProjectWriter(builder, buildInfo)
            % Call base class constructor
            h@coder.make.Writer(builder, buildInfo);
            % Initialize properties
            h@coder.make.internal.IDEProjectMixIn(builder, buildInfo);
        end
        
        % -------------------------------------------------------------------------
        % Writer::run
        % -------------------------------------------------------------------------
        function [results, artifact] = run(h, buildInfo)
            assert(h.Parent.isBuildToolContextInitialized());
            artifact = h.callProjectTool('createProject', buildInfo, h.ToolchainInfo, h.Parent.BuildOutputType, h.Parent.Components);
            if isempty(artifact)
                results = message('CoderFoundation:builder:CreatingProject');
            else
                results = []; %no error
            end
            %artifact must be name of the project
            if ~ischar(artifact)
                throw(MException('CoderFoundation:builder:CreatingProject'));
            end
            %if it is not a cell str, let use just convert to cell str
            if ~iscellstr(artifact)
                artifact = {artifact};
            end
        end
        
        function delete(h)
            %just in case we need to terminate
            h.terminate([]);
        end
    end    
end
