List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE
int K_SOURCE
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.
Click Source Link
From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java
License:Open Source License
/** * Get all the resolved classpath entries for a specific project. The entries * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved * or included in the result. At also add the source and output folder provided with the * project//from w w w. jav a 2s. co m * * @param project the project where the file to compile is contained, must be not null * @return a not null list of string that contains the classpath to include in the compilation project */ private List<String> getClasspaths(IProject project) { IJavaProject jprj = JavaCore.create(project); List<String> classpath = new ArrayList<String>(); IWorkspaceRoot wsRoot = project.getWorkspace().getRoot(); if (jprj != null) { try { IClasspathEntry[] entries = jprj.getRawClasspath(); //Add the default output folder if any IPath defaultLocationPath = jprj.getOutputLocation(); if (defaultLocationPath != null) { IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } for (IClasspathEntry en : entries) { if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String containerPath = en.getPath().toString(); //Don't add the eclipse runtime and the classpath extension defined in the exclusion list if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER) && !classpathExclusionSet.contains(containerPath)) { addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath, jprj); } } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) { classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator); } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) { //check if is a source folder and if it has a custom output folder to add them also to the classpath IPath entryOutputLocation = en.getOutputLocation(); if (entryOutputLocation != null) { IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } } else { //It is a jar check if it is internal to the workspace of external IPath location = wsRoot.getFile(en.getPath()).getLocation(); if (location == null) { //The location could not be resolved from the root of the workspace, it is external classpath.add(en.getPath().toOSString()); } else { //The location has been resolved from the root of the workspace, it is internal classpath.add(location.toOSString()); } } } } catch (Exception ex) { ex.printStackTrace(); } } return classpath; }
From source file:com.legstar.eclipse.plugin.cixsmap.dialogs.LegacyStructureDialog.java
License:Open Source License
/** * Examines packages in a given project and adds segments which contain the * .bind suffix to the package list table. ".bind" suffix identify segments * that correspond to COXB binding packages. * /*from w w w.ja v a 2 s. co m*/ * @param project the java project to get packages from * @return map of java package names to fragments * @throws CoreException if the given project is not a Java project */ private Map<String, IPackageFragment> createPackageList(final IProject project) throws CoreException { Map<String, IPackageFragment> packageMap = new HashMap<String, IPackageFragment>(); IJavaProject jproject = JavaCore.create(project); IPackageFragmentRoot[] pkgRoots = jproject.getPackageFragmentRoots(); for (int j = 0; j < pkgRoots.length; j++) { IPackageFragmentRoot pkgRoot = pkgRoots[j]; if (pkgRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { for (int k = 0; k < pkgRoot.getChildren().length; k++) { IJavaElement el = pkgRoot.getChildren()[k]; if (el.getPath().lastSegment().compareTo(BIND_FRAG) == 0) { packageMap.put(el.getElementName(), (IPackageFragment) el); } } } } return packageMap; }
From source file:com.legstar.eclipse.plugin.cixsmap.wizards.NewMappingFileWizardPage.java
License:Open Source License
/** {@inheritDoc} */ protected boolean validatePage() { setCanFinish(false);//from w w w . j a v a2 s . c o m if (!super.validatePage()) { return false; } /* There must be a mapping file name */ if (getFileName() == null || getFileName().length() == 0) { setErrorMessage(NLS.bind(Messages.invalid_mapping_file_msg, getFileName())); return false; } /* There must be more than the mere mapping file name extension */ IPath path = new Path(getFileName()); IPath noExtensionPath = path.removeFileExtension(); if (noExtensionPath.isEmpty()) { setErrorMessage(NLS.bind(Messages.invalid_mapping_file_msg, getFileName())); return false; } /* Make sure the file name has the correct extension */ String extension = path.getFileExtension(); if (extension == null || !extension.equals(Messages.operations_mapping_file_suffix)) { setErrorMessage(NLS.bind(Messages.invalid_mapping_file_extension_msg, extension, Messages.operations_mapping_file_suffix)); return false; } /* Only Java projects are valid containers. */ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(getContainerFullPath()); IJavaProject jproject = JavaCore.create(resource.getProject()); try { /* Check that there are LegStar binding classes in this project */ IPackageFragmentRoot[] pkgRoots = jproject.getPackageFragmentRoots(); for (int j = 0; j < pkgRoots.length; j++) { IPackageFragmentRoot pkgRoot = pkgRoots[j]; if (pkgRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { for (int k = 0; k < pkgRoot.getChildren().length; k++) { IJavaElement el = pkgRoot.getChildren()[k]; if (el.getPath().lastSegment().compareTo(LegacyStructureDialog.BIND_FRAG) == 0) { setCanFinish(true); return true; } } } } setErrorMessage(NLS.bind(Messages.no_coxb_classes_in_project_msg, resource.getProject().getName())); return false; } catch (JavaModelException e) { setErrorMessage( NLS.bind(Messages.invalid_java_project_msg, resource.getProject().getName(), e.getMessage())); return false; } }
From source file:com.liferay.ide.core.util.PropertiesUtil.java
License:Open Source License
public static List<IFile> getDefaultLanguagePropertiesFromModuleProject(IProject project) { IJavaProject javaProject = JavaCore.create(project); IType portletType = null;/*from ww w .j a v a 2 s. co m*/ List<IFile> retvals = new ArrayList<IFile>(); try { portletType = javaProject.findType("javax.portlet.Portlet"); final ITypeHierarchy typeHierarchy = portletType.newTypeHierarchy(javaProject, new NullProgressMonitor()); final IPackageFragmentRoot[] packageRoots = javaProject.getPackageFragmentRoots(); List<String> packages = new ArrayList<String>(); List<IType> srcJavaTypes = new ArrayList<IType>(); for (IPackageFragmentRoot packageRoot : packageRoots) { if (packageRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { IJavaElement[] javaElements = packageRoot.getChildren(); for (IJavaElement javaElement : javaElements) { IPackageFragment packageFragment = (IPackageFragment) javaElement; packages.add(packageFragment.getElementName()); } } } IType[] subTypes = typeHierarchy.getAllSubtypes(portletType); for (IType type : subTypes) { if (isInPackage(packages, type.getFullyQualifiedName())) { srcJavaTypes.add(type); } } String resourceBundleValue = null; for (IType type : srcJavaTypes) { File file = type.getResource().getLocation().toFile(); String content = FileUtil.readContents(file); String key = "javax.portlet.resource-bundle="; int i = content.indexOf(key); if (i == -1) { continue; } else { i += key.length(); StringBuilder strBuilder = new StringBuilder(); for (; i < content.length(); i++) { char ch = content.charAt(i); if (ch != '"') { strBuilder.append(ch); } else { break; } } resourceBundleValue = strBuilder.toString(); // find the first language config break; } } String resourceBundle = resourceBundleValue.replaceAll("(^\\s*)|(\\s*$)", StringPool.BLANK); if (!resourceBundle.endsWith(PROPERTIES_FILE_SUFFIX) && !resourceBundle.contains(IPath.SEPARATOR + "") && !(CoreUtil.isWindows() && resourceBundle.contains("\\"))) { resourceBundle = new Path(resourceBundle.replace(".", IPath.SEPARATOR + "")).toString(); } final ILiferayProject lrproject = LiferayCore.create(project); final IFolder[] srcFolders = lrproject.getSourceFolders(); for (IFolder srcFolder : srcFolders) { final IFile languageFile = CoreUtil.getWorkspaceRoot() .getFile(srcFolder.getFullPath().append(resourceBundle + PROPERTIES_FILE_SUFFIX)); if ((languageFile != null) && languageFile.exists()) { retvals.add(languageFile); } } } catch (Exception e) { } return retvals; }
From source file:com.liferay.ide.portlet.core.util.PortletUtil.java
License:Open Source License
/** * This method will return the first source folder of the Java project * //from w w w .j a v a2s. c o m * @param javaProject * - the java project where the source folder needs to be indentified * @return * @throws JavaModelException */ public static IPackageFragmentRoot getSourceFolder(IJavaProject javaProject) throws JavaModelException { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { return root; } } return null; }
From source file:com.liferay.ide.project.core.modules.templates.AbstractLiferayComponentTemplate.java
License:Open Source License
protected IPackageFragmentRoot getSourceFolder(IJavaProject javaProject) { try {// w w w .j ava 2s .c o m for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { return root; } } } catch (Exception e) { ProjectCore.logError(e); } return null; }
From source file:com.liferay.ide.server.util.ComponentUtil.java
License:Open Source License
private static IPackageFragmentRoot[] getSources(IProject project) { IJavaProject jProject = JavaCore.create(project); if (jProject == null) { return new IPackageFragmentRoot[0]; }//from w w w. java 2s . co m List<IPackageFragmentRoot> list = new ArrayList<IPackageFragmentRoot>(); IVirtualComponent vc = ComponentCore.createComponent(project); IPackageFragmentRoot[] roots; try { roots = jProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() != IPackageFragmentRoot.K_SOURCE) { continue; } IResource resource = roots[i].getResource(); if (null != resource) { IVirtualResource[] vResources = ComponentCore.createResources(resource); boolean found = false; for (int j = 0; !found && j < vResources.length; j++) { if (vResources[j].getComponent().equals(vc)) { if (!list.contains(roots[i])) { list.add(roots[i]); } found = true; } } } } if (list.size() == 0) { for (IPackageFragmentRoot root : roots) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { if (!list.contains(root)) { list.add(root); } } } } } catch (JavaModelException e) { LiferayServerCore.logError(e); } return list.toArray(new IPackageFragmentRoot[list.size()]); }
From source file:com.motorola.studio.android.model.BuildingBlockModel.java
License:Apache License
/** * Extract source folder from selection. * @param selection/*from w w w.java 2s . c o m*/ * @return * @throws CoreException */ private static IPackageFragmentRoot extractPackageFragmentRoot(IStructuredSelection selection) throws CoreException { IPackageFragmentRoot pack = null; Object selectionElement = selection.getFirstElement(); if (selectionElement instanceof IPackageFragmentRoot) { pack = (IPackageFragmentRoot) selectionElement; } else if (selectionElement instanceof IJavaElement) { pack = (IPackageFragmentRoot) ((IJavaElement) selectionElement) .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (pack == null) { IJavaProject element = ((IJavaElement) selectionElement).getJavaProject(); for (IPackageFragmentRoot root : element.getPackageFragmentRoots()) { if (root.getResource() != null) { boolean isSrc = (root.getElementType() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE; boolean isGen = root.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (root.getParent() instanceof IJavaProject); if (isSrc && !isGen) { pack = root; break; } } } } } else if (selectionElement instanceof IResource) { IJavaProject element = JavaCore.create(((IResource) selectionElement).getProject()); if (element.isOpen()) { for (IPackageFragmentRoot root : element.getPackageFragmentRoots()) { if (root.getResource() != null) { boolean isSrc = (root.getElementType() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE; boolean isGen = root.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (root.getParent() instanceof IJavaProject); if (isSrc && !isGen) { pack = root; break; } } } } } else { IJavaProject[] allProjects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()) .getJavaProjects(); if ((allProjects != null) && (allProjects.length > 0)) { for (IJavaProject project : allProjects) { if (project.getResource().getProject().hasNature(IAndroidConstants.ANDROID_NATURE)) { IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); if ((roots != null) && (roots.length > 0)) { boolean found = false; for (IPackageFragmentRoot root : roots) { boolean isSrc = (root.getElementType() & IPackageFragmentRoot.K_SOURCE) == IPackageFragmentRoot.K_SOURCE; boolean isGen = root.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (root.getParent() instanceof IJavaProject); if (isSrc && !isGen) { found = true; pack = root; break; } } if (found) { break; } } } } } } if (pack != null) { if (!pack.getJavaProject().getProject().hasNature(IAndroidConstants.ANDROID_NATURE)) { pack = extractPackageFragmentRoot(new TreeSelection()); } } return pack; }
From source file:com.motorola.studio.android.wizards.buildingblocks.ElementTreeValidator.java
License:Apache License
@Override public boolean isSelectedValid(Object element) { boolean isValid = false; try {/*from w ww . j av a 2 s.c o m*/ if (element instanceof IJavaProject) { IJavaProject jproject = (IJavaProject) element; IPath path = jproject.getProject().getFullPath(); isValid = (jproject.findPackageFragmentRoot(path) != null); } else if (element instanceof IPackageFragmentRoot) { IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) element; boolean isSrc = (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE); boolean isGen = packageFragmentRoot.getElementName().equals(IAndroidConstants.GEN_SRC_FOLDER) && (packageFragmentRoot.getParent() instanceof IJavaProject); isValid = isSrc && !isGen; } else { isValid = true; } } catch (JavaModelException e) { StudioLogger.error(ElementTreeValidator.class, e.getLocalizedMessage(), e); } return isValid; }
From source file:com.motorola.studio.android.wizards.buildingblocks.ElementTreeViewFilter.java
License:Apache License
@Override public boolean select(Viewer viewer, Object parent, Object element) { boolean select = false; if (element instanceof IPackageFragmentRoot) { try {/*w w w .jav a 2 s .com*/ select = (((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE); } catch (JavaModelException e) { StudioLogger.error(ElementTreeViewFilter.class, e.getLocalizedMessage(), e); } } else { select = super.select(viewer, parent, element); } return select; }