Skip to content

Commit

Permalink
ROO-2745: Post 1.2.0.M1 code refactor and clean up - use StringUtils.…
Browse files Browse the repository at this point in the history
…LINE_SEPARATOR where possible
  • Loading branch information
Alan Stewart committed Oct 4, 2011
1 parent 47c3ccf commit c5fb567
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.springframework.roo.classpath;

import static org.springframework.roo.support.util.StringUtils.LINE_SEPARATOR;

import java.util.Set;

import org.apache.felix.scr.annotations.Component;
Expand Down Expand Up @@ -40,7 +42,7 @@ public void metadataTrace(@CliOption(key={"","level"}, mandatory=true, help="The
public String metadataTimings() {
StringBuilder sb = new StringBuilder();
for (MetadataTimingStatistic stat : metadataLogger.getTimings()) {
sb.append(stat.toString()).append(System.getProperty("line.separator"));
sb.append(stat.toString()).append(LINE_SEPARATOR);
}
sb.append(metadataService.toString());
return sb.toString();
Expand All @@ -49,40 +51,40 @@ public String metadataTimings() {
@CliCommand(value = "metadata for id", help = "Shows detailed information about the metadata item")
public String metadataForId(@CliOption(key = { "", "metadataId" }, mandatory = true, help = "The metadata ID (should start with MID:)") String metadataId) {
StringBuilder sb = new StringBuilder();
sb.append("Identifier : ").append(metadataId).append(System.getProperty("line.separator"));
sb.append("Identifier : ").append(metadataId).append(LINE_SEPARATOR);

Set<String> upstream = metadataDependencyRegistry.getUpstream(metadataId);
if (upstream.isEmpty()) {
sb.append("Upstream : ").append(System.getProperty("line.separator"));
sb.append("Upstream : ").append(LINE_SEPARATOR);
}

for (String s : upstream) {
sb.append("Upstream : ").append(s).append(System.getProperty("line.separator"));
sb.append("Upstream : ").append(s).append(LINE_SEPARATOR);
}

// Include any "class level" notifications that this instance would receive (useful for debugging)
// Only necessary if the ID doesn't already represent a class (as such dependencies would have been listed earlier)
if (!MetadataIdentificationUtils.isIdentifyingClass(metadataId)) {
String asClass = MetadataIdentificationUtils.create(MetadataIdentificationUtils.getMetadataClass(metadataId));
for (String s : metadataDependencyRegistry.getUpstream(asClass)) {
sb.append("Upstream : ").append(s).append(" (via class)").append(System.getProperty("line.separator"));
sb.append("Upstream : ").append(s).append(" (via class)").append(LINE_SEPARATOR);
}
}

Set<String> downstream = metadataDependencyRegistry.getDownstream(metadataId);
if (downstream.isEmpty()) {
sb.append("Downstream : ").append(System.getProperty("line.separator"));
sb.append("Downstream : ").append(LINE_SEPARATOR);
}
for (String s : downstream) {
sb.append("Downstream : ").append(s).append(System.getProperty("line.separator"));
sb.append("Downstream : ").append(s).append(LINE_SEPARATOR);
}

// Include any "class level" notifications that this instance would receive (useful for debugging)
// Only necessary if the ID doesn't already represent a class (as such dependencies would have been listed earlier)
if (!MetadataIdentificationUtils.isIdentifyingClass(metadataId)) {
String asClass = MetadataIdentificationUtils.create(MetadataIdentificationUtils.getMetadataClass(metadataId));
for (String s : metadataDependencyRegistry.getDownstream(asClass)) {
sb.append("Downstream : ").append(s).append(" (via class)").append(System.getProperty("line.separator"));
sb.append("Downstream : ").append(s).append(" (via class)").append(LINE_SEPARATOR);
}
}

Expand All @@ -99,14 +101,14 @@ public String metadataForType(@CliOption(key={"", "type"}, mandatory=true, help=
return "Cannot locate source for " + javaType.getFullyQualifiedTypeName();
}
StringBuilder sb = new StringBuilder();
sb.append("Java Type : ").append(javaType.getFullyQualifiedTypeName()).append(System.getProperty("line.separator"));
sb.append("Java Type : ").append(javaType.getFullyQualifiedTypeName()).append(LINE_SEPARATOR);
PhysicalTypeMetadata ptm = (PhysicalTypeMetadata) metadataService.get(PhysicalTypeIdentifier.createIdentifier(javaType, Path.SRC_MAIN_JAVA));
if (ptm == null || ptm.getMemberHoldingTypeDetails() == null || !(ptm.getMemberHoldingTypeDetails() instanceof ClassOrInterfaceTypeDetails)) {
sb.append("Java type details unavailable").append(System.getProperty("line.separator"));
sb.append("Java type details unavailable").append(LINE_SEPARATOR);
} else {
ClassOrInterfaceTypeDetails cid = (ClassOrInterfaceTypeDetails) ptm.getMemberHoldingTypeDetails();
for (MemberHoldingTypeDetails holder : memberDetailsScanner.getMemberDetails(getClass().getName(), cid).getDetails()) {
sb.append("Member scan: ").append(holder.getDeclaredByMetadataId()).append(System.getProperty("line.separator"));
sb.append("Member scan: ").append(holder.getDeclaredByMetadataId()).append(LINE_SEPARATOR);
}
}
sb.append(metadataForId(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ private JavaSymbolName getUserDefinedMethod(List<MemberHoldingTypeDetails> membe
private ClassOrInterfaceTypeDetails getMostConcreteClassOrInterfaceTypeDetails(List<MemberHoldingTypeDetails> memberHoldingTypeDetailsList) {
ClassOrInterfaceTypeDetails classOrInterfaceTypeDetails = null;
// The last ClassOrInterfaceTypeDetails is the most concrete as dictated by the logic in MemberDetailsScannerImpl
for (MemberHoldingTypeDetails aMemberHoldingTypeDetailsList : memberHoldingTypeDetailsList) {
if (aMemberHoldingTypeDetailsList instanceof ClassOrInterfaceTypeDetails) {
classOrInterfaceTypeDetails = (ClassOrInterfaceTypeDetails) aMemberHoldingTypeDetailsList;
for (MemberHoldingTypeDetails memberHoldingTypeDetails : memberHoldingTypeDetailsList) {
if (memberHoldingTypeDetails instanceof ClassOrInterfaceTypeDetails) {
classOrInterfaceTypeDetails = (ClassOrInterfaceTypeDetails) memberHoldingTypeDetails;
}
}
Assert.notNull(classOrInterfaceTypeDetails, "No concrete type found; cannot continue");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public InvocableMemberBodyBuilder newLine(boolean indentBefore) {
}
// We use \n for consistency with JavaParser's DumpVisitor, which always uses \n
stringBuilder.append("\n");
// stringBuilder.append(System.getProperty("line.separator"));
// stringBuilder.append(StringUtils.LINE_SEPARATOR);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ private ItdSourceFileComposer newLine(final boolean indent) {
if (indent) appendIndent();
// We use \n for consistency with JavaParser's DumpVisitor, which always uses \n
pw.append(getNewLine());
// pw.append(System.getProperty("line.separator"));
// pw.append(StringUtils.LINE_SEPARATOR);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.roo.project.PathResolver;
import org.springframework.roo.project.ProjectOperations;
import org.springframework.roo.shell.AbstractShell;
import org.springframework.roo.support.util.StringUtils;

/**
* Base implementation of {@link HintOperations}.
Expand Down Expand Up @@ -45,7 +46,7 @@ public String hint(String topic) {
}
try {
String message = bundle.getString(topic);
return message.replace("\r", System.getProperty("line.separator")).replace("${completion_key}", AbstractShell.completionKeys);
return message.replace("\r", StringUtils.LINE_SEPARATOR).replace("${completion_key}", AbstractShell.completionKeys);
} catch (MissingResourceException exception) {
return "Cannot find topic '" + topic + "'";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.roo.shell.Shell;
import org.springframework.roo.shell.osgi.AbstractFlashingObject;
import org.springframework.roo.support.logging.HandlerUtils;
import org.springframework.roo.support.util.StringUtils;

/**
* Delegates OSGi log messages to the JDK logging infrastructure. This in turn makes it compatible
Expand Down Expand Up @@ -97,13 +98,12 @@ private void logNow(LogEntry entry, boolean removeDoNotLogTag) {

public static String cleanThrowable(Throwable throwable) {
final StringBuilder result = new StringBuilder();
final String NEW_LINE = System.getProperty("line.separator");
result.append(NEW_LINE);
result.append(StringUtils.LINE_SEPARATOR);
result.append(throwable.toString().replace(DO_NOT_LOG, ""));
result.append(NEW_LINE);
result.append(StringUtils.LINE_SEPARATOR);
for (StackTraceElement ste : throwable.getStackTrace()) {
result.append(ste);
result.append(NEW_LINE);
result.append(StringUtils.LINE_SEPARATOR);
}
return result.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CliOption;
import org.springframework.roo.shell.CommandMarker;
import org.springframework.roo.support.util.StringUtils;

/**
* Enables a user to manage the Roo PGP keystore.
Expand Down Expand Up @@ -189,6 +190,6 @@ private static String getAlgorithm(int algId) {
}

private void appendLine(StringBuilder sb, String line) {
sb.append(line).append(System.getProperty("line.separator"));
sb.append(line).append(StringUtils.LINE_SEPARATOR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
@Component(immediate = true)
@Service
public class JLineShellComponent extends JLineShell {

// Constants
private static final String LINE_SEPARATOR = System.getProperty("line.separator");


// Fields
@Reference private ExecutionStrategy executionStrategy;
@Reference private Parser parser;
Expand Down Expand Up @@ -101,7 +98,7 @@ private String getLatestFavouriteTweet() {
String screenName = (String) ((JSONObject) jsonObject.get("user")).get("screen_name");
String tweet = (String) jsonObject.get("text");
// We only want one line
tweet = tweet.replaceAll(LINE_SEPARATOR, " ");
tweet = tweet.replaceAll(StringUtils.LINE_SEPARATOR, " ");
List<String> words = Arrays.asList(tweet.split(" "));
StringBuilder sb = new StringBuilder();
// Add in Roo's twitter account to give context to the notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.roo.support.util.Assert;
import org.springframework.roo.support.util.IOUtils;
import org.springframework.roo.support.util.OsUtils;
import org.springframework.roo.support.util.StringUtils;

/**
* JDK logging {@link Handler} that emits log messages to a JLine {@link ConsoleReader}.
Expand Down Expand Up @@ -48,7 +49,7 @@ public JLineLogHandler(ConsoleReader reader, ShellPromptAccessor shellPromptAcce
public String format(LogRecord record) {
StringBuffer sb = new StringBuffer();
if (record.getMessage() != null) {
sb.append(record.getMessage()).append(System.getProperty("line.separator"));
sb.append(record.getMessage()).append(StringUtils.LINE_SEPARATOR);
}
if (record.getThrown() != null) {
PrintWriter pw = null;
Expand Down Expand Up @@ -155,7 +156,7 @@ private String toDisplay(LogRecord event) {
lineSeparatorAndIndentingString.append(" ");
}

eventString = " " + getFormatter().format(event).replace(System.getProperty("line.separator"), System.getProperty("line.separator") + lineSeparatorAndIndentingString.toString());
eventString = " " + getFormatter().format(event).replace(StringUtils.LINE_SEPARATOR, StringUtils.LINE_SEPARATOR + lineSeparatorAndIndentingString.toString());

if (eventString.endsWith(lineSeparatorAndIndentingString.toString())) {
eventString = eventString.substring(0, eventString.length() - lineSeparatorAndIndentingString.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void run() {
// Try to build previous command history from the project's log
try {
String logFileContents = FileCopyUtils.copyToString(new File("log.roo"));
String[] logEntries = logFileContents.split(System.getProperty("line.separator"));
String[] logEntries = logFileContents.split(StringUtils.LINE_SEPARATOR);
// LIFO
for (String logEntry : logEntries) {
if (!logEntry.startsWith("//")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.springframework.roo.shell;

import static org.springframework.roo.support.util.StringUtils.LINE_SEPARATOR;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -308,8 +310,7 @@ public String props() {
data.add(entry.getKey() + " = " + entry.getValue());
}

final String lineSeparator = System.getProperty("line.separator");
return StringUtils.collectionToDelimitedString(data, lineSeparator) + lineSeparator;
return StringUtils.collectionToDelimitedString(data, LINE_SEPARATOR) + LINE_SEPARATOR;
}

@CliCommand(value = { "date" }, help = "Displays the local date and time")
Expand Down Expand Up @@ -347,36 +348,36 @@ public String version(@CliOption(key="", help="Special version flags") String ex
StringBuilder sb = new StringBuilder();

if ("jaime".equals(extra)) {
sb.append(" /\\ /l").append(System.getProperty("line.separator"));
sb.append(" ((.Y(!").append(System.getProperty("line.separator"));
sb.append(" \\ |/").append(System.getProperty("line.separator"));
sb.append(" / 6~6,").append(System.getProperty("line.separator"));
sb.append(" \\ _ +-.").append(System.getProperty("line.separator"));
sb.append(" \\`-=--^-' \\").append(System.getProperty("line.separator"));
sb.append(" \\ \\ |\\--------------------------+").append(System.getProperty("line.separator"));
sb.append(" _/ \\ | Thanks for loading Roo! |").append(System.getProperty("line.separator"));
sb.append(" ( . Y +---------------------------+").append(System.getProperty("line.separator"));
sb.append(" /\"\\ `---^--v---.").append(System.getProperty("line.separator"));
sb.append(" / _ `---\"T~~\\/~\\/").append(System.getProperty("line.separator"));
sb.append(" / \" ~\\. !").append(System.getProperty("line.separator"));
sb.append(" _ Y Y.~~~ /'").append(System.getProperty("line.separator"));
sb.append(" Y^| | | Roo 7").append(System.getProperty("line.separator"));
sb.append(" | l | / . /'").append(System.getProperty("line.separator"));
sb.append(" | `L | Y .^/ ~T").append(System.getProperty("line.separator"));
sb.append(" | l ! | |/ | | ____ ____ ____").append(System.getProperty("line.separator"));
sb.append(" | .`\\/' | Y | ! / __ \\/ __ \\/ __ \\").append(System.getProperty("line.separator"));
sb.append(" l \"~ j l j L______ / /_/ / / / / / / /").append(System.getProperty("line.separator"));
sb.append(" \\,____{ __\"\" ~ __ ,\\_,\\_ / _, _/ /_/ / /_/ /").append(System.getProperty("line.separator"));
sb.append(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~ /_/ |_|\\____/\\____/").append(" ").append(versionInfo()).append(System.getProperty("line.separator"));
sb.append(" /\\ /l").append(LINE_SEPARATOR);
sb.append(" ((.Y(!").append(LINE_SEPARATOR);
sb.append(" \\ |/").append(LINE_SEPARATOR);
sb.append(" / 6~6,").append(LINE_SEPARATOR);
sb.append(" \\ _ +-.").append(LINE_SEPARATOR);
sb.append(" \\`-=--^-' \\").append(LINE_SEPARATOR);
sb.append(" \\ \\ |\\--------------------------+").append(LINE_SEPARATOR);
sb.append(" _/ \\ | Thanks for loading Roo! |").append(LINE_SEPARATOR);
sb.append(" ( . Y +---------------------------+").append(LINE_SEPARATOR);
sb.append(" /\"\\ `---^--v---.").append(LINE_SEPARATOR);
sb.append(" / _ `---\"T~~\\/~\\/").append(LINE_SEPARATOR);
sb.append(" / \" ~\\. !").append(LINE_SEPARATOR);
sb.append(" _ Y Y.~~~ /'").append(LINE_SEPARATOR);
sb.append(" Y^| | | Roo 7").append(LINE_SEPARATOR);
sb.append(" | l | / . /'").append(LINE_SEPARATOR);
sb.append(" | `L | Y .^/ ~T").append(LINE_SEPARATOR);
sb.append(" | l ! | |/ | | ____ ____ ____").append(LINE_SEPARATOR);
sb.append(" | .`\\/' | Y | ! / __ \\/ __ \\/ __ \\").append(LINE_SEPARATOR);
sb.append(" l \"~ j l j L______ / /_/ / / / / / / /").append(LINE_SEPARATOR);
sb.append(" \\,____{ __\"\" ~ __ ,\\_,\\_ / _, _/ /_/ / /_/ /").append(LINE_SEPARATOR);
sb.append(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~ /_/ |_|\\____/\\____/").append(" ").append(versionInfo()).append(LINE_SEPARATOR);
return sb.toString();
}

sb.append(" ____ ____ ____ ").append(System.getProperty("line.separator"));
sb.append(" / __ \\/ __ \\/ __ \\ ").append(System.getProperty("line.separator"));
sb.append(" / /_/ / / / / / / / ").append(System.getProperty("line.separator"));
sb.append(" / _, _/ /_/ / /_/ / ").append(System.getProperty("line.separator"));
sb.append("/_/ |_|\\____/\\____/ ").append(" ").append(versionInfo()).append(System.getProperty("line.separator"));
sb.append(System.getProperty("line.separator"));
sb.append(" ____ ____ ____ ").append(LINE_SEPARATOR);
sb.append(" / __ \\/ __ \\/ __ \\ ").append(LINE_SEPARATOR);
sb.append(" / /_/ / / / / / / / ").append(LINE_SEPARATOR);
sb.append(" / _, _/ /_/ / /_/ / ").append(LINE_SEPARATOR);
sb.append("/_/ |_|\\____/\\____/ ").append(" ").append(versionInfo()).append(LINE_SEPARATOR);
sb.append(LINE_SEPARATOR);

return sb.toString();
}
Expand Down
Loading

0 comments on commit c5fb567

Please sign in to comment.