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.appnativa.studio.builder.J2ObjCHelper.java
static String getSourcePath(IProject p, StringBuilder sb) { try {//ww w .ja v a 2 s . co m sb.setLength(0); IJavaProject javaProject = JavaCore.create(p); IClasspathEntry[] classpathEntries = null; classpathEntries = javaProject.getResolvedClasspath(true); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (int i = 0; i < classpathEntries.length; i++) { IClasspathEntry entry = classpathEntries[i]; if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath path = entry.getPath(); IResource res = root.findMember(path); if (res != null) { String srcPath = res.getLocation().toOSString(); sb.append(srcPath).append(File.pathSeparator); } } } if (sb.charAt(sb.length() - 1) == File.pathSeparatorChar) { sb.setLength(sb.length() - 1); return sb.toString(); } } catch (Exception ignore) { ignore.printStackTrace(); } return ""; }
From source file:com.beck.ep.team.internal.WarPatchCreator.java
License:BSD License
public void packToFile(Map<String, String> param, IProject project, List<IFile> toPackFiles, Map<File, String> toPackJavaFiles, IProgressMonitor monitor) throws Exception { monitor.beginTask("Preparing...", 2); String fileAbsPath = param.get(IFilePacker.PARAM_FILE_ABS_PATH); String rootDir = param.get(IFilePacker.PARAM_ROOT_DIRNAME); if (rootDir != null) { if (rootDir.length() == 0) { rootDir = null;/*from w w w .j av a2 s.c om*/ } else if (rootDir.endsWith("/")) { rootDir = rootDir.substring(0, rootDir.length() - 1); } } IPath[] srcs = null; if (initJDT(project)) { ArrayList<IPath> javaSrcs = new ArrayList<IPath>(); IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { javaSrcs.add(roots[i].getPath().removeFirstSegments(1)); } } srcs = javaSrcs.toArray(new IPath[javaSrcs.size()]); } StringBuilder folder = new StringBuilder(128); if (rootDir != null) { folder.append(rootDir).append('/'); } folder.append(CLASS_OUTPUT_DIR); int folderLen = folder.length(); if (monitor.isCanceled()) { return; } monitor.beginTask("Create zip...", toPackFiles.size()); ZipUtil zipFile = ZipUtil.newZipFile(fileAbsPath, true); try { for (Iterator iterator = toPackFiles.iterator(); !monitor.isCanceled() && iterator.hasNext();) { IFile file = (IFile) iterator.next(); if (srcs != null) { IJavaElement ele = JavaCore.create(file); if (ele instanceof ICompilationUnit) { IPath packagePath = null; IPath relPath = file.getProjectRelativePath(); for (int i = 0; i < srcs.length; i++) { if (srcs[i].isPrefixOf(relPath)) { packagePath = relPath.removeFirstSegments(srcs[i].segmentCount()) .removeLastSegments(1); } } IType[] czs = ((ICompilationUnit) ele).getAllTypes(); for (int i = 0; i < czs.length; i++) { String qname = czs[i].getTypeQualifiedName(); IPath cp = packagePath.append(qname + ".class"); IFile fclazz = project.getFile(outputDir.append(cp)); if (fclazz.isAccessible()) { folder.setLength(folderLen); zipFile.addStream(folder.append(cp.toString()).toString(), fclazz.getContents()); int anonymousCnt = 1; IFile anonymousCZ = null; do {//inner class... cp = packagePath.append(qname + "$" + anonymousCnt + ".class"); anonymousCnt++; anonymousCZ = project.getFile(outputDir.append(cp)); if (anonymousCZ.isAccessible()) { folder.setLength(folderLen); zipFile.addStream(folder.append(cp.toString()).toString(), anonymousCZ.getContents()); } else { anonymousCZ = null; } } while (anonymousCZ != null); } } file = null; } } if (file != null) { IVirtualResource[] vrs = ComponentCore.createResources(file); for (int i = 0; i < vrs.length; i++) { String path = vrs[i].getRuntimePath().toString(); if (rootDir != null) { path = rootDir + path; } else { path = path.substring(1); } InputStream is = file.getContents(); try { zipFile.addStream(path, is); } finally { try { is.close(); } catch (Exception e) { } } } } monitor.worked(1); } } finally { zipFile.close(); } monitor.done(); }
From source file:com.centurylink.mdw.plugin.WizardPage.java
License:Apache License
public void determinePackageFragmentRoot(WorkflowProject workflowProject) { IPackageFragmentRoot oldPackageFragmentRoot = getPackageFragmentRoot(); if (workflowProject != null && workflowProject.isLocalJavaSupported()) { try {/* w w w .j ava2 s . c om*/ IPackageFragmentRoot tempRoot = null; IPackageFragmentRoot srcRoot = null; IJavaProject javaProject = workflowProject == null ? null : workflowProject.getSourceJavaProject(); if (javaProject != null) { for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { if (pfr.getElementName().equals(MdwPlugin.getSettings().getTempResourceLocation())) { tempRoot = pfr; } else { srcRoot = pfr; break; } } } if (srcRoot == null && tempRoot == null) srcRoot = javaProject.getPackageFragmentRoot(javaProject.getResource()); setPackageFragmentRoot(srcRoot == null ? tempRoot : srcRoot, true); } } catch (JavaModelException ex) { PluginMessages.log(ex); } } else { setPackageFragmentRoot(getPackageFragmentRoot(), true); } if (oldPackageFragmentRoot == null || !oldPackageFragmentRoot.equals(getPackageFragmentRoot())) setPackageFragment(null, true); }
From source file:com.centurylink.mdw.plugin.WizardPage.java
License:Apache License
/** * Override to prefer non-temp package root. *//*from w w w .jav a 2s .com*/ @SuppressWarnings("restriction") @Override protected void initContainerPage(IJavaElement elem) { IPackageFragmentRoot tempRoot = null; // only as fallback IPackageFragmentRoot initRoot = null; if (elem != null) { initRoot = org.eclipse.jdt.internal.corext.util.JavaModelUtil.getPackageFragmentRoot(elem); try { if (initRoot == null || initRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { IJavaProject jproject = elem.getJavaProject(); if (jproject != null) { initRoot = null; if (jproject.exists()) { IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { if (roots[i].getElementName() .equals(MdwPlugin.getSettings().getTempResourceLocation())) { tempRoot = roots[i]; } else { initRoot = roots[i]; break; } } } } if (initRoot == null && tempRoot == null) { initRoot = jproject.getPackageFragmentRoot(jproject.getResource()); } } } } catch (JavaModelException e) { org.eclipse.jdt.internal.ui.JavaPlugin.log(e); } } setPackageFragmentRoot(initRoot == null ? tempRoot : initRoot, true); }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns a printable representation of this classpath entry. *//*from w w w . ja v a 2 s .c om*/ public String toString() { StringBuffer buffer = new StringBuffer(); Object target = JavaModel.getTarget(getPath(), true); if (target instanceof File) buffer.append(getPath().toOSString()); else buffer.append(String.valueOf(getPath())); buffer.append('['); switch (getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: buffer.append("CPE_LIBRARY"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: buffer.append("CPE_PROJECT"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE: buffer.append("CPE_SOURCE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE: buffer.append("CPE_VARIABLE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER: buffer.append("CPE_CONTAINER"); //$NON-NLS-1$ break; } buffer.append("]["); //$NON-NLS-1$ switch (getContentKind()) { case IPackageFragmentRoot.K_BINARY: buffer.append("K_BINARY"); //$NON-NLS-1$ break; case IPackageFragmentRoot.K_SOURCE: buffer.append("K_SOURCE"); //$NON-NLS-1$ break; case ClasspathEntry.K_OUTPUT: buffer.append("K_OUTPUT"); //$NON-NLS-1$ break; } buffer.append(']'); if (getSourceAttachmentPath() != null) { buffer.append("[sourcePath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentPath()); buffer.append(']'); } if (getSourceAttachmentRootPath() != null) { buffer.append("[rootPath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentRootPath()); buffer.append(']'); } buffer.append("[isExported:"); //$NON-NLS-1$ buffer.append(this.isExported); buffer.append(']'); IPath[] patterns = this.inclusionPatterns; int length; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[including:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } patterns = this.exclusionPatterns; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[excluding:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } if (this.accessRuleSet != null) { buffer.append('['); buffer.append(this.accessRuleSet.toString(false/*on one line*/)); buffer.append(']'); } if (this.entryKind == CPE_PROJECT) { buffer.append("[combine access rules:"); //$NON-NLS-1$ buffer.append(this.combineAccessRules); buffer.append(']'); } if (getOutputLocation() != null) { buffer.append("[output:"); //$NON-NLS-1$ buffer.append(getOutputLocation()); buffer.append(']'); } if ((length = this.extraAttributes == null ? 0 : this.extraAttributes.length) > 0) { buffer.append("[attributes:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(this.extraAttributes[i]); if (i != length - 1) { buffer.append(','); } } buffer.append(']'); } return buffer.toString(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
protected IStatus validateCompilationUnit(File resource) { IPackageFragmentRoot root = getPackageFragmentRoot(); // root never null as validation is not done for working copies try {//from w w w . java2 s .com if (root.getKind() != IPackageFragmentRoot.K_SOURCE) return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root); } catch (JavaModelException e) { return e.getJavaModelStatus(); } if (resource != null) { char[][] inclusionPatterns = ((PackageFragmentRoot) root).fullInclusionPatternChars(); char[][] exclusionPatterns = ((PackageFragmentRoot) root).fullExclusionPatternChars(); if (Util.isExcluded(new Path(resource.getPath()), inclusionPatterns, exclusionPatterns, false)) return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this); if (!resource.exists()) return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this); } IJavaProject project = getJavaProject(); return JavaConventions.validateCompilationUnitName(getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)); }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Notifies the given requestor of all types (classes and interfaces) in the * given package fragment with the given (unqualified) name. * Checks the requestor at regular intervals to see if the requestor * has canceled. If the given package fragment is <code>null</code>, all types in the * project whose simple name matches the given name are found. * * @param name// ww w . j a v a2 s. c o m * The name to search * @param pkg * The corresponding package fragment * @param partialMatch * partial name matches qualify when <code>true</code>; * only exact name matches qualify when <code>false</code> * @param acceptFlags * a bit mask describing if classes, interfaces or both classes and interfaces * are desired results. If no flags are specified, all types are returned. * @param requestor * The requestor that collects the result * @see #ACCEPT_CLASSES * @see #ACCEPT_INTERFACES * @see #ACCEPT_ENUMS * @see #ACCEPT_ANNOTATIONS */ public void seekTypes(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor, boolean considerSecondaryTypes) { /* if (VERBOSE) { Util.verbose(" SEEKING TYPES"); //$NON-NLS-1$ Util.verbose(" -> name: " + name); //$NON-NLS-1$ Util.verbose(" -> pkg: " + ((JavaElement) pkg).toStringWithAncestors()); //$NON-NLS-1$ Util.verbose(" -> partial match:" + partialMatch); //$NON-NLS-1$ } */ String matchName = partialMatch ? name.toLowerCase() : name; if (pkg == null) { findAllTypes(matchName, partialMatch, acceptFlags, requestor); return; } PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent(); try { // look in working copies first int firstDot = -1; String topLevelTypeName = null; int packageFlavor = root.internalKind(); if (this.typesInWorkingCopies != null || packageFlavor == IPackageFragmentRoot.K_SOURCE) { firstDot = matchName.indexOf('.'); if (!partialMatch) topLevelTypeName = firstDot == -1 ? matchName : matchName.substring(0, firstDot); } if (this.typesInWorkingCopies != null) { if (seekTypesInWorkingCopies(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor, considerSecondaryTypes)) return; } // look in model switch (packageFlavor) { case IPackageFragmentRoot.K_BINARY: matchName = matchName.replace('.', '$'); seekTypesInBinaryPackage(matchName, pkg, partialMatch, acceptFlags, requestor); break; case IPackageFragmentRoot.K_SOURCE: seekTypesInSourcePackage(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor); if (matchName.indexOf('$') != -1) { matchName = matchName.replace('$', '.'); firstDot = matchName.indexOf('.'); if (!partialMatch) topLevelTypeName = firstDot == -1 ? matchName : matchName.substring(0, firstDot); seekTypesInSourcePackage(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor); } break; default: return; } } catch (JavaModelException e) { return; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
/** * @see Openable//from w w w. ja v a2s . c o m */ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, File underlyingResource) throws JavaModelException { // add compilation units/class files from resources HashSet vChildren = new HashSet(); int kind = getKind(); PackageFragmentRoot root = getPackageFragmentRoot(); char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); File[] members = underlyingResource.listFiles(); { int length = members.length; if (length > 0) { IJavaProject project = getJavaProject(); String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); for (int i = 0; i < length; i++) { File child = members[i]; if (child.isFile() && !Util.isExcluded(new Path(child.getAbsolutePath()), inclusionPatterns, exclusionPatterns, false)) { IJavaElement childElement; if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName(), sourceLevel, complianceLevel)) { childElement = new CompilationUnit(this, manager, child.getName(), DefaultWorkingCopyOwner.PRIMARY); vChildren.add(childElement); } else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName(), sourceLevel, complianceLevel)) { childElement = getClassFile(child.getName()); vChildren.add(childElement); } } } } } if (kind == IPackageFragmentRoot.K_SOURCE) { // add primary compilation units ICompilationUnit[] primaryCompilationUnits = getCompilationUnits(DefaultWorkingCopyOwner.PRIMARY); for (int i = 0, length = primaryCompilationUnits.length; i < length; i++) { ICompilationUnit primary = primaryCompilationUnits[i]; vChildren.add(primary); } } IJavaElement[] children = new IJavaElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
/** * Returns a the collection of class files in this - a folder package fragment which has a root * that has its kind set to <code>IPackageFragmentRoot.K_Source</code> does not * recognize class files./*ww w .ja va 2 s . c om*/ * * @see org.eclipse.jdt.core.IPackageFragment#getClassFiles() */ public IClassFile[] getClassFiles() throws JavaModelException { if (getKind() == IPackageFragmentRoot.K_SOURCE) { return NO_CLASSFILES; } ArrayList list = getChildrenOfType(CLASS_FILE); IClassFile[] array = new IClassFile[list.size()]; list.toArray(array); return array; }
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
protected IStatus validateExistence(File underlyingResource) { // check that the name of the package is valid (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=108456) if (!isValidPackageName()) return newDoesNotExistStatus(); // check whether this pkg can be opened if (underlyingResource != null && !resourceExists(underlyingResource)) return newDoesNotExistStatus(); // check that it is not excluded (https://bugs.eclipse.org/bugs/show_bug.cgi?id=138577) int kind;/* w w w .j a v a 2 s . c o m*/ try { kind = getKind(); } catch (JavaModelException e) { return e.getStatus(); } if (kind == IPackageFragmentRoot.K_SOURCE && Util.isExcluded(this)) return newDoesNotExistStatus(); return JavaModelStatus.VERIFIED_OK; }