List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
private void addJavaProject(IJavaProject project) throws CoreException { if (project != null) { final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>(); for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) { if (fragment.getKind() == IPackageFragmentRoot.K_BINARY && fragment.getSourceAttachmentPath() != null) { File classpathLocation; if (fragment.isExternal()) { classpathLocation = fragment.getPath().toFile(); } else { classpathLocation = toFile(fragment.getPath()); }// www. j a v a 2s . c o m if (classpathLocation != null) { classpath.put(classpathLocation, fragment); } } } final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath); final Set<File> projectLocations = new HashSet<File>(); final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR); if (jarLocation != null) { // maven binary project projectLocations.add(new File(jarLocation)); } else { // regular project projectLocations.add(toFile(project.getOutputLocation())); for (IClasspathEntry cpe : project.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { projectLocations.add(toFile(cpe.getOutputLocation())); } } } synchronized (lock) { projects.put(project, projectLocations); for (File projectLocation : projectLocations) { locations.put(projectLocation, projectInfo); } } } }
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
static ISourceContainer getProjectSourceContainer(IJavaProject javaProject) { List<ISourceContainer> containers = new ArrayList<ISourceContainer>(); boolean hasSources = false; try {/*w w w . j av a2 s . c om*/ for (IClasspathEntry cpe : javaProject.getRawClasspath()) { switch (cpe.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: hasSources = true; break; case IClasspathEntry.CPE_LIBRARY: IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource lib = workspaceRoot.findMember(cpe.getPath()); IPackageFragmentRoot fragmentRoot; if (lib != null) { fragmentRoot = javaProject.getPackageFragmentRoot(lib); } else { fragmentRoot = javaProject.getPackageFragmentRoot(cpe.getPath().toOSString()); } containers.add(new PackageFragmentRootSourceContainer(fragmentRoot)); break; } } } catch (JavaModelException e) { // ignore... maybe log } if (hasSources) { containers.add(0, new JavaProjectSourceContainer(javaProject)); } if (containers.isEmpty()) { return null; } if (containers.size() == 1) { return containers.get(0); } return new CompositeSourceContainer(containers); }
From source file:com.iw.plugins.spindle.ant.AntScriptGenerator.java
License:Mozilla Public License
/** * We need to collect and filter the list of classpath roots, src and binary. * We need to separate jars containing javax.servet.* classes and ignore the * JRE classpath container setting altogether. * //from ww w. j av a 2 s . c o m * @param monitor a progress monitor */ private void resolveProjectClasspath(IProgressMonitor monitor) { ArrayList resolvedEntries = new ArrayList(); IJavaProject jproject = null; try { jproject = fTapestryProject.getJavaProject(); IClasspathEntry[] entries = jproject.getRawClasspath(); // we need to ignore JRE entires and collect all of the other entries! // don't separate src from binary roots at this time. for (int i = 0; i < entries.length; i++) { switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedEntry = null; try { resolvedEntry = JavaCore.getResolvedClasspathEntry(entries[i]); } catch (org.eclipse.jdt.internal.core.Assert.AssertionFailedException e) { UIPlugin.log(e); } if (resolvedEntry != null) resolvedEntries.add(resolvedEntry); break; case IClasspathEntry.CPE_CONTAINER: //We don't care about the JRE! if ("".equals(entries[i].getPath())) break; IClasspathContainer container = JavaCore.getClasspathContainer(entries[i].getPath(), jproject); if (container == null) break; IClasspathEntry[] containerEntries = container.getClasspathEntries(); if (containerEntries == null) break; // container was bound for (int j = 0, containerLength = containerEntries.length; j < containerLength; j++) { IClasspathEntry cEntry = containerEntries[j]; // if (generateMarkerOnError) // { // IJavaModelStatus containerStatus = // ClasspathEntry.validateClasspathEntry( // jproject, // cEntry, // false, // true /* recurse */); // if (!containerStatus.isOK()) // createClasspathProblemMarker(containerStatus); // } // if container is exported, then its nested entries must in turn // be exported (21749) resolvedEntries.add(cEntry); } break; default: resolvedEntries.add(entries[i]); } } } catch (CoreException e) { UIPlugin.log(e); } if (jproject == null) return; }
From source file:com.iw.plugins.spindle.ui.properties.ProjectPropertyPage.java
License:Mozilla Public License
private void doOk(IProgressMonitor monitor) throws CoreException { // store the values as properties IResource resource = (IResource) getElement(); // resource.setPersistentProperty( // new QualifiedName("", PROJECT_TYPE_PROPERTY), // new Integer(TapestryProject.APPLICATION_PROJECT_TYPE).toString()); resource.setPersistentProperty(new QualifiedName("", CONTEXT_ROOT_PROPERTY), fWebContextRoot.getText()); resource.setPersistentProperty(new QualifiedName("", VALIDATE_WEBXML_PROPERTY), Boolean.toString(fValidateWebXML.getSelection())); final IProject workspaceProject = (IProject) (this.getElement().getAdapter(IProject.class)); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { if (fIsTapestryProjectCheck.getSelection()) { String projectName = workspaceProject.getProject().getName(); String temp = fWebContextRoot.getText(); createFolderIfRequired(projectName + temp); fNewProjectMetadata.setWebContext(temp); fNewProjectMetadata.setValidateWebXML(fValidateWebXML.getSelection()); fNewProjectMetadata.saveProperties(monitor); IJavaProject jproject = getJavaProject(); TapestryProject prj = getTapestryProject(); if (prj == null) { TapestryProject.addTapestryNature(jproject, true); } else { prj.clearMetadata(); }//from w w w. java 2 s . co m try { if (jproject .findType(TapestryCore.getString("TapestryComponentSpec.specInterface")) == null) { MessageDialog dialog = new MessageDialog(getShell(), "Tapestry jars missing", null, "Add the Tapestry jars to the classpath?", MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); // OK is the default int result = dialog.open(); if (result == 0) { List entries = Arrays.asList(jproject.getRawClasspath()); ArrayList useEntries = new ArrayList(entries); useEntries.add(JavaCore.newContainerEntry(new Path(TapestryCore.CORE_CONTAINER))); jproject.setRawClasspath( (IClasspathEntry[]) useEntries.toArray(new IClasspathEntry[entries.size()]), monitor); } } } catch (JavaModelException e) { UIPlugin.log(e); } } else { TapestryProject.removeTapestryNature(getJavaProject()); } if (fIsTapestryProjectCheck.getSelection()) { IProject project = getJavaProject().getProject(); project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); } } }; UIPlugin.getWorkspace().run(runnable, monitor); }
From source file:com.iw.plugins.spindle.ui.widgets.TypeChooserWidget.java
License:Mozilla Public License
public void configure(final IJavaProject project, final IRunnableContext context) { try {// w w w. j a v a2 s .c o m final boolean baseIsInterface = fHierarchyRoot.isInterface(); fSearchResults = new ArrayList(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IJavaSearchScope scope = null; try { // we want to rip out the JRE entry as there's no chance of finding a tapestry class there. ArrayList roots = new ArrayList(); IClasspathEntry[] classpath = project.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath cpPath = classpath[i].getPath(); if (JavaRuntime.JRE_CONTAINER.equals(cpPath.segment(0))) continue; } roots.add(project.findPackageFragmentRoots(classpath[i])); } scope = SearchEngine.createJavaSearchScope( (IJavaElement[]) roots.toArray(new IJavaElement[roots.size()]), true); } catch (JavaModelException e1) { scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, true); } ISearchPattern pattern = SearchEngine.createSearchPattern("*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, true); SearchEngine engine = new SearchEngine(); IJavaSearchResultCollector collector = new IJavaSearchResultCollector() { public void aboutToStart() { } public void accept(IResource resource, int start, int end, IJavaElement enclosingElement, int accuracy) throws CoreException { if (accuracy != EXACT_MATCH) return; if (enclosingElement.getElementType() != IJavaElement.TYPE) return; IType type = (IType) enclosingElement; System.out.println(type.getFullyQualifiedName()); if (baseIsInterface) { if (!CoreUtils.implementsInterface(type, fHierarchyRoot.getElementName())) return; } else { if (!CoreUtils.extendsType(type, fHierarchyRoot)) return; } System.out.println(type.getFullyQualifiedName()); fSearchResults.add(type); } public void done() { } public IProgressMonitor getProgressMonitor() { return monitor; } }; try { engine.search(ResourcesPlugin.getWorkspace(), pattern, scope, collector); } catch (JavaModelException e) { UIPlugin.log(e); } } }; context.run(false, true, runnable); } catch (InvocationTargetException e) { UIPlugin.log(e); } catch (InterruptedException e) { //do nothing; } catch (JavaModelException e) { UIPlugin.log(e); } }
From source file:com.iw.plugins.spindle.wizards.project.NewProjectUtils.java
License:Mozilla Public License
private static void addToClasspath(String jarFileName, IJavaProject jproject, IProgressMonitor monitor) throws InterruptedException, CoreException { URL installUrl = TapestryPlugin.getDefault().getDescriptor().getInstallURL(); URL jarURL = null;/*from w ww .j av a 2 s .c o m*/ try { jarURL = new URL(installUrl, jarFileName); jarURL = Platform.resolve(jarURL); } catch (IOException e) { } if (jarURL == null) { return; } IClasspathEntry[] classpath = jproject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length + 1]; System.arraycopy(classpath, 0, newClasspath, 0, classpath.length); newClasspath[classpath.length] = new ClasspathEntry(IPackageFragmentRoot.K_BINARY, ClasspathEntry.CPE_LIBRARY, new Path(jarURL.getFile()), new Path[] {}, null, null, null, false); jproject.setRawClasspath(newClasspath, monitor); }
From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java
License:Open Source License
/** * Get all the resolved classpath entries for a specific project. The entries * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved * or included in the result. At also add the source and output folder provided with the * project// w w w .j a va 2 s .c o m * * @param project the project where the file to compile is contained, must be not null * @return a not null list of string that contains the classpath to include in the compilation project */ private List<String> getClasspaths(IProject project) { IJavaProject jprj = JavaCore.create(project); List<String> classpath = new ArrayList<String>(); IWorkspaceRoot wsRoot = project.getWorkspace().getRoot(); if (jprj != null) { try { IClasspathEntry[] entries = jprj.getRawClasspath(); //Add the default output folder if any IPath defaultLocationPath = jprj.getOutputLocation(); if (defaultLocationPath != null) { IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } for (IClasspathEntry en : entries) { if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String containerPath = en.getPath().toString(); //Don't add the eclipse runtime and the classpath extension defined in the exclusion list if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER) && !classpathExclusionSet.contains(containerPath)) { addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath, jprj); } } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) { classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator); } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) { //check if is a source folder and if it has a custom output folder to add them also to the classpath IPath entryOutputLocation = en.getOutputLocation(); if (entryOutputLocation != null) { IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } } else { //It is a jar check if it is internal to the workspace of external IPath location = wsRoot.getFile(en.getPath()).getLocation(); if (location == null) { //The location could not be resolved from the root of the workspace, it is external classpath.add(en.getPath().toOSString()); } else { //The location has been resolved from the root of the workspace, it is internal classpath.add(location.toOSString()); } } } } catch (Exception ex) { ex.printStackTrace(); } } return classpath; }
From source file:com.javadude.antxr.eclipse.core.AntxrNature.java
License:Open Source License
public void configure() throws CoreException { if (AntxrNature.DEBUG) { System.out.println("configuring ANTXR nature"); }//w ww .j a va 2s.c o m IProject project = getProject(); IProjectDescription projectDescription = project.getDescription(); List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(projectDescription.getBuildSpec())); ICommand antxrBuilderCommand = projectDescription.newCommand(); antxrBuilderCommand.setBuilderName(AntxrBuilder.BUILDER_ID); ICommand warningCleanerBuilderCommand = projectDescription.newCommand(); warningCleanerBuilderCommand.setBuilderName(WarningCleanerBuilder.BUILDER_ID); ICommand smapBuilderCommand = projectDescription.newCommand(); smapBuilderCommand.setBuilderName(SMapInstallerBuilder.BUILDER_ID); if (!commands.contains(antxrBuilderCommand)) { commands.add(0, antxrBuilderCommand); // add at start } if (!commands.contains(warningCleanerBuilderCommand)) { commands.add(warningCleanerBuilderCommand); // add at end } if (!commands.contains(smapBuilderCommand)) { commands.add(smapBuilderCommand); // add at end } // Commit the spec change into the project projectDescription.setBuildSpec(commands.toArray(new ICommand[commands.size()])); getProject().setDescription(projectDescription, null); // // add the antxr.jar file to a lib dir // IFolder folder = getProject().getFolder("lib"); // if (!folder.exists()) { // folder.create(true, true, null); // } // IPath rawLocation = folder.getRawLocation(); // URL antxrJarUrl = AntxrCorePlugin.getDefault().getBundle().getEntry("lib/antxr.jar"); // // BufferedOutputStream bout = null; // BufferedInputStream bin = null; // int b; // try { // try { // bout = new BufferedOutputStream(new FileOutputStream(new File(rawLocation.toFile(), "antxr.jar"))); // bin = new BufferedInputStream(antxrJarUrl.openStream()); // while ((b = bin.read()) != -1) { // bout.write(b); // } // } finally { // if (bout != null) { // bout.close(); // } // if (bin != null) { // bin.close(); // } // } // } catch (IOException e) { // e.printStackTrace(); // } // // folder.refreshLocal(IResource.DEPTH_ONE, null); // // // add the jar to the classpath if not present // String jarPath = "/" + getProject().getName() + "/lib/antxr.jar"; IFolder antxr3GeneratedFolder = getProject().getFolder("antxr-generated"); if (!antxr3GeneratedFolder.exists()) { antxr3GeneratedFolder.create(true, true, null); } String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated"; final IJavaProject javaProject = JavaCore.create(getProject()); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean generatedSourceDirFound = false; for (IClasspathEntry classpathEntry : rawClasspath) { // if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // if (classpathEntry.getPath().toString().equals(jarPath)) { // found = true; // } // } if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (classpathEntry.getPath().toString().equals(generatedSourcePath)) { generatedSourceDirFound = true; } } } int toAdd = 0; if (!generatedSourceDirFound) { toAdd++; } if (!generatedSourceDirFound) { final IClasspathEntry newEntries[] = new IClasspathEntry[rawClasspath.length + toAdd]; System.arraycopy(rawClasspath, 0, newEntries, 0, rawClasspath.length); // newEntries[rawClasspath.length] = JavaCore.newLibraryEntry(new Path(jarPath), Path.EMPTY, Path.ROOT); if (!generatedSourceDirFound) { newEntries[newEntries.length - 1] = JavaCore.newSourceEntry(new Path(generatedSourcePath)); } JavaCore.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { javaProject.setRawClasspath(newEntries, null); } }, null); } }
From source file:com.javadude.antxr.eclipse.core.AntxrNature.java
License:Open Source License
public void deconfigure() throws CoreException { if (AntxrNature.DEBUG) { System.out.println("deconfiguring ANTXR nature"); }//from w w w. java 2 s . c o m IProject project = getProject(); IProjectDescription desc = project.getDescription(); List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(desc.getBuildSpec())); for (Iterator i = commands.iterator(); i.hasNext();) { ICommand command = (ICommand) i.next(); if (command.getBuilderName().equals(AntxrBuilder.BUILDER_ID) || command.getBuilderName().equals(SMapInstallerBuilder.BUILDER_ID) || command.getBuilderName().equals(WarningCleanerBuilder.BUILDER_ID)) { i.remove(); } } // Commit the spec change into the project desc.setBuildSpec(commands.toArray(new ICommand[commands.size()])); project.setDescription(desc, null); // remove the jar from the classpath if present // delete the jar from the lib dir // if the lib dir is empty, delete it // String jarPath = "/" + getProject().getName() + "/lib/antxr.jar"; String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated"; final IJavaProject javaProject = JavaCore.create(getProject()); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); final List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : rawClasspath) { // if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // if (entry.getPath().toString().equals(jarPath)) { // found = i; // break; // } if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getPath().toString().equals(generatedSourcePath)) { continue; // skip the antxr-generated source folder } } newEntries.add(entry); } JavaCore.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { IClasspathEntry entries[] = newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(entries, null); IFolder folder = getProject().getFolder("antxr-generated"); if (folder.exists() && !hasNonAntxrGeneratedFile(folder)) { folder.delete(true, null); } else { AntxrCorePlugin.getUtil().warning(4211, "Did not delete antxr-generated source directory; it contains non-generated source. You should move that source to another source dir; it really doesn't belong there..."); } } }, null); }
From source file:com.javadude.antxr.eclipse.core.builder.AntxrBuilder.java
License:Open Source License
/** * Returns list of commandline arguments for ANTXR compiler. * * @param map/*w w w .ja v a 2 s.c o m*/ * the saved antxr-eclipse settings for this project * @param file * The grammar file to parse * @return a list of command-line arguments */ private List<String> createArguments(Map<String, Map<String, String>> map, IFile file) { List<String> args = new ArrayList<String>(); AntxrCorePlugin.getDefault().upgradeOldSettings(file, map); fOutput = SettingsPersister.get(map, file, SettingsPersister.OUTPUT_PROPERTY); // Prepare absolute output path (-o) String outputPath = null; if (fOutput != null && fOutput.trim().length() > 0) { outputPath = convertRootRelatedPath(fOutput); } if (outputPath == null) { try { IJavaProject javaProject = JavaCore.create(file.getProject()); IClasspathEntry rawClasspath[] = javaProject.getRawClasspath(); String longestSourceDirPrefix = ""; String grammarFilePath = file.getFullPath().toString(); for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String sourceDirString = entry.getPath().toString(); if (grammarFilePath.startsWith(sourceDirString) && sourceDirString.length() > longestSourceDirPrefix.length()) { longestSourceDirPrefix = sourceDirString; } } } if ("".equals(longestSourceDirPrefix)) { return null; } String basePath = file.getFullPath().removeLastSegments(1).toString(); String packageName = basePath.substring(longestSourceDirPrefix.length()); IFolder targetDirFolder = file.getProject().getFolder("antxr-generated/" + packageName); if (!targetDirFolder.exists()) { targetDirFolder.getRawLocation().toFile().mkdirs(); file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } fOutput = targetDirFolder.getFullPath().toString(); outputPath = targetDirFolder.getLocation().toString(); } catch (Exception e) { throw new RuntimeException("Could not set up antxr-generated as output dir", e); } } args.add("-o"); args.add(outputPath); // Get boolean options from grammar properties addBooleanGrammarProperty(map, file, SettingsPersister.DEBUG_PROPERTY, "-debug", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.HTML_PROPERTY, "-html", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.DOCBOOK_PROPERTY, "-docbook", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.DIAGNOSTIC_PROPERTY, "-diagnostic", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_PROPERTY, "-trace", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_PARSER_PROPERTY, "-traceParser", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_LEXER_PROPERTY, "-traceLexer", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_TREE_PARSER_PROPERTY, "-traceTreeParser", null, args, false); addBooleanGrammarProperty(map, file, SettingsPersister.SMAP_PROPERTY, "-smap", null, args, true); // Get super grammars from grammar properties String superGrammars = SettingsPersister.get(map, file, SettingsPersister.SUPER_GRAMMARS_PROPERTY); // Prepare optional super grammar(s) (-glib) // Can be defined in two ways : in a property dialog OR // inside the grammar using a comment "// -glib <file in same folder>" if (superGrammars != null && superGrammars.trim().length() > 0) { superGrammars = convertRootRelatedPathList(superGrammars); if (superGrammars != null) { args.add("-glib"); args.add(superGrammars); } } else { // Try to get // -glib parameter from comment in .g file. This // enables sharing in a team project without local reconfiguration String localSuperGrammar = extractGlibComment(fFile); if (localSuperGrammar != null) { localSuperGrammar = convertFolderRelatedPath(localSuperGrammar); if (localSuperGrammar != null) { args.add("-glib"); args.add(localSuperGrammar); } } } // Prepare ANTXR grammar file which needs to be compiled args.add(fFile.getLocation().toOSString()); return args; }