use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.
the class ModuleGroupContentProvider method getChildrenOf.
/**
* Returns the children of a project.
*
* @param project
* @return The children of the Project or an empty object array if the
* project is closed or not an ABS project or an Exception occurs
*/
private Object[] getChildrenOf(IProject project) {
try {
if (project.isAccessible() && project.hasNature(Constants.NATURE_ID)) {
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature != null) {
synchronized (nature.modelLock) {
ArrayList<InternalASTNode<?>> decls = new ArrayList<InternalASTNode<?>>();
Model model = nature.getCompleteModel();
// something could be compiled in the project (i.e. the project is not empty...)
if (model != null) {
Collection<ModuleDecl> moduleDecls = model.getModuleDecls();
for (ModuleDecl m : moduleDecls) {
String name = m.getName();
/* Don't show internal resources which would be read-only anyway.
* This is either the standard lib, or e.g. ABS.FLI, ABS.DC */
if (name.startsWith("ABS.")) {
continue;
}
decls.add(new InternalASTNode<ModuleDecl>(m, nature));
}
}
return decls.toArray();
}
}
}
} catch (CoreException ce) {
ce.printStackTrace();
return EMPTY_OBJECT_ARRAY;
}
return EMPTY_OBJECT_ARRAY;
}
use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.
the class SDAction method run.
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
/* 1. Get the project */
IProject project = getCurrentProject();
if (project == null)
return;
/* 2. Get the Console */
MessageConsoleStream outConsole = findConsole().newMessageStream();
outConsole.setActivateOnWrite(true);
PrintStream out = new PrintStream(outConsole);
/* 3. Get the model in a good shape (typed. For now, there is nothing we can do about deltas) */
AbsNature nature = org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature(project);
Model model = nature.getCompleteModel();
model.typeCheck();
/* 4. Perform the analysis */
SDARun run = new SDARun(model, false, 3, 2, out);
run.schedule();
}
use of org.absmodels.abs.plugin.builder.AbsNature 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.builder.AbsNature 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.builder.AbsNature 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