Skip to content

Commit

Permalink
NCLSUP153 Improve logging and sort manipulation.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Oct 5, 2020
1 parent eaae43f commit e5749ce
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Response {

String getAlignedVersionOfGav(ProjectVersionRef gav) {
final Optional<ProjectRef> projectRef = matchingProjectRef(gav);

if (projectRef.isPresent()) {
return overrideMap.get(projectRef.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<ProjectVersionRef> allDeps = cache.getDependencies().values().stream()
.flatMap(m -> m.values().stream()).collect(Collectors.toSet());

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -370,6 +372,8 @@ private HashMap<RelaxedProjectVersionRef, ProjectVersionRef> 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();
Expand Down Expand Up @@ -527,13 +531,22 @@ 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<RelaxedProjectVersionRef, ProjectVersionRef> allModuleDependencies,
Response alignmentResponse) {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectRef> predicate;

Expand Down Expand Up @@ -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()));
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> projects) {

Expand All @@ -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);

Expand All @@ -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);
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +22,8 @@
*/
public class WithCustomizersDelegatingAlignmentService implements AlignmentService {

private final Logger logger = GMLogger.getLogger(getClass());

private final DAAlignmentService delegate;
private final List<AlignmentService.RequestCustomizer> requestCustomizers;
private final List<AlignmentService.ResponseCustomizer> responseCustomizers;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand All @@ -61,7 +71,7 @@ public class ManipulationModel {
* {@code 3.6.3.SP1-redhat-00001} version
*/
@JsonProperty
protected Map<String, ProjectVersionRef> alignedDependencies = new HashMap<>();
protected Map<String, ProjectVersionRef> alignedDependencies = new TreeMap<>();

/**
* Representation of this project children projects if any, keyed by name(artifactId).
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -148,22 +150,6 @@ private void addDependenciesRec(ManipulationModel manipulationModel, Map<String,
}
}

public String getVersion() {
return version;
}

public void setVersion(String newProjectVersion) {
this.version = newProjectVersion;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public Map<String, ManipulationModel> getChildren() {
return children;
}
Expand Down

0 comments on commit e5749ce

Please sign in to comment.