|
| 1 | +// |
| 2 | +// OptionAttribute.cs |
| 3 | +// |
| 4 | +// Copyright ©2002-2014 Rafael 'Monoman' Teixeira, Managed Commons Team |
| 5 | +// |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining |
| 7 | +// a copy of this software and associated documentation files (the |
| 8 | +// "Software"), to deal in the Software without restriction, including |
| 9 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 10 | +// distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | +// permit persons to whom the Software is furnished to do so, subject to |
| 12 | +// the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be |
| 15 | +// included in all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 21 | +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | +// |
| 25 | +using System; |
| 26 | +using System.Collections.Generic; |
| 27 | +using System.Linq; |
| 28 | +using System.Text; |
| 29 | + |
| 30 | +namespace Commons |
| 31 | +{ |
| 32 | + public enum LicenseType |
| 33 | + { |
| 34 | + Proprietary, |
| 35 | + AGPL3, |
| 36 | + Apache2, |
| 37 | + BSD3Clause, |
| 38 | + BSD2Clause, |
| 39 | + GPL2, |
| 40 | + GPL3, |
| 41 | + LGPL21, |
| 42 | + LGPL3, |
| 43 | + MIT, |
| 44 | + Mozilla2, |
| 45 | + CDDL, |
| 46 | + Eclipse, |
| 47 | + Other |
| 48 | + } |
| 49 | + |
| 50 | + [AttributeUsage(AttributeTargets.Assembly)] |
| 51 | + public class LicenseAttribute : Attribute |
| 52 | + { |
| 53 | + public string Details; |
| 54 | + public string Name; |
| 55 | + public LicenseType Type; |
| 56 | + |
| 57 | + private struct LicenseDescriptor |
| 58 | + { |
| 59 | + public readonly string Name; |
| 60 | + public readonly string Details; |
| 61 | + public LicenseDescriptor(string name, string details) { Name = name; Details = details; } |
| 62 | + } |
| 63 | + |
| 64 | + private static Dictionary<LicenseType, LicenseDescriptor> Licenses = new Dictionary<LicenseType, LicenseDescriptor>(); |
| 65 | + |
| 66 | + static LicenseAttribute() |
| 67 | + { |
| 68 | + Licenses.Add(LicenseType.Proprietary, new LicenseDescriptor("Proprietary", null)); |
| 69 | + Licenses.Add(LicenseType.AGPL3, new LicenseDescriptor("GNU Affero General Public License, Version 3 (AGPL-3.0)", "See http://opensource.org/licenses/AGPL-3.0")); |
| 70 | + Licenses.Add(LicenseType.Apache2, new LicenseDescriptor("Apache License, Version 2.0", "See http://opensource.org/licenses/Apache-2.0")); |
| 71 | + Licenses.Add(LicenseType.BSD3Clause, new LicenseDescriptor("BSD 3-Clause License", "See http://opensource.org/licenses/BSD-3-Clause")); |
| 72 | + Licenses.Add(LicenseType.BSD2Clause, new LicenseDescriptor("BSD 2-Clause License", "See http://opensource.org/licenses/BSD-2-Clause")); |
| 73 | + Licenses.Add(LicenseType.GPL2, new LicenseDescriptor("GNU General Public License, Version 2 (GPL-2.0)", "See http://opensource.org/licenses/GPL-2.0")); |
| 74 | + Licenses.Add(LicenseType.GPL3, new LicenseDescriptor("GNU General Public License, Version 3 (GPL-3.0)", "See http://opensource.org/licenses/GPL-3.0")); |
| 75 | + Licenses.Add(LicenseType.LGPL21, new LicenseDescriptor("GNU Lesser General Public License, Version 2.1 (LGPL-2.1)", "See http://opensource.org/licenses/LGPL-2.1")); |
| 76 | + Licenses.Add(LicenseType.LGPL3, new LicenseDescriptor("GNU Lesser General Public License, Version 3.0 (LGPL-3.0)", "See http://opensource.org/licenses/LGPL-3.0")); |
| 77 | + Licenses.Add(LicenseType.MIT, new LicenseDescriptor("MIT License", "See http://opensource.org/licenses/MIT")); |
| 78 | + Licenses.Add(LicenseType.Mozilla2, new LicenseDescriptor("Mozilla Public License 2.0 (MPL-2.0)", "See http://opensource.org/licenses/MPL-2.0")); |
| 79 | + Licenses.Add(LicenseType.CDDL, new LicenseDescriptor("COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0 (CDDL-1.0)", "See http://opensource.org/licenses/CDDL-1.0")); |
| 80 | + Licenses.Add(LicenseType.Eclipse, new LicenseDescriptor("Eclipse Public License, Version 1.0 (EPL-1.0)", "See http://opensource.org/licenses/EPL-1.0")); |
| 81 | + } |
| 82 | + |
| 83 | + public LicenseAttribute(LicenseType type) |
| 84 | + { |
| 85 | + if (type == LicenseType.Other) |
| 86 | + throw new ArgumentOutOfRangeException("type", "The license 'type' should not be 'Other', use the alternate constructor"); |
| 87 | + var license = Licenses[type]; |
| 88 | + @Type = type; |
| 89 | + Name = license.Name; |
| 90 | + Details = license.Details; |
| 91 | + } |
| 92 | + |
| 93 | + public LicenseAttribute(string name, string details) |
| 94 | + { |
| 95 | + @Type = LicenseType.Other; |
| 96 | + Name = name; |
| 97 | + Details = details; |
| 98 | + } |
| 99 | + |
| 100 | + public override string ToString() |
| 101 | + { |
| 102 | + return string.IsNullOrWhiteSpace(Details) ? Name : (Name + " - " + Details); |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments