public void testEditOutputFolderBug154044() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPackageFragmentRoot src1 = JavaProjectHelper.addSourceContainer(fJavaProject, "src1"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath oldOutputPath = projectPath.append("src1").append("sub").append(DEFAULT_OUTPUT_FOLDER_NAME); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject)); ClasspathModifier.setOutputLocation(element, oldOutputPath, false, cpProject); ClasspathModifier.commitClassPath(cpProject, null); IPath outputPath = projectPath.append("src1").append("sub").append("newBin"); cpProject = CPJavaProject.createFromExisting(fJavaProject); element = cpProject.getCPElement( CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.isOK()); BuildpathDelta delta = ClasspathModifier.setOutputLocation(element, outputPath, false, cpProject); assertDeltaResources( delta, new IPath[] {outputPath}, new IPath[] {oldOutputPath}, new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder( delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME)); assertDeltaRemovedEntries(delta, new IPath[0]); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); IClasspathEntry entry = classpathEntries[1]; assertTrue(src1.getRawClasspathEntry() == entry); IPath location = entry.getOutputLocation(); assertTrue( "Output path is " + location + " expected was " + outputPath, outputPath.equals(location)); IPath[] exclusionPatterns = entry.getExclusionPatterns(); assertTrue(exclusionPatterns.length == 1); assertTrue( exclusionPatterns[0].toString(), exclusionPatterns[0].toString().equals("sub/newBin/")); }
public void testEditOutputFolder01SetOutputFolderForSourceFolder() throws Exception { fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME); IPackageFragmentRoot src = JavaProjectHelper.addSourceContainer(fJavaProject, "src"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath outputPath = projectPath.append("srcbin"); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.getSeverity() != IStatus.ERROR); BuildpathDelta delta = ClasspathModifier.setOutputLocation(element, outputPath, false, cpProject); assertDeltaResources(delta, new IPath[] {outputPath}, new IPath[0], new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder(delta, fJavaProject.getOutputLocation()); assertDeltaAddedEntries(delta, new IPath[0]); assertDeltaRemovedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 2); IClasspathEntry entry = classpathEntries[1]; assertTrue(src.getRawClasspathEntry() == entry); IPath location = entry.getOutputLocation(); assertTrue( "Output path is " + location + " expected was " + outputPath, outputPath.equals(location)); }
public void testEditOutputFolder04RemoveProjectAndExcludeOutput() throws Exception { fJavaProject = createProject(null); // Use the old behavior in order to test the fallback code. Set to ERROR since 3.8. fJavaProject.setOption( JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.IGNORE); JavaProjectHelper.addSourceContainer( fJavaProject, null, new IPath[] {new Path("src1/"), new Path("src2/")}); IPackageFragmentRoot src1 = JavaProjectHelper.addSourceContainer(fJavaProject, "src1"); IPackageFragmentRoot src2 = JavaProjectHelper.addSourceContainer(fJavaProject, "src2"); IPath projectPath = fJavaProject.getProject().getFullPath(); IPath outputPath = projectPath.append("src2").append(DEFAULT_OUTPUT_FOLDER_NAME); CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject); CPListElement element = cpProject.getCPElement( CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject)); IStatus status = ClasspathModifier.checkSetOutputLocationPrecondition(element, outputPath, false, cpProject); assertTrue(status.getMessage(), status.getSeverity() == IStatus.INFO); BuildpathDelta delta = ClasspathModifier.setOutputLocation(element, outputPath, false, cpProject); assertDeltaResources(delta, new IPath[] {outputPath}, new IPath[0], new IPath[0], new IPath[0]); assertDeltaDefaultOutputFolder( delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME)); assertDeltaRemovedEntries(delta, new IPath[] {fJavaProject.getPath()}); assertDeltaAddedEntries(delta, new IPath[0]); ClasspathModifier.commitClassPath(cpProject, null); assertTrue( "Default output folder was not set to bin", fJavaProject .getOutputLocation() .equals(fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME))); IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath(); assertNumberOfEntries(classpathEntries, 3); IClasspathEntry entry = classpathEntries[1]; assertTrue(src1.getRawClasspathEntry() == entry); IPath location = entry.getOutputLocation(); assertTrue( "Output path is " + location + " expected was " + outputPath, outputPath.equals(location)); entry = classpathEntries[2]; assertTrue(src2.getRawClasspathEntry() == entry); IPath[] exclusionPatterns = entry.getExclusionPatterns(); assertTrue(exclusionPatterns.length == 1); assertTrue(exclusionPatterns[0].toString().equals("bin/")); }