|
Added
Link Here
|
| 1 |
package org.eclipse.jst.j2ee.internal.javalite; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
import java.util.Collections; |
| 5 |
import java.util.List; |
| 6 |
|
| 7 |
import org.eclipse.core.resources.IContainer; |
| 8 |
import org.eclipse.core.runtime.IPath; |
| 9 |
import org.eclipse.jdt.core.IClasspathEntry; |
| 10 |
import org.eclipse.wst.common.componentcore.ComponentCore; |
| 11 |
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; |
| 12 |
import org.eclipse.wst.common.componentcore.resources.IVirtualResource; |
| 13 |
|
| 14 |
public final class JavaLiteUtilities { |
| 15 |
|
| 16 |
public final static List<IContainer> getAllJavaSourceContainers(final IJavaProjectLite javaProject) { |
| 17 |
IClasspathEntry[] entries = javaProject.readRawClasspath(); |
| 18 |
List<IContainer> sourceContainers = new ArrayList<IContainer>(); |
| 19 |
for (IClasspathEntry entry : entries) { |
| 20 |
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { |
| 21 |
IContainer container = javaProject.getProject().getFolder(entry.getPath()); |
| 22 |
sourceContainers.add(container); |
| 23 |
} |
| 24 |
} |
| 25 |
return sourceContainers; |
| 26 |
} |
| 27 |
|
| 28 |
public final static List<IContainer> getJavaSourceContainers(final IVirtualComponent component) { |
| 29 |
if (!component.isBinary()) { |
| 30 |
IJavaProjectLite javaProject = JavaCoreLite.create(component.getProject()); |
| 31 |
if (javaProject != null) { |
| 32 |
List<IContainer> allSourceContainers = getAllJavaSourceContainers(javaProject); |
| 33 |
List<IContainer> componentSourceContainers = new ArrayList<IContainer>(); |
| 34 |
for (IContainer sourceContainer : allSourceContainers) { |
| 35 |
IVirtualResource[] virtualResources = ComponentCore.createResources(sourceContainer); |
| 36 |
for (IVirtualResource virtualResource : virtualResources) { |
| 37 |
if (virtualResource.getComponent().equals(component)) { |
| 38 |
componentSourceContainers.add(sourceContainer); |
| 39 |
break; |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
return Collections.EMPTY_LIST; |
| 46 |
} |
| 47 |
|
| 48 |
public final static List<IContainer> getOutputContainers(final IVirtualComponent component, int kind) { |
| 49 |
if (!component.isBinary()) { |
| 50 |
IJavaProjectLite javaProject = JavaCoreLite.create(component.getProject()); |
| 51 |
if (javaProject != null) { |
| 52 |
IClasspathEntry[] entries; |
| 53 |
entries = javaProject.readRawClasspath(); |
| 54 |
List<IContainer> componentOutputContainers = new ArrayList<IContainer>(); |
| 55 |
for (IClasspathEntry entry : entries) { |
| 56 |
IContainer container = null; |
| 57 |
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE |
| 58 |
&& (kind & IClasspathEntry.CPE_SOURCE) == IClasspathEntry.CPE_SOURCE) { |
| 59 |
container = javaProject.getProject().getFolder(entry.getPath()); |
| 60 |
} else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY |
| 61 |
&& (kind & IClasspathEntry.CPE_LIBRARY) == IClasspathEntry.CPE_LIBRARY) { |
| 62 |
container = javaProject.getProject().getFolder(entry.getPath()); |
| 63 |
if (!container.exists()) { |
| 64 |
container = null; |
| 65 |
} |
| 66 |
} |
| 67 |
if (container != null) { |
| 68 |
IVirtualResource[] virtualResources = ComponentCore.createResources(container); |
| 69 |
for (IVirtualResource virtualResource : virtualResources) { |
| 70 |
if (virtualResource.getComponent().equals(component)) { |
| 71 |
IPath outputPath = entry.getOutputLocation(); |
| 72 |
IContainer outputContainer = null; |
| 73 |
if (outputPath == null) { |
| 74 |
if (javaProject.readOutputLocation().segmentCount() == 1) { |
| 75 |
outputContainer = javaProject.getProject(); |
| 76 |
} else { |
| 77 |
outputContainer = javaProject.getProject().getFolder( |
| 78 |
javaProject.readOutputLocation().removeFirstSegments(1)); |
| 79 |
} |
| 80 |
} else { |
| 81 |
outputContainer = javaProject.getProject().getFolder( |
| 82 |
outputPath.removeFirstSegments(1)); |
| 83 |
} |
| 84 |
if (!componentOutputContainers.contains(outputContainer)) { |
| 85 |
componentOutputContainers.add(outputContainer); |
| 86 |
} |
| 87 |
break; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
return componentOutputContainers; |
| 93 |
} |
| 94 |
} |
| 95 |
return Collections.EMPTY_LIST; |
| 96 |
} |
| 97 |
|
| 98 |
} |