List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.eclipse.acceleo.internal.ide.ui.builders.AcceleoBuilder.java
License:Open Source License
/** * Computes the classpath for the given java project. * //from w w w . j av a 2s.co m * @param javaProject * The Java project * @return The classpath entries */ private Set<AcceleoProjectClasspathEntry> computeProjectClassPath(IJavaProject javaProject) { Set<AcceleoProjectClasspathEntry> classpathEntries = new LinkedHashSet<AcceleoProjectClasspathEntry>(); // Compute the classpath of the acceleo project IClasspathEntry[] rawClasspath; try { rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry iClasspathEntry : rawClasspath) { int entryKind = iClasspathEntry.getEntryKind(); if (IClasspathEntry.CPE_SOURCE == entryKind) { // We have the source folders of the project. IPath inputFolderPath = iClasspathEntry.getPath(); IPath outputFolderPath = iClasspathEntry.getOutputLocation(); if (outputFolderPath == null) { outputFolderPath = javaProject.getOutputLocation(); } IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(inputFolderPath.lastSegment()); if (!(project != null && project.exists() && project.equals(javaProject.getProject()))) { IContainer inputContainer = ResourcesPlugin.getWorkspace().getRoot() .getFolder(inputFolderPath); IContainer outputContainer = ResourcesPlugin.getWorkspace().getRoot() .getFolder(outputFolderPath); if (inputContainer != null && outputContainer != null) { File inputDirectory = inputContainer.getLocation().toFile(); File outputDirectory = outputContainer.getLocation().toFile(); AcceleoProjectClasspathEntry entry = new AcceleoProjectClasspathEntry(inputDirectory, outputDirectory); classpathEntries.add(entry); this.outputFolders.add(outputDirectory); } } } } } catch (JavaModelException e) { AcceleoUIActivator.log(e, true); } return classpathEntries; }
From source file:org.eclipse.acceleo.internal.ide.ui.editors.template.actions.refactor.AcceleoRefactoringUtils.java
License:Open Source License
/** * Gets the output folder of the project. For example : '/MyProject/bin'. * //from ww w. j a va 2 s. c o m * @param aProject * is a project of the workspace * @return the output folder of the project, or null if it doesn't exist * @see org.eclipse.acceleo.ide.ui.resources.AcceleoProject.getOutputFolder(IProject aProject) */ public static IPath getOutputFolder(IProject aProject) { final IJavaProject javaProject = JavaCore.create(aProject); try { IPath output = javaProject.getOutputLocation(); if (output != null && output.segmentCount() > 1) { IFolder folder = aProject.getWorkspace().getRoot().getFolder(output); if (folder.isAccessible()) { return folder.getFullPath(); } } } catch (JavaModelException e) { AcceleoUIActivator.getDefault().getLog().log(e.getStatus()); } return null; }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
/** * Copies over all non-excluded resources into the out folders. * //from w w w. j av a2 s . c om * Called during a full build * * @param javaProject */ private void copyResources(IJavaProject project) throws CoreException { IClasspathEntry[] srcEntries = getSrcClasspathEntry(project); for (int i = 0, l = srcEntries.length; i < l; i++) { IClasspathEntry srcEntry = srcEntries[i]; IPath srcPath = srcEntry.getPath().removeFirstSegments(1); IPath outPath = srcEntry.getOutputLocation(); if (outPath == null) { outPath = project.getOutputLocation(); } outPath = outPath.removeFirstSegments(1); if (!srcPath.equals(outPath)) { final char[][] inclusionPatterns = ((ClasspathEntry) srcEntry).fullInclusionPatternChars(); final char[][] exclusionPatterns = ((ClasspathEntry) srcEntry).fullExclusionPatternChars(); final IContainer srcContainer = getContainerForGivenPath(srcPath, project.getProject()); if (!srcContainer.exists()) { continue; } final int segmentsToRemove = srcContainer.getLocation().segmentCount(); final IContainer outContainer = getContainerForGivenPath(outPath, project.getProject()); if (outContainer.getType() == IResource.FOLDER && (!outContainer.exists())) { // also ensure parent folders exist createFolder(outPath, getProject(), false); } IResourceVisitor copyVisitor = new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) { return false; } else if (resource.getType() == IResource.PROJECT) { return true; } if (resource.getType() == IResource.FOLDER || !isSourceFile(resource)) { // refresh to ensure that resource has not been deleted from file system resource.refreshLocal(IResource.DEPTH_ZERO, null); if (resource.exists()) { switch (resource.getType()) { case IResource.FOLDER: // ensure folder exists and is derived IPath outPath = resource.getLocation().removeFirstSegments(segmentsToRemove); IFolder outFolder = (IFolder) createFolder(outPath, outContainer, true); // outfolder itself should not be derived if (outFolder.equals(outContainer)) { outFolder.setDerived(false, null); } break; case IResource.FILE: // if this is not a CU, then copy over and mark as derived if (!isSourceFile(resource)) { outPath = resource.getLocation().removeFirstSegments(segmentsToRemove); IFile outFile = outContainer.getFile(outPath); // check to make sure that resource has not been deleted from the file // system without a refresh if (!outFile.exists()) { try { resource.copy(outFile.getFullPath(), IResource.DERIVED | IResource.FORCE, null); Util.setReadOnly(outFile, false); } catch (ResourceException e) { resource.refreshLocal(IResource.DEPTH_ZERO, null); if (resource.exists()) { // probably hit https://bugs.eclipse.org/bugs/show_bug.cgi?id=331036 // We just checked to see if the outfile exists, but we get this exception // anyway. It might be that it has not been refreshed. if (e.getStatus() .getCode() == IResourceStatus.FAILED_WRITE_LOCAL) { AJLog.log(AJLog.BUILDER, "Could not write to resource '" + resource + "'. " + "It probbly already exists on disk. Try a clean build."); outFile.refreshLocal(IResource.DEPTH_ZERO, null); } else { throw e; } } else { // resource was deleted in the middle of the build. Can safely ignore this } } } } break; } return true; } } return false; } }; srcContainer.accept(copyVisitor); } } }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
/** * Copies non-src resources to the output directory (bug 78579). The main * part of this method was taken from // w ww . j a v a2s . c o m * org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IResourceDelta,ClasspathMultiDirectory,int) * * @param IJavaProject - the project which is being built * @param IResourceDelta - the projects delta * @param IClasspathEntry - the src entry on the classpath * @param int - the segment count * * @throws CoreException */ private void copyResources(IJavaProject javaProject, IResourceDelta sourceDelta, IClasspathEntry srcEntry, int segmentCount) throws CoreException { IResource resource = sourceDelta.getResource(); // bug 161739: skip excluded resources char[][] inclusionPatterns = ((ClasspathEntry) srcEntry).fullInclusionPatternChars(); char[][] exclusionPatterns = ((ClasspathEntry) srcEntry).fullExclusionPatternChars(); if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) { return; } IPath outputPath = srcEntry.getOutputLocation(); if (outputPath == null) { outputPath = javaProject.getOutputLocation(); } outputPath = outputPath.removeFirstSegments(1).makeRelative(); IContainer outputFolder = getContainerForGivenPath(outputPath, javaProject.getProject()); IContainer srcContainer = getContainerForGivenPath(srcEntry.getPath().removeFirstSegments(1), javaProject.getProject()); IPath deltaPath = resource.getFullPath().removeFirstSegments(segmentCount); switch (resource.getType()) { case IResource.FOLDER: IContainer folderToRefresh = outputFolder.getFolder(deltaPath); switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: createFolder(deltaPath, outputFolder, true); // ensure package exists in the output folder // fall through & collect all the resource files case IResourceDelta.CHANGED: IResourceDelta[] children = sourceDelta.getAffectedChildren(); for (int i = 0, l = children.length; i < l; i++) { copyResources(javaProject, children[i], srcEntry, segmentCount); } break; case IResourceDelta.REMOVED: IClasspathEntry[] srcEntries = getSrcClasspathEntry(javaProject); if (srcEntries.length > 1) { for (int i = 0, l = srcEntries.length; i < l; i++) { IPath srcPath = srcEntries[i].getPath().removeFirstSegments(1); IFolder srcFolder = javaProject.getProject().getFolder(srcPath); if (srcFolder.getFolder(deltaPath).exists()) { // only a package fragment was removed, same as removing multiple source files // ensure package exists in the output folder // ADE---wait...why are we doing this??? why not just delete and be done with it? // not going to change this because I don't know the ramifications. createFolder(deltaPath, outputFolder, true); IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren(); for (int j = 0, m = removedChildren.length; j < m; j++) { copyResources(javaProject, removedChildren[j], srcEntry, segmentCount); } folderToRefresh.refreshLocal(IResource.DEPTH_ZERO, null); return; } } } IFolder removedPackageFolder = outputFolder.getFolder(deltaPath); if (removedPackageFolder.exists()) { removedPackageFolder.delete(IResource.FORCE, null); } break; } // switch(sourceDelta.getKind()) folderToRefresh.refreshLocal(IResource.DEPTH_ZERO, null); break; case IResource.FILE: // only do something if the output folder is different to the src folder if (!outputFolder.equals(srcContainer)) { // copy all resource deltas to the output folder if (deltaPath == null) return; // don't want to copy over .aj or .java files if (deltaPath.getFileExtension() != null && (deltaPath.getFileExtension().equals("aj") //$NON-NLS-1$ || deltaPath.getFileExtension().equals("java"))) { //$NON-NLS-1$ break; } IResource fileToRefresh = outputFolder.getFile(deltaPath); switch (sourceDelta.getKind()) { case IResourceDelta.ADDED: if (fileToRefresh.exists()) { AJLog.log(AJLog.BUILDER, "Deleting existing file " + deltaPath);//$NON-NLS-1$ fileToRefresh.delete(IResource.FORCE, null); } AJLog.log(AJLog.BUILDER, "Copying added file " + deltaPath);//$NON-NLS-1$ createFolder(deltaPath.removeLastSegments(1), outputFolder, true); resource.copy(fileToRefresh.getFullPath(), IResource.FORCE | IResource.DERIVED, null); Util.setReadOnly(fileToRefresh, false); // just in case the original was read only fileToRefresh.refreshLocal(IResource.DEPTH_ZERO, null); // mark this change so compiler knows about it. CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject()) .configurationChanged(CompilerConfigurationChangeFlags.PROJECTSOURCERESOURCES_CHANGED); break; case IResourceDelta.REMOVED: if (fileToRefresh.exists()) { AJLog.log(AJLog.BUILDER, "Deleting removed file " + deltaPath);//$NON-NLS-1$ fileToRefresh.delete(IResource.FORCE, null); } // mark this change so compiler knows about it. CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject()) .configurationChanged(CompilerConfigurationChangeFlags.PROJECTSOURCERESOURCES_CHANGED); break; case IResourceDelta.CHANGED: if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0 && (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) { return; // skip it since it really isn't changed } if (fileToRefresh.exists()) { AJLog.log(AJLog.BUILDER, "Deleting existing file " + deltaPath);//$NON-NLS-1$ fileToRefresh.delete(IResource.FORCE, null); } AJLog.log(AJLog.BUILDER, "Copying changed file " + deltaPath);//$NON-NLS-1$ createFolder(deltaPath.removeLastSegments(1), outputFolder, true); resource.copy(fileToRefresh.getFullPath(), IResource.FORCE | IResource.DERIVED, null); Util.setReadOnly(fileToRefresh, false); // just in case the original was read only break; } fileToRefresh.refreshLocal(IResource.DEPTH_ZERO, null); } // switch (sourceDelta.getKind()) break; } // switch(resource.getType()) }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
/** * This method is taken/*from www .j a v a 2 s . c om*/ * from org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.isExcludedFromProject(IPath) */ private boolean isExcludedFromProject(IJavaProject javaProject, IPath childPath, IClasspathEntry[] srcEntries) throws JavaModelException { // answer whether the folder should be ignored when walking the project as a source folder if (childPath.segmentCount() > 2) return false; // is a subfolder of a package for (int j = 0, k = srcEntries.length; j < k; j++) { IPath outputPath = srcEntries[j].getOutputLocation(); if (outputPath == null) { outputPath = javaProject.getOutputLocation(); } outputPath = outputPath.removeFirstSegments(1).makeRelative(); if (childPath.equals(getContainerForGivenPath(outputPath, javaProject.getProject()).getFullPath())) return true; IPath srcPath = srcEntries[j].getPath().removeFirstSegments(1); if (childPath.equals(getContainerForGivenPath(srcPath, javaProject.getProject()).getFullPath())) return true; } // skip default output folder which may not be used by any source folder return childPath.equals(javaProject.getOutputLocation()); }
From source file:org.eclipse.ajdt.core.CoreUtils.java
License:Open Source License
/** * Get the output locations for the project * /* www .j a va 2 s. co m*/ * @param project * @return list of IPath objects */ public static List<IPath> getOutputLocationPaths(IProject project) { List<IPath> outputLocations = new ArrayList<IPath>(); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) return outputLocations; try { // Have been unable to create a user scenario where the following // for // loop adds something to outputLocations, therefore always // fall through to the following if loop. However, if a project has // more than one output folder, then this for loop should pick them // up. // Needs testing....... IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; int contentKind = entry.getContentKind(); if (contentKind == ClasspathEntry.K_OUTPUT) { if (entry.getOutputLocation() != null) { outputLocations.add(entry.getOutputLocation()); } } } // If we haven't added anything from reading the .classpath // file, then use the default output location if (outputLocations.size() == 0) { outputLocations.add(javaProject.getOutputLocation()); } } catch (JavaModelException e) { } return outputLocations; }
From source file:org.eclipse.ajdt.core.CoreUtils.java
License:Open Source License
public static IPath[] getOutputFolders(IJavaProject project) throws CoreException { List<IPath> paths = new ArrayList<IPath>(); paths.add(project.getOutputLocation()); IClasspathEntry[] cpe = project.getRawClasspath(); for (int i = 0; i < cpe.length; i++) { if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = cpe[i].getOutputLocation(); if (output != null) { paths.add(output);/*from w w w .ja v a 2s.co m*/ } } } return (IPath[]) paths.toArray(new IPath[paths.size()]); }
From source file:org.eclipse.ajdt.core.tests.builder.AJBuilderTest.java
License:Open Source License
private boolean outputDirContainsFile(IProject project, String packageName, String fileName) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IPath workspaceRelativeOutputPath = javaProject.getOutputLocation(); String realOutputLocation = null; if (workspaceRelativeOutputPath.segmentCount() == 1) { // project // root/* w ww .j a v a2s . c o m*/ realOutputLocation = javaProject.getResource().getLocation().toOSString(); } else { IFolder out = ResourcesPlugin.getWorkspace().getRoot().getFolder(workspaceRelativeOutputPath); realOutputLocation = out.getLocation().toOSString(); } File outputDir = new File(realOutputLocation + File.separator + packageName); if (outputDir.exists()) { File[] outputFiles = outputDir.listFiles(); for (int i = 0; i < outputFiles.length; i++) { if (outputFiles[i].getName().equals(fileName)) { return true; } } } return false; }
From source file:org.eclipse.ajdt.core.tests.builder.AJBuilderTest2.java
License:Open Source License
/** * Part of Bug 91420 - if the output folder has changed then need to do a * build/*from w w w . ja v a 2 s. co m*/ */ public void testChangeInOutputDirCausesReBuild() throws Exception { IProject project = createPredefinedProject("bug91420"); //$NON-NLS-1$ IJavaProject javaProject = JavaCore.create(project); IPath origOutput = javaProject.getOutputLocation(); IPath newOutput = new Path("/bug91420/newBin"); //$NON-NLS-1$ assertFalse("should be setting output dir to new place", //$NON-NLS-1$ origOutput.toString().equals(newOutput.toString())); TestLogger testLog = new TestLogger(); AspectJPlugin.getDefault().setAJLogger(testLog); javaProject.setOutputLocation(newOutput, null); joinBackgroudActivities(); assertNotSame("should have set output directory to new place", origOutput, newOutput); //$NON-NLS-1$ List log = testLog.getMostRecentEntries(3); // print log to the screen for test case development purposes testLog.printLog(); assertTrue("output dir has changed so should have spent time in AJDE", //$NON-NLS-1$ testLog.containsMessage("Total time spent in AJDE")); //$NON-NLS-1$ assertTrue("output dir has changed so should have spent time in AJBuilder.build()", //$NON-NLS-1$ testLog.containsMessage("Total time spent in AJBuilder.build()")); //$NON-NLS-1$ // reset the output dir back to its original setting javaProject.setOutputLocation(origOutput, null); waitForAutoBuild(); assertEquals("should have reset the output directory", origOutput.toString(), //$NON-NLS-1$ javaProject.getOutputLocation().toString()); }
From source file:org.eclipse.ajdt.core.tests.builder.AJBuilderTest2.java
License:Open Source License
private boolean outputDirContainsFile(IProject project, String packageName, String fileName) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IPath workspaceRelativeOutputPath = javaProject.getOutputLocation(); String realOutputLocation = null; if (workspaceRelativeOutputPath.segmentCount() == 1) { // project // root//from ww w. j a va2 s . com realOutputLocation = javaProject.getResource().getLocation().toOSString(); } else { IFolder out = ResourcesPlugin.getWorkspace().getRoot().getFolder(workspaceRelativeOutputPath); realOutputLocation = out.getLocation().toOSString(); } File outputDir = new File(realOutputLocation + File.separator + packageName); File[] outputFiles = outputDir.listFiles(); for (int i = 0; i < outputFiles.length; i++) { if (outputFiles[i].getName().equals(fileName)) { return true; } } return false; }