MuleProjectValidator extends AbstractProjectValidator { public void validateSharedLibraries(List<SharedLibraryDependency> sharedLibraries, List<ArtifactCoordinates> projectDependencies) throws ValidationException { if (sharedLibraries != null && sharedLibraries.size() != 0) { Set<String> projectDependenciesCoordinates = projectDependencies.stream() .map(coordinate -> coordinate.getArtifactId() + ":" + coordinate.getGroupId()).collect(Collectors.toSet()); Set<String> sharedLibrariesCoordinates = sharedLibraries.stream() .map(sharedLibrary -> sharedLibrary.getArtifactId() + ":" + sharedLibrary.getGroupId()).collect(Collectors.toSet()); if (!projectDependenciesCoordinates.containsAll(sharedLibrariesCoordinates)) { sharedLibrariesCoordinates.removeAll(projectDependenciesCoordinates); throw new ValidationException("The mule application does not contain the following shared libraries: " + sharedLibrariesCoordinates.toString()); } } } MuleProjectValidator(ProjectInformation projectInformation, List<SharedLibraryDependency> sharedLibraries,
                              boolean strictCheck);  MuleProjectValidator(ProjectInformation projectInformation, List<SharedLibraryDependency> sharedLibraries,
                              ProjectRequirement requirement); static void isProjectStructureValid(String packagingType, Path projectBaseDir); void validateSharedLibraries(List<SharedLibraryDependency> sharedLibraries,
                                      List<ArtifactCoordinates> projectDependencies);  }
@Test public void validateNoSharedLibrariesInDependencies() throws MojoExecutionException, ValidationException { expectedException.expect(ValidationException.class); List<SharedLibraryDependency> sharedLibraries = new ArrayList<>(); sharedLibraries.add(buildSharedLibraryDependency(GROUP_ID, ARTIFACT_ID)); expectedException.expectMessage(VALIDATE_SHARED_LIBRARIES_MESSAGE + "[artifact-id:group-id]"); validator.validateSharedLibraries(sharedLibraries, new ArrayList<>()); }
@Test public void validateSharedLibrariesInDependencies() throws MojoExecutionException, ValidationException { SharedLibraryDependency sharedLibraryDependencyB = new SharedLibraryDependency(); sharedLibraryDependencyB.setGroupId(GROUP_ID + "-b"); sharedLibraryDependencyB.setArtifactId(ARTIFACT_ID + "-b"); List<SharedLibraryDependency> sharedLibraries = new ArrayList<>(); sharedLibraries.add(buildSharedLibraryDependency(GROUP_ID + "-a", ARTIFACT_ID + "-a")); sharedLibraries.add(buildSharedLibraryDependency(GROUP_ID + "-b", ARTIFACT_ID + "-b")); List<ArtifactCoordinates> projectDependencies = new ArrayList<>(); projectDependencies.add(buildDependency(GROUP_ID + "-a", ARTIFACT_ID + "-a")); projectDependencies.add(buildDependency(GROUP_ID + "-b", ARTIFACT_ID + "-b")); projectDependencies.add(buildDependency(GROUP_ID + "-c", ARTIFACT_ID + "-c")); validator.validateSharedLibraries(sharedLibraries, projectDependencies); }