Skip to content
Closed
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
2 changes: 2 additions & 0 deletions rewrite-maven/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies {

implementation("org.antlr:antlr4-runtime:4.13.2")
implementation("dev.failsafe:failsafe:latest.release")
//implementation(platform("com.fasterxml.jackson:jackson-bom:2.20.1"))
implementation(platform("com.fasterxml.jackson:jackson-bom:2.17.3"))
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-smile")
implementation("com.fasterxml.jackson.module:jackson-module-jaxb-annotations")
Expand Down
125 changes: 87 additions & 38 deletions rewrite-maven/src/main/java/org/openrewrite/maven/MavenSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
Expand Down Expand Up @@ -57,31 +57,33 @@ public class MavenSettings {
@Nullable
@NonFinal
@JsonIgnore
MavenRepository mavenLocal;
private MavenRepository mavenLocal;

@Nullable
Profiles profiles;
private Profiles profiles;

@Nullable
ActiveProfiles activeProfiles;
private ActiveProfiles activeProfiles;

@Nullable
Mirrors mirrors;
private Mirrors mirrors;

@Nullable
@With
Servers servers;

@JsonCreator
public MavenSettings(@Nullable String localRepository, @Nullable Profiles profiles,
@Nullable ActiveProfiles activeProfiles, @Nullable Mirrors mirrors,
@Nullable Servers servers) {
this.localRepository = localRepository;
this.profiles = profiles;
this.activeProfiles = activeProfiles;
this.mirrors = mirrors;
this.servers = servers;
}
private Servers servers;

@JsonCreator
public MavenSettings(@JsonProperty("localRepository") @Nullable String localRepository,
@JsonProperty("profiles") @Nullable Profiles profiles,
@JsonProperty("activeProfiles") @Nullable ActiveProfiles activeProfiles,
@JsonProperty("mirrors") @Nullable Mirrors mirrors,
@JsonProperty("servers") @Nullable Servers servers) {
this.localRepository = localRepository;
this.profiles = profiles;
this.activeProfiles = activeProfiles;
this.mirrors = mirrors;
this.servers = servers;
}

public static @Nullable MavenSettings parse(Parser.Input source, ExecutionContext ctx) {
try {
Expand Down Expand Up @@ -279,10 +281,11 @@ private Mirror interpolate(Mirror mirror) {
if (configuration == null) {
return null;
}
return new ServerConfiguration(
ListUtils.map(configuration.httpHeaders, this::interpolate),
configuration.timeout
);
ServerConfiguration config = new ServerConfiguration();
config.setHttpHeaders(ListUtils.map(configuration.httpHeaders, this::interpolate));
config.setTimeout(configuration.timeout);

return config;
}

private HttpHeader interpolate(HttpHeader httpHeader) {
Expand Down Expand Up @@ -358,9 +361,18 @@ public static class Profile {
@Nullable
RawRepositories repositories;

public boolean isActive(Iterable<String> activeProfiles) {
return ProfileActivation.isActive(id, activeProfiles, activation);
}
@JsonCreator
public Profile(@JsonProperty("id") @Nullable String id,
@JsonProperty("activation") @Nullable ProfileActivation activation,
@JsonProperty("repositories") @Nullable RawRepositories repositories) {
this.id = id;
this.activation = activation;
this.repositories = repositories;
}

public boolean isActive(Iterable<String> activeProfiles) {
return ProfileActivation.isActive(id, activeProfiles, activation);
}

@SuppressWarnings("unused")
public boolean isActive(String... activeProfiles) {
Expand Down Expand Up @@ -441,27 +453,57 @@ public static class Server {
String username;
String password;

@Nullable
ServerConfiguration configuration;
}
public ServerConfiguration configuration;

@JsonCreator
public Server(@JsonProperty("id") String id,
@JsonProperty("username") String username,
@JsonProperty("password") String password,
@JsonProperty("configuration") ServerConfiguration configuration) {
this.id = id;
this.username = username;
this.password = password;
this.configuration = configuration;
}
}

@SuppressWarnings("DefaultAnnotationParam")
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@Data
@With
@JsonIgnoreProperties("httpHeaders")
public static class ServerConfiguration {
@JacksonXmlProperty(localName = "property")
@JacksonXmlElementWrapper(localName = "httpHeaders", useWrapping = true)
// wrapping is disabled by default on MavenXmlMapper
@Nullable
List<HttpHeader> httpHeaders;

private @Nullable List<HttpHeader> httpHeaders;

/**
* Timeout in milliseconds for reading connecting to and reading from the connection.
*/
@Nullable
Long timeout;
private @Nullable Long timeout;

public ServerConfiguration() {}

@JacksonXmlProperty(
localName = "property"
)
@JacksonXmlElementWrapper(
localName = "httpHeaders",
useWrapping = true
)
public @Nullable List<HttpHeader> getHttpHeaders() {
return this.httpHeaders;
}

@JacksonXmlProperty(
localName = "timeout"
)
public @Nullable Long getTimeout() {
return this.timeout;
}

public void setHttpHeaders(@Nullable List<HttpHeader> httpHeaders) {
this.httpHeaders = httpHeaders;
}

public void setTimeout(@Nullable Long timeout) {
this.timeout = timeout;
}
}

@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
Expand All @@ -470,5 +512,12 @@ public static class ServerConfiguration {
public static class HttpHeader {
String name;
String value;

@JsonCreator
public HttpHeader(@JsonProperty("name") String name,
@JsonProperty("value") String value) {
this.name = name;
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class MavenXmlMapper {
ObjectMapper m = XmlMapper.builder(xmlFactory)
.constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED)
.enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL)
.defaultUseWrapper(false)
.defaultUseWrapper(true)
.build()
.registerModule(new ParameterNamesModule())
.disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openrewrite.maven.internal;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -187,6 +188,26 @@ public static class Dependency {
@Nullable
@JacksonXmlElementWrapper
List<GroupArtifact> exclusions;

@JsonCreator
public Dependency(
@JsonProperty("groupId") String groupId,
@JsonProperty("artifactId") String artifactId,
@JsonProperty("version") @Nullable String version,
@JsonProperty("scope") @Nullable String scope,
@JsonProperty("type") @Nullable String type,
@JsonProperty("classifier") @Nullable String classifier,
@Nullable @JsonProperty("optional") String optional,
@Nullable @JsonProperty("exclusions") List<GroupArtifact> exclusions) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.scope = scope;
this.type = type;
this.classifier = classifier;
this.optional = optional;
this.exclusions = exclusions;
}
}

@Getter
Expand All @@ -198,6 +219,7 @@ public DependencyManagement() {
this.dependencies = null;
}

@JsonCreator
public DependencyManagement(@JsonProperty("dependencies") @Nullable Dependencies dependencies) {
this.dependencies = dependencies;
}
Expand All @@ -211,7 +233,8 @@ public Dependencies() {
this.dependencies = new ArrayList<>();
}

public Dependencies(@JacksonXmlProperty(localName = "dependency") List<Dependency> dependencies) {
@JsonCreator
public Dependencies(@JacksonXmlProperty(localName = "dependency") @JacksonXmlElementWrapper(useWrapping = false) List<Dependency> dependencies) {
this.dependencies = dependencies;
}
}
Expand All @@ -224,7 +247,8 @@ public Licenses() {
this.licenses = emptyList();
}

public Licenses(@JacksonXmlProperty(localName = "license") List<License> licenses) {
@JsonCreator
public Licenses(@JacksonXmlProperty(localName = "license") @JacksonXmlElementWrapper(useWrapping = false) List<License> licenses) {
this.licenses = licenses;
}
}
Expand All @@ -245,7 +269,8 @@ public Profiles() {
this.profiles = emptyList();
}

public Profiles(@JacksonXmlProperty(localName = "profile") List<Profile> profiles) {
@JsonCreator
public Profiles(@JacksonXmlProperty(localName = "profile") @JacksonXmlElementWrapper(useWrapping = false) List<Profile> profiles) {
this.profiles = profiles;
}
}
Expand All @@ -258,7 +283,8 @@ public Modules() {
this.modules = emptyList();
}

public Modules(@JacksonXmlProperty(localName = "module") List<String> modules) {
@JsonCreator
public Modules(@JacksonXmlProperty(localName = "module") @JacksonXmlElementWrapper(useWrapping = false) List<String> modules) {
this.modules = modules;
}
}
Expand All @@ -271,7 +297,8 @@ public SubProjects() {
this.subprojects = emptyList();
}

public SubProjects(@JacksonXmlProperty(localName = "subproject") List<String> subprojects) {
@JsonCreator
public SubProjects(@JacksonXmlProperty(localName = "subproject") @JacksonXmlElementWrapper(useWrapping = false) List<String> subprojects) {
this.subprojects = subprojects;
}
}
Expand Down Expand Up @@ -373,8 +400,10 @@ public License() {
this.name = "";
}

@JsonCreator
public License(@JsonProperty("name") String name) {
this.name = name;
// Handling null to avoid potential NPEs if <name/> is empty or missing
this.name = name != null ? name : "";
}
}

Expand All @@ -401,6 +430,24 @@ public static class Profile {

@Nullable
RawPluginRepositories pluginRepositories;

@JsonCreator
public Profile(
@JsonProperty("id") @Nullable String id,
@JsonProperty("activation") @Nullable ProfileActivation activation,
@JsonProperty("properties") @Nullable Map<String, String> properties,
@JsonProperty("dependencies") @Nullable Dependencies dependencies,
@JsonProperty("dependencyManagement") @Nullable DependencyManagement dependencyManagement,
@JsonProperty("repositories") @Nullable RawRepositories repositories,
@JsonProperty("pluginRepositories") @Nullable RawPluginRepositories pluginRepositories) {
this.id = id;
this.activation = activation;
this.properties = properties;
this.dependencies = dependencies;
this.dependencyManagement = dependencyManagement;
this.repositories = repositories;
this.pluginRepositories = pluginRepositories;
}
}

public @Nullable String getGroupId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.openrewrite.maven.internal;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.*;
Expand All @@ -39,6 +41,9 @@ public static class Repository {
@Nullable
String id;

@With
String name;

@With
String url;

Expand All @@ -47,6 +52,19 @@ public static class Repository {

@Nullable
ArtifactPolicy snapshots;

@JsonCreator
public Repository(@JsonProperty("id") @Nullable String id,
@JsonProperty("name") @Nullable String name,
@JsonProperty("url") String url,
@JsonProperty("releases") RawRepositories.ArtifactPolicy releases,
@JsonProperty("snapshots") RawRepositories.ArtifactPolicy snapshots) {
this.id = id;
this.name = name;
this.url = url;
this.releases = releases;
this.snapshots = snapshots;
}
}

@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
Expand Down
Loading