Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,15 @@
@Singleton
public class BuildModelTransformer implements ModelTransformer {

public static final String NAMESPACE_PREFIX = "http://maven.apache.org/POM/";

@Override
public Model transform(ModelTransformerContext context, Model model, Path path) {
Model.Builder builder = Model.newBuilder(model);
handleModelVersion(context, model, path, builder);
handleParent(context, model, path, builder);
handleReactorDependencies(context, model, path, builder);
handleCiFriendlyVersion(context, model, path, builder);
return builder.build();
}

//
// Infer modelVersion from namespace URI
//
void handleModelVersion(ModelTransformerContext context, Model model, Path pomFile, Model.Builder builder) {
String namespace = model.getNamespaceUri();
if (model.getModelVersion() == null && namespace != null && namespace.startsWith(NAMESPACE_PREFIX)) {
builder.modelVersion(namespace.substring(NAMESPACE_PREFIX.length()));
}
}

//
// Infer parent information
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
@Singleton
public class DefaultModelBuilder implements ModelBuilder {

public static final String NAMESPACE_PREFIX = "http://maven.apache.org/POM/";
private static final String RAW = "raw";
private static final String FILE = "file";
private static final String IMPORT = "import";
Expand Down Expand Up @@ -749,6 +750,11 @@ private ModelData doReadRawModel(
}
}

String namespace = rawModel.getNamespaceUri();
if (rawModel.getModelVersion() == null && namespace != null && namespace.startsWith(NAMESPACE_PREFIX)) {
rawModel = rawModel.withModelVersion(namespace.substring(NAMESPACE_PREFIX.length()));
}

modelValidator.validateRawModel(rawModel, request, problems);

if (hasFatalErrors(problems)) {
Expand Down