Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ chsrc set rust | cargo | crate
chsrc set rustup

chsrc set go
chsrc set java | maven | mvn | gradle
chsrc set java | maven | mvn | maven-daemon | mvnd | gradle
chsrc set clojure | clojars
chsrc set dart | pub
chsrc set flutter
Expand Down Expand Up @@ -595,4 +595,4 @@ chsrc set conda | anaconda
[@Efterklang]: https://github.com/Efterklang
[@wickdynex]: https://github.com/wickdynex
[@YU-7]: https://github.com/YU-7
[@sanchuanhehe]: https://github.com/sanchuanhehe
[@sanchuanhehe]: https://github.com/sanchuanhehe
11 changes: 6 additions & 5 deletions lib/xy.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ _xy_log_brkt (int level, const char *prompt1, const char *prompt2, const char *c
* 由于目标行会被返回出来,所以 `func` 并不执行目标行,只会执行遍历过的行
*/
static char *
xy_run_iter_lines (const char *cmd, unsigned long n, void (*func) (const char *))
xy_run_iter_lines (const char *cmd, unsigned long n, bool (*func) (const char *))
{
const int size = 512;
char *buf = (char *) malloc (size);
Expand All @@ -796,7 +796,10 @@ xy_run_iter_lines (const char *cmd, unsigned long n, void (*func) (const char
break;
if (func)
{
func (buf);
if (func (buf)) {
pclose (stream);
return ret;
}
}
}

Expand Down Expand Up @@ -1497,7 +1500,6 @@ xy_map_get (XyMap_t *map, const char *key)
return NULL;
}


/**
* @flavor Ruby: Hash#each
*/
Expand All @@ -1521,5 +1523,4 @@ xy_map_each (
}
}


#endif
#endif
24 changes: 14 additions & 10 deletions src/framework/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ struct

/* 此时 chsrc_run() 不再是recipe中指定要运行的一个外部命令,而是作为一个功能实现的支撑 */
bool chsrc_run_faas;
char *user_agent;
}
ProgStatus =
{
.leader_selected_index = -1,
.chgtype = ChgType_Auto,
.chsrc_run_faas = false
.chsrc_run_faas = false,
.user_agent = "chsrc/" Chsrc_Version,
};


Expand Down Expand Up @@ -642,15 +644,13 @@ measure_speed_for_url (void *url)
/**
* @note 我们用 —L,因为部分链接会跳转到其他地方,比如: RubyChina, npmmirror
*/
char *curl_cmd = xy_strcat (8, "curl -qsL ", ipv6,
" -o ", os_devnull,
" -w \"%{http_code} %{speed_download}\" -m", time_sec,
" -A chsrc/" Chsrc_Version " ", url);

// chsrc_info (xy_2strcat ("测速命令 ", curl_cmd));
char *curl_cmd = xy_strcat (10, "curl -qsL ", ipv6,
" -o ", os_devnull,
" -w \"%{http_code} %{speed_download}\" -m", time_sec,
" -A ", ProgStatus.user_agent, " ", url);

// chsrc_note2 (xy_2strcat ("测速命令 ", curl_cmd));
char *curl_buf = xy_run (curl_cmd, 0);

return curl_buf;
}

Expand Down Expand Up @@ -1111,7 +1111,11 @@ chsrc_determine_chgtype (ChgType_t type)
ProgStatus.chgtype = chsrc_in_reset_mode() ? ChgType_Reset : type;
}


void
chsrc_custom_user_agent (char *user_agent)
{
ProgStatus.user_agent = user_agent;
}

#define MSG_EN_PUBLIC_URL "If the URL you specify is a public service, you are invited to contribute: chsrc issue"
#define MSG_CN_PUBLIC_URL "若您指定的URL为公有服务,邀您参与贡献: chsrc issue"
Expand Down Expand Up @@ -1845,4 +1849,4 @@ chsrc_get_cpucore ()
#endif

return cores;
}
}
9 changes: 8 additions & 1 deletion src/framework/mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ Huawei =
{NotSkip, NA, NA, "https://mirrors.huaweicloud.com/ubuntu-releases" Big_File_ubuntu, ROUGH}
},

HuaweiCdn =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个有点纠结,不知道它到底是否通用

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个的话,我去找一些链接(其他镜像)去替换域名到repo 试试, 试试才知道

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let new = HuaweiCDN
let old = 现有的那个默认华为镜像站

如果 $new 如此通用,而且一直比 $old 快一些,我觉得可以把 $old 直接给换成 $new。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$new 通用 单 并不能保证一直比$old 快 , 从实际体验上来说,和之前的经验, 要看网络状态。我之前都是手动测速后设置的。

