Java Code Examples for org.eclipse.jdt.core.IJavaProject#getOutputLocation()
The following examples show how to use
org.eclipse.jdt.core.IJavaProject#getOutputLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixProjectsUtils.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 6 votes |
public static void setOutputDirectory(IProgressMonitor monitor, IProject project, IJavaProject javaProject) { IPath outputLocation = null, newOutputLocation = null; try { outputLocation = javaProject.getOutputLocation(); // Only change the output location if it is the eclipse default one "bin" if ("bin".equals(outputLocation.lastSegment())) { newOutputLocation = outputLocation.removeLastSegments(1).append("eclipsebin"); javaProject.setOutputLocation(newOutputLocation, monitor); } } catch (JavaModelException e) { System.err.println("project:" + project.getName()); System.err.println("outputLocation:" + outputLocation); System.err.println("newOutputLocation:" + newOutputLocation); Activator.logError("Could not set output directory", e); } }
Example 2
Source File: GradleBuildSupport.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public boolean isBuildFile(IResource resource) { if (resource != null && resource.getType() == IResource.FILE && (resource.getName().endsWith(GRADLE_SUFFIX) || resource.getName().equals(GRADLE_PROPERTIES)) && ProjectUtils.isGradleProject(resource.getProject())) { try { if (!ProjectUtils.isJavaProject(resource.getProject())) { return true; } IJavaProject javaProject = JavaCore.create(resource.getProject()); IPath outputLocation = javaProject.getOutputLocation(); return outputLocation == null || !outputLocation.isPrefixOf(resource.getFullPath()); } catch (JavaModelException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } } return false; }
Example 3
Source File: JdtHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isFromOutputPath(IResource resource) { IProject project = resource.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.exists()) { try { IPath defaultOutputLocation = javaProject.getOutputLocation(); IPath resourcePath = resource.getFullPath(); if (defaultOutputLocation != null && !defaultOutputLocation.isEmpty() && defaultOutputLocation.isPrefixOf(resourcePath)) { return true; } IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for(IClasspathEntry classpathEntry: classpathEntries) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath specializedOutputLocation = classpathEntry.getOutputLocation(); if (specializedOutputLocation != null) { if (!specializedOutputLocation.equals(classpathEntry.getPath()) && specializedOutputLocation.isPrefixOf(resourcePath)) { return true; } } } } } catch(CoreException e) { if (log.isDebugEnabled()) log.debug("Error in isJavaTargetFolder():" + e.getMessage(), e); } } return false; }
Example 4
Source File: OutputFolderFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the result of this filter, when applied to the * given element. * * @param viewer the viewer * @param parent the parent * @param element the element to test * @return <code>true</code> if element should be included * @since 3.0 */ @Override public boolean select(Viewer viewer, Object parent, Object element) { if (element instanceof IFolder) { IFolder folder= (IFolder)element; IProject proj= folder.getProject(); try { if (!proj.hasNature(JavaCore.NATURE_ID)) return true; IJavaProject jProject= JavaCore.create(folder.getProject()); if (jProject == null || !jProject.exists()) return true; // Check default output location IPath defaultOutputLocation= jProject.getOutputLocation(); IPath folderPath= folder.getFullPath(); if (defaultOutputLocation != null && defaultOutputLocation.equals(folderPath)) return false; // Check output location for each class path entry IClasspathEntry[] cpEntries= jProject.getRawClasspath(); for (int i= 0, length= cpEntries.length; i < length; i++) { IPath outputLocation= cpEntries[i].getOutputLocation(); if (outputLocation != null && outputLocation.equals(folderPath)) return false; } } catch (CoreException ex) { return true; } } return true; }
Example 5
Source File: EditFilterAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IPath getOutputLocation(IJavaProject javaProject) { try { return javaProject.getOutputLocation(); } catch (CoreException e) { IProject project= javaProject.getProject(); IPath projPath= project.getFullPath(); return projPath.append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); } }
Example 6
Source File: CreateSourceFolderAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IPath getOutputLocation(IJavaProject javaProject) { try { return javaProject.getOutputLocation(); } catch (CoreException e) { IProject project= javaProject.getProject(); IPath projPath= project.getFullPath(); return projPath.append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); } }
Example 7
Source File: CreateLinkedSourceFolderAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IPath getOutputLocation(IJavaProject javaProject) { try { return javaProject.getOutputLocation(); } catch (CoreException e) { IProject project= javaProject.getProject(); IPath projPath= project.getFullPath(); return projPath.append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); } }
Example 8
Source File: JarFileExportOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isOutputFolder(IFolder folder) { try { IJavaProject javaProject= JavaCore.create(folder.getProject()); IPath outputFolderPath= javaProject.getOutputLocation(); return folder.getFullPath().equals(outputFolderPath); } catch (JavaModelException ex) { return false; } }
Example 9
Source File: JavaUtils.java From developer-studio with Apache License 2.0 | 5 votes |
public static IPath getJavaOutputDirectory(IProject project){ IPath outputLocation = null; try { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { outputLocation = javaProject.getOutputLocation(); } } catch (JavaModelException e) { } return outputLocation; }
Example 10
Source File: ClasspathChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static ClasspathChange removeEntryChange(IJavaProject project, IClasspathEntry entryToRemove) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); ArrayList<IClasspathEntry> newClasspath= new ArrayList<IClasspathEntry>(); for (int i= 0; i < rawClasspath.length; i++) { IClasspathEntry curr= rawClasspath[i]; if (curr.getEntryKind() != entryToRemove.getEntryKind() || !curr.getPath().equals(entryToRemove.getPath())) { newClasspath.add(curr); } } IClasspathEntry[] entries= newClasspath.toArray(new IClasspathEntry[newClasspath.size()]); IPath outputLocation= project.getOutputLocation(); return newChange(project, entries, outputLocation); }
Example 11
Source File: ClasspathChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static ClasspathChange addEntryChange(IJavaProject project, IClasspathEntry entryToAdd) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); IClasspathEntry[] newClasspath= new IClasspathEntry[rawClasspath.length + 1]; System.arraycopy(rawClasspath, 0, newClasspath, 0, rawClasspath.length); newClasspath[rawClasspath.length]= entryToAdd; IPath outputLocation= project.getOutputLocation(); return newChange(project, newClasspath, outputLocation); }
Example 12
Source File: WebAppUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Sets the project's default output directory to the WAR output directory's * WEB-INF/classes folder. If the WAR output directory does not have a WEB-INF * directory, this method returns without doing anything. * * @throws CoreException if there's a problem setting the output directory */ public static void setOutputLocationToWebInfClasses(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { IProject project = javaProject.getProject(); IFolder webInfOut = getWebInfOut(project); if (!webInfOut.exists()) { // If the project has no output <WAR>/WEB-INF directory, don't touch the // output location return; } IPath oldOutputPath = javaProject.getOutputLocation(); IPath outputPath = webInfOut.getFullPath().append("classes"); if (!outputPath.equals(oldOutputPath)) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); // Remove old output location and contents IFolder oldOutputFolder = workspaceRoot.getFolder(oldOutputPath); if (oldOutputFolder.exists()) { try { removeOldClassfiles(oldOutputFolder); } catch (Exception e) { CorePluginLog.logError(e); } } // Create the new output location if necessary IFolder outputFolder = workspaceRoot.getFolder(outputPath); if (!outputFolder.exists()) { // TODO: Could move recreate this in a utilities class CoreUtility.createDerivedFolder(outputFolder, true, true, null); } javaProject.setOutputLocation(outputPath, monitor); } }
Example 13
Source File: DeployJob.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Gets the java output directory of the given project. * * @return the java output directory */ private IPath getJavaOutputDirectory() { IPath outputLocation = null; try { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { outputLocation = javaProject.getOutputLocation(); } } catch (JavaModelException e) { LOGGER.error("Failed to get java output of the project", e); //$NON-NLS-1$ return null; } return outputLocation; }
Example 14
Source File: ClasspathChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static ClasspathChange removeEntryChange(IJavaProject project, IClasspathEntry entryToRemove) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); ArrayList<IClasspathEntry> newClasspath= new ArrayList<>(); for (int i= 0; i < rawClasspath.length; i++) { IClasspathEntry curr= rawClasspath[i]; if (curr.getEntryKind() != entryToRemove.getEntryKind() || !curr.getPath().equals(entryToRemove.getPath())) { newClasspath.add(curr); } } IClasspathEntry[] entries= newClasspath.toArray(new IClasspathEntry[newClasspath.size()]); IPath outputLocation= project.getOutputLocation(); return newChange(project, entries, outputLocation); }
Example 15
Source File: ClasspathChange.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static ClasspathChange addEntryChange(IJavaProject project, IClasspathEntry entryToAdd) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); IClasspathEntry[] newClasspath= new IClasspathEntry[rawClasspath.length + 1]; System.arraycopy(rawClasspath, 0, newClasspath, 0, rawClasspath.length); newClasspath[rawClasspath.length]= entryToAdd; IPath outputLocation= project.getOutputLocation(); return newChange(project, newClasspath, outputLocation); }
Example 16
Source File: CreateAppEngineWtpProject.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private void fixTestSourceDirectorySettings(IProject newProject, IProgressMonitor monitor) throws CoreException { // 1. Fix the output folder of "src/test/java". IPath testSourcePath = newProject.getFolder("src/test/java").getFullPath(); IJavaProject javaProject = JavaCore.create(newProject); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().equals(testSourcePath) && entry.getOutputLocation() == null) { // Default output location? IPath oldOutputPath = javaProject.getOutputLocation(); IPath newOutputPath = oldOutputPath.removeLastSegments(1).append("test-classes"); entries[i] = JavaCore.newSourceEntry(testSourcePath, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, newOutputPath); javaProject.setRawClasspath(entries, monitor); break; } } // 2. Remove "src/test/java" from the Web Deployment Assembly sources. deployAssemblyEntryRemoveJob = new DeployAssemblyEntryRemoveJob(newProject, new Path("src/test/java")); deployAssemblyEntryRemoveJob.setSystem(true); deployAssemblyEntryRemoveJob.schedule(); }
Example 17
Source File: NewModuleWizardPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
private IStatus packageChanged() { String packName = modulePackageField.getText(); IStatus validatePackageStatus = Util.validatePackageName(packName); if (validatePackageStatus.getSeverity() == IStatus.ERROR) { return validatePackageStatus; } if (packName.length() == 0) { modulePackageField.setStatus(NewWizardMessages.NewTypeWizardPage_default); } else { modulePackageField.setStatus(""); } IJavaProject project = getJavaProject(); IPackageFragmentRoot root = getPackageFragmentRoot(); if (project != null && root != 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)) { return Util.newErrorStatus(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); } } } catch (JavaModelException e) { // Not a critical exception at this juncture; we'll just log it // and move on. GWTPluginLog.logError(e); } } } return validatePackageStatus; }
Example 18
Source File: ClasspathModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Validate the new entry in the context of the existing entries. Furthermore, * check if exclusion filters need to be applied and do so if necessary. * * If validation was successful, add the new entry to the list of existing entries. * * @param entry the entry to be validated and added to the list of existing entries. * @param existingEntries a list of existing entries representing the build path * @param project the Java project * @throws CoreException in case that validation fails */ private static void validateAndAddEntry(CPListElement entry, List<CPListElement> existingEntries, IJavaProject project) throws CoreException { IPath path= entry.getPath(); IPath projPath= project.getProject().getFullPath(); IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); IStatus validate= workspaceRoot.getWorkspace().validatePath(path.toString(), IResource.FOLDER); StatusInfo rootStatus= new StatusInfo(); rootStatus.setOK(); boolean isExternal= isExternalArchiveOrLibrary(entry); if (!isExternal && validate.matches(IStatus.ERROR) && !project.getPath().equals(path)) { rootStatus.setError(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName, validate.getMessage())); throw new CoreException(rootStatus); } else { if (!isExternal && !project.getPath().equals(path)) { IResource res= workspaceRoot.findMember(path); if (res != null) { if (res.getType() != IResource.FOLDER && res.getType() != IResource.FILE) { rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_NotAFolder); throw new CoreException(rootStatus); } } else { URI projLocation= project.getProject().getLocationURI(); if (projLocation != null) { IFileStore store= EFS.getStore(projLocation).getFileStore(path); if (store.fetchInfo().exists()) { rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExistingDifferentCase); throw new CoreException(rootStatus); } } } } for (int i= 0; i < existingEntries.size(); i++) { CPListElement curr= existingEntries.get(i); if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (path.equals(curr.getPath()) && !project.getPath().equals(path)) { rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting); throw new CoreException(rootStatus); } } } if (!isExternal && !entry.getPath().equals(project.getPath())) exclude(entry.getPath(), existingEntries, new ArrayList<CPListElement>(), project, null); IPath outputLocation= project.getOutputLocation(); insertAtEndOfCategory(entry, existingEntries); IClasspathEntry[] entries= convert(existingEntries); IJavaModelStatus status= JavaConventions.validateClasspath(project, entries, outputLocation); if (!status.isOK()) { if (outputLocation.equals(projPath)) { IStatus status2= JavaConventions.validateClasspath(project, entries, outputLocation); if (status2.isOK()) { if (project.isOnClasspath(project)) { rootStatus.setInfo(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSFandOL, BasicElementLabels.getPathLabel(outputLocation, false))); } else { rootStatus.setInfo(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceOL, BasicElementLabels.getPathLabel(outputLocation, false))); } return; } } rootStatus.setError(status.getMessage()); throw new CoreException(rootStatus); } if (isSourceFolder(project) || project.getPath().equals(path)) { rootStatus.setWarning(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSF); return; } rootStatus.setOK(); return; } }
Example 19
Source File: NewTypeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * 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> * 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); IResource resource= fCurrPackage.getResource(); if (resource != null){ if (resource.isVirtual()){ status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageIsVirtual); return status; } if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) { status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageNameFiltered); return status; } } } else { status.setError(""); //$NON-NLS-1$ } return status; }
Example 20
Source File: JreServiceProjectSREProviderFactory.java From sarl with Apache License 2.0 | 4 votes |
private static ProjectSREProvider findOnClasspath(IJavaProject project) { try { final IClasspathEntry[] classpath = project.getResolvedClasspath(true); for (final IClasspathEntry entry : classpath) { final IPath path; final String id; final String name; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: path = entry.getPath(); if (path != null) { id = path.makeAbsolute().toPortableString(); name = path.lastSegment(); } else { id = null; name = null; } break; case IClasspathEntry.CPE_PROJECT: final IResource res = project.getProject().getParent().findMember(entry.getPath()); if (res instanceof IProject) { final IProject dependency = (IProject) res; final IJavaProject javaDependency = JavaCore.create(dependency); path = javaDependency.getOutputLocation(); id = javaDependency.getHandleIdentifier(); name = javaDependency.getElementName(); break; } continue; default: continue; } if (path != null && !SARLRuntime.isPackedSRE(path) && !SARLRuntime.isUnpackedSRE(path)) { final String bootstrap = SARLRuntime.getDeclaredBootstrap(path); if (!Strings.isEmpty(bootstrap)) { final List<IRuntimeClasspathEntry> classpathEntries = Collections.singletonList(new RuntimeClasspathEntry(entry)); return new JreServiceProjectSREProvider( id, name, project.getPath().toPortableString(), bootstrap, classpathEntries); } } } } catch (JavaModelException exception) { // } return null; }