/** * Program entry point. * * @param args program arguments */ public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); // input/out File input = new File(VisibilityCircle.class.getResource("/visibility-circle.in").toURI().getPath()); File output = new File(input.getParentFile(), "visibility-circle.csv"); new VisibilityCircle().run(input, output, ","); System.out.println("visibility circle saved as file " + output); } catch (URISyntaxException use) { System.err.println(use.getLocalizedMessage()); System.exit(1); } catch (IOException ioe) { System.err.println(ioe.getLocalizedMessage()); System.exit(1); } catch (IllegalArgumentException iae) { System.err.println(iae.getLocalizedMessage()); System.exit(1); } catch (OrekitException oe) { System.err.println(oe.getLocalizedMessage()); System.exit(1); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case FILE_SELECT_CODE: if (resultCode == Activity.RESULT_OK) { // Get the Uri of the selected file Uri uri = data.getData(); Log.d(LOG_TAG, "File Uri: " + uri.toString()); try { filePath = FileUtils.getPath(getActivity(), uri); fileChoosen = new File(filePath); if (fileChoosen != null) { tv_choose_file.setText(fileChoosen.getName()); } else { break; } bt_upload.setEnabled(true); } catch (URISyntaxException e) { Log.d(LOG_TAG, e.getLocalizedMessage()); } } break; } super.onActivityResult(requestCode, resultCode, data); }
/** {@inheritDoc} */ @Override public URI getURI() { try { return serverURL.toURI(); } catch (URISyntaxException ex) { LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex); } return null; }
private String getPath(String resourceName) { try { ClassLoader loader = DirectoryCrawlerTest.class.getClassLoader(); return loader.getResource(resourceName).toURI().getPath(); } catch (URISyntaxException e) { Assert.fail(e.getLocalizedMessage()); return null; } }
private void checkPage() { try { pushURI = new URIish(uriText.getText()); scheme.select(scheme.indexOf(pushURI.getScheme())); } catch (URISyntaxException e) { setErrorMessage(e.getLocalizedMessage()); setPageComplete(false); return; } String branchName = branch.getText(); if (branchName.length() == 0) { setErrorMessage(UIText.GerritConfigurationPage_errorBranchName); setPageComplete(false); return; } setErrorMessage(null); setPageComplete(true); }
public boolean downloadFormAndSubmissionFiles(List<FormStatus> formsToTransfer) { boolean allSuccessful = true; // boolean error = false; int total = formsToTransfer.size(); for (int i = 0; i < total; i++) { FormStatus fs = formsToTransfer.get(i); if (isCancelled()) { fs.setStatusString("aborted. Skipping fetch of form and submissions...", true); EventBus.publish(new FormStatusEvent(fs)); return false; } RemoteFormDefinition fd = (RemoteFormDefinition) fs.getFormDefinition(); fs.setStatusString("Fetching form definition", true); EventBus.publish(new FormStatusEvent(fs)); try { File tmpdl = FileSystemUtils.getTempFormDefinitionFile(); AggregateUtils.commonDownloadFile(serverInfo, tmpdl, fd.getDownloadUrl()); fs.setStatusString("resolving against briefcase form definitions", true); EventBus.publish(new FormStatusEvent(fs)); boolean successful = false; BriefcaseFormDefinition briefcaseLfd; DatabaseUtils formDatabase = null; try { try { briefcaseLfd = BriefcaseFormDefinition.resolveAgainstBriefcaseDefn(tmpdl); if (briefcaseLfd.needsMediaUpdate()) { if (fd.getManifestUrl() != null) { File mediaDir = FileSystemUtils.getMediaDirectory(briefcaseLfd.getFormDirectory()); String error = downloadManifestAndMediaFiles(mediaDir, fs); if (error != null) { allSuccessful = false; fs.setStatusString("Error fetching form definition: " + error, false); EventBus.publish(new FormStatusEvent(fs)); continue; } } } formDatabase = new DatabaseUtils(FileSystemUtils.getFormDatabase(briefcaseLfd.getFormDirectory())); } catch (BadFormDefinition e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString("Error parsing form definition: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } fs.setStatusString("preparing to retrieve instance data", true); EventBus.publish(new FormStatusEvent(fs)); File formInstancesDir = FileSystemUtils.getFormInstancesDirectory(briefcaseLfd.getFormDirectory()); // this will publish events successful = downloadAllSubmissionsForForm(formInstancesDir, formDatabase, briefcaseLfd, fs); } catch (FileSystemException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString("unable to open form database: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } finally { if (formDatabase != null) { try { formDatabase.close(); } catch (SQLException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString("unable to close form database: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } } } allSuccessful = allSuccessful && successful; // on success, we haven't actually set a success event (because we don't know we're done) if (successful) { fs.setStatusString("SUCCESS!", true); EventBus.publish(new FormStatusEvent(fs)); } else { fs.setStatusString("FAILED.", true); EventBus.publish(new FormStatusEvent(fs)); } } catch (SocketTimeoutException se) { se.printStackTrace(); allSuccessful = false; fs.setStatusString( "Communications to the server timed out. Detailed message: " + se.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl() + " A network login screen may be interfering with the transmission to the server.", false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (IOException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl() + " A network login screen may be interfering with the transmission to the server.", false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (FileSystemException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (URISyntaxException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (TransmissionException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } } return allSuccessful; }
@Override public void launch( ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { try { ConfigUtils configUtils = new ConfigUtils(config); project = configUtils.getProject(); // check if Perf exists in $PATH if (!PerfCore.checkPerfInPath(project)) { IStatus status = new Status( IStatus.ERROR, PerfPlugin.PLUGIN_ID, "Error: Perf was not found on PATH"); //$NON-NLS-1$ throw new CoreException(status); } URI binURI = new URI(configUtils.getExecutablePath()); binPath = Path.fromPortableString(binURI.toString()); workingDirPath = Path.fromPortableString( Path.fromPortableString(binURI.toString()).removeLastSegments(2).toPortableString()); PerfPlugin.getDefault().setWorkingDir(workingDirPath); if (config.getAttribute(PerfPlugin.ATTR_ShowStat, PerfPlugin.ATTR_ShowStat_default)) { showStat(config, launch); } else { URI exeURI = new URI(configUtils.getExecutablePath()); String configWorkingDir = configUtils.getWorkingDirectory() + IPath.SEPARATOR; RemoteConnection exeRC = new RemoteConnection(exeURI); String perfPathString = RuntimeProcessFactory.getFactory().whichCommand(PerfPlugin.PERF_COMMAND, project); boolean copyExecutable = configUtils.getCopyExecutable(); if (copyExecutable) { URI copyExeURI = new URI(configUtils.getCopyFromExecutablePath()); RemoteConnection copyExeRC = new RemoteConnection(copyExeURI); IRemoteFileProxy copyExeRFP = copyExeRC.getRmtFileProxy(); IFileStore copyExeFS = copyExeRFP.getResource(copyExeURI.getPath()); IRemoteFileProxy exeRFP = exeRC.getRmtFileProxy(); IFileStore exeFS = exeRFP.getResource(exeURI.getPath()); IFileInfo exeFI = exeFS.fetchInfo(); if (exeFI.isDirectory()) { // Assume the user wants to copy the file to the given directory, using // the same filename as the "copy from" executable. IPath copyExePath = Path.fromOSString(copyExeURI.getPath()); IPath newExePath = Path.fromOSString(exeURI.getPath()).append(copyExePath.lastSegment()); // update the exeURI with the new path. exeURI = new URI( exeURI.getScheme(), exeURI.getAuthority(), newExePath.toString(), exeURI.getQuery(), exeURI.getFragment()); exeFS = exeRFP.getResource(exeURI.getPath()); } copyExeFS.copy(exeFS, EFS.OVERWRITE | EFS.SHALLOW, new SubProgressMonitor(monitor, 1)); // Note: assume that we don't need to create a new exeRC since the // scheme and authority remain the same between the original exeURI and the new one. } IPath remoteBinFile = Path.fromOSString(exeURI.getPath()); IFileStore workingDir; URI workingDirURI = new URI(RemoteProxyManager.getInstance().getRemoteProjectLocation(project)); RemoteConnection workingDirRC = new RemoteConnection(workingDirURI); IRemoteFileProxy workingDirRFP = workingDirRC.getRmtFileProxy(); workingDir = workingDirRFP.getResource(workingDirURI.getPath()); // Build the commandline string to run perf recording the given project String arguments[] = getProgramArgumentsArray(config); // Program args from launch config. ArrayList<String> command = new ArrayList<>(4 + arguments.length); Version perfVersion = PerfCore.getPerfVersion(config); command.addAll( Arrays.asList( PerfCore.getRecordString( config, perfVersion))); // Get the base commandline string (with flags/options based on // config) command.add(remoteBinFile.toOSString()); // Add the path to the executable command.set(0, perfPathString); command.add(2, OUTPUT_STR + configWorkingDir + PerfPlugin.PERF_DEFAULT_DATA); // Compile string command.addAll(Arrays.asList(arguments)); // Spawn the process String[] commandArray = command.toArray(new String[command.size()]); Process pProxy = RuntimeProcessFactory.getFactory() .exec(commandArray, getEnvironment(config), workingDir, project); MessageConsole console = new MessageConsole("Perf Console", null); // $NON-NLS-1$ console.activate(); ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console}); MessageConsoleStream stream = console.newMessageStream(); if (pProxy != null) { try (BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream()))) { String err = error.readLine(); while (err != null) { stream.println(err); err = error.readLine(); } } } /* This commented part is the basic method to run perf record without integrating into eclipse. String binCall = exePath.toOSString(); for(String arg : arguments) { binCall.concat(" " + arg); } PerfCore.Run(binCall);*/ pProxy.destroy(); PrintStream print = null; if (config.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true)) { // Get the console to output to. // This may not be the best way to accomplish this but it shall do for now. ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); IConsole[] existing = conMan.getConsoles(); IOConsole binaryOutCons = null; // Find the console for (IConsole x : existing) { if (x.getName().contains(renderProcessLabel(commandArray[0]))) { binaryOutCons = (IOConsole) x; } } if ((binaryOutCons == null) && (existing.length != 0)) { // if can't be found get the most recent opened, this should probably // never happen. if (existing[existing.length - 1] instanceof IOConsole) binaryOutCons = (IOConsole) existing[existing.length - 1]; } // Get the printstream via the outputstream. // Get ouput stream OutputStream outputTo; if (binaryOutCons != null) { outputTo = binaryOutCons.newOutputStream(); // Get the printstream for that console print = new PrintStream(outputTo); } for (int i = 0; i < command.size(); i++) { print.print(command.get(i) + " "); // $NON-NLS-1$ } // Print Message print.println(); print.println("Analysing recorded perf.data, please wait..."); // $NON-NLS-1$ // Possibly should pass this (the console reference) on to PerfCore.Report if theres // anything we ever want to spit out to user. } PerfCore.report( config, getEnvironment(config), Path.fromOSString(configWorkingDir), monitor, null, print); URI perfDataURI = null; IRemoteFileProxy proxy = null; perfDataURI = new URI( RemoteProxyManager.getInstance().getRemoteProjectLocation(project) + PerfPlugin.PERF_DEFAULT_DATA); proxy = RemoteProxyManager.getInstance().getFileProxy(perfDataURI); IFileStore perfDataFileStore = proxy.getResource(perfDataURI.getPath()); IFileInfo info = perfDataFileStore.fetchInfo(); info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true); perfDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null); PerfCore.refreshView(renderProcessLabel(exeURI.getPath())); if (config.getAttribute( PerfPlugin.ATTR_ShowSourceDisassembly, PerfPlugin.ATTR_ShowSourceDisassembly_default)) { showSourceDisassembly( Path.fromPortableString(workingDirURI.toString() + IPath.SEPARATOR)); } } } catch (IOException e) { e.printStackTrace(); abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); } catch (RemoteConnectionException e) { e.printStackTrace(); abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); } catch (URISyntaxException e) { e.printStackTrace(); abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); } }