List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:com.google.gdt.eclipse.core.validators.WebAppProjectValidator.java
License:Open Source License
private boolean validateOutputDirectory(IJavaProject javaProject) throws CoreException { IPath expectedOutputDir = WebAppUtilities.getWebInfOut(getProject()).getFolder("classes").getFullPath(); if (!javaProject.getOutputLocation().equals(expectedOutputDir)) { MarkerUtilities.createQuickFixMarker(PROBLEM_MARKER_ID, ProjectStructureOrSdkProblemType.BUILD_OUTPUT_DIR_NOT_WEBINF_CLASSES, null, getProject(), expectedOutputDir.toString()); return false; }/*from w ww. java2s .c o m*/ return true; }
From source file:com.google.gdt.eclipse.core.WebAppUtilities.java
License:Open Source License
/** * Returns the project default output location * * @param project/* w w w . j a v a 2 s. co m*/ * @return The absolute path to the resource, check with {@link IResource#exists()}, can be null * @throws JavaModelException if unable to find the output location from the project */ public static IPath getOutputFolderPath(IJavaProject project) throws JavaModelException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFolder outputLoc = workspaceRoot.getFolder(project.getOutputLocation()); return outputLoc.getLocation(); }
From source file:com.google.gdt.eclipse.core.WebAppUtilities.java
License:Open Source License
/** * Sets the project's default output directory to the WAR output directory's * WEB-INF/classes folder. If the WAR output directory does not have a WEB-INF * directory, this method returns without doing anything. * * @throws CoreException if there's a problem setting the output directory *///from w w w. j a va 2 s .c o m public static void setOutputLocationToWebInfClasses(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { IProject project = javaProject.getProject(); IFolder webInfOut = getWebInfOut(project); if (!webInfOut.exists()) { // If the project has no output <WAR>/WEB-INF directory, don't touch the // output location return; } IPath oldOutputPath = javaProject.getOutputLocation(); IPath outputPath = webInfOut.getFullPath().append("classes"); if (!outputPath.equals(oldOutputPath)) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); // Remove old output location and contents IFolder oldOutputFolder = workspaceRoot.getFolder(oldOutputPath); if (oldOutputFolder.exists()) { try { removeOldClassfiles(oldOutputFolder); } catch (Exception e) { CorePluginLog.logError(e); } } // Create the new output location if necessary IFolder outputFolder = workspaceRoot.getFolder(outputPath); if (!outputFolder.exists()) { // TODO: Could move recreate this in a utilities class CoreUtility.createDerivedFolder(outputFolder, true, true, null); } javaProject.setOutputLocation(outputPath, monitor); } }
From source file:com.google.gdt.eclipse.designer.actions.deploy.DeployModuleAction.java
License:Open Source License
/** * Returns ANT code for creating jar's for given project itself, coping its jar's from classpath * and calls itself for required projects. *///from w w w. j a va 2s. c o m private static String prepareJars(IProject project, String targetModulePath, boolean addRuntimeJars) throws Exception { String script = ""; // IJavaProject javaProject = JavaCore.create(project); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); // add <jar> task for creating jar from project source and output folders { List<String> sourceLocations = Lists.newArrayList(); List<String> binaryLocations = Lists.newArrayList(); for (IPackageFragmentRoot packageFragmentRoot : roots) { if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { // add source location sourceLocations.add(packageFragmentRoot.getResource().getLocation().toPortableString()); // add output location { // prepare output location IPath location; { IClasspathEntry cpEntry = packageFragmentRoot.getRawClasspathEntry(); location = cpEntry.getOutputLocation(); if (location == null) { location = javaProject.getOutputLocation(); } } // add absolute location { // remove first segment (project) location = location.removeFirstSegments(1); // prepare absolute location IPath absoluteLocation = project.getLocation().append(location); binaryLocations.add(absoluteLocation.toPortableString()); } } } } // script += "\t\t<!--=== " + project.getName() + " ===-->\n"; script += "\t\t<jar destfile='" + targetModulePath + "/WEB-INF/lib/" + project.getName() + ".jar'>\n"; script += prepareFileSets(sourceLocations, "**"); script += prepareFileSets(binaryLocations, "**/*.class"); script += "\t\t</jar>\n"; } // add <copy> task for coping required runtime jar's if (addRuntimeJars) { String jars = ""; IRuntimeClasspathEntry[] classpathEntries = JavaRuntime.computeUnresolvedRuntimeClasspath(javaProject); for (int entryIndex = 0; entryIndex < classpathEntries.length; entryIndex++) { IRuntimeClasspathEntry entry = classpathEntries[entryIndex]; IRuntimeClasspathEntry[] resolvedEntries = JavaRuntime.resolveRuntimeClasspathEntry(entry, javaProject); for (int resolvedEntryIndex = 0; resolvedEntryIndex < resolvedEntries.length; resolvedEntryIndex++) { IRuntimeClasspathEntry resolvedEntry = resolvedEntries[resolvedEntryIndex]; if (resolvedEntry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES && resolvedEntry.getType() == IRuntimeClasspathEntry.ARCHIVE) { String location = resolvedEntry.getLocation(); // exclude gwt-user.jar, it is in classpath, but it has Servlet class, so can not be in application if (location.endsWith("gwt-user.jar")) { continue; } // add jar file in fileset jars += "\t\t\t<fileset file=\"" + location + "\"/>\n"; } } } // if (jars.length() != 0) { script += "\t\t<copy todir='" + targetModulePath + "/WEB-INF/lib'>\n"; script += jars; script += "\t\t</copy>\n"; } } // add required projects { IProject[] referencedProjects = project.getReferencedProjects(); for (int i = 0; i < referencedProjects.length; i++) { IProject referencedProject = referencedProjects[i]; script += prepareJars(referencedProject, targetModulePath, false); } } // return script; }
From source file:com.google.gdt.eclipse.designer.wizards.ui.JUnitWizardPage.java
License:Open Source License
private IPackageFragmentRoot handleTestSourceFolder(IJavaProject javaProject) throws Exception { String testSourceFolderName = com.google.gdt.eclipse.designer.Activator.getStore() .getString(Constants.P_GWT_TESTS_SOURCE_FOLDER); IFolder testSourceFolder = javaProject.getProject().getFolder(testSourceFolderName); IPackageFragmentRoot testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); // check create if (!testSourceFolder.exists() || testSourceFragmentRoot == null || !testSourceFragmentRoot.exists()) { // create folder if (!testSourceFolder.exists()) { testSourceFolder.create(true, false, null); }//from ww w .j a v a2 s .c o m IClasspathEntry[] classpath = javaProject.getRawClasspath(); // find last source entry int insertIndex = -1; for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { insertIndex = i + 1; } } // insert new source to entries IClasspathEntry testSourceEntry = JavaCore.newSourceEntry(testSourceFolder.getFullPath()); if (insertIndex == -1) { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, testSourceEntry); } else { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, insertIndex, testSourceEntry); } // modify classpath javaProject.setRawClasspath(classpath, javaProject.getOutputLocation(), null); testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); } // setPackageFragmentRoot(testSourceFragmentRoot, true); return testSourceFragmentRoot; }
From source file:com.google.gwt.eclipse.core.compile.GWTCompileRunnerTest.java
License:Open Source License
/** * Gets a File pointing to the output of the given Java project. *//*from www . j a v a 2s. c o m*/ private static File getOutputOfProject(IJavaProject javaProject) throws CoreException { return ResourceUtils.resolveToAbsoluteFileSystemPath(javaProject.getOutputLocation()).toFile(); }
From source file:com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.java
License:Open Source License
private IStatus packageChanged() { String packName = modulePackageField.getText(); IStatus validatePackageStatus = Util.validatePackageName(packName); if (validatePackageStatus.getSeverity() == IStatus.ERROR) { return validatePackageStatus; }//ww w.j a v a 2s . c o m if (packName.length() == 0) { modulePackageField.setStatus(NewWizardMessages.NewTypeWizardPage_default); } else { modulePackageField.setStatus(""); } IJavaProject project = getJavaProject(); IPackageFragmentRoot root = getPackageFragmentRoot(); if (project != null && root != 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)) { return Util .newErrorStatus(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); } } } catch (JavaModelException e) { // Not a critical exception at this juncture; we'll just log it // and move on. GWTPluginLog.logError(e); } } } return validatePackageStatus; }
From source file:com.google.inject.tools.ideplugin.eclipse.EclipseJavaProject.java
License:Apache License
private String getProjectOutputLocation(IJavaProject project) throws JavaModelException { IResource resource = project.getResource(); String resourceLocation = resource.getLocation().toOSString(); String projectLocation = project.getOutputLocation().makeRelative().toOSString(); return projectLocation.replaceFirst(project.getProject().getName(), resourceLocation); }
From source file:com.google.test.metric.eclipse.internal.core.TestabilityLauncher.java
License:Apache License
public String[] getClassPaths(IJavaProject javaProject, String projectLocation) throws JavaModelException { IClasspathEntry[] classPathEntries = javaProject.getRawClasspath(); String[] classPaths = new String[classPathEntries.length + 1]; for (int i = 0; i < classPathEntries.length; i++) { IClasspathEntry classPathEntry = classPathEntries[i]; String classPathString = null; IPath outputPath = classPathEntry.getOutputLocation(); if (outputPath != null) { classPathString = projectLocation + outputPath.toOSString(); } else {/*from ww w .j a va2 s. c o m*/ IPath classPath = classPathEntry.getPath(); classPathString = classPath.toOSString(); if (!classPathString.startsWith(System.getProperty("file.separator"))) { classPathString = System.getProperty("file.separator") + classPathString; } classPathString = projectLocation + classPathString; } classPathString = classPathString.replace("\\", "/"); classPaths[i] = classPathString; } String defaultOutputPath = javaProject.getOutputLocation().toOSString(); defaultOutputPath = defaultOutputPath.replace("\\", "/"); classPaths[classPathEntries.length] = projectLocation + defaultOutputPath; return classPaths; }
From source file:com.gwtplatform.plugin.wizard.NewActionWizardPage.java
License:Apache License
private IStatus actionHandlerChanged() { StatusInfo status = new StatusInfo(); if (actionHandlerPackage.getText().isEmpty()) { status.setError("You must select the ActionHandler's package"); return status; }/*from w w w. j av a2 s. c o m*/ IPackageFragmentRoot root = getPackageFragmentRoot(); IJavaProject project = root.getJavaProject(); IPackageFragment pack = root.getPackageFragment(actionHandlerPackage.getText()); if (!pack.getElementName().isEmpty()) { IStatus val = JavaConventionsUtil.validatePackageName(pack.getElementName(), 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 (!pack.getElementName().contains(".server")) { status.setError("ActionHandler's package must be in the server package"); return status; } if (project != null) { if (project.exists() && !pack.getElementName().isEmpty()) { 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(pack.getElementName().replace('.', '/')); if (outputPath.isPrefixOf(packagePath)) { status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation); return status; } } } catch (JavaModelException e) { JavaPlugin.log(e); // let pass } } } else { status.setError(""); } return status; }