Skip to content

Commit

Permalink
mojohaus#384: removing dependencies to jackson and guava
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeDemoulinGebit committed Mar 12, 2024
1 parent ba1be66 commit ea2c835
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
15 changes: 0 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,6 @@
<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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* under the License.
*/

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.codehaus.plexus.util.xml.Xpp3Dom;
Expand All @@ -46,8 +46,8 @@ public FlattenDescriptor() {
this.name2handlingMap = new HashMap<>();
}

public ImmutableMap<String, ElementHandling> getName2handlingMap() {
return ImmutableMap.copyOf(name2handlingMap);
public Map<String, ElementHandling> getName2handlingMap() {
return Collections.unmodifiableMap(name2handlingMap);
}

/**
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
Expand Down Expand Up @@ -456,24 +453,35 @@ protected boolean shouldSkipGoal() {

private void logParameters() {

try {
getLog().info("Generating flattened POM of project " + this.project.getId() + " with following parameters "
+ new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this.getParameters()));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
getLog().info("Generating flattened POM of project " + this.project.getId() + " with following parameters "
+ this.asString(this.getParameters()));
}

private String asString(Map<String, Object> map) {
final StringBuilder stringBuilder = new StringBuilder("{");
int i = 0;
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (i > 0) {
stringBuilder.append(", ");
}
stringBuilder
.append(entry.getKey())
.append("='")
.append(entry.getValue())
.append("'");
i++;
}
stringBuilder.append(" }");
return stringBuilder.toString();
}

private Map<String, Object> getParameters() {

final Map<String, Object> parameters = new HashMap<>();
final List<Field> fields = new ArrayList<>(Arrays.asList(this.getClass().getDeclaredFields()));
fields.addAll(Arrays.asList(this.getClass().getSuperclass().getDeclaredFields()));

final ImmutableList.Builder<Field> fieldsBuilder = ImmutableList.builder();
Arrays.stream(this.getClass().getDeclaredFields()).forEach(fieldsBuilder::add);
Arrays.stream(this.getClass().getSuperclass().getDeclaredFields()).forEach(fieldsBuilder::add);
fieldsBuilder.build().stream()
.sorted(Comparator.comparing(Field::getName))
.forEach(field -> putValue(parameters, field));
final Map<String, Object> parameters = new HashMap<>();
fields.stream().sorted(Comparator.comparing(Field::getName)).forEach(field -> putValue(parameters, field));

return parameters;
}
Expand Down

0 comments on commit ea2c835

Please sign in to comment.