use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class BundleVersionErrorHandler method generateMarkerData.
@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
List<MarkerData> result = new LinkedList<MarkerData>();
IFile bndFile = null;
LineLocation loc = null;
BundleInfo info = (BundleInfo) location.details;
try (ProjectBuilder pb = model.getBuilder(null)) {
for (Builder builder : pb.getSubBuilders()) {
if (builder.getBsn().equals(info.bsn)) {
File propsFile = builder.getPropertiesFile();
// Try to find in the sub-bundle file
if (propsFile != null) {
bndFile = project.getWorkspace().getRoot().getFileForLocation(new Path(propsFile.getAbsolutePath()));
if (bndFile != null) {
loc = findBundleVersionHeader(bndFile);
}
}
if (loc == null) {
// Not found in sub-bundle file, try bnd.bnd
bndFile = project.getFile(Project.BNDFILE);
loc = findBundleVersionHeader(bndFile);
}
if (loc == null) {
// Not found in bnd.bnd, try build.bnd. Marker will appear on bnd.bnd
IFile buildFile = Central.getWorkspaceBuildFile();
loc = findBundleVersionHeader(buildFile);
if (loc != null) {
loc = new LineLocation();
loc.lineNum = 1;
loc.start = 1;
loc.end = 1;
}
}
if (loc == null) {
// Not found in build.bnd, try included files. Marker will appear on bnd.bnd
List<File> extensions = Central.getWorkspace().getIncluded();
if (extensions != null) {
for (File extension : extensions) {
loc = findBundleVersionHeader(Central.toResource(extension));
if (loc != null) {
loc = new LineLocation();
loc.lineNum = 1;
loc.start = 1;
loc.end = 1;
break;
}
}
}
}
if (loc != null) {
Map<String, Object> attribs = new HashMap<String, Object>();
attribs.put(IMarker.MESSAGE, location.message);
attribs.put(IMarker.LINE_NUMBER, loc.lineNum);
attribs.put(IMarker.CHAR_START, loc.start);
attribs.put(IMarker.CHAR_END, loc.end);
String qualifier = null;
String currentVersion = builder.getUnprocessedProperty(Constants.BUNDLE_VERSION, "");
if (currentVersion != null) {
Matcher m = VERSION_ACCEPTING_MACRO.matcher(currentVersion);
if (m.matches()) {
qualifier = m.group(4);
}
}
attribs.put(PROP_SUGGESTED_VERSION, info.suggestedVersion.toString() + (qualifier != null ? '.' + qualifier : ""));
result.add(new MarkerData(bndFile, attribs, true, BndtoolsConstants.MARKER_JAVA_BASELINE));
}
}
}
}
return result;
}
use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class BaselineErrorHandler method generateMarkerData.
@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
List<MarkerData> result = new LinkedList<MarkerData>();
Info baselineInfo = (Info) location.details;
IJavaProject javaProject = JavaCore.create(project);
result.addAll(generatePackageInfoMarkers(baselineInfo, javaProject, location.message));
result.addAll(generateStructuralChangeMarkers(baselineInfo, javaProject));
return result;
}
use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class BaselineErrorHandler method generateRemovedMethodMarker.
List<MarkerData> generateRemovedMethodMarker(IJavaProject javaProject, final String className, final String methodName, final Delta requiresDelta) throws JavaModelException {
final List<MarkerData> markers = new LinkedList<MarkerData>();
final CompilationUnit ast = createAST(javaProject, className);
if (ast != null) {
ast.accept(new ASTVisitor() {
@Override
public boolean visit(TypeDeclaration typeDecl) {
ITypeBinding typeBinding = typeDecl.resolveBinding();
if (typeBinding != null) {
if (typeBinding.getBinaryName().equals(className)) {
Map<String, Object> attribs = new HashMap<String, Object>();
SimpleName nameNode = typeDecl.getName();
attribs.put(IMarker.CHAR_START, nameNode.getStartPosition());
attribs.put(IMarker.CHAR_END, nameNode.getStartPosition() + nameNode.getLength());
String message = String.format("The method '%s' was removed, which requires a %s change to the package.", methodName, requiresDelta);
attribs.put(IMarker.MESSAGE, message);
markers.add(new MarkerData(ast.getJavaElement().getResource(), attribs, false));
return false;
}
}
return true;
}
});
}
return markers;
}
use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class BaselineErrorHandler method generatePackageInfoMarkers.
List<MarkerData> generatePackageInfoMarkers(Info baselineInfo, IJavaProject javaProject, String message) throws JavaModelException {
List<MarkerData> markers = new LinkedList<>();
for (IClasspathEntry entry : javaProject.getRawClasspath()) {
if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) {
IPath entryPath = entry.getPath();
IPath pkgPath = entryPath.append(baselineInfo.packageName.replace('.', '/'));
// Find in packageinfo file
IPath pkgInfoPath = pkgPath.append(PACKAGEINFO);
IFile pkgInfoFile = javaProject.getProject().getWorkspace().getRoot().getFile(pkgInfoPath);
if (pkgInfoFile != null && pkgInfoFile.exists()) {
Map<String, Object> attribs = new HashMap<String, Object>();
attribs.put(IMarker.MESSAGE, message.trim());
attribs.put(PROP_SUGGESTED_VERSION, baselineInfo.suggestedVersion.toString());
LineLocation lineLoc = findVersionLocation(pkgInfoFile.getLocation().toFile());
if (lineLoc != null) {
attribs.put(IMarker.LINE_NUMBER, lineLoc.lineNum);
attribs.put(IMarker.CHAR_START, lineLoc.start);
attribs.put(IMarker.CHAR_END, lineLoc.end);
}
markers.add(new MarkerData(pkgInfoFile, attribs, true));
}
// Find in package-info.java
IPackageFragment pkg = javaProject.findPackageFragment(pkgPath);
if (pkg != null) {
ICompilationUnit pkgInfoJava = pkg.getCompilationUnit(PACKAGEINFOJAVA);
if (pkgInfoJava != null && pkgInfoJava.exists()) {
ISourceRange range = findPackageInfoJavaVersionLocation(baselineInfo.packageName, pkgInfoJava);
Map<String, Object> attribs = new HashMap<String, Object>();
attribs.put(IMarker.MESSAGE, message.trim());
attribs.put(IJavaModelMarker.ID, 8088);
attribs.put(PROP_SUGGESTED_VERSION, baselineInfo.suggestedVersion.toString());
if (range != null) {
attribs.put(IMarker.CHAR_START, range.getOffset());
attribs.put(IMarker.CHAR_END, range.getOffset() + range.getLength());
markers.add(new MarkerData(pkgInfoJava.getResource(), attribs, true, BndtoolsConstants.MARKER_JAVA_BASELINE));
}
}
}
}
}
return markers;
}
use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class BaselineErrorHandler method generateStructuralChangeMarkers.
List<MarkerData> generateStructuralChangeMarkers(Info baselineInfo, IJavaProject javaProject) throws JavaModelException {
List<MarkerData> markers = new LinkedList<MarkerData>();
Delta packageDelta = baselineInfo.packageDiff.getDelta();
// Iterate into the package member diffs
for (Diff pkgMemberDiff : baselineInfo.packageDiff.getChildren()) {
// Skip deltas that have lesser significance than the overall package delta
if (pkgMemberDiff.getDelta().ordinal() < packageDelta.ordinal())
continue;
if (Delta.ADDED == pkgMemberDiff.getDelta()) {
@SuppressWarnings("unused") Tree pkgMember = pkgMemberDiff.getNewer();
// markers.addAll(generateAddedTypeMarker(javaProject, pkgMember.getName(), pkgMember.ifAdded()));
} else if (Delta.REMOVED == pkgMemberDiff.getDelta()) {
} else {
Tree pkgMember = pkgMemberDiff.getOlder();
if (pkgMember != null && (Type.INTERFACE == pkgMember.getType() || Type.CLASS == pkgMember.getType())) {
String className = pkgMember.getName();
// Iterate into the class member diffs
for (Diff classMemberDiff : pkgMemberDiff.getChildren()) {
// Skip deltas that have lesser significance than the overall package delta (again)
if (classMemberDiff.getDelta().ordinal() < packageDelta.ordinal())
continue;
if (Delta.ADDED == classMemberDiff.getDelta()) {
Tree classMember = classMemberDiff.getNewer();
if (Type.METHOD == classMember.getType())
markers.addAll(generateAddedMethodMarker(javaProject, className, classMember.getName(), classMember.ifAdded()));
} else if (Delta.REMOVED == classMemberDiff.getDelta()) {
Tree classMember = classMemberDiff.getOlder();
if (Type.METHOD == classMember.getType()) {
markers.addAll(generateRemovedMethodMarker(javaProject, className, classMember.getName(), classMember.ifRemoved()));
}
}
}
}
}
}
return markers;
}
Aggregations