List of usage examples for org.aspectj.ajde.core AjCompiler getCompilerConfiguration
public ICompilerConfiguration getCompilerConfiguration()
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 .java2 s . 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:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
/** * Performs post build actions including calling listeners and handling compilation participants * //from www. j av a2 s . c om * returns any extra problems to be applied for this build */ private void postBuild(int kind, boolean noSourceChanges, CompilationParticipant[] participants, AjCompiler compiler) { final IJavaProject javaProject = JavaCore.create(getProject()); Map<IFile, List<CategorizedProblem>> newProblems = Collections.emptyMap(); // now handle participants if (participants != null) { if (noSourceChanges) { for (final CompilationParticipant participant : participants) { // from ReconcileWorkingCopyOperation SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { if (exception instanceof Error) { throw (Error) exception; // errors are not supposed to be caught } else if (exception instanceof OperationCanceledException) throw (OperationCanceledException) exception; else if (exception instanceof UnsupportedOperationException) { // might want to disable participant as it tried to modify the buffer of the working copy being reconciled Util.log(exception, "Reconcile participant attempted to modify the buffer of the working copy being reconciled"); //$NON-NLS-1$ } else Util.log(exception, "Exception occurred in reconcile participant"); //$NON-NLS-1$ } public void run() throws Exception { participant.buildStarting(new CompilationParticipantResult[0], false); participant.buildFinished(javaProject); } }); } } else { // first calculate the CompilationParticipantResults final BuildContext[] results = calculateCompilationParticipantResults( (CoreCompilerConfiguration) compiler.getCompilerConfiguration()); for (final CompilationParticipant participant : participants) { SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { if (exception instanceof Error) { throw (Error) exception; // errors are not supposed to be caught } else if (exception instanceof OperationCanceledException) throw (OperationCanceledException) exception; else if (exception instanceof UnsupportedOperationException) { // might want to disable participant as it tried to modify the buffer of the working copy being reconciled Util.log(exception, "Reconcile participant attempted to modify the buffer of the working copy being reconciled"); //$NON-NLS-1$ } else Util.log(exception, "Exception occurred in reconcile participant"); //$NON-NLS-1$ } public void run() throws Exception { participant.buildStarting(results, false); if (participant.isAnnotationProcessor()) { participant.processAnnotations(results); } participant.buildFinished(javaProject); } }); } // extra problems and new dependencies newProblems = new HashMap<IFile, List<CategorizedProblem>>(); for (int i = 0; i < results.length; i++) { AJCompilationParticipantResult result = (AJCompilationParticipantResult) results[i]; // Bug 349963---why is result null? if (result == null) { continue; } List<CategorizedProblem> problems = result.getProblems(); if (problems != null) { newProblems.put(result.getFile(), problems); } String[] dependencies = result.getDependencies(); if (dependencies != null && dependencies.length > 0) { compiler.addDependencies(result.getFile().getLocation().toFile(), dependencies); } } } } postCallListeners(kind, noSourceChanges, newProblems); ((CoreCompilerConfiguration) compiler.getCompilerConfiguration()).buildComplete(); }
From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.AJSerialVersionHashOperation.java
License:Open Source License
/** * The original version of this method used the JDT state * object to find the class file of the type, but in * AspectJ projects, there is no State object. * /*from ww w .java 2 s . c o m*/ * Instead use the IOutputLocationManager for the project * * Note that this will not work when the type is anonymous or it is * a named type inside a method declaration */ private static IFile getClassfile(ITypeBinding typeBinding) throws CoreException { IType type = (IType) typeBinding.getJavaElement(); // get the output location manager IProject project = typeBinding.getJavaElement().getJavaProject().getProject(); AjCompiler compiler = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project); IOutputLocationManager manager = compiler.getCompilerConfiguration().getOutputLocationManager(); if (!(manager instanceof CoreOutputLocationManager)) { return null; } CoreOutputLocationManager coreManager = (CoreOutputLocationManager) manager; // get the binary folder ICompilationUnit cu = type.getCompilationUnit(); File file = new File(cu.getResource().getLocation().toOSString()); File outLocation = coreManager.getOutputLocationForResource(file); // convert to IFolder IPath outPath = new Path(outLocation.getPath()); IPath projPath = project.getLocation(); if (projPath.isPrefixOf(outPath)) { outPath = outPath.removeFirstSegments(projPath.segmentCount()); } IFolder outFolder = project.getFolder(outPath); if (!outFolder.exists()) { return null; } // get the package path IPackageFragment frag = type.getPackageFragment(); String packageName = frag.getElementName(); IPath packagePath = new Path(packageName.replace('.', '/')); IFolder packageFolder = outFolder.getFolder(packagePath); if (!packageFolder.exists()) { return null; } // determine the binary name of this type StringBuffer binaryName = new StringBuffer(); IJavaElement enclosing = type.getParent(); while (enclosing != null && !(enclosing instanceof ICompilationUnit)) { binaryName.append(enclosing.getElementName() + "$"); enclosing = enclosing.getParent(); } binaryName.append(type.getElementName() + ".class"); IFile classFile = packageFolder.getFile(new Path(binaryName.toString())); if (classFile.exists()) { return classFile; } else { return null; } }