Repository navigation
Expand file tree
/
Copy pathSSGenUtil.java
More file actions
134 lines (123 loc) · 3.67 KB
/
Copy pathSSGenUtil.java
File metadata and controls
134 lines (123 loc) · 3.67 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package shellScriptGen;
import java.util.ArrayList;
import java.util.Map;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
/**
* A singleton utility class used by various components
* of the plugin that contains a series of helper methods.
*
* @author Amit Nithian ([email protected])
*
*/
public class SSGenUtil
{
private IJavaModel m_jModel;
private static SSGenUtil m_util;
private IWorkspaceRoot m_rWorkspace;
private ILaunchConfigurationType m_javaApplicationType;
/**
* Returns the instance of the utility class.
*
* @return
*/
public static SSGenUtil getInstance()
{
if(m_util==null)
{
m_util = new SSGenUtil();
}
return m_util;
}
private SSGenUtil()
{
m_rWorkspace = ResourcesPlugin.getWorkspace().getRoot();
m_jModel = JavaCore.create(m_rWorkspace);
//We are only concerned with Java Applications so let's
//restrict to just those so that we don't show targets for
//other things like JUnit, Ant etc.
ILaunchConfigurationType[] types =
DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes();
for(ILaunchConfigurationType i:types)
{
if(i.getName().equals("Java Application"))
{
m_javaApplicationType = i;
break;
}
}
}
/**
* Returns the JavaModel associated with the workspace.
* @return
*/
public IJavaProject getJavaProject(String pProjectName)
{
return m_jModel.getJavaProject(pProjectName);
}
/**
* Returns a list of launch configurations for a given java project.
*
* @param pProject The desired java project to query the launch configurations.
* @return
*/
public ArrayList<ILaunchConfiguration> getLaunchConfigurations(IJavaProject pProject)
{
ArrayList aList = new ArrayList();
try
{
ILaunchConfiguration[] launches = DebugPlugin.getDefault()
.getLaunchManager().getLaunchConfigurations(m_javaApplicationType);
for(ILaunchConfiguration i : launches)
{
String sProjectName = i.getAttribute(
IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
//Null category seems to mean only those that are runtime configurations
//and not those like ant build.xml targets.
if(sProjectName.equalsIgnoreCase(pProject.getElementName())
&& i.getCategory() == null)
aList.add(i);
//System.out.println(i.getName());
//System.out.println(i.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,""));
}
}
catch(CoreException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
return aList;
}
/**
* Returns a list of the java projects associated with the current workspace.
* @return
*/
public IJavaProject[] getProjects()
{
IJavaProject[] javaProjects;
try
{
javaProjects = m_jModel.getJavaProjects();
}
catch(JavaModelException ee)
{
javaProjects = new IJavaProject[0];
}
return javaProjects;
}
public IResource getResource(IPath pPath)
{
return m_rWorkspace.findMember(pPath);
}
}