List of usage examples for org.eclipse.jdt.core IJavaProject getProject
IProject getProject();
IProject
on which this IJavaProject
was created. From source file:com.google.gwt.eclipse.core.launch.LaunchShortcutStrategyTest.java
License:Open Source License
public void testWebAppLaunchShortcutStrategy() throws CoreException, UnsupportedEncodingException { IJavaProject javaProject = getTestProject(); ILaunchShortcutStrategy strategy = new WebAppLaunchShortcutStrategy(); WebAppUtilities.verifyIsWebApp(javaProject.getProject()); IFolder warFolder = WebAppUtilities.getWarSrc(javaProject.getProject()); IResource selection = warFolder.getFile("Hello.html"); String url = strategy.generateUrl(selection, false); assertTrue(url.equals("Hello.html")); // Now we'll add a file in a subdirectory of war. IFolder warSubDir = warFolder.getFolder("subdir"); warSubDir.create(true, true, null);//from www .ja v a 2 s . c o m IFile otherHello = warSubDir.getFile("OtherHello.html"); ResourceUtils.createFile(otherHello.getFullPath(), "(other hello)"); String otherUrl = strategy.generateUrl(otherHello, false); assertTrue(otherUrl.equals("subdir/OtherHello.html")); }
From source file:com.google.gwt.eclipse.core.launch.ModuleClasspathProvider.java
License:Open Source License
@Override public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration config) throws CoreException { IRuntimeClasspathEntry[] unresolvedClasspathEntries = super.computeUnresolvedClasspath(config); IJavaProject proj = JavaRuntime.getJavaProject(config); if (proj == null || !GWTNature.isGWTProject(proj.getProject())) { // Only GWT projects require source folders to be computed return unresolvedClasspathEntries; }/*w w w . ja v a 2 s . c o m*/ /* * Figure out if we are supposed to be relying on the default classpath or not. The default * classpath is the one that is generated for a launch configuration based on the launch * configuration's project's build classpath. * * To determine whether or not to rely on the default classpath, we look at the * ATTR_DEFAULT_CLASSPATH attribute of the launch configuration. This attribute is set whenever * the user makes a change to the launch configuration classpath using the add/remove buttons. * From this point on, Eclipse will respect the user's changes and will not replace their * entries with the classpath that it computes. * * However, users can specify that they want to restore the behavior of having Eclipse compute * the classpath by clicking on the "Restore Default Entries" button. This causes the * ATTR_DEFAULT_ATTRIBUTE to be unset for a launch configuration. */ boolean useDefault = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); if (!useDefault) { return unresolvedClasspathEntries; } /* * Compute the default classpath for the launch configuration. Note that all of the entries for * the default classpath DO NOT appear under the 'default entries' section. This is because we * are going to be adding the GWT-related source paths to the classpath, and we want to give * users the opportunity to tweak them. If we add them to the 'default entries' section, they * will be unable to tweak them. * * You might think that adding the source paths to the non-default section would cause Eclipse * to think that the user actually modified the classpath, thereby causing the * ATTR_DEFAULT_CLASSPATH attribute to be changed. This is not the case; this attribute is only * changed based on UI interaction, so it is safe for us to add entries to the non-default * section programmatically. */ ArrayList<IRuntimeClasspathEntry> defaultRuntimeClasspathEntries = new ArrayList<IRuntimeClasspathEntry>(); defaultRuntimeClasspathEntries.addAll(Arrays.asList(unresolvedClasspathEntries)); /* * Now, record the source folder(s) of each of the transitively required projects. * * Make sure that the source paths come before the default classpath entries so users can * override GWT functionality. They also must appear after any existing bootstrap entries (e.g. * the JRE), since that's the order the JavaClasspathTab will expect them to be in when it goes * to calculate whether or not the configured classpath = default. */ int srcPathsInsertionIndex = findIndexOfFirstUserEntry(defaultRuntimeClasspathEntries); try { defaultRuntimeClasspathEntries.addAll(srcPathsInsertionIndex, GWTProjectUtilities.getGWTSourceFolderPathsFromProjectAndDependencies(proj, GWTJUnitLaunchDelegate.isJUnitLaunchConfig(config.getType()))); } catch (SdkException e) { GWTPluginLog.logError(e); } return defaultRuntimeClasspathEntries .toArray(new IRuntimeClasspathEntry[defaultRuntimeClasspathEntries.size()]); }
From source file:com.google.gwt.eclipse.core.launch.ModuleClasspathProvider.java
License:Open Source License
/** * Ensure that the war out directory is created. This may be a bit agressive. * @param project/* ww w .j a v a 2s. co m*/ * */ private void createWarOutDirectory(IJavaProject project) { try { IPath warOutPath = WebAppProjectProperties.getLastUsedWarOutLocation(project.getProject()); if (warOutPath != null) { warOutPath.toFile().mkdirs(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.google.gwt.eclipse.core.launch.ModuleClasspathProvider.java
License:Open Source License
/** * @param proj// w w w. ja v a 2 s . c o m * @param iProject * @param resolvedEntries */ private void logErrorIfMoreThanGWTSdkOnClassPath(IJavaProject project, IRuntimeClasspathEntry[] resolvedEntries) { MessageConsole messageConsole = MessageConsoleUtilities .getMessageConsoleKeepLog(project.getProject().getName() + "-GWT", null); MessageConsoleStream out = messageConsole.newMessageStream(); String message = "~~~~~> There is more than one jar on the classpath? Recommended removing one: "; int countDupsGwtUser = 0; int countDupsCodeServer = 0; for (int i = 0; i < resolvedEntries.length; i++) { IRuntimeClasspathEntry entry = resolvedEntries[i]; if (entry.getPath().toString().toLowerCase().contains("gwt-") && entry.getType() == IRuntimeClasspathEntry.ARCHIVE) { if (entry.getPath().toString().toLowerCase().contains("gwt-user")) { countDupsGwtUser++; } } } if (countDupsCodeServer > 1 || countDupsGwtUser > 1) { out.println("\n\n More than one gwt jar has been found on the classpath. Clear console after fix."); } for (int i = 0; i < resolvedEntries.length; i++) { IRuntimeClasspathEntry entry = resolvedEntries[i]; if (entry.getPath().toString().toLowerCase().contains("gwt-") && entry.getType() == IRuntimeClasspathEntry.ARCHIVE) { if (countDupsGwtUser > 1 && entry.getPath().toString().toLowerCase().contains("gwt-user")) { String m = message.replace("jar", "gwt-user.jar") + " ::: path=" + entry.getPath(); out.println(m); } } } }
From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeCodeServerLauncherDirArgumentProcessor.java
License:Open Source License
/** * Only update this argument when in GWT SDM mode. *//* w w w . jav a2 s .c o m*/ @Override public void update(ILaunchConfigurationWorkingCopy launchConfig, IJavaProject javaProject, List<String> programArgs, List<String> vmArgs) throws CoreException { // Only GWT projects if (!GWTNature.isGWTProject(javaProject.getProject())) { return; } // Only GWT projects with SDM mode CodeServer main type if (!GwtLaunchConfigurationProcessorUtilities.isSuperDevModeCodeServer(launchConfig)) { return; } // Skip if arg already exists, developer entered or this previously added it. int argIndex = programArgs.indexOf(LAUNCHERDIR_ARG); if (argIndex > -1) { return; } // Path to the output war directory String pathToWarOutDir = null; // 1. First check if the launcherDir is coming from a Server launching this // Override the path with the launcher configuration stored attribute. // This is activated in the GWT WTP plugin. // This is created in the GWT WTP facet and started by WTP server String launcherDir = GWTLaunchConfiguration.getSuperDevModeCodeServerLauncherDir(launchConfig); if (launcherDir != null) { pathToWarOutDir = launcherDir; } // 2. The classic launch configuration will provide the output war, and if not ask for it. // Only try this if the server didn't provide it if (pathToWarOutDir == null) { IPath path = WebAppUtilities.getWarOutLocationOrPrompt(javaProject.getProject()); if (path != null) { pathToWarOutDir = path.toFile().getAbsolutePath(); } } // Not a WTP project or classic launcher config // TODO, should it prompt for one? if (pathToWarOutDir == null || pathToWarOutDir.isEmpty()) { String msg = "SuperDevModeCodeServerLauncherDirArgumentProcessor > update: couldn't determine pathtoWarOutDir."; GWTPluginLog.logWarning(msg); return; } // Then remove previous arg and replace it with launcherDir arg int insertionIndex = LaunchConfigurationProcessorUtilities.removeArgsAndReturnInsertionIndex(programArgs, argIndex, true); // Add the args to the list programArgs.add(insertionIndex, LAUNCHERDIR_ARG); programArgs.add(insertionIndex + 1, pathToWarOutDir); }
From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeCodeServerMainTypeProcessor.java
License:Open Source License
@Override public void update(ILaunchConfigurationWorkingCopy config, IJavaProject javaProject, List<String> programArgs, List<String> vmArgs) throws CoreException { String currentMainTypeName = LaunchConfigurationProcessorUtilities.getMainTypeName(config); String previouslySetMainTypeName = getPreviouslySetMainTypeName(config); if (!StringUtilities.isEmpty(currentMainTypeName) && !currentMainTypeName.equals(previouslySetMainTypeName)) { // Our previously set main type must have been changed by the user, do not // adjust return;/*from w ww . j ava 2 s . c o m*/ } String newMainTypeName = null; IProject project = javaProject.getProject(); if (GWTNature.isGWTProject(project)) { newMainTypeName = MainType.GWT_SDM_MODE.mainTypeName; } if (StringUtilities.isEmpty(newMainTypeName) || newMainTypeName.equals(currentMainTypeName)) { return; } setMainTypeName(config, newMainTypeName); }
From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeCodeServerPortArgumentProcessor.java
License:Open Source License
@Override public void update(ILaunchConfigurationWorkingCopy launchConfig, IJavaProject javaProject, List<String> programArgs, List<String> vmArgs) throws CoreException { // only gwt projects use -codeServerPort if (!GWTNature.isGWTProject(javaProject.getProject())) { return;//from w w w.j a v a2 s . c o m } // Only run this if the entry point is CodeServer. Do not run this with a DevMode entry point. String mainType = GWTLaunchConfigurationWorkingCopy.getMainType(launchConfig); if (mainType != null && !mainType.contains("CodeServer")) { return; } int insertionIndex = LaunchConfigurationProcessorUtilities.removeArgsAndReturnInsertionIndex(programArgs, getArgIndex(programArgs), true); String port = GWTLaunchConfigurationWorkingCopy.getSdmCodeServerPort(launchConfig); if (!validatePort(port)) { port = GWTLaunchAttributes.SDM_CODE_SERVER_PORT.getDefaultValue().toString(); } programArgs.add(insertionIndex, SDM_CODE_SERVER_PORT_ARG); programArgs.add(insertionIndex + 1, port); }
From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeSrcArgumentProcessor.java
License:Open Source License
/** * Only update this argument when in GWT SDM mode. *///from w ww . j a v a 2 s.c o m @Override public void update(ILaunchConfigurationWorkingCopy launchConfig, IJavaProject javaProject, List<String> programArgs, List<String> vmArgs) throws CoreException { // only gwt projects use -src if (!GWTNature.isGWTProject(javaProject.getProject())) { return; } // only gwt projects with SDM mode if (!GwtLaunchConfigurationProcessorUtilities.isSuperDevModeCodeServer(launchConfig)) { return; } int srcArgIndex = getArgIndex(programArgs); // Prefer the existing value, fallback on the precanned one String srcDirs = null; if (srcArgIndex >= 0) { srcDirs = LaunchConfigurationProcessorUtilities.getArgValue(programArgs, srcArgIndex + 1); } // default directories, is retrieved from classpaths if (StringUtilities.isEmpty(srcDirs)) { srcDirs = getSrcDirectories(javaProject); } int insertionIndex = LaunchConfigurationProcessorUtilities.removeArgsAndReturnInsertionIndex(programArgs, srcArgIndex, true); // add the args to the list programArgs.add(insertionIndex, SRC_ARG); programArgs.add(insertionIndex + 1, srcDirs); }
From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeSrcArgumentProcessor.java
License:Open Source License
/** * Get the class path entries that are the source. * * @param javaProject the java project./*w ww .ja v a 2 s . c om*/ * @param entry classpath entry value. * @return the path. */ private String getPathIfDir(IJavaProject javaProject, IClasspathEntry entry) { IPath p = entry.getPath(); String projectName = javaProject.getProject().getName(); String path = null; // src directories don't have an output // cpe source are src,test directories if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && (entry.getOutputLocation() == null || (entry.getOutputLocation() != null && !entry.getOutputLocation().lastSegment().toString().equals("test-classes")))) { String dir = p.toString(); // if the base segment has the project name, // lets remove that so its relative to project if (dir.contains(projectName)) { IPath relative = p.removeFirstSegments(1); path = relative.toString(); } } return path; }
From source file:com.google.gwt.eclipse.core.launch.processors.CodeServerPortArgumentProcessor.java
License:Open Source License
public void update(ILaunchConfigurationWorkingCopy launchConfig, IJavaProject javaProject, List<String> programArgs, List<String> vmArgs) throws CoreException { // only gwt projects use -codeServerPort if (!GWTNature.isGWTProject(javaProject.getProject())) { return;/*from w w w .j a v a 2s . c om*/ } int index = getArgIndex(programArgs); String port = GWTLaunchConfigurationWorkingCopy.getCodeServerPort(launchConfig); boolean auto = GWTLaunchConfigurationWorkingCopy.getCodeServerPortAuto(launchConfig); if (auto || !validatePort(port)) { port = "auto"; } if (index < 0) { programArgs.add(0, CODE_SERVER_PORT_ARG); programArgs.add(1, port); } else { if (index == programArgs.size() - 1) { programArgs.add(port); } else { String argValue = programArgs.get(index + 1); if (validatePort(argValue)) { programArgs.set(index + 1, port); } else { programArgs.add(index + 1, port); } } } }