use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method findAndExecuteMain.
/**
* Tries to find the main block in the chosen ABS file or in the
* ABS project, if file is null.
*
* Finally: executes Modulename.Main
*
* @param absFrontendLocation - where to find the absfrontend
* @throws AbsJobException - if no main block found
* @throws IOException - If an I/O error occurs
*/
private void findAndExecuteMain(String absFrontendLocation) throws AbsJobException, IOException {
String info = null;
ModuleDecl module;
if (absUnit) {
module = getModuleByName(ABSTestRunnerGenerator.RUNNER_MAIN);
} else if (runTarget != null) {
module = getModuleByName(runTarget);
} else {
module = searchForMainBlockInCurrentFile();
// Search for the main file if previous searching was not successful
if (module == null) {
List<ModuleDecl> modules = getAllModulesWithMainInCurrentProject();
if (modules.size() == 0) {
throw new AbsJobException("No Module with main block found.");
} else {
module = modules.get(0);
}
if (currentFile != null) {
info = "No main file found for \"" + currentFile.getName() + "\".\nBut there is a main file in the project:";
}
}
}
String moduleName = JavaBackend.getFullJavaNameForMainBlock(module);
try {
debugAbsFiles(absFrontendLocation, javaPath, startSDE, moduleName, info);
} catch (InvalidRandomSeedException e) {
throw new AbsJobException(e);
}
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method generateJavaCode.
/**
* Generates .java files (no .class files).
* If 'product' is set, will flatten accordingly.
* @param monitor - must not be null
* @param path - where to add the modules / java-files
* @param project - the ABS project
* @throws IOException, if unable to create java files
* @throws AbsJobException, if unable to generate java files
* @throws JavaCodeGenerationException, if unable to generate java files
* @throws CoreException
* @throws NoModelException
*/
private void generateJavaCode(IProgressMonitor monitor, Path path, IProject project) throws AbsJobException, IOException, JavaCodeGenerationException, CoreException, NoModelException {
assert monitor != null;
monitor.subTask("Creating java source files");
AbsNature nat = UtilityFunctions.getAbsNature(project);
synchronized (nat.modelLock) {
Model model = nat.getCompleteModel();
if (model == null)
throw new NoModelException();
JavaCode javaCode = new JavaCode(path.toFile());
if (product != null) {
/* [stolz] Flattening for a product will mangle the model according to [ramus]...
*/
// work on a copy:
model = model.treeCopyNoTransform();
model.flushTreeCache();
String productN = product.getName();
try {
model.flattenForProduct(productN);
model.flushCache();
if (model.hasErrors() || model.hasTypeErrors()) {
nat.createMarkers(model);
throw new AbsJobException("An ABS file in the project has type errors after applying deltas");
}
} catch (WrongProgramArgumentException e) {
throw new AbsJobException(e);
} catch (DeltaModellingException e) {
throw new AbsJobException(e);
}
}
// TODO: the second parameter toggles listener code creation (3
// Java method calls per ABS statement); make this configurable
model.generateJavaCode(javaCode, true);
int countUnits = model.getNumCompilationUnit();
if (countUnits == 0)
throw new AbsJobException("No compilation unit found");
}
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method getModelFromProject.
/**
* @Deprecated According to Yannick, you need to hold {@link AbsNature#modelLock} to safely do anything with the model,
* which means you need the nature first, and then this helper is just a fancy wrapper around {@link AbsNature#getCompleteModel()}...
* @see AbsNature#getCompleteModel()
*/
public static Model getModelFromProject(IProject project) throws AbsJobException {
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature == null) {
throw new AbsJobException("The file is not in an ABS project!");
}
Model model = nature.getCompleteModel();
// if (model==null && curFile!=null ) model = abs.frontend.parser.Main.parse(new File(curFile.getLocation().toString()), withStdLib);
if (model == null) {
throw new AbsJobException("No ABS model found");
}
if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
// just to be sure
throw new AbsJobException("An ABS file in the project has type or parser errors");
}
return model;
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class MavenAction method run.
@Override
public void run() {
if (selection != null && selection instanceof TreeSelection) {
final IProject project = getProject((TreeSelection) selection);
new Job("Maven") {
protected IStatus run(IProgressMonitor monitor) {
final MavenJob mavenJob = new MavenJob(project);
mavenJob.setUser(true);
try {
mavenJob.runMavenUpdates();
} catch (NoABSNatureException e) {
showErrorMessage(e.getMessage());
} catch (AbsJobException e) {
showErrorMessage(e.getMessage());
} catch (IOException e) {
showErrorMessage(e.getMessage());
}
MavenAction.super.run();
return new Status(IStatus.OK, PLUGIN_ID, "done");
}
}.schedule();
}
}
use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.
the class JavaJob method checkPath.
private void checkPath(Path javaPath) throws AbsJobException {
File javaDir = javaPath.toFile();
File[] genDirs = javaDir.listFiles();
if (genDirs == null || genDirs.length == 0) {
throw new AbsJobException("No generated Java files found. Please compile ABS files to Java before debugging.");
}
}
Aggregations