Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
22 changes: 14 additions & 8 deletions src/framework/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool chsrc_in_no_color_mode(){return ProgMode.NoColorMode;}
static bool in_measure_mode(){return ProgMode.MeasureMode;}
static bool in_ipv6_mode(){return ProgMode.Ipv6Mode;}
static bool in_dry_run_mode(){return ProgMode.DryRunMode;}

static bool in_custom_user_agent_mode(){return false;}

/**
* Target Group mode (相反则称为 standalone mode)
Expand Down Expand Up @@ -603,20 +603,26 @@ measure_speed_for_url (void *url)
ipv6 = "--ipv6";
}

char *user_agent = NULL;
if (in_custom_user_agent_mode())
{
user_agent = strdup("maven/3.9.11");
}else{
user_agent = xy_2strjoin("chsrc/", Chsrc_Version);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

不要这么处理,看最后的评论。

另外注意代码格式,

if ()
  {
  }
else 
  {
  }

char *os_devnull = xy_os_devnull;

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

// chsrc_info (xy_2strjoin ("测速命令 ", curl_cmd));

char *curl_buf = xy_run (curl_cmd, 0);

free(user_agent);
return curl_buf;
}

Expand Down Expand Up @@ -1803,4 +1809,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}
};
};
79 changes: 62 additions & 17 deletions src/recipe/lang/Java.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,62 @@ pl_java_prelude ()
chef_allow_user_define(this);

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/", DelegateToMirror},
{&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");
*gradle_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
chef_is_home (const char *str)
Copy link
Contributor

Choose a reason for hiding this comment

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

不要定义 chef_ 开头的任何函数,因为 chef_ 开头的函数是通用函数,你可以看下 framework 目录的两个 chef 文件。

辅助性函数全都应该加上 pl_java_ 的前缀,因为我们每一个recipe文件都是被 #include 到全局编译的。

而且这里单独定义这个小函数的意图是?

{
return (xy_str_start_with (str, "Maven home:"));
}

char*
pl_java_find_maven_home (const char *source)
{
if(chef_is_home(source))
{
char *maven_home = xy_str_delete_prefix (source, "Maven home: ");
}
}

char *
pl_java_find_maven_config ()
{
char *buf = xy_run ("mvn -v", 2);
char *maven_home = xy_str_delete_prefix (buf, "Maven home: ");
char *maven_home = xy_run_iter ("mvn -v", 0, pl_java_find_maven_home);
maven_home = xy_str_strip (maven_home);

char *maven_config = xy_normalize_path (xy_2strjoin (maven_home, "/conf/settings.xml"));
return maven_config;
}


char *
pl_java_find_maven_daemon_config ()
{
char *buf = xy_run_iter ("mvnd -v", 0, pl_java_find_maven_home);
char *maven_home = xy_str_delete_prefix (buf, "Maven daemon home: ");
maven_home = xy_str_strip (maven_home);

char *maven_config = xy_normalize_path (xy_2strjoin (maven_home, "/conf/settings.xml"));
Expand All @@ -64,10 +91,18 @@ pl_java_find_maven_config ()
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_2strjoin ("请查看 ", 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_2strjoin ("请查看 ", maven_config));
}
if(maven_daemon_exist)
{
char *maven_config = pl_java_find_maven_daemon_config ();
chsrc_note2 (xy_2strjoin ("请查看 ", maven_config));
}
}


Expand All @@ -77,8 +112,8 @@ pl_java_getsrc (char *option)
void
pl_java_setsrc (char *option)
{
bool maven_exist, gradle_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist);
bool maven_exist, gradle_exist, maven_daemon_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist, &maven_daemon_exist);

use_this_source(pl_java);

Expand All @@ -92,6 +127,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_strjoin (3, "请在 maven 配置文件 ", maven_config, " 中添加:"));
println (file);
}

if (gradle_exist)
{
if (maven_exist) br();
Expand All @@ -108,4 +153,4 @@ void
pl_java_resetsrc (char *option)
{
pl_java_setsrc (option);
}
}
2 changes: 1 addition & 1 deletion src/recipe/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,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