Class CAppDependencyResolver


  • public class CAppDependencyResolver
    extends Object
    Utility class for resolving CApp (Carbon Application) dependencies in a Maven project.
    • Constructor Detail

      • CAppDependencyResolver

        public CAppDependencyResolver()
    • Method Detail

      • resolveDependencies

        public static void resolveDependencies​(CARMojo carMojo,
                                               org.apache.maven.project.MavenProject project,
                                               String archiveDir,
                                               List<ArtifactDependency> dependencies,
                                               List<ArtifactDependency> metaDependencies)
                                        throws Exception
        Resolves CApp (Carbon Application) dependencies for the given Maven project. Executes the Maven dependency copy, checks for fat CAR packaging, extracts dependent CApp files, copies their contents to the archive directory, handles config properties merging, and updates artifact dependencies.
        Parameters:
        carMojo - The CARMojo instance used for logging and project context.
        project - The Maven project for which dependencies are being resolved.
        archiveDir - The directory where dependencies should be extracted/copied.
        dependencies - The list of artifact dependencies to update.
        Throws:
        Exception
      • isFatCarEnabled

        public static boolean isFatCarEnabled​(org.apache.maven.project.MavenProject project)
        Checks if the fat.car.enable property is set to true in the Maven project's properties.
        Parameters:
        project - The Maven project to check for the fat.car.enable property.
        Returns:
        true if fat.car.enable is set to true, false otherwise.
      • handleConfigPropertiesFile

        public static void handleConfigPropertiesFile​(File srcDir,
                                                      File targetDir)
                                               throws IOException
        Handles the `config.properties` file by copying it from the source directory to the target directory. If the target directory already contains a `config.properties` file, the method merges the contents of the source and target files.
        Parameters:
        srcDir - The source directory containing the `config.properties` file.
        targetDir - The target directory where the `config.properties` file will be copied or merged.
        Throws:
        IOException - If an error occurs during file operations.
      • mergePropertiesFiles

        public static void mergePropertiesFiles​(File sourceFile,
                                                File targetFile)
                                         throws IOException
        Merges the contents of two properties files. The method reads the source and target files, combines their unique lines, and writes the merged content back to the target file.
        Parameters:
        sourceFile - The source properties file to merge from.
        targetFile - The target properties file to merge into.
        Throws:
        IOException
      • updateArtifactDependencies

        public static void updateArtifactDependencies​(File artifactDependencyFile,
                                                      List<ArtifactDependency> artifactDependencies,
                                                      CARMojo carMojo)
                                               throws Exception
        Updates the list of artifact dependencies by reading and parsing the specified artifact dependency file. Parses the XML file, extracts dependency information, and adds new dependencies to the provided list if they do not already exist. Logs an error if a dependency already exists or if there is an issue reading the file.
        Parameters:
        artifactDependencyFile - The XML file containing artifact dependency definitions.
        artifactDependencies - The list to update with new artifact dependencies.
        carMojo - The CARMojo instance used for logging.
        Throws:
        Exception
      • unzipFile

        public static void unzipFile​(File zipFile,
                                     File extractDir)
                              throws IOException
        Unzips the given .zip file into the specified extraction directory.
        Parameters:
        zipFile - The .zip file to be extracted.
        extractDir - The directory where the contents of the .zip file will be extracted.
        Throws:
        IOException - If an error occurs during file extraction.
      • getResolvedDependentCAppFiles

        public static ArrayList<File> getResolvedDependentCAppFiles​(File projectDir,
                                                                    File dependenciesDir,
                                                                    String artifactId,
                                                                    String version,
                                                                    CARMojo carMojo)
                                                             throws Exception
        Retrieves a list of resolved dependent CApp \(.car\) files from the dependencies directory. This method scans the dependencies directory for .car files, processes them, and collects all their dependencies recursively, avoiding cycles.
        Parameters:
        projectDir - The project directory
        dependenciesDir - The directory containing dependency .car files.
        carMojo - The CARMojo instance used for logging and project context.
        Returns:
        An ArrayList of resolved dependent CApp files.
        Throws:
        Exception
      • collectDependentCAppFiles

        public static void collectDependentCAppFiles​(File projectDir,
                                                     File dependenciesDir,
                                                     File carFile,
                                                     ArrayList<File> cAppFiles,
                                                     Set<String> visited,
                                                     CARMojo carMojo)
                                              throws Exception
        Recursively collects dependent CAPP files from the given .car file. This method reads the descriptor.xml file inside the .car file, extracts dependency information, and resolves each dependency recursively.
        Parameters:
        projectDir - The project directory where the .car file is located.
        dependenciesDir - The directory containing dependency .car files.
        carFile - The .car file to process.
        cAppFiles - The list to collect resolved CAPP files.
        visited - A set to track already processed dependencies to avoid cycles.
        carMojo - The `CARMojo` instance used for logging and project context.
        Throws:
        Exception
      • findCarFileInDependencies

        public static File findCarFileInDependencies​(File dependenciesDir,
                                                     String artifactId,
                                                     String version)
        Finds a \`.car\` file in the given dependencies directory that matches the specified groupId, artifactId, and version.
        Parameters:
        dependenciesDir - The directory containing dependency \`.car\` files.
        artifactId - The artifact ID of the dependency.
        version - The version of the dependency.
        Returns:
        The matching \`.car\` file if found, otherwise null.
      • fetchCarFileFromMavenRepo

        public static File fetchCarFileFromMavenRepo​(File projectDir,
                                                     File dependenciesDir,
                                                     String groupId,
                                                     String artifactId,
                                                     String version,
                                                     CARMojo carMojo)
                                              throws Exception
        Attempts to fetch a \`.car\` file for the specified groupId, artifactId, and version from the local Maven repository. If found, copies it to the dependencies directory and returns the copied file.
        Parameters:
        projectDir - The project directory where the Maven project is located.
        dependenciesDir - The directory where the dependency \`.car\` file should be copied.
        groupId - The group ID of the dependency.
        artifactId - The artifact ID of the dependency.
        version - The version of the dependency.
        Returns:
        The copied \`.car\` file if found and copied, otherwise null.
        Throws:
        Exception
      • getTopLevelCAppDependencies

        public static List<CAppDependency> getTopLevelCAppDependencies​(org.apache.maven.project.MavenProject project)
        Retrieves the list of top-level CApp dependencies from the given Maven project. Only dependencies of type `car` are included in the result.
        Parameters:
        project - The Maven project to extract dependencies from.
        Returns:
        A list of `CAppDependency` objects representing top-level CApp dependencies.