/
TcServerSourcePathComputerDelegate.java
80 lines (73 loc) · 3.37 KB
/
TcServerSourcePathComputerDelegate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package com.vmware.vfabric.ide.eclipse.tcserver.internal.core;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jst.server.tomcat.core.internal.TomcatSourcePathComputerDelegate;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerUtil;
/**
* Specialized version of TomcatSourcePathComputerDelegate, to ensure that
* grails.app projects will get their source code added to the source code
* lookup.
* @author Kris De Volder
* @author Christian Dupuis
* @since 2.5.2
*/
public class TcServerSourcePathComputerDelegate extends TomcatSourcePathComputerDelegate {
@Override
public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor)
throws CoreException {
ISourceContainer[] superContainers = super.computeSourceContainers(configuration, monitor);
// Super doesn't handle "grails.app" modules. So we must handle them.
IServer server = ServerUtil.getServer(configuration);
// TODO: KDV: instead of putting code like below in here to support
// grails.app modules. It would be nicer if we made
// it possible to contribute a handler for a module type / version... so
// that this kind of code can be placed in the
// plugin that defines the module type.
IModule[] modules = server.getModules();
List<IProject> grailsProjects = new ArrayList<IProject>();
for (IModule m : modules) {
if (ITcServerConstants.GRAILS_APP_MODULE_TYPE.equals(m.getModuleType().getId())) {
grailsProjects.add(m.getProject());
}
}
ISourceContainer[] allSourceContainers;
if (grailsProjects.size() == 0) {
allSourceContainers = superContainers;
}
else {
ArrayList<ISourceContainer> containers = new ArrayList<ISourceContainer>(Arrays.asList(superContainers));
IRuntimeClasspathEntry[] projectEntries = new IRuntimeClasspathEntry[grailsProjects.size()];
int i = 0;
for (IProject p : grailsProjects) {
IJavaProject javaProject = JavaCore.create(p);
projectEntries[i++] = JavaRuntime.newDefaultProjectClasspathEntry(javaProject);
}
IRuntimeClasspathEntry[] sourceEntries = JavaRuntime.resolveSourceLookupPath(projectEntries, configuration);
containers.addAll(Arrays.asList(JavaRuntime.getSourceContainers(sourceEntries)));
allSourceContainers = containers.toArray(new ISourceContainer[containers.size()]);
}
return allSourceContainers;
}
}