/** * Gets the validation report from the validator. * * @param source the source text * @param path the source path * @return the report */ private static String getReport(String source, URI path) { StyleSheetParser parser = new StyleSheetParser(); ApplContext ac = new ApplContext("en"); // $NON-NLS-1$ ac.setProfile(APTANA_PROFILE); try { parser.parseStyleElement( ac, new ByteArrayInputStream(source.getBytes(IOUtil.UTF_8)), null, null, path.toURL(), 0); } catch (MalformedURLException e) { IdeLog.logError( CSSPlugin.getDefault(), MessageFormat.format(Messages.CSSValidator_ERR_InvalidPath, path), e); } catch (UnsupportedEncodingException e) { IdeLog.logError(CSSPlugin.getDefault(), e); } StyleSheet stylesheet = parser.getStyleSheet(); stylesheet.findConflicts(ac); StyleReport report = StyleReportFactory.getStyleReport( ac, "Title", stylesheet, "soap12", 2); // $NON-NLS-1$ //$NON-NLS-2$ ByteArrayOutputStream out = new ByteArrayOutputStream(); report.print(new PrintWriter(out)); return out.toString().replaceAll("m:", ""); // $NON-NLS-1$ //$NON-NLS-2$ }
/** * Download the remote content and store it the temp directory. * * @param URLs * @param progressMonitor */ public IStatus download(String[] URLs, IProgressMonitor progressMonitor) { if (URLs.length == 0) { String err = Messages.InstallerConfigurationProcessor_missingDownloadTargets; applyErrorAttributes(err); IdeLog.logError( PortalUIPlugin.getDefault(), "We expected an array of URLs, but got an empty array.", new Exception(err)); // $NON-NLS-1$ return new Status(IStatus.ERROR, PortalUIPlugin.PLUGIN_ID, err); } downloadedPaths = null; DownloadManager downloadManager = new DownloadManager(); List<URI> urlsList = new ArrayList<URI>(URLs.length); for (int i = 0; i < URLs.length; i++) { try { urlsList.add(new URI(urls[i])); } catch (URISyntaxException mue) { IdeLog.logError(PortalUIPlugin.getDefault(), mue); } } try { downloadManager.addURIs(urlsList); IStatus status = downloadManager.start(progressMonitor); if (status.isOK()) { downloadedPaths = downloadManager.getContentsLocations(); } return status; } catch (Exception e) { IdeLog.logError(PortalUIPlugin.getDefault(), e); } return Status.CANCEL_STATUS; }
/** * Install an extension directly into profile location * * @param extensionURL * @param extensionID * @param dir * @return boolean */ public static boolean installExtension(URL extensionURL, String extensionID, File dir) { dir = new File(dir, extensionID); if (dir.exists()) { return true; } if (!dir.mkdirs()) { return false; } File file = null; InputStream in = null; FileOutputStream out = null; try { file = File.createTempFile("ffe", ".zip"); // $NON-NLS-1$ //$NON-NLS-2$ in = extensionURL.openStream(); out = new FileOutputStream(file); byte[] buffer = new byte[0x1000]; int n; while ((n = in.read(buffer)) > 0) { out.write(buffer, 0, n); } } catch (IOException e) { IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e); if (file != null) { if (!file.delete()) { file.deleteOnExit(); } } return false; } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } } } try { ZipUtil.extract(file, dir, null); } catch (IOException e) { IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e); return false; } finally { if (!file.delete()) { file.deleteOnExit(); } } return true; }
/** * Sends a ping. * * @param event * @param user * @return The ping response code. */ protected int sendPing(AnalyticsEvent event, IAnalyticsUser user) { HttpURLConnection connection = null; DataOutputStream output = null; try { URL url = new URL(getAnalyticsURL()); connection = (HttpURLConnection) url.openConnection(); if (user != null) { connection.setRequestProperty( "Cookie", user.getCookie() + "; uid=" + user.getGUID()); // $NON-NLS-1$ //$NON-NLS-2$ } connection.setRequestProperty("User-Agent", AnalyticsEvent.getUserAgent()); // $NON-NLS-1$ connection.setDoOutput(true); connection.setReadTimeout(getTimeout()); connection.setConnectTimeout(getTimeout()); connection.setRequestMethod("POST"); // $NON-NLS-1$ // writes POST output = new DataOutputStream(connection.getOutputStream()); String data = event.getEventString(); output.writeBytes(data); output.flush(); if (IdeLog.isTraceEnabled(UsagePlugin.getDefault(), IDebugScopes.USAGE)) { IdeLog.logTrace( UsagePlugin.getDefault(), MessageFormat.format("Sending usage: {0}, {1}", url, data)); // $NON-NLS-1$ } int code = connection.getResponseCode(); if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) { UsagePlugin.logError( MessageFormat.format( Messages.StudioAnalytics_connection_unauthorized, Integer.toString(code))); } else if (code < 200 || code > 205) { UsagePlugin.logError( MessageFormat.format( Messages.StudioAnalytics_connection_failed, Integer.toString(code))); } return code; } catch (Exception e) { UsagePlugin.logError(e); return HttpURLConnection.HTTP_UNAVAILABLE; } finally { if (output != null) { try { output.close(); } catch (IOException ignore) { } } if (connection != null) { connection.disconnect(); } } }
/** * Find location of user's default(current) Firefox profile. * * @return IPath */ public static IPath findDefaultProfileLocation() { String[] locations = (String[]) LOCATIONS.get(Platform.getOS()); if (locations != null) { for (int i = 0; i < locations.length; ++i) { String location = PlatformUtil.expandEnvironmentStrings(locations[i]); File dir = new File(location); if (!dir.isDirectory()) { continue; } IdeLog.logInfo( CorePlugin.getDefault(), MessageFormat.format( "Check location {0} for default profile", location)); // $NON-NLS-1$ File[] profiles = readProfiles(dir); if (profiles.length == 0) { File dirProfiles = new File(dir, "Profiles"); // $NON-NLS-1$ if (!dirProfiles.exists() || !dirProfiles.isDirectory()) { dirProfiles = dir; } profiles = dirProfiles.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".default"); // $NON-NLS-1$ } }); } // Debug output StringBuffer sb = new StringBuffer(); for (int j = 0; j < profiles.length; ++j) { if (j != 0) { sb.append(','); } sb.append(profiles[j].toString()); } IdeLog.logInfo( CorePlugin.getDefault(), MessageFormat.format("Profiles found: {0}", sb.toString())); // $NON-NLS-1$ // End of Debug output for (File profile : profiles) { if (profile.isDirectory()) { IdeLog.logInfo( CorePlugin.getDefault(), MessageFormat.format( "Default profile was found at {0}", profile.toString())); // $NON-NLS-1$ return Path.fromOSString(profile.getAbsolutePath()); } } } } return null; }
/* * (non-Javadoc) * @see com.aptana.index.core.IIndexFileContributor#contributeFiles(java.net.URI) */ public Set<IFileStore> getFiles(URI containerURI) { IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(containerURI); Set<IFileStore> result = new HashSet<IFileStore>(); if (containers != null && containers.length > 0) { for (IContainer container : containers) { if (container instanceof IProject) { IProject project = (IProject) container; Set<BuildPathEntry> entries = BuildPathManager.getInstance().getBuildPaths(project); if (entries != null) { for (BuildPathEntry entry : entries) { try { IFileStore fileStore = EFS.getStore(entry.getPath()); result.add(fileStore); } catch (CoreException e) { IdeLog.logError(BuildPathCorePlugin.getDefault(), e.getMessage(), e); } } } } } } return result; }
/** * Makes a copy of the internal list of changed files so that iterating won't ever result in a * ConcurrentModificationException. try to avoid use if possible, since a deep copy is made which * can be expensive. This method populates the changedFiles collection lazily on first demand. * * @return */ public List<ChangedFile> changedFiles() { boolean isNull = false; synchronized (this.changedFilesLock) { isNull = (this.changedFiles == null); } if (isNull) { // Don't want to call back to fireIndexChangeEvent yet! IStatus status = refresh(false, null, new NullProgressMonitor()); if (!status.isOK()) { IdeLog.logError(GitPlugin.getDefault(), status.getMessage()); return Collections.emptyList(); } } synchronized (this.changedFilesLock) { if (this.changedFiles == null) { return Collections.emptyList(); } List<ChangedFile> copy = new ArrayList<ChangedFile>(this.changedFiles.size()); for (ChangedFile file : this.changedFiles) { copy.add(new ChangedFile(file)); } return copy; } }
/** * Returns the defined encoding for the given module. * * <pre> * The search for the encoding is done in this order: * 1. Check the encoding that is set specifically to a LocalModule. * 2. Check the workspace default charset. * 3. If all the above fails, get ResourcesPlugin.getEncoding(), which actually gets the encoding from the system. * </pre> * * @param module an {@link IModule}. * @return The module's encoding. */ public static String getModuleEncoding(IModule module) { String charset = null; try { if (module instanceof LocalModule) { IFile file = ((LocalModule) module).getFile(); if (file != null) { String fileCharset = file.getCharset(true); if (fileCharset != null) { charset = fileCharset; } } } } catch (Throwable e) { // If there is any error, return the default IdeLog.logInfo( PHPEditorPlugin.getDefault(), "PHP encoding utils - Returning the default encoding due to an error (getModuleEncoding)", //$NON-NLS-1$ e, PHPEditorPlugin.DEBUG_SCOPE); } if (charset == null) { try { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); charset = workspaceRoot.getDefaultCharset(true); } catch (CoreException ce) { charset = WorkbenchEncoding.getWorkbenchDefaultEncoding(); } } if (charset == null) { // Use the system's encoding charset = ResourcesPlugin.getEncoding(); } return charset; }
public void updateTaskTags( final String contents, final Program program, final List<Comment> comments, IModule module) { try { if (module instanceof LocalModule) { LocalModule lm = (LocalModule) module; final IFile file = lm.getFile(); // TODO get project level task tags/prefs when we support them. Collection<TaskTag> tags = TaskTag.getTaskTags(); boolean isCaseSensitive = TaskTag.isCaseSensitive(); program.setLineEndTable(Util.lineEndTable(new Document(contents))); // visit the comment nodes and parse for tasks! Collection<Task> tasks = new ArrayList<Task>(); for (Comment comment : comments) { tasks.addAll(processCommentNode(program, contents, isCaseSensitive, tags, comment)); } final Task[] finalTasks = tasks.toArray(new Task[tasks.size()]); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) { doHandleErrorsJob(finalTasks, file); } }; ResourcesPlugin.getWorkspace() .run(runnable, getMarkerRule(file), IWorkspace.AVOID_UPDATE, new NullProgressMonitor()); } } catch (Exception e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the PHP task-tags.", e, PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } }
/** * Install an extension using linked method * * @param extensionURL * @param extensionID * @param dir * @return boolean */ public static boolean installLinkedExtension(URL extensionURL, String extensionID, File dir) { File file = new File(dir, extensionID); if (file.exists() && file.isDirectory()) { return true; } IPath base = CorePlugin.getDefault().getStateLocation().addTrailingSeparator(); boolean result = installExtension(extensionURL, extensionID, base.toFile()); if (result) { String linkedPath = base.append(extensionID).toOSString(); FileOutputStream out = null; try { out = new FileOutputStream(file); out.write(linkedPath.getBytes()); } catch (IOException e) { IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } } return result; }
/* * @see IPainter#paint(int) */ public void paint(int reason) { if (fViewer == null) { return; } if (fViewer.getDocument() == null) { deactivate(false); return; } // initialization if (!fIsActive) { StyledText textWidget = fViewer.getTextWidget(); textWidget.addLineBackgroundListener(this); textWidget.addPaintListener(this); fPositionManager.managePosition(fCurrentLine); fIsActive = true; } // This forces redraw of the line highlight if (updateHighlightLine()) { // clear last line // Fix the background colors for tokens that didn't have the same as line! if (isOpaque() && !fLastLine.isDeleted() && fViewer instanceof ITextViewerExtension2) { ITextViewerExtension2 ext = (ITextViewerExtension2) fViewer; try { ext.invalidateTextPresentation(fLastLine.getOffset(), fLastLine.getLength()); } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } } drawHighlightLine(fLastLine); // draw new line drawHighlightLine(fCurrentLine); } }
/** * Process all metadata files via the metadata reader returned by createMetadataReader * * @param monitor * @param reader * @param resources */ private void loadMetadata(IProgressMonitor monitor, T reader, String... resources) { SubMonitor subMonitor = SubMonitor.convert(monitor, resources.length); for (String resource : resources) { URL url = FileLocator.find(this.getBundle(), new Path(resource), null); if (url != null) { InputStream stream = null; try { stream = url.openStream(); reader.loadXML(stream, url.toString()); } catch (Throwable t) { IdeLog.logError( CommonEditorPlugin.getDefault(), Messages.MetadataLoader_Error_Loading_Metadata + resource, t); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } } subMonitor.worked(1); } subMonitor.done(); }
private void buildFile( BuildContext context, List<IBuildParticipant> participants, IProgressMonitor monitor) throws CoreException { if (CollectionsUtil.isEmpty(participants)) { return; } SubMonitor sub = SubMonitor.convert(monitor, 2 * participants.size()); for (IBuildParticipant participant : participants) { long startTime = System.nanoTime(); participant.buildFile(context, sub.newChild(1)); if (traceParticipantsEnabled) { double endTime = ((double) System.nanoTime() - startTime) / 1000000; IdeLog.logTrace( BuildPathCorePlugin.getDefault(), MessageFormat.format( "Executed build participant ''{0}'' on ''{1}'' in {2} ms.", participant.getName(), context.getURI(), endTime), IDebugScopes.BUILDER_PARTICIPANTS); // $NON-NLS-1$ } // stop building if it has been canceled if (sub.isCanceled()) { break; } } updateMarkers(context, sub.newChild(participants.size())); sub.done(); }
/** * Cache the installed application location and version in the preferences. * * @param installDir - The directory the application was installed to. * @param versionedFileLocation - Can be the URL that we grabbed the installer from, or any other * string that contains a version information in a form of x.y.z. * @param appName - The application name (e.g. xampp) */ @SuppressWarnings("unchecked") public void cacheVersion(String installDir, String versionedFileLocation, String appName) { IPreferenceStore preferenceStore = PortalUIPlugin.getDefault().getPreferenceStore(); String versions = preferenceStore.getString(IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME); Map<String, Map<String, String>> versionsMap = null; if (versions == null || versions.equals(StringUtil.EMPTY)) { versionsMap = new HashMap<String, Map<String, String>>(); } else { versionsMap = (Map<String, Map<String, String>>) JSON.parse(versions); } Map<String, String> appVersionMap = new HashMap<String, String>(); Version version = VersionUtil.parseVersion(versionedFileLocation); if (!VersionUtil.isEmpty(version)) { appVersionMap.put(IPortalPreferences.CACHED_VERSION_PROPERTY, version.toString()); appVersionMap.put(IPortalPreferences.CACHED_LOCATION_PROPERTY, installDir); versionsMap.put(appName.toLowerCase(), appVersionMap); preferenceStore.setValue( IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME, JSON.toString(versionsMap)); } else { IdeLog.logError( PortalUIPlugin.getDefault(), MessageFormat.format( "Could not cache the location and version for {0}. Install dir: {1}, versionedFileLocation: {2}", //$NON-NLS-1$ appName, installDir, versionedFileLocation), new Exception()); } }
/** * Loads our CSS profile. * * @throws IOException if profile loading fails */ private static void loadAptanaCSSProfile() { InputStream configStream = CSSValidator.class.getResourceAsStream(CONFIG_FILE); InputStream profilesStream = CSSValidator.class.getResourceAsStream(PROFILES_CONFIG_FILE); try { // loads our config PropertiesLoader.config.load(configStream); // loads our profile Utf8Properties profiles = new Utf8Properties(); profiles.load(profilesStream); // a hack, but no other way since PropertiesLoader provides no public access to stored // profiles Field field = PropertiesLoader.class.getDeclaredField("profiles"); // $NON-NLS-1$ field.setAccessible(true); field.set(null, profiles); } catch (Exception e) { IdeLog.logError(CSSPlugin.getDefault(), Messages.CSSValidator_ERR_FailToLoadProfile, e); } finally { try { configStream.close(); } catch (IOException e) { } try { profilesStream.close(); } catch (IOException e) { } } }
/** * Locates a PHPDoc comment above the offset in the document specified. In case the given entry is * a parameter variable, the search for the documentation will include the documentation of the * parameter's wrapping function. * * @param entry * @param document * @param offset * @return A {@link PHPDocBlock}, or <code>null</code>. */ public static PHPDocBlock findFunctionPHPDocComment( IElementEntry entry, IDocument document, int offset) { boolean isParameter = ((entry.getValue() instanceof VariablePHPEntryValue) && ((VariablePHPEntryValue) entry.getValue()).isParameter()); if (entry.getModule() != null) { return findFunctionPHPDocComment(entry.getModule(), document, offset, isParameter); } // In case that the entry module is null, it's probably a PHP API documentation item, so // parse the right item. try { String entryPath = entry.getEntryPath(); if (entryPath != null) { InputStream stream = PHPBuiltins.getInstance().getBuiltinResourceStream(entryPath); if (stream != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // $codepro.audit.disable // closeWhereCreated return innerParsePHPDoc(offset, reader, isParameter); } } } catch (Exception ex) { IdeLog.logError( PHPEditorPlugin.getDefault(), "Failed locating the PHP function doc", ex); // $NON-NLS-1$ return null; } return null; }
/** Start the server that listens on a socket for command line arguments. */ public static void startServer() { try { CommandLineArgsServer server = new CommandLineArgsServer(); server.start(); } catch (IOException e) { IdeLog.logError(CommandlineLauncherPlugin.getDefault(), e); } }
public IStatus unstageFiles(Collection<ChangedFile> unstageFiles) { if (CollectionsUtil.isEmpty(unstageFiles)) { // no-op, return OK return Status.OK_STATUS; } StringBuilder input = new StringBuilder(); for (ChangedFile file : unstageFiles) { input.append(file.indexInfo()); } IStatus result = repository.executeWithInput( input.toString(), "update-index", "-z", "--index-info"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (result == null) { return new Status( IStatus.ERROR, GitPlugin.PLUGIN_ID, "Failed to unstage files. Process failed to run."); //$NON-NLS-1$ } if (!result.isOK()) { IdeLog.logError( GitPlugin.getDefault(), MessageFormat.format("Failed to stage files: {0}", result.getMessage()), IDebugScopes.DEBUG); // $NON-NLS-1$ return result; } // Update the staged/unstaged flags in the passed in copy of changed files, and our internal // list of changed // files. ArrayList<ChangedFile> preFiles = new ArrayList<ChangedFile>(unstageFiles.size()); for (ChangedFile file : unstageFiles) { preFiles.add(new ChangedFile(file)); synchronized (this.changedFilesLock) { if (this.changedFiles != null) { int index = Collections.binarySearch(this.changedFiles, file); if (index >= 0) { ChangedFile orig = this.changedFiles.get(index); orig.hasUnstagedChanges = true; orig.hasStagedChanges = false; } } } file.hasUnstagedChanges = true; file.hasStagedChanges = false; } preFiles.trimToSize(); postIndexChange(preFiles, unstageFiles); return result; }
@SuppressWarnings("rawtypes") @Override protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { traceParticipantsEnabled = IdeLog.isTraceEnabled(BuildPathCorePlugin.getDefault(), IDebugScopes.BUILDER_PARTICIPANTS); boolean logTraceEnabled = traceLoggingEnabled(); IProject project = getProjectHandle(); String projectName = project.getName(); long startTime = System.nanoTime(); SubMonitor sub = SubMonitor.convert(monitor, 100); // Keep these build participant instances and use them in the build process, rather than // grabbing new ones // in sub-methods. We do pre- and post- setups on them, so we need to retain instances. IBuildParticipantManager manager = getBuildParticipantManager(); if (manager == null) { return new IProject[0]; } List<IBuildParticipant> participants = manager.getAllBuildParticipants(); participants = filterToEnabled(participants, project); buildStarting(participants, kind, sub.newChild(10)); if (kind == IncrementalProjectBuilder.FULL_BUILD) { if (logTraceEnabled) { logTrace(MessageFormat.format(Messages.UnifiedBuilder_PerformingFullBuld, projectName)); } fullBuild(participants, sub.newChild(80)); } else { IResourceDelta delta = getResourceDelta(); if (delta == null) { if (logTraceEnabled) { logTrace( MessageFormat.format( Messages.UnifiedBuilder_PerformingFullBuildNullDelta, projectName)); } fullBuild(participants, sub.newChild(80)); } else { if (logTraceEnabled) { logTrace( MessageFormat.format( Messages.UnifiedBuilder_PerformingIncrementalBuild, projectName)); } incrementalBuild(participants, delta, sub.newChild(80)); } } buildEnding(participants, sub.newChild(10)); if (logTraceEnabled) { double endTime = ((double) System.nanoTime() - startTime) / 1000000; logTrace(MessageFormat.format(Messages.UnifiedBuilder_FinishedBuild, projectName, endTime)); } return null; }
/** * Opens the internal HelpView and address it to the given doc url. * * @param url */ public static void openHelp(String url) { IWorkbenchPage page = getActivePage(); if (page != null) { try { IViewPart part = page.showView(HELP_VIEW_ID); if (part != null) { HelpView view = (HelpView) part; view.showHelp(url); } } catch (PartInitException e) { IdeLog.logError(UIPlugin.getDefault(), e); } } else { IdeLog.logWarning( UIPlugin.getDefault(), "Could not open the help view. Active page was null."); //$NON-NLS-1$ } }
public IStatus stageFiles(Collection<ChangedFile> stageFiles) { if (CollectionsUtil.isEmpty(stageFiles)) { // no-op return Status.OK_STATUS; } StringBuffer input = new StringBuffer(stageFiles.size() * stageFiles.iterator().next().getPath().length()); for (ChangedFile file : stageFiles) { input.append(file.getPath()).append('\n'); } @SuppressWarnings("nls") IStatus result = repository.executeWithInput( input.toString(), "update-index", "--add", "--remove", "--stdin"); if (result == null) { return new Status( IStatus.ERROR, GitPlugin.PLUGIN_ID, "Failed to stage files. Process failed to run."); //$NON-NLS-1$; } if (!result.isOK()) { IdeLog.logError( GitPlugin.getDefault(), MessageFormat.format("Failed to stage files: {0}", result.getMessage()), IDebugScopes.DEBUG); // $NON-NLS-1$ return result; } ArrayList<ChangedFile> preFiles = new ArrayList<ChangedFile>(stageFiles.size()); // Update the staged/unstaged flags in the passed in copy of changed files, and our internal // list of changed // files. for (ChangedFile file : stageFiles) { preFiles.add(new ChangedFile(file)); synchronized (changedFilesLock) { if (this.changedFiles != null) { int index = Collections.binarySearch(this.changedFiles, file); if (index >= 0) { ChangedFile orig = this.changedFiles.get(index); orig.hasUnstagedChanges = false; orig.hasStagedChanges = true; } } } file.hasUnstagedChanges = false; file.hasStagedChanges = true; } preFiles.trimToSize(); postIndexChange(preFiles, stageFiles); return result; }
void doHandleErrorsJob(Task[] errors, IFile file) { synchronized (this) // prevent simultaneous error updates on the same file { if (ResourcesPlugin.getWorkspace().isTreeLocked()) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the document errors. The workspace tree is locked.", PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } if (file == null || !file.exists()) { return; } int depth = IResource.DEPTH_INFINITE; try { IMarker[] problemMarkers = file.findMarkers(IMarker.TASK, true, depth); for (IMarker m : problemMarkers) { Object attribute2 = m.getAttribute(APTANA_TASK); if (attribute2 != null && attribute2.equals("true")) // $NON-NLS-1$ { m.delete(); } } for (Task t : errors) { IMarker problemMarker = file.createMarker(IMarker.TASK); problemMarker.setAttribute(IMarker.PRIORITY, t.getPriority()); problemMarker.setAttribute(IMarker.CHAR_START, t.getStart()); problemMarker.setAttribute(IMarker.CHAR_END, t.getEnd()); problemMarker.setAttribute(APTANA_TASK, Boolean.TRUE.toString()); problemMarker.setAttribute(IMarker.MESSAGE, t.getDescription()); problemMarker.setAttribute(IMarker.LINE_NUMBER, t.getLineNumber()); } } catch (Exception e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the PHP task-tags.", e, PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } } }
/** * Sets the scanner offset to the given offset. * * @param offset The offset to set * @throws IOException */ public void setOffset(int offset) { this.offset = offset; charReader.reset(offset); try { scanner.yyreset(charReader); scanner.setInScriptingState(); scanner.resetCommentList(); } catch (IOException e) { IdeLog.logError( PHPEplPlugin.getDefault(), "Error setting a PHP token-scanner offset", e); // $NON-NLS-1$ } }
/** * Select a PHP version. * * @param phpAlias The version alias. */ private void setSelectedVersion(String phpAlias) { int index = PHPVersionConfigurationBlock.PHP_ALIASES.indexOf(phpAlias); if (index < 0) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Unresolved PHP version: " + phpAlias, new Exception("Unresolved PHP version"), PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ //$NON-NLS-2$ index = 0; } fPHPVersions.select(index); }
/** * Returns the Shell command path. * * @return The shell command path. */ public static String getShellPath() { try { IPath path = ShellExecutable.getPath(); if (path != null) { return path.toOSString(); } } catch (CoreException e) { IdeLog.logError(ConfigurationsPlugin.getDefault(), e); } return null; }
private void openIndexFile() { IFile indexFile = newProject.getFile("index.html"); // $NON-NLS-1$ if (indexFile.exists()) { IWorkbenchPage page = UIUtils.getActivePage(); if (page != null) { try { IDE.openEditor(page, indexFile); } catch (PartInitException e) { IdeLog.logError( SamplesUIPlugin.getDefault(), Messages.NewSampleProjectWizard_ERR_OpenIndexFile, e); } } } }
protected void openIndexFile(boolean activatateEditor) { IFile indexFile = newProject.getFile("index.html"); // $NON-NLS-1$ if (indexFile.exists()) { IWorkbenchPage page = UIUtils.getActivePage(); if (page != null) { try { IDE.openEditor(page, indexFile, activatateEditor); } catch (PartInitException e) { IdeLog.logError( ProjectsPlugin.getDefault(), Messages.NewProjectWizard_ERR_OpeningIndex, e); } } } }
protected void loadState(IMemento memento) { IMemento child = memento.getChild(ELEMENT_NAME); if (child != null) { name = child.getTextData(); } child = memento.getChild(ELEMENT_SOURCE); if (child != null) { URI uri = URI.create(child.getTextData()); sourceConnectionPoint = ConnectionPointUtils.findConnectionPoint(uri); if (sourceConnectionPoint == null) { IdeLog.logWarning( SyncingPlugin.getDefault(), "Failed to load source connection point from URI " + uri, // $NON-NLS-1$ IDebugScopes.DEBUG); } } child = memento.getChild(ELEMENT_DESTINATION); if (child != null) { URI uri = URI.create(child.getTextData()); destinationConnectionPoint = ConnectionPointUtils.findConnectionPoint(uri); if (destinationConnectionPoint == null) { IdeLog.logWarning( SyncingPlugin.getDefault(), "Failed to load destination connection point from URI " + uri, // $NON-NLS-1$ IDebugScopes.DEBUG); } } child = memento.getChild(ELEMENT_EXCLUDES); if (child != null) { for (IMemento i : child.getChildren(ELEMENT_PATH)) { excludes.add(Path.fromPortableString(i.getTextData())); } for (IMemento i : child.getChildren(ELEMENT_WILDCARD)) { excludes.add(i.getTextData()); } } }
/** * Constructs include path from one module to another. * * @param from - module to construct include path from. * @param to - module to construct include path to. * @return constructed include path */ public static ConstructedIncludePath constructIncludePath(IModule from, IModule to) { IBuildPath fromBuildPath = from.getBuildPath(); IBuildPath toBuildPath = to.getBuildPath(); Set<IBuildPath> fromDependencies = fromBuildPath.getDependencies(); if (fromDependencies.equals(toBuildPath)) { String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, null, null); } // if "from" build-path directly depends from "to" build-path if (fromDependencies.contains(toBuildPath)) { String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, null, null); } else { // for local modules using its project-based build-path instead of native module build-path if (to instanceof LocalModule) { IFile file = ((LocalModule) to).getFile(); if (!file.isSynchronized(1)) { try { file.refreshLocal(1, new NullProgressMonitor()); if (file.exists()) { IProject project = file.getProject(); IBuildPath projectBuildPath = BuildPathManager.getInstance().getBuildPathByResource(project); if (projectBuildPath != null) { IModule alternativeToModule = projectBuildPath.getModule(file); if (alternativeToModule != null) { String includePath = constructPathFromRoot(alternativeToModule); return new ConstructedIncludePath(includePath, fromBuildPath, projectBuildPath); } } } } catch (CoreException e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "PHP Refactoring - Error while constructing an include-path (constructIncludePath)", //$NON-NLS-1$ e, PHPEditorPlugin.DEBUG_SCOPE); } } } // in other case, using original build-paths for reporting unsatisfied state String includePath = constructPathFromRoot(to); return new ConstructedIncludePath(includePath, fromBuildPath, toBuildPath); } }
private ISourceLocator getDefaultSourceLocator() { if (fDefaultSourceLocator == null) { try { fDefaultSourceLocator = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(DEFAULT_SOURCE_LOCATOR_ID); if (fDefaultSourceLocator instanceof ISourceLookupDirector) { ISourceLookupDirector sourceLookupDirector = (ISourceLookupDirector) fDefaultSourceLocator; sourceLookupDirector.initializeParticipants(); sourceLookupDirector.setSourceContainers( new ISourceContainer[] { new DefaultSourceContainer() { /* * (non-Javadoc) * @see org.eclipse.debug.core.sourcelookup.containers. * DefaultSourceContainer#createSourceContainers() */ @Override protected ISourceContainer[] createSourceContainers() throws CoreException { ISourcePathComputer sourcePathComputer = null; ISourceLookupDirector director = getDirector(); if (director != null) { sourcePathComputer = director.getSourcePathComputer(); } if (sourcePathComputer != null) { return sourcePathComputer.computeSourceContainers(null, null); } return EMPTY_CONTAINERS; } } }); ISourcePathComputer sourcePathComputer = DebugPlugin.getDefault() .getLaunchManager() .getSourcePathComputer(DEFAULT_SOURCE_PATH_COMPUTER_ID); sourceLookupDirector.setSourcePathComputer(sourcePathComputer); } } catch (CoreException e) { IdeLog.logError(JSDebugUIPlugin.getDefault(), e); } } return fDefaultSourceLocator; }