use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class NpmExportWizard method performFinish.
@Override
public boolean performFinish() {
String destination = exportPage.getDestinationValue();
List<IProject> toExport = exportPage.getChosenProjects();
boolean shouldPackAsTarball = exportPage.getShouldPackAsTarball();
File folder = new File(destination);
// remap all IProjects
List<? extends IN4JSProject> toExportIN4JSProjects = mapToIN4JSProjects(toExport);
if (runTools() && toolRunnerPage.isToolrunRequested()) {
// bring to front.
((WizardDialog) getContainer()).showPage(toolRunnerPage);
}
try {
npmExporter.export(toExportIN4JSProjects, folder);
if (shouldPackAsTarball) {
npmExporter.tarAndZip(toExportIN4JSProjects, folder);
}
boolean runIt = runTools() && toolRunnerPage.queryRunTool();
if (runIt) {
final List<String> toolCommand = toolRunnerPage.getCommand();
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<String> cmds = newArrayList();
// cmds.add("echo"); // prepend with echo for debug TODO remove
// cmds.addAll(toolCommand);
cmds.add("bash");
cmds.add("-login");
cmds.add("-c");
// cmds.addAll(toolCommand);
cmds.add(Joiner.on(" ").join(toolCommand));
System.out.println("Comman will be: " + Joiner.on(" :: ").join(cmds));
for (IN4JSProject p : toExportIN4JSProjects) {
String info = "Processing " + p.toString() + "\n";
System.out.println(info);
toolRunnerPage.appendText(info);
File dir = npmExporter.exportDestination(p, folder);
ProcessBuilder pb = new ProcessBuilder();
pb.directory(dir);
pb.command(cmds);
pb.redirectErrorStream(true);
Process proc = pb.start();
// handle each of proc's streams in a separate thread
ExecutorService handlerThreadPool = Executors.newFixedThreadPool(3);
// handlerThreadPool.submit(new Runnable() {
// @Override
// public void run() {
// // we want to write to the stdin of the process
// BufferedWriter stdin = new BufferedWriter(
// new OutputStreamWriter(proc.getOutputStream()));
//
// // read from our own stdin so we can write it to proc's stdin
// BufferedReader myStdin =
// new BufferedReader(new InputStreamReader(System.in));
// String line = null;
// try {
// do {
// line = myStdin.readLine();
// stdin.write(String.format("%s%n", line));
// stdin.flush();
// } while(! "exit".equalsIgnoreCase(line));
// } catch(IOException e) {
// e.printStackTrace();
// }
// }
// });
handlerThreadPool.submit(new Runnable() {
@Override
public void run() {
// we want to read the stdout of the process
BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
try {
while (null != (line = stdout.readLine())) {
System.err.printf("[stderr] %s%n", line);
toolRunnerPage.appendConsoleOut(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
handlerThreadPool.submit(new Runnable() {
@Override
public void run() {
// we want to read the stderr of the process
BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String line;
try {
while (null != (line = stderr.readLine())) {
System.err.printf("[stderr] %s%n", line);
toolRunnerPage.appendConsoleErr(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
// wait for the process to terminate
int exitCode = proc.waitFor();
System.out.printf("Process terminated with exit code %d%n", exitCode);
handlerThreadPool.shutdown();
}
// done with all projects.
// wait for close.
toolRunnerPage.queryCloseDialog();
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
}
} catch (IOException | ArchiveException | CompressorException e) {
e.printStackTrace();
Status s = new Status(ERROR, NpmExporterActivator.PLUGIN_ID, "Error occured during export.", e);
N4JSActivator.getInstance().getLog().log(s);
return false;
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// successfully done, then store relevant history:
exportPage.finish();
if (runTools()) {
toolRunnerPage.finish();
}
return true;
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class NpmExportWizard method init.
@Override
public void init(IWorkbench targetWorkbench, IStructuredSelection currentSelection) {
// this.selection = currentSelection;
List<?> selectedResources = IDE.computeSelectedResources(currentSelection);
List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
// Find all selected projects
Set<IProject> projects = selectedResources.stream().filter(m -> m instanceof IResource).map(m -> ((IResource) m).getProject()).filter(// only open projects
p -> p.isOpen()).collect(Collectors.toSet());
// make the behavior predictable by ordering:
TreeSet<IProject> sortedProjects = Sets.<IProject>newTreeSet((a, b) -> a.getName().compareToIgnoreCase(b.getName()));
sortedProjects.addAll(projects);
// 0) turn into IN4JSProject and give and process further.
// a) find out which projects fulfill the npm-"exportable"-contract
// b) give back a list to the user what to export,
// c) disable things not fullfilling the contract.
// d) take choosing from the list and pass to exporter in non-ui package.
// 0)
List<IN4JSEclipseProject> rawN4jsProjects = Lists.newArrayList();
iP2in4jsP = HashBiMap.create();
for (IProject iProject : workspaceProjects) {
IN4JSEclipseProject mappedIn4jsProject = map2In4js(iProject);
if (mappedIn4jsProject != null) {
rawN4jsProjects.add(mappedIn4jsProject);
iP2in4jsP.put(iProject, mappedIn4jsProject);
}
}
// filter out Non-N4JS-projects from initial selection.
sortedProjects.retainAll(iP2in4jsP.keySet());
// filter out all non-N4JS-projects from the workspace projects.
ArrayList<IProject> filteredWorkspaceProjects = new ArrayList<>(workspaceProjects);
filteredWorkspaceProjects.retainAll(iP2in4jsP.keySet());
setWindowTitle("N4JS to npm Export");
setNeedsProgressMonitor(true);
Map<IProject, Boolean> selectedProjects = new HashMap<>();
// Add all workspace projects to list, default selection value is false
filteredWorkspaceProjects.forEach(project -> selectedProjects.put(project, false));
// Override selection value for all initially selected projects
sortedProjects.forEach(project -> selectedProjects.put(project, true));
// exportPage = new ExportSelectionPage("Export Page", rawN4jsProjects, labelProvider);
exportPage = new ExportSelectionPage("Export Page", selectedProjects);
if (runTools())
toolRunnerPage = new NpmToolRunnerPage("npm Execution Page");
comparePage = new PackageJsonComparePage("Compare package.json Page");
pageListener = new IPageChangedListener() {
@Override
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == comparePage) {
udpatePackagJasonComparison();
}
}
};
}
use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.
the class NpmExportWizard method updateProjectsToExportSelection.
/**
* @param checked
* list of selected projects to export
* @throws InterruptedException
* @throws InvocationTargetException
*/
public void updateProjectsToExportSelection(Object[] checked) throws InvocationTargetException, InterruptedException {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<IProject> checkedProjects = newArrayList();
for (Object o : checked) checkedProjects.add((IProject) o);
List<? extends IN4JSProject> checkedIN4JSProjects = mapToIN4JSProjects(checkedProjects);
// validate:
final Diagnostician diag = new Diagnostician();
List<IN4JSProject> _requiresMerge1 = newArrayList();
for (IN4JSProject p : checkedIN4JSProjects) {
diag.setActiveProject(p);
npmExporter.validate(p, diag);
if (npmExporter.requiresJsonMerge(p)) {
_requiresMerge1.add(p);
}
}
setRequireJsonMerge(_requiresMerge1);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (diag.isIssueFree()) {
exportPage.setErrorMessage(null);
exportPage.setErrorText("");
} else {
exportPage.setPageComplete(false);
exportPage.setErrorMessage("Validation errors for projects: " + Joiner.on(", ").join(diag.projectsWithEntries().stream().map(p -> p.getProjectId()).iterator()));
String text = diag.asErrorText();
exportPage.setErrorText(text);
}
}
});
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
}
Aggregations