Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 280683
Collapse All | Expand All

(-)j2eecreation/org/eclipse/jst/j2ee/internal/javalite/JavaProjectLite.java (+52 lines)
Added Link Here
1
package org.eclipse.jst.j2ee.internal.javalite;
2
3
import org.eclipse.core.resources.IProject;
4
import org.eclipse.core.runtime.IPath;
5
import org.eclipse.jdt.core.IClasspathEntry;
6
import org.eclipse.jdt.core.IJavaProject;
7
8
/**
9
 * @see IJavaProjectLite
10
 */
11
public final class JavaProjectLite implements IJavaProjectLite {
12
	final IJavaProject javaProject;
13
14
	JavaProjectLite(IJavaProject javaProject) {
15
		this.javaProject = javaProject;
16
	}
17
18
	/**
19
	 * @see IJavaProjectLite#readRawClasspath()
20
	 */
21
	public final IClasspathEntry[] readRawClasspath() {
22
		return javaProject.readRawClasspath();
23
	}
24
25
	/**
26
	 * @see IJavaProjectLite#readOutputLocation()
27
	 */
28
	public final IPath readOutputLocation() {
29
		return javaProject.readOutputLocation();
30
	}
31
32
	/**
33
	 * @see IJavaProjectLite#getProject()
34
	 */
35
	public final IProject getProject() {
36
		return javaProject.getProject();
37
	}
38
39
	/**
40
	 * @see IJavaProjectLite#isOpen()
41
	 */
42
	public final boolean isOpen() {
43
		return javaProject.isOpen();
44
	}
45
	
46
	/**
47
	 * @see IJavaProjectLite#hasBuildState()
48
	 */
49
	public final boolean hasBuildState(){
50
		return javaProject.hasBuildState();
51
	}
52
}
(-)j2eecreation/org/eclipse/jst/j2ee/internal/javalite/JavaCoreLite.java (+16 lines)
Added Link Here
1
package org.eclipse.jst.j2ee.internal.javalite;
2
3
import org.eclipse.core.resources.IProject;
4
import org.eclipse.jdt.core.IJavaProject;
5
import org.eclipse.jdt.core.JavaCore;
6
7
public final class JavaCoreLite {
8
9
	public static final IJavaProjectLite create(IProject project) {
10
		IJavaProject javaProject = JavaCore.create(project);
11
		if (javaProject != null) {
12
			return new JavaProjectLite(javaProject);
13
		}
14
		return null;
15
	}
16
}
(-)j2eecreation/org/eclipse/jst/j2ee/internal/javalite/IJavaProjectLite.java (+60 lines)
Added Link Here
1
package org.eclipse.jst.j2ee.internal.javalite;
2
3
import org.eclipse.core.resources.IProject;
4
import org.eclipse.core.runtime.IPath;
5
import org.eclipse.jdt.core.IClasspathEntry;
6
import org.eclipse.jdt.core.IJavaModel;
7
import org.eclipse.jdt.core.IJavaProject;
8
import org.eclipse.jdt.core.JavaCore;
9
10
/**
11
 * <p>
12
 * Represents a scaled down version of an {@link IJavaProject}. This subset of
13
 * methods is guaranteed to not force a load of the underlying
14
 * {@link IJavaModel}. This enables safe access to a limited set of
15
 * {@link IJavaProject} API for multi-threaded clients to call during times of
16
 * extreme concurrency, e.g. workbench startup.
17
 * </p>
18
 * <p>
19
 * An instance of one of these handles can be created via
20
 * <code>JavaCoreLite.create(project)</code>.
21
 * </p>
22
 * 
23
 * @see JavaCore#create(org.eclipse.core.resources.IProject)
24
 * @see IJavaProject
25
 * @see IClasspathEntry
26
 */
27
public interface IJavaProjectLite {
28
	/**
29
	 * @see IJavaProject#readRawClasspath()
30
	 * 
31
	 * @return
32
	 */
33
	IClasspathEntry[] readRawClasspath();
34
35
	/**
36
	 * @see IJavaProject#readOutputLocation()
37
	 * 
38
	 * @return
39
	 */
40
	IPath readOutputLocation();
41
42
	/**
43
	 * @see IJavaProject#getProject()
44
	 * 
45
	 * @return
46
	 */
47
	IProject getProject();
48
49
	/**
50
	 * @see IJavaProject#isOpen()
51
	 * @return
52
	 */
53
	boolean isOpen();
54
55
	/**
56
	 * @see IJavaProject#hasBuildState()
57
	 * @return
58
	 */
59
	public boolean hasBuildState();
60
}
(-)j2eecreation/org/eclipse/jst/j2ee/internal/javalite/JavaLiteUtilities.java (+98 lines)
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
}

Return to bug 280683