Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ares: Build Tool Configurator #26

Merged
merged 9 commits into from
Oct 8, 2024
Merged

Conversation

sarpsahinalp
Copy link
Collaborator

@sarpsahinalp sarpsahinalp commented Sep 6, 2024

Checklist

General

Ares

  • I documented the Java code using JavaDoc style.

Motivation and Context

A Java class that ensures the build.gradle or pom.xml of a programming exercise is correctly configured can prevent build failures and streamline the development process. Incorrect configurations, such as missing dependencies or plugins, can lead to broken builds, wasting developer time on debugging. Automating the validation and correction of these files ensures consistency and reduces errors, especially in environments where exercises are generated or modified dynamically. This enhances the user experience, promotes best practices, and reduces manual intervention during the setup of programming exercises.

Description

New Features

  • Introduced a DependencyManager class for managing dependencies in Maven and Gradle project configurations.
  • Added integration testing capabilities for Maven configurations with the MavenConfigurationUser class.
  • Established a Gradle build configuration file to manage project dependencies and structure.
  • Created a new Maven POM file to define project metadata, dependencies, and build settings.

Bug Fixes

  • Implemented checks in the Gradle configuration to ensure forbidden package folders are not present in submissions.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Summary by CodeRabbit

  • New Features

    • Introduced the DependencyManager class for managing dependencies and plugins in Maven and Gradle configuration files.
    • Added functionality to add and remove dependencies and plugins with support for both pom.xml and build.gradle.
  • Tests

    • Added MavenConfigurationUser class for integration testing of Maven configurations, including a test method for validating POM XML path handling.

@sarpsahinalp sarpsahinalp self-assigned this Sep 6, 2024
Copy link
Contributor

coderabbitai bot commented Sep 6, 2024

Walkthrough

The changes introduce a DependencyManager class designed for managing dependencies in Maven and Gradle configuration files. This class includes methods for adding and removing dependencies, utilizing XML DOM manipulation for pom.xml files and text manipulation for build.gradle files. Additionally, a new MavenConfigurationUser class is implemented for integration testing purposes, demonstrating the use of the DependencyManager.

Changes

Files Change Summary
src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java Introduced DependencyManager class for managing dependencies in Maven and Gradle files, including methods for adding and removing dependencies.
src/test/java/de/tum/cit/ase/ares/integration/testuser/MavenConfigurationUser.java Added MavenConfigurationUser class for integration testing with a method to log the POM XML path.

Possibly related PRs

  • Add workflow to build package and run tests #8: The changes in this PR include enhancements to the build process and method access management, which may relate to the overall dependency management and integration testing introduced in the main PR's DependencyManager class.

Poem

🐰 In the garden of code, new tools do bloom,
A manager for dependencies, dispelling the gloom.
With POMs and Gradles, they dance side by side,
Adding and removing, with joy as their guide.
Hooray for the changes, let’s hop and rejoice,
For in this new structure, we all have a voice! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

Outside diff range, codebase verification and nitpick comments (1)
src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java (1)

157-164: Main Method Review: Example Usage

The main method provides an example of how to use the DependencyManager. While this is useful for demonstration, including such a method within a utility class might not adhere to best practices, especially in production code.

Consider moving this example usage to a separate class or a test suite to keep the utility class clean and focused on its responsibilities:

- public static void main(String[] args) {
-     try {
-         DependencyManager manager = new DependencyManager("/path/to/pom.xml");
-         manager.addDependency("org.example", "example-artifact", "1.0.0");
-         manager.removeDependency("org.example", "example-artifact");
-     } catch (Exception e) {
-         e.printStackTrace();
-     }
- }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 846e704 and 37fbe82.