{
IS_GeneralMirrorSite,
"huaweiCdn", "Huawei Cloud", "华为开源镜像站", "https://repo.huaweicloud.com/",
{NotSkip, NA, NA, "https://repo.huaweicloud.com/ubuntu-releases" Big_File_ubuntu, ROUGH}
},

Volcengine =
{
IS_GeneralMirrorSite,
Expand Down Expand Up @@ -294,4 +301,4 @@ Sohu =
IS_GeneralMirrorSite,
"sohu", "SOHU", "搜狐开源镜像站", "https://mirrors.sohu.com/",
{NotSkip, NA, NA, "https://mirrors.sohu.com/deepin-cd" Big_File_deepin, ROUGH}
};
};
110 changes: 87 additions & 23 deletions src/recipe/lang/Java.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
* ------------------------------------------------------------*/

def_target(pl_java, "java/maven/mvn/gradle");
def_target(pl_java, "java/maven/mvn/maven-daemon/mvnd/gradle");

void
pl_java_prelude ()
Expand All @@ -20,65 +20,119 @@ pl_java_prelude ()
chef_allow_local_mode (this, CanNot, NULL, NULL);
chef_forbid_english(this);
chef_allow_user_define(this);
chsrc_custom_user_agent("Maven/3.9.11");

def_sources_begin()
{&UpstreamProvider, "https://repo1.maven.org/maven2/", DelegateToUpstream},
{&Ali, "https://maven.aliyun.com/repository/public/", DelegateToMirror},
{&Huawei, "https://mirrors.huaweicloud.com/repository/maven/", DelegateToMirror},

{&UpstreamProvider, "https://repo1.maven.org/maven2/", DelegateToUpstream},
{&Ali, "https://maven.aliyun.com/repository/public/", "https://maven.aliyun.com/repository/public/com/tencentcloudapi/tencentcloud-sdk-java/3.1.1033/tencentcloud-sdk-java-3.1.1033-javadoc.jar"},
{&Huawei, "https://mirrors.huaweicloud.com/repository/maven/", "https://mirrors.huaweicloud.com/repository/maven/com/tencentcloudapi/tencentcloud-sdk-java/3.1.1033/tencentcloud-sdk-java-3.1.1033-javadoc.jar"},
{&HuaweiCdn, "https://repo.huaweicloud.com/repository/maven/", "https://repo.huaweicloud.com/repository/maven/com/tencentcloudapi/tencentcloud-sdk-java/3.1.1033/tencentcloud-sdk-java-3.1.1033-javadoc.jar"},
{&Tencent, "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/", "https://mirrors.cloud.tencent.com/nexus/repository/maven-public/com/tencentcloudapi/tencentcloud-sdk-java/3.1.1033/tencentcloud-sdk-java-3.1.1033-javadoc.jar"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可参考一下 https://github.com/RubyMetric/chsrc/blob/main/src/recipe/os/APT/Debian.c#L50

如果是直接往后面加后缀,可以直接用 chef_ 函数,不用定义一大堆重复的。

// 网易的24小时更新一次
{&Netease, "http://mirrors.163.com/maven/repository/maven-public/", DelegateToMirror}
{&Netease, "http://mirrors.163.com/maven/repository/maven-public/", "https://mirrors.163.com/maven/repository/maven-public/com/tencentcloudapi/tencentcloud-sdk-java/3.1.1033/tencentcloud-sdk-java-3.1.1033-javadoc.jar"}
def_sources_end()
}


void
pl_java_check_cmd (bool *maven_exist, bool *gradle_exist)
pl_java_check_cmd (bool *maven_exist, bool *gradle_exist, bool *maven_daemon_exist)
{
*maven_exist = chsrc_check_program ("mvn");
*gradle_exist = chsrc_check_program ("gradle");
*maven_daemon_exist = chsrc_check_program ("mvnd");

if (! *maven_exist && ! *gradle_exist)
if (! *maven_exist && ! *gradle_exist && ! *maven_daemon_exist)
{
chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一");
chsrc_error ("maven(maven-daemon) 与 gradle 命令均未找到,请检查是否存在其一");
exit (Exit_UserCause);
}
}

bool
pl_java_is_home (const char *str)
{
return (xy_str_start_with (str, "Maven home:"));
}

bool
pl_java_find_maven_home (const char *line)
{
if(pl_java_is_home(line))
{
return true;
}
return false;
}

