Skip to content

Commit

Permalink
Use a newer version of askalono so ISC is detected
Browse files Browse the repository at this point in the history
Also:
 * Remove unused build-dependency as we don't generate the cache anymore at
   build time
 * Adapt license module to the new askalono API
 * Remove duplicates when multiple files with the same license are used
  • Loading branch information
ebroto committed Nov 6, 2019
1 parent 13993b5 commit 4dfc4e5
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 82 deletions.
146 changes: 76 additions & 70 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ exclude = ["assets/*.png"]
colored= "1.8.0"
git2 = {version = "0.7.5", default-features = false}
tokei = "10.0"
askalono = "0.3.0"
askalono = { git = "https://github.com/amzn/askalono.git", rev = "39f6e228775e17266bcba46f48b26b01bbfb7698" }
bytecount = "0.5.1"
clap = "2.33.0"
strum = "0.16.0"
strum_macros = "0.16.0"
image = "0.22.3"

[build-dependencies]
askalono = "0.3.0"

[target.'cfg(windows)'.dependencies]
ansi_term = "0.12"

Expand Down
Binary file removed resources/licenses/cache.bin.gz
Binary file not shown.
Binary file added resources/licenses/cache.bin.zstd
Binary file not shown.
9 changes: 6 additions & 3 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ impl Info {
fn get_project_license(dir: &str) -> Result<String> {
let detector = Detector::new()?;

let output = fs::read_dir(dir)
let mut output = fs::read_dir(dir)
.map_err(|_| Error::ReadDirectory)?
.filter_map(std::result::Result::ok)
.map(|entry| entry.path())
Expand All @@ -601,8 +601,11 @@ impl Info {
let contents = fs::read_to_string(entry).unwrap_or_default();
detector.analyze(&contents)
})
.collect::<Vec<_>>()
.join(", ");
.collect::<Vec<_>>();

output.sort();
output.dedup();
let output = output.join(", ");

if output == "" {
Ok("??".into())
Expand Down
13 changes: 8 additions & 5 deletions src/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::Error;

type Result<T> = std::result::Result<T, Error>;

static CACHE_DATA: &[u8] = include_bytes!("../resources/licenses/cache.bin.gz");
static CACHE_DATA: &[u8] = include_bytes!("../resources/licenses/cache.bin.zstd");

pub struct Detector {
store: Store,
Expand All @@ -18,9 +18,12 @@ impl Detector {
}

pub fn analyze(&self, text: &str) -> Option<String> {
self.store
.analyze(&TextData::from(text))
.ok()
.map(|license| license.name)
let matched = self.store.analyze(&TextData::from(text));

if matched.score > 0. {
Some(matched.name.into())
} else {
None
}
}
}

0 comments on commit 4dfc4e5

Please sign in to comment.