List of usage examples for org.eclipse.jdt.internal.core.builder JavaBuilder SOURCE_ID
String SOURCE_ID
To view the source code for org.eclipse.jdt.internal.core.builder JavaBuilder SOURCE_ID.
Click Source Link
From source file:org.eclipse.ajdt.internal.builder.UIBuildListener.java
License:Open Source License
public void postAJBuild(int kind, final IProject project, boolean noSourceChanges, Map<IFile, List<CategorizedProblem>> newProblems) { if (noSourceChanges) { return;// w ww. j a v a 2 s . c o m } // The message to feature in the problems view of depending projects String buildPrereqsMessage = NLS.bind(UIMessages.buildPrereqsMessage, project.getName()); boolean buildCancelled = ((IAJCompilerMonitor) AspectJPlugin.getDefault().getCompilerFactory() .getCompilerForProject(project).getBuildProgressMonitor()).buildWasCancelled(); if (buildCancelled) { markReferencingProjects(project, buildPrereqsMessage); } else { removeMarkerOnReferencingProjects(project, buildPrereqsMessage); } // Bug22258: Get the compiler monitor to display any issues with // that compile. IBuildMessageHandler messageHandler = AspectJPlugin.getDefault().getCompilerFactory() .getCompilerForProject(project).getMessageHandler(); if (messageHandler instanceof UIMessageHandler) { ((UIMessageHandler) messageHandler).showOutstandingProblems(project); } // before returning, check to see if the project sent its output // to an outjar and if so, then update any depending projects checkOutJarEntry(project); checkInpathOutFolder(project); // update the markers on files, but only the ones that have changed DeleteAndUpdateAJMarkersJob deleteUpdateMarkers; CoreCompilerConfiguration compilerConfig = getCompilerConfiguration(project); switch (kind) { case IncrementalProjectBuilder.CLEAN_BUILD: deleteUpdateMarkers = new DeleteAndUpdateAJMarkersJob(project); deleteUpdateMarkers.doDeleteOnly(true); deleteUpdateMarkers.setPriority(Job.BUILD); deleteUpdateMarkers.schedule(); break; case IncrementalProjectBuilder.FULL_BUILD: deleteUpdateMarkers = new DeleteAndUpdateAJMarkersJob(project); deleteUpdateMarkers.setPriority(Job.BUILD); deleteUpdateMarkers.schedule(); break; case IncrementalProjectBuilder.AUTO_BUILD: case IncrementalProjectBuilder.INCREMENTAL_BUILD: File[] touchedFiles = compilerConfig.getCompiledSourceFiles(); if (touchedFiles == null /* recreate all markers */ || touchedFiles.length > 0) { deleteUpdateMarkers = new DeleteAndUpdateAJMarkersJob(project, touchedFiles); deleteUpdateMarkers.schedule(); } } // sanity check the model if the event trace viewer is open if (DebugTracing.DEBUG_MODEL) { AJModelChecker.doModelCheckIfRequired(AJProjectModelFactory.getInstance().getModelForProject(project)); } if (AspectJUIPlugin.getDefault().getDisplay().isDisposed()) { AJLog.log("Not updating vis, xref, or changes views as display is disposed!"); //$NON-NLS-1$ } else { AspectJUIPlugin.getDefault().getDisplay().asyncExec(new Runnable() { public void run() { AJLog.logStart("Update visualizer, xref, advice listeners for (separate thread): " + project.getName()); // TODO: can we determine whether there were // actually changes to the set of advised elements? Object[] listeners = fListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { ((IAdviceChangedListener) listeners[i]).adviceChanged(); } // refresh Cross References if (AspectJUIPlugin.usingXref) { XReferenceUIPlugin.refresh(); } // refresh Visualiser if (AspectJUIPlugin.usingVisualiser) { Bundle vis = Platform.getBundle(AspectJUIPlugin.VISUALISER_ID); // avoid activating the bundle if it's not active already if ((vis != null) && (vis.getState() == Bundle.ACTIVE)) { if (ProviderManager.getContentProvider() instanceof AJDTContentProvider) { AJDTContentProvider provider = (AJDTContentProvider) ProviderManager .getContentProvider(); provider.reset(); VisualiserPlugin.refresh(); } } } AJLog.logEnd(AJLog.BUILDER, "Update visualizer, xref, advice listeners for (separate thread): " + project.getName()); } }); } // finally, create markers for extra problems coming from compilation participants for (Entry<IFile, List<CategorizedProblem>> problemsForFile : newProblems.entrySet()) { try { IFile file = problemsForFile.getKey(); for (CategorizedProblem problem : problemsForFile.getValue()) { String markerType = problem.getMarkerType(); IMarker marker = file.createMarker(markerType); String[] attributeNames = AbstractImageBuilder.JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES; String[] extraAttributeNames = problem.getExtraMarkerAttributeNames(); int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length; int standardLength = attributeNames.length + 1; String[] allNames = new String[standardLength]; System.arraycopy(attributeNames, 0, allNames, 0, standardLength - 1); allNames[standardLength - 1] = IMarker.SOURCE_ID; if (extraLength > 0) { allNames = new String[standardLength + extraLength]; System.arraycopy(extraAttributeNames, 0, allNames, standardLength + 1, extraLength); } Object[] allValues = new Object[allNames.length]; // standard attributes int index = 0; allValues[index++] = problem.getMessage(); // message allValues[index++] = problem.isError() ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING; // severity allValues[index++] = new Integer(problem.getID()); // ID allValues[index++] = new Integer(problem.getSourceStart()); // start int end = problem.getSourceEnd(); allValues[index++] = new Integer(end > 0 ? end + 1 : end); // end allValues[index++] = new Integer(problem.getSourceLineNumber()); // line allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments allValues[index++] = new Integer(problem.getCategoryID()); // category ID // SOURCE_ID attribute for JDT problems allValues[index++] = JavaBuilder.SOURCE_ID; // optional extra attributes if (extraLength > 0) System.arraycopy(problem.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength); marker.setAttributes(allNames, allValues); } } catch (CoreException e) { } } }
From source file:org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.java
License:Open Source License
protected void createProblemFor(IResource resource, IMember javaElement, String message, String problemSeverity) { try {/*from w w w . j a v a 2 s . c o m*/ IMarker marker = resource.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); int severity = problemSeverity.equals(JavaCore.WARNING) ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR; ISourceRange range = null; if (javaElement != null) { try { range = javaElement.getNameRange(); } catch (JavaModelException e) { if (e.getJavaModelStatus().getCode() != IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) { throw e; } if (!CharOperation.equals(javaElement.getElementName().toCharArray(), TypeConstants.PACKAGE_INFO_NAME)) { throw e; } // else silently swallow the exception as the synthetic interface type package-info has no // source range really. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=258145 } } int start = range == null ? 0 : range.getOffset(); int end = range == null ? 1 : start + range.getLength(); marker.setAttributes( new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IMarker.CHAR_START, IMarker.CHAR_END, IMarker.SOURCE_ID }, new Object[] { message, new Integer(severity), new Integer(start), new Integer(end), JavaBuilder.SOURCE_ID }); } catch (CoreException e) { throw internalException(e); } }
From source file:org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.java
License:Open Source License
/** * Creates a marker from each problem and adds it to the resource. * The marker is as follows:// w ww . j a va2 s . c om * - its type is T_PROBLEM * - its plugin ID is the JavaBuilder's plugin ID * - its message is the problem's message * - its priority reflects the severity of the problem * - its range is the problem's range * - it has an extra attribute "ID" which holds the problem's id * - it's {@link IMarker#SOURCE_ID} attribute is positioned to {@link JavaBuilder#SOURCE_ID} if * the problem was generated by JDT; else the {@link IMarker#SOURCE_ID} attribute is * carried from the problem to the marker in extra attributes, if present. */ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException { if (sourceFile == null || problems == null || problems.length == 0) return; // once a classpath error is found, ignore all other problems for this project so the user can see the main error // but still try to compile as many source files as possible to help the case when the base libraries are in source if (!this.keepStoringProblemMarkers) return; // only want the one error recorded on this source file IResource resource = sourceFile.resource; HashSet managedMarkerTypes = JavaModelManager.getJavaModelManager().compilationParticipants .managedMarkerTypes(); for (int i = 0, l = problems.length; i < l; i++) { CategorizedProblem problem = problems[i]; int id = problem.getID(); // handle missing classfile situation if (id == IProblem.IsClassPathCorrect) { String missingClassfileName = problem.getArguments()[0]; if (JavaBuilder.DEBUG) System.out.println(Messages.bind(Messages.build_incompleteClassPath, missingClassfileName)); boolean isInvalidClasspathError = JavaCore.ERROR .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true)); // insert extra classpath problem, and make it the only problem for this project (optional) if (isInvalidClasspathError && JavaCore.ABORT.equals( this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true))) { JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject); // make this the only problem for this project this.keepStoringProblemMarkers = false; } IMarker marker = this.javaBuilder.currentProject .createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttributes( new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID }, new Object[] { Messages.bind(Messages.build_incompleteClassPath, missingClassfileName), new Integer(isInvalidClasspathError ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING), new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID }); // even if we're not keeping more markers, still fall through rest of the problem reporting, so that offending // IsClassPathCorrect problem gets recorded since it may help locate the offending reference } String markerType = problem.getMarkerType(); boolean managedProblem = false; if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType) || (managedProblem = managedMarkerTypes.contains(markerType))) { IMarker marker = resource.createMarker(markerType); String[] attributeNames = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES; int standardLength = attributeNames.length; String[] allNames = attributeNames; int managedLength = managedProblem ? 0 : 1; String[] extraAttributeNames = problem.getExtraMarkerAttributeNames(); int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length; if (managedLength > 0 || extraLength > 0) { allNames = new String[standardLength + managedLength + extraLength]; System.arraycopy(attributeNames, 0, allNames, 0, standardLength); if (managedLength > 0) allNames[standardLength] = IMarker.SOURCE_ID; System.arraycopy(extraAttributeNames, 0, allNames, standardLength + managedLength, extraLength); } Object[] allValues = new Object[allNames.length]; // standard attributes int index = 0; allValues[index++] = problem.getMessage(); // message allValues[index++] = problem.isError() ? S_ERROR : S_WARNING; // severity allValues[index++] = new Integer(id); // ID allValues[index++] = new Integer(problem.getSourceStart()); // start int end = problem.getSourceEnd(); allValues[index++] = new Integer(end > 0 ? end + 1 : end); // end allValues[index++] = new Integer(problem.getSourceLineNumber()); // line allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments allValues[index++] = new Integer(problem.getCategoryID()); // category ID // SOURCE_ID attribute for JDT problems if (managedLength > 0) allValues[index++] = JavaBuilder.SOURCE_ID; // optional extra attributes if (extraLength > 0) System.arraycopy(problem.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength); marker.setAttributes(allNames, allValues); if (!this.keepStoringProblemMarkers) return; // only want the one error recorded on this source file } } }
From source file:org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.java
License:Open Source License
protected void storeTasksFor(SourceFile sourceFile, CategorizedProblem[] tasks) throws CoreException { if (sourceFile == null || tasks == null || tasks.length == 0) return;/*from w w w .j a v a 2 s . c om*/ IResource resource = sourceFile.resource; for (int i = 0, l = tasks.length; i < l; i++) { CategorizedProblem task = tasks[i]; if (task.getID() == IProblem.Task) { IMarker marker = resource.createMarker(IJavaModelMarker.TASK_MARKER); Integer priority = P_NORMAL; String compilerPriority = task.getArguments()[2]; if (JavaCore.COMPILER_TASK_PRIORITY_HIGH.equals(compilerPriority)) priority = P_HIGH; else if (JavaCore.COMPILER_TASK_PRIORITY_LOW.equals(compilerPriority)) priority = P_LOW; String[] attributeNames = JAVA_TASK_MARKER_ATTRIBUTE_NAMES; int standardLength = attributeNames.length; String[] allNames = attributeNames; String[] extraAttributeNames = task.getExtraMarkerAttributeNames(); int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length; if (extraLength > 0) { allNames = new String[standardLength + extraLength]; System.arraycopy(attributeNames, 0, allNames, 0, standardLength); System.arraycopy(extraAttributeNames, 0, allNames, standardLength, extraLength); } Object[] allValues = new Object[allNames.length]; // standard attributes int index = 0; allValues[index++] = task.getMessage(); allValues[index++] = priority; allValues[index++] = new Integer(task.getID()); allValues[index++] = new Integer(task.getSourceStart()); allValues[index++] = new Integer(task.getSourceEnd() + 1); allValues[index++] = new Integer(task.getSourceLineNumber()); allValues[index++] = Boolean.FALSE; allValues[index++] = JavaBuilder.SOURCE_ID; // optional extra attributes if (extraLength > 0) System.arraycopy(task.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength); marker.setAttributes(allNames, allValues); } } }
From source file:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
/** * Record a new marker denoting a classpath problem *//*from w ww .j a v a 2 s .co m*/ public void createClasspathProblemMarker(IJavaModelStatus status) { IMarker marker = null; int severity; String[] arguments = CharOperation.NO_STRINGS; boolean isCycleProblem = false, isClasspathFileFormatProblem = false, isOutputOverlapping = false; switch (status.getCode()) { case IJavaModelStatusConstants.CLASSPATH_CYCLE: isCycleProblem = true; if (JavaCore.ERROR.equals(getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))) { severity = IMarker.SEVERITY_ERROR; } else { severity = IMarker.SEVERITY_WARNING; } break; case IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT: isClasspathFileFormatProblem = true; severity = IMarker.SEVERITY_ERROR; break; case IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL: String setting = getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true); if (JavaCore.ERROR.equals(setting)) { severity = IMarker.SEVERITY_ERROR; } else if (JavaCore.WARNING.equals(setting)) { severity = IMarker.SEVERITY_WARNING; } else { return; // setting == IGNORE } break; case IJavaModelStatusConstants.OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE: isOutputOverlapping = true; setting = getOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, true); if (JavaCore.ERROR.equals(setting)) { severity = IMarker.SEVERITY_ERROR; } else if (JavaCore.WARNING.equals(setting)) { severity = IMarker.SEVERITY_WARNING; } else { return; // setting == IGNORE } break; default: IPath path = status.getPath(); if (path != null) arguments = new String[] { path.toString() }; if (JavaCore.ERROR.equals(getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true)) && status.getSeverity() != IStatus.WARNING) { severity = IMarker.SEVERITY_ERROR; } else { severity = IMarker.SEVERITY_WARNING; } break; } try { marker = this.project.createMarker(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER); marker.setAttributes( new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IMarker.LOCATION, IJavaModelMarker.CYCLE_DETECTED, IJavaModelMarker.CLASSPATH_FILE_FORMAT, IJavaModelMarker.OUTPUT_OVERLAPPING_SOURCE, IJavaModelMarker.ID, IJavaModelMarker.ARGUMENTS, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID, }, new Object[] { status.getMessage(), new Integer(severity), Messages.classpath_buildPath, isCycleProblem ? "true" : "false", //$NON-NLS-1$ //$NON-NLS-2$ isClasspathFileFormatProblem ? "true" : "false", //$NON-NLS-1$ //$NON-NLS-2$ isOutputOverlapping ? "true" : "false", //$NON-NLS-1$ //$NON-NLS-2$ new Integer(status.getCode()), Util.getProblemArgumentsForMarker(arguments), new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID, }); } catch (CoreException e) { // could not create marker: cannot do much if (JavaModelManager.VERBOSE) { e.printStackTrace(); } } }
From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianCompilationParticipant.java
License:Open Source License
@Override public void buildFinished(IJavaProject project) { if (ArquillianCoreActivator.getDefault() == null) { return;//from w w w . j av a 2s .c om } try { project.getProject().deleteMarkers(ArquillianConstants.MARKER_CLASS_ID, false, IResource.DEPTH_INFINITE); project.getProject().deleteMarkers(ArquillianConstants.MARKER_RESOURCE_ID, false, IResource.DEPTH_INFINITE); } catch (CoreException e) { ArquillianCoreActivator.log(e); } if (!ArquillianUtility.isValidatorEnabled(project.getProject())) { return; } try { IMarker[] markers = project.getProject().findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); for (IMarker marker : markers) { Integer severity = (Integer) marker.getAttribute(IMarker.SEVERITY); if (severity != null && severity.intValue() == IMarker.SEVERITY_ERROR && JavaBuilder.SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) { return; } } } catch (CoreException e1) { // ignore } List<SourceFile> sourceFiles = new ArrayList(33); this.problemSourceFiles = new ArrayList(3); this.notifier = new BuildNotifier(new NullProgressMonitor(), project.getProject()); this.notifier.begin(); compiler = newCompiler(project); this.notifier.updateProgressDelta(0.05f); this.notifier.subTask(Messages.build_analyzingSources); sourceLocations = nameEnvironment.sourceLocations; try { addAllSourceFiles(sourceFiles, project); } catch (CoreException e) { ArquillianCoreActivator.log(e); } this.notifier.updateProgressDelta(0.10f); if (sourceFiles.size() <= 0) { return; } Iterator<SourceFile> iterator = sourceFiles.iterator(); while (iterator.hasNext()) { SourceFile sourceFile = iterator.next(); boolean remove = false; String preference = ArquillianUtility.getPreference(ArquillianConstants.MISSING_DEPLOYMENT_METHOD, project.getProject()); if (!JavaCore.IGNORE.equals(preference) && !ArquillianSearchEngine.hasDeploymentMethod(sourceFile, project)) { try { Integer severity = ArquillianUtility.getSeverity(preference); storeProblem(sourceFile, "Arquillian test requires at least one method annotated with @Deployment", severity); } catch (CoreException e) { ArquillianCoreActivator.log(e); } remove = true; } preference = ArquillianUtility.getPreference(ArquillianConstants.MISSING_TEST_METHOD, project.getProject()); if (!JavaCore.IGNORE.equals(preference) && !ArquillianSearchEngine.hasTestMethod(sourceFile, project)) { try { Integer severity = ArquillianUtility.getSeverity(preference); storeProblem(sourceFile, "Arquillian test requires at least one method annotated with @Test", severity); } catch (CoreException e) { ArquillianCoreActivator.log(e); } remove = true; } if (remove) { iterator.remove(); } } for (SourceFile sourceFile : sourceFiles) { if (nameEnvironment.setEnvironment(sourceFile, project)) { compile(new SourceFile[] { sourceFile }); } } }