ModuleName moduleName,
String targetPackage,
boolean publicEntities,
boolean testOnly) {
ModuleTypeInfo typeInfo = workspaceManager.getModuleTypeInfo(moduleName);
if (typeInfo == null) {
iceLogger.log(Level.INFO, "The module " + moduleName + " does not exist in the current workspace.");
return;
}
if (testOnly) {
String fullClassName = JavaBindingGenerator.getPackageName(targetPackage, moduleName) + '.' + JavaBindingGenerator.getClassName(moduleName, publicEntities);
try {
if(JavaBindingGenerator.checkJavaBindingClass(typeInfo, targetPackage, publicEntities, false)) {
iceLogger.log(Level.INFO, "The binding class " + fullClassName + (publicEntities ? " for the public members of " : " for the non-public members of ") + moduleName + " is up to date.");
} else {
iceLogger.log(Level.INFO, "WARNING:");
iceLogger.log(Level.INFO, "The binding class " + fullClassName + (publicEntities ? " for the public members of " : " for the non-public members of ") + moduleName + " is not up to date.");
}
} catch (UnableToResolveForeignEntityException e) {
iceLogger.log(Level.INFO, "Unable to check the java binding file for module " + moduleName + ":");
iceLogger.log(Level.INFO, " " + e.getCompilerMessage());
}
return;
}
// Generate the source for the Java binding class.
final String text;
try {
text = JavaBindingGenerator.getJavaBinding(typeInfo, targetPackage, publicEntities);
} catch (UnableToResolveForeignEntityException e) {
iceLogger.log(Level.INFO, "Unable to generate the java binding file for module " + moduleName + ":");
iceLogger.log(Level.INFO, " " + e.getCompilerMessage());
return;
}
// Need to find where to write the file.
String location = getModulePath(moduleName);
if (location == null) {
iceLogger.log(Level.INFO, "Unable to determine location for java binding file for module " + moduleName + ".");
return;
}
// Generally this location will follow the pattern of project_root\src\cal\module.cal or
// project_root\test\cal\module.cal. However, if the Eclipse project has its output
// set to a different directory, such as 'bin', the CAL source file will be in
// project_root\bin\module.cal.
File root = null;
while (root == null) {
if (location.indexOf(File.separator + "src" + File.separator) != -1) {
root = new File(location.substring(0,location.indexOf(File.separator + "src" + File.separator) + 5));
} else
if (location.indexOf(File.separator + "test" + File.separator) != -1) {
root = new File(location.substring(0,location.indexOf(File.separator + "test" + File.separator) + 6));
} else
if (location.indexOf(File.separator + "bin" + File.separator) != -1) {
root = new File(location.substring(0,location.indexOf(File.separator + "bin" + File.separator)));
// This should be the project root. Try to find the location of the CAL
// source file.
File[] files = root.listFiles();
root = null;
for (int i = 0; i < files.length; ++i) {
File f = files[i];
if (f.isDirectory() && !f.getName().equals("bin")) {
root = findFile(f, moduleName + ".cal");
if (root != null) {
break;
}
}
}
if (root != null) {
// At this point root is the location of the CAL source other than the bin directory.
// Reset the location string and keep going.
location = root.getAbsolutePath();
root = null;
} else {
// We couldn't find a location other than the one in the bin directory.
// Exit the loop and try moving relative to the CAL source location.
root = null;
break;
}
} else {
break;
}
}
if (root == null) {
// Go up one directory from the CAL source location
// and then add on org\openquark\cal\module
File f = new File (location);
f = f.getParentFile();
if (f.getName().equals("CAL")) {
f = f.getParentFile();
}
root = f;
}
String actualPackage;
if (targetPackage != null) {
actualPackage = JavaBindingGenerator.getPackageName(targetPackage.trim(), typeInfo.getModuleName());
} else {
actualPackage = JavaBindingGenerator.getPackageName(targetPackage, typeInfo.getModuleName());
}
String packageDirs = actualPackage.replace('.', File.separatorChar);
File bindingLocation = new File (root, packageDirs);
if (!bindingLocation.exists()) {
// Try to create the containing directory.
if (!bindingLocation.mkdirs()) {
iceLogger.log(Level.INFO, "Unable to create necessary directory " + bindingLocation.getPath() + ".");
return;
} else {
iceLogger.log(Level.INFO, "Directory " + bindingLocation.getPath() + " created.");
}
}
// We differentiate the generated classes for public vs. private module elements.
bindingLocation = new File(bindingLocation, JavaBindingGenerator.getClassName(typeInfo.getModuleName(), publicEntities) + ".java");
if (bindingLocation.exists()) {
try {
// Check to see if there is a difference between the new source
// and the existing source.