Files selected for processing (4)
  • src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/MavenConfigurationUser.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/example/build/tools/build.gradle (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/example/build/tools/pom.xml (1 hunks)
Additional comments not posted (3)
src/test/java/de/tum/cit/ase/ares/integration/testuser/MavenConfigurationUser.java (1)

11-13: Annotations are correctly applied.

The use of @Public, @UseLocale("en"), and @StrictTimeout(5) annotations are appropriate for setting up the test environment and localization requirements.

src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/example/build/tools/build.gradle (1)

68-77: Custom task implementation is appropriate.

The task test correctly implements checks for forbidden package folders using assertions. This is a good security practice to ensure that certain directories are not included in the submission.

src/test/java/de/tum/cit/ase/ares/integration/testuser/subject/example/build/tools/pom.xml (1)

45-83: Maven enforcer plugin configuration is well-implemented.

The configuration of the maven-enforcer-plugin to ensure that no student code exists in trusted packages is an excellent security measure. This helps maintain the integrity of the codebase and prevents potential issues during the build process.

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 37fbe82 and 8afba2c.

Files selected for processing (1)
  • src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8afba2c and 95cd077.

Files selected for processing (1)
  • src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java

@sarpsahinalp
Copy link
Collaborator Author

  1. Add plugin support for gradle
  2. Improve JavaDocs
  3. Test it with an exercise

@sarpsahinalp sarpsahinalp changed the title Feature/build tool configurator Build Tool Configurator Sep 16, 2024
@sarpsahinalp sarpsahinalp changed the title Build Tool Configurator Ares: Build Tool Configurator Sep 18, 2024
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: 7

🧹 Outside diff range and nitpick comments (2)
src/test/java/de/tum/cit/ase/ares/integration/testuser/MavenConfigurationUser.java (1)

16-19: Consider increasing the timeout for integration tests.

The @StrictTimeout(5) annotation sets a 5-second timeout for the test. This might be too restrictive for integration tests, which often involve I/O operations and can take longer to execute. Consider increasing this value or removing the annotation if the test doesn't require a strict timeout.

src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java (1)

409-410: Enhance error logging to include stack trace

Currently, the error logging in the catch block only logs the exception message. To facilitate debugging, it's beneficial to log the entire stack trace.

Modify the logging statement:

- log.error(e.getMessage());
+ log.error("An error occurred while adding dependencies and plugins: ", e);

This change provides detailed information about the exception.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 93f576d and 9bc4365.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/ase/ares/api/util/DependencyManager.java (1 hunks)
  • src/test/java/de/tum/cit/ase/ares/integration/testuser/MavenConfigurationUser.java (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/test/java/de/tum/cit/ase/ares/integration/testuser/MavenConfigurationUser.java (1)

41-41: Consider changing the logging level.

As mentioned in a previous review, using log.error for logging the path is typically reserved for error conditions. Consider using log.info or log.debug unless the use of log.error is specifically intended to highlight an issue during testing.

Comment on lines +25 to +43
@PublicTest
void testGetPomXmlPath() {
try {
File copiedFile = Files.createTempFile(
"pom",
".xml"
).toFile();

FileOutputStream fos = new FileOutputStream(copiedFile);
// copy the content of the POM file to the temporary file
fos.write(Files.readAllBytes(new File(POM_XML_PATH).toPath()));

DependencyManager.addDependenciesAndPluginsForMaven(copiedFile.getAbsolutePath());

copiedFile.deleteOnExit();
} catch (Exception e) {
log.error(e.getLocalizedMessage());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance test method with assertions and proper resource management.

  1. The test method lacks assertions to verify the expected behavior after calling DependencyManager.addDependenciesAndPluginsForMaven. Consider adding assertions to check if the dependencies and plugins were correctly added to the POM file.

  2. The FileOutputStream is not properly closed, which could lead to resource leaks. Use try-with-resources to ensure proper resource management.

Here's a suggested improvement:

@PublicTest
void testGetPomXmlPath() {
    File copiedFile = null;
    try {
        copiedFile = Files.createTempFile("pom", ".xml").toFile();
        copiedFile.deleteOnExit();

        try (FileOutputStream fos = new FileOutputStream(copiedFile)) {
            fos.write(Files.readAllBytes(new File(POM_XML_PATH).toPath()));
        }

        DependencyManager.addDependenciesAndPluginsForMaven(copiedFile.getAbsolutePath());

        // Add assertions here to verify the expected changes in the POM file
        // For example:
        // String updatedPomContent = Files.readString(copiedFile.toPath());
        // assertTrue(updatedPomContent.contains("<groupId>org.example</groupId>"));
        // assertTrue(updatedPomContent.contains("<artifactId>example-dependency</artifactId>"));
    } catch (Exception e) {
        log.error("Error in testGetPomXmlPath", e);
        fail("Test failed due to exception: " + e.getMessage());
    } finally {
        if (copiedFile != null && copiedFile.exists()) {
            copiedFile.delete();
        }
    }
}

This improvement addresses the resource management issue and provides a structure for adding assertions. Remember to import necessary classes like fail from JUnit.

Comment on lines +202 to +208
if (dependenciesIndex != -1) {
lines.add(dependenciesIndex + 1, dependencyLine);
Files.write(path, lines);
} else {
throw new IOException("No dependencies block found in build.gradle");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle the absence of the dependencies block gracefully

If a build.gradle file lacks a dependencies block, the current implementation throws an IOException. To enhance usability, consider adding a new dependencies block to the file instead of throwing an exception.

Modify the code as follows:

if (dependenciesIndex != -1) {
    lines.add(dependenciesIndex + 1, dependencyLine);
} else {
    log.info("No dependencies block found. Adding a new dependencies block to build.gradle");
    lines.add("");
    lines.add("dependencies {");
    lines.add(dependencyLine);
    lines.add("}");
}
Files.write(path, lines);

This approach ensures that the dependency is added even if the dependencies block is initially absent.

Comment on lines +323 to +336
private Node getOrCreatePluginsNode(Document doc) {
NodeList pluginsList = doc.getElementsByTagName("plugins");
Node pluginsNode;

if (pluginsList.getLength() == 0) {
// Create a new <plugins> section if it doesn't exist
pluginsNode = doc.createElement("plugins");
doc.getDocumentElement().appendChild(pluginsNode);
} else {
pluginsNode = pluginsList.item(0);
}

return pluginsNode;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure the <plugins> element is correctly placed under <build> in the POM

In Maven pom.xml files, the <plugins> element should be nested within the <build> section (<project><build><plugins>). Currently, the code adds the <plugins> element directly under the <project> root, which may not be recognized properly by Maven.

Refactor the getOrCreatePluginsNode method to place <plugins> under <build>:

private Node getOrCreatePluginsNode(Document doc) {
    NodeList buildList = doc.getElementsByTagName("build");
    Node buildNode;

    if (buildList.getLength() == 0) {
        // Create a new <build> section if it doesn't exist
        buildNode = doc.createElement("build");
        doc.getDocumentElement().appendChild(buildNode);
    } else {
        buildNode = buildList.item(0);
    }

    NodeList pluginsList = ((Element) buildNode).getElementsByTagName("plugins");
    Node pluginsNode;

    if (pluginsList.getLength() == 0) {
        // Create a new <plugins> section if it doesn't exist
        pluginsNode = doc.createElement("plugins");
        buildNode.appendChild(pluginsNode);
    } else {
        pluginsNode = pluginsList.item(0);
    }

    return pluginsNode;
}

This ensures that the <plugins> element is correctly nested, adhering to Maven's structure.

Comment on lines +349 to +412
public static void addDependenciesAndPluginsForMaven(String pomPath) {
try {
DependencyManager manager = new DependencyManager(pomPath);

// Create document to build XML elements
var docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();

// 1. Create the dependencies section
Element dependencies = doc.createElement("dependencies");
Element dependency = doc.createElement("dependency");

Element groupIdDep = doc.createElement("groupId");
groupIdDep.appendChild(doc.createTextNode("org.aspectj"));
dependency.appendChild(groupIdDep);

Element artifactIdDep = doc.createElement("artifactId");
artifactIdDep.appendChild(doc.createTextNode("aspectjtools"));
dependency.appendChild(artifactIdDep);

Element versionDep = doc.createElement("version");
versionDep.appendChild(doc.createTextNode("${aspectj.version}"));
dependency.appendChild(versionDep);

dependencies.appendChild(dependency);

// 2. Create the configuration section
Element complianceLevel = doc.createElement("complianceLevel");
complianceLevel.appendChild(doc.createTextNode("21"));
Element aspectDirectory = doc.createElement("aspectDirectory");
aspectDirectory.appendChild(doc.createTextNode("src/test/java"));

// First execution
Element execution1 = doc.createElement("execution");
Element goals1 = doc.createElement("goals");
Element goalCompile = doc.createElement("goal");
goalCompile.appendChild(doc.createTextNode("compile"));
Element goalTestCompile = doc.createElement("goal");
goalTestCompile.appendChild(doc.createTextNode("test-compile"));
goals1.appendChild(goalCompile);
goals1.appendChild(goalTestCompile);
execution1.appendChild(goals1);

// Second execution
Element execution2 = doc.createElement("execution");
Element executionId = doc.createElement("id");
executionId.appendChild(doc.createTextNode("process-integration-test-classes"));
Element phase = doc.createElement("phase");
phase.appendChild(doc.createTextNode("process-test-classes"));
Element goals2 = doc.createElement("goals");
Element goalCompileAgain = doc.createElement("goal");
goalCompileAgain.appendChild(doc.createTextNode("compile"));
goals2.appendChild(goalCompileAgain);
execution2.appendChild(executionId);
execution2.appendChild(phase);
execution2.appendChild(goals2);

// Add the plugin with dependencies, configuration, and executions
manager.addPlugin("dev.aspectj", "aspectj-maven-plugin", "1.14", List.of(complianceLevel, aspectDirectory), List.of(execution1, execution2));
} catch (Exception e) {
log.error(e.getMessage());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Review the implementation of addDependenciesAndPluginsForMaven method

The addDependenciesAndPluginsForMaven method appears to construct XML elements for dependencies and configurations but does not integrate them with the DependencyManager instance or update the POM file effectively. The created Document is not utilized in a way that impacts the POM.

Consider refactoring the method to properly use the DependencyManager class:

  • Use the existing methods like addDependency and addPlugin to add dependencies and plugins.
  • Remove the unnecessary creation of a new Document unless it's required for constructing configuration elements passed to addPlugin.

Example refactoring:

public static void addDependenciesAndPluginsForMaven(String pomPath) {
    try {
        DependencyManager manager = new DependencyManager(pomPath);

        // Add dependencies using the addDependency method
        manager.addDependency("org.aspectj", "aspectjtools", "${aspectj.version}");

        // Prepare configurations and executions for the plugin
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();

        // Configurations
        Element complianceLevel = doc.createElement("complianceLevel");
        complianceLevel.appendChild(doc.createTextNode("21"));
        Element aspectDirectory = doc.createElement("aspectDirectory");
        aspectDirectory.appendChild(doc.createTextNode("src/test/java"));
        List<Element> configurations = List.of(complianceLevel, aspectDirectory);

        // Executions
        Element execution1 = doc.createElement("execution");
        // Build execution elements...
        List<Element> executions = List.of(execution1 /*, other executions */);

        // Add plugin
        manager.addPlugin("dev.aspectj", "aspectj-maven-plugin", "1.14", configurations, executions);

    } catch (Exception e) {
        log.error("An error occurred while adding dependencies and plugins: ", e);
    }
}

This refactoring:

  • Utilizes addDependency to add dependencies.
  • Prepares configurations and executions to pass to addPlugin.
  • Ensures proper error logging by including the stack trace.

Comment on lines +40 to +42
if (filePath == null || filePath.isEmpty()) {
throw new SecurityException("File path cannot be null or empty.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use IllegalArgumentException instead of SecurityException for invalid arguments

In the constructor, throwing a SecurityException when filePath is null or empty is inappropriate. The IllegalArgumentException is more suitable for indicating that a method has been passed an illegal or inappropriate argument.

Apply this diff to fix the exception type:

- throw new SecurityException("File path cannot be null or empty.");
+ throw new IllegalArgumentException("File path cannot be null or empty.");
📝 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
if (filePath == null || filePath.isEmpty()) {
throw new SecurityException("File path cannot be null or empty.");
}
if (filePath == null || filePath.isEmpty()) {
throw new IllegalArgumentException("File path cannot be null or empty.");
}

Comment on lines +58 to +61
if (filePath.trim().endsWith("pom.xml")) {
addDependencyToPom(groupId, artifactId, version);
} else if (filePath.trim().endsWith("build.gradle")) {
addDependencyToGradle(groupId, artifactId, version);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure consistent trimming of filePath across methods

In addDependency, you trim filePath before checking its ending, which is good practice to avoid issues with leading or trailing whitespace. However, in removeDependency, the trimming is missing. For consistency and to prevent potential bugs, consider trimming filePath in both methods.

Apply this diff to removeDependency:

- if (filePath.endsWith("pom.xml")) {
+ if (filePath.trim().endsWith("pom.xml")) {
    removeDependencyFromPom(groupId, artifactId);
} else if (filePath.endsWith("build.gradle")) {
+ if (filePath.trim().endsWith("build.gradle")) {
    removeDependencyFromGradle(groupId, artifactId);
}

Committable suggestion was skipped due to low confidence.

Comment on lines +196 to +200
if (lines.get(i).trim().equalsIgnoreCase("dependencies {")) {
dependenciesIndex = i;
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve robustness when detecting the dependencies block in Gradle files

The current check for the dependencies block using equalsIgnoreCase("dependencies {") may fail if there are variations in formatting, such as additional spaces, comments, or different cases. Consider using a more flexible approach to identify the dependencies block.

Apply this diff to enhance detection:

- if (lines.get(i).trim().equalsIgnoreCase("dependencies {")) {
+ if (lines.get(i).trim().startsWith("dependencies")) {
+     if (lines.get(i).contains("{")) {
+         dependenciesIndex = i;
+         break;
+     } else {
+         // Handle cases where '{' is on the next line
+         dependenciesIndex = i;
+     }
+ }

This modification checks if the line starts with dependencies and accounts for cases where the opening brace { is on the same line or the following line.

📝 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
if (lines.get(i).trim().equalsIgnoreCase("dependencies {")) {
dependenciesIndex = i;
break;
}
}
if (lines.get(i).trim().startsWith("dependencies")) {
if (lines.get(i).contains("{")) {
dependenciesIndex = i;
break;
} else {
// Handle cases where '{' is on the next line
dependenciesIndex = i;
}
}
}

Copy link
Collaborator

@MarkusPaulsen MarkusPaulsen left a comment

Choose a reason for hiding this comment

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

Code looks good to me

Copy link
Collaborator

@az108 az108 left a comment

Choose a reason for hiding this comment

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

Code LGTM 👍

@MarkusPaulsen MarkusPaulsen merged commit ddb1358 into main Oct 8, 2024
1 of 2 checks passed
@MarkusPaulsen MarkusPaulsen deleted the feature/build-tool-configurator branch October 8, 2024 20:04
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.

3 participants