Skip to content

Commit 3436ff4

Browse files
committed
Output more debugging data
1 parent 5aab89e commit 3436ff4

1 file changed

Lines changed: 55 additions & 9 deletions

File tree

plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/DebugNativeAppEngineStandardProjectTest.java

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@
2727
import com.google.cloud.tools.eclipse.swtbot.SwtBotTestingUtilities;
2828
import com.google.cloud.tools.eclipse.swtbot.SwtBotTreeUtilities;
2929
import com.google.cloud.tools.eclipse.test.util.ThreadDumpingWatchdog;
30-
30+
import com.google.common.base.Strings;
31+
import com.google.common.io.CharStreams;
32+
33+
import org.eclipse.core.resources.IContainer;
34+
import org.eclipse.core.resources.IFile;
35+
import org.eclipse.core.resources.IProject;
36+
import org.eclipse.core.resources.IResource;
37+
import org.eclipse.core.resources.IResourceVisitor;
38+
import org.eclipse.core.runtime.CoreException;
39+
import org.eclipse.core.runtime.IPath;
3140
import org.eclipse.core.runtime.preferences.InstanceScope;
3241
import org.eclipse.swt.custom.StyledText;
3342
import org.eclipse.swt.widgets.Tree;
@@ -125,9 +134,14 @@ public void run() {
125134
System.out.printf("---- Dev App Server ----\n%s\n------------------\n",
126135
consoleContents.getText());
127136

137+
listFiles(project);
128138
listFiles(project.getLocation().toFile().toPath());
129-
listFiles(Paths.get(
130-
"/home/travis/build/GoogleCloudPlatform/google-cloud-eclipse/plugins/com.google.cloud.tools.eclipse.integration.appengine/target/work/data/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testapp"));
139+
printFileContents(project, ".project");
140+
printFileContents(project, ".classpath");
141+
142+
Path workspacePath = project.getWorkspace().getRoot().getLocation().toFile().toPath();
143+
Path testAppPath = workspacePath.resolve(".metadata/.plugins/org.eclipse.wst.server.core/tmp0/testapp");
144+
listFiles(testAppPath);
131145

132146
assertEquals("Hello App Engine!",
133147
getUrlContents(new URL("http://localhost:8080/hello"), (int) SWTBotPreferences.TIMEOUT));
@@ -148,16 +162,13 @@ public void run() {
148162
assertFalse("Stop Server button should be disabled", stopServerButton.isEnabled());
149163
}
150164

151-
/**
152-
* @param path
153-
*/
154-
private void listFiles(Path path) {
165+
private void listFiles(final Path path) {
155166
try {
156-
System.out.println(">> files in " + path);
167+
System.out.println("> files in " + path);
157168
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
158169
@Override
159170
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
160-
System.out.println(">> " + file);
171+
System.out.println(" " + path.relativize(file));
161172
return FileVisitResult.CONTINUE;
162173
}
163174
});
@@ -166,6 +177,41 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
166177
}
167178
}
168179

180+
private void listFiles(IContainer container) {
181+
try {
182+
IResourceVisitor fileVisitor = new IResourceVisitor() {
183+
@Override
184+
public boolean visit(IResource resource) throws CoreException {
185+
if (resource.getType() == IResource.FILE) {
186+
System.out.println(" " + resource);
187+
}
188+
return true;
189+
}
190+
};
191+
System.out.println("> files in " + container);
192+
container.accept(fileVisitor);
193+
} catch (CoreException ex) {
194+
System.err.println("Error while listing files in " + container + ": " + ex);
195+
}
196+
}
197+
198+
private void printFileContents(IContainer container, String path) {
199+
IResource resource = container.findMember(path);
200+
if (!resource.exists()) {
201+
System.err.println("--- Path does not exist: " + path);
202+
} else if (resource.getType() != IResource.FILE) {
203+
System.err.println("--- Path is not a file: " + path);
204+
} else {
205+
try {
206+
String contents = CharStreams.toString(
207+
new InputStreamReader(((IFile) resource).getContents(), StandardCharsets.UTF_8));
208+
System.out.printf("---- Contents of %s ----\n%s\n----------------\n", path, contents);
209+
} catch (Exception ex) {
210+
System.err.println("--- Exception accesing file: " + path + ": " + ex);
211+
}
212+
}
213+
}
214+
169215
/**
170216
* Check that there is no remote service for the URL.
171217
*/

0 commit comments

Comments
 (0)