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

fix: detect packages in multi-project repositories #290

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

zermelo-wisen
Copy link
Contributor

@zermelo-wisen zermelo-wisen commented Aug 24, 2024

Fixes #283.

This PR addresses the issue of failure to autodetect package names in some multi-project repositories. Specifically, the Java AppMap agent was unable to auto-detect packages in the multi-project structure of the Retrofit repository. The agent only looked for src/main/java directories, which led to an appmap.yml configuration file with no detected packages, as shown below:

# This is the AppMap configuration file.
# For full documentation of this file for Java programs, see:
# https://appmap.io/docs/reference/appmap-java.html#configuration
name: retrofit
packages: []
# appmap-java init looks for source packages in src/main/java.
# This folder was not found in your project, so no packages were auto-detected.
# You can add your source packages by replacing the line above with lines like this:
# packages:
# - path: com.mycorp.pkg
# - path: org.otherstuff.pkg

The repository is structured with multiple subprojects, each containing their own src/main/java directories:

Changes Made

  1. AppMapConfig.java: Updated AppMapConfig.java to traverse the root directory and collect packages from all relevant src/main/java directories across subprojects.

    • Introduced a method collectPackages to encapsulate the logic for collecting Java packages.
    • Modified the main initialization logic to traverse the root directory and look for src/main/java subdirectories.
    • Ensured the autodetection mechanism now works for projects with nested subprojects.
  2. agent_cli.bats: Updated the test for the CLI agent initialization to verify the detection of packages within subprojects.

    • Added assertions to check for the presence of subproject package paths in CLI output.
  3. Test Project Structure: Added a sample subproject structure to the test project for verifying the updated behavior.

@zermelo-wisen zermelo-wisen marked this pull request as ready for review August 24, 2024 23:03
@zermelo-wisen zermelo-wisen force-pushed the fix/detect-packages-in-multi-repos branch from a44ddf2 to 26a8b02 Compare August 28, 2024 06:42
@apotterri apotterri force-pushed the fix/detect-packages-in-multi-repos branch from 26a8b02 to 7ce1654 Compare August 31, 2024 10:28
@apotterri apotterri force-pushed the fix/detect-packages-in-multi-repos branch 2 times, most recently from 0ad98d1 to cd7d692 Compare September 2, 2024 10:04
These changes fix a test failure that happened in my dev environment.

They make sure to use a directory created by @tempdir, rather than just
using java.io.tmpdir (a very full/messy tmp directory was causing one of
the config tests to fail).

Also, a new .gitignore hides the intellij download created for tests in
agent/test/intellij.
@apotterri apotterri force-pushed the fix/detect-packages-in-multi-repos branch from cd7d692 to c85a803 Compare September 2, 2024 12:00
@apotterri apotterri merged commit 2c29c16 into master Sep 2, 2024
6 checks passed
@apotterri apotterri deleted the fix/detect-packages-in-multi-repos branch September 2, 2024 17:27
@appland-release
Copy link

🎉 This PR is included in version 1.27.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to autodetect package names in (some) multi-project repositories
3 participants