Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2018-03-19 21:28:08 +0000
committerMickael Istria2018-09-10 08:55:14 +0000
commit749e6f86b20add3c4fa8193fea1a613d6b0a897b (patch)
treedd39630f4f7ac8813f899ea373172f2069218db3 /org.eclipse.jdt.apt.core
parent137440659e5f6de2b611e18488e240eb603d47e1 (diff)
downloadeclipse.jdt.core-749e6f86b20add3c4fa8193fea1a613d6b0a897b.tar.gz
eclipse.jdt.core-749e6f86b20add3c4fa8193fea1a613d6b0a897b.tar.xz
eclipse.jdt.core-749e6f86b20add3c4fa8193fea1a613d6b0a897b.zip
Bug 531554 - Pref to allow null scheduling rule for Java Builder
Also relax rules for several other WorkspaceRunnable, so it allows Workspace to enable parallel builds even when some JDT projects are present. Change-Id: Idae1a746077f9d380eb67fc7c3345aa072bab351 Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.jdt.apt.core')
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java240
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java2
2 files changed, 127 insertions, 115 deletions
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java
index c4da45e2d8..c8c022c482 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BuildEnv.java
@@ -18,7 +18,12 @@ import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -38,45 +43,52 @@ import org.eclipse.jdt.apt.core.internal.util.Visitors.AnnotationVisitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.BuildContext;
-import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+
import com.sun.mirror.apt.Filer;
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
import com.sun.mirror.declaration.PackageDeclaration;
import com.sun.mirror.declaration.TypeDeclaration;
public class BuildEnv extends AbstractCompilationEnv
-{
+{
private boolean _hasRaisedErrors = false;
- private final BuildFilerImpl _filer;
+ private final BuildFilerImpl _filer;
/**
* Set of strings that indicate new type dependencies introduced on the file
* each string is a fully-qualified type name.
*/
private Set<String> _typeDependencies = new HashSet<>();
-
+
/**
- * Indicates whether we are in batch mode or not. This gets flipped only
- * during build and could be flipped back and forth.
+ * Indicates whether we are in batch mode or not. This gets flipped only
+ * during build and could be flipped back and forth.
*/
private boolean _batchMode = false; // off by default.
- /**
+ /**
* Holds all the files that contains annotation that are to be processed during build.
- * If we are not in batch mode, <code>super._file</code> holds the file
- * being processed at the time.
- */
+ * If we are not in batch mode, <code>super._file</code> holds the file
+ * being processed at the time.
+ */
private BuildContext[] _filesWithAnnotation = null;
-
+
/**
* These are files that are part of a build but does not have annotations on it.
- * During batch mode processing, these files still also need to be included.
+ * During batch mode processing, these files still also need to be included.
*/
private BuildContext[] _additionFiles = null;
- /**
+ /**
* This is intialized when <code>_batchMode</code> is set to be <code>true</code> or
* when batch processing is expected. <p>
* It is also set in build mode for perf reason rather than parsing and resolving
@@ -85,29 +97,29 @@ public class BuildEnv extends AbstractCompilationEnv
*/
private CompilationUnit[] _astRoots = null;
private List<MarkerInfo> _markerInfos = null;
-
+
/**
* Constructor for creating a processor environment used during build.
* @param filesWithAnnotations
* @param additionalFiles
* @param units
* @param javaProj
- * @param isTestCode
+ * @param isTestCode
* @param phase
*/
BuildEnv(
final BuildContext[] filesWithAnnotations,
final BuildContext[] additionalFiles,
final IJavaProject javaProj, boolean isTestCode) {
-
+
super(null, null, javaProj, Phase.BUILD, isTestCode);
_filer = new BuildFilerImpl(this);
_filesWithAnnotation = filesWithAnnotations;
_additionFiles = additionalFiles;
_problems = new ArrayList<>();
_markerInfos = new ArrayList<>();
-
- if (AptPlugin.DEBUG_COMPILATION_ENV) AptPlugin.trace(
+
+ if (AptPlugin.DEBUG_COMPILATION_ENV) AptPlugin.trace(
"constructed " + this + " for " + _filesWithAnnotation.length + " files"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
@@ -127,12 +139,12 @@ public class BuildEnv extends AbstractCompilationEnv
@Override
public TypeDeclaration getTypeDeclaration(String name)
{
- checkValid();
+ checkValid();
TypeDeclaration decl = super.getTypeDeclaration(name);
-
- if (!_batchMode)
+
+ if (!_batchMode)
addTypeDependency(name);
-
+
return decl;
}
@@ -142,7 +154,7 @@ public class BuildEnv extends AbstractCompilationEnv
*/
public boolean hasRaisedErrors(){
return _hasRaisedErrors;
- }
+ }
public static InputStreamReader getFileReader( final IFile file ) throws IOException, CoreException {
return new InputStreamReader(getInputStream(file), file.getCharset());
@@ -167,7 +179,7 @@ public class BuildEnv extends AbstractCompilationEnv
*/
@Override
public void close(){
- if( isClosed() )
+ if( isClosed() )
return;
_markerInfos = null;
_astRoot = null;
@@ -175,13 +187,13 @@ public class BuildEnv extends AbstractCompilationEnv
_astRoots = null;
_filesWithAnnotation = null;
_problems = null;
- _modelCompUnit2astCompUnit.clear();
+ _modelCompUnit2astCompUnit.clear();
_hasRaisedErrors = false;
super.close();
}
-
+
/**
- *
+ *
* @param resource null to indicate current resource
* @param start the starting offset of the marker
* @param end -1 to indicate unknow ending offset.
@@ -190,21 +202,21 @@ public class BuildEnv extends AbstractCompilationEnv
* @param line the line number of where the marker should be
*/
@Override
- void addMessage(IFile resource,
- int start,
+ void addMessage(IFile resource,
+ int start,
int end,
- Severity severity,
- String msg,
+ Severity severity,
+ String msg,
int line,
String[] arguments)
{
checkValid();
-
+
if( resource == null )
resource = getFile();
-
+
_hasRaisedErrors |= severity == MessagerImpl.Severity.ERROR;
-
+
// Eclipse doesn't support INFO-level IProblems, so we send them to the log instead.
if ( severity == Severity.INFO) {
StringBuilder sb = new StringBuilder();
@@ -236,69 +248,69 @@ public class BuildEnv extends AbstractCompilationEnv
AptPlugin.log(status);
return;
}
-
+
if( resource == null ){
assert _batchMode : "not in batch mode but don't know about current resource"; //$NON-NLS-1$
addMarker(start, end, severity, msg, line, arguments);
}
- else
+ else
addProblem(resource, start, end, severity, msg, line, arguments);
}
-
+
private void addProblem(
- IFile resource,
- int start,
+ IFile resource,
+ int start,
int end,
- Severity severity,
- String msg,
+ Severity severity,
+ String msg,
int line,
String[] arguments)
- {
-
+ {
+
APTProblem problem = createProblem(resource, start, end, severity, msg, line, arguments);
_problems.add(problem);
}
-
+
private void addMarker(
- int start,
+ int start,
int end,
- Severity severity,
- String msg,
+ Severity severity,
+ String msg,
int line,
String[] arguments)
- {
-
+ {
+
// Note that the arguments are ignored -- no quick-fix for markers.
_markerInfos.add(new MarkerInfo(start, end, severity, msg, line));
}
-
+
@Override
public Map<String, AnnotationTypeDeclaration> getAnnotationTypes()
{
checkValid();
- assert _astRoot != null && _file != null && !_batchMode :
+ assert _astRoot != null && _file != null && !_batchMode :
"operation not available under batch mode."; //$NON-NLS-1$
return super.getAnnotationTypes();
}
-
+
/**
* Return all annotations at declaration level within all compilation unit(s)
- * associated with this environment. All the files associated with this environment will
+ * associated with this environment. All the files associated with this environment will
* be parsed and resolved for all declaration level elements at the return of this call.
- *
+ *
* @param file2Annotations populated by this method to map files to the annotation types
* if contains. May be null.
* @return the map containing all annotation types found within this environment.
*/
public Map<String, AnnotationTypeDeclaration> getAllAnnotationTypes(
final Map<BuildContext, Set<AnnotationTypeDeclaration>> file2Annotations) {
-
+
checkValid();
- if( _filesWithAnnotation == null )
+ if( _filesWithAnnotation == null )
return getAnnotationTypes();
-
+
final List<Annotation> instances = new ArrayList<>();
- final Map<String, AnnotationTypeDeclaration> decls =
+ final Map<String, AnnotationTypeDeclaration> decls =
new HashMap<>();
final AnnotationVisitor visitor = new AnnotationVisitor(instances);
for( int astIndex=0, len=_astRoots.length; astIndex<len; astIndex++ ){
@@ -306,13 +318,13 @@ public class BuildEnv extends AbstractCompilationEnv
System.err.println();
_astRoots[astIndex].accept(visitor);
final Set<AnnotationTypeDeclaration> perFileAnnos = new HashSet<>();
-
+
for (int instanceIndex=0, size = instances.size(); instanceIndex < size; instanceIndex++) {
final Annotation instance = instances.get(instanceIndex);
final ITypeBinding annoType = instance.resolveTypeBinding();
if (annoType == null)
continue;
- final TypeDeclarationImpl decl =
+ final TypeDeclarationImpl decl =
Factory.createReferenceType(annoType, this);
if (decl != null && decl.kind() == EclipseMirrorObject.MirrorKind.TYPE_ANNOTATION){
final AnnotationTypeDeclaration annoDecl = (AnnotationTypeDeclaration)decl;
@@ -324,37 +336,37 @@ public class BuildEnv extends AbstractCompilationEnv
file2Annotations.put(_filesWithAnnotation[astIndex], perFileAnnos);
visitor.reset();
}
-
+
return decls;
}
/**
* @return - the extra type dependencies for the files under compilation
*/
- public Set<String> getTypeDependencies() { return _typeDependencies; }
-
+ public Set<String> getTypeDependencies() { return _typeDependencies; }
+
/**
- * Switch to batch processing mode.
- * Note: Call to this method will cause all files associated with this environment to be
+ * Switch to batch processing mode.
+ * Note: Call to this method will cause all files associated with this environment to be
* read and parsed.
*/
- public void beginBatchProcessing(){
+ public void beginBatchProcessing(){
if( _phase != Phase.BUILD )
throw new IllegalStateException("No batch processing outside build."); //$NON-NLS-1$
-
+
if( _batchMode ) return;
checkValid();
-
+
_batchMode = true;
_file = null;
_astRoot = null;
}
-
+
public void completedBatchProcessing(){
postMarkers();
completedProcessing();
}
-
+
void createASTs(BuildContext[] cpResults){
final int len = cpResults.length;
final ICompilationUnit[] units = new ICompilationUnit[len];
@@ -366,17 +378,17 @@ public class BuildEnv extends AbstractCompilationEnv
createASTs(_javaProject, units, _requestor = new CallbackRequestor(units));
}
- public void beginFileProcessing(BuildContext result){
+ public void beginFileProcessing(BuildContext result){
if( result == null )
throw new IllegalStateException("missing compilation result"); //$NON-NLS-1$
_batchMode = false;
final IFile file = result.getFile();
if( file.equals(_file) ) // this is a no-op
return;
-
+
_astRoot = null;
_file = null;
-
+
// need to match up the file with the ast.
if( _filesWithAnnotation != null ){
for( int i=0, len=_filesWithAnnotation.length; i<len; i++ ){
@@ -386,37 +398,37 @@ public class BuildEnv extends AbstractCompilationEnv
}
}
}
-
+
if( _file == null || _astRoot == null)
throw new IllegalStateException(
"file " + //$NON-NLS-1$
- file.getName() +
+ file.getName() +
" is not in the list to be processed."); //$NON-NLS-1$
}
-
+
public void completedFileProcessing(){
completedProcessing();
}
-
+
@Override
protected void completedProcessing(){
_problems.clear();
_typeDependencies.clear();
super.completedProcessing();
}
-
+
@Override
public List<? extends CategorizedProblem> getProblems(){
if( !_problems.isEmpty() )
EnvUtil.updateProblemLength(_problems, getAstCompilationUnit());
return _problems;
}
-
+
// Implementation for EclipseAnnotationProcessorEnvironment
@Override
public CompilationUnit getAST()
{
- if( _batchMode )
+ if( _batchMode )
return null;
return _astRoot;
}
@@ -424,12 +436,12 @@ public class BuildEnv extends AbstractCompilationEnv
@Override
public void addTypeDependency(final String fullyQualifiedTypeName )
{
- if(!_batchMode){
+ if(!_batchMode){
_typeDependencies.add( fullyQualifiedTypeName );
}
}
// End of implementation for EclipseAnnotationProcessorEnvironment
-
+
/**
* Include all the types from all files, files with and without annotations on it
* if we are in batch mode. Otherwise, just the types from the file that's currently
@@ -443,15 +455,15 @@ public class BuildEnv extends AbstractCompilationEnv
final List<AbstractTypeDeclaration> typeDecls = new ArrayList<>();
for( int i=0, len=_astRoots.length; i<len; i++ )
typeDecls.addAll( _astRoots[i].types() );
-
+
getTypeDeclarationsFromAdditionFiles(typeDecls);
-
+
return typeDecls;
}
-
+
private void getTypeDeclarationsFromAdditionFiles(List<AbstractTypeDeclaration> typeDecls){
if( _additionFiles == null || _additionFiles.length == 0 ) return;
-
+
final int len = _additionFiles.length;
final ICompilationUnit[] units = new ICompilationUnit[len];
for( int i=0; i<len; i++ ){
@@ -461,7 +473,7 @@ public class BuildEnv extends AbstractCompilationEnv
}
BaseRequestor r = new BaseRequestor(units);
createASTs(_javaProject, units, r);
-
+
CompilationUnit[] asts = r.asts;
for( CompilationUnit ast : asts ){
if( ast != null ){
@@ -469,19 +481,19 @@ public class BuildEnv extends AbstractCompilationEnv
}
}
}
-
+
@Override
protected Map<ASTNode, List<Annotation>> getASTNodesWithAnnotations()
{
if( !_batchMode )
return super.getASTNodesWithAnnotations();
final Map<ASTNode, List<Annotation>> astNode2Anno = new HashMap<>();
- final AnnotatedNodeVisitor visitor = new AnnotatedNodeVisitor(astNode2Anno);
+ final AnnotatedNodeVisitor visitor = new AnnotatedNodeVisitor(astNode2Anno);
for( int i=0, len=_astRoots.length; i<len; i++ )
_astRoots[i].accept( visitor );
return astNode2Anno;
}
-
+
@Override
protected IFile getFileForNode(final ASTNode node)
{
@@ -494,12 +506,12 @@ public class BuildEnv extends AbstractCompilationEnv
}
throw new IllegalStateException();
}
-
+
/**
* Go through the list of compilation unit in this environment and looking for
* the declaration node of the given binding.
- * @param binding
- * @return the compilation unit that defines the given binding or null if no
+ * @param binding
+ * @return the compilation unit that defines the given binding or null if no
* match is found.
*/
@Override
@@ -507,7 +519,7 @@ public class BuildEnv extends AbstractCompilationEnv
{
if( !_batchMode )
return super.searchLocallyForBinding(binding);
-
+
for( int i=0, len=_astRoots.length; i<len; i++ ){
ASTNode node = _astRoots[i].findDeclaringNode(binding);
if( node != null)
@@ -515,12 +527,12 @@ public class BuildEnv extends AbstractCompilationEnv
}
return null;
}
-
+
/**
* Go through the list of compilation unit in this environment and looking for
* the declaration node of the given binding.
- * @param binding
- * @return the compilation unit that defines the given binding or null if no
+ * @param binding
+ * @return the compilation unit that defines the given binding or null if no
* match is found.
*/
@Override
@@ -528,7 +540,7 @@ public class BuildEnv extends AbstractCompilationEnv
{
if( !_batchMode )
return super.searchLocallyForIFile(binding);
-
+
for( int i=0, len=_astRoots.length; i<len; i++ ){
ASTNode node = _astRoots[i].findDeclaringNode(binding);
if( node != null)
@@ -536,7 +548,7 @@ public class BuildEnv extends AbstractCompilationEnv
}
return null;
}
-
+
/**
* @param file
* @return the compilation unit associated with the given file.
@@ -546,7 +558,7 @@ public class BuildEnv extends AbstractCompilationEnv
@Override
public CompilationUnit getASTFrom(final IFile file)
{
- if( file == null )
+ if( file == null )
return null;
else if( file.equals(_file) )
return _astRoot;
@@ -558,15 +570,15 @@ public class BuildEnv extends AbstractCompilationEnv
}
return null;
}
-
+
/**
* @return the current ast being processed if in per-file mode.
* If in batch mode, one of the asts being processed (no guarantee which
- * one will be returned.
+ * one will be returned.
*/
@Override
protected AST getCurrentDietAST(){
-
+
if( _astRoot != null )
return _astRoot.getAST();
else{
@@ -575,7 +587,7 @@ public class BuildEnv extends AbstractCompilationEnv
return _astRoots[0].getAST();
}
}
-
+
void postMarkers()
{
if( _markerInfos == null || _markerInfos.size() == 0 )
@@ -586,8 +598,8 @@ public class BuildEnv extends AbstractCompilationEnv
final IWorkspaceRunnable runnable = new IWorkspaceRunnable(){
@Override
public void run(IProgressMonitor monitor)
- {
- for( MarkerInfo markerInfo : _markerInfos ){
+ {
+ for( MarkerInfo markerInfo : _markerInfos ){
try{
final IMarker marker = _javaProject.getProject().createMarker(AptPlugin.APT_BATCH_PROCESSOR_PROBLEM_MARKER);
markerInfo.copyIntoMarker(marker);
@@ -599,7 +611,7 @@ public class BuildEnv extends AbstractCompilationEnv
}
};
IWorkspace ws = _javaProject.getProject().getWorkspace();
- ws.run(runnable, null);
+ ws.run(runnable, _javaProject.getProject(), IWorkspace.AVOID_UPDATE, null);
}
catch(CoreException e){
AptPlugin.log(e, "Failed to post markers"); //$NON-NLS-1$
@@ -608,17 +620,17 @@ public class BuildEnv extends AbstractCompilationEnv
_markerInfos.clear();
}
}
-
+
public BuildContext[] getFilesWithAnnotation()
{
return _filesWithAnnotation;
}
-
+
public BuildContext[] getFilesWithoutAnnotation()
{
return _additionFiles;
}
-
+
private class CallbackRequestor extends BaseRequestor {
CallbackRequestor(ICompilationUnit[] parseUnits) {
super(parseUnits);
@@ -629,7 +641,7 @@ public class BuildEnv extends AbstractCompilationEnv
// then assign the asts, then begin dispatch
_astRoots = asts;
_callback.run(BuildEnv.this);
- }
+ }
}
-
+
}
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java
index 697c1b2dd2..f709eafa6c 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/generatedfile/GeneratedSourceFolderManager.java
@@ -488,7 +488,7 @@ public class GeneratedSourceFolderManager {
};
IWorkspace ws = ResourcesPlugin.getWorkspace();
try{
- ws.run(runnable, ws.getRoot(), IWorkspace.AVOID_UPDATE, null);
+ ws.run(runnable, srcFolder.getProject(), IWorkspace.AVOID_UPDATE, null);
}catch(CoreException e){
AptPlugin.log(e, "Runnable for deleting old generated source folder " + srcFolder.getName() + " failed."); //$NON-NLS-1$ //$NON-NLS-2$
}

Back to the top