Example usage for org.eclipse.jdt.core IJavaProject getProject

List of usage examples for org.eclipse.jdt.core IJavaProject getProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getProject.

Prototype

IProject getProject();

Source Link

Document

Returns the IProject on which this IJavaProject was created.

Usage

From source file:com.google.gdt.eclipse.suite.launch.processors.WarArgumentProcessor.java

License:Open Source License

@Override
public void update(ILaunchConfigurationWorkingCopy launchConfig, IJavaProject javaProject,
        List<String> programArgs, List<String> vmArgs) throws CoreException {

    // First, try to get a war argument from the extensions, then try everything
    // else./*from   w w  w .j  a va 2  s  .c  o m*/
    if (isWarArgsFromExtensions(launchConfig, javaProject, programArgs)) {
        launchConfig.setAttribute(ATTR_IS_WAR_FROM_PROJECT_PROPERTIES, false);
    } else {
        if (warDirFromLaunchConfigCreation == null) {
            // Check the scenarios where this processor should do nothing. If a WAR
            // dir is given from launch config creation, we set it regardless of
            // whether we would normally do nothing.
            if (!doesMainTypeTakeWarArgument(launchConfig)) {
                removeVerifiedWarArgAndDir(programArgs, javaProject);
                return;
            }

            if (!WebAppUtilities.isWebApp(javaProject.getProject())) {
                return;
            }

            if (!WebAppUtilities.hasManagedWarOut(javaProject.getProject())) {
                // We are not managing the runtime WAR
                return;
            }
        }

        WarParser info = WarParser.parse(programArgs, javaProject);
        String warFromProjProps = LaunchConfigurationProcessorUtilities.getWarDirectory(javaProject);
        // Did we use the WAR from the project properties when we last ran this?
        boolean wasWarFromProjProps = isWarFromProjectProperties(launchConfig);
        /*
         * If both dirs are the same, perfect, we'll record that it is from project properties. Otherwise, if it is a
         * manual user update, then we say it is not from project properties. Finally, if we took it from the project
         * properties last time, or if the current last-arg-based WAR dir is invalid then we say it is from project
         * properties.
         */
        boolean isWarFromProjProps = JavaUtilities.equalsWithNullCheck(warFromProjProps, info.unverifiedWarDir);
        if (!isWarFromProjProps && !isUserUpdate) {
            isWarFromProjProps = wasWarFromProjProps || (!info.isSpecifiedWithWarArg && !info.isWarDirValid);
        }
        String newWarDir;
        if (warDirFromLaunchConfigCreation != null) {
            newWarDir = warDirFromLaunchConfigCreation;
        } else {
            newWarDir = isWarFromProjProps ? warFromProjProps : info.unverifiedWarDir;
        }

        if (StringUtilities.isEmpty(newWarDir)) {
            // A WAR dir is required but we do not have one, leave untouched
            return;
        }

        if (GWTNature.isGWTProject(javaProject.getProject())) {
            // Ensure there is a -war arg and the WAR dir
            if (!info.isSpecifiedWithWarArg) {
                // Remove the old style, add the new "-war" and value
                removeVerifiedWarArgAndDir(programArgs, javaProject);
                programArgs.add(0, ARG_WAR);
                programArgs.add(1, newWarDir);

            } else {
                // It is specified with the "-war", so just update the value
                programArgs.remove(info.unverifiedWarDirIndex);
                programArgs.add(info.unverifiedWarDirIndex, newWarDir);
            }

        }

        // TODO ?
        // else if (GaeNature.isGaeProject(javaProject.getProject())) {
        // // Ensure there is a valid WAR dir without "-war" arg
        // if (info.isSpecifiedWithWarArg) {
        // // Remove the -war and WAR dir
        // removeVerifiedWarArgAndDir(programArgs, javaProject);
        // // Add the last arg WAR dir
        // programArgs.add(newWarDir);
        //
        // } else {
        // if (info.unverifiedWarDirIndex >= 0) {
        // // Remove the existing WAR dir
        // programArgs.remove(info.unverifiedWarDirIndex);
        // }
        // // Add the last arg WAR dir
        // programArgs.add(newWarDir);
        // }
        // }

        launchConfig.setAttribute(ATTR_IS_WAR_FROM_PROJECT_PROPERTIES, isWarFromProjProps);
    }
}

From source file:com.google.gdt.eclipse.suite.launch.SpeedTracerLaunchDelegate.java

License:Open Source License

@Override
public boolean buildForLaunch(ILaunchConfiguration config, String mode, IProgressMonitor originalMonitor)
        throws CoreException, OperationCanceledException {

    boolean performGwtCompile = LaunchConfigurationAttributeUtilities.getBoolean(config,
            SpeedTracerLaunchConfiguration.Attribute.PERFORM_GWT_COMPILE);
    if (!performGwtCompile) {
        return super.buildForLaunch(config, mode, originalMonitor);
    }// w  w  w  .  j  a va  2s . co m

    SubMonitor subMonitor = SubMonitor.convert(originalMonitor);
    try {
        IJavaProject javaProject = getJavaProject(config);
        if (javaProject == null) {
            abortLaunch("The project is not a Java project.");
        }

        IProject project = javaProject.getProject();

        IPath warOutLocation = null;

        List<String> args = LaunchConfigurationProcessorUtilities.parseProgramArgs(config);
        WarParser parser = WarArgumentProcessor.WarParser.parse(args, javaProject);
        if (parser.isWarDirValid) {
            warOutLocation = new Path(parser.resolvedUnverifiedWarDir);
        }

        if (warOutLocation == null) {
            warOutLocation = WebAppUtilities.getWarOutLocationOrPrompt(project);

            if (warOutLocation == null) {
                throw new OperationCanceledException("Speed Tracer launch canceled by the user");
            }

            // TODO: Copied from WebAppLaunchDelegate. We need to unify these two.
            WarArgumentProcessor warArgProcessor = new WarArgumentProcessor();
            warArgProcessor.setWarDirFromLaunchConfigCreation(warOutLocation.toOSString());

            ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
            LaunchConfigurationProcessorUtilities.updateViaProcessor(warArgProcessor, wc);
            wc.doSave();
        }

        boolean needsGenFilesOrSymbolManifest = needsGenFiles(warOutLocation)
                || needsSymbolManifest(warOutLocation);
        long curStamp = ProjectChangeTimestampTracker.getProjectTimestamp(project);
        if (curStamp == ProjectChangeTimestampTracker.getTimestampFromKey(project,
                PREVIOUS_ST_BUILD_PROJECT_CHANGE_STAMP_KEY) && !needsGenFilesOrSymbolManifest) {
            // No source change, do not re-build
            printToCompilationConsole(project,
                    "Skipping GWT compilation since no relevant changes have occurred since the last Speed Tracer session.");
            return super.buildForLaunch(config, mode, originalMonitor);
        }

        if (needsGenFilesOrSymbolManifest) {
            printToCompilationConsole(project,
                    "Recompiling because generated files or symbol manifests for Speed Tracer are missing.");
        }

        File extraDir = createTempExtraDir();

        try {
            subMonitor.setTaskName("Performing GWT compile");
            List<String> modules = GWTLaunchConfiguration.getEntryPointModules(config);
            performGwtCompile(project, extraDir, modules, warOutLocation, subMonitor.newChild(70));
        } catch (OperationCanceledException e) {
            abortLaunchBecauseUserCancellation();
        } catch (Throwable e) {
            GdtPlugin.getLogger().logError(e, "Could not perform GWT compile");
            abortLaunch("Could not perform GWT compile, see logs for details.");
        }

        if (originalMonitor.isCanceled()) {
            abortLaunchBecauseUserCancellation();
        }

        try {
            // Generate the symbol manifest AFTER the compile, since the compile
            // wipes away ST artifacts
            subMonitor.setTaskName("Generating Speed Tracer symbol manifest");
            generateSymbolManifest(project, extraDir, warOutLocation);
        } catch (IOException e) {
            abortLaunch("Could not generate the symbol manifest file required by Speed Tracer.");
        }

        if (originalMonitor.isCanceled()) {
            abortLaunchBecauseUserCancellation();
        }

        extraDir.delete();

        /*
         * wtp publish
         */
        try {
            WebAppLaunchDelegate.maybePublishModulesToWarDirectory(config, subMonitor, javaProject, true);
        } catch (IOException e) {
            GdtPlugin.getLogger().logError(e, "Could not perform a WTP publish.");
        }

        // Build was successful, mark this last successful build
        project.setPersistentProperty(PREVIOUS_ST_BUILD_PROJECT_CHANGE_STAMP_KEY, String.valueOf(curStamp));

        final int amountOfWorkForSuperBuildForLaunch = 30;
        subMonitor.setWorkRemaining(amountOfWorkForSuperBuildForLaunch);
        return super.buildForLaunch(config, mode, subMonitor.newChild(amountOfWorkForSuperBuildForLaunch));

    } finally {
        if (originalMonitor != null) {
            originalMonitor.done();
        }
    }
}

From source file:com.google.gdt.eclipse.suite.launch.ui.GaeSettingsTab.java

License:Open Source License

private void updateFromProjectSettings() {
    appIdLabel.setText(NOT_SET);//from w  w  w.  j  ava  2 s . c  o  m
    appVersionLabel.setText(NOT_SET);
    setMessage(null);

    IJavaProject javaProject = getJavaProject();
    GaeProject gaeProject = javaProject != null ? GaeProject.create(javaProject.getProject()) : null;

    SWTUtilities.setEnabledRecursive(composite, gaeProject != null);

    if (gaeProject != null) {
        String appid = gaeProject.getAppId();
        String version = gaeProject.getAppVersion();

        if (appid != null && appid.length() > 0) {
            appIdLabel.setText(appid);
        }
        if (version != null && version.length() > 0) {
            appVersionLabel.setText(version);
        }
    } else {
        setMessage(
                "App Engine is not enabled for this project. You can enable it in the project's properties.");
    }
    updateLaunchConfigurationDialog();
}

From source file:com.google.gdt.eclipse.suite.launch.ui.tabs.WebAppServerTab.java

License:Open Source License

@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
    setErrorMessage(null);//ww w. j a  va  2s  .c o m
    setMessage(null);

    if (!super.isValid(launchConfig)) {
        return false;
    }

    IProject project;
    try {
        IJavaProject javaProject = JavaRuntime.getJavaProject(launchConfig);
        if (javaProject == null) {
            return false;
        }

        project = javaProject.getProject();
    } catch (CoreException ce) {
        // Thrown if the Java project does not exist, which is not of concern in
        // this tab (the Main tab handles those error messages)
        return false;
    }

    // TODO ?
    if (runServerButton != null) {
        if (!runServerButton.getSelection()) {
            setErrorMessage("App Engine projects need to run the built-in server.");
            return false;
        }
    }

    return true;
}

From source file:com.google.gdt.eclipse.suite.launch.ui.WebAppServerTab.java

License:Open Source License

@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
    setErrorMessage(null);//ww w  .  j a v  a 2 s. co m
    setMessage(null);

    if (!super.isValid(launchConfig)) {
        return false;
    }

    IProject project;
    try {
        IJavaProject javaProject = JavaRuntime.getJavaProject(launchConfig);
        if (javaProject == null) {
            return false;
        }

        project = javaProject.getProject();
    } catch (CoreException ce) {
        // Thrown if the Java project does not exist, which is not of concern in
        // this tab (the Main tab handles those error messages)
        return false;
    }

    if (runServerButton != null) {
        if (WebAppLaunchUtil.projectIsGaeOnly(project) && !runServerButton.getSelection()) {
            setErrorMessage("App Engine projects need to run the built-in server.");
            return false;
        }
    }

    return true;
}

From source file:com.google.gdt.eclipse.suite.launch.WebAppLaunchDelegate.java

License:Open Source License

/**
 * Publish any {@link IModule}s that the project has if it is not using a managed war directory and it is running a
 * server./* w  w  w . j a  va2 s .  c o m*/
 */
public static void maybePublishModulesToWarDirectory(ILaunchConfiguration configuration,
        IProgressMonitor monitor, IJavaProject javaProject, boolean forceFullPublish) throws CoreException {

    if (javaProject == null) {
        // No Java Project
        return;
    }

    IProject project = javaProject.getProject();

    List<String> args = LaunchConfigurationProcessorUtilities.parseProgramArgs(configuration);
    if (WebAppUtilities.hasManagedWarOut(project) || NoServerArgumentProcessor.hasNoServerArg(args)) {
        // Project has a managed war directory or it is running in noserver
        // mode
        return;
    }

    WarParser parser = WarArgumentProcessor.WarParser.parse(args, javaProject);
    if (parser.resolvedUnverifiedWarDir == null) {
        // Invalid war directory
        return;
    }

    IModule[] modules = ServerUtil.getModules(project);
    if (modules.length > 0) {
        Path unmanagedWarPath = new Path(parser.resolvedUnverifiedWarDir);
        WtpPublisher.publishModulesToWarDirectory(project, modules, unmanagedWarPath, forceFullPublish,
                monitor);
    }
}

From source file:com.google.gdt.eclipse.suite.launch.WebAppLaunchDelegate.java

License:Open Source License

/**
 * In the case of a project with an unmanaged WAR directory or when the project is not a web app but the main type
 * takes a WAR argument, we need to check at launch-time whether the launch config has a runtime WAR. If it does not,
 * then we ask the user for one and insert it into the launch config.
 *
 * @param configuration/*from  www .  ja  v  a 2s  . c o m*/
 *          the launch configuration that may be written to
 * @return true to continue the launch, false to abort silently
 * @throws CoreException
 */
private boolean ensureWarArgumentExistenceInCertainCases(ILaunchConfiguration configuration)
        throws CoreException {
    IJavaProject javaProject = getJavaProject(configuration);
    if (javaProject != null) {
        IProject project = javaProject.getProject();
        boolean isWebApp = WebAppUtilities.isWebApp(project);
        if ((isWebApp && !WebAppUtilities.hasManagedWarOut(project))
                || (!isWebApp && WarArgumentProcessor.doesMainTypeTakeWarArgument(configuration))) {

            List<String> args = LaunchConfigurationProcessorUtilities.parseProgramArgs(configuration);
            WarParser parser = WarArgumentProcessor.WarParser.parse(args, javaProject);

            if (!(parser.isSpecifiedWithWarArg || parser.isWarDirValid)) {
                // The project's output WAR dir is unknown, so ask the user
                IPath warDir = WebAppUtilities.getWarOutLocationOrPrompt(project);
                if (warDir == null) {
                    return false;
                }

                // The processor will update to the proper argument style
                // for the
                // current project nature(s)
                WarArgumentProcessor warArgProcessor = new WarArgumentProcessor();
                warArgProcessor.setWarDirFromLaunchConfigCreation(warDir.toOSString());

                ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
                LaunchConfigurationProcessorUtilities.updateViaProcessor(warArgProcessor, wc);
                wc.doSave();
            }
        }
    }

    return true;
}

From source file:com.google.gdt.eclipse.suite.update.builders.UpdateTriggerCompilationParticipant.java

License:Open Source License

@Override
public boolean isActive(IJavaProject project) {
    if (!project.exists()) {
        return false;
    }/*  ww  w  .ja  va2  s  . c o  m*/

    if (GWTNature.isGWTProject(project.getProject())) {
        GdtExtPlugin.getFeatureUpdateManager().checkForUpdates();
        return true;
    } else {
        return false;
    }
}

From source file:com.google.gdt.eclipse.suite.wizards.WebAppProjectCreator.java

License:Open Source License

protected void setProjectClasspath(IJavaProject javaProject, IFolder srcFolder, IProgressMonitor monitor)
        throws JavaModelException {
    List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
    classpathEntries.add(JavaCore.newSourceEntry(srcFolder.getFullPath()));

    // Add the "test" folder as a src path, if it exists
    IProject project = javaProject.getProject();
    IFolder testFolder = project.getFolder("test");
    if (testFolder.exists()) {
        classpathEntries.add(JavaCore.newSourceEntry(testFolder.getFullPath(), new IPath[0],
                project.getFullPath().append("test-classes")));
    }//from   ww w .  j a  va 2s.co  m

    // Add our container entries to the path
    for (IPath containerPath : containerPaths) {
        classpathEntries.add(JavaCore.newContainerEntry(containerPath));
    }

    classpathEntries.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary()));

    javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor);
}

From source file:com.google.gwt.eclipse.core.compile.GWTCompileRunner.java

License:Open Source License

/**
 * @param processReceiver optional, receives the process after it is started
 *///ww  w .j  a  v a  2s  . com
public static void compile(IJavaProject javaProject, IPath warLocation, GWTCompileSettings settings,
        OutputStream consoleOutputStream, IProcessReceiver processReceiver)
        throws IOException, InterruptedException, CoreException, OperationCanceledException {
    IProject project = javaProject.getProject();

    if (settings.getEntryPointModules().isEmpty()) {
        // Nothing to compile, so just return.
        return;
    }

    int processStatus = ProcessUtilities.launchProcessAndWaitFor(
            computeCompilerCommandLine(javaProject, warLocation, settings), project.getLocation().toFile(),
            consoleOutputStream, processReceiver);

    /*
     * Do a refresh on the war folder if it's in the workspace. This ensures
     * that Eclipse sees the generated artifacts from the GWT compile, and
     * doesn't complain about stale resources during subsequent file searches.
     */
    if (warLocation != null) {
        for (IContainer warFolder : ResourcesPlugin.getWorkspace().getRoot()
                .findContainersForLocationURI(URIUtil.toURI(warLocation))) {
            warFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
    }

    if (processStatus != 0) {
        if (processReceiver != null && processReceiver.hasDestroyedProcess()) {
            PrintWriter printWriter = new PrintWriter(consoleOutputStream);
            printWriter.println("GWT compilation terminated by the user.");
            printWriter.flush();
            throw new OperationCanceledException();
        } else {
            throw new CoreException(new Status(IStatus.ERROR, GWTPlugin.PLUGIN_ID, "GWT compilation failed"));
        }
    }
}