List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.google.gdt.eclipse.core.properties.ui.BuildpathJarSelectionDialog.java
License:Open Source License
/** * Returns the absolute file system paths of all JAR files on the project's * build classpath, which are not part of a classpath container. *//*from ww w. j a v a2s . com*/ private List<IPath> getJarsOnBuildPath() { List<IPath> jars = new ArrayList<IPath>(); try { IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath(); for (IClasspathEntry rawClasspath : rawClasspaths) { rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath); if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath jarPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath()); jars.add(jarPath); } } } catch (JavaModelException e) { CorePluginLog.logError(e); } return jars; }
From source file:com.google.gdt.eclipse.core.sdk.ClasspathContainerUpdateJob.java
License:Open Source License
@Override protected IStatus run(IProgressMonitor jobMonitor) { try {/*from ww w . j a v a 2s .c om*/ IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor runnableMonitor) throws CoreException { IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()) .getJavaProjects(); runnableMonitor.beginTask(LaunchingMessages.LaunchingPlugin_0, projects.length + 1); rebindContainers(runnableMonitor, projects); runnableMonitor.done(); } /** * Rebind all of the classpath containers whose comparison ID matches * the expected ID. */ private void rebindContainers(IProgressMonitor runnableMonitor, IJavaProject[] projects) throws CoreException { for (IJavaProject project : projects) { // Update the progress monitor runnableMonitor.worked(1); IClasspathEntry[] rawClasspathEntries = project.getRawClasspath(); for (IClasspathEntry rawClasspathEntry : rawClasspathEntries) { if (rawClasspathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { continue; } IPath path = rawClasspathEntry.getPath(); if (path == null || path.segmentCount() == 0) { continue; } Object actualComparisonId = classpathContainerInitializer.getComparisonID(path, project); if (!actualComparisonId.equals(expectedComparisonId)) { continue; } classpathContainerInitializer.initialize(path, project); } } } }; JavaCore.run(runnable, null, jobMonitor); return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); } }
From source file:com.google.gdt.eclipse.core.sdk.SdkClasspathContainer.java
License:Open Source License
/** * Returns <code>true</code> if the classpath entry is an * {@link IClasspathEntry#CPE_CONTAINER} and it has the specified container * ID.// w ww.ja v a2 s . c o m * * @param containerId * @param classpathEntry * @return whether the classpathEntry is a container and has the containerId */ public static boolean isContainerClasspathEntry(String containerId, IClasspathEntry classpathEntry) { if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { return false; } return isContainerPath(containerId, classpathEntry.getPath()); }
From source file:com.google.gdt.eclipse.core.ui.ProjectSdkSelectionBlock.java
License:Open Source License
private T findRegisteredSdk(T projectBoundSdk) { // First, see if we're dealing with a classpath container try {//from w w w .j a va2s . c o m IClasspathEntry entry = ClasspathUtilities.findClasspathEntryContainer(javaProject.getRawClasspath(), doGetContainerId()); if (entry != null) { T containerSdk = doGetSdkManager().findSdkForPath(entry.getPath()); if (containerSdk != null) { return containerSdk; } } } catch (CoreException ce) { CorePluginLog.logError(ce); } // If we're here, it means that we're not dealing with a project that has // a classpath container. Let's see if we can convert the project-bound // SDK into an actual registered SDK. if (projectBoundSdk != null) { return SdkUtils.findSdkForInstallationPath(doGetSdkManager().getSdks(), projectBoundSdk.getInstallationPath()); } return null; }
From source file:com.google.gdt.eclipse.core.ui.ProjectSdkSelectionBlock.java
License:Open Source License
/** * Returns true if the given project SDK is actually the default SDK for the * workspace AND the project has a classpath container entry for the given SDK * that indicates that the workspace default should actually be used (i.e. no * trailing segments).// ww w . j av a 2 s. c o m * * Also returns true if the project SDK is the default SDK for the workspace * and the project does not have a classpath container entry for the SDK. * * @param projectSdk * @return */ private boolean isProjectUsingDefaultSdk(T projectSdk) { if (!isDefaultSdk(projectSdk)) { return false; } try { IClasspathEntry entry = ClasspathUtilities.findClasspathEntryContainer(javaProject.getRawClasspath(), doGetContainerId()); if (entry != null) { if (SdkClasspathContainer.isDefaultContainerPath(doGetContainerId(), entry.getPath())) { return true; } } } catch (CoreException ce) { CorePluginLog.logError(ce); } return false; }
From source file:com.google.gdt.eclipse.core.validators.WebAppProjectValidator.java
License:Open Source License
private boolean validateBuildClasspath(IJavaProject javaProject) throws CoreException { IPath webInfLibFolderLocation = null; IFolder webInfLibFolder = WebAppUtilities.getWebInfOut(getProject()).getFolder("lib"); if (webInfLibFolder.exists()) { webInfLibFolderLocation = webInfLibFolder.getLocation(); }/*from ww w .j a va 2 s . com*/ IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath(); boolean isOk = true; List<IPath> excludedJars = WebAppProjectProperties.getJarsExcludedFromWebInfLib(javaProject.getProject()); for (IClasspathEntry rawClasspath : rawClasspaths) { rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath); if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath()); if (excludedJars.contains(entryPath)) { continue; } if (webInfLibFolderLocation == null || !webInfLibFolderLocation.isPrefixOf(entryPath)) { MarkerUtilities.createQuickFixMarker(PROBLEM_MARKER_ID, ProjectStructureOrSdkProblemType.JAR_OUTSIDE_WEBINF_LIB, entryPath.toPortableString(), javaProject.getProject(), entryPath.toOSString()); isOk = false; } } } return isOk; }
From source file:com.google.gdt.eclipse.designer.core.model.widgets.ClassLoaderTest.java
License:Open Source License
/** * We should make sure that we support parsing for Maven projects. *///w ww. ja v a2 s. co m @DisposeProjectAfter public void test_gwtInMavenStructure() throws Exception { // remove existing GWT jars from classpath ProjectUtils.removeClasspathEntries(m_javaProject, new Predicate<IClasspathEntry>() { @Override public boolean apply(IClasspathEntry entry) { return entry.getPath().toPortableString().contains("gwt-"); } }); // prepare Maven-like structure File userFile; File devFile; { String testLocation = Activator.getDefault().getStateLocation().toPortableString(); File gwtDirectory = new File(testLocation + "/SDK from Maven"); // prepare locations userFile = new File(gwtDirectory + "/gwt/gwt-user/2.2.0/gwt-user-2.2.0.jar"); devFile = new File(gwtDirectory + "/gwt/gwt-dev/2.2.0/gwt-dev-2.2.0.jar"); FileUtils.forceMkdir(userFile.getParentFile()); FileUtils.forceMkdir(devFile.getParentFile()); // copy jars String sdkLocation = getGWTLocation_forProject(); FileUtils.copyFile(new File(sdkLocation + "/gwt-user.jar"), userFile, false); FileUtils.copyFile(new File(sdkLocation + "/gwt-dev.jar"), devFile, false); // use this gwt-user.jar ProjectUtils.addExternalJar(m_javaProject, userFile.getAbsolutePath(), null); m_project.refreshLocal(IResource.DEPTH_INFINITE, null); } // try parse try { parseJavaInfo("// filler filler filler filler filler", "public class Test extends FlowPanel {", " public Test() {", " }", "}"); } finally { makeGwtJarEmpty(userFile); makeGwtJarEmpty(devFile); } }
From source file:com.google.gdt.eclipse.designer.core.model.widgets.ClassLoaderTest.java
License:Open Source License
/** * There was regression during 2.3.0 release. *//* w w w. j a v a2 s .co m*/ @DisposeProjectAfter public void test_gwtInDirectoryWithSpace() throws Exception { // remove existing GWT jars from classpath ProjectUtils.removeClasspathEntries(m_javaProject, new Predicate<IClasspathEntry>() { @Override public boolean apply(IClasspathEntry entry) { return entry.getPath().toPortableString().contains("gwt-"); } }); // use GWT jars from directory with spaces File gwtDirectory; { String testLocation = Activator.getDefault().getStateLocation().toPortableString(); gwtDirectory = new File(testLocation + "/SDK with spaces"); // copy jars String sdkLocation = getGWTLocation_forProject(); FileUtils.copyFileToDirectory(new File(sdkLocation + "/gwt-user.jar"), gwtDirectory); FileUtils.copyFileToDirectory(new File(sdkLocation + "/gwt-dev.jar"), gwtDirectory); // add jars into classpath m_testProject.addExternalJars(gwtDirectory.getAbsolutePath()); } // try parse try { parseJavaInfo("// filler filler filler filler filler", "public class Test extends FlowPanel {", " public Test() {", " }", "}"); } finally { makeGwtJarsEmpty(gwtDirectory); } }
From source file:com.google.gdt.eclipse.designer.core.model.widgets.ClassLoaderTest.java
License:Open Source License
/** * We can not find "gwt-dev.jar" relative to "gwt-user.jar", but "gwt-dev.jar" is in project * classpath. So, we can just use it./* w w w . j a va 2s . c o m*/ */ @DisposeProjectAfter public void test_unknownStructure_gwtDevInClasspath() throws Exception { // remove existing GWT jars from classpath ProjectUtils.removeClasspathEntries(m_javaProject, new Predicate<IClasspathEntry>() { @Override public boolean apply(IClasspathEntry entry) { return entry.getPath().toPortableString().contains("gwt-"); } }); // prepare non-standard structure File userFile; File devFile; { String testLocation = Activator.getDefault().getStateLocation().toPortableString(); File gwtDirectory = new File(testLocation + "/SDK unknown structure"); // prepare locations userFile = new File(gwtDirectory + "/gwt/gwt-user/gwt-user.jar"); devFile = new File(gwtDirectory + "/gwt/gwt-dev-2.3.0.jar"); FileUtils.forceMkdir(userFile.getParentFile()); FileUtils.forceMkdir(devFile.getParentFile()); // copy jars String sdkLocation = getGWTLocation_forProject(); FileUtils.copyFile(new File(sdkLocation + "/gwt-user.jar"), userFile, false); FileUtils.copyFile(new File(sdkLocation + "/gwt-dev.jar"), devFile, false); // use these gwt-user.jar and gwt-dev.jar ProjectUtils.addExternalJar(m_javaProject, userFile.getAbsolutePath(), null); ProjectUtils.addExternalJar(m_javaProject, devFile.getAbsolutePath(), null); m_project.refreshLocal(IResource.DEPTH_INFINITE, null); } // try parse try { parseJavaInfo("// filler filler filler filler filler", "public class Test extends FlowPanel {", " public Test() {", " }", "}"); } finally { makeGwtJarEmpty(userFile); makeGwtJarEmpty(devFile); } }
From source file:com.google.gdt.eclipse.designer.gxt.model.widgets.ComponentTest.java
License:Open Source License
/** * Some users try to use old version of GXT, but our descriptions are for GXT 2.0.1 (we are not * subscribers, so don't have access to higher versions). We should check version and fail with * good message./*w ww.ja v a 2 s .c om*/ * <p> * http://fogbugz.instantiations.com/fogbugz/default.php?43669 */ @DisposeProjectAfter public void test_oldVersion() throws Exception { dontUseSharedGWTState(); // replace GXT jar, use old version { IClasspathEntry[] entries = m_javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; String path = entry.getPath().toString(); if (path.contains("gxt") && path.endsWith(".jar")) { entries = (IClasspathEntry[]) ArrayUtils.remove(entries, i); break; } } m_javaProject.setRawClasspath(entries, null); waitForAutoBuild(); // add gxt.jar for version 1.2.4 m_testProject.addExternalJar(ExtGwtTests.GXT_LOCATION_OLD + "/gxt.jar"); } // try to parse, failure expected try { parseJavaInfo("public class Test implements EntryPoint {", " public void onModuleLoad() {", " RootPanel rootPanel = RootPanel.get();", " {", " Button button = new Button();", " rootPanel.add(button);", " }", " }", "}"); fail(); } catch (Throwable e) { DesignerException de = DesignerExceptionUtils.getDesignerException(e); assertEquals(de.getCode(), IExceptionConstants.INCORRECT_VERSION); assertTrue(DesignerExceptionUtils.isWarning(e)); } }