You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2023/04/16 06:20:34 UTC

[skywalking-php] branch master updated: Refactor script create_package_xml. (#67)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-php.git


The following commit(s) were added to refs/heads/master by this push:
     new 36e2c23  Refactor script create_package_xml. (#67)
36e2c23 is described below

commit 36e2c237bcc2e9c7cc4cdb1e10b3ed0a728f4cb6
Author: jmjoy <jm...@apache.org>
AuthorDate: Sun Apr 16 14:20:29 2023 +0800

    Refactor script create_package_xml. (#67)
---
 package.tpl.xml                           |  2 +-
 scripts/src/command/create_package_xml.rs | 42 ++++++++++++++++---------------
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/package.tpl.xml b/package.tpl.xml
index 26cae2c..9a340cc 100644
--- a/package.tpl.xml
+++ b/package.tpl.xml
@@ -55,7 +55,7 @@ limitations under the License.
 	</notes>
 	<contents>
 		<dir name="/">
-			{% for file in files %}{{ file.path|file_filter }}
+			{% for file in files %}<file name="{{ file.name }}" role="{{ file.role }}" />
 			{% endfor %}
 		</dir>
 	</contents>
diff --git a/scripts/src/command/create_package_xml.rs b/scripts/src/command/create_package_xml.rs
index 8ded8b9..7b4beec 100644
--- a/scripts/src/command/create_package_xml.rs
+++ b/scripts/src/command/create_package_xml.rs
@@ -16,8 +16,8 @@
 use chrono::{DateTime, Local};
 use clap::Parser;
 use serde::Serialize;
-use std::{collections::HashMap, fs, path::PathBuf, process::Command, time::SystemTime};
-use tera::{Context, Result, Tera, Value};
+use std::{fs, path::PathBuf, process::Command, time::SystemTime};
+use tera::{Context, Tera};
 use tracing::info;
 
 /// Create package.xml from template file.
@@ -50,20 +50,28 @@ pub struct CreatePackageXmlCommand {
 
 #[derive(Serialize)]
 struct File {
-    path: String,
+    name: String,
+    role: String,
 }
 
-pub fn file_filter(value: &Value, _: &HashMap<String, Value>) -> Result<Value> {
-    let mut role = "src";
-    let path = value.to_string().trim_matches('"').to_string();
-    if path.ends_with(".md") || path == "LICENSE" || path == "NOTICE" {
-        role = "doc"
+impl File {
+    fn new(path: &str) -> Self {
+        let path = path.trim_matches('"');
+        let role = if path.ends_with(".md")
+            || path.starts_with("docs/")
+            || path.starts_with("dist-material/")
+            || ["LICENSE", "NOTICE"].contains(&path)
+        {
+            "doc"
+        } else {
+            "src"
+        };
+
+        Self {
+            name: path.to_owned(),
+            role: role.to_owned(),
+        }
     }
-
-    Ok(Value::String(format!(
-        "<file name=\"{}\" role=\"{}\"/>",
-        path, role
-    )))
 }
 
 impl CreatePackageXmlCommand {
@@ -78,7 +86,6 @@ impl CreatePackageXmlCommand {
         context.insert("files", &self.get_git_files()?);
 
         let mut tera = Tera::default();
-        tera.register_filter("file_filter", file_filter);
         let contents = tera.render_str(&tpl, &context)?;
 
         info!(target_path = ?&self.target_path, "write target content");
@@ -102,11 +109,6 @@ impl CreatePackageXmlCommand {
             .args(["ls-tree", "-r", "HEAD", "--name-only"])
             .output()?;
         let content = String::from_utf8(output.stdout)?;
-        Ok(content
-            .split_whitespace()
-            .map(|path| File {
-                path: path.to_owned(),
-            })
-            .collect())
+        Ok(content.split_whitespace().map(File::new).collect())
     }
 }