Java Code Examples for org.eclipse.core.resources.IFolder#findMember()

The following examples show how to use org.eclipse.core.resources.IFolder#findMember() . 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: JarEntryAwareTrace.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected AbsoluteURI resolvePath(IJavaProject javaProject, SourceRelativeURI path) {
	try {
		for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots())
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				IResource resource = root.getResource();
				if (resource instanceof IFolder) {
					IFolder folder = (IFolder) resource;
					String decodedPath = URI.decode(path.toString());
					IResource candidate = folder.findMember(decodedPath);
					if (candidate != null && candidate.exists())
						return new AbsoluteURI(URI.createPlatformResourceURI(resource.getFullPath() + "/" + decodedPath, true));
				}
			}
	} catch (JavaModelException e) {
		log.error("Error resolving path", e);
	}
	return null;
}
 
Example 2
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
private void addJarFilesNotInClasspath(IProgressMonitor monitor, IProject project, IJavaProject javaProject) throws CoreException
{
	 addMembersOfFolderToClasspath("/lib", monitor, javaProject);
	 addMembersOfFolderToClasspath("/web/webroot/WEB-INF/lib", monitor, javaProject);
	 // check if this is a backoffice extension
	 IFolder backofficeFolder = javaProject.getProject().getFolder("/resources/backoffice");
	 if (backofficeFolder != null && backofficeFolder.exists())
	 {
		 IResource backofficeJar = backofficeFolder.findMember(javaProject.getProject().getName() + "_bof.jar");
		 if (backofficeJar != null && backofficeJar.exists())
		 {
			 if (!isClasspathEntryForJar(javaProject, backofficeJar))
			 {
				 Activator.log("Adding library [" + backofficeJar.getFullPath() + "] to classpath for project [" + javaProject.getProject().getName() + "]");
				 FixProjectsUtils.addToClassPath(backofficeJar, IClasspathEntry.CPE_LIBRARY, javaProject, monitor);
			 }
		 }
	 }
	 
	 // add db drivers for platform/lib/dbdriver directory
	 if (project.getName().equalsIgnoreCase("platform"))
	 {
		 addMembersOfFolderToClasspath("/lib/dbdriver", monitor, javaProject);
	 }
}
 
Example 3
Source File: Model.java    From tlaplus with MIT License 5 votes vote down vote up
private IFile getFile(final String id) {
	final IFolder targetFolder = getTargetDirectory();
	if (targetFolder != null && targetFolder.exists()) {
		final IFile teFile = (IFile) targetFolder.findMember(id);
		if (teFile != null && teFile.exists()) {
			return teFile;
		}
	}
	return null;
}
 
Example 4
Source File: RemoteImportTracesOperation.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private IResource downloadFileTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException {

        IFolder folder = traceFolder;
        String traceName = trace.getName();

        traceName = TmfTraceCoreUtils.validateName(traceName);

        IResource resource = folder.findMember(traceName);
        if ((resource != null) && resource.exists()) {
            String newName = fConflictHandler.checkAndHandleNameClash(resource.getFullPath(), monitor);
            if (newName == null) {
                return null;
            }
            traceName = newName;
        }
        SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
        subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, 1);

        IPath destination = folder.getLocation().addTrailingSeparator().append(traceName);
        IFileInfo info = trace.fetchInfo();
        subMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + trace.getName());
        try (InputStream in = trace.openInputStream(EFS.NONE, new NullProgressMonitor())) {
            copy(in, folder, destination, subMonitor, info.getLength());
        }
        folder.refreshLocal(IResource.DEPTH_INFINITE, null);
        return folder.findMember(traceName);
    }
 
Example 5
Source File: TmfOpenTraceHelper.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static boolean isWrongMember(IFolder folder, String name, final File traceFile) {
    final IResource candidate = folder.findMember(name);
    if (candidate != null) {
        final IPath rawLocation = candidate.getRawLocation();
        File file = rawLocation.toFile();
        try {
            file = file.getCanonicalFile();
        } catch (IOException e) {
            /* just use original file path */
        }
        return !file.equals(traceFile);
    }
    return false;
}
 
Example 6
Source File: AbstractGroovyScriptConfigurationSynchronizer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void removeDeletedPackage(Configuration configuration, GroovyRepositoryStore store, CompoundCommand cc,
        EditingDomain editingDomain) {
    IFolder srcFolder = store.getResource();
    FragmentContainer container = getContainer(configuration);
    for (Fragment f : container.getFragments()) {
        IResource member = srcFolder.findMember(Path.fromOSString(f.getValue()));
        if (member == null || !member.exists()) {
            cc.append(RemoveCommand.create(editingDomain, container,
                    ConfigurationPackage.Literals.FRAGMENT_CONTAINER__FRAGMENTS, f));
        }
    }
}
 
Example 7
Source File: WebArtifactRepositoryStore.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T getChild(final String folderName, boolean force) {
    if (folderName != null) {
        final IFolder folder = getResource().getFolder(folderName);
        if(force) {
            refresh(folder);
        }
        IResource jsonDescriptorFile = folder.findMember(folderName + ".json");
        if (folder.exists() && jsonDescriptorFile != null && jsonDescriptorFile.exists()) {
            return createRepositoryFileStore(folderName);
        }
    }
    return null;
}
 
Example 8
Source File: RemoteFetchLogWizardRemotePage.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean determinePageCompletion() {
     if (getElementViewer().getCheckedElements().length <= 0) {
         return false;
     }

     validateProject();

     if ((fExperimentName != null) && (fCreateExperimentCheckbox.getSelection())) {
         String name = fExperimentNameText.getText().trim();
         // verify if experiment name is empty
         if (name.isEmpty()) {
             setMessage(null);
             setErrorMessage(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorEmptyExperimentName);
             return false;
         }

         // verify that name is a valid resource name
         IWorkspace workspace = ResourcesPlugin.getWorkspace();
         if ((workspace != null) && (!workspace.validateName(name, IResource.FILE).isOK())) {
             setMessage(null);
             setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorExperimentNameInvalid, name));
             return false;
         }

         TmfExperimentFolder experimentFolder = fExperimentFolderElement;
         if (experimentFolder != null) {
             TmfExperimentElement element =
                     experimentFolder.getExperiment(name);
             // verify if experiment already exists
             if (element != null) {
                 setMessage(null);
                 setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorExperimentAlreadyExists, name));
                 return false;
             }

             // verify if a resource already exists in the experiment folder
             IFolder expResource = experimentFolder.getResource();
             IResource res = expResource.findMember(name);
             if (res != null) {
                 setMessage(null);
                 setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorResourceAlreadyExists, name));
                 return false;
             }
         }
     }

     return true;

}
 
Example 9
Source File: TmfOpenTraceHelper.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private static boolean traceExists(String path, IFolder folder) {
    String val = getTraceName(path, folder);
    return (folder.findMember(val) != null);
}
 
Example 10
Source File: ImportTraceWizardPage.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean validateOptionsGroup() {
    if (fCreateExperimentCheckbox != null && fCreateExperimentCheckbox.getSelection()) {
        String name = fExperimentNameText.getText().trim();
        // verify if experiment name is empty
        if (name.isEmpty()) {
            setMessage(null);
            setErrorMessage(Messages.ImportTraceWizard_ErrorEmptyExperimentName);
            return false;
        }
        // verify that name is a valid resource name
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        if ((workspace != null) && (!workspace.validateName(name, IResource.FILE).isOK())) {
            setMessage(null);
            setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorExperimentNameInvalid, name));
            return false;
        }
        // verify if experiment already exists
        if (fExperimentFolderElement != null) {
            TmfExperimentElement element = fExperimentFolderElement.getExperiment(name);
            if (element != null) {
                setMessage(null);
                setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorExperimentAlreadyExists, name));
                return false;
            }
            IFolder expResource = fExperimentFolderElement.getResource();
            IResource res = expResource.findMember(name);
            if (res != null) {
                setMessage(null);
                setErrorMessage(NLS.bind(Messages.ImportTraceWizard_ErrorResourceAlreadyExists, name));
                return false;
            }
        }
    }

    if (fTimeRangeCheckbox != null && fTimeRangeCheckbox.getSelection() && !validateTimeRange()) {
        fStartTimestamp = null;
        fEndTimestamp = null;
        setMessage(null);
        setErrorMessage(Messages.ImportTraceWizard_TimeRangeErrorMessage);
        return false;
    }
    setErrorMessage(null);
    return true;
}