Skip to content

Commit

Permalink
Merge pull request #5 from ethankhall/add-maven-support
Browse files Browse the repository at this point in the history
Adding maven support
  • Loading branch information
ethankhall authored Jan 24, 2019
2 parents 12facb9 + 9889f78 commit 1570f0e
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 200 deletions.
15 changes: 10 additions & 5 deletions src/common/commands/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use std::path::PathBuf;

use clap::ArgMatches;

use crate::common::error::*;
use crate::common::*;
use crate::crom_lib::*;

pub fn exec_update_version(args: &ArgMatches, project: &dyn Project) -> Result<i32, CromError> {
pub fn exec_update_version(
args: &ArgMatches,
project: &dyn Project,
) -> Result<i32, ErrorContainer> {
let modifier = parse_pre_release(args);

let latest_version = match args.value_of("override_version") {
Expand All @@ -19,18 +21,21 @@ pub fn exec_update_version(args: &ArgMatches, project: &dyn Project) -> Result<i
Ok(0)
}

pub fn exec_upload_artifacts(args: &ArgMatches, project: &dyn Project) -> Result<i32, CromError> {
pub fn exec_upload_artifacts(
args: &ArgMatches,
project: &dyn Project,
) -> Result<i32, ErrorContainer> {
let names = args.values_of("NAMES").unwrap().map(|x| s!(x)).collect();

let version = project.find_latest_version(VersionModification::None);

let root_artifact_path = args.value_of("root_artifact_path").map(|x| PathBuf::from(x));
let root_artifact_path = args.value_of("root_artifact_path").map(PathBuf::from);
project.publish(&version, names, root_artifact_path)?;

Ok(0)
}

pub fn exec_claim_version(args: &ArgMatches, project: &dyn Project) -> Result<i32, CromError> {
pub fn exec_claim_version(args: &ArgMatches, project: &dyn Project) -> Result<i32, ErrorContainer> {
let allow_dirty_repo = if !args.is_present("ignore_changes") {
true
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/common/commands/get.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use clap::ArgMatches;

use crate::common::error::CromError;
use crate::crom_lib::*;

pub fn handle_get_command(args: &ArgMatches, project: &dyn Project) -> Result<i32, CromError> {
pub fn handle_get_command(args: &ArgMatches, project: &dyn Project) -> Result<i32, ErrorContainer> {
match args.subcommand() {
("current-version", Some(run_matches)) => {
let modifier = if run_matches.is_present("no_snapshot") {
Expand All @@ -24,7 +23,7 @@ pub fn handle_get_command(args: &ArgMatches, project: &dyn Project) -> Result<i3
fn print_version(
project: &dyn Project,
modification: VersionModification,
) -> Result<i32, CromError> {
) -> Result<i32, ErrorContainer> {
let latest_version = project.find_latest_version(modification);

info!("{}", latest_version);
Expand Down
9 changes: 5 additions & 4 deletions src/common/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use std::path::Path;

use clap::ArgMatches;

use crate::common::error::*;

use crate::crom_lib::*;

pub fn handle_init_command(args: &ArgMatches) -> Result<i32, CromError> {
pub fn handle_init_command(args: &ArgMatches) -> Result<i32, ErrorContainer> {
let path = std::env::current_dir()?.join(CONFIG_FILE);
let pattern = match args.value_of("bumper").unwrap() {
"semver" => "v0.1.%d",
Expand All @@ -32,7 +30,10 @@ pub fn handle_init_command(args: &ArgMatches) -> Result<i32, CromError> {
Ok(0)
}

fn write_default_config<P: AsRef<Path>>(default_format: &str, dest: P) -> Result<(), CromError> {
fn write_default_config<P: AsRef<Path>>(
default_format: &str,
dest: P,
) -> Result<(), ErrorContainer> {
let default_config = build_default_config(default_format);

let mut file = File::create(dest)?;
Expand Down
131 changes: 0 additions & 131 deletions src/common/error.rs

This file was deleted.

6 changes: 2 additions & 4 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
pub mod commands;
pub mod error;
mod logging;

use clap::ArgMatches;
use std::io::Write;

pub use self::logging::configure_logging;

use self::error::*;
use crate::crom_lib::*;

type CromResult<T> = Result<T, CromError>;
type CromResult<T> = Result<T, ErrorContainer>;

fn are_you_sure(default: bool) -> CromResult<bool> {
std::io::stdout().flush()?;
Expand All @@ -21,7 +19,7 @@ fn are_you_sure(default: bool) -> CromResult<bool> {
"n" => Ok(!default),
_ => {
error!("Didn't understand. Please try again.");
Err(CromError::UserInput)
Err(ErrorContainer::UserInput)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/crom_lib/artifact/compress.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::path::{PathBuf, Path};
use std::path::{Path, PathBuf};

use libflate::gzip::Encoder;
use std::io::Write;
Expand Down Expand Up @@ -47,7 +47,9 @@ fn zip(
art_path.push(Path::new(path));

if !art_path.exists() {
return Err(ErrorContainer::Compress(CompressError::UnableToFindArtifact(art_path.to_str().unwrap().to_string())));
return Err(ErrorContainer::Compress(
CompressError::UnableToFindArtifact(art_path.to_str().unwrap().to_string()),
));
}

let mut file = File::open(art_path)?;
Expand Down
17 changes: 6 additions & 11 deletions src/crom_lib/artifact/github.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;

use hyper::client::HttpConnector;
Expand All @@ -24,7 +23,6 @@ pub fn make_upload_request(
artifacts: ProjectArtifacts,
root_artifact_path: Option<PathBuf>,
) -> Result<Vec<ArtifactContainer>, ErrorContainer> {

let (owner, repo) = match &details.remote {
RepoRemote::GitHub(owner, repo) => (owner, repo),
};
Expand All @@ -48,15 +46,12 @@ pub fn make_upload_request(
let res = rt.block_on(client.request(request)).unwrap();
let upload_url = extract_upload_url(res)?;

let root_path = root_artifact_path.unwrap_or(details.path.clone());
let root_path = root_artifact_path.unwrap_or_else(|| details.path.clone());

match artifacts.compress {
Some(compression) => compress_artifact(
&upload_url,
root_path,
&artifacts.paths,
&compression,
),
Some(compression) => {
compress_artifact(&upload_url, root_path, &artifacts.paths, &compression)
}
None => build_artifact_containers(&upload_url, root_path, &artifacts.paths),
}
}
Expand Down Expand Up @@ -126,7 +121,7 @@ fn extract_upload_url(res: Response<Body>) -> Result<Url, ErrorContainer> {
Err(err) => {
debug!("Body was: {}", body_text);
return Err(ErrorContainer::GitHub(
GitHubError::UnkownCommunicationError(err.description().to_lowercase()),
GitHubError::UnkownCommunicationError(err.to_string().to_lowercase()),
));
}
}
Expand Down Expand Up @@ -157,7 +152,7 @@ fn extract_upload_url(res: Response<Body>) -> Result<Url, ErrorContainer> {
match Url::parse(upload_url) {
Ok(it) => Ok(it),
Err(e) => Err(ErrorContainer::GitHub(GitHubError::UnableToGetUploadUrl(
e.description().to_string(),
e.to_string(),
))),
}
}
4 changes: 3 additions & 1 deletion src/crom_lib/artifact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ pub fn upload_artifacts(

for art in artifacts {
let res = match art.target {
ProjectArtifactTarget::GitHub => github::make_upload_request(details, version, art, root_artifact_path.clone()),
ProjectArtifactTarget::GitHub => {
github::make_upload_request(details, version, art, root_artifact_path.clone())
}
};

match res {
Expand Down
18 changes: 15 additions & 3 deletions src/crom_lib/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ impl Project for ParsedProjectConfig {
)
}

fn publish(&self, version: &Version, names: Vec<String>, root_artifact_path: Option<PathBuf>) -> Result<(), ErrorContainer> {
fn publish(
&self,
version: &Version,
names: Vec<String>,
root_artifact_path: Option<PathBuf>,
) -> Result<(), ErrorContainer> {
let mut artifacts: Vec<ProjectArtifacts> = Vec::new();

for name in names {
Expand All @@ -62,12 +67,19 @@ impl Project for ParsedProjectConfig {
}

if artifacts.is_empty() {
return Err(ErrorContainer::State(StateError::ArtifactNotFound(s!("No aritifact defined"))));
return Err(ErrorContainer::State(StateError::ArtifactNotFound(s!(
"No aritifact defined"
))));
}

debug!("Artifacts to upload: {:?}", artifacts);

crate::crom_lib::artifact::upload_artifacts(&self.repo_details, version, artifacts, root_artifact_path)
crate::crom_lib::artifact::upload_artifacts(
&self.repo_details,
version,
artifacts,
root_artifact_path,
)
}

fn tag_version(
Expand Down
Loading

0 comments on commit 1570f0e

Please sign in to comment.