Java Code Examples for org.eclipse.core.resources.IResource#getPersistentProperty()
The following examples show how to use
org.eclipse.core.resources.IResource#getPersistentProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TmfExperiment.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Check if an experiment contains traces of all the same type. If so, * returns this type as a String. If not, returns null. * * @param experiment * The experiment * @return The common trace type if there is one, or 'null' if there are * different types. */ private @Nullable String getCommonTraceType() { String commonTraceType = null; try { for (final ITmfTrace trace : getTraces()) { final IResource resource = trace.getResource(); if (resource == null) { return null; } final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE); if ((commonTraceType != null) && !commonTraceType.equals(traceType)) { return null; } commonTraceType = traceType; } } catch (CoreException e) { /* * One of the traces didn't advertise its type, we can't infer * anything. */ return null; } return commonTraceType; }
Example 2
Source File: GdbTrace.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@Override public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException { try { String tracedExecutable = resource.getPersistentProperty(EXEC_KEY); if (tracedExecutable == null) { throw new TmfTraceException(Messages.GdbTrace_ExecutableNotSet); } String defaultGdbCommand = Platform.getPreferencesService().getString(GdbPlugin.PLUGIN_ID, IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND, IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT, null); fGdbTpRef = new DsfGdbAdaptor(this, defaultGdbCommand, path, tracedExecutable); fNbFrames = getNbFrames(); } catch (CoreException e) { throw new TmfTraceException(Messages.GdbTrace_FailedToInitializeTrace, e); } super.initTrace(resource, path, type); }
Example 3
Source File: LttngRelaydConnectionManager.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private static LttngRelaydConnectionInfo getEntry(final ITmfTrace trace) throws CoreException { if (trace instanceof CtfTmfTrace) { CtfTmfTrace ctfTmfTrace = (CtfTmfTrace) trace; if (!ctfTmfTrace.isComplete()) { IResource resource = ctfTmfTrace.getResource(); String host = resource.getPersistentProperty(CtfConstants.LIVE_HOST); String port = resource.getPersistentProperty(CtfConstants.LIVE_PORT); String sessionName = resource.getPersistentProperty(CtfConstants.LIVE_SESSION_NAME); if (host != null && port != null && sessionName != null && !sessionName.isEmpty()) { LttngRelaydConnectionInfo entry = new LttngRelaydConnectionInfo(host, Integer.parseInt(port), sessionName); return entry; } } } return null; }
Example 4
Source File: OriginalEditorSelector.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected IEditorDescriptor findXbaseEditor(String fileName, boolean ignorePreference) { if (decisions.isJDI()) { String file = debugPluginListener.findXtextSourceFileNameForClassFile(fileName); if (file != null) return getXtextEditor(URI.createURI(file)); } if (decisions.decideAccordingToCallerForSimpleFileName() == Decision.FORCE_JAVA) { return null; } IType type = findJavaTypeForSimpleFileName(fileName); if (type != null) { if (!ignorePreference) { IResource resource = type.getResource(); if (resource != null) { try { // the user has chosen to always use a particular editor, e.g. by means of // Open With in the package explorer String favoriteEditor = resource.getPersistentProperty(IDE.EDITOR_KEY); if (favoriteEditor != null) return null; } catch (CoreException e) { logger.debug(e.getMessage(), e); } } } IEclipseTrace trace = traceForTypeRootProvider.getTraceToSource(type.getTypeRoot()); return getXtextEditor(trace); } return null; }
Example 5
Source File: TexlipseProperties.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * Read a project property. * * @param project the current project * @param property the name of the property * @return the value of the named project property or null if the property is not found */ public static String getProjectProperty(IResource project, String property) { String value = null; try { value = project.getPersistentProperty(new QualifiedName(TexlipseProperties.PACKAGE_NAME, property)); } catch (CoreException e) { // do nothing } return value; }
Example 6
Source File: TimestampTransformFactory.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Returns the file resource used to store synchronization formula. The file * may not exist. * * @param resource * the trace resource * @return the synchronization file */ private static @Nullable File getSyncFormulaFile(@Nullable IResource resource) { if (resource == null) { return null; } try { String supplDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); return new File(supplDirectory + File.separator + SYNCHRONIZATION_FORMULA_FILE); } catch (CoreException e) { /* Ignored */ } return null; }
Example 7
Source File: TmfTraceManager.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Return the path (as a string) to the directory for supplementary files to * use with a given trace. If no supplementary file directory has been * configured, a temporary directory based on the trace's name will be * provided. * * @param trace * The trace * @return The path to the supplementary file directory (trailing slash is * INCLUDED!) */ public static String getSupplementaryFileDir(ITmfTrace trace) { IResource resource = trace.getResource(); if (resource == null) { return getTemporaryDir(trace); } String supplDir = null; try { supplDir = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); } catch (CoreException e) { return getTemporaryDir(trace); } return supplDir + File.separator; }
Example 8
Source File: TmfExperiment.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Get the path to the folder in the supplementary file where * synchronization-related data can be kept so they are not deleted when the * experiment is synchronized. Analysis involved in synchronization can put * their supplementary files in there so they are preserved after * synchronization. * * If the directory does not exist, it will be created. A return value of * <code>null</code> means either the trace resource does not exist or * supplementary resources cannot be kept. * * @param absolute * If <code>true</code>, it returns the absolute path in the file * system, including the supplementary file path. Otherwise, it * returns only the directory name. * @return The path to the folder where synchronization-related * supplementary files can be kept or <code>null</code> if not * available. */ public String getSynchronizationFolder(boolean absolute) { /* Set up the path to the synchronization file we'll use */ IResource resource = this.getResource(); String syncDirectory = null; try { /* get the directory where the file will be stored. */ if (resource != null) { String fullDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER); /* Create the synchronization data directory if not present */ if (fullDirectory != null) { fullDirectory = fullDirectory + File.separator + SYNCHRONIZATION_DIRECTORY; File syncDir = new File(fullDirectory); syncDir.mkdirs(); } if (absolute) { syncDirectory = fullDirectory; } else { syncDirectory = SYNCHRONIZATION_DIRECTORY; } } } catch (CoreException e) { return null; } return syncDirectory; }
Example 9
Source File: TmfTraceTypeUIUtils.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Get the trace type (as a String) for the given trace * * @param trace * The trace object * @return The String representing the trace type, or 'null' if this trace * does not advertise it. */ private static @Nullable String getTraceType(ITmfTrace trace) { IResource res = trace.getResource(); if (res == null) { return null; } try { String traceType = res.getPersistentProperty(TmfCommonConstants.TRACETYPE); /* May be null here too */ return traceType; } catch (CoreException e) { return null; } }
Example 10
Source File: TLAParsingBuilder.java From tlaplus with MIT License | 4 votes |
/** * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); if (resource.exists() && IResource.FILE == resource.getType()) { // a file found if (ResourceHelper.isModule(resource)) { // if the spec is null, this means that we are unable to get // access to the spec manager // because it has not yet been instantiatec. Instantiating // it would trigger a resource change // event which is not allowed if (spec == null) { modules.add(resource); } else if (spec.getRootFile().getParent().equals(resource.getParent())) { // we are only concerned with modules in the same // directory as the root module because those are the // only ones allowed to be a part of the spec if (resource.getPersistentProperty(TLAParsingBuilderConstants.LAST_BUILT) == null) { if (spec.getStatus() < IParseConstants.PARSED && spec.getStatus() > IParseConstants.UNKNOWN) { // If the property has never been set, the // resource has never been built. If the // current status is parsed, then it cannot be // relevant because it would have been built // if it were relevant. If the status is // unknown, it should remain unknown. In all // other cases, it is possible that the resource // is relevant but it is not known because there // was not a successful parse. Conservatively we // should consider it relevant. modules.add(resource); } } // If there current spec status is a problem status (see // AdaptorFactory.isProblemStatus), // then it is not known whether a given resource is // relevant so all resources are considered // relevant. Relevant resources are not necessarily in // dependancy storage. Any resource that is // out of build when the parse status is error is added to // the list of modules. else if (Long.parseLong(resource.getPersistentProperty(TLAParsingBuilderConstants.LAST_BUILT)) < resource .getLocalTimeStamp() && (dependancyTable.containsKey(resource.getName()) || (spec.getStatus() < IParseConstants.PARSED && spec .getStatus() > IParseConstants.UNPARSED))) { modules.add(resource); } } } } // we want the visitor to visit the whole tree return true; }
Example 11
Source File: StandardImportAndReadSmokeTest.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath, String experimentName, IPath expectedElementPathRenamed) throws CoreException { IProject project = getProjectResource(); assertTrue(project.exists()); TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true); assertNotNull(tmfProject); TmfTraceFolder tracesFolder = tmfProject.getTracesFolder(); assertNotNull(tracesFolder); List<TmfTraceElement> traces = tracesFolder.getTraces(); assertFalse(traces.isEmpty()); Collections.sort(traces, new Comparator<TmfTraceElement>() { @Override public int compare(TmfTraceElement arg0, TmfTraceElement arg1) { return arg0.getElementPath().compareTo(arg1.getElementPath()); } }); TmfTraceElement tmfTraceElement = traces.get(0); IResource traceResource = tmfTraceElement.getResource(); assertEquals((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0, traceResource.isLinked()); String tracesFolderName = tracesFolder.getResource().getName(); // i.e. /Tracing/Traces IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(tracesFolderName).append(expectedElementPath); assertEquals(expectedPath, traceResource.getFullPath()); if (expectedElementPathRenamed != null) { IPath expectedPathRenamed = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(tracesFolderName).append(expectedElementPathRenamed); IResource traceResourceRenamed = traces.get(1).getResource(); assertEquals(expectedPathRenamed, traceResourceRenamed.getFullPath()); } String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION); assertNotNull(sourceLocation); assertEquals(expectedSourceLocation, sourceLocation); TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder(); assertNotNull(expFolder); if ((optionFlags & (ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT | TEST_OPTION_CHECK_EXPERIMENT)) != 0) { if (experimentName != null) { TmfExperimentElement expElement = expFolder.getExperiment(experimentName); assertNotNull(expElement); assertEquals(2, expElement.getTraces().size()); } } else { assertTrue(expFolder.getExperiments().size() == 0); } }
Example 12
Source File: DropAdapterAssistant.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
/** * Drop a trace by copying/linking a resource in a trace folder * * @param sourceResource the source resource * @param traceFolder the target trace folder * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK) * @return the target resource or null if unsuccessful */ private static IResource drop(IResource sourceResource, TmfTraceFolder traceFolder, int operation) { if (sourceResource.getParent().equals(traceFolder.getResource())) { return null; } String targetName = sourceResource.getName(); for (ITmfProjectModelElement element : traceFolder.getChildren()) { if (element.getName().equals(targetName)) { targetName = promptRename(element); if (targetName == null) { return null; } break; } } try { if (operation == DND.DROP_COPY && !ResourceUtil.isSymbolicLink(sourceResource)) { IPath destination = traceFolder.getResource().getFullPath().addTrailingSeparator().append(targetName); sourceResource.copy(destination, false, null); cleanupBookmarks(destination); } else { createLink(traceFolder.getResource(), sourceResource, targetName); } IResource traceResource = traceFolder.getResource().findMember(targetName); if (traceResource != null && traceResource.exists()) { String sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION); if (sourceLocation == null) { sourceLocation = URIUtil.toUnencodedString(new File(ResourceUtil.getLocationURI(sourceResource)).toURI()); } traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation); setTraceType(traceResource); } return traceResource; } catch (CoreException e) { TraceUtils.displayErrorMsg(e); } return null; }