Skip to content

Conversation

@gaosaroma
Copy link
Contributor

@gaosaroma gaosaroma commented Jun 26, 2024

To fix koupleless/koupleless#221

使用方式

  1. 基座配置需要的模块包,如下:

image

bootstrap.properties:

integrateBizURLs=file://${biz_path_1},http://${biz_path_2},https://${biz_path_3}
integrateLocalDirs=${localDir1},${localDir2},${localDir3}

bootstrap.yml

integrateBizURLs:
  - file://${biz_path_1}
  - http://${biz_path_2}
  - https://${biz_path_3}
 integrateLocalDirs:
  - ${localDir1}
  - ${localDir2}
  - ${localDir3}
  1. 基座bootstrap的pom中给 koupleless-base-build-plugin 添加 <goal>integrate-biz</goal>
<plugin>
                <groupId>com.alipay.sofa.koupleless</groupId>
                <artifactId>koupleless-base-build-plugin</artifactId>
                <version>${koupleless.runtime.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>add-patch</goal>
                            <goal>integrate-biz</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
  1. 基座打包时,模块ark-biz.jar 将放在 BOOT-INF/classes/SOFA-ARK/biz 下,和用户自行放在 resources/SOFA-ARK/biz 效果一样。

Summary by CodeRabbit

  • New Features

    • Introduced a Maven Mojo for integrating business artifacts into resources.
    • Added utility classes for parsing properties, handling JAR files, and managing OS-specific settings.
    • Introduced functionality for managing SOFA-ARK configurations via properties and YAML files.
    • Added test files for validating business configuration integrations.
    • Introduced constants for file and URL handling in the SOFA-ARK module.
  • Bug Fixes

    • Corrected a typo in a comment within the MavenDependencyAdapterMapping class.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

The changes introduce a Maven Mojo KouplelessBaseIntegrateBizMojo to facilitate the integration of business artifacts into resources. This includes reading configurations from properties and YAML files, copying files and directories to target directories, and handling URLs for business artifacts. Supporting utility classes and methods were added to assist in parsing configurations and handling file operations.

Changes

File Path Summary
.../KouplelessBaseIntegrateBizMojo.java Introduces a Maven Mojo for integrating business artifacts, including methods for execution, configuration initialization, and resource integration.
.../JarFileUtils.java Adds imports and a method to retrieve main attributes from a JAR file.
.../Constants.java Introduces various string constants related to file prefixes, paths, and configurations.
.../ArkConfigHolder.java Provides methods to initialize and retrieve properties and YAML configurations for an Ark application.
.../KouplelessIntegrateBizConfig.java Introduces a class with methods to add file and local directory URLs to corresponding sets.
.../MavenDependencyAdapterMapping.java Updates a comment description for dependency matching functionality.
.../ParseUtils.java Introduces utility methods for parsing properties and maps to retrieve sets of values.
.../OSUtils.java Provides a utility class with a method to retrieve the local file protocol prefix based on the operating system.
.../MockUtils.java Provides a utility class with a method to retrieve a file as a resource given a path.
.../test/resources/.../ark.properties Introduces configurations for integrating business URLs and local directories.
.../test/resources/.../ark.yml Introduces configurations for integrating business URLs and local directories.
.../KouplelessBaseIntegrateBizMojoTest.java Contains test methods for initializing and integrating business configurations.
.../test/resources/.../bootstrap.properties Specifies integrated business URLs and local directories for the system.
.../test/resources/.../bootstrap.yml Introduces configurations for integrating business URLs and local directories.

Sequence Diagram(s)

sequenceDiagram
    participant MavenBuild as Maven Build
    participant KouplelessBaseIntegrateBizMojo
    participant ArkConfigHolder
    participant Constants
    participant Resources

    MavenBuild->>KouplelessBaseIntegrateBizMojo: Execute Mojo
    KouplelessBaseIntegrateBizMojo->>ArkConfigHolder: Init Configurations
    ArkConfigHolder->>Constants: Retrieve Config Paths
    Constants-->>ArkConfigHolder: Config Paths
    ArkConfigHolder-->>KouplelessBaseIntegrateBizMojo: Configurations Initialized
    KouplelessBaseIntegrateBizMojo->>Resources: Copy Files and Directories
    Resources-->>KouplelessBaseIntegrateBizMojo: Files Integrated
    KouplelessBaseIntegrateBizMojo-->>MavenBuild: Mojo Execution Complete
Loading

Assessment against linked issues

Objective (Issue) Addressed Explanation
Unified design for multiple deployment modes (221)

Poem

In the world of code where dreams reside,
A Maven Mojo takes a mighty stride,
Integrating biz with files to share,
From local paths to resources fair.
Configs read from YAML, properties too,
A rabbit's touch makes dreams come true!
🌟🐇✨

Tip

You can get early access to new features

Enable the early-access setting in your project's settings in CodeRabbit to enable early-access features.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7c0505f and be1cd2e.

Files selected for processing (8)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseBuildPrePackageMojo.java (2 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojo.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/common/JarFileUtils.java (2 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/constant/Constants.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/model/ArkConfigHolder.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/model/KouplelessIntegrateBizConfig.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/model/MavenDependencyAdapterMapping.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/utils/ParseUtils.java (1 hunks)
Files skipped from review due to trivial changes (3)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseBuildPrePackageMojo.java
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/constant/Constants.java
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/model/MavenDependencyAdapterMapping.java

Comment on lines 29 to 42
@Getter
public class KouplelessIntegrateBizConfig {
private Set<String> fileURLs = new HashSet<>();

private Set<String> localDirURLs = new HashSet<>();

public void addFileURLs(Set<String> urls) {
fileURLs.addAll(urls);
}

public void addLocalDirURLs(Set<String> urls) {
localDirURLs.addAll(urls);
}
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Good use of Java Collections and Lombok for simplicity in KouplelessIntegrateBizConfig.

The use of HashSet ensures uniqueness and @Getter from Lombok simplifies the boilerplate code. However, consider adding thread safety if concurrent modifications are expected.

-   private Set<String> fileURLs     = new HashSet<>();
-   private Set<String> localDirURLs = new HashSet<>();
+   private Set<String> fileURLs     = Collections.synchronizedSet(new HashSet<>());
+   private Set<String> localDirURLs = Collections.synchronizedSet(new HashSet<>());
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Getter
public class KouplelessIntegrateBizConfig {
private Set<String> fileURLs = new HashSet<>();
private Set<String> localDirURLs = new HashSet<>();
public void addFileURLs(Set<String> urls) {
fileURLs.addAll(urls);
}
public void addLocalDirURLs(Set<String> urls) {
localDirURLs.addAll(urls);
}
}
@Getter
public class KouplelessIntegrateBizConfig {
private Set<String> fileURLs = Collections.synchronizedSet(new HashSet<>());
private Set<String> localDirURLs = Collections.synchronizedSet(new HashSet<>());
public void addFileURLs(Set<String> urls) {
fileURLs.addAll(urls);
}
public void addLocalDirURLs(Set<String> urls) {
localDirURLs.addAll(urls);
}
}

Comment on lines +34 to +47
public static Set<String> getSetValues(Properties prop, String confKey) {
if (null == prop) {
return newHashSet();
}
String[] values = StringUtils.split(prop.getProperty(confKey), COMMA_SPLIT);
return values == null ? newHashSet() : newHashSet(values);
}

public static Set<String> getStringSet(Map<String, Object> yaml, String confKey) {
if (null != yaml && yaml.containsKey(confKey) && null != yaml.get(confKey)) {
return newHashSet((List<String>) yaml.get(confKey));
}
return newHashSet();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Review of ParseUtils methods for extracting sets from properties and maps.

The methods correctly handle null inputs and use efficient libraries for string manipulation and set creation. Ensure that the type casting in getStringSet is safe and consider adding generics to avoid unchecked casting.

-   public static Set<String> getStringSet(Map<String, Object> yaml, String confKey) {
+   public static Set<String> getStringSet(Map<String, Object> yaml, String confKey) {
+       // Ensure type safety with a check before casting
+       if (!(yaml.get(confKey) instanceof List)) throw new IllegalArgumentException("Expected a List type for key: " + confKey);
        return newHashSet((List<String>) yaml.get(confKey));
    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static Set<String> getSetValues(Properties prop, String confKey) {
if (null == prop) {
return newHashSet();
}
String[] values = StringUtils.split(prop.getProperty(confKey), COMMA_SPLIT);
return values == null ? newHashSet() : newHashSet(values);
}
public static Set<String> getStringSet(Map<String, Object> yaml, String confKey) {
if (null != yaml && yaml.containsKey(confKey) && null != yaml.get(confKey)) {
return newHashSet((List<String>) yaml.get(confKey));
}
return newHashSet();
}
public static Set<String> getStringSet(Map<String, Object> yaml, String confKey) {
// Ensure type safety with a check before casting
if (!(yaml.get(confKey) instanceof List)) throw new IllegalArgumentException("Expected a List type for key: " + confKey);
return newHashSet((List<String>) yaml.get(confKey));
}

Comment on lines +75 to +84
@SneakyThrows
public static Map<String, Object> getMainAttributes(String bizUrl) {
try (JarFile jarFile = new JarFile(bizUrl)) {
Manifest manifest = jarFile.getManifest();
Preconditions.checkState(manifest != null, "Manifest file not found in the JAR.");
Map<String, Object> result = new HashMap<>();
manifest.getMainAttributes().forEach((k, v) -> result.put(k.toString(), v));
return result;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

New method getMainAttributes in JarFileUtils needs improvements in exception handling.

The method uses Preconditions.checkState from Guava, which is good for state validation. However, consider enhancing the error message to include more context about the failure.

-   Preconditions.checkState(manifest != null, "Manifest file not found in the JAR.");
+   Preconditions.checkState(manifest != null, "Manifest file not found in JAR: " + bizUrl);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@SneakyThrows
public static Map<String, Object> getMainAttributes(String bizUrl) {
try (JarFile jarFile = new JarFile(bizUrl)) {
Manifest manifest = jarFile.getManifest();
Preconditions.checkState(manifest != null, "Manifest file not found in the JAR.");
Map<String, Object> result = new HashMap<>();
manifest.getMainAttributes().forEach((k, v) -> result.put(k.toString(), v));
return result;
}
}
@SneakyThrows
public static Map<String, Object> getMainAttributes(String bizUrl) {
try (JarFile jarFile = new JarFile(bizUrl)) {
Manifest manifest = jarFile.getManifest();
Preconditions.checkState(manifest != null, "Manifest file not found in JAR: " + bizUrl);
Map<String, Object> result = new HashMap<>();
manifest.getMainAttributes().forEach((k, v) -> result.put(k.toString(), v));
return result;
}
}

Comment on lines 42 to 105
public static Properties getArkProperties(String baseDir) {
return arkProperties == null ? initArkProperties(baseDir) : arkProperties;
}

public static Map<String, Object> getArkYaml(String baseDir) {
return arkYaml == null ? initArkYaml(baseDir) : arkYaml;
}

@SneakyThrows
private static Map<String, Object> initArkYaml(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_YML_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
System.out.printf(
"koupleless-base-build-plugin: extension-config %s not found, will not config it",
configPath);
return newHashMap();
}

System.out.printf(
"koupleless-base-build-plugin: find extension-config %s and will config it\n",
configPath);

try (FileInputStream fis = new FileInputStream(configPath)) {
Yaml yaml = new Yaml();
arkYaml = yaml.load(fis);
return arkYaml;
} catch (IOException ex) {
System.out.printf(
String.format("failed to parse excludes artifacts from %s.", configPath), ex);
throw ex;
}
}

@SneakyThrows
private static Properties initArkProperties(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_PROPERTIES_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
System.out.printf(
"koupleless-base-build-plugin: extension-config %s not found, will not config it%n\n",
configPath);
return new Properties();
}

System.out.printf(
"koupleless-base-build-plugin: find extension-config %s and will config it",
configPath);

Properties prop = new Properties();
try (FileInputStream fis = new FileInputStream(configPath)) {
prop.load(fis);
arkProperties = prop;
return prop;
} catch (IOException ex) {
System.out.printf(
String.format("koupleless-base-build-plugin: failed to read extension-config %s.",
configPath),
ex);
throw ex;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Review of configuration loading methods in ArkConfigHolder.

Methods use System.out.printf for logging, which is not suitable for production. Replace with a proper logging framework. Additionally, consider catching specific exceptions rather than using SneakyThrows.

-   System.out.printf("...");
+   logger.info("..."); // Use a logging framework like SLF4J

-   @SneakyThrows
+   try {
+       ...
+   } catch (SpecificException ex) {
+       logger.error("Error message", ex);
+       throw new CustomException("Error message", ex);
+   }

Committable suggestion was skipped due to low confidence.

Comment on lines 67 to 166
/** {@inheritDoc} */
@Override
public void execute() {
try {
initKouplelessIntegrateBizConfig();
integrateBizToResource();
} catch (Throwable t) {
getLog().error(t);
throw new RuntimeException(t);
}
}

private void integrateBizToResource() throws IOException {
copyFilesToResource();
copyLocalDirsToResource();
}

private void copyFilesToResource() throws IOException {
File targetDir = new File(outputDirectory, SOFA_ARK_MODULE);
for (String urlStr : kouplelessIntegrateBizConfig.getFileURLs()) {
File targetFile = new File(targetDir, getFullRevision(urlStr));
if (!targetFile.exists()) {
URL url = new URL(urlStr);
try (InputStream inputStream = url.openStream()) {
FileUtils.copyInputStreamToFile(inputStream, targetFile);
}
}
}
}

private String getFullRevision(String bizUrl) {
// file:///xxx/{name}-{version}-ark-biz.jar
if (bizUrl.startsWith(FILE_PREFIX)) {
return StringUtils.substringAfterLast(bizUrl, File.separator);
}

// https://xxx/{name}-{version}.jar
if (bizUrl.startsWith(HTTP_PREFIX) || bizUrl.startsWith(HTTPS_PREFIX)) {
return StringUtils.substringAfterLast(bizUrl, "/");
}

return "unknownBizName-unknownBizVersion.jar";
}

private void copyLocalDirsToResource() throws IOException {
File targetDir = new File(outputDirectory, SOFA_ARK_MODULE);
for (String dirPath : kouplelessIntegrateBizConfig.getLocalDirURLs()) {
for (File bizSourceFile : getBizFileFromLocalFileSystem(dirPath)) {
File targetFile = new File(targetDir, bizSourceFile.getName());
if (!targetFile.exists()) {
FileUtils.copyFileToDirectory(bizSourceFile, targetDir);
}
}
}
}

@SneakyThrows
public List<File> getBizFileFromLocalFileSystem(String absoluteBizDirPath) {
List<File> bizFiles = new ArrayList<>();
Files.walkFileTree(new File(absoluteBizDirPath).toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Path absolutePath = file.toAbsolutePath();
if (absolutePath.toString().endsWith(".jar")) {
Map<String, Object> attributes = JarFileUtils
.getMainAttributes(absolutePath.toString());
if (attributes.containsKey("Ark-Biz-Name")) {
getLog().info(String.format("Found biz jar file: %s", absolutePath));
bizFiles.add(file.toFile());
}
}

return FileVisitResult.CONTINUE;
}
});

return bizFiles;
}

private void initKouplelessIntegrateBizConfig() {
readFromArkPropertiesFile();
readFromArkYamlFile();
}

private void readFromArkYamlFile() {
Map<String, Object> arkYaml = ArkConfigHolder.getArkYaml(baseDir.getAbsolutePath());
kouplelessIntegrateBizConfig
.addFileURLs(ParseUtils.getStringSet(arkYaml, EXTENSION_INTEGRATE_LOCAL_URLS));
kouplelessIntegrateBizConfig
.addLocalDirURLs(ParseUtils.getStringSet(arkYaml, EXTENSION_INTEGRATE_LOCAL_DIRS));
}

private void readFromArkPropertiesFile() {
Properties arkProperties = ArkConfigHolder.getArkProperties(baseDir.getAbsolutePath());
kouplelessIntegrateBizConfig
.addFileURLs(ParseUtils.getSetValues(arkProperties, EXTENSION_INTEGRATE_LOCAL_URLS));
kouplelessIntegrateBizConfig.addLocalDirURLs(
ParseUtils.getSetValues(arkProperties, EXTENSION_INTEGRATE_LOCAL_DIRS));

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Review of execute and configuration methods in KouplelessBaseIntegrateBizMojo.

The methods are well-structured and follow Maven's guidelines for Mojos. However, improve exception handling by not rethrowing RuntimeException without context.

-   throw new RuntimeException(t);
+   throw new RuntimeException("Error during integration of business artifacts", t);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/** {@inheritDoc} */
@Override
public void execute() {
try {
initKouplelessIntegrateBizConfig();
integrateBizToResource();
} catch (Throwable t) {
getLog().error(t);
throw new RuntimeException(t);
}
}
private void integrateBizToResource() throws IOException {
copyFilesToResource();
copyLocalDirsToResource();
}
private void copyFilesToResource() throws IOException {
File targetDir = new File(outputDirectory, SOFA_ARK_MODULE);
for (String urlStr : kouplelessIntegrateBizConfig.getFileURLs()) {
File targetFile = new File(targetDir, getFullRevision(urlStr));
if (!targetFile.exists()) {
URL url = new URL(urlStr);
try (InputStream inputStream = url.openStream()) {
FileUtils.copyInputStreamToFile(inputStream, targetFile);
}
}
}
}
private String getFullRevision(String bizUrl) {
// file:///xxx/{name}-{version}-ark-biz.jar
if (bizUrl.startsWith(FILE_PREFIX)) {
return StringUtils.substringAfterLast(bizUrl, File.separator);
}
// https://xxx/{name}-{version}.jar
if (bizUrl.startsWith(HTTP_PREFIX) || bizUrl.startsWith(HTTPS_PREFIX)) {
return StringUtils.substringAfterLast(bizUrl, "/");
}
return "unknownBizName-unknownBizVersion.jar";
}
private void copyLocalDirsToResource() throws IOException {
File targetDir = new File(outputDirectory, SOFA_ARK_MODULE);
for (String dirPath : kouplelessIntegrateBizConfig.getLocalDirURLs()) {
for (File bizSourceFile : getBizFileFromLocalFileSystem(dirPath)) {
File targetFile = new File(targetDir, bizSourceFile.getName());
if (!targetFile.exists()) {
FileUtils.copyFileToDirectory(bizSourceFile, targetDir);
}
}
}
}
@SneakyThrows
public List<File> getBizFileFromLocalFileSystem(String absoluteBizDirPath) {
List<File> bizFiles = new ArrayList<>();
Files.walkFileTree(new File(absoluteBizDirPath).toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Path absolutePath = file.toAbsolutePath();
if (absolutePath.toString().endsWith(".jar")) {
Map<String, Object> attributes = JarFileUtils
.getMainAttributes(absolutePath.toString());
if (attributes.containsKey("Ark-Biz-Name")) {
getLog().info(String.format("Found biz jar file: %s", absolutePath));
bizFiles.add(file.toFile());
}
}
return FileVisitResult.CONTINUE;
}
});
return bizFiles;
}
private void initKouplelessIntegrateBizConfig() {
readFromArkPropertiesFile();
readFromArkYamlFile();
}
private void readFromArkYamlFile() {
Map<String, Object> arkYaml = ArkConfigHolder.getArkYaml(baseDir.getAbsolutePath());
kouplelessIntegrateBizConfig
.addFileURLs(ParseUtils.getStringSet(arkYaml, EXTENSION_INTEGRATE_LOCAL_URLS));
kouplelessIntegrateBizConfig
.addLocalDirURLs(ParseUtils.getStringSet(arkYaml, EXTENSION_INTEGRATE_LOCAL_DIRS));
}
private void readFromArkPropertiesFile() {
Properties arkProperties = ArkConfigHolder.getArkProperties(baseDir.getAbsolutePath());
kouplelessIntegrateBizConfig
.addFileURLs(ParseUtils.getSetValues(arkProperties, EXTENSION_INTEGRATE_LOCAL_URLS));
kouplelessIntegrateBizConfig.addLocalDirURLs(
ParseUtils.getSetValues(arkProperties, EXTENSION_INTEGRATE_LOCAL_DIRS));
}
/** {@inheritDoc} */
@Override
public void execute() {
try {
initKouplelessIntegrateBizConfig();
integrateBizToResource();
} catch (Throwable t) {
getLog().error(t);
throw new RuntimeException("Error during integration of business artifacts", t);
}
}
private void integrateBizToResource() throws IOException {
copyFilesToResource();
copyLocalDirsToResource();
}
private void copyFilesToResource() throws IOException {
File targetDir = new File(outputDirectory, SOFA_ARK_MODULE);
for (String urlStr : kouplelessIntegrateBizConfig.getFileURLs()) {
File targetFile = new File(targetDir, getFullRevision(urlStr));
if (!targetFile.exists()) {
URL url = new URL(urlStr);
try (InputStream inputStream = url.openStream()) {
FileUtils.copyInputStreamToFile(inputStream, targetFile);
}
}
}
}
private String getFullRevision(String bizUrl) {
// file:///xxx/{name}-{version}-ark-biz.jar
if (bizUrl.startsWith(FILE_PREFIX)) {
return StringUtils.substringAfterLast(bizUrl, File.separator);
}
// https://xxx/{name}-{version}.jar
if (bizUrl.startsWith(HTTP_PREFIX) || bizUrl.startsWith(HTTPS_PREFIX)) {
return StringUtils.substringAfterLast(bizUrl, "/");
}
return "unknownBizName-unknownBizVersion.jar";
}
private void copyLocalDirsToResource() throws IOException {
File targetDir = new File(outputDirectory, SOFA_ARK_MODULE);
for (String dirPath : kouplelessIntegrateBizConfig.getLocalDirURLs()) {
for (File bizSourceFile : getBizFileFromLocalFileSystem(dirPath)) {
File targetFile = new File(targetDir, bizSourceFile.getName());
if (!targetFile.exists()) {
FileUtils.copyFileToDirectory(bizSourceFile, targetDir);
}
}
}
}
@SneakyThrows
public List<File> getBizFileFromLocalFileSystem(String absoluteBizDirPath) {
List<File> bizFiles = new ArrayList<>();
Files.walkFileTree(new File(absoluteBizDirPath).toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Path absolutePath = file.toAbsolutePath();
if (absolutePath.toString().endsWith(".jar")) {
Map<String, Object> attributes = JarFileUtils
.getMainAttributes(absolutePath.toString());
if (attributes.containsKey("Ark-Biz-Name")) {
getLog().info(String.format("Found biz jar file: %s", absolutePath));
bizFiles.add(file.toFile());
}
}
return FileVisitResult.CONTINUE;
}
});
return bizFiles;
}
private void initKouplelessIntegrateBizConfig() {
readFromArkPropertiesFile();
readFromArkYamlFile();
}
private void readFromArkYamlFile() {
Map<String, Object> arkYaml = ArkConfigHolder.getArkYaml(baseDir.getAbsolutePath());
kouplelessIntegrateBizConfig
.addFileURLs(ParseUtils.getStringSet(arkYaml, EXTENSION_INTEGRATE_LOCAL_URLS));
kouplelessIntegrateBizConfig
.addLocalDirURLs(ParseUtils.getStringSet(arkYaml, EXTENSION_INTEGRATE_LOCAL_DIRS));
}
private void readFromArkPropertiesFile() {
Properties arkProperties = ArkConfigHolder.getArkProperties(baseDir.getAbsolutePath());
kouplelessIntegrateBizConfig
.addFileURLs(ParseUtils.getSetValues(arkProperties, EXTENSION_INTEGRATE_LOCAL_URLS));
kouplelessIntegrateBizConfig.addLocalDirURLs(
ParseUtils.getSetValues(arkProperties, EXTENSION_INTEGRATE_LOCAL_DIRS));
}

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between be1cd2e and a17009a.

Files ignored due to path filters (2)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/resourcesToCopy/biz2-bootstrap-0.0.1-SNAPSHOT-ark-biz.jar is excluded by !**/*.jar
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/resourcesToCopy/staticDeployDir/biz1-bootstrap-0.0.1-SNAPSHOT-ark-biz.jar is excluded by !**/*.jar
Files selected for processing (8)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojo.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/constant/Constants.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/model/KouplelessIntegrateBizConfig.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/utils/OSUtils.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojoTest.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/java/com/alipay/sofa/koupleless/utils/MockUtils.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/ark.properties (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/ark.yml (1 hunks)
Files skipped from review due to trivial changes (2)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/java/com/alipay/sofa/koupleless/utils/MockUtils.java
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/ark.properties
Files skipped from review as they are similar to previous changes (3)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojo.java
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/constant/Constants.java
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/model/KouplelessIntegrateBizConfig.java
Additional context used
yamllint
koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/ark.yml

[error] 5-5:

Additional comments not posted (2)
koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/utils/OSUtils.java (1)

31-37: Validate OS-specific file protocol handling.

The method getLocalFileProtocolPrefix correctly handles file protocol prefixes for different operating systems. However, consider adding more detailed OS checks and handling edge cases or less common OS names.

koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojoTest.java (1)

41-49: Ensure comprehensive testing for configuration initialization.

The test testInitKouplelessIntegrateBizConfig checks the size of file URLs and local directories. Consider adding assertions for the actual content of these configurations to ensure they are loaded correctly.

Comment on lines 1 to 5
integrateBizURLs:
- file:///aaa.jar
integrateLocalDirs:
- /aaa
- /bbb No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent indentation in YAML files.

The static analysis tool flagged an error related to indentation at line 5. Proper indentation is crucial for the correct parsing of YAML files.

  integrateLocalDirs:
-  - /aaa
-  - /bbb
+    - /aaa
+    - /bbb
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
integrateBizURLs:
- file:///aaa.jar
integrateLocalDirs:
- /aaa
- /bbb
integrateBizURLs:
- file:///aaa.jar
integrateLocalDirs:
- /aaa
- /bbb
Tools
yamllint

[error] 5-5:

Comment on lines 51 to 66
@Test
public void testIntegrateBizToResource() throws Exception {
KouplelessBaseIntegrateBizMojo mojo = new KouplelessBaseIntegrateBizMojo();
mojo.outputDirectory = getResourceAsFile("mockOutputDirectory");
FileUtils.cleanDirectory(mojo.outputDirectory);

String bizFileURL = OSUtils.getLocalFileProtocolPrefix() + getResourceAsFile(
"resourcesToCopy/biz2-bootstrap-0.0.1-SNAPSHOT-ark-biz.jar");
String bizDir = getResourceAsFile("resourcesToCopy/staticDeployDir").getAbsolutePath();
mojo.kouplelessIntegrateBizConfig = KouplelessIntegrateBizConfig.builder()
.fileURLs(Sets.newHashSet(bizFileURL)).localDirs(Sets.newHashSet(bizDir)).build();
mojo.integrateBizToResource();

File targetDir = new File(mojo.outputDirectory,SOFA_ARK_MODULE);
assertEquals(2, targetDir.listFiles().length);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Validate resource integration functionality.

The test testIntegrateBizToResource checks the number of files in the target directory. It's important to also verify the integrity and correctness of the files themselves, not just their count.

// Suggestion to add file content verification
assertEquals("Expected file content", FileUtils.readFileToString(new File(targetDir, "expectedFileName"), StandardCharsets.UTF_8));

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a17009a and eb41651.

Files selected for processing (4)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/constant/Constants.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojoTest.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/bootstrap.properties (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/bootstrap.yml (1 hunks)
Files skipped from review due to trivial changes (1)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/bootstrap.properties
Files skipped from review as they are similar to previous changes (2)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/constant/Constants.java
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojoTest.java
Additional context used
yamllint
koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/bootstrap.yml

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)

Additional comments not posted (4)
koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/test/resources/mockBaseDir/conf/ark/bootstrap.yml (4)

1-1: Ensure consistency in configuration keys.

The configuration key integrateBizURLs is consistent with the naming conventions used in the rest of the project.


2-2: Verify the validity of the file URL.

The file URL file:///aaa.jar is likely a placeholder. Ensure that it is replaced with a valid file path in the actual configuration.


3-3: Ensure consistency in configuration keys.

The configuration key integrateLocalDirs is consistent with the naming conventions used in the rest of the project.


4-5: Verify the validity of the directory paths.

The directory paths /aaa and /bbb are likely placeholders. Ensure that they are replaced with valid directory paths in the actual configuration.

Tools
yamllint

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)

- file:///aaa.jar
integrateLocalDirs:
- /aaa
- /bbb No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a new line character at the end of the file.

The file should end with a new line character to comply with POSIX standards.

  - /bbb
+
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- /bbb
- /bbb
Tools
yamllint

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eb41651 and 10c3b9a.

Files selected for processing (2)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojo.java (1 hunks)
  • koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/model/ArkConfigHolder.java (1 hunks)
Additional comments not posted (6)
koupleless-ext/koupleless-build-plugin/koupleless-base-build-plugin/src/main/java/com/alipay/sofa/koupleless/base/build/plugin/KouplelessBaseIntegrateBizMojo.java (6)

79-81: LGTM!

The method is well-structured and follows good practices.


84-94: LGTM!

The method is well-structured and follows good practices.


97-110: LGTM!

The method is well-structured and handles different URL protocols appropriately.


112-121: LGTM!

The method is well-structured and follows good practices.


147-150: LGTM!

The method is well-structured and follows good practices.


152-165: LGTM!

The methods are well-structured and follow good practices.

Comment on lines +45 to +47
public static Properties getArkProperties(String baseDir) {
return arkProperties == null ? initArkProperties(baseDir) : arkProperties;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using SneakyThrows and improve logging.

Using SneakyThrows is not recommended for production code. Instead, handle exceptions explicitly and use a proper logging framework.

-   @SneakyThrows
    private static Properties initArkProperties(String baseDir) {
        String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
                            + ARK_PROPERTIES_FILE;
        File configFile = new File(configPath);
        if (!configFile.exists()) {
            log.info(String.format(
                "koupleless-base-build-plugin: extension-config %s not found, will not config it",
                configPath));
            return new Properties();
        }

        log.info(String.format(
            "koupleless-base-build-plugin: find extension-config %s and will config it",
            configPath));

        Properties prop = new Properties();
        try (FileInputStream fis = new FileInputStream(configPath)) {
            prop.load(fis);
            arkProperties = prop;
            return prop;
        } catch (IOException ex) {
            log.error(String.format(
                "koupleless-base-build-plugin: failed to read extension-config from %s.",
                configPath), ex);
            throw new RuntimeException("Failed to read extension-config", ex);
        }
    }

Committable suggestion was skipped due to low confidence.

Comment on lines +49 to +51
public static Map<String, Object> getArkYaml(String baseDir) {
return arkYaml == null ? initArkYaml(baseDir) : arkYaml;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using SneakyThrows and improve logging.

Using SneakyThrows is not recommended for production code. Instead, handle exceptions explicitly and use a proper logging framework.

-   @SneakyThrows
    private static Map<String, Object> initArkYaml(String baseDir) {
        String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
                            + ARK_YML_FILE;
        File configFile = new File(configPath);
        if (!configFile.exists()) {
            log.info(String.format(
                "koupleless-base-build-plugin: extension-config %s not found, will not config it",
                configPath));
            return newHashMap();
        }

        log.info(String.format(
            "koupleless-base-build-plugin: find extension-config %s and will config it",
            configPath));

        try (FileInputStream fis = new FileInputStream(configPath)) {
            Yaml yaml = new Yaml();
            arkYaml = yaml.load(fis);
            return arkYaml;
        } catch (IOException ex) {
            log.error(String.format("failed to parse excludes artifacts from %s.", configPath), ex);
            throw new RuntimeException("Failed to parse excludes artifacts", ex);
        }
    }

Committable suggestion was skipped due to low confidence.

Comment on lines +53 to +77
@SneakyThrows
private static Map<String, Object> initArkYaml(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_YML_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
log.info(String.format(
"koupleless-base-build-plugin: extension-config %s not found, will not config it",
configPath));
return newHashMap();
}

log.info(String.format(
"koupleless-base-build-plugin: find extension-config %s and will config it",
configPath));

try (FileInputStream fis = new FileInputStream(configPath)) {
Yaml yaml = new Yaml();
arkYaml = yaml.load(fis);
return arkYaml;
} catch (IOException ex) {
log.error(String.format("failed to parse excludes artifacts from %s.", configPath), ex);
throw ex;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve exception handling and logging.

Explicitly handle exceptions and use a proper logging framework.

-   @SneakyThrows
    private static Map<String, Object> initArkYaml(String baseDir) {
        String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
                            + ARK_YML_FILE;
        File configFile = new File(configPath);
        if (!configFile.exists()) {
            log.info(String.format(
                "koupleless-base-build-plugin: extension-config %s not found, will not config it",
                configPath));
            return newHashMap();
        }

        log.info(String.format(
            "koupleless-base-build-plugin: find extension-config %s and will config it",
            configPath));

        try (FileInputStream fis = new FileInputStream(configPath)) {
            Yaml yaml = new Yaml();
            arkYaml = yaml.load(fis);
            return arkYaml;
        } catch (IOException ex) {
            log.error(String.format("failed to parse excludes artifacts from %s.", configPath), ex);
            throw new RuntimeException("Failed to parse excludes artifacts", ex);
        }
    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@SneakyThrows
private static Map<String, Object> initArkYaml(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_YML_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
log.info(String.format(
"koupleless-base-build-plugin: extension-config %s not found, will not config it",
configPath));
return newHashMap();
}
log.info(String.format(
"koupleless-base-build-plugin: find extension-config %s and will config it",
configPath));
try (FileInputStream fis = new FileInputStream(configPath)) {
Yaml yaml = new Yaml();
arkYaml = yaml.load(fis);
return arkYaml;
} catch (IOException ex) {
log.error(String.format("failed to parse excludes artifacts from %s.", configPath), ex);
throw ex;
}
}
private static Map<String, Object> initArkYaml(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_YML_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
log.info(String.format(
"koupleless-base-build-plugin: extension-config %s not found, will not config it",
configPath));
return newHashMap();
}
log.info(String.format(
"koupleless-base-build-plugin: find extension-config %s and will config it",
configPath));
try (FileInputStream fis = new FileInputStream(configPath)) {
Yaml yaml = new Yaml();
arkYaml = yaml.load(fis);
return arkYaml;
} catch (IOException ex) {
log.error(String.format("failed to parse excludes artifacts from %s.", configPath), ex);
throw new RuntimeException("Failed to parse excludes artifacts", ex);
}
}

Comment on lines +79 to +106
@SneakyThrows
private static Properties initArkProperties(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_PROPERTIES_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
log.info(String.format(
"koupleless-base-build-plugin: extension-config %s not found, will not config it",
configPath));
return new Properties();
}

log.info(String.format(
"koupleless-base-build-plugin: find extension-config %s and will config it",
configPath));

Properties prop = new Properties();
try (FileInputStream fis = new FileInputStream(configPath)) {
prop.load(fis);
arkProperties = prop;
return prop;
} catch (IOException ex) {
log.error(String.format(
"koupleless-base-build-plugin: failed to read extension-config from %s.",
configPath), ex);
throw ex;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve exception handling and logging.

Explicitly handle exceptions and use a proper logging framework.

-   @SneakyThrows
    private static Properties initArkProperties(String baseDir) {
        String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
                            + ARK_PROPERTIES_FILE;
        File configFile = new File(configPath);
        if (!configFile.exists()) {
            log.info(String.format(
                "koupleless-base-build-plugin: extension-config %s not found, will not config it",
                configPath));
            return new Properties();
        }

        log.info(String.format(
            "koupleless-base-build-plugin: find extension-config %s and will config it",
            configPath));

        Properties prop = new Properties();
        try (FileInputStream fis = new FileInputStream(configPath)) {
            prop.load(fis);
            arkProperties = prop;
            return prop;
        } catch (IOException ex) {
            log.error(String.format(
                "koupleless-base-build-plugin: failed to read extension-config from %s.",
                configPath), ex);
            throw new RuntimeException("Failed to read extension-config", ex);
        }
    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@SneakyThrows
private static Properties initArkProperties(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_PROPERTIES_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
log.info(String.format(
"koupleless-base-build-plugin: extension-config %s not found, will not config it",
configPath));
return new Properties();
}
log.info(String.format(
"koupleless-base-build-plugin: find extension-config %s and will config it",
configPath));
Properties prop = new Properties();
try (FileInputStream fis = new FileInputStream(configPath)) {
prop.load(fis);
arkProperties = prop;
return prop;
} catch (IOException ex) {
log.error(String.format(
"koupleless-base-build-plugin: failed to read extension-config from %s.",
configPath), ex);
throw ex;
}
}
private static Properties initArkProperties(String baseDir) {
String configPath = baseDir + File.separator + ARK_CONF_BASE_DIR + File.separator
+ ARK_PROPERTIES_FILE;
File configFile = new File(configPath);
if (!configFile.exists()) {
log.info(String.format(
"koupleless-base-build-plugin: extension-config %s not found, will not config it",
configPath));
return new Properties();
}
log.info(String.format(
"koupleless-base-build-plugin: find extension-config %s and will config it",
configPath));
Properties prop = new Properties();
try (FileInputStream fis = new FileInputStream(configPath)) {
prop.load(fis);
arkProperties = prop;
return prop;
} catch (IOException ex) {
log.error(String.format(
"koupleless-base-build-plugin: failed to read extension-config from %s.",
configPath), ex);
throw new RuntimeException("Failed to read extension-config", ex);
}
}

Comment on lines +125 to +145
public List<File> getBizFileFromLocalFileSystem(String absoluteBizDirPath) {
List<File> bizFiles = new ArrayList<>();
Files.walkFileTree(new File(absoluteBizDirPath).toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Path absolutePath = file.toAbsolutePath();
if (absolutePath.toString().endsWith(".jar")) {
Map<String, Object> attributes = JarFileUtils
.getMainAttributes(absolutePath.toString());
if (attributes.containsKey("Ark-Biz-Name")) {
getLog().info(String.format("Found biz jar file: %s", absolutePath));
bizFiles.add(file.toFile());
}
}

return FileVisitResult.CONTINUE;
}
});

return bizFiles;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve exception handling and logging.

Explicitly handle exceptions and use a proper logging framework.

-   @SneakyThrows
    public List<File> getBizFileFromLocalFileSystem(String absoluteBizDirPath) {
        List<File> bizFiles = new ArrayList<>();
        Files.walkFileTree(new File(absoluteBizDirPath).toPath(), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                Path absolutePath = file.toAbsolutePath();
                if (absolutePath.toString().endsWith(".jar")) {
                    Map<String, Object> attributes = JarFileUtils
                        .getMainAttributes(absolutePath.toString());
                    if (attributes.containsKey("Ark-Biz-Name")) {
                        getLog().info(String.format("Found biz jar file: %s", absolutePath));
                        bizFiles.add(file.toFile());
                    }
                }

                return FileVisitResult.CONTINUE;
            }
        });

        return bizFiles;
    }

Committable suggestion was skipped due to low confidence.

Comment on lines +69 to +75
public void execute() {
try {
initKouplelessIntegrateBizConfig();
integrateBizToResource();
} catch (Throwable t) {
getLog().error(t);
throw new RuntimeException(t);
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve exception handling.

Provide more context when rethrowing exceptions.

-   throw new RuntimeException(t);
+   throw new RuntimeException("Error during integration of business artifacts", t);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void execute() {
try {
initKouplelessIntegrateBizConfig();
integrateBizToResource();
} catch (Throwable t) {
getLog().error(t);
throw new RuntimeException(t);
public void execute() {
try {
initKouplelessIntegrateBizConfig();
integrateBizToResource();
} catch (Throwable t) {
getLog().error(t);
throw new RuntimeException("Error during integration of business artifacts", t);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

基于远程配置的合并部署能力

2 participants