-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from ebroto/feature/license-with-askalono
Replace license crate with askalono
- Loading branch information
Showing
10 changed files
with
175 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ | |
|
||
# nix result from nix-build | ||
result | ||
|
||
# generated license cache | ||
resources/licenses/cache.bin.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "resources/licenses/spdx"] | ||
path = resources/licenses/spdx | ||
url = https://github.com/spdx/license-list-data |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
extern crate askalono; | ||
|
||
use std::fs::File; | ||
use std::path::Path; | ||
|
||
use askalono::Store; | ||
|
||
const EMBEDDED_CACHE: &str = "resources/licenses/cache.bin.gz"; | ||
|
||
fn main() { | ||
if Path::new(EMBEDDED_CACHE).exists() { | ||
println!("cargo:warning=onefetch license cache file already exists; not re-building"); | ||
return; | ||
} | ||
|
||
let mut store = Store::new(); | ||
store | ||
.load_spdx(Path::new("resources/licenses/spdx/json/details"), false) | ||
.expect("Couldn't create a store from SPDX data. Have submodules been initialized?"); | ||
|
||
let mut cache = File::create(EMBEDDED_CACHE).unwrap(); | ||
store.to_cache(&mut cache).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use askalono::{Store, TextData}; | ||
|
||
use crate::Error; | ||
|
||
type Result<T> = std::result::Result<T, Error>; | ||
|
||
static CACHE_DATA: &[u8] = include_bytes!("../resources/licenses/cache.bin.gz"); | ||
|
||
pub struct Detector { | ||
store: Store, | ||
} | ||
|
||
impl Detector { | ||
pub fn new() -> Result<Self> { | ||
Store::from_cache(CACHE_DATA) | ||
.map(|store| Self { store }) | ||
.map_err(|_| Error::LicenseDetectorError) | ||
} | ||
|
||
pub fn analyze(&self, text: &str) -> Option<String> { | ||
self.store | ||
.analyze(&TextData::from(text)) | ||
.ok() | ||
.map(|license| license.name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters