Skip to content

Commit

Permalink
Fix maven lockfile generation on Windows (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewillmon committed Sep 16, 2024
1 parent dff36d8 commit 958f5f7
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed

- Lockfile parsing of bun-generated yarn lockfiles
- Maven lockfile generation on Windows

### Removed

Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lockfile_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ anyhow = "1.0.75"
glob = "0.3.1"
thiserror = "1.0.49"
tempfile = "3.3.0"
dunce = "1.0.5"
2 changes: 1 addition & 1 deletion lockfile_generator/src/gradle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Generator for Gradle {
fn generate_lockfile(&self, manifest_path: &Path) -> Result<String> {
self.check_prerequisites(manifest_path)?;

let canonicalized = fs::canonicalize(manifest_path)?;
let canonicalized = dunce::canonicalize(manifest_path)?;
let project_path = canonicalized
.parent()
.ok_or_else(|| Error::InvalidManifest(manifest_path.to_path_buf()))?;
Expand Down
5 changes: 2 additions & 3 deletions lockfile_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub trait Generator {
fn generate_lockfile(&self, manifest_path: &Path) -> Result<String> {
self.check_prerequisites(manifest_path)?;

let canonicalized = fs::canonicalize(manifest_path)?;
let canonicalized = dunce::canonicalize(manifest_path)?;
let project_path = canonicalized
.parent()
.ok_or_else(|| Error::InvalidManifest(manifest_path.to_path_buf()))?;
Expand All @@ -69,7 +69,6 @@ pub trait Generator {
let mut command = self.command(&canonicalized);
command.current_dir(project_path);
command.stdin(Stdio::null());
command.stdout(Stdio::null());

// Provide better error message, including the failed program's name.
let output = command.output().map_err(|err| {
Expand Down Expand Up @@ -143,7 +142,7 @@ pub enum Error {
Json(#[from] JsonError),
NonZeroExit(Output),
PipReportVersionMismatch(&'static str, String),
ProcessCreation(String, String, io::Error),
ProcessCreation(String, String, #[source] io::Error),
StripPrefix(#[from] StripPrefixError),
UnsupportedCommandVersion(&'static str, &'static str, String),
NoLockfileGenerated,
Expand Down
13 changes: 12 additions & 1 deletion lockfile_generator/src/maven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ use crate::{Error, Generator, Result};

pub struct Maven;

#[cfg(not(windows))]
fn maven_command() -> Command {
Command::new("mvn")
}

#[cfg(windows)]
fn maven_command() -> Command {
// Maven uses a batch script on Windows
Command::new("mvn.cmd")
}

impl Generator for Maven {
fn lockfile_path(&self, manifest_path: &Path) -> Result<PathBuf> {
let project_path = manifest_path
Expand All @@ -17,7 +28,7 @@ impl Generator for Maven {

fn command(&self, manifest_path: &Path) -> Command {
let lockfile_path = self.lockfile_path(manifest_path).unwrap();
let mut command = Command::new("mvn");
let mut command = maven_command();
command.args([
"-q",
"help:effective-pom",
Expand Down
3 changes: 1 addition & 2 deletions lockfile_generator/src/pip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Python pip ecosystem.

use std::fmt::Write;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -56,7 +55,7 @@ impl Generator for Pip {
/// we provide a custom method here which parses this output and transforms
/// it into the locked requirements.txt format our lockfile parser expects.
fn generate_lockfile(&self, manifest_path: &Path) -> Result<String> {
let canonicalized = fs::canonicalize(manifest_path)?;
let canonicalized = dunce::canonicalize(manifest_path)?;
let project_path = canonicalized
.parent()
.ok_or_else(|| Error::InvalidManifest(manifest_path.to_path_buf()))?;
Expand Down
3 changes: 1 addition & 2 deletions lockfile_generator/src/yarn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! JavaScript yarn ecosystem.

use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -42,7 +41,7 @@ impl Generator for Yarn {

/// Get the yarn version of the project.
fn yarn_version(manifest_path: &Path) -> Result<String> {
let canonicalized = fs::canonicalize(manifest_path)?;
let canonicalized = dunce::canonicalize(manifest_path)?;
let project_path = canonicalized
.parent()
.ok_or_else(|| Error::InvalidManifest(manifest_path.to_path_buf()))?;
Expand Down

0 comments on commit 958f5f7

Please sign in to comment.