use of org.absmodels.abs.plugin.exceptions.NoABSNatureException 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.NoABSNatureException 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