List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath
IPath getPath();
From source file:de.loskutov.bco.editors.BytecodeSourceMapper.java
License:Open Source License
private static String getArchivePath(IPackageFragmentRoot root) { String archivePath = null;// w w w.j a v a2 s.c o m IResource resource; try { if ((resource = root.getUnderlyingResource()) != null) { // jar in workspace archivePath = resource.getLocation().toOSString(); } else { // external jar archivePath = root.getPath().toOSString(); } } catch (JavaModelException e) { BytecodeOutlinePlugin.log(e, IStatus.ERROR); } return archivePath; }
From source file:de.ovgu.featureide.core.framework.FrameworkProjectCreator.java
License:Open Source License
/** * Creates a new subproject inside a folder * //from ww w .j a v a 2 s.co m * @param name - project name * @param destination - folder which contains the subproject * @throws CoreException */ public static void createSubprojectFolder(String name, IFolder destination) throws CoreException { final IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(name); description.setLocation(destination.getLocation()); final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (project.exists()) { return; } project.create(description, null); project.open(null); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); javaProject.open(null); final IFolder binFolder = project.getFolder("bin"); binFolder.create(true, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); final IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); final LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall); for (final LibraryLocation element : locations) { entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null)); } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); final IFolder sourceFolder = project.getFolder("src"); sourceFolder.create(false, true, null); final IPackageFragmentRoot srcRoot = javaProject.getPackageFragmentRoot(sourceFolder); final IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); final int oldLength = oldEntries.length; final IClasspathEntry[] newEntries = new IClasspathEntry[oldLength + 2]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldLength] = JavaCore.newSourceEntry(srcRoot.getPath()); newEntries[oldLength + 1] = JavaCore.newProjectEntry(destination.getProject().getFullPath()); javaProject.setRawClasspath(newEntries, null); final IFile infoXML = destination.getFile("info.xml"); if (!infoXML.exists()) { createInfoXML(destination); } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
/********************************************************************************/ void handleFindHierarchy(String proj, String pkg, String cls, boolean all, IvyXmlWriter xw) throws BedrockException { IJavaProject ijp = getJavaProject(proj); IRegion rgn = JavaCore.newRegion();//from w w w. ja v a 2 s. c o m IType fortype = null; boolean havejp = (ijp != null); if (ijp == null && (pkg != null || cls != null)) { IJavaElement[] aps = getAllProjects(); if (aps.length == 0) return; if (cls != null) { for (IJavaElement ije : aps) { IJavaProject xjp = ije.getJavaProject(); try { if (xjp.findType(cls) != null) { ijp = xjp; break; } } catch (JavaModelException e) { } } } if (ijp == null) ijp = aps[0].getJavaProject(); } int addct = 0; if (cls != null && ijp != null) { try { IType typ = ijp.findType(cls); fortype = typ; // rgn.add(typ); // ++addct; } catch (JavaModelException e) { BedrockPlugin.logE("Problem getting type by name: " + e); } } if (pkg != null && ijp != null) { String ppth = "/" + pkg.replace(".", "/"); try { for (IPackageFragmentRoot ipr : ijp.getPackageFragmentRoots()) { IPath rpath = ipr.getPath(); Path npath = new Path(rpath.toString() + ppth); IPackageFragment ipf = ijp.findPackageFragment(npath); if (ipf != null) { rgn.add(ipf); ++addct; } } } catch (Exception e) { BedrockPlugin.logE("Problem getting package fragments for " + ppth + ": " + e); } } else if (havejp && ijp != null) { if (all) { rgn.add(ijp); ++addct; } else { try { for (IPackageFragment ipf : ijp.getPackageFragments()) { for (ICompilationUnit icu : ipf.getCompilationUnits()) { IType ity = ((ITypeRoot) icu).findPrimaryType(); if (ity != null) { rgn.add(ity); ++addct; } } } } catch (Throwable e) { BedrockPlugin.logE("Problem getting package fragments: " + e); } } } else { for (IJavaElement pi : getAllProjects()) { IJavaProject xjp = pi.getJavaProject(); if (xjp != null && !rgn.contains(xjp)) { rgn.add(xjp); ++addct; } // String pnm = pi.getJavaProject().getProject().getName(); // handleFindHierarchy(pnm,null,null,all,xw); } } if (addct > 0 && ijp != null) { try { BedrockPlugin.logD("FIND TYPE HIERARCHY FOR " + fortype + " " + addct + " " + rgn); ITypeHierarchy ith; if (fortype != null) ith = ijp.newTypeHierarchy(fortype, rgn, null); else ith = ijp.newTypeHierarchy(rgn, null); BedrockUtil.outputTypeHierarchy(ith, xw); } catch (JavaModelException e) { BedrockPlugin.logE("Problem outputing type hierarchy: " + e); } catch (NullPointerException e) { // this is a bug in Eclipse that should be fixed } } }
From source file:edu.buffalo.cse.green.test.core.Project.java
License:Open Source License
/** * Creates the SRC folder for the project. *///from w ww . j a v a2 s . c om private IPackageFragmentRoot createSourceFolder() throws CoreException { IFolder folder = project.getFolder("src"); folder.create(false, true, null); IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); javaProject.setRawClasspath(newEntries, null); return root; }
From source file:edu.pdx.cs.multiview.test.JavaTestProject.java
License:Open Source License
private IPackageFragmentRoot createSourceFolder() throws CoreException { IFolder folder = project.getFolder("src"); if (!folder.exists()) { monitor.reset();//from ww w . java 2 s . c om folder.create(false, true, monitor); monitor.waitForCompletion(); } IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); monitor.reset(); javaProject.setRawClasspath(newEntries, monitor); monitor.waitForCompletion(); return root; }
From source file:es.bsc.servicess.ide.PackagingUtils.java
License:Apache License
/** create the package for a group of core elements * this method creates a jar and a zip file with the * element classes, their dependencies and runtime files * /*from ww w. j av a2 s . c o m*/ * @param runtimePath Path where the runtime is located * @param packageName Name of the package to create * @param elementsInPackage Array of Core elements in the package * @param dependencies Array of Core Element dependencies of the package * @param elements Descriptions of all the Core Elements of the java project * @param sourceDir Location of the source folder in the java project * @param binariesFolder Location where the binaries (.class) are stored in the java project * @param packagesFolder Location where the packages are stored * @param myProgressMonitor Eclipse Progress Monitor to report the progress of the different tasks * @throws CoreException * @throws InterruptedException */ public static void createCorePackage(String runtimePath, String packageName, String[] elementsInPackage, List<Dependency> dependencies, HashMap<String, ServiceElement> elements, IPackageFragmentRoot sourceDir, IFolder binariesFolder, IFolder packagesFolder, IProgressMonitor myProgressMonitor) throws CoreException, InterruptedException { IFolder jar_folder = packagesFolder.getFolder(packageName); if (jar_folder != null && jar_folder.exists()) { jar_folder.delete(true, myProgressMonitor); } jar_folder.create(true, true, myProgressMonitor); IFolder classes = jar_folder; IPackageFragment[] coreFragments = getCorePackageFragments(elementsInPackage, elements, sourceDir); if (coreFragments != null && coreFragments.length > 0) { copyClasses(coreFragments, sourceDir.getPath(), binariesFolder, classes, myProgressMonitor); } IFolder lib = jar_folder.getFolder("lib"); lib.create(true, true, myProgressMonitor); manageDependencies(dependencies, packageName, packagesFolder, classes, lib, myProgressMonitor); copyCoreRuntimeFiles(runtimePath, jar_folder); IFile jar = packagesFolder.getFile(packageName + ".jar"); createJar(jar, jar_folder, myProgressMonitor); jar_folder.delete(true, myProgressMonitor); }
From source file:es.bsc.servicess.ide.PackagingUtils.java
License:Apache License
/** Creates an element package for the front-end which includes all the internal * Orchestration Elements of a package.// ww w . j a v a2 s. c o m * * Create the service stubs, instrument the classes which contains Orchestration elements, * manage dependencies, copy programming model runtime files and generate a war package * * @param runtimePath * @param projectClasspath * @param projectName * @param orchestrationClasses * @param dependencies * @param sourceDir * @param generated * @param outputFolder * @param packagesFolder * @param myProgressMonitor * @param isWar * @throws CoreException * @throws InterruptedException */ public static void createInternalOrchestrationPackage(String runtimePath, String projectClasspath, String projectName, Map<String, List<String>> orchClassesAndElements, List<Dependency> dependencies, IPackageFragmentRoot sourceDir, IPackageFragmentRoot generated, IFolder outputFolder, IFolder packagesFolder, IProgressMonitor myProgressMonitor, boolean isWar) throws CoreException, InterruptedException { IFolder classes; IFolder lib; IFile war; String[] orchestrationClasses = orchClassesAndElements.keySet() .toArray(new String[orchClassesAndElements.keySet().size()]); IFolder war_folder = packagesFolder.getFolder(projectName); if (war_folder != null && war_folder.exists()) { war_folder.delete(true, myProgressMonitor); } war_folder.create(true, true, myProgressMonitor); if (isWar) { log.debug("Generating service package"); IFolder web_inf = war_folder.getFolder("WEB-INF"); web_inf.create(true, true, myProgressMonitor); IFile web_xml = web_inf.getFile("web.xml"); InputStream web_info = generateWebInfo(projectName, orchestrationClasses); web_xml.create(web_info, true, myProgressMonitor); IFile sun_jaxws = web_inf.getFile("sun-jaxws.xml"); InputStream jaxws = generateJAXWSInfo(projectName, orchestrationClasses); sun_jaxws.create(jaxws, true, myProgressMonitor); classes = web_inf.getFolder("classes"); classes.create(true, true, myProgressMonitor); lib = web_inf.getFolder("lib"); if (!lib.exists()) { lib.create(true, true, myProgressMonitor); } war = packagesFolder.getFile(projectName + ".war"); } else { classes = war_folder; lib = war_folder.getFolder("lib"); if (!lib.exists()) { lib.create(true, true, myProgressMonitor); } war = packagesFolder.getFile(projectName + ".jar"); } // IPackageFragment[] packageFragments = // getOrchestrationPackageFragments(cls, source_dir); IPackageFragment[] packageFragments = getAllPackageFragments(sourceDir); copyClasses(packageFragments, sourceDir.getPath(), outputFolder, classes, myProgressMonitor); if (isWar) { if (generated != null) { IPackageFragment[] genFragments = getAllPackageFragments(generated); copyClasses(genFragments, generated.getPath(), outputFolder, classes, myProgressMonitor); } } instrumentOrchestrations(runtimePath, orchestrationClasses, classes, dependencies, myProgressMonitor); if (isWar) { generateServiceStubs(projectClasspath, orchestrationClasses, classes, myProgressMonitor); copyJaxWSLibraries(lib); } manageDependencies(dependencies, projectName, packagesFolder, classes, lib, myProgressMonitor); copyOrchestrationRuntimeFiles(runtimePath, lib); createJar(war, war_folder, myProgressMonitor); war_folder.delete(true, myProgressMonitor); }
From source file:es.bsc.servicess.ide.PackagingUtils.java
License:Apache License
private static void processOrchestrationClassForExternalPackage(String orchClass, List<String> methods, IPackageFragmentRoot sourceDir, IFolder outFolder, IFolder classes, String runtimePath, List<Dependency> dependencies, IProgressMonitor myProgressMonitor) throws CoreException { IPackageFragment pf = sourceDir.getPackageFragment(Signature.getQualifier(orchClass)); copyInterface(Signature.getSimpleName(orchClass), pf, sourceDir.getPath(), outFolder, classes, myProgressMonitor);//from w w w .j a va2 s .c o m preInstrumentOrchestration(runtimePath, orchClass, methods, classes, dependencies, myProgressMonitor); instrumentOrchestrations(runtimePath, new String[] { orchClass }, classes, dependencies, myProgressMonitor); }
From source file:es.bsc.servicess.ide.wizards.ServiceSsCommonWizardPage.java
License:Apache License
/** * 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>//from w ww. j a v a2s.c om * 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); } else { status.setError(""); //$NON-NLS-1$ } return status; }
From source file:es.bsc.servicess.ide.wizards.ServiceSsNewServiceClassPage.java
License:Apache License
/** * 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>/*from w ww .ja v a 2s . c o m*/ * 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); } else { status.setError(""); //$NON-NLS-1$ } return status; }