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

[JBIDE-15200] fixed NPE & made sure we inform the user about timeout #196

Merged
merged 1 commit into from
Jul 15, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected IStatus doRun(IProgressMonitor monitor) {
} catch (OpenShiftTimeoutException e) {
this.application = refreshAndCreateApplication(monitor);
if (application != null) {
// creation went ok, but initial request timed out
return new Status(IStatus.OK, OpenShiftUIActivator.PLUGIN_ID, TIMEOUTED, "timeouted", null);
} else {
return new Status(IStatus.CANCEL, OpenShiftUIActivator.PLUGIN_ID, TIMEOUTED, "timeouted", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
Expand All @@ -49,7 +50,6 @@
public class CreationLogDialog extends TitleAreaDialog {

private static final Pattern HTTP_LINK_REGEX = Pattern.compile("(http[^ |\n]+)");
private static final Pattern ECLIPSE_LINK_REGEX = Pattern.compile("(<a>)(.+)(</a>)");

private List<Link> links;
private LogEntry[] logEntries;
Expand Down Expand Up @@ -151,12 +151,9 @@ private void createTextAndStyle(LogEntry logEntry, StringBuilder builder, List<S
private void appendLog(LogEntry logEntry, StringBuilder builder, List<StyleRange> styles) {
String log = logEntry.getLog();
if (logEntry.isTimeouted) {
log = createEnvironmentVariablesLink(
"<request timed out, you can look up the credentials in the <a>environment variables</a>>",
builder.length(),
styles,
logEntry.getElement());
builder.append(log);
builder.append(
NLS.bind("<The request timed out but we could create {0}. "
+ "You can look up eventual credentials in the environment variables>", logEntry.getName()));
} else if (StringUtils.isEmpty(log)) {
builder.append("<no information reported by OpenShift>");
} else {
Expand All @@ -166,27 +163,6 @@ private void appendLog(LogEntry logEntry, StringBuilder builder, List<StyleRange
builder.append(StringUtils.getLineSeparator());
}

private String createEnvironmentVariablesLink(String log, int baseIndex, List<StyleRange> styles, Object element) {
String newLog = log;
Matcher matcher = ECLIPSE_LINK_REGEX.matcher(log);
while (matcher.find()
&& matcher.groupCount() == 3) {
newLog = new StringBuilder()
.append(log.substring(0, matcher.start(1)))
.append(matcher.group(2))
.append(log.substring(matcher.end(3), log.length()))
.toString();
int startOffset = matcher.start(1) + baseIndex;
int stopOffset = matcher.start(1) + matcher.group(2).length() + baseIndex;
StyleRange linkStyle = createLinkStyleRange(startOffset, stopOffset);
styles.add(linkStyle);

links.add(new EnvironmentVariablesLink(startOffset, stopOffset, element));
}

return newLog;
}

private void createUrlLinks(String log, int baseIndex, List<StyleRange> styles) {
if(log == null) {
return;
Expand Down Expand Up @@ -339,18 +315,4 @@ public void execute() {
}
}

private static class EnvironmentVariablesLink extends Link {

private Object element;

public EnvironmentVariablesLink(int startOffset, int stopOffset, Object element) {
super(startOffset, stopOffset);
this.element = element;
}

public void execute() throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException {
IStructuredSelection selection = new StructuredSelection(element);
CommandUtils.executeCommand(ICommandIds.SHOW_ENVIRONMENT, selection);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ public static LogEntry[] create(IApplication application, boolean isTimeouted){
for(Message message : messages) {
if (message != null
&& !StringUtils.isEmpty(message.getText())) {
entries.add( new LogEntry(
entries.add(
new LogEntry(
application.getName(),
message.getText(),
isTimeouted,
application));
} else if (isTimeouted) {
// report timeout to the user
entries.add(new LogEntry(application.getName(), null, isTimeouted, application));
}
}
} else if (isTimeouted) {
// report timeout to the user
entries.add(new LogEntry(application.getName(), null, isTimeouted, application));
}

return entries.toArray(new LogEntry[entries.size()]);
}
return logEntry;
Expand All @@ -68,15 +76,24 @@ public static LogEntry[] create(Collection<IEmbeddedCartridge> cartridges, boole
message.getText(),
isTimeouted,
cartridge));
} else if (isTimeouted) {
// report timeout to the user
entries.add(new LogEntry(cartridge.getName(), null, isTimeouted, cartridge));
}
}
} else if (isTimeouted) {
// report timeout to the user
entries.add(new LogEntry(cartridge.getName(), null, isTimeouted, cartridge));
}
}

return entries.toArray(new LogEntry[entries.size()]);
}

private static List<Message> getMessages(Messages messages) {
if (messages == null) {
return null;
}
List<Message> resultMessages = messages.getBy(IField.RESULT);
// workaround(s) for https://issues.jboss.org/browse/JBIDE-15115
if (resultMessages == null
Expand Down