KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > debug > AntSourceContainer


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ant.internal.ui.debug;
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.util.ArrayList JavaDoc;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IWorkspaceRoot;
20 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IPath;
23 import org.eclipse.core.runtime.Path;
24 import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
25 import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
26 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
27
28 public class AntSourceContainer extends AbstractSourceContainer {
29
30     private IWorkspaceRoot fRoot;
31
32     public AntSourceContainer() {
33         fRoot = ResourcesPlugin.getWorkspace().getRoot();
34     }
35
36     /* (non-Javadoc)
37      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
38      */

39     public Object JavaDoc[] findSourceElements(String JavaDoc path) throws CoreException {
40         ArrayList JavaDoc sources = new ArrayList JavaDoc();
41         File JavaDoc osFile = new File JavaDoc(path);
42         if (osFile.exists()) {
43             try {
44                 IPath canonicalPath = new Path(osFile.getCanonicalPath());
45                 IFile[] files = fRoot.findFilesForLocation(canonicalPath);
46                 if (files.length > 0) {
47                     for (int i = 0; i < files.length; i++) {
48                         sources.add(files[i]);
49                     }
50                 } else {
51                     sources.add(new LocalFileStorage(osFile));
52                 }
53             } catch (IOException JavaDoc e) {
54             }
55         }
56         return sources.toArray();
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
61      */

62     public String JavaDoc getName() {
63         return AntDebugMessages.AntSourceContainer_0;
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
68      * Not persisted via the launch configuration
69      */

70     public ISourceContainerType getType() {
71         return null;
72     }
73 }
Popular Tags