List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getKind
int getKind() throws JavaModelException;
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
private void addJavaProject(IJavaProject project) throws CoreException { if (project != null) { final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>(); for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) { if (fragment.getKind() == IPackageFragmentRoot.K_BINARY && fragment.getSourceAttachmentPath() != null) { File classpathLocation; if (fragment.isExternal()) { classpathLocation = fragment.getPath().toFile(); } else { classpathLocation = toFile(fragment.getPath()); }//from ww w .j a v a 2s. co m if (classpathLocation != null) { classpath.put(classpathLocation, fragment); } } } final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath); final Set<File> projectLocations = new HashSet<File>(); final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR); if (jarLocation != null) { // maven binary project projectLocations.add(new File(jarLocation)); } else { // regular project projectLocations.add(toFile(project.getOutputLocation())); for (IClasspathEntry cpe : project.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { projectLocations.add(toFile(cpe.getOutputLocation())); } } } synchronized (lock) { projects.put(project, projectLocations); for (File projectLocation : projectLocations) { locations.put(projectLocation, projectInfo); } } } }
From source file:com.iw.plugins.spindle.ui.wizards.fields.PackageDialogField.java
License:Mozilla Public License
public IStatus packageChanged() { SpindleStatus status = new SpindleStatus(); checkButtonEnabled();//w ww. j ava 2 s . c o m String packName = getTextValue(); if (!"".equals(packName)) { IStatus val = JavaConventions.validatePackageName(packName); if (val.getSeverity() == IStatus.ERROR) { status.setError(UIPlugin.getString(name + ".error.InvalidPackageName", val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(UIPlugin.getString(name + ".warning.DiscouragedPackageName", val.getMessage())); // continue } } else { status.setError(UIPlugin.getString(name + ".error.defaultPackage")); return status; } IPackageFragmentRoot root; if (container == null) { root = null; } else { root = container.getPackageFragmentRoot(); } if (root != null) { IPackageFragment pack = root.getPackageFragment(packName); try { if (fSourcePackagesOnly && root.getKind() == IPackageFragmentRoot.K_BINARY) { status.setError(UIPlugin.getString(name + ".error.PackageMustBeSource")); return status; } IPath rootPath = root.getPath(); IPath outputPath = root.getJavaProject().getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, dont allow to name a // package // like the bin folder IPath packagePath = pack.getUnderlyingResource().getFullPath(); if (outputPath.isPrefixOf(packagePath)) { status.setError(UIPlugin.getString(name + ".error.ClashOutputLocation")); return status; } } } catch (JavaModelException e) { UIPlugin.log(e); // let pass } currentPackage = pack; if (currentPackage != null && nameField != null) { try { IContainer folder = (IContainer) getPackageFragment().getUnderlyingResource(); boolean isComponent = nameField.getKind() == AbstractNameField.COMPONENT_NAME; IFile file = folder .getFile(new Path(nameField.getTextValue() + (isComponent ? ".jwc" : ".page"))); if (file.exists()) { status.setError(UIPlugin.getString(name + ".error.ComponentAlreadyExists", file.getFullPath().toString())); return status; } } catch (JavaModelException e) { UIPlugin.log(e); } } } else { status.setError(""); } return status; }
From source file:com.iw.plugins.spindle.util.lookup.TapestryLookup.java
License:Mozilla Public License
public boolean seek(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, ILookupRequestor requestor) {//w w w . j ava 2 s .c om if (!initialized) { throw new Error("not initialized"); } boolean stopLooking = false; String matchName = partialMatch ? name.toLowerCase() : name; if (pkg == null) { findAllManaged(matchName, partialMatch, requestor, acceptFlags); return stopLooking; } IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent(); try { int packageFlavor = root.getKind(); switch (packageFlavor) { case IPackageFragmentRoot.K_BINARY: if ((acceptFlags & WRITEABLE) != 0) { break; } stopLooking = seekInBinaryPackage(matchName, pkg, partialMatch, acceptFlags, requestor); break; case IPackageFragmentRoot.K_SOURCE: stopLooking = seekInSourcePackage(matchName, pkg, partialMatch, acceptFlags, requestor); break; default: return stopLooking; } } catch (JavaModelException e) { return stopLooking; } return stopLooking; }
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. * //w ww. j a v a 2 s. c o 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);// ww w . jav a 2 s. co 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.adt.core.model.internal.JavaPackageNameDefaultValueService.java
License:Open Source License
@Override protected String compute() { final IJavaProject project = op().adapt(IJavaProject.class); try {//from ww w. j a v a 2 s .c om final IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (root.getKind() != IPackageFragmentRoot.K_BINARY) { for (IJavaElement element : root.getChildren()) { if (element instanceof IPackageFragment) { final IPackageFragment fragment = (IPackageFragment) element; if (!fragment.isDefaultPackage() && !fragment.hasSubpackages()) { return fragment.getElementName(); } } } } } } catch (Exception e) { ADTCore.logError(e.getMessage(), e); } return null; }
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;/*w ww. 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 ww w . ja v a 2 s . 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 {/*from w ww .j a va2 s .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]; }// w ww. j a va 2 s . c o 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()]); }