Skip to content

Instantly share code, notes, and snippets.

@gnodet
Created March 22, 2024 15:42
Show Gist options
  • Save gnodet/a2e8131df2448d7c27adcc2ad37674d1 to your computer and use it in GitHub Desktop.
Save gnodet/a2e8131df2448d7c27adcc2ad37674d1 to your computer and use it in GitHub Desktop.
Using records in the maven 4 api
// =================== DO NOT EDIT THIS FILE ====================
// Generated by Modello Velocity from model.vm
// template, any modifications will be overwritten.
// ==============================================================
package org.apache.maven.api.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Generated;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.NotThreadSafe;
import org.apache.maven.api.annotations.ThreadSafe;
/**
* Base class for the {@code Model} and the {@code Profile} objects.
*/
@Experimental
@Generated @ThreadSafe @Immutable
public interface ModelBase
extends Serializable, InputLocationTracker
{
/**
* The modules (sometimes called subprojects) to build as a part of this
* project. Each module listed is a relative path to the directory containing the module.
* To be consistent with the way default urls are calculated from parent, it is recommended
* to have module names match artifact ids.
*/
List<String> modules();
/**
* Distribution information for a project that enables deployment of the site
* and artifacts to remote web servers and repositories respectively.
*/
DistributionManagement distributionManagement();
/**
* Properties that can be used throughout the POM as a substitution, and
* are used as filters in resources if enabled.
* The format is {@code <name>value</name>}.
*/
Map<String, String> properties();
/**
* Default dependency information for projects that inherit from this one. The
* dependencies in this section are not immediately resolved. Instead, when a POM derived
* from this one declares a dependency described by a matching groupId and artifactId, the
* version and other values from this section are used for that dependency if they were not
* already specified.
*/
DependencyManagement dependencyManagement();
/**
* This element describes all the dependencies associated with a project.
* These dependencies are used to construct a classpath for your
* project during the build process. They are automatically downloaded from the
* repositories defined in this project.
*
* @see <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">Dependency mechanism</a>
*/
List<Dependency> dependencies();
/**
* The lists of the remote repositories for discovering dependencies and
* extensions.
*/
List<Repository> repositories();
/**
* The lists of the remote repositories for discovering plugins for builds and
* reports.
*/
List<Repository> pluginRepositories();
/**
* This element includes the specification of report plugins to use
* to generate the reports on the Maven-generated site.
* These reports will be run when a user executes {@code mvn site}.
* All the reports will be included in the navigation bar for browsing.
*/
Reporting reporting();
/** Locations */
Map<Object, InputLocation> locations();
/**
* Creates a new builder with this object as the basis.
*
* @return a {@code Builder}
*/
@Nonnull
public default Builder with() {
return newBuilder(this);
}
/**
* Creates a new {@code ModelBase} instance using the specified modules.
*
* @param modules the new {@code Collection<String>} to use
* @return a {@code ModelBase} with the specified modules
*/
@Nonnull
public default ModelBase withModules(Collection<String> modules) {
return newBuilder(this, true).modules(modules).build();
}
/**
* Creates a new {@code ModelBase} instance using the specified distributionManagement.
*
* @param distributionManagement the new {@code DistributionManagement} to use
* @return a {@code ModelBase} with the specified distributionManagement
*/
@Nonnull
public default ModelBase withDistributionManagement(DistributionManagement distributionManagement) {
return newBuilder(this, true).distributionManagement(distributionManagement).build();
}
/**
* Creates a new {@code ModelBase} instance using the specified properties.
*
* @param properties the new {@code Map<String, String>} to use
* @return a {@code ModelBase} with the specified properties
*/
@Nonnull
public default ModelBase withProperties(Map<String, String> properties) {
return newBuilder(this, true).properties(properties).build();
}
/**
* Creates a new {@code ModelBase} instance using the specified dependencyManagement.
*
* @param dependencyManagement the new {@code DependencyManagement} to use
* @return a {@code ModelBase} with the specified dependencyManagement
*/
@Nonnull
public default ModelBase withDependencyManagement(DependencyManagement dependencyManagement) {
return newBuilder(this, true).dependencyManagement(dependencyManagement).build();
}
/**
* Creates a new {@code ModelBase} instance using the specified dependencies.
*
* @param dependencies the new {@code Collection<Dependency>} to use
* @return a {@code ModelBase} with the specified dependencies
*/
@Nonnull
public default ModelBase withDependencies(Collection<Dependency> dependencies) {
return newBuilder(this, true).dependencies(dependencies).build();
}
/**
* Creates a new {@code ModelBase} instance using the specified repositories.
*
* @param repositories the new {@code Collection<Repository>} to use
* @return a {@code ModelBase} with the specified repositories
*/
@Nonnull
public default ModelBase withRepositories(Collection<Repository> repositories) {
return newBuilder(this, true).repositories(repositories).build();
}
/**
* Creates a new {@code ModelBase} instance using the specified pluginRepositories.
*
* @param pluginRepositories the new {@code Collection<Repository>} to use
* @return a {@code ModelBase} with the specified pluginRepositories
*/
@Nonnull
public default ModelBase withPluginRepositories(Collection<Repository> pluginRepositories) {
return newBuilder(this, true).pluginRepositories(pluginRepositories).build();
}
/**
* Creates a new {@code ModelBase} instance using the specified reporting.
*
* @param reporting the new {@code Reporting} to use
* @return a {@code ModelBase} with the specified reporting
*/
@Nonnull
public default ModelBase withReporting(Reporting reporting) {
return newBuilder(this, true).reporting(reporting).build();
}
/**
* Creates a new {@code ModelBase} instance.
* Equivalent to {@code newInstance(true)}.
* @see #newInstance(boolean)
*
* @return a new {@code ModelBase}
*/
@Nonnull
public static ModelBase newInstance() {
return newInstance(true);
}
/**
* Creates a new {@code ModelBase} instance using default values or not.
* Equivalent to {@code newBuilder(withDefaults).build()}.
*
* @param withDefaults the boolean indicating whether default values should be used
* @return a new {@code ModelBase}
*/
@Nonnull
public static ModelBase newInstance(boolean withDefaults) {
return newBuilder(withDefaults).build();
}
/**
* Creates a new {@code ModelBase} builder instance.
* Equivalent to {@code newBuilder(true)}.
* @see #newBuilder(boolean)
*
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder() {
return newBuilder(true);
}
/**
* Creates a new {@code ModelBase} builder instance using default values or not.
*
* @param withDefaults the boolean indicating whether default values should be used
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder(boolean withDefaults) {
return new Builder(withDefaults);
}
/**
* Creates a new {@code ModelBase} builder instance using the specified object as a basis.
* Equivalent to {@code newBuilder(from, false)}.
*
* @param from the {@code ModelBase} instance to use as a basis
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder(ModelBase from) {
return newBuilder(from, false);
}
/**
* Creates a new {@code ModelBase} builder instance using the specified object as a basis.
*
* @param from the {@code ModelBase} instance to use as a basis
* @param forceCopy the boolean indicating if a copy should be forced
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder(ModelBase from, boolean forceCopy) {
return new Builder(from, forceCopy);
}
/**
* Builder class used to create ModelBase instances.
* @see #with()
* @see #newBuilder()
*/
@NotThreadSafe
public static class Builder
{
ModelBase base;
Collection<String> modules;
DistributionManagement distributionManagement;
Map<String, String> properties;
DependencyManagement dependencyManagement;
Collection<Dependency> dependencies;
Collection<Repository> repositories;
Collection<Repository> pluginRepositories;
Reporting reporting;
Map<Object, InputLocation> locations;
Builder(boolean withDefaults) {
if (withDefaults) {
}
}
Builder(ModelBase base, boolean forceCopy) {
if (forceCopy) {
this.modules = base.modules();
this.distributionManagement = base.distributionManagement();
this.properties = base.properties();
this.dependencyManagement = base.dependencyManagement();
this.dependencies = base.dependencies();
this.repositories = base.repositories();
this.pluginRepositories = base.pluginRepositories();
this.reporting = base.reporting();
this.locations = base.locations();
} else {
this.base = base;
}
}
@Nonnull
public Builder modules(Collection<String> modules) {
this.modules = modules;
return this;
}
@Nonnull
public Builder distributionManagement(DistributionManagement distributionManagement) {
this.distributionManagement = distributionManagement;
return this;
}
@Nonnull
public Builder properties(Map<String, String> properties) {
this.properties = properties;
return this;
}
@Nonnull
public Builder dependencyManagement(DependencyManagement dependencyManagement) {
this.dependencyManagement = dependencyManagement;
return this;
}
@Nonnull
public Builder dependencies(Collection<Dependency> dependencies) {
this.dependencies = dependencies;
return this;
}
@Nonnull
public Builder repositories(Collection<Repository> repositories) {
this.repositories = repositories;
return this;
}
@Nonnull
public Builder pluginRepositories(Collection<Repository> pluginRepositories) {
this.pluginRepositories = pluginRepositories;
return this;
}
@Nonnull
public Builder reporting(Reporting reporting) {
this.reporting = reporting;
return this;
}
@Nonnull
public Builder location(Object key, InputLocation location) {
if (location != null) {
if (!(this.locations instanceof HashMap)) {
this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
}
this.locations.put(key, location);
}
return this;
}
@Nonnull
public ModelBase build() {
if (base != null
&& (modules == null || modules == base.modules())
&& (distributionManagement == null || distributionManagement == base.distributionManagement())
&& (properties == null || properties == base.properties())
&& (dependencyManagement == null || dependencyManagement == base.dependencyManagement())
&& (dependencies == null || dependencies == base.dependencies())
&& (repositories == null || repositories == base.repositories())
&& (pluginRepositories == null || pluginRepositories == base.pluginRepositories())
&& (reporting == null || reporting == base.reporting())
) {
return base;
}
Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations() != null ? this.base.locations() : Collections.emptyMap();
Map<Object, InputLocation> locations = new HashMap<>();
locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
locations.put("modules", newlocs.containsKey("modules") ? newlocs.get("modules") : oldlocs.get("modules"));
locations.put("distributionManagement", newlocs.containsKey("distributionManagement") ? newlocs.get("distributionManagement") : oldlocs.get("distributionManagement"));
locations.put("properties", newlocs.containsKey("properties") ? newlocs.get("properties") : oldlocs.get("properties"));
locations.put("dependencyManagement", newlocs.containsKey("dependencyManagement") ? newlocs.get("dependencyManagement") : oldlocs.get("dependencyManagement"));
locations.put("dependencies", newlocs.containsKey("dependencies") ? newlocs.get("dependencies") : oldlocs.get("dependencies"));
locations.put("repositories", newlocs.containsKey("repositories") ? newlocs.get("repositories") : oldlocs.get("repositories"));
locations.put("pluginRepositories", newlocs.containsKey("pluginRepositories") ? newlocs.get("pluginRepositories") : oldlocs.get("pluginRepositories"));
locations.put("reporting", newlocs.containsKey("reporting") ? newlocs.get("reporting") : oldlocs.get("reporting"));
return new ModelBaseImpl(
ImmutableCollections.copy(modules != null ? modules : (base != null ? base.modules() : null)),
distributionManagement != null ? distributionManagement : (base != null ? base.distributionManagement() : null),
ImmutableCollections.copy(properties != null ? properties : (base != null ? base.properties() : null)),
dependencyManagement != null ? dependencyManagement : (base != null ? base.dependencyManagement() : null),
ImmutableCollections.copy(dependencies != null ? dependencies : (base != null ? base.dependencies() : null)),
ImmutableCollections.copy(repositories != null ? repositories : (base != null ? base.repositories() : null)),
ImmutableCollections.copy(pluginRepositories != null ? pluginRepositories : (base != null ? base.pluginRepositories() : null)),
reporting != null ? reporting : (base != null ? base.reporting() : null),
ImmutableCollections.copy(locations)
);
}
record ModelBaseImpl(
List<String> modules,
DistributionManagement distributionManagement,
Map<String, String> properties,
DependencyManagement dependencyManagement,
List<Dependency> dependencies,
List<Repository> repositories,
List<Repository> pluginRepositories,
Reporting reporting,
Map<Object, InputLocation> locations
) implements ModelBase {
@Override
public InputLocation getLocation(Object field) {
return locations.get(field);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment