Skip to content

Commit

Permalink
Implement support for Maven's prerequisites mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Sep 11, 2024
1 parent 45f5198 commit 7b2093a
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class RawPom {
@Nullable
String description;

@Nullable
Prerequisites prerequisites;

@Nullable
String packaging;

Expand Down Expand Up @@ -192,6 +195,14 @@ public Licenses(@JacksonXmlProperty(localName = "license") List<License> license
}
}

@Getter
public static class Prerequisites {

@JacksonXmlProperty(localName = "maven")
@Nullable
public String maven;
}

@Getter
public static class Profiles {
private final List<Profile> profiles;
Expand Down Expand Up @@ -371,6 +382,7 @@ public Pom toPom(@Nullable Path inputPath, @Nullable MavenRepository repo) {
null))
.name(name)
.obsoletePomVersion(pomVersion)
.prerequisites(prerequisites == null ? null : new org.openrewrite.maven.tree.Prerequisites(prerequisites.getMaven()))
.packaging(packaging)
.properties(getProperties() == null ? emptyMap() : getProperties())
.licenses(mapLicenses(getLicenses()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public static int getModelVersion() {
@Nullable
String name;

@Nullable
Prerequisites prerequisites;

@Nullable
String packaging;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.maven.tree;

import lombok.Value;
import org.jspecify.annotations.Nullable;

/**
* Models the <a href="https://maven.apache.org/pom.html#Prerequisites">prerequisites</a> element of a POM.
*/
@Value
public class Prerequisites {

/**
* The minimum version of Maven required to build the project.
*/
@Nullable
String maven;
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ public String getPackaging() {
case "project.parent.version":
case "parent.version":
return requested.getParent() != null ? requested.getParent().getVersion() : null;
case "prerequisites.maven":
case "pom.prerequisites.maven":
case "project.prerequisites.maven":
return requested.getPrerequisites() == null ? null : requested.getPrerequisites().getMaven();
}

return System.getProperty(property);
Expand Down
Loading

0 comments on commit 7b2093a

Please sign in to comment.