List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.eclipse.jst.j2ee.internal.archive.ComponentArchiveLoadAdapter.java
License:Open Source License
protected void aggregateClassFiles() { StructureEdit se = null;/*w w w .j a va 2 s . com*/ try { IPackageFragmentRoot[] sourceRoots = J2EEProjectUtilities.getSourceContainers(vComponent.getProject()); se = StructureEdit.getStructureEditForRead(vComponent.getProject()); for (int i = 0; i < sourceRoots.length; i++) { IPath outputPath = sourceRoots[i].getRawClasspathEntry().getOutputLocation(); if (outputPath == null) { IProject project = vComponent.getProject(); if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); outputPath = javaProject.getOutputLocation(); } } if (outputPath != null) { IContainer javaOutputContainer = outputPath.segmentCount() > 1 ? (IContainer) ResourcesPlugin.getWorkspace().getRoot().getFolder(outputPath) : (IContainer) ResourcesPlugin.getWorkspace().getRoot() .getProject(outputPath.lastSegment()); IPath runtimePath = null; try { ComponentResource[] componentResources = se .findResourcesBySourcePath(sourceRoots[i].getResource().getProjectRelativePath()); if (componentResources.length > 0) { IPath tmpRuntimePath = componentResources[0].getRuntimePath(); IPath tmpSourcePath = componentResources[0].getSourcePath(); if (!tmpRuntimePath.equals(tmpSourcePath)) { while (tmpSourcePath.segmentCount() > 0 && tmpRuntimePath.segmentCount() > 0 && tmpRuntimePath.lastSegment().equals(tmpSourcePath.lastSegment())) { tmpRuntimePath = tmpRuntimePath.removeLastSegments(1); tmpSourcePath = tmpSourcePath.removeLastSegments(1); } if (tmpRuntimePath.segmentCount() != 0) { runtimePath = tmpRuntimePath.makeRelative(); } } } } catch (UnresolveableURIException e) { J2EEPlugin.logError(e); } if (null == runtimePath) { runtimePath = new Path(""); //$NON-NLS-1$ } aggregateOutputFiles(new IResource[] { javaOutputContainer }, runtimePath, javaOutputContainer.getProjectRelativePath().segmentCount()); } } } catch (CoreException e) { J2EEPlugin.logError(e); } finally { if (se != null) { se.dispose(); } } }
From source file:org.eclipse.jst.j2ee.internal.archive.ConnectorComponentArchiveLoadAdapter.java
License:Open Source License
private IArchiveResource getNestedJar(IPackageFragmentRoot sourceRoot) throws JavaModelException, ArchiveOpenFailureException { IPath outputPath = sourceRoot.getRawClasspathEntry().getOutputLocation(); if (outputPath == null) { IProject project = vComponent.getProject(); try {/*from ww w . java 2 s . c om*/ if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); outputPath = javaProject.getOutputLocation(); } } catch (CoreException e) { J2EEPlugin.logError(e); } if (outputPath == null) { return null; } } IFolder javaOutputFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputPath); indexClassesForOutputFolder(javaOutputFolder); IContainer sourceContainer = (IContainer) sourceRoot.getResource(); int sourceContainerSegmentCount = sourceContainer.getProjectRelativePath().segmentCount(); boolean isModuleRoot = knownDD.getProjectRelativePath().toString() .startsWith(sourceContainer.getProjectRelativePath().toString()); Set iFilesSet = new HashSet(); boolean foundJava = gatherFilesForJAR(iFilesSet, sourceContainer, isModuleRoot, false, sourceContainerSegmentCount); if (!isModuleRoot || foundJava) { List<IFile> iFilesList = Collections.list(Collections.enumeration(iFilesSet)); for (int i = 0; i < iFilesList.size(); i++) { filesHolder.removeIFile(iFilesList.get(i)); } IArchiveResource nestedArchive = createNestedArchive(iFilesList, sourceContainer, javaOutputFolder); return nestedArchive; } return null; }
From source file:org.eclipse.jst.j2ee.internal.archive.operations.ComponentLoadStrategyImpl.java
License:Open Source License
protected void aggregateClassFiles() { StructureEdit se = null;/*from w w w .j ava2s . com*/ try { IPackageFragmentRoot[] sourceRoots = J2EEProjectUtilities.getSourceContainers(vComponent.getProject()); se = StructureEdit.getStructureEditForRead(vComponent.getProject()); for (int i = 0; i < sourceRoots.length; i++) { IPath outputPath = sourceRoots[i].getRawClasspathEntry().getOutputLocation(); if (outputPath == null) { IProject project = vComponent.getProject(); if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); outputPath = javaProject.getOutputLocation(); } } if (outputPath != null) { IContainer javaOutputContainer = outputPath.segmentCount() > 1 ? (IContainer) ResourcesPlugin.getWorkspace().getRoot().getFolder(outputPath) : (IContainer) ResourcesPlugin.getWorkspace().getRoot() .getProject(outputPath.lastSegment()); IPath runtimePath = null; try { ComponentResource[] componentResources = se .findResourcesBySourcePath(sourceRoots[i].getResource().getProjectRelativePath()); if (componentResources.length > 0) { IPath tmpRuntimePath = componentResources[0].getRuntimePath(); IPath tmpSourcePath = componentResources[0].getSourcePath(); if (!tmpRuntimePath.equals(tmpSourcePath)) { while (tmpSourcePath.segmentCount() > 0 && tmpRuntimePath.segmentCount() > 0 && tmpRuntimePath.lastSegment().equals(tmpSourcePath.lastSegment())) { tmpRuntimePath = tmpRuntimePath.removeLastSegments(1); tmpSourcePath = tmpSourcePath.removeLastSegments(1); } if (tmpRuntimePath.segmentCount() != 0) { runtimePath = tmpRuntimePath.makeRelative(); } } } } catch (UnresolveableURIException e) { J2EEPlugin.logError(e); } if (null == runtimePath) { runtimePath = new Path(""); //$NON-NLS-1$ } aggregateOutputFiles(new IResource[] { javaOutputContainer }, runtimePath, javaOutputContainer.getProjectRelativePath().segmentCount()); } } } catch (CoreException e) { J2EEPlugin.logError(e); } finally { if (se != null) { se.dispose(); } } }
From source file:org.eclipse.jst.j2ee.internal.jca.archive.operations.ConnectorComponentLoadStrategyImpl.java
License:Open Source License
private File getNestedJar(IPackageFragmentRoot sourceRoot) throws JavaModelException { IPath outputPath = sourceRoot.getRawClasspathEntry().getOutputLocation(); if (outputPath == null) { IProject project = vComponent.getProject(); try {//from ww w . j av a 2 s . c o m if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); outputPath = javaProject.getOutputLocation(); } } catch (CoreException e) { Logger.getLogger().logError(e); } if (outputPath == null) { return null; } } IFolder javaOutputFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputPath); indexClassesForOutputFolder(javaOutputFolder); IContainer sourceContainer = (IContainer) sourceRoot.getResource(); int sourceContainerSegmentCount = sourceContainer.getProjectRelativePath().segmentCount(); boolean isModuleRoot = knownDD.getProjectRelativePath().toString() .startsWith(sourceContainer.getProjectRelativePath().toString()); Set iFilesSet = new HashSet(); boolean foundJava = gatherFilesForJAR(iFilesSet, sourceContainer, isModuleRoot, false, sourceContainerSegmentCount); if (!isModuleRoot || foundJava) { List iFilesList = Collections.list(Collections.enumeration(iFilesSet)); for (int i = 0; i < iFilesList.size(); i++) { filesHolder.removeIFile((IFile) iFilesList.get(i)); } File nestedArchive = createNestedArchive(iFilesList, sourceContainer, javaOutputFolder); return nestedArchive; } return null; }
From source file:org.eclipse.jst.j2ee.internal.project.WTPJETEmitter.java
License:Open Source License
/** * @param workspace//from w w w . j a v a 2s .c om * @param project * @param javaProject * @param packageName * @param subProgressMonitor * @throws JavaModelException * @throws MalformedURLException * @throws ClassNotFoundException * @throws SecurityException */ protected void loadClass(final IWorkspace workspace, final IProject project, IJavaProject javaProject, String packageName, IProgressMonitor subProgressMonitor) throws JavaModelException, MalformedURLException, ClassNotFoundException, SecurityException { //IContainer targetContainer = // workspace.getRoot().getFolder(javaProject.getOutputLocation()); subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETLoadingClass_message", //$NON-NLS-1$ new Object[] { jetCompiler.getSkeleton().getClassName() + ".class" })); //$NON-NLS-1$ // Construct a proper URL for relative lookup. // URL url = new File( project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/").toURL(); //$NON-NLS-1$ //$NON-NLS-2$ URLClassLoader theClassLoader = new URLClassLoader(new URL[] { url }, classLoader); Class theClass = theClassLoader.loadClass( (packageName.length() == 0 ? "" : packageName + ".") + jetCompiler.getSkeleton().getClassName()); //$NON-NLS-1$ //$NON-NLS-2$ String methodName = jetCompiler.getSkeleton().getMethodName(); Method[] methods = theClass.getDeclaredMethods(); for (int i = 0; i < methods.length; ++i) { if (methods[i].getName().equals(methodName)) { setMethod(methods[i]); break; } } }
From source file:org.eclipse.jst.j2ee.internal.web.deployables.WebDeployableArtifactUtil.java
License:Open Source License
public static String getClassNameForType(IResource resource, String superType) { if (resource == null) return null; try {//www . ja v a 2 s . c o m IProject project = resource.getProject(); IPath path = resource.getFullPath(); if (!project.hasNature(JavaCore.NATURE_ID) || path == null) return null; IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); if (!javaProject.isOpen()) javaProject.open(new NullProgressMonitor()); // output location may not be on classpath IPath outputPath = javaProject.getOutputLocation(); if (outputPath != null && "class".equals(path.getFileExtension()) && outputPath.isPrefixOf(path)) { //$NON-NLS-1$ int count = outputPath.segmentCount(); path = path.removeFirstSegments(count); } // remove initial part of classpath IClasspathEntry[] classPathEntry = javaProject.getResolvedClasspath(true); if (classPathEntry != null) { int size = classPathEntry.length; for (int i = 0; i < size; i++) { IPath classPath = classPathEntry[i].getPath(); if (classPath.isPrefixOf(path)) { int count = classPath.segmentCount(); path = path.removeFirstSegments(count); i += size; } } } // get java element IJavaElement javaElement = javaProject.findElement(path); IType[] types = getTypes(javaElement); if (types != null) { int size2 = types.length; for (int i = 0; i < size2; i++) { if (hasSuperclass(types[i], superType)) return types[i].getFullyQualifiedName(); } } return null; } catch (Exception e) { return null; } }
From source file:org.eclipse.jst.j2ee.project.facet.J2EEFacetInstallDelegate.java
License:Open Source License
/** * This method will set the output property on the model element for the given component. * //ww w . j a v a 2 s. c om * @param model * @param component */ protected void setOutputFolder(IDataModel model, IVirtualComponent component) { IJavaProject javaProject = JavaCore.create(component.getProject()); IPath currentDefaultOutput = null; try { currentDefaultOutput = javaProject.getOutputLocation(); component.setMetaProperty("java-output-path", currentDefaultOutput.toString()); //$NON-NLS-1$ } catch (JavaModelException e) { org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e); } }
From source file:org.eclipse.jst.jsp.core.internal.taglib.BuildPathClassLoader.java
License:Open Source License
protected Class findClass(String className) throws ClassNotFoundException { if (DEBUG)/* w w w . ja v a 2 s .com*/ System.out.println("finding: [" + className + "]"); //$NON-NLS-1$ //$NON-NLS-2$ try { IType type = fProject.findType(className); int offset = -1; if (type == null && (offset = className.indexOf('$')) != -1) { // Internal classes from source files must be referenced by . instead of $ String cls = className.substring(0, offset) + className.substring(offset).replace('$', '.'); type = fProject.findType(cls); } if (type != null) { IPath path = null; IResource resource = type.getResource(); if (resource != null) path = resource.getLocation(); if (path == null) path = type.getPath(); // needs to be compiled before we can load it if ("class".equalsIgnoreCase(path.getFileExtension())) { IFile file = null; if (resource != null && resource.getType() == IResource.FILE) file = (IFile) resource; else file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (file != null && file.isAccessible()) { byte[] bytes = loadBytes(file); return defineClass(className, bytes, 0, bytes.length); } } // Look up the class file based on the output location of the java project else if ("java".equalsIgnoreCase(path.getFileExtension()) && resource != null) { //$NON-NLS-1$ if (resource.getProject() != null) { IJavaProject jProject = JavaCore.create(resource.getProject()); String outputClass = StringUtils.replace(type.getFullyQualifiedName(), ".", "/") //$NON-NLS-1$//$NON-NLS-2$ .concat(".class"); //$NON-NLS-1$ IPath classPath = jProject.getOutputLocation().append(outputClass); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(classPath); if (file != null && file.isAccessible()) { byte[] bytes = loadBytes(file); return defineClass(className, bytes, 0, bytes.length); } } } else if ("jar".equalsIgnoreCase(path.getFileExtension())) { String expectedFileName = StringUtils.replace(className, ".", "/").concat(".class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ byte[] bytes = getCachedInputStream(path.toOSString(), expectedFileName); return defineClass(className, bytes, 0, bytes.length); } } } catch (JavaModelException e) { Logger.logException(e); } return super.findClass(className); }
From source file:org.eclipse.jst.ws.internal.common.ResourceUtils.java
License:Open Source License
/** * Returns the build output location of the <code>project</code> as an * <code>IPath</code>, or null if the project has no Java nature. * i.e. WP\.deployables\webModule\WEB-INF\classes * @param project//from ww w . j a v a 2 s . com * The project. * @return The build output location of the <code>project</code> or null * if the project has no Java nature. */ public static IPath getJavaOutputLocation(IProject project) { IPath outputLocation = null; try { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { outputLocation = javaProject.getOutputLocation(); } } catch (JavaModelException e) { } ILog log = EnvironmentService.getEclipseLog(); log.log(ILog.INFO, 5032, ResourceUtils.class, "getJavaOutputLocation", "project=" + project + ",outputLocation=" + outputLocation); return outputLocation; }
From source file:org.eclipse.libra.facet.OSGiBundleFacetInstallDelegate.java
License:Open Source License
private IBundleClasspathEntry[] getBundleClasspath(IBundleProjectDescription bundleProjectDescription) throws CoreException { IProject project = bundleProjectDescription.getProject(); IBundleClasspathEntry[] bundleClasspath = bundleProjectDescription.getBundleClasspath(); IJavaProject javaProject = JavaCore.create(project); if (bundleClasspath == null) { IPath[] javaSourceFolderPaths = getJavaSourceFolderPaths(javaProject); if (javaSourceFolderPaths != null && javaSourceFolderPaths.length > 0) { IBundleProjectService bundleProjectService = LibraFacetPlugin.getDefault() .getBundleProjectService(); List<IBundleClasspathEntry> bundleClasspathList = new ArrayList<IBundleClasspathEntry>(); IPath binary = getRelativePath(project, javaProject.getOutputLocation()); IPath library = (isWebProject(project)) ? new Path(WEB_INF_CLASSES) // add WEB-INF/classes for WABs : null; // add . for other OSGi bundles //iterate over source folders and create IBundleClasspathEntry for each one. for (IPath iPath : javaSourceFolderPaths) { bundleClasspathList.add(bundleProjectService .newBundleClasspathEntry(getRelativePath(project, iPath), binary, library)); }/*from www .j av a 2 s. c o m*/ bundleClasspath = bundleClasspathList.toArray(new IBundleClasspathEntry[] {}); ; } } else { // TODO } // don't modify bin.includes by default return bundleClasspath; }