| Copyright | (c) 2015 Oleg Grenrus |
|---|---|
| License | BSD3 |
| Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
| Safe Haskell | Safe |
| Language | Haskell98 |
Data.SPDX
Description
- 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 #
data LicenseExceptionId #
Opaque license exception identifier type.
data LicenseRef #
Constructors
| LicenseRef | |
Fields
| |
Instances
data LicenseExpression #
Data
licenses :: [(LicenseId, String, Bool)] #
A list of LicenseId, license name and whether the license is OSI approved.
licenseIdentifiers :: [LicenseId] #
A list of SPDX licenses identifiers.
isOsiApproved :: LicenseId -> Bool #
Whether license is OSI approved
Ranges
licenseRanges :: [[LicenseId]] #
lookupLicenseRange :: LicenseId -> [LicenseId] #
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] #
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 #
prettyLicenseRef :: LicenseRef -> String #
Logic
Arguments
| :: 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 #
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