Skip to content

Commit

Permalink
formatting corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeDemoulinGebit committed Mar 11, 2024
1 parent 93085a1 commit e28aee2
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 186 deletions.
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,21 @@
<artifactId>plexus-interpolation</artifactId>
<version>1.27</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.16.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
</dependency>
<!-- testing -->
<dependency>
<groupId>junit</groupId>
Expand All @@ -224,6 +238,7 @@
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
68 changes: 51 additions & 17 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,28 @@
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -38,7 +55,16 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.*;
import org.apache.maven.model.Activation;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.model.building.DefaultModelBuildingRequest;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelBuildingRequest;
Expand Down Expand Up @@ -197,17 +223,18 @@ public class FlattenMojo extends AbstractFlattenMojo {
*/
@Parameter(defaultValue = "${settings}", readonly = true, required = true)
private Settings settings;

/**
* The {@link MavenSession} used to get user properties.
*/
@Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;

/**
* The Maven Project.
*/
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

/**
* The flag to indicate if the generated flattened POM shall be set as POM file to the current project. By default
* this is only done for projects with packaging other than <code>pom</code>. You may want to also do this for
Expand All @@ -217,6 +244,7 @@ public class FlattenMojo extends AbstractFlattenMojo {
*/
@Parameter(property = "updatePomFile")
private Boolean updatePomFile;

/**
* Profiles activated by OS or JDK are valid ways to have different dependencies per environment. However, profiles
* activated by property of file are less clear. When setting this parameter to <code>true</code>, the latter
Expand All @@ -226,27 +254,31 @@ public class FlattenMojo extends AbstractFlattenMojo {
*/
@Parameter(defaultValue = "false")
private Boolean embedBuildProfileDependencies;

/**
* The {@link MojoExecution} used to get access to the raw configuration of {@link #pomElements} as empty tags are
* mapped to null.
*/
@Parameter(defaultValue = "${mojo}", readonly = true, required = true)
private MojoExecution mojoExecution;

/**
* The {@link Model} that defines how to handle additional POM elements. Please use <code>flattenMode</code> in
* preference if possible. This parameter is only for ultimate flexibility.
*/
@Parameter
@Parameter(required = false)
private FlattenDescriptor pomElements;

/**
* Dictates whether dependency exclusions stanzas should be included in the flattened POM. By default exclusions
* will be included in the flattened POM but if you wish to omit exclusions stanzas from being present then set
* this configuration property to <code>true</code>.
*
* @since 1.3.0
*/
@Parameter(defaultValue = "false")
@Parameter(defaultValue = "false", required = false)
private boolean omitExclusions;

/**
* The different possible values for flattenMode:
* <table border="1" summary="">
Expand Down Expand Up @@ -299,8 +331,9 @@ public class FlattenMojo extends AbstractFlattenMojo {
* </tbody>
* </table>
*/
@Parameter(property = "flatten.mode")
@Parameter(property = "flatten.mode", required = false)
private FlattenMode flattenMode;

/**
* The different possible values for flattenDependencyMode:
* <table border="1" summary="">
Expand All @@ -324,26 +357,25 @@ public class FlattenMojo extends AbstractFlattenMojo {
* </tbody>
* </table>
*/
@Parameter(property = "flatten.dependency.mode")
@Parameter(property = "flatten.dependency.mode", required = false)
private FlattenDependencyMode flattenDependencyMode;

/**
* The core maven model readers/writers are discarding the comments of the pom.xml.
* By setting keepCommentsInPom to true the current comments are moved to the flattened pom.xml.
* Default value is false (= not re-adding comments).
*
* @since 1.3.0
*/
@Parameter(property = "flatten.dependency.keepComments", defaultValue = "false")
@Parameter(property = "flatten.dependency.keepComments", required = false, defaultValue = "false")
private boolean keepCommentsInPom;

/**
* If {@code true} the flatten goal will be skipped.
*
* @since 1.6.0
*/
@Parameter(property = "flatten.flatten.skip", defaultValue = "false")
private boolean skipFlatten;

/**
* The default operation to use when no element handling is given. Defaults to <code>flatten</code>.
*
Expand All @@ -354,12 +386,16 @@ public class FlattenMojo extends AbstractFlattenMojo {

@Inject
private DirectDependenciesInheritanceAssembler inheritanceAssembler;

/**
* The {@link ModelInterpolator} used to resolve variables.
*/
@Inject
private ExtendedModelInterpolator extendedModelInterpolator;

/**
* The {@link ModelInterpolator} used to resolve variables.
*/
@Inject
private CiInterpolator modelCiFriendlyInterpolator;

Expand All @@ -371,7 +407,6 @@ public class FlattenMojo extends AbstractFlattenMojo {

@Inject
private RepositorySystem repositorySystem;

/**
* The constructor.
*/
Expand Down Expand Up @@ -544,7 +579,6 @@ protected void writePom(Model pom, File pomFile, String headerComment, KeepComme
* @throws MojoExecutionException if anything goes wrong.
*/
protected void writeStringToFile(String data, File file, String encoding) throws MojoExecutionException {

if (!"\n".equals(System.lineSeparator())) {
data = data.replace("\n", System.lineSeparator());
}
Expand Down Expand Up @@ -635,8 +669,7 @@ private Model createCleanPom(Model effectivePom) throws MojoExecutionException {
}
}

private Model createInterpolatedPom(
ModelBuildingRequest buildingRequest, Model originalPom, File projectDirectory) {
private Model createInterpolatedPom(ModelBuildingRequest buildingRequest, Model originalPom, File projectDirectory) {
LoggingModelProblemCollector problems = new LoggingModelProblemCollector(getLog());
if (this.flattenMode == FlattenMode.resolveCiFriendliesOnly) {
return this.modelCiFriendlyInterpolator.interpolateModel(
Expand All @@ -645,8 +678,7 @@ private Model createInterpolatedPom(
return extendedModelInterpolator.interpolateModel(originalPom, projectDirectory, buildingRequest, problems);
}

private Model createExtendedInterpolatedPom(
ModelBuildingRequest buildingRequest, Model originalPom, Model effectivePom, File projectDirectory) {
private Model createExtendedInterpolatedPom(ModelBuildingRequest buildingRequest, Model originalPom, Model effectivePom, File projectDirectory) {
LoggingModelProblemCollector problems = new LoggingModelProblemCollector(getLog());
if (this.flattenMode == FlattenMode.resolveCiFriendliesOnly) {
return this.modelCiFriendlyInterpolator.interpolateModel(
Expand Down Expand Up @@ -1073,6 +1105,8 @@ private void createFlattenedDependenciesDirect(
*
* @param projectDependencies is the effective POM {@link Model}'s current dependencies
* @param flattenedDependencies is the {@link List} where to add the collected {@link Dependency dependencies}.
* @throws DependencyCollectionException
* @throws ArtifactDescriptorException
*/
private void createFlattenedDependenciesAll(
List<Dependency> projectDependencies,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.codehaus.mojo.flatten.extendedinterpolation;

import java.io.File;

import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.interpolation.ModelInterpolator;

public interface ExtendedModelInterpolator extends ModelInterpolator {
Model interpolateModel(
Model effectiveModel,
Model model,
File projectDir,
ModelBuildingRequest config,
ModelProblemCollector problems);
}
package org.codehaus.mojo.flatten.extendedinterpolation;

import java.io.File;

import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.interpolation.ModelInterpolator;

public interface ExtendedModelInterpolator extends ModelInterpolator {
Model interpolateModel(
Model effectiveModel,
Model model,
File projectDir,
ModelBuildingRequest config,
ModelProblemCollector problems);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.codehaus.mojo.flatten.extendedinterpolation;

public class ExtendedModelInterpolatorException extends RuntimeException {
public ExtendedModelInterpolatorException(Throwable cause) {
super(cause.getMessage(), cause);
}
}
package org.codehaus.mojo.flatten.extendedinterpolation;

public class ExtendedModelInterpolatorException extends RuntimeException {
public ExtendedModelInterpolatorException(Throwable cause) {
super(cause.getMessage(), cause);
}
}
Loading

0 comments on commit e28aee2

Please sign in to comment.