// set java nature
addJavaNature(projectName);
// create classpath entries
IProject project = root.getProject(projectName);
IPath projectPath = project.getFullPath();
int sourceLength = sourceFolders.length;
int libLength = libraries.length;
IClasspathEntry[] entries = new IClasspathEntry[sourceLength
+ libLength];
for (int i = 0; i < sourceLength; i++) {
IPath sourcePath = new Path(sourceFolders[i]);
int segmentCount = sourcePath.segmentCount();
if (segmentCount > 0) {
// create folder and its parents
IContainer container = project;
for (int j = 0; j < segmentCount; j++) {
IFolder folder = container.getFolder(new Path(
sourcePath.segment(j)));
if (!folder.exists()) {
folder.create(true, true, null);
}
container = folder;
}
}
// create source entry
entries[i] = JavaCore.newSourceEntry(
projectPath.append(sourcePath), new IPath[0],
new IPath[0], null);
}
for (int i = 0; i < libLength; i++) {
String lib = libraries[i];
if (lib.startsWith("JCL")) {
// ensure JCL variables are set
try {
setUpJCLClasspathVariables(compliance);
} catch (IOException e) {
e.printStackTrace();
}
}
if (lib.indexOf(File.separatorChar) == -1
&& lib.charAt(0) != '/'
&& lib.equals(lib.toUpperCase())) { // all upper case is a var
char[][] vars = CharOperation.splitOn(',', lib
.toCharArray());
entries[sourceLength + i] = JavaCore.newVariableEntry(
new Path(new String(vars[0])), vars.length > 1
? new Path(new String(vars[1]))
: null, vars.length > 2
? new Path(new String(vars[2]))
: null);
} else {
IPath libPath = new Path(lib);
if (!libPath.isAbsolute() && libPath.segmentCount() > 0
&& libPath.getFileExtension() == null) {
project.getFolder(libPath).create(true, true, null);
libPath = projectPath.append(libPath);
}
entries[sourceLength + i] = JavaCore.newLibraryEntry(
libPath, null, null, ClasspathEntry.getAccessRules(
new IPath[0], new IPath[0]),
new IClasspathAttribute[0], false);
}
}
// create project's output folder
IPath outputPath = new Path(projectOutput);
if (outputPath.segmentCount() > 0) {
IFolder output = project.getFolder(outputPath);
if (!output.exists()) {
output.create(true, true, null);
}
}