Copyright | (c) 2015 Oleg Grenrus |
---|---|
License | BSD3 |
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
Safe Haskell | None |
Language | Haskell2010 |
- data LicenseId
- getLicenseId :: LicenseId -> String
- data LicenseExceptionId
- getLicenseExceptionId :: LicenseExceptionId -> String
- data LicenseRef = LicenseRef {
- lrDocument :: !(Maybe String)
- lrLicense :: !String
- data LicenseExpression
- licenses :: [(LicenseId, String, Bool)]
- licenseIdentifiers :: [LicenseId]
- mkLicenseId :: String -> Maybe LicenseId
- isOsiApproved :: LicenseId -> Bool
- licenseExceptions :: [LicenseExceptionId]
- licenseRanges :: [[LicenseId]]
- lookupLicenseRange :: LicenseId -> [LicenseId]
- parseExpression :: String -> [LicenseExpression]
- unsafeParseExpr :: String -> LicenseExpression
- prettyLicenseId :: LicenseId -> String
- prettyLicenseExceptionId :: LicenseExceptionId -> String
- prettyLicenseRef :: LicenseRef -> String
- prettyLicenseExpression :: LicenseExpression -> String
- satisfies :: LicenseExpression -> LicenseExpression -> Bool
- equivalent :: LicenseExpression -> LicenseExpression -> Bool
Types
Opaque license identifier type.
getLicenseId :: LicenseId -> String Source
data LicenseExceptionId Source
Opaque license exception identifier type.
data LicenseRef Source
LicenseRef | |
|
data LicenseExpression Source
Data
licenses :: [(LicenseId, String, Bool)] Source
A list of LicenseId
, license name and whether the license is OSI approved.
licenseIdentifiers :: [LicenseId] Source
A list of SPDX licenses identifiers.
isOsiApproved :: LicenseId -> Bool Source
Whether license is OSI approved
Ranges
licenseRanges :: [[LicenseId]] Source
lookupLicenseRange :: LicenseId -> [LicenseId] Source
Lookup newer licenses we know about
>>>
lookupLicenseRange $ fromJust $ mkLicenseId "MIT"
[LicenseId "MIT"]
>>>
lookupLicenseRange $ fromJust $ mkLicenseId "GPL-2.0"
[LicenseId "GPL-2.0",LicenseId "GPL-3.0"]
>>>
lookupLicenseRange $ fromJust $ mkLicenseId "LGPL-2.0"
[LicenseId "LGPL-2.0",LicenseId "LGPL-2.1",LicenseId "LGPL-3.0"]
Parsing
parseExpression :: String -> [LicenseExpression] Source
Parse SPDX License Expression
>>>
parseExpression "LGPL-2.1 OR MIT"
[EDisjunction (ELicense False (Right (LicenseId "LGPL-2.1")) Nothing) (ELicense False (Right (LicenseId "MIT")) Nothing)]
Prettifying
Inverse of parsing
prettyLicenseId :: LicenseId -> String Source
Logic
:: LicenseExpression | package license |
-> LicenseExpression | license policy |
-> Bool |
⟦ satisfies a b ⟧ ≡ a ≥ b ≡ a ∧ b = b
>>>
unsafeParseExpr "GPL-3.0" `satisfies` unsafeParseExpr "ISC AND MIT"
False
>>>
unsafeParseExpr "Zlib" `satisfies` unsafeParseExpr "ISC AND MIT AND Zlib"
True
>>>
unsafeParseExpr "(MIT OR GPL-2.0)" `satisfies` unsafeParseExpr "(ISC AND MIT)"
True
>>>
unsafeParseExpr "(MIT AND GPL-2.0)" `satisfies` unsafeParseExpr "(MIT AND GPL-2.0)"
True
>>>
unsafeParseExpr "(MIT AND GPL-2.0)" `satisfies` unsafeParseExpr "(ISC AND GPL-2.0)"
False
equivalent :: LicenseExpression -> LicenseExpression -> Bool Source
Check wheather two LicenseExpression
are equivalent.
>>>
unsafeParseExpr "(MIT AND GPL-2.0)" `equivalent` unsafeParseExpr "(GPL-2.0 AND MIT)"
True
>>>
unsafeParseExpr "MIT" `equivalent` unsafeParseExpr "MIT OR BSD-3-Clause"
False