Skip to content

Commit

Permalink
First check if it is likely a valid descriptor before issue validation
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jul 29, 2023
1 parent 0adc55e commit 7e0f9db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ private Dependency createScopedDependency(ArtifactDescriptor descriptor, String
return dependency;
}

private boolean isValidMavenDescriptor(MavenDependencyDescriptor dependencyDescriptor) {
public static boolean isValidMavenDescriptor(MavenDependencyDescriptor dependencyDescriptor) {
if (dependencyDescriptor == null) {
return false;
}
//TODO we should make this configurable maybe on the tycho plugin level e.g.
// <plugin>
// <groupId>org.eclipse.tycho</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,23 +401,27 @@ public void injectDependenciesIntoMavenModel(MavenProject project, AbstractTycho
if (configuration.getP2MetadataHandling() == InjectP2MavenMetadataHandling.inject) {
descriptorMapping = resolverFactory::resolveDependencyDescriptor;
} else if (configuration.getP2MetadataHandling() == InjectP2MavenMetadataHandling.validate) {
descriptorMapping = descriptor -> {
MavenDependencyDescriptor result = resolverFactory.resolveDependencyDescriptor(descriptor);
if (result != null) {
try {
dependenciesResolver.resolveArtifact(project, context.getSession(), result.getGroupId(),
result.getArtifactId(), result.getVersion());
} catch (ArtifactResolutionException e) {
logger.warn("Mapping P2 > Maven Coordinates failed: " + e.getMessage());
}
}
return null;
};
descriptorMapping = descriptor -> resolveDescriptorWithValidation(project, logger, descriptor);
} else {
descriptorMapping = null;
}
MavenDependencyInjector.injectMavenDependencies(project, dependencyArtifacts, testDependencyArtifacts,
bundleReader, descriptorMapping, logger, repositorySystem, context.getSession().getSettings(),
buildPropertiesParser);
}

private MavenDependencyDescriptor resolveDescriptorWithValidation(MavenProject project, Logger logger,
ArtifactDescriptor descriptor) {
MavenDependencyDescriptor result = resolverFactory.resolveDependencyDescriptor(descriptor);
if (MavenDependencyInjector.isValidMavenDescriptor(result)) {
try {
dependenciesResolver.resolveArtifact(project, context.getSession(), result.getGroupId(),
result.getArtifactId(), result.getVersion());
} catch (ArtifactResolutionException e) {
logger.warn("Mapping P2 > Maven Coordinates failed: " + e.getMessage());
return null;
}
}
return result;
}
}

0 comments on commit 7e0f9db

Please sign in to comment.