use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method searchForMainBlockInCurrentFile.
/**
* @return a module with a main block from the current file or null if no such module was found
* @throws AbsJobException
*/
private ModuleDecl searchForMainBlockInCurrentFile() throws AbsJobException {
if (currentFile == null) {
return null;
}
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature == null) {
throw new AbsJobException("Could not start the debugger, because selected file (" + currentFile.getName() + ") is not in an ABS project!");
}
synchronized (nature.modelLock) {
CompilationUnit unit = nature.getCompilationUnit(currentFile);
List<ModuleDecl> modules = findModulesWithMain(unit);
// TODO: is the module still valid once you have returned the lock?
return modules.size() == 0 ? null : modules.get(0);
}
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method getPathToGeneratedJavaFiles.
/**
* Returns path of generated Java files.
* Throws an IllegalArumentException, if path can not be found for the given project.
*
* @param project
* @return
* @throws CoreException
* @throws AbsJobException
*/
private Path getPathToGeneratedJavaFiles(IProject project) throws AbsJobException {
Path path;
String tempPath;
try {
tempPath = getAbsNature(project).getProjectPreferenceStore().getString(JAVA_SOURCE_PATH);
Assert.isLegal(tempPath != null);
} catch (NullPointerException e) {
standardExceptionHandling(e);
throw new AbsJobException("No ABS project selected.");
}
path = new Path(tempPath);
if (!path.isAbsolute()) {
path = new Path(project.getLocation().append(path).toOSString());
}
return path;
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method generateJavaClassFiles.
/**
* generates .class files (needs .java files)
* @param monitor
*
* @param absFrontendLocation -where to find the absfrontend
* @param path - directory with java files
* @param noWarnings - do not show any compile warnings
* @throws AbsJobException
*/
private void generateJavaClassFiles(IProgressMonitor monitor, String absFrontendLocation, File path, boolean noWarnings) throws AbsJobException {
monitor.subTask("Creating class files");
// args
String noWarn;
if (noWarnings) {
noWarn = "-nowarn";
} else {
noWarn = "";
}
if (!path.isDirectory() || !path.isAbsolute()) {
if (debugMode)
System.err.println("Not a absolute path of a directory: " + path.getAbsolutePath());
throw new AbsJobException("Path is not an absolute path of a directory");
}
String args = "-1.5 " + noWarn + " -classpath " + "\"" + absFrontendLocation + "\"" + " " + "\"" + path.getAbsolutePath() + "\"";
if (debugMode)
System.out.println("arguments: " + args);
// console
try {
ConsoleManager.displayConsoleView();
} catch (PartInitException e) {
standardExceptionHandling(e);
throw new AbsJobException("Not able to show console");
}
// compile with jdt-BatchCompiler
CompilationProgress progress = null;
OutputStream os = javaConsole.getOutputStream(ConsoleManager.MessageType.MESSAGE_ERROR);
boolean compilationSuccessful = BatchCompiler.compile(args, new PrintWriter(os), new PrintWriter(os), progress);
if (!compilationSuccessful) {
throw new AbsJobException("Sorry, there seems to be a bug in the java backend. The generated java " + "files could not be compiled correctly.");
}
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method getModuleByName.
/**
* finds a module with a given name in the current
* @param moduleName
* @return
* @throws AbsJobException
*/
private ModuleDecl getModuleByName(String moduleName) throws AbsJobException {
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature == null) {
throw new AbsJobException("Could not start the debugger, because selected file (" + currentFile.getName() + ") is not in an ABS project!");
}
synchronized (nature.modelLock) {
Model model = nature.getCompleteModel();
ModuleDecl result = model.lookupModule(moduleName);
if (result == null) {
throw new AbsJobException("Could not find a module with name " + moduleName + ".");
}
return result;
}
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class MavenJob method runMavenUpdates.
public void runMavenUpdates() throws NoABSNatureException, AbsJobException, IOException {
AbsNature nature = getAbsNature(project);
if (nature == null) {
throw new NoABSNatureException();
}
IFile pom = null;
if (!(pom = getPom()).exists()) {
throw new AbsJobException("POM for this project is not defined");
}
MsgConsole console = nature.getMavenConsole();
console.clear();
List<String> args = new ArrayList<String>();
File file = new File(getMavenPath());
if (!file.exists() || !file.isDirectory()) {
throw new AbsJobException("Maven path is not defined");
}
String command;
if (Platform.getOS().equals(Platform.OS_WIN32)) {
command = new File(file, "bin\\mvn.bat").getAbsolutePath();
} else {
command = new File(file, "bin/mvn").getAbsolutePath();
}
args.add(command);
args.add("-f");
args.add(pom.getLocation().toFile().getAbsolutePath());
args.add(goal);
InputStream ins = null;
OutputStream outs = null;
try {
if (!abort)
process = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
ins = process.getInputStream();
outs = console.getOutputStream(MessageType.MESSAGE_INFO);
int d = 0;
while ((d = ins.read()) != -1) {
outs.write(d);
}
if (process.waitFor() != 0) {
console.getOutputStream(MessageType.MESSAGE_ERROR).write("An error has occurred.");
}
} catch (InterruptedException e) {
throw new AbsJobException(e.getMessage());
} finally {
if (ins != null)
ins.close();
}
}
Aggregations