Skip to content

Commit 0d710f9

Browse files
committed
Trap exceptions for launch thingies
1 parent c1301fb commit 0d710f9

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

plugins/com.google.cloud.tools.eclipse.appengine.localserver/src/com/google/cloud/tools/eclipse/appengine/localserver/server/LocalAppEngineServerLaunchConfigurationDelegate.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@
3333
import com.google.common.annotations.VisibleForTesting;
3434
import com.google.common.base.Preconditions;
3535
import com.google.common.base.Strings;
36+
import com.google.common.io.CharStreams;
3637
import com.google.common.net.InetAddresses;
3738
import java.io.File;
39+
import java.io.InputStreamReader;
3840
import java.net.InetAddress;
3941
import java.net.UnknownHostException;
42+
import java.nio.charset.StandardCharsets;
43+
import java.nio.file.Paths;
4044
import java.text.MessageFormat;
4145
import java.util.ArrayList;
4246
import java.util.Arrays;
@@ -48,7 +52,10 @@
4852
import java.util.Set;
4953
import java.util.logging.Level;
5054
import java.util.logging.Logger;
55+
import org.eclipse.core.resources.IContainer;
56+
import org.eclipse.core.resources.IFile;
5157
import org.eclipse.core.resources.IProject;
58+
import org.eclipse.core.resources.IResource;
5259
import org.eclipse.core.runtime.CoreException;
5360
import org.eclipse.core.runtime.IPath;
5461
import org.eclipse.core.runtime.IProgressMonitor;
@@ -138,6 +145,27 @@ public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws
138145
return super.getLaunch(configuration, mode);
139146
}
140147

148+
private void printFileContents(IContainer container, String path) {
149+
java.nio.file.Path path = Paths.get("foo");
150+
path.relativize(other)
151+
container.getProject().getWorkspace().getRoot().
152+
IResource resource = container.findMember(path);
153+
if (!resource.exists()) {
154+
System.err.println("--- Path does not exist: " + path);
155+
} else if (resource.getType() != IResource.FILE) {
156+
System.err.println("--- Path is not a file: " + path);
157+
} else {
158+
try {
159+
String contents = CharStreams.toString(
160+
new InputStreamReader(((IFile) resource).getContents(), StandardCharsets.UTF_8));
161+
System.out.printf("---- Contents of %s ----\n%s\n----------------",
162+
path, contents);
163+
} catch (Exception ex) {
164+
System.err.println("--- Exception accesing file: " + path + ": " + ex);
165+
}
166+
}
167+
}
168+
141169
/**
142170
* Create a CloudSdk RunConfiguration corresponding to the launch configuration and server
143171
* defaults. Details are pulled from {@link ILaunchConfiguration#getAttributes() launch
@@ -459,15 +487,25 @@ static String determinePageLocation(IServer server) {
459487
@Override
460488
protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode)
461489
throws CoreException {
462-
IProject[] projects = getReferencedProjects(configuration);
463-
return computeBuildOrder(projects);
490+
try {
491+
IProject[] projects = getReferencedProjects(configuration);
492+
return computeBuildOrder(projects);
493+
} catch (Throwable ex) {
494+
ex.printStackTrace();
495+
throw ex;
496+
}
464497
}
465498

466499
@Override
467500
protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode)
468501
throws CoreException {
469-
IProject[] projects = getReferencedProjects(configuration);
470-
return computeReferencedBuildOrder(projects);
502+
try {
503+
IProject[] projects = getReferencedProjects(configuration);
504+
return computeReferencedBuildOrder(projects);
505+
} catch (Throwable ex) {
506+
ex.printStackTrace();
507+
throw ex;
508+
}
471509
}
472510

473511
private static IProject[] getReferencedProjects(ILaunchConfiguration configuration)

0 commit comments

Comments
 (0)