List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.switchyard.tools.ui.JavaUtil.java
License:Open Source License
/** * Creates a ClassLoader using the project's build path. * //from w w w. ja v a 2s . c o m * @param javaProject the Java project. * @param parentClassLoader the parent class loader, may be null. * * @return a new ClassLoader based on the project's build path. * * @throws Exception if something goes wrong. */ public static ClassLoader getProjectClassLoader(IJavaProject javaProject, ClassLoader parentClassLoader) throws Exception { IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add( new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") //$NON-NLS-1$ //$NON-NLS-2$ .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$ + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$ } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL()); } } if (parentClassLoader == null) { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } else { return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader); } }
From source file:org.teavm.eclipse.TeaVMProjectBuilder.java
License:Apache License
private void prepareClassPath() throws CoreException { classPath = new URL[0]; sourceContainers = new IContainer[0]; sourceProviders = new SourceFileProvider[0]; IProject project = getProject();/*www. j a v a 2 s .c o m*/ if (!project.hasNature(JavaCore.NATURE_ID)) { return; } IJavaProject javaProject = JavaCore.create(project); PathCollector collector = new PathCollector(); SourcePathCollector srcCollector = new SourcePathCollector(); SourcePathCollector binCollector = new SourcePathCollector(); SourceFileCollector sourceFileCollector = new SourceFileCollector(); IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); try { if (javaProject.getOutputLocation() != null) { IContainer container = (IContainer) workspaceRoot.findMember(javaProject.getOutputLocation()); collector.addPath(container.getLocation()); binCollector.addContainer(container); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } Queue<IJavaProject> projectQueue = new ArrayDeque<>(); projectQueue.add(javaProject); Set<IJavaProject> visitedProjects = new HashSet<>(); while (!projectQueue.isEmpty()) { javaProject = projectQueue.remove(); if (!visitedProjects.add(javaProject)) { continue; } IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: try { collector.addPath(entry.getPath()); } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } if (entry.getSourceAttachmentPath() != null) { sourceFileCollector.addFile(entry.getSourceAttachmentPath()); } break; case IClasspathEntry.CPE_SOURCE: if (entry.getOutputLocation() != null) { try { IResource res = workspaceRoot.findMember(entry.getOutputLocation()); if (res != null) { collector.addPath(res.getLocation()); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } IContainer srcContainer = (IContainer) workspaceRoot.findMember(entry.getPath()); if (srcContainer != null) { srcCollector.addContainer(srcContainer); sourceFileCollector.addFile(srcContainer.getLocation()); try { collector.addPath(srcContainer.getLocation()); } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } break; case IClasspathEntry.CPE_PROJECT: { IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); IProject depProject = resource.getProject(); if (!depProject.hasNature(JavaCore.NATURE_ID)) { break; } IJavaProject depJavaProject = JavaCore.create(depProject); if (depJavaProject.getOutputLocation() != null) { try { IContainer container = (IContainer) workspaceRoot .findMember(depJavaProject.getOutputLocation()); if (container != null) { collector.addPath(container.getLocation()); binCollector.addContainer(container); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } projectQueue.add(depJavaProject); break; } } } } classPath = collector.getUrls(); sourceContainers = srcCollector.getContainers(); classFileContainers = binCollector.getContainers(); sourceProviders = sourceFileCollector.getProviders(); }
From source file:org.wso2.developerstudio.eclipse.artifact.axis2.ui.action.WSDLGenerationAction.java
License:Open Source License
/** * This method is for showing a location selector window to user to input the location of WSDL file * and for creating WSDL file using Java to WSDL code engine * * @param project Axis2 project//w ww . j ava 2 s . c o m * @throws org.wso2.developerstudio.eclipse.artifact.axis2.ui.action.exception.WSDLGenerationException * @throws org.eclipse.core.runtime.CoreException */ private void generateWSDL(IProject project) throws WSDLGenerationException, CoreException { Shell shell = Display.getDefault().getActiveShell(); List<File> classpathLocations = new ArrayList<File>(); project.build(CLEAN_BUILD, null); project.build(FULL_BUILD, null); IJavaProject javaProject = JavaCore.create(project); IPath outputLocation; try { outputLocation = javaProject.getOutputLocation(); } catch (JavaModelException e) { throw new WSDLGenerationException("Error in getting output location for Java project : " + javaProject, e); } File classPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation).getLocation().toFile(); try { updateClassPathLocations(classPath, classpathLocations, project); } catch (JavaModelException e) { throw new WSDLGenerationException( "Error in updating class path location for project : " + project.getName(), e); } IFolder resourcesDir = project.getFolder(new Path(DEFAULT_RESOURCES_DIRECTORY)); String serviceClassName; try { serviceClassName = Axis2ServiceUtils .getServiceClassNameFromFolder(resourcesDir.getLocation().toOSString()); } catch (Exception e) { throw new WSDLGenerationException( "Error in extracting service class name from services.xml file, Location : " + resourcesDir.getLocation().toOSString(), e); } String serviceName; try { serviceName = Axis2ServiceUtils.getServiceNameFromFolder(resourcesDir.getLocation().toOSString()); } catch (Exception e) { throw new WSDLGenerationException("Error in extracting service name from services.xml file, Location : " + resourcesDir.getLocation().toOSString(), e); } String serviceFileName = serviceName.concat(WSDL_EXTENSION); IFile defaultFile = resourcesDir.getFile(new Path(serviceFileName)); IFile userSelectedFile = WorkspaceResourceDialog.openNewFile(shell, "WSDL for " + serviceName, SELECT_NAME_AND_LOCATION_MESSAGE, defaultFile.getFullPath(), null); if (userSelectedFile == null) { return; } ITemporaryFileTag wsdlTempTag = FileUtils.createNewTempTag(); File wsdlFile = generateWSDLFromJava2WSDLCodeGenEngine(serviceName, classpathLocations.toArray(new File[] {}), serviceClassName); InputStream wsdlFileStream; try { wsdlFileStream = new FileInputStream(wsdlFile); } catch (FileNotFoundException e) { throw new WSDLGenerationException( "Error in creating input stream for generated WSDL file : " + wsdlFile.getName(), e); } if (userSelectedFile.exists()) { userSelectedFile.setContents(wsdlFileStream, IResource.FORCE, null); } else { userSelectedFile.create(wsdlFileStream, true, null); } project.refreshLocal(IResource.DEPTH_INFINITE, null); try { IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), userSelectedFile); } catch (PartInitException e) { log.error("Error in opening created WSDL file for Axis2 service : " + serviceName, e); } finally { wsdlTempTag.clearAndEnd(); } }
From source file:org.wso2.developerstudio.eclipse.artifact.brs.export.BRSExportHandler.java
License:Open Source License
@Override public List<IResource> exportArtifact(IProject project) throws Exception { List<IResource> exportResources = new ArrayList<IResource>(); ArchiveManipulator archiveManipulator = new ArchiveManipulator(); NullProgressMonitor nullProgressMonitor = new NullProgressMonitor(); clearTarget(project);//w ww. jav a 2s .c o m project.build(IncrementalProjectBuilder.FULL_BUILD, nullProgressMonitor); IJavaProject javaProject = JavaCore.create(project); List<String> exportPac = getExportPackages(javaProject); BundleManifest manifest = new BundleManifest(); manifest.setBundleName(project.getName()); manifest.setBundleVersion("1.0"); manifest.setExportPackagesList(exportPac); IPath outPutPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(javaProject.getOutputLocation()) .getLocation(); IPath rslmetaData = project.getFolder("src" + File.separator + "main" + File.separator + "ruleservice") .getLocation(); File tempProject = createTempProject(); File brsAarResources = createTempDir(tempProject, "aar_resources"); File brsJarResources = createTempDir(tempProject, "jar_resources"); if (rslmetaData.toFile().exists()) { FileUtils.copyDirectoryContents(rslmetaData.toFile(), brsAarResources); } FileUtils.copyDirectoryContents(outPutPath.toFile(), brsJarResources); File metainfPath = new File(brsJarResources, "META-INF"); metainfPath.mkdir(); File manifestFile = new File(metainfPath, "MANIFEST.MF"); FileUtils.createFile(manifestFile, manifest.toString()); File tmpArchivejar = new File(tempProject, project.getName().concat(".jar")); archiveManipulator.archiveDir(tmpArchivejar.toString(), brsJarResources.toString()); IFolder binaries = project.getFolder("target"); if (!binaries.exists()) { binaries.create(true, true, nullProgressMonitor); binaries.setHidden(true); } /*IFile serviceArchivejar = project.getFile("jarFolder" + File.separator + "lib" + File.separator + project.getName().concat(".jar"));*/ IFile jarFile = project.getFile("src" + File.separator + "main" + File.separator + "ruleservice" + File.separator + "lib" + File.separator + project.getName().concat(".jar")); /*IPath jarFile = project.getFolder( "src" + File.separator + "main" + File.separator + "ruleservice" + File.separator + "lib" +File.separator+ project.getName().concat(".jar")).getLocation();*/ /*File libFolder = serviceArchivejar.getParent().getLocation().toFile();*/ File libFolder = jarFile.getParent().getLocation().toFile(); /*FileUtils.copy(tmpArchivejar, serviceArchivejar.getLocation().toFile());*/ FileUtils.copy(tmpArchivejar, jarFile.getLocation().toFile()); FileUtils.copyDirectoryContents(libFolder.getParentFile(), brsAarResources); /*FileUtils.copyDirectoryContents(libFolder.getParentFile(), brsAarResources);*/ File tmpArchive = new File(tempProject, project.getName().concat(".aar")); archiveManipulator.archiveDir(tmpArchive.toString(), brsAarResources.toString()); IFile serviceArchive = getTargetArchive(project, "aar"); FileUtils.copy(tmpArchive, serviceArchive.getLocation().toFile()); exportResources.add(serviceArchive); TempFileUtils.cleanUp(); return exportResources; }
From source file:org.wso2.developerstudio.eclipse.artifact.registry.filter.project.export.RegistryFilterArtifactHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) { List<IResource> exportResources = new ArrayList<IResource>(); List<String> exportedPackageList = new ArrayList<String>(); if (!project.isOpen()) { return exportResources; }/*from ww w . j a v a 2s .co m*/ try { ArchiveManipulator archiveManipulator = new ArchiveManipulator(); NullProgressMonitor nullProgressMonitor = new NullProgressMonitor(); //cleaning target directory clearTarget(project); //getting maven details MavenProject mavenProject = MavenUtils .getMavenProject(project.getFile("pom.xml").getLocation().toFile()); // First compile the code project.build(IncrementalProjectBuilder.FULL_BUILD, nullProgressMonitor); // Get the output location IJavaProject javaProject = JavaCore.create(project); IPath outPutPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(javaProject.getOutputLocation()) .getLocation(); // get resource location IPath resources = project.getFolder("src" + File.separator + "main" + File.separator + "resources") .getLocation(); // getting export packages for (IPackageFragment pkg : javaProject.getPackageFragments()) { if (pkg.getKind() == IPackageFragmentRoot.K_SOURCE) { if (pkg.hasChildren()) { exportedPackageList.add(pkg.getElementName()); } } } IProject tempProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(".temp" + System.currentTimeMillis()); tempProject.create(nullProgressMonitor); tempProject.open(nullProgressMonitor); tempProject.setHidden(true); org.eclipse.osgi.storagemanager.StorageManager manager = new StorageManager( tempProject.getLocation().toFile(), "false"); File filterResources = manager.createTempFile("filter_resources"); filterResources.delete(); filterResources.mkdir(); FileUtils.copyDirectoryContents(outPutPath.toFile(), filterResources); // copy binaries if (resources.toFile().exists()) { FileUtils.copyDirectoryContents(resources.toFile(), filterResources); // copy resources } /* writing manifest */ BundleManifest manifest = new BundleManifest(); manifest.setBundleName(project.getName()); manifest.setBundleSymbolicName(project.getName()); if (null != mavenProject.getModel().getDescription() && !"".equals(mavenProject.getModel().getDescription())) { manifest.setBundleDescription(mavenProject.getModel().getDescription()); } else { manifest.setBundleDescription(project.getName()); } if (null != mavenProject.getModel().getVersion() && !"".equals(mavenProject.getDescription())) { manifest.setBundleVersion(mavenProject.getModel().getVersion()); } else { manifest.setBundleVersion("1.0.0"); } manifest.setExportPackagesList(exportedPackageList); File metaInfDir = new File(filterResources, "META-INF"); if (!metaInfDir.exists()) metaInfDir.mkdir(); File manifestFile = new File(metaInfDir, "MANIFEST.MF"); FileUtils.createFile(manifestFile, manifest.toString()); File tmpArchive = new File(tempProject.getLocation().toFile(), project.getName().concat(".jar")); archiveManipulator.archiveDir(tmpArchive.toString(), filterResources.toString()); IFolder binaries = project.getFolder("target"); if (!binaries.exists()) { binaries.create(true, false, nullProgressMonitor); binaries.setHidden(true); } IFile bundleArchive = project.getFile("target/" + project.getName().concat(".jar")); FileUtils.copy(tmpArchive, bundleArchive.getLocation().toFile()); exportResources.add((IResource) bundleArchive); // cleaning temp project tempProject.delete(true, nullProgressMonitor); } catch (Exception e) { e.printStackTrace(); } return exportResources; }
From source file:org.wso2.developerstudio.eclipse.platform.core.project.export.ProjectArtifactHandler.java
License:Open Source License
protected IPath getOutputPath(IJavaProject project) throws Exception { return ResourcesPlugin.getWorkspace().getRoot().getFolder(project.getOutputLocation()).getLocation(); }
From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java
License:Open Source License
public static IPath getJavaOutputDirectory(IProject project) { IPath outputLocation = null;// w w w . ja v a2s . c o m try { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { outputLocation = javaProject.getOutputLocation(); } } catch (JavaModelException e) { } return outputLocation; }
From source file:pt.org.aguiaj.core.AguiaJActivator.java
License:Open Source License
private void addDependencyPaths(List<IPath> workingDirs, IPath dir) { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); try {/* ww w . j ava 2 s. c o m*/ for (IProject proj : projects) { if (proj.getLocation().equals(dir) && proj.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProj = (IJavaProject) proj.getNature(JavaCore.NATURE_ID); IClasspathEntry[] classpath = javaProj.getRawClasspath(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { for (IProject p : projects) { if (p.isOpen() && p.hasNature(JavaCore.NATURE_ID) && p.getLocation().lastSegment().equals(entry.getPath().lastSegment())) { IJavaProject javaProj2 = (IJavaProject) proj.getNature(JavaCore.NATURE_ID); IPath path = p.getLocation() .append(javaProj2.getOutputLocation().lastSegment()); workingDirs.add(path); } } } } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:pt.org.aguiaj.eclipse.OpenAguiaJ.java
License:Open Source License
@Override public void run(IAction action) { IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (editor == null) return;/*from ww w .j ava2s .c o m*/ IJavaProject project = null; IEditorInput input = editor.getEditorInput(); IResource resource = (IResource) input.getAdapter(IResource.class); if (resource != null) { IProject proj = resource.getProject(); try { project = (IJavaProject) proj.getNature(JavaCore.NATURE_ID); } catch (CoreException e) { e.printStackTrace(); } } if (project == null) { try { execute(null); return; } catch (ExecutionException e1) { e1.printStackTrace(); } } try { IPerspectiveDescriptor pers = workbench.getActiveWorkbenchWindow().getActivePage().getPerspective(); if (pers != null) Activator.setPerspective(pers.getId()); String version = Platform.getBundle(AguiaJContribution.AGUIAJ_PLUGIN).getVersion().toString(); workbench.showPerspective(AguiaJContribution.PERSPECTIVE, workbench.getActiveWorkbenchWindow()); workbench.getActiveWorkbenchWindow().getShell() .setText("AguiaJ " + version + " - Inspecting project " + project.getElementName()); if (Activator.getProject() == project) { ReloadClassesCommand reloadCommand = new ReloadClassesCommand(); reloadCommand.execute(null); } else { IPath path = project.getProject().getLocation() .append(project.getOutputLocation().removeFirstSegments(1)); ChangeWorkingDirCommand command = new ChangeWorkingDirCommand(); command.setDirectory(path); command.execute(null); Activator.setProject(project); } IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.showView(AguiaJContribution.CLASSES_VIEW); page.showView(AguiaJContribution.JAVABAR_VIEW); } catch (PartInitException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:repast.simphony.agents.designer.core.AgentBuilderPlugin.java
License:Open Source License
/** * Adds classpath entries to the supported list. * //from www. ja va2 s .c o m * @param projectName * @param pathEntries */ public static void getResolvedClasspath(String projectName, List pathEntries) { IJavaProject javaProject = AgentBuilderPlugin.getJavaProject(projectName); IPath path = null; try { IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; path = null; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { path = getWorkspaceRoot().getLocation() .append(JavaCore.getResolvedClasspathEntry(entry).getPath()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { path = JavaCore.getResolvedClasspathEntry(entry).getPath(); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { path = entry.getPath().makeAbsolute(); if (!path.toFile().getAbsoluteFile().exists()) { IPath location = getWorkspaceRoot().getProject(entry.getPath().segment(0)) .getFile(entry.getPath().removeFirstSegments(1)).getLocation(); if (location != null) { File tmpFile = location.toFile(); if (tmpFile.exists()) path = location; } } } if (path != null && !pathEntries.contains(path)) pathEntries.add(path); if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProject = getWorkspaceProject(entry.getPath()); // recurse into projects if (requiredProject != null) getResolvedClasspath(requiredProject, pathEntries); } } IPath outputPath = javaProject.getOutputLocation(); if (outputPath.segmentCount() == 1) outputPath = javaProject.getResource().getLocation(); else outputPath = javaProject.getProject().getFile(outputPath.removeFirstSegments(1)).getLocation(); if (outputPath != null && !pathEntries.contains(outputPath)) pathEntries.add(outputPath); } catch (JavaModelException e) { AgentBuilderPlugin.log(e); } }