List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.eclipse.ajdt.internal.core.ajde.CoreOutputLocationManager.java
License:Open Source License
/** * Record the 'common output directory', namely the one where all the output * goes// w w w .j a v a2s . co m */ private void setCommonOutputDir() { IJavaProject jProject = JavaCore.create(project); IPath workspaceRelativeOutputPath; try { workspaceRelativeOutputPath = jProject.getOutputLocation(); } catch (JavaModelException e) { commonOutputDir = project.getLocation().toFile(); outputIsRoot = true; return; } if (workspaceRelativeOutputPath.segmentCount() == 1) { commonOutputDir = jProject.getResource().getLocation().toFile(); outputIsRoot = true; return; } IFolder out = ResourcesPlugin.getWorkspace().getRoot().getFolder(workspaceRelativeOutputPath); commonOutputDir = out.getLocation().toFile(); }
From source file:org.eclipse.ajdt.internal.core.ajde.CoreOutputLocationManager.java
License:Open Source License
private void handleClassPathEntry(IJavaProject jp, IClasspathEntry cpe) throws JavaModelException { switch (cpe.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jp); if (container != null && container.getKind() != IClasspathContainer.K_DEFAULT_SYSTEM) { IClasspathEntry[] cpes = container.getClasspathEntries(); for (int i = 0; i < cpes.length; i++) { handleClassPathEntry(jp, cpes[i]); }/*from w w w .j a v a 2 s . co m*/ } break; case IClasspathEntry.CPE_LIBRARY: File libFile = pathToFile(cpe.getPath()); if (libFile.isDirectory()) { // ignore jar files if (libFile != null && !binFolderToProject.containsKey(libFile)) { binFolderToProject.put(libFile, jp.getProject()); } } break; case IClasspathEntry.CPE_PROJECT: IJavaProject jpClasspath = pathToProject(cpe.getPath()); if (jpClasspath != null) { mapProject(jpClasspath); } break; case IClasspathEntry.CPE_SOURCE: File outFile = pathToFile( cpe.getOutputLocation() == null ? jp.getOutputLocation() : cpe.getOutputLocation()); if (outFile != null && !binFolderToProject.containsKey(outFile)) { binFolderToProject.put(outFile, jp.getProject()); } break; case IClasspathEntry.CPE_VARIABLE: IClasspathEntry cpeResolved = JavaCore.getResolvedClasspathEntry(cpe); if (cpeResolved != null) { handleClassPathEntry(jp, cpeResolved); } break; } }
From source file:org.eclipse.ajdt.internal.launching.LTWUtils.java
License:Open Source License
private static void copyToOutputFolder(IFile file, IJavaProject javaProject, IClasspathEntry srcEntry) throws CoreException { IPath outputPath = srcEntry.getOutputLocation(); if (outputPath == null) { outputPath = javaProject.getOutputLocation(); }/*from www . j a v a2s. c o m*/ outputPath = outputPath.removeFirstSegments(1).makeRelative(); IContainer outputFolder = getContainerForGivenPath(outputPath, javaProject.getProject()); IContainer srcContainer = getContainerForGivenPath(srcEntry.getPath().removeFirstSegments(1), javaProject.getProject()); if (!outputFolder.equals(srcContainer)) { IResource outputFile = outputFolder.getFile(new Path(AOP_XML_LOCATION)); if (outputFile.exists()) { AJLog.log("Deleting existing file " + outputFile);//$NON-NLS-1$ outputFile.delete(IResource.FORCE, null); } AJLog.log("Copying added file " + file);//$NON-NLS-1$ IFolder metainf = (IFolder) ((Workspace) ResourcesPlugin.getWorkspace()).newResource( new Path(outputFolder.getFullPath() + "/META-INF"), //$NON-NLS-1$ IResource.FOLDER); if (!metainf.exists()) { metainf.create(true, true, null); } file.copy(outputFile.getFullPath(), IResource.FORCE, null); outputFile.setDerived(true); outputFile.refreshLocal(IResource.DEPTH_ZERO, null); } }
From source file:org.eclipse.ajdt.internal.ui.ajdocexport.AJdocTreeWizardPage.java
License:Open Source License
private IPath[] getClassPath(IJavaProject[] javaProjects) { HashSet res = new HashSet(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (int j = 0; j < javaProjects.length; j++) { IJavaProject curr = javaProjects[j]; try {// w ww. j a v a2 s . c o m IPath outputLocation = null; IResource outputPathFolder = root.findMember(curr.getOutputLocation()); if (outputPathFolder != null) outputLocation = outputPathFolder.getLocation(); String[] classPath = JavaRuntime.computeDefaultRuntimeClassPath(curr); for (int i = 0; i < classPath.length; i++) { IPath path = Path.fromOSString(classPath[i]); if (!path.equals(outputLocation)) { res.add(path); } } } catch (CoreException e) { JavaPlugin.log(e); } } return (IPath[]) res.toArray(new IPath[res.size()]); }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
/** * Exports the passed resource to the JAR file * * @param element the resource or JavaElement to export *///www .ja v a2 s. co m protected void exportElement(Object element, IProgressMonitor progressMonitor) throws InterruptedException { // AspectJ Change Begin if (!AspectJPlugin.USING_CU_PROVIDER) { // Don't export AJCompilationUnits because they are duplicates of files that we also export. if (element instanceof AJCompilationUnit) { return; } } // AspectJ Change End int leadSegmentsToRemove = 1; IPackageFragmentRoot pkgRoot = null; boolean isInJavaProject = false; IResource resource = null; IJavaProject jProject = null; if (element instanceof IJavaElement) { isInJavaProject = true; IJavaElement je = (IJavaElement) element; int type = je.getElementType(); if (type != IJavaElement.CLASS_FILE && type != IJavaElement.COMPILATION_UNIT) { exportJavaElement(progressMonitor, je); return; } try { resource = je.getUnderlyingResource(); } catch (JavaModelException ex) { addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_resourceNotFound, je.getElementName()), ex); return; } jProject = je.getJavaProject(); pkgRoot = JavaModelUtil.getPackageFragmentRoot(je); } else resource = (IResource) element; if (!resource.isAccessible()) { addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_resourceNotFound, resource.getFullPath()), null); return; } if (resource.getType() == IResource.FILE) { if (!isInJavaProject) { // check if it's a Java resource try { isInJavaProject = resource.getProject().hasNature(JavaCore.NATURE_ID); } catch (CoreException ex) { addWarning( Messages.format(JarPackagerMessages.JarFileExportOperation_projectNatureNotDeterminable, resource.getFullPath()), ex); return; } if (isInJavaProject) { jProject = JavaCore.create(resource.getProject()); try { IPackageFragment pkgFragment = jProject .findPackageFragment(resource.getFullPath().removeLastSegments(1)); if (pkgFragment != null) pkgRoot = JavaModelUtil.getPackageFragmentRoot(pkgFragment); else pkgRoot = findPackageFragmentRoot(jProject, resource.getFullPath().removeLastSegments(1)); } catch (JavaModelException ex) { addWarning(Messages.format( JarPackagerMessages.JarFileExportOperation_javaPackageNotDeterminable, resource.getFullPath()), ex); return; } } } if (pkgRoot != null && jProject != null) { leadSegmentsToRemove = pkgRoot.getPath().segmentCount(); boolean isOnBuildPath; isOnBuildPath = jProject.isOnClasspath(resource); if (!isOnBuildPath || (mustUseSourceFolderHierarchy() && !pkgRoot.getElementName().equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH))) leadSegmentsToRemove--; } IPath destinationPath = resource.getFullPath().removeFirstSegments(leadSegmentsToRemove); boolean isInOutputFolder = false; if (isInJavaProject && jProject != null) { try { isInOutputFolder = jProject.getOutputLocation().isPrefixOf(resource.getFullPath()); } catch (JavaModelException ex) { isInOutputFolder = false; } } exportClassFiles(progressMonitor, pkgRoot, resource, jProject, destinationPath); exportResource(progressMonitor, pkgRoot, isInJavaProject, resource, destinationPath, isInOutputFolder); progressMonitor.worked(1); ModalContext.checkCanceled(progressMonitor); } else exportContainer(progressMonitor, (IContainer) resource); }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
private boolean isOutputFolder(IFolder folder) { try {// www . jav a2 s .c o m IJavaProject javaProject = JavaCore.create(folder.getProject()); IPath outputFolderPath = javaProject.getOutputLocation(); return folder.getFullPath().equals(outputFolderPath); } catch (JavaModelException ex) { return false; } }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
private IContainer[] getOutputContainers(IJavaProject javaProject) throws CoreException { Set<IPath> outputPaths = new HashSet<IPath>(); boolean includeDefaultOutputPath = false; IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i] != null) { IClasspathEntry cpEntry = roots[i].getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = cpEntry.getOutputLocation(); if (location != null) outputPaths.add(location); else includeDefaultOutputPath = true; }/*from w w w. j a v a 2 s . c om*/ } } if (includeDefaultOutputPath) { // Use default output location outputPaths.add(javaProject.getOutputLocation()); } // Convert paths to containers Set<IContainer> outputContainers = new HashSet<IContainer>(outputPaths.size()); Iterator<IPath> iter = outputPaths.iterator(); while (iter.hasNext()) { IPath path = iter.next(); if (javaProject.getProject().getFullPath().equals(path)) outputContainers.add(javaProject.getProject()); else { IFolder outputFolder = createFolderHandle(path); if (outputFolder == null || !outputFolder.isAccessible()) { String msg = JarPackagerMessages.JarFileExportOperation_outputContainerNotAccessible; addToStatus(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null))); } else outputContainers.add(outputFolder); } } return outputContainers.toArray(new IContainer[outputContainers.size()]); }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
/** * Returns an iterator on a list with files that correspond to the * passed file and that are on the classpath of its project. * * @param file the file for which to find the corresponding classpath resources * @param pathInJar the path that the file has in the JAR (i.e. project and source folder segments removed) * @param javaProject the javaProject that contains the file * @param pkgRoot the package fragment root that contains the file * @return the iterator over the corresponding classpath files for the given file *//* ww w.j a v a2 s .c o m*/ protected Iterator<IFile> filesOnClasspath(IFile file, IPath pathInJar, IJavaProject javaProject, IPackageFragmentRoot pkgRoot, IProgressMonitor progressMonitor) throws CoreException { // Allow JAR Package to provide its own strategy IFile[] classFiles = fJarPackage.findClassfilesFor(file); if (classFiles != null) return Arrays.asList(classFiles).iterator(); if (!isJavaFile(file)) return Collections.<IFile>emptyList().iterator(); IPath outputPath = null; if (pkgRoot != null) { IClasspathEntry cpEntry = pkgRoot.getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) outputPath = cpEntry.getOutputLocation(); } if (outputPath == null) // Use default output location outputPath = javaProject.getOutputLocation(); IContainer outputContainer; if (javaProject.getProject().getFullPath().equals(outputPath)) outputContainer = javaProject.getProject(); else { outputContainer = createFolderHandle(outputPath); if (outputContainer == null || !outputContainer.isAccessible()) { String msg = JarPackagerMessages.JarFileExportOperation_outputContainerNotAccessible; throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null)); } } // Java CU - search files with .class ending boolean hasErrors = hasCompileErrors(file); boolean hasWarnings = hasCompileWarnings(file); boolean canBeExported = canBeExported(hasErrors, hasWarnings); if (!canBeExported) return Collections.<IFile>emptyList().iterator(); reportPossibleCompileProblems(file, hasErrors, hasWarnings, canBeExported); IContainer classContainer = outputContainer; if (pathInJar.segmentCount() > 1) classContainer = outputContainer.getFolder(pathInJar.removeLastSegments(1)); if (fExportedClassContainers.contains(classContainer)) return Collections.<IFile>emptyList().iterator(); if (fClassFilesMapContainer == null || !fClassFilesMapContainer.equals(classContainer)) { fJavaNameToClassFilesMap = buildJavaToClassMap(classContainer); if (fJavaNameToClassFilesMap == null) { // Could not fully build map. fallback is to export whole directory IPath location = classContainer.getLocation(); String containerName = ""; //$NON-NLS-1$ if (location != null) containerName = location.toFile().toString(); String msg = Messages.format( JarPackagerMessages.JarFileExportOperation_missingSourceFileAttributeExportedAll, containerName); addInfo(msg, null); fExportedClassContainers.add(classContainer); return getClassesIn(classContainer); } fClassFilesMapContainer = classContainer; } ArrayList classFileList = (ArrayList) fJavaNameToClassFilesMap.get(file.getName()); if (classFileList == null || classFileList.isEmpty()) { String msg = Messages.format( JarPackagerMessages.JarFileExportOperation_classFileOnClasspathNotAccessible, file.getFullPath()); throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null)); } return classFileList.iterator(); }
From source file:org.eclipse.ajdt.internal.ui.wizards.NewTypeWizardPage.java
License:Open Source License
/** * A hook method that gets called when the package field has changed. The method * validates the package name and returns the status of the validation. The validation * also updates the package fragment model. * <p>/*from www . j a v a2s . c om*/ * Subclasses may extend this method to perform their own validation. * </p> * * @return the status of the validation */ protected IStatus packageChanged() { StatusInfo status = new StatusInfo(); IPackageFragmentRoot root = getPackageFragmentRoot(); fPackageDialogField.enableButton(root != null); IJavaProject project = root != null ? root.getJavaProject() : null; String packName = getPackageText(); if (packName.length() > 0) { IStatus val = validatePackageName(packName, project); if (val.getSeverity() == IStatus.ERROR) { status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage())); return status; } else if (val.getSeverity() == IStatus.WARNING) { status.setWarning(Messages.format( NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage())); // continue } } else { status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged); } if (project != null) { if (project.exists() && packName.length() > 0) { try { IPath rootPath = root.getPath(); IPath outputPath = project.getOutputLocation(); if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) { // if the bin folder is inside of our root, don't allow to name a package // like the bin folder IPath packagePath = rootPath.append(packName.replace('.', '/')); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); return status; } } } catch (JavaModelException e) { JavaPlugin.log(e); // let pass } } fCurrPackage = root.getPackageFragment(packName); } else { status.setError(""); //$NON-NLS-1$ } return status; }
From source file:org.eclipse.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
/** * Bug 98911: Delete any .aj files from the output folder, if the output * folder and the source folder are not the same. *///from w ww . j a v a2s. c o m private static void checkOutputFoldersForAJFiles(IProject project) throws CoreException { IJavaProject jp = JavaCore.create(project); if (jp == null) { return; } IPath defaultOutputLocation = jp.getOutputLocation(); if (defaultOutputLocation.equals(project.getFullPath())) { return; } boolean defaultOutputLocationIsSrcFolder = false; List<IPath> extraOutputLocations = new ArrayList<IPath>(); List<IClasspathEntry> srcFolders = new ArrayList<IClasspathEntry>(); IClasspathEntry[] cpe = jp.getRawClasspath(); for (int i = 0; i < cpe.length; i++) { if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcFolders.add(cpe[i]); IPath output = cpe[i].getOutputLocation(); if (output != null) { extraOutputLocations.add(output); } } } for (IClasspathEntry entry : srcFolders) { IPath path = entry.getPath(); if (path.equals(defaultOutputLocation)) { defaultOutputLocationIsSrcFolder = true; } for (Iterator<IPath> iterator = extraOutputLocations.iterator(); iterator.hasNext();) { IPath outputPath = iterator.next(); if (outputPath.equals(path)) { iterator.remove(); } } } boolean ajFilesFound = false; if (!defaultOutputLocationIsSrcFolder) { IFolder folder = project.getWorkspace().getRoot().getFolder(defaultOutputLocation); ajFilesFound = containsAJFiles(folder); } if (!ajFilesFound && extraOutputLocations.size() > 0) { for (IPath outputPath : extraOutputLocations) { IFolder folder = project.getWorkspace().getRoot().getFolder(outputPath); ajFilesFound = ajFilesFound || containsAJFiles(folder); } } if (ajFilesFound) { IWorkbenchWindow window = AspectJUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); boolean remove = MessageDialog.openQuestion(window.getShell(), UIMessages.AJFiles_title, UIMessages.AJFiles_message); if (remove) { if (!defaultOutputLocationIsSrcFolder) { AJBuilder.cleanAJFilesFromOutputFolder(defaultOutputLocation); } for (IPath extraLocationPath : extraOutputLocations) { AJBuilder.cleanAJFilesFromOutputFolder(extraLocationPath); } } } }