char *
pl_java_find_maven_config ()
{
char *buf = xy_run ("mvn -v", 2);
char *maven_home = xy_str_delete_prefix (buf, "Maven home: ");
maven_home = xy_str_strip (maven_home);
char *output;
int status = xy_run_capture ("mvn -v", &output);
if (0==status)
{
char *maven_home_line = xy_run_iter_lines ("mvn -v", 0, pl_java_find_maven_home);
char *maven_home = xy_str_delete_prefix (maven_home_line, "Maven home: ");
char *maven_config = xy_normalize_path (xy_2strcat (maven_home, "/conf/settings.xml"));
return maven_config;
}
else
{
printf("no find maven home\n");
}
return "~/.m2/settings.xml";
}

char *maven_config = xy_normalize_path (xy_2strcat (maven_home, "/conf/settings.xml"));
return maven_config;
char *
pl_java_find_maven_daemon_config ()
{
char *output;
int status = xy_run_capture ("mvnd -v", &output);
if (0==status)
{
char *maven_home_line = xy_run_iter_lines ("mvnd -v", 0, pl_java_find_maven_home);
char *maven_home = xy_str_delete_prefix (maven_home_line, "Maven home: ");
char *maven_config = xy_normalize_path (xy_2strcat (maven_home, "/conf/settings.xml"));
return maven_config;
}
else
{
printf ("no find maven home\n");
}
return "~/.m2/settings.xml";
}


void
pl_java_getsrc (char *option)
{
bool maven_exist, gradle_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist);
char *maven_config = pl_java_find_maven_config ();
chsrc_note2 (xy_2strcat ("请查看 ", maven_config));
bool maven_exist, gradle_exist, maven_daemon_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist, &maven_daemon_exist);
if (maven_exist)
{
char *maven_config = pl_java_find_maven_config ();
chsrc_note2 (xy_2strcat ("请查看 ", maven_config));
}
if(maven_daemon_exist)
{
char *maven_config = pl_java_find_maven_daemon_config ();
chsrc_note2 (xy_2strcat ("请查看 ", maven_config));
}
}



/**
* @consult https://developer.aliyun.com/mirror/maven
*/
void
pl_java_setsrc (char *option)
{
bool maven_exist, gradle_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist);

chsrc_use_this_source (pl_java);
bool maven_exist, gradle_exist, maven_daemon_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist, &maven_daemon_exist);

chsrc_use_this_source(pl_java);
use_custom_user_agent();
if (maven_exist)
{
char *file = xy_str_gsub (RAWSTR_pl_java_maven_config, "@1@", source.mirror->code);
Expand All @@ -89,6 +143,16 @@ pl_java_setsrc (char *option)
println (file);
}

if (maven_daemon_exist)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

条件不用加 “或” maven_exist 吗?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实我是想删掉这个命令判断的, 如果我是用windows 那么 这三个命令都将不存在,如果是linux 则正常存在。 因为我不会主动去配置环境变量,因为本身可以自动切换配置了反而导致每次切换要修改环境变量,甚至有时注销才能生效(还不支持同时启动 不同版本jdk的项目的需求)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image 这里maven_config 指针如何提取作用域,这样就可以加 ||

{
char *file = xy_str_gsub (RAWSTR_pl_java_maven_config, "@1@", source.mirror->code);
file = xy_str_gsub (file, "@name@", source.mirror->name);
file = xy_str_gsub (file, "@url@", source.url);
char *maven_config = pl_java_find_maven_daemon_config ();
chsrc_note2 (xy_strcat (3, "请在 maven 配置文件 ", maven_config, " 中添加:"));
println (file);
}

if (gradle_exist)
{
if (maven_exist) br();
Expand All @@ -105,4 +169,4 @@ void
pl_java_resetsrc (char *option)
{
pl_java_setsrc (option);
}
}
5 changes: 3 additions & 2 deletions src/recipe/lang/Ruby/Ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pl_ruby_getsrc (char *option)
chsrc_run ("bundle config get mirror.https://rubygems.org", RunOpt_Default);
}

void
bool
pl_ruby_remove_gem_source (const char *source)
{
char *cmd = NULL;
Expand All @@ -59,6 +59,7 @@ pl_ruby_remove_gem_source (const char *source)
cmd = xy_2strcat ("gem sources -r ", source);
chsrc_run (cmd, RunOpt_Default);
}
return false;
}

/**
Expand Down Expand Up @@ -103,4 +104,4 @@ void
pl_ruby_resetsrc (char *option)
{
pl_ruby_setsrc (option);
}
}
2 changes: 1 addition & 1 deletion src/recipe/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ chsrc_available_mirrors[] = {

/* ------------------------ chsrc 内部实现 ------------------------ */
/* 不要列出 &UpstreamProvider 和 &UserDefinedProvider */
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

似乎你的编辑器会删除最后一行空行,可以安装一下 EditorConfig 插件。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

编辑器应该是自动加换行, 这个配置昨天才关掉的,我再看下吧.

Loading