In all cases where the defendant in ejectment would be liable for mesne profits and damages, the plaintiff may declare for and recover the same in the action of ejectment, or he may have his action for mesne profits after the recovery in ejectment as heretofore. It shall be lawful in all cases for the defendant in ejectment, whether the plaintiff demand mesne profits or damages or not, or in an action of mesne profits, to plead the value of all permanent, valuable and not ornamental improvements made on the land by the defendant, or by any one under whom he holds, before notice of the intention of the plaintiff to bring the action, and all taxes that may have been lawfully paid on the land by defendant or those under whom he holds up to the date of trial, including interest, costs, and damages incident to such taxes; but a defendant shall not be entitled to such compensation for improvements or taxes unless he claim the premises under some deed or contract of purchase acquired or made in good faith.