Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8475] In the loop scenario, StringBuilder is used instead of concatenation #2014

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ protected MavenProject getProjectWithDependencies(File pom) throws Exception {
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause instanceof ModelBuildingException) {
String message = "In: " + pom + "\n\n";
StringBuilder message = new StringBuilder("In: " + pom + "\n\n");
for (ModelProblem problem : ((ModelBuildingException) cause).getProblems()) {
message += problem + "\n";
message.append(problem).append("\n");
}
System.out.println(message);
fail(message);
fail(message.toString());
}

throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,19 @@ private Model loadPom(
if (logger.isDebugEnabled()) {
String problem = (problems.size() == 1) ? "problem" : "problems";
String problemPredicate = problem + ((problems.size() == 1) ? " was" : " were");
String message = String.format(
StringBuilder message = new StringBuilder(String.format(
"%s %s encountered while building the effective model for %s during %s\n",
problems.size(),
problemPredicate,
request.getArtifact(),
RequestTraceHelper.interpretTrace(true, request.getTrace()));
message += StringUtils.capitalizeFirstLetter(problem);
RequestTraceHelper.interpretTrace(true, request.getTrace())));
message.append(StringUtils.capitalizeFirstLetter(problem));
for (ModelProblem modelProblem : problems) {
message += String.format(
message.append(String.format(
"\n* %s @ %s",
modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null));
modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null)));
}
logger.warn(message);
logger.warn(message.toString());
} else {
logger.warn(
"{} {} encountered while building the effective model for {} during {} (use -X to see details)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void artifactResolved(RepositoryEvent event) {
String ext = missing ? ".miss" : ".dep";
Path trackingFile = null;

String indent = "";
StringBuilder indent = new StringBuilder();
ArrayList<String> trackingData = new ArrayList<>();

if (collectStepTrace == null && plugin != null) {
Expand All @@ -110,16 +110,16 @@ public void artifactResolved(RepositoryEvent event) {
}

if (event.getArtifact() != null) {
trackingData.add(indent + event.getArtifact());
indent += " ";
trackingData.add(indent.toString() + event.getArtifact());
indent.append(" ");
}
trackingData.add(indent + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion());
indent += " ";
indent.append(" ");

InputLocation location = plugin.getLocation("");
if (location != null && location.getSource() != null) {
trackingData.add(indent + location.getSource().getModelId() + " (implicit)");
indent += " ";
indent.append(" ");
}
} else if (collectStepTrace != null) {
if (collectStepTrace.getPath().get(0).getArtifact() == null) {
Expand All @@ -138,15 +138,15 @@ public void artifactResolved(RepositoryEvent event) {
if (isInScope(resolvedArtifact, nodeArtifact) || "pom".equals(resolvedArtifact.getExtension())) {
Dependency node = collectStepTrace.getNode();
trackingData.add(resolvedArtifact.toString());
indent += " ";
trackingData.add(indent + node + " (" + collectStepTrace.getContext() + ")");
indent.append(" ");
trackingData.add(indent.toString() + node + " (" + collectStepTrace.getContext() + ")");
ListIterator<DependencyNode> iter = collectStepTrace
.getPath()
.listIterator(collectStepTrace.getPath().size());
while (iter.hasPrevious()) {
DependencyNode curr = iter.previous();
indent += " ";
trackingData.add(indent + curr + " (" + collectStepTrace.getContext() + ")");
indent.append(" ");
trackingData.add(indent.toString() + curr + " (" + collectStepTrace.getContext() + ")");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
PluginVersionResolutionException {
String goal = null;
StringBuilder goal = new StringBuilder();

Plugin plugin = null;
Plugin plugin;

String[] tok = task.split(":");

Expand All @@ -160,11 +160,11 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
plugin.setGroupId(tok[0]);
plugin.setArtifactId(tok[1]);
plugin.setVersion(tok[2]);
goal = tok[3];
goal.append(tok[3]);

// This won't be valid, but it constructs something easy to read in the error message
for (int idx = 4; idx < tok.length; idx++) {
goal += ":" + tok[idx];
goal.append(":").append(tok[idx]);
}
} else if (numTokens == 3) {
// groupId:artifactId:goal or pluginPrefix:version:goal (since Maven 3.9.0)
Expand All @@ -189,7 +189,7 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
plugin = findPluginForPrefix(firstToken, session);
plugin.setVersion(tok[1]);
}
goal = tok[2];
goal.append(tok[2]);
} else {
// We have a prefix and goal
//
Expand All @@ -198,10 +198,7 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
String prefix = tok[0];

if (numTokens == 2) {
goal = tok[1];
} else {
// goal was missing - pass through to MojoNotFoundException
goal = "";
goal.append(tok[1]);
}

// This is the case where someone has executed a single goal from the command line
Expand All @@ -216,9 +213,9 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
plugin = findPluginForPrefix(prefix, session);
}

int executionIdx = goal.indexOf('@');
int executionIdx = goal.indexOf("@");
if (executionIdx > 0) {
goal = goal.substring(0, executionIdx);
goal.setLength(executionIdx);
}

injectPluginDeclarationFromProject(plugin, project);
Expand All @@ -231,7 +228,7 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
}

return pluginManager.getMojoDescriptor(
plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession());
plugin, goal.toString(), project.getRemotePluginRepositories(), session.getRepositorySession());
}

// TODO take repo mans into account as one may be aggregating prefixes of many
Expand Down
Loading