List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getResource
IResource getResource();
From source file:net.atos.optimus.m2m.engine.sdk.wizards.transformations.TransformationCreatorJob.java
License:Open Source License
@Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { monitor.beginTask(Messages.JOBTASK.message(), 4); monitor.subTask(Messages.JOB_SUBTASK_1.message()); if (!fragment.exists()) { IPackageFragmentRoot root = (IPackageFragmentRoot) this.fragment .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); this.fragment = root.createPackageFragment(this.fragment.getElementName(), false, monitor); root.getResource().refreshLocal(IResource.DEPTH_ONE, monitor); }// w w w .j a v a2 s.c o m Properties properties = new Properties(); properties.put(VAR_PACKAGENAME, this.fragment.getElementName()); properties.put(VAR_TRANSFO_ELT_FQN, elementType); properties.put(VAR_TRANSFO_CLASSNAME, className); properties.put(VAR_TRANSFO_FACTORYNAME, factoryName); ResourceSet resourceSet = new ResourceSetImpl(); monitor.worked(1); monitor.subTask(Messages.JOB_SUBTASK_2.message()); this.generateJava(resourceSet, properties); monitor.worked(1); monitor.subTask(Messages.JOB_SUBTASK_3.message()); this.generateXML(resourceSet, properties); monitor.worked(1); monitor.subTask(Messages.JOB_SUBTASK_4.message()); for (Resource r : resourceSet.getResources()) r.unload(); resourceSet.getResources().clear(); monitor.worked(1); monitor.done(); return Status.OK_STATUS; }
From source file:net.harawata.mybatipse.mybatis.ConfigRegistry.java
License:Open Source License
/** * Scans the project and returns the MyBatis config file if found.<br> * If there are multiple files in the project, only the first one is returned. * //from ww w . j a v a 2 s . c om * @param project * @return MyBatis config file or <code>null</code> if none found. */ private Map<IFile, IContentType> search(IJavaProject project) { final Map<IFile, IContentType> configFiles = new ConcurrentHashMap<IFile, IContentType>(); try { project.getResource().accept(new ConfigVisitor(configFiles), IContainer.NONE); for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { if (root.getKind() != IPackageFragmentRoot.K_SOURCE) continue; root.getResource().accept(new ConfigVisitor(configFiles), IContainer.NONE); } } catch (CoreException e) { Activator.log(Status.ERROR, "Searching MyBatis Config xml failed.", e); } return configFiles; }
From source file:net.harawata.mybatipse.mybatis.MapperNamespaceCache.java
License:Open Source License
private void collectMappers(IJavaProject project, final Map<String, IFile> map, final IReporter reporter) { try {// ww w . j a v a 2 s.c om for (IPackageFragmentRoot root : project.getAllPackageFragmentRoots()) { if (root.getKind() != IPackageFragmentRoot.K_SOURCE) { continue; } root.getResource().accept(new IResourceProxyVisitor() { @Override public boolean visit(IResourceProxy proxy) throws CoreException { if (!proxy.isDerived() && proxy.getType() == IResource.FILE && proxy.getName().endsWith(".xml")) { IFile file = (IFile) proxy.requestResource(); IContentDescription contentDesc = file.getContentDescription(); if (contentDesc != null) { IContentType contentType = contentDesc.getContentType(); if (contentType != null && contentType.isKindOf(mapperContentType)) { String namespace = extractNamespace(file); if (namespace != null) { map.put(namespace, file); } return false; } } } return true; } }, IContainer.NONE); } } catch (CoreException e) { Activator.log(Status.ERROR, "Searching MyBatis Mapper xml failed.", e); } }
From source file:net.hillsdon.testlink.model.conventions.FixedSourceFolderConvention.java
License:Open Source License
public IPackageFragmentRoot getSourceFolder(final IJavaProject project) throws JavaModelException { for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { final IResource resource = root.getResource(); if (resource != null && _projectRelativePath.equals(resource.getProjectRelativePath().toString())) { return root; }/*from w w w .j a v a 2s . c om*/ } return null; }
From source file:net.officefloor.eclipse.classpath.ClasspathUtil.java
License:Open Source License
/** * Obtains the location on the class path for the input {@link IPath}. * /*w w w. ja va2 s .c o m*/ * @param path * {@link IPath}. * @return Location on the class path for the input {@link IPath}. */ public static String getClassPathLocation(IPath path) { // Obtain the resource for the path IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource pathResource = workspaceRoot.findMember(path); IResource resource = pathResource; // Obtain the java element IJavaElement javaElement = null; do { // Ensure have the resource if (resource == null) { // Did not find java element for resource return null; } // Obtain the java element from the resource javaElement = JavaCore.create(resource); // Obtain the parent resource resource = resource.getParent(); } while (javaElement == null); // Obtain the package fragment root for the java element IPackageFragmentRoot fragmentRoot = null; do { // Determine if package fragment root if (javaElement instanceof IPackageFragmentRoot) { fragmentRoot = (IPackageFragmentRoot) javaElement; } // Obtain the parent java element javaElement = javaElement.getParent(); } while ((fragmentRoot == null) && (javaElement != null)); // Determine if have fragment root if (fragmentRoot == null) { // Return path as is return path.toString(); } // Obtain the fragment root full path String fragmentPath = fragmentRoot.getResource().getFullPath().toString() + "/"; // Obtain the class path location (by removing fragment root path) String fullPath = pathResource.getFullPath().toString(); String location = fullPath.substring(fragmentPath.length()); // Return the location return location; }
From source file:net.rim.ejde.internal.util.ImportUtils.java
License:Open Source License
static private List<LinkBuffer> generateLinks(IJavaProject eclipseJavaProject, ResourcesBuffer buffer, Project legacyProject) {//from w w w. j a va 2 s .c om Map<String, Set<File>> javaArtifacts = buffer.getJavaContener(); Map<String, Set<File>> localeArtifacts = buffer.getlocaleContener(); Set<File> nonPackageableFiles = buffer.getNonPackageContener(); IPath drfpath = null, filePath = null; IFile eclipseFileHandle = null, fileHandle = null; IProject eclipseProject = eclipseJavaProject.getProject(); IWorkspaceRoot workspaceRoot = eclipseProject.getWorkspace().getRoot(); List<String> sources = net.rim.ejde.internal.legacy.Util.getSources(legacyProject); IPackageFragmentRoot[] packageFragmentRoots; IPackageFragment packageFragment; IFolder packageFolder; IResource resource, packageDirectory; List<LinkBuffer> linkBuffers = Collections.emptyList(); try { // packageFragmentRoots = // eclipseJavaProject.getPackageFragmentRoots(); //!WARNING: it // seems this is buggy!!!! packageFragmentRoots = eclipseJavaProject.getAllPackageFragmentRoots(); linkBuffers = new ArrayList<LinkBuffer>(); String srcFolder = POTENTIAL_SOURCE_FOLDERS[PROJECT_SRC_FOLDE_INDEX]; String resFolder = POTENTIAL_SOURCE_FOLDERS[PROJECT_RES_FOLDE_INDEX]; String localeFolder = POTENTIAL_SOURCE_FOLDERS[PROJECT_LOCALE_FOLDE_INDEX]; IJavaProject javaProject = null; for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { javaProject = packageFragmentRoot.getParent().getJavaProject(); if (javaProject == null || !javaProject.equals(eclipseJavaProject)) { // fixed DPI225325, we only care source folders in the // current project continue; } if (IPackageFragmentRoot.K_SOURCE == packageFragmentRoot.getKind()) { packageDirectory = packageFragmentRoot.getResource(); if (null != packageDirectory) { if (isResourceTargetFolder(packageDirectory)) { if (IResource.FOLDER == packageDirectory.getType()) { // handle resource files which are not java, rrh // and rrc if (resFolder.equalsIgnoreCase(packageDirectory.getName())) { packageFragment = packageFragmentRoot.createPackageFragment(StringUtils.EMPTY, true, new NullProgressMonitor()); packageFolder = (IFolder) packageFragment.getResource(); for (File file : nonPackageableFiles) { filePath = new Path(file.getAbsolutePath()); if (canIgnoreFile(filePath, eclipseJavaProject)) { continue; } // drfpath = PackageUtils.resolvePathForFile( filePath, legacyProjectPath, // legacyWorkspacePath ); // DPI222295 try { drfpath = new Path(PackageUtils.getFilePackageString(filePath.toFile(), legacyProject)).append(filePath.lastSegment()); } catch (CoreException e) { _log.error(e.getMessage()); drfpath = new Path(IConstants.EMPTY_STRING); } if (drfpath.segmentCount() > 1) { if (sources.contains(drfpath.segment(0))) { drfpath = drfpath.removeFirstSegments(1); } drfpath = assureFolderPath(packageFolder, drfpath); } fileHandle = createFileHandle(packageFolder, drfpath.toOSString()); resource = eclipseProject.findMember( PackageUtils.deResolve(filePath, eclipseProject.getLocation())); if (resource != null) eclipseFileHandle = workspaceRoot.getFile(resource.getFullPath()); else eclipseFileHandle = workspaceRoot .getFile(eclipseProject.getFullPath().append(drfpath)); if (!fileHandle.equals(eclipseFileHandle)) { linkBuffers.add(new LinkBuffer(fileHandle, filePath)); } } } if (srcFolder.equalsIgnoreCase(packageDirectory.getName()) || srcFolder.equalsIgnoreCase(packageDirectory.getName())) { // All linkPackagableFiles(javaProject, packageFragmentRoot, javaArtifacts, linkBuffers); } if (localeFolder.equalsIgnoreCase(packageDirectory.getName()) || localeFolder.equalsIgnoreCase(packageDirectory.getName())) { linkPackagableFiles(javaProject, packageFragmentRoot, localeArtifacts, linkBuffers); } } else { continue; } } } } } } catch (JavaModelException e1) { _log.error(e1.getMessage(), e1); } return linkBuffers; }
From source file:org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider.java
License:Apache License
@Override public void getPipelinedChildren(Object aParent, Set theCurrentChildren) { if (aParent instanceof IProject) { IProject project = (IProject) aParent; if (ProjectHelper.isContentProject(project)) { for (Iterator<?> it = theCurrentChildren.iterator(); it.hasNext();) { Object aChild = (Object) it.next(); if (aChild instanceof IPackageFragmentRoot) { IPackageFragmentRoot ipfr = (IPackageFragmentRoot) aChild; IResource res = ipfr.getResource(); IFolder syncDir = getSyncDir(project); if (res != null && syncDir != null && res.equals(syncDir)) { // then remove this one folder provided via j2ee content provider // reason: we are showing it too via the sling content provider it.remove();/*from ww w . ja v a2 s.c o m*/ // and we can break here since there's only one syncdir currently break; } } } } Object[] children = projectGetChildren(project); if (children != null && children.length > 0) { theCurrentChildren.addAll(Arrays.asList(children)); } return; } else if (aParent instanceof SyncDir) { theCurrentChildren.clear(); Object[] children = getChildren(aParent); if (children != null) { theCurrentChildren.addAll(Arrays.asList(children)); } } }
From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.application.JavaCloudFoundryArchiver.java
License:Open Source License
protected IFile getManifest(IPackageFragmentRoot[] roots, IJavaProject javaProject) throws CoreException { IFolder metaFolder = null;//from w w w . j a v a 2s . c o m for (IPackageFragmentRoot root : roots) { if (!root.isArchive() && !root.isExternal()) { IResource resource = root.getResource(); metaFolder = getMetaFolder(resource); if (metaFolder != null) { break; } } } // Otherwise look for manifest file in the java project: if (metaFolder == null) { metaFolder = getMetaFolder(javaProject.getProject()); } if (metaFolder != null) { IResource[] members = metaFolder.members(); if (members != null) { for (IResource mem : members) { if (MANIFEST_FILE.equals(mem.getName().toUpperCase()) && mem instanceof IFile) { return (IFile) mem; } } } } return null; }
From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.application.JavaPackageFragmentRootHandler.java
License:Open Source License
/** * //from www .j av a 2 s.c o m * Determines if the given package fragment root corresponds to the class * path entry path. * <p/> * Note that different package fragment roots may point to the same class * path entry. * <p/> * Example: * <p/> * A Java project may have the following package fragment roots: * <p/> * - src/main/java * <p/> * - src/main/resources * <p/> * Both may be using the same output folder: * <p/> * target/classes. * <p/> * In this case, the output folder will have a class path entry - * target/classes - and it will be the same for both roots, and this method * will return true for both roots if passed the entry for target/classes * * @param root * to check if it corresponds to the given class path entry path * @param entry * @return true if root is at the given entry */ private static boolean isRootAtEntry(IPackageFragmentRoot root, IPath entry) { try { IClasspathEntry cpe = root.getRawClasspathEntry(); if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = cpe.getOutputLocation(); if (outputLocation == null) { outputLocation = root.getJavaProject().getOutputLocation(); } IPath location = ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation(); if (entry.equals(location)) { return true; } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } IResource resource = root.getResource(); if (resource != null && entry.equals(resource.getLocation())) { return true; } IPath path = root.getPath(); if (path != null && entry.equals(path)) { return true; } return false; }
From source file:org.codehaus.groovy.eclipse.launchers.GroovyConsoleLineTracker.java
License:Apache License
/** * @param groovyFileName//from w w w. ja va 2 s .co m * @return * @throws JavaModelException */ private IFile[] searchForFileInLaunchConfig(String groovyFileName) throws JavaModelException { List<IFile> files = new LinkedList<IFile>(); IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); for (IJavaProject javaProject : projects) { if (GroovyNature.hasGroovyNature(javaProject.getProject())) { for (IPackageFragmentRoot root : javaProject.getAllPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IResource resource = root.getResource(); if (resource.isAccessible() && resource.getType() != IResource.FILE) { IFile file = ((IContainer) resource).getFile(new Path(groovyFileName)); if (file.isAccessible()) { files.add(file); } } } } } } return files.toArray(new IFile[files.size()]); }