List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.eclipse.libra.framework.equinox.EquinoxHandler.java
License:Open Source License
private String[] prepareDevProperties(IPath configPath, String[] wsBundleIds) { try {// w ww . j a va 2 s .co m // Create file FileWriter fstream = new FileWriter(configPath.toPortableString() + "/dev.properties"); BufferedWriter out = new BufferedWriter(fstream); out.write("#OSAMI AUTO GENERATED\n"); for (String bundle : wsBundleIds) { if (bundle.indexOf("@") != -1) bundle = bundle.substring(0, bundle.indexOf("@")); IPluginModelBase[] models = PluginRegistry.getWorkspaceModels(); String modelId = ""; for (IPluginModelBase iPluginModelBase : models) { if (bundle.indexOf(iPluginModelBase.getPluginBase().getId()) > -1) { IProject pluginProject = iPluginModelBase.getUnderlyingResource().getProject(); IJavaProject javaProject = JavaCore.create(pluginProject); IBundleProjectDescription bundleProjectDescription = FrameworkCorePlugin .getDescription(pluginProject); IBundleClasspathEntry[] allCPEntry = bundleProjectDescription.getBundleClasspath(); modelId = iPluginModelBase.getPluginBase().getId(); out.write("\n" + modelId + "="); for (IBundleClasspathEntry bcpe : allCPEntry) { if (bcpe.getSourcePath() != null && bcpe.getBinaryPath() == null) out.write(" " + javaProject.getOutputLocation() .makeRelativeTo(pluginProject.getFullPath()) + ","); else if (bcpe.getSourcePath() != null && bcpe.getBinaryPath() != null) out.write(" " + bcpe.getBinaryPath().toOSString() + ","); else if (bcpe.getLibrary() != null && bcpe.getLibrary().toOSString().endsWith(".jar")) out.write(" " + bcpe.getLibrary().toOSString() + ","); else out.write(" " + javaProject.getOutputLocation() .makeRelativeTo(pluginProject.getFullPath()) + ","); } } } } out.close(); } catch (Exception e) { Trace.trace(Trace.SEVERE, "Could not create equinox dev.properties configuration file:" + e.getMessage(), e); } return wsBundleIds; }
From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java
License:Open Source License
public void testProjectImport001_useMavenOutputFolders() throws Exception { deleteProject("projectimport-p001"); ResolverConfiguration configuration = new ResolverConfiguration(); IProject project = importProject("projectimport-p001", "projects/projectimport/p001", configuration); waitForJobsToComplete();//from www. ja v a 2 s.c om IJavaProject javaProject = JavaCore.create(project); assertEquals(new Path("/projectimport-p001/target/classes"), javaProject.getOutputLocation()); IClasspathEntry[] cp = javaProject.getRawClasspath(); assertEquals(4, cp.length); assertEquals(new Path("/projectimport-p001/src/main/java"), cp[0].getPath()); assertEquals(new Path("/projectimport-p001/target/classes"), cp[0].getOutputLocation()); assertEquals(new Path("/projectimport-p001/src/test/java"), cp[1].getPath()); assertEquals(new Path("/projectimport-p001/target/test-classes"), cp[1].getOutputLocation()); }
From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java
License:Open Source License
public void _testProjectImport002_useMavenOutputFolders() throws Exception { deleteProject("projectimport-p002"); ResolverConfiguration configuration = new ResolverConfiguration(); IProject project = importProject("projectimport-p002", "projects/projectimport/p002", configuration); waitForJobsToComplete();/*w ww . ja v a2 s . co m*/ IJavaProject javaProject = JavaCore.create(project); assertEquals(new Path("/projectimport-p002/target/classes"), javaProject.getOutputLocation()); IClasspathEntry[] cp = javaProject.getRawClasspath(); assertEquals(3, cp.length); assertEquals(new Path("/projectimport-p002/p002-m1/src/main/java"), cp[0].getPath()); assertEquals(new Path("/projectimport-p002/p002-m1/target/classes"), cp[0].getOutputLocation()); }
From source file:org.eclipse.objectteams.otdt.test.builder.IncrementalTests.java
License:Open Source License
public void testModifyTSuperRole2() throws Exception { System.out.println("***** testModifyTSuperRole2() *****"); IPath projectPath = env.addProject("Project", "1.5"); env.addExternalJars(projectPath, Util.getJavaClassLibs()); env.addExternalJar(projectPath, getOTREPath(this.weavingScheme)); // remove old package fragment root so that names don't collide env.removePackageFragmentRoot(projectPath, ""); IPath root = env.addPackageFragmentRoot(projectPath, "src"); env.setOutputFolder(projectPath, "bin"); env.addClass(root, "p", "AA", "package p; \n" + "public team class AA { \n" + " protected class R {\n" + " String bar() { return \"NOK\"; }\n" + "}}"); env.addClass(root, "p", "AB", "package p; \n" + "public team class AB extends AA {\n" + " protected class R {\n" + " protected String foo() { return this.bar(); }\n" + " }\n" + " public static String test() {\n" + " return new AB().new R().foo();\n" + " }\n" + "}"); fullBuild(projectPath);/*ww w .j a va2 s. c o m*/ expectingNoProblems(); /* Change method R.bar() */ env.addClass(root, "p", "AA", "package p; \n" + "public team class AA {\n" + " protected class R {\n" + " String bar() { return \"OK\"; }\n" + "}}"); /* build must achieve that AB - although unchanged - behaves differently. */ incrementalBuild(projectPath); expectingNoProblems(); IJavaProject project = JavaCore.create(env.getProject("Project")); try (OTLaunchEnvironment launcher = new OTLaunchEnvironment(env.getWorkspaceRootPath(), project.getOutputLocation())) { Object result = launcher.launch("p.AB", "test"); assertEquals("OK", result); } // cleanup: System.gc(); }
From source file:org.eclipse.objectteams.otdt.test.builder.IncrementalTests.java
License:Open Source License
public void testModifyTSuperRole3() throws Exception { System.out.println("***** testModifyTSuperRole3() *****"); IPath projectPath = env.addProject("Project", "1.5"); env.addExternalJars(projectPath, Util.getJavaClassLibs()); env.addExternalJar(projectPath, getOTREPath(this.weavingScheme)); // remove old package fragment root so that names don't collide env.removePackageFragmentRoot(projectPath, ""); IPath root = env.addPackageFragmentRoot(projectPath, "src"); env.setOutputFolder(projectPath, "bin"); env.addClass(root, "p", "AA", "package p; \n" + "public team class AA { \n" + " protected class R {\n" + " String bar() { \n" + " return \"NOK\";\n" + " }\n" + "}}"); env.addClass(root, "p", "AB", "package p; \n" + "public team class AB extends AA {}"); env.addClass(root, "p", "AC", "package p; \n" + "public team class AC extends AB {\n" + " protected class R {\n" + " protected String foo() { return this.bar(); }\n" + " }\n" + " public static String test() {\n" + " return new AC().new R().foo();\n" + " }\n" + "}"); fullBuild(projectPath);//from w ww.j av a 2 s .c o m expectingNoProblems(); /* Change method R.bar() */ env.addClass(root, "p", "AA", "package p; \n" + "public team class AA {\n" + " protected class R {\n" + " String bar() { return \"OK\"; }\n" + "}}"); /* build must achieve that AB - although unchanged - behaves differently. */ incrementalBuild(projectPath); expectingNoProblems(); IJavaProject project = JavaCore.create(env.getProject("Project")); try (OTLaunchEnvironment launcher = new OTLaunchEnvironment(env.getWorkspaceRootPath(), project.getOutputLocation())) { Object result = launcher.launch("p.AC", "test"); assertEquals("OK", result); } // cleanup: System.gc(); }
From source file:org.eclipse.objectteams.otdt.test.builder.IncrementalTests.java
License:Open Source License
public void testModifyTeam1() throws Exception { System.out.println("***** testModifyTeam1() *****"); IPath projectPath = env.addProject("Project", "1.5"); env.addExternalJars(projectPath, Util.getJavaClassLibs()); env.addExternalJar(projectPath, getOTREPath(this.weavingScheme)); // remove old package fragment root so that names don't collide env.removePackageFragmentRoot(projectPath, ""); IPath root = env.addPackageFragmentRoot(projectPath, "src"); env.setOutputFolder(projectPath, "bin"); env.addClass(root, "p", "B", "package p; \n" + "public class B { \n" + " String bar() { return \"NOK\"; }\n" + "}"); env.addClass(root, "p", "AA", "package p; \n" + "public team class AA { \n" + " public static String test() {\n" + " new AA();\n" + " return new B().bar();\n" + " }\n" + "}"); env.addClass(root, "p.AA", "R", "team package p.AA; \n" + "protected class R playedBy B {\n" + " @SuppressWarnings(\"basecall\")\n" + " callin String foo() { return \"OK\"; }\n" + " foo <- replace bar;\n" + "}"); fullBuild(projectPath);// www . j a v a 2 s.c o m expectingNoProblems(); /* add constructor */ env.addClass(root, "p", "AA", "package p; \n" + "public team class AA { \n" + " public AA() { this.activate(); }\n" + " public static String test() {\n" + " new AA();\n" + " return new B().bar();\n" + " }\n" + "}"); /* build must achieve that R - although unchanged - is compiled into AA. */ incrementalBuild(projectPath); expectingNoProblems(); IJavaProject project = JavaCore.create(env.getProject("Project")); try (OTLaunchEnvironment launcher = new OTLaunchEnvironment(env.getWorkspaceRootPath(), project.getOutputLocation(), true /* useTransformer */)) { Object result = launcher.launch("p.AA", "test"); assertEquals("OK", result); } // cleanup: System.gc(); }
From source file:org.eclipse.osee.ote.runtimemanager.UserLibResourceFinder.java
License:Open Source License
@Override public byte[] find(String path) throws IOException { try {// w ww . j av a2 s .c o m for (OteUserLibsNature userLibsNature : OteUserLibsNature.getWorkspaceProjects()) { IProject project = userLibsNature.getProject(); IProjectDescription description; try { description = project.getDescription(); if (description.hasNature("org.eclipse.jdt.core.javanature")) { IJavaProject javaProject = JavaCore.create(project); // Projects don't have to be stored in the workspace, so make sure to use the project.getLocation as the starting point IPath candidate = project.getLocation().removeLastSegments(1) .append(javaProject.getOutputLocation().makeAbsolute()).append(path); if (candidate.toFile().exists()) { File file = candidate.toFile(); try { return getBytes(new FileInputStream(file), file.length()); } catch (FileNotFoundException e) { } } } } catch (CoreException ex) { ex.printStackTrace(); } } } catch (CoreException ex) { } return null; }
From source file:org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder.java
License:Open Source License
/** * Returns the complete listing of required projects from the classpath of * the backing project//from w w w. j a v a 2 s .c o m * * @param includeBinaryPrerequisites * @return the list of projects required * @throws CoreException */ IProject[] getRequiredProjects(boolean includebinaries) throws CoreException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); if (this.currentproject == null || workspaceRoot == null) { return new IProject[0]; } ArrayList<IProject> projects = new ArrayList<IProject>(); try { IJavaProject javaProject = JavaCore.create(this.currentproject); HashSet<IPath> blocations = new HashSet<IPath>(); blocations.add(javaProject.getOutputLocation()); this.output_locs.put(this.currentproject, blocations); HashSet<IPath> slocations = new HashSet<IPath>(); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].isArchive()) { continue; } slocations.add(roots[i].getPath()); } this.src_locs.put(this.currentproject, slocations); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0, l = entries.length; i < l; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); IProject p = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: { p = workspaceRoot.getProject(path.lastSegment()); // missing // projects // are // considered // too if (isOptional(entry) && !p.hasNature(ApiPlugin.NATURE_ID)) {// except // if // entry // is // optional p = null; } break; } case IClasspathEntry.CPE_LIBRARY: { if (includebinaries && path.segmentCount() > 1) { // some binary resources on the class path can come // from projects that are not included in the // project references IResource resource = workspaceRoot.findMember(path.segment(0)); if (resource instanceof IProject) { p = (IProject) resource; } } break; } case IClasspathEntry.CPE_SOURCE: { IPath entrypath = entry.getOutputLocation(); if (entrypath != null) { blocations.add(entrypath); } break; } default: { break; } } if (p != null && !projects.contains(p)) { projects.add(p); // try to derive all of the output locations for each of the // projects javaProject = JavaCore.create(p); HashSet<IPath> bins = new HashSet<IPath>(); HashSet<IPath> srcs = new HashSet<IPath>(); if (javaProject.exists()) { bins.add(javaProject.getOutputLocation()); IClasspathEntry[] source = javaProject.getRawClasspath(); IPath entrypath = null; for (int j = 0; j < source.length; j++) { if (source[j].getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcs.add(source[j].getPath()); entrypath = source[j].getOutputLocation(); if (entrypath != null) { bins.add(entrypath); } } } this.output_locs.put(p, bins); this.src_locs.put(p, srcs); } } } } catch (JavaModelException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that changing the output folder settings for a project cause the * class file containers to be updated//from w ww . j a va 2s .c o m */ public void testWPUpdateDefaultOutputFolderChanged() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IContainer container = ProjectUtils.addFolderToProject(project.getProject(), "bin2"); //$NON-NLS-1$ assertNotNull("the new output folder cannot be null", container); //$NON-NLS-1$ IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertNotNull("the workspace component must exist", component); //$NON-NLS-1$ int before = component.getApiTypeContainers().length; project.setOutputLocation(container.getFullPath(), new NullProgressMonitor()); waitForAutoBuild(); assertTrue("there must be the same number of containers after the change", //$NON-NLS-1$ before == component.getApiTypeContainers().length); assertTrue("the new output location should be 'bin2'", //$NON-NLS-1$ "bin2".equalsIgnoreCase(project.getOutputLocation().toFile().getName())); //$NON-NLS-1$ }
From source file:org.eclipse.pde.internal.core.builders.SourceEntryErrorReporter.java
License:Open Source License
public void initialize(ArrayList<?> sourceEntries, ArrayList<?> outputEntries, IClasspathEntry[] cpes, IProject project) {//from w ww . j av a 2 s.c o m fProject = project; IPath defaultOutputLocation = null; IJavaProject javaProject = JavaCore.create(fProject); try { defaultOutputLocation = javaProject.getOutputLocation(); } catch (JavaModelException e) { } List<String> pluginLibraryNames = new ArrayList<String>(1); IPluginModelBase pluginModel = PluginRegistry.findModel(fProject); if (pluginModel != null) { IPluginLibrary[] pluginLibraries = pluginModel.getPluginBase().getLibraries(); for (int i = 0; i < pluginLibraries.length; i++) { pluginLibraryNames.add(pluginLibraries[i].getName()); } } if (!pluginLibraryNames.contains(".")) { //$NON-NLS-1$ pluginLibraryNames.add("."); //$NON-NLS-1$) } for (int i = 0; i < cpes.length; i++) { if (cpes[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = getPath(cpes[i]); if (sourcePath == null) continue; IPath outputLocation = cpes[i].getOutputLocation(); if (outputLocation == null) outputLocation = defaultOutputLocation; IPath outputPath = getPath(outputLocation); OutputFolder outputFolder = fOutputFolderMap.get(outputPath); if (outputFolder == null) { outputFolder = new OutputFolder(outputPath); } SourceFolder sourceFolder = fSourceFolderMap.get(sourcePath); if (sourceFolder == null) { sourceFolder = new SourceFolder(sourcePath, outputFolder); } outputFolder.addSourceFolder(sourceFolder); fOutputFolderMap.put(outputPath, outputFolder); fSourceFolderMap.put(sourcePath, sourceFolder); } else if (cpes[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry entry = cpes[i]; IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); IPath outputPath = null; if (roots.length == 1) { // should only be one entry for a library if (!roots[0].isArchive()) { outputPath = getPath(entry); OutputFolder outputFolder = new OutputFolder(outputPath, true); fOutputFolderMap.put(outputPath, outputFolder); } } } } for (Iterator<?> iterator = sourceEntries.iterator(); iterator.hasNext();) { IBuildEntry sourceEntry = (IBuildEntry) iterator.next(); String libName = sourceEntry.getName().substring(PROPERTY_SOURCE_PREFIX.length()); if (!pluginLibraryNames.contains(libName)) { prepareError(sourceEntry.getName(), null, NLS.bind(PDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName), PDEMarkerFactory.B_REMOVAL, fSrcLibSeverity, PDEMarkerFactory.CAT_OTHER); } String[] tokens = sourceEntry.getTokens(); for (int i = 0; i < tokens.length; i++) { IPath path = new Path(tokens[i]).addTrailingSeparator(); SourceFolder sourceFolder = fSourceFolderMap.get(path); if (sourceFolder == null) { sourceFolder = new SourceFolder(path, null); fSourceFolderMap.put(path, sourceFolder); } sourceFolder.setToken(tokens[i]); sourceFolder.addLib(libName); } } for (Iterator<?> iterator = outputEntries.iterator(); iterator.hasNext();) { IBuildEntry outputEntry = (IBuildEntry) iterator.next(); String libName = outputEntry.getName().substring(PROPERTY_OUTPUT_PREFIX.length()); if (!pluginLibraryNames.contains(libName)) { prepareError(outputEntry.getName(), null, NLS.bind(PDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName), PDEMarkerFactory.B_REMOVAL, fOututLibSeverity, PDEMarkerFactory.CAT_OTHER); } String[] tokens = outputEntry.getTokens(); for (int i = 0; i < tokens.length; i++) { IPath path = new Path(tokens[i]).addTrailingSeparator(); if (path.segmentCount() == 1 && path.segment(0).equals(".")) { //$NON-NLS-1$ // translate "." to root path path = Path.ROOT; } OutputFolder outputFolder = fOutputFolderMap.get(path); if (outputFolder == null) { outputFolder = new OutputFolder(path); fOutputFolderMap.put(path, outputFolder); } outputFolder.setToken(tokens[i]); outputFolder.addLib(libName); } } }