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

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

Introduction

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

Prototype

boolean hasBuildState();

Source Link

Document

Returns whether this project has been built at least once and thus whether it has a build state.

Usage

From source file:fr.imag.adele.cadse.cadseg.eclipse.CheckCompilationError.java

License:Apache License

public boolean checkError(IJavaProject jp, IProgressMonitor monitor) throws CoreException {
    jp.getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
    jp.hasBuildState();

    IMarker[] markers = jp.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
            IResource.DEPTH_INFINITE);/*from w w  w. j av a2  s .c om*/
    if (markers == null)
        return false;

    for (IMarker iMarker : markers) {
        return true;
    }
    return false;
}

From source file:no.javatime.inplace.bundleproject.ProjectProperties.java

License:Open Source License

/**
 * Checks if the project has build state
 * /*  w ww  . j  a  v a 2  s. c  o  m*/
 * @param project to check for build state
 * @return true if the project has build state, otherwise false
 */
public static boolean hasBuildState(IProject project) throws InPlaceException {

    if (null == project) {
        throw new InPlaceException("null_project_build_state");
    }
    if (project.isAccessible()) {
        IJavaProject javaProject = getJavaProject(project.getName());
        if (javaProject.hasBuildState()) {
            return true;
        }
    }
    return false;
}

From source file:org.eclipse.ajdt.core.builder.AJBuilder.java

License:Open Source License

protected IProject[] build(int kind, Map args, IProgressMonitor progressMonitor) throws CoreException {
    IProject project = getProject();/*  w  w w  .  ja  va2s  . c  o  m*/
    AjCompiler compiler = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project);

    CoreCompilerConfiguration compilerConfig = (CoreCompilerConfiguration) compiler.getCompilerConfiguration();

    // 100 ticks for the compiler, 1 for the pre-build actions, 1 for the post-build actions
    progressMonitor.beginTask(CoreMessages.builder_taskname, 102);

    AJLog.logStart(TimerLogEvent.TIME_IN_BUILD);
    AJLog.logStart("Pre compile");
    AJLog.log(AJLog.BUILDER,
            "==========================================================================================="); //$NON-NLS-1$
    AJLog.log(AJLog.BUILDER, "Build kind = " + buildKindString(kind)); //$NON-NLS-1$

    IProject[] requiredProjects = getRequiredProjects(project, true);

    // perform all pre-build actions
    CompilationParticipant[] participants = prebuild(kind, project, requiredProjects, compilerConfig);
    progressMonitor.worked(1);

    String mode = ""; //$NON-NLS-1$
    if (kind != IncrementalProjectBuilder.FULL_BUILD) {
        mode = "Incremental AspectJ compilation"; //$NON-NLS-1$
    } else {
        mode = "Full AspectJ compilation"; //$NON-NLS-1$
    }
    AJLog.log(AJLog.BUILDER, "Project=" //$NON-NLS-1$
            + project.getName() + ", kind of build requested=" + mode); //$NON-NLS-1$

    // bug 270554 augment the aspect path with builder arguments
    augmentAspectPath(project, args);

    if (!isWorthBuilding(project)) {
        postBuild(kind, true, participants, compiler);
        AJLog.log(AJLog.BUILDER, "build: Abort due to missing classpath/inpath/aspectpath entries"); //$NON-NLS-1$
        AJLog.logEnd(AJLog.BUILDER, TimerLogEvent.TIME_IN_BUILD);
        progressMonitor.done();
        return requiredProjects;
    }

    // workaround for bug 73435
    IProject[] dependingProjects = getDependingProjects(project);
    IJavaProject javaProject = JavaCore.create(project);
    if (!javaProject.hasBuildState() && dependingProjects.length > 0) {
        updateJavaCompilerPreferences(dependingProjects);
    }
    // end of workaround

    AJLog.logStart("Flush included source file cache");
    // Flush the list of included source files stored for this project
    BuildConfig.flushIncludedSourceFileCache(project);
    AJLog.logEnd(AJLog.BUILDER, "Flush included source file cache");

    AJLog.logStart("Check delta");
    // Check the delta - we only want to proceed if something relevant
    // in this project has changed (a .java file, a .aj file or a 
    // .lst file)
    IResourceDelta delta = getDelta(getProject());
    // copy over any new resources (bug 78579)
    if (delta != null) {
        copyResources(javaProject, delta);
    }
    AJLog.logEnd(AJLog.BUILDER, "Check delta");

    if (kind != FULL_BUILD) {
        AJLog.logStart("Look for source/resource changes");
        if (!hasChangesAndMark(delta, project)) {

            AJLog.log(AJLog.BUILDER, "build: Examined delta - no source file or classpath changes for project " //$NON-NLS-1$
                    + project.getName());

            // if the source files of any projects which the current
            // project depends on have changed, then need
            // also to build the current project                
            boolean continueToBuild = false;
            for (int i = 0; !continueToBuild && i < requiredProjects.length; i++) {
                IResourceDelta otherProjDelta = getDelta(requiredProjects[i]);
                continueToBuild = otherProjDelta != null
                        && (hasChangesAndMark(otherProjDelta, requiredProjects[i]));
            }

            // no changes found!  end the compilation.
            if (!continueToBuild) {
                // bug 107027
                compilerConfig.flushClasspathCache();
                compilerConfig.configurationRead(); // reset config
                postBuild(kind, true, participants, compiler);
                AJLog.logEnd(AJLog.BUILDER, "Look for source/resource changes");
                AJLog.log(AJLog.BUILDER, "No source/resource changes found, exiting build");
                AJLog.logEnd(AJLog.BUILDER, TimerLogEvent.TIME_IN_BUILD);
                progressMonitor.done();
                return requiredProjects;
            }
        }
        AJLog.logEnd(AJLog.BUILDER, "Look for source/resource changes");
    }

    migrateToRTContainerIfNecessary(javaProject);

    IAJCompilerMonitor compilerMonitor = (IAJCompilerMonitor) compiler.getBuildProgressMonitor();

    // Bug 43711 must do a clean and rebuild if we can't 
    // find a buildConfig file from a previous compilation
    if (kind == FULL_BUILD || !hasValidPreviousBuildConfig(compiler.getId())) {

        cleanOutputFolders(javaProject, false);
        AJProjectModelFactory.getInstance().removeModelForProject(project);
        copyResources(javaProject);

    } else {
        // doing an incremental build
        if (AspectJCorePreferences.isIncrementalCompilationOptimizationsEnabled()) {
            // Bug 245566:
            // facilitate incremental compilation by checking 
            // classpath for projects that have changed since the last build
            long timestamp = getLastBuildTimeStamp(compiler);
            compilerConfig.setClasspathElementsWithModifiedContents(getChangedRequiredProjects(timestamp));
        }
    }

    // bug 270335 -- if output locations have changed, then 
    // need a new output location manager.
    compilerConfig.flushOutputLocationManagerIfNecessary(kind);
    compilerConfig.buildStarting();

    compilerMonitor.prepare(new SubProgressMonitor(progressMonitor, 100));

    AJLog.log(AJLog.BUILDER_CLASSPATH, "Classpath = " + compilerConfig.getClasspath()); //$NON-NLS-1$
    AJLog.logEnd(AJLog.BUILDER, "Pre compile");

    // ----------------------------------------
    // Do the compilation
    AJLog.logStart(TimerLogEvent.TIME_IN_AJDE);
    if (kind == FULL_BUILD) {
        compiler.buildFresh();
    } else {
        compiler.build();
    }
    AJLog.logEnd(AJLog.BUILDER, TimerLogEvent.TIME_IN_AJDE);
    // compilation is done
    // ----------------------------------------

    doRefreshAfterBuild(project, dependingProjects, javaProject);

    // do the cleanup
    // bug 107027
    compilerConfig.flushClasspathCache();

    postBuild(kind, false, participants, compiler);
    progressMonitor.worked(1);
    progressMonitor.done();

    AJLog.logEnd(AJLog.BUILDER, TimerLogEvent.TIME_IN_BUILD);
    return requiredProjects;
}

From source file:test.fede.workspace.domain.internal.TestWorkingLogiqueCopy.java

License:Apache License

public void checkError(IJavaProject jp, IProgressMonitor monitor) throws CoreException {
    jp.getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
    if (!jp.hasBuildState())
        return;/* ww  w  .j a  va 2s  .  c om*/

    IMarker[] markers = jp.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
            IResource.DEPTH_INFINITE);
    if (markers == null)
        return;
    StringBuilder errors = new StringBuilder();
    for (IMarker iMarker : markers) {
        Integer severity = (Integer) iMarker.getAttribute(IMarker.SEVERITY);
        if (severity != null && severity == IMarker.SEVERITY_ERROR) {
            errors.append(iMarker.getAttribute(IMarker.MESSAGE)).append("\n");
        }
    }
    if (errors.length() != 0) {
        fail("compilation error on " + jp.getElementName() + "\n" + errors);
    }
}