List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:net.sf.j2s.ui.launching.J2SClasspathOptionTab.java
License:Open Source License
public void performApply(ILaunchConfigurationWorkingCopy configuration) { try {/*from w w w . j a va 2s . c om*/ IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null); if ((projectName == null) || (projectName.trim().length() < 1)) { return; } IJavaProject javaProject = javaModel.getJavaProject(projectName); if ((javaProject == null) || !javaProject.exists()) { return; } IProject project = javaProject.getProject(); String prjFolder = project.getLocation().toOSString(); File workingDir = new File(prjFolder); boolean useDefault = true; try { useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); } catch (CoreException e) { //JDIDebugUIPlugin.log(e); } String path = javaProject.getOutputLocation().toString(); int idx = path.indexOf('/', 2); String relativePath = null; if (idx != -1) { relativePath = path.substring(idx + 1); } File j2sFile = new File(workingDir, ".j2s"); String classpath = configuration.getAttribute(IJ2SLauchingConfiguration.J2S_CLASS_PATH, (String) null); String abandonClasspath = configuration.getAttribute(IJ2SLauchingConfiguration.J2S_ABANDON_CLASS_PATH, (String) null); if (relativePath == null) { relativePath = ""; } String propStr = "j2s.output.path=" + relativePath + "\r\nj2s.resources.list=" + classpath + "\r\nj2s.abandoned.resources.list==" + abandonClasspath; InputStream is = new ByteArrayInputStream(propStr.getBytes()); Properties prop = configPage.getUpdatedProperties(is, j2sFile); String resList = prop.getProperty("j2s.resources.list"); if (!resList.equals(classpath)) { configuration.setAttribute(IJ2SLauchingConfiguration.J2S_CLASS_PATH, resList); } resList = prop.getProperty("j2s.abandoned.resources.list"); if (!resList.equals(classpath)) { configuration.setAttribute(IJ2SLauchingConfiguration.J2S_ABANDON_CLASS_PATH, resList); } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:net.sf.j2s.ui.wizards.Java2ScriptProjectWizard.java
License:Open Source License
public boolean performFinish() { boolean finished = super.performFinish(); if (finished) { final IJavaElement newElement = getCreatedElement(); IWorkingSet[] workingSets = fFirstPage.getWorkingSets(); if (workingSets.length > 0) { PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(newElement, workingSets); }/*from ww w . j a v a2 s. co m*/ BasicNewProjectResourceWizard.updatePerspective(fConfigElement); selectAndReveal(fSecondPage.getJavaProject().getProject()); Display.getDefault().asyncExec(new Runnable() { public void run() { IWorkbenchPart activePart = getActivePart(); if (activePart instanceof IPackagesViewPart) { (new ShowInPackageViewAction(activePart.getSite())).run(newElement); } } }); IProgressMonitor monitor = null; IJavaProject jproject = (IJavaProject) getCreatedElement(); IProject project = jproject.getProject(); String prjFolder = project.getLocation().toOSString(); File file = new File(prjFolder, ".j2s"); Properties props = new Properties(); try { String path = jproject.getOutputLocation().toString(); int idx = path.indexOf('/', 2); String relativePath = null; if (idx != -1) { relativePath = path.substring(idx + 1); props.setProperty("j2s.output.path", relativePath); } else { props.setProperty("j2s.output.path", ""); } } catch (JavaModelException e) { e.printStackTrace(); } J2SClasspathModel classpathModel = new J2SClasspathModel(); String[][] allResources = ExternalResources.getAllResources(); String j2sLibPath = null; if (allResources != null && allResources.length != 0 && allResources[0].length != 0) { if ((allResources[0][0]).startsWith("|")) { allResources[0][0] = allResources[0][0].substring(1).replace('\\', '/'); } j2sLibPath = allResources[0][0].substring(0, allResources[0][0].lastIndexOf("/") + 1); } else { j2sLibPath = "../net.sf.j2s.lib/j2slib/"; } IRuntimeClasspathEntry entry = JavaRuntime .newArchiveRuntimeClasspathEntry(j2sLibPath + "/java.runtime.j2x"); if (entry != null) { ((Resource) entry).setAbsolute(true); classpathModel.addResource((Resource) entry); } updateJava2ScriptLibraries(classpathModel, j2sLibPath); StringBuffer buffer = new StringBuffer(); Resource[] resources = classpathModel.getResources(); for (int i = 0; i < resources.length; i++) { Resource res = resources[i]; String resPath = null; resPath = res.toResourceString(); if (res.isAbsolute()) { resPath = FileUtil.toRelativePath(resPath.substring(1), new File(prjFolder).getAbsolutePath()); } if (resPath != null) { if (buffer.length() != 0) { buffer.append(','); } buffer.append(resPath); } } props.setProperty("j2s.resources.list", buffer.toString()); props.setProperty("j2s.abandoned.resources.list", ""); props.setProperty("j2s.compiler.status", "enable"); try { props.store(new FileOutputStream(file), "Java2Script Configuration"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } updateJava2ScriptProject(prjFolder, props.getProperty("j2s.output.path")); try { project.refreshLocal(1, null); } catch (CoreException e) { e.printStackTrace(); } try { Java2ScriptProjectNature pn = new Java2ScriptProjectNature(); pn.setProject(project); pn.configure(); } catch (CoreException e) { e.printStackTrace(); } try { project.build(IncrementalProjectBuilder.CLEAN_BUILD, monitor); } catch (CoreException e) { e.printStackTrace(); } } return finished; }
From source file:net.sf.jasperreports.eclipse.classpath.OutputFolderClassLoader.java
License:Open Source License
private byte[] loadClassData(String className, IJavaProject javaProject) throws Exception { IPath defaultLocationPath = javaProject.getOutputLocation(); IWorkspaceRoot wsRoot = javaProject.getProject().getWorkspace().getRoot(); IFolder folder = wsRoot.getFolder(defaultLocationPath); String prjDefaultLocation = folder.getLocation().toOSString(); byte[] classBytes = loadClassFile(prjDefaultLocation + "/" + className.replaceAll("\\.", "/") + ".class"); if (classBytes == null) { // Iterate over the (possible) output locations of the sourcefolder classpath entries IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (IClasspathEntry e : classpathEntries) { if (e.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath entryOutputLocation = e.getOutputLocation(); if (entryOutputLocation != null) { IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation); classBytes = loadClassFile( entryOutputFolder + "/" + className.replaceAll("\\.", "/") + ".class"); if (classBytes != null) break; }//from w ww . java 2 s . co m } } } return classBytes; }
From source file:net.sourceforge.eclipsejetty.launch.JettyLaunchConfigurationDelegate.java
License:Apache License
private File createTomcatConfigurationFile(ILaunchConfiguration configuration, ContainerVersion version, String catalinaBase, String[] classpath) throws CoreException { AbstractServerConfiguration serverConfiguration = version.createServerConfiguration(); // the file name is the name of the context String contextPath = JettyPluginConstants.getContext(configuration); if (contextPath != null && !contextPath.trim().equals("")) { if (contextPath.trim().equals("/") || contextPath.trim().toLowerCase().equals("/root") || contextPath.trim().toLowerCase().equals("root")) { contextPath = "ROOT"; }/*www . j a v a2 s . co m*/ if (contextPath.startsWith("/")) { contextPath = contextPath.substring(1); } } else { contextPath = "ROOT"; } File file = new File(catalinaBase, "conf/Catalina/localhost/" + contextPath + ".xml"); // if the file exists, rewrite it if (file.exists()) { file.delete(); } // check if the parent dirs exist File parentDirs = file.getParentFile(); if (!parentDirs.exists()) { parentDirs.mkdirs(); } // get absolute path for webapp folder. IJavaProject project = getJavaProject(configuration); String projectname = getResourceUri(project.getResource()); String projectRoot = project.getResource().getLocation().toString(); File webappdir = new File(projectRoot, JettyPluginConstants.getWebAppDir(configuration)); String outputFolder = project.getOutputLocation().makeAbsolute().toString(); String outputDir = null; if (outputFolder.startsWith(projectname)) { outputDir = outputFolder.substring(projectname.length()); } else { outputDir = outputFolder; } String absOutDir = projectRoot + outputDir; serverConfiguration.setDefaultContextPath(JettyPluginConstants.getContext(configuration)); serverConfiguration.setDefaultWar(webappdir.getAbsolutePath()); serverConfiguration.addDefaultClasspath(classpath); serverConfiguration.setOutputFolder(absOutDir); // TODO: Port number, Jndi, Catalina_base and additional features try { serverConfiguration.write(file); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, JettyPlugin.PLUGIN_ID, "Failed to write tomcat context file at " + file.getAbsolutePath())); } return file; }
From source file:net.sourceforge.floggy.eclipse.builder.DefaultBuilder.java
License:Open Source License
/** * DOCUMENT ME!//w w w . j a v a2s . c om * * @param project DOCUMENT ME! * @param monitor DOCUMENT ME! * * @return DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public IProject[] build(IProject project, IProgressMonitor monitor) throws Exception { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); List classpathList = new ArrayList(); ClassPool classPool = new ClassPool(); IClasspathEntry classpathEntry; String pathName; for (int i = 0; i < entries.length; i++) { classpathEntry = JavaCore.getResolvedClasspathEntry(entries[i]); pathName = classpathEntry.getPath().toFile().toString(); if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (!classpathEntry.getPath().toFile().exists()) { IFile pathIFile = project.getWorkspace().getRoot().getFile(classpathEntry.getPath()); pathName = pathIFile.getLocationURI().getPath(); } } classpathList.add(pathName); classPool.appendClassPath(pathName); } if (validateClasspath(project, classPool)) { Weaver weaver = new Weaver(classPool); IPath root = project.getLocation(); File input = root.removeLastSegments(1).append(javaProject.getOutputLocation()).toFile(); IFolder floggyTemp = project.getFolder(".floggy.tmp"); if (!floggyTemp.exists()) { floggyTemp.create(IResource.DERIVED, true, monitor); } IFile configurationFile = project .getFile(project.getPersistentProperty(ConfigurationFileAction.PROPERTY_NAME)); weaver.setOutputFile(floggyTemp.getLocation().toFile()); weaver.setInputFile(input); weaver.setClasspath((String[]) classpathList.toArray(new String[classpathList.size()])); if (!configurationFile.exists()) { weaver.setConfiguration(createWeaverConfiguration(project)); } else { weaver.setConfigurationFile(configurationFile.getLocation().toFile()); } weaver.execute(); IPath path = javaProject.getOutputLocation(); if (path.segmentCount() > 1) { path = path.removeFirstSegments(1); } IFolder outputLocation = project.getFolder(path); floggyTemp.refreshLocal(IResource.DEPTH_INFINITE, monitor); copyFiles(floggyTemp, outputLocation, monitor); outputLocation.refreshLocal(IResource.DEPTH_INFINITE, monitor); cleanFolder(floggyTemp, monitor); } return new IProject[0]; }
From source file:net.sourceforge.floggy.eclipse.builder.MTJBuilder.java
License:Open Source License
/** * Entry point into builder// www . j a va 2 s .co m * * @param project the project to be build * @param monitor the current progress monitor displayed to the user * @return List of any projects which the one being built says it depends on * @throws Exception if an irrecoverable error occurs */ public IProject[] build(IProject project, IProgressMonitor monitor) throws Exception { LOG.debug(project.getName() + " is going to be build using the MTJBuilder"); List classPoolList = new ArrayList(); ClassPool classPool = new ClassPool(); IJavaProject javaProject = JavaCore.create(project); configureClassPool(classPool, classPoolList, javaProject, true); if (validateClasspath(project, classPool)) { Weaver weaver = new Weaver(classPool); IPath root = project.getLocation(); File input = root.removeLastSegments(1).append(javaProject.getOutputLocation()).toFile(); IFile implJar = project.getFile("floggy-persistence-framework-impl.jar"); IFolder floggyTemp = project.getFolder(".floggy.tmp"); if (!floggyTemp.exists()) { floggyTemp.create(IResource.DERIVED, true, monitor); } IFile configurationFile = project .getFile(project.getPersistentProperty(ConfigurationFileAction.PROPERTY_NAME)); weaver.setEmbeddedClassesOutputPool(implJar.getLocation().toFile()); weaver.setOutputFile(floggyTemp.getLocation().toFile()); weaver.setInputFile(input); weaver.setClasspath((String[]) classPoolList.toArray(new String[classPoolList.size()])); if (!configurationFile.exists()) { weaver.setConfiguration(createWeaverConfiguration(project)); } else { weaver.setConfigurationFile(configurationFile.getLocation().toFile()); } // Let the weaving commence weaver.execute(); IPath path = javaProject.getOutputLocation(); if (path.segmentCount() > 1) { path = path.removeFirstSegments(1); } IFolder outputLocation = project.getFolder(path); floggyTemp.refreshLocal(IResource.DEPTH_INFINITE, monitor); copyFiles(floggyTemp, outputLocation, monitor); outputLocation.refreshLocal(IResource.DEPTH_INFINITE, monitor); cleanFolder(floggyTemp, monitor); } return project.getReferencedProjects(); }
From source file:nz.ac.auckland.ptjava.internal.builder.BuildDeltaVisitor.java
License:Open Source License
/** * Visits each resource node in the delta tree, starting at the workspace root. * If the node in the tree is a .ptjava file, invokes {@link PTJavaFileBuilder#invokeCompiler(String, IResource)} * on the file.// ww w .ja v a2 s.co m * * Does not visit the Java output location (default: bin/) if such a location is specified in the Java Project * by {@link IJavaProject#getOutputLocation()}. * */ @Override public boolean visit(IResourceDelta delta) throws CoreException { // get the resource this change represented IResource resource = delta.getResource(); String relPath = resource.getFullPath().toString(); int index = relPath.lastIndexOf('/'); if (index == -1) { return false; } relPath = relPath.substring(0, index); // After removing the last '/', we should be left with a path like: // "/project_name" or "/project_name/bin", depending on whether the User wanted // separate src and bin folders or not. // Test if we have the first, or second case if (relPath.lastIndexOf('/') > 0) { // latter case IJavaProject javaProj = JavaCore.create(resource.getProject()); if (javaProj == null) { return false; } String outputPath = javaProj.getOutputLocation().toString(); // .ptjava files tend to get created in the bin directory when // Java builder is invoked. // we don't want to build anything in the bin directory, or subdirectories if (relPath.equals(outputPath)) { return false; } } // find the absolute file path to the resource // this way, files can be built even if they are not in workspace directory String fullPath = resource.getLocationURI().getPath(); if (fullPath.endsWith(".ptjava")) { // delete the resource markers MarkerManager.getInstance().deletePTJavaMarkers(resource); // invoke the compiler PTJavaFileBuilder.invokeCompiler(fullPath, delta.getResource()); } // return true to visit children as well return true; }
From source file:nz.ac.auckland.ptjava.internal.builder.BuildVisitor.java
License:Open Source License
/** * Visits each resource node in the project resource tree, starting at the workspace root. * If the node in the tree is a .ptjava file, invokes {@link PTJavaFileBuilder#invokeCompiler(String, IResource)} * on the file.//from w w w.ja v a 2 s . c om * * Does not visit the Java output location (default: bin/) if such a location is specified in the Java project * by {@link IJavaProject#getOutputLocation()}. */ @Override public boolean visit(IResource resource) throws CoreException { // build the resource String relPath = resource.getFullPath().toString(); int index = relPath.lastIndexOf('/'); if (index == -1) { return false; } relPath = relPath.substring(0, index); // After removing the last '/', we should be left with a path like: // "/project_name" or "/project_name/bin", depending on whether the User wanted // separate src and bin folders or not. // Test if we have the first, or second case if (relPath.lastIndexOf('/') > 0) { // latter case IJavaProject javaProj = JavaCore.create(resource.getProject()); if (javaProj == null) { return false; } String outputPath = javaProj.getOutputLocation().toString(); // .ptjava files tend to get created in the bin directory when // Java builder is invoked. // we don't want to build anything in the bin directory or subdirectories. if (relPath.equals(outputPath)) { return false; } } // find the absolute file path to the resource // this way, files can be built even if they are not in workspace directory String fullPath = resource.getLocationURI().getPath(); // test if file is a .ptjava file if (fullPath != null && fullPath.endsWith(".ptjava")) { // file is a .ptjava file .: compile it // delete resource markers MarkerManager.getInstance().deletePTJavaMarkers(resource); // compile PTJavaFileBuilder.invokeCompiler(fullPath, resource); } // return true to visit children of the resource return true; }
From source file:org.antlr.eclipse.smapinstaller.SMapInstallerBuilder.java
License:Open Source License
/** * Installs the modified smap into a generated classfile * @param resource/*from w ww . ja v a 2 s . c o m*/ * @throws JavaModelException */ protected void installSmap(final IResource resource) throws JavaModelException { // We only work on smap files -- skip everything else if (!(resource instanceof IFile)) return; IFile smapIFile = (IFile) resource; if (!"smap".equalsIgnoreCase(smapIFile.getFileExtension())) return; IJavaProject javaProject = JavaCore.create(smapIFile.getProject()); // get the name of the corresponding java source file IPath smapPath = smapIFile.getFullPath(); IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (int i = 0, l = classpathEntries.length; i < l; i++) { IClasspathEntry entry = classpathEntries[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; if (!entry.getPath().isPrefixOf(smapPath)) continue; // found the right source container IPath outputLocation = entry.getOutputLocation(); if (outputLocation == null) outputLocation = javaProject.getOutputLocation(); // strip the source dir and .smap suffix String sourceDir = entry.getPath().toString(); String smapName = smapPath.toString(); String javaSourceName = smapName.substring(0, smapName.length() - 5) + ".java"; String className = smapName.substring(sourceDir.length(), smapName.length() - 5) + ".class"; IPath path = outputLocation.append(className); IPath workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation(); IPath classFileLocation = workspaceLoc.append(path); IResource classResource = ResourcesPlugin.getWorkspace().getRoot().findMember(javaSourceName); File classFile = classFileLocation.toFile(); File smapFile = smapIFile.getLocation().toFile(); try { String installSmap = classResource.getPersistentProperty(AntlrBuilder.INSTALL_SMAP); if ("true".equals(installSmap)) SDEInstaller.install(classFile, smapFile); } catch (CoreException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.apache.cactus.eclipse.webapp.internal.WarBuilder.java
License:Apache License
/** * @param theJavaProject the java project for which we want to get the * absolute output path /*from w w w . j av a 2 s . c o m*/ * @return the absolute project output path * @throws JavaModelException if we fail to get the project relative * output location */ private static File getAbsoluteOutputLocation(final IJavaProject theJavaProject) throws JavaModelException { IPath projectPath = theJavaProject.getProject().getLocation(); IPath outputLocation = theJavaProject.getOutputLocation(); IPath classFilesPath = projectPath.append(outputLocation.removeFirstSegments(1)); return classFilesPath.toFile(); }