diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentService.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentService.java index 22cbb1e4..83ed707e 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentService.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentService.java @@ -58,6 +58,7 @@ class Response { String getAlignedVersionOfGav(ProjectVersionRef gav) { final Optional projectRef = matchingProjectRef(gav); + if (projectRef.isPresent()) { return overrideMap.get(projectRef.get()); } diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java index fcc693ef..7f205441 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java @@ -154,6 +154,7 @@ public void perform() { project, getDependencies(project, configuration, lockFileDeps)); + logger.debug("For project {} adding to the cache the dependencies {}", project, dependencies); // TODO: Trace level? cache.addDependencies(project, dependencies); project.getRepositories().forEach(r -> cache.addRepository(r, @@ -175,7 +176,8 @@ public void perform() { // when the set is empty, we know that this was the last alignment task to execute. if (cache.removeProject(project)) { - logger.info("Completed scanning {} projects; now processing for REST...", cache.getDependencies().size()); + logger.info("Completed scanning {} projects; now processing for exclusions/REST/overrides...", + cache.getDependencies().size()); Set allDeps = cache.getDependencies().values().stream() .flatMap(m -> m.values().stream()).collect(Collectors.toSet()); @@ -193,7 +195,6 @@ public void perform() { // While we've completed processing (sub)projects the current one is not going to be the root; so // explicitly retrieve it and set its version. if (configuration.versionModificationEnabled()) { - project.getRootProject().setVersion(newVersion); logger.info("Updating project {} version to {}", project.getRootProject(), newVersion); alignmentModel.setVersion(newVersion); @@ -203,7 +204,8 @@ public void perform() { projectDependencies.forEach((key, value) -> { final ManipulationModel correspondingModule = alignmentModel.findCorrespondingChild(key); if (configuration.versionModificationEnabled()) { - logger.info("Updating sub-project {} version to {} ", correspondingModule, newVersion); + logger.info("Updating sub-project {} (path: {}) version to {} ", correspondingModule, + correspondingModule.getProjectPathName(), newVersion); correspondingModule.setVersion(newVersion); } updateModuleDynamicDependencies(correspondingModule, value); @@ -370,6 +372,8 @@ private HashMap getDependencies(Pro project.getConfigurations().all(configuration -> { if (configuration.isCanBeResolved()) { + logger.debug("Examining configuration {}", configuration.getName()); + // using getAllDependencies here instead of getDependencies because the later // was returning an empty array for the root project of SpringLikeLayoutFunctionalTest final DependencySet allDependencies = configuration.getAllDependencies(); @@ -527,6 +531,13 @@ private void updateModuleDynamicDependencies(ManipulationModel correspondingModu }); } + /** + * This does the actual substitution replacing the dependencies with aligned version if it exists + * + * @param correspondingModule the module we are working on + * @param allModuleDependencies the collection of dependencies + * @param alignmentResponse the response which (possibly) contains overrides and DA information + */ private void updateModuleDependencies(ManipulationModel correspondingModule, HashMap allModuleDependencies, Response alignmentResponse) { @@ -534,6 +545,8 @@ private void updateModuleDependencies(ManipulationModel correspondingModule, allModuleDependencies.forEach((d, p) -> { final String newDependencyVersion = alignmentResponse.getAlignedVersionOfGav(p); if (!StringUtils.isEmpty(newDependencyVersion)) { + logger.debug("In module {} with GAV {} found a replacement version of {}", + correspondingModule.getProjectPathName(), p, newDependencyVersion); final ProjectVersionRef newVersion = ProjectVersionFactory.withNewVersion(p, newDependencyVersion); // we need to make sure that dynamic dependencies are stored with their original key // in order for the manipulation plugin to be able to look them up properly diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyExclusionCustomizer.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyExclusionCustomizer.java index 2c741af9..12ff7f41 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyExclusionCustomizer.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyExclusionCustomizer.java @@ -32,7 +32,7 @@ */ public class DependencyExclusionCustomizer implements AlignmentService.RequestCustomizer { - private static final Logger log = GMLogger.getLogger(DependencyExclusionCustomizer.class); + private static final Logger logger = GMLogger.getLogger(DependencyExclusionCustomizer.class); private final Predicate predicate; @@ -68,7 +68,7 @@ public static AlignmentService.RequestCustomizer fromConfigurationForModule(Conf project.getName(), project.getVersion().toString()); if (keyParseResult.matchesModule(projectRef)) { - log.debug("Excluding dependency {} from alignment of module {}", keyParseResult.getDependency(), + logger.debug("Excluding dependency {} from alignment of module {}", keyParseResult.getDependency(), projectRef); // if the key matches this module, add a predicate that rejects the artifact that was configured in the property predicates.add(new DependencyExclusionPredicate(keyParseResult.getDependency())); @@ -81,6 +81,7 @@ public static AlignmentService.RequestCustomizer fromConfigurationForModule(Conf if (!predicates.isEmpty()) { result = new DependencyExclusionCustomizer(predicates.stream().reduce(x -> true, Predicate::and)); } + // If null is returned this is filtered out in AlignmentServiceFactory::getRequestCustomizer with the filter return result; } diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyOverrideCustomizer.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyOverrideCustomizer.java index 8d41537f..edc16364 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyOverrideCustomizer.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/DependencyOverrideCustomizer.java @@ -46,6 +46,13 @@ public Response customize(Response response) { return response; } + /** + * This is created by the {@link AlignmentServiceFactory} when creating the request/response customizers. + * + * @param configuration the Configuration object + * @param projects the collection of projects + * @return An initiated ResponseCustomizer + */ public static ResponseCustomizer fromConfigurationForModule(Configuration configuration, Set projects) { @@ -55,7 +62,6 @@ public static ResponseCustomizer fromConfigurationForModule(Configuration config "dependencyOverride."); if (!prefixed.isEmpty()) { - //the idea is to create one DependencyOverrideCustomizer per configuration property for (String key : prefixed.keySet()) { final DependencyPropertyParser.Result keyParseResult = DependencyPropertyParser.parse(key); @@ -64,12 +70,11 @@ public static ResponseCustomizer fromConfigurationForModule(Configuration config if (isNotEmpty(project.getVersion().toString()) && isNotEmpty(group) && isNotEmpty(project.getName())) { - final ProjectVersionRef projectRef = new SimpleProjectVersionRef(group, project.getName(), project.getVersion().toString()); if (keyParseResult.matchesModule(projectRef)) { final String overrideVersion = prefixed.get(key); - logger.debug("Overriding dependency {} from in module {} with version {}", + logger.debug("Overriding dependency {} in module {} with version {}", keyParseResult.getDependency(), projectRef, overrideVersion); overrideMap.put(keyParseResult.getDependency(), overrideVersion); } @@ -82,6 +87,7 @@ public static ResponseCustomizer fromConfigurationForModule(Configuration config logger.debug("Returning overrideMap of {} ", overrideMap); result = new DependencyOverrideCustomizer(overrideMap); } + // If null is returned this is filtered out in AlignmentServiceFactory::geResponseCustomizer with the filter return result; } } diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/WithCustomizersDelegatingAlignmentService.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/WithCustomizersDelegatingAlignmentService.java index a89c9fa8..8e9c7a19 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/WithCustomizersDelegatingAlignmentService.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/WithCustomizersDelegatingAlignmentService.java @@ -6,6 +6,8 @@ import java.util.stream.Collectors; import org.commonjava.maven.ext.common.ManipulationException; +import org.gradle.api.logging.Logger; +import org.jboss.gm.common.logging.GMLogger; /** * An implementation of {@link org.jboss.gm.analyzer.alignment.AlignmentService} that @@ -20,6 +22,8 @@ */ public class WithCustomizersDelegatingAlignmentService implements AlignmentService { + private final Logger logger = GMLogger.getLogger(getClass()); + private final DAAlignmentService delegate; private final List requestCustomizers; private final List responseCustomizers; @@ -41,12 +45,15 @@ public WithCustomizersDelegatingAlignmentService(DAAlignmentService delegate, @Override public Response align(Request request) throws ManipulationException { + logger.debug("Invoking request customizers..."); for (RequestCustomizer requestCustomizer : requestCustomizers) { request = requestCustomizer.customize(request); } + logger.debug("Invoking DA..."); Response response = delegate.align(request); + logger.debug("Invoking response customizers..."); for (ResponseCustomizer responseCustomizer : responseCustomizers) { response = responseCustomizer.customize(response); } diff --git a/common/src/main/java/org/jboss/gm/common/model/ManipulationModel.java b/common/src/main/java/org/jboss/gm/common/model/ManipulationModel.java index c6805f8c..6cce7cb2 100644 --- a/common/src/main/java/org/jboss/gm/common/model/ManipulationModel.java +++ b/common/src/main/java/org/jboss/gm/common/model/ManipulationModel.java @@ -3,8 +3,11 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.TreeMap; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import org.apache.commons.lang.StringUtils; import org.commonjava.maven.atlas.ident.ref.ProjectVersionRef; @@ -35,24 +38,31 @@ public class ManipulationModel { protected Logger logger; @JsonProperty + @Getter + @Setter protected String group; /** * Name of the project as defined by the build system. */ @JsonProperty + @Getter + @Setter protected String name; /** * This should be effectively the same as the folder name. */ @JsonProperty + @Getter protected String projectPathName; /** * Version of the project. */ @JsonProperty + @Getter + @Setter protected String version; /** @@ -61,7 +71,7 @@ public class ManipulationModel { * {@code 3.6.3.SP1-redhat-00001} version */ @JsonProperty - protected Map alignedDependencies = new HashMap<>(); + protected Map alignedDependencies = new TreeMap<>(); /** * Representation of this project children projects if any, keyed by name(artifactId). @@ -111,14 +121,6 @@ public ManipulationModel(Project project) { this.group = group; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - @Override public String toString() { return getGroup() + ':' + getName() + ':' + getVersion(); @@ -148,22 +150,6 @@ private void addDependenciesRec(ManipulationModel manipulationModel, Map getChildren() { return children; }