Skip to content

Commit

Permalink
Merge pull request #5969 from pkriens/issue/5828-quick-fix-version
Browse files Browse the repository at this point in the history
Issue/5828 quick fix version
  • Loading branch information
pkriens authored Jan 15, 2024
2 parents 641fecc + acfd3e2 commit 326f3cd
Show file tree
Hide file tree
Showing 47 changed files with 6,857 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SnapshotTest {
static final String org_apache_felix_scr = "org.apache.felix.scr;version='[2.1.12,2.1.13)'";
static final String org_apache_felix_log = "org.apache.felix.log;version='[1.2.0,1.2.1)'";
static final String org_apache_felix_configadmin = "org.apache.felix.configadmin;version='[1.9.10,1.9.11)'";
static final String org_apache_felix_gogo_runtime = "org.apache.felix.gogo.runtime;version='[1.1.0,1.1.0]'";
static final String org_apache_felix_gogo_runtime = "org.apache.felix.gogo.runtime;version='[1.1.6,1.1.6]'";
@InjectTemporaryDirectory
File tmp;
LaunchpadBuilder builder;
Expand Down
6 changes: 6 additions & 0 deletions biz.aQute.bnd/src/aQute/bnd/main/bnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,10 @@ public void _grep(grepOptions opts) throws Exception {
});
}
Manifest m = in.getManifest();
if (m == null) {
warning("no manifest in %s", file);
continue;
}
for (Object header : m.getMainAttributes()
.keySet()) {
Attributes.Name name = (Name) header;
Expand All @@ -2848,6 +2852,8 @@ public void _grep(grepOptions opts) throws Exception {
}
}
}
} catch (Exception e) {
error("faild to load file %s : %s", file, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IPro
}
case IProblem.UndefinedMethod : {
ASTNode node = location.getCoveredNode(context.getASTRoot());
if (node == null)
continue;
ASTNode parent = node.getParent();
UNDEFINED_METHOD: while (parent != null) {
switch (parent.getNodeType()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package bndtools.core.test.editors.quickfix;

import static org.assertj.core.api.Assertions.assertThat;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class BaseModelTest extends AbstractBuildpathQuickFixProcessorTest {

@BeforeAll
static void beforeAll() throws Exception {
clearBuildpath();
}

@Test
void test() throws JavaModelException {
ICompilationUnit icu = pack.createCompilationUnit("Test.java", "package foo;\n", true, null);
assertThat(icu).isNotNull();
}

}
9 changes: 9 additions & 0 deletions bndtools.core/_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,21 @@
icon="icons/blueprint.png" name="OSGi Blueprint Descriptor"
project="false">
</wizard>
<wizard id="bndtools.newPackageInfo"
category="bndtools.wizardCategory"
class="org.bndtools.core.ui.wizards.packge.NewPackageInfoWizard"
finalPerspective="bndtools.perspective"
preferredPerspectives="bndtools.perspective"
icon="icons/package_folder_impexp.gif" name="package-info.java"
project="false">
</wizard>
<wizard id="bndtools.newIndexWizard"
category="bndtools.wizardCategory"
class="org.bndtools.core.ui.wizards.index.NewIndexWizard"
icon="icons/repoindex.png" name="OSGi Repository Index"
project="false">
</wizard>

<wizard name="OSGi Declarative Services Component"
icon="${icons.component}" category="bndtools.wizardCategory"
id="bndtools.newDsComponentWizard">
Expand Down
7 changes: 5 additions & 2 deletions bndtools.core/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Export-Package: org.osgi.service.metatype.annotations
bndtools.*,\
org.bndtools.build.api.*, \
org.bndtools.core.*,\
org.bndtools.facade
org.bndtools.facade, \
org.bndtools.refactor.*

-conditionalpackage: \
aQute.lib.*,\
Expand Down Expand Up @@ -111,7 +112,9 @@ Export-Package: org.osgi.service.metatype.annotations
org.eclipse.ui.ide.application;version='1.3',\
org.eclipse.ui.console,\
org.eclipse.e4.core.services,\
org.osgi.service.event
org.osgi.service.event,\
org.eclipse.jdt.annotation,\
org.apache.felix.gogo.runtime;version=1.1.6

-testpath: \
slf4j.api,\
Expand Down
14 changes: 14 additions & 0 deletions bndtools.core/icons.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ icons.bundle.new=icons/bundle-new.png
icons.component=icons/component.png
icons.service=icons/service.png
icons.capreq=icons/connections.png
icons.version-plain=icons/version-plain.png
icons.version-major=icons/version-major.png
icons.version-minor=icons/version-minor.png
icons.aA=icons/lower-to-upper.png
icons.Aa=icons/upper-to-lower.png

# Gogo things

icons.gogo=icons/gogo.png

# Java Things
icons.java=icons/java.png
Expand All @@ -23,6 +32,9 @@ icons.bnd.workspace.bndlayout=icons/bnd-layout-24.png
icons.bnd.workspace.standalone=icons/standalone-layout-24.png
icons.bndeditor.page=icons/page_white_text.png
icons.bndeditor.plugin=icons/plugin.png
icons.package-info=icons/package-info.png
icons.package-export=icons/package-info.png


# Generic Objects
icons.lock=icons/lock.png
Expand All @@ -47,6 +59,8 @@ icons.download.disabled=icons/download_d.png
icons.resolve=icons/lightbulb.png
icons.match=icons/star-small.png
icons.help=icons/help.gif
icons.checked=icons/checked.png
icons.unchecked=icons/unchecked.png

# Repository View
icons.add=icons/add_obj.png
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions bndtools.core/src/bndtools/PartConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public final class PartConstants {
public static final String WIZARD_ID_NEWWRAPPROJECT = PREFIX + "newWrapProjWiz";
public static final String WIZARD_ID_NEWBLUEPRINT_XML = PREFIX + "newBlueprintXml";

public static final String WIZARD_ID_NEWPACKAGE_INFO = PREFIX + "newPackageInfo";
public static final String WIZARD_ID_NEWDSCOMPONENT = PREFIX + "newDsComponentWizard";

private PartConstants() {}
}
14 changes: 11 additions & 3 deletions bndtools.core/src/bndtools/editor/contents/PackageInfoStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.eclipse.jdt.core.JavaModelException;
import org.osgi.framework.Version;

import aQute.lib.io.IO;
import aQute.bnd.unmodifiable.Sets;
import aQute.lib.io.IO;

/**
* Models the three available styles for versioning exported packages.
Expand All @@ -37,8 +37,12 @@ public enum PackageInfoStyle {
/**
* Annotated package-info.java, using the OSGi spec annotations from R6.
*/
SpecAnnotation("package-info.java", "@org.osgi.annotation.versioning.Version(\"%s\")%npackage %s;%n",
"org.osgi.annotation.versioning.Version");
SpecAnnotation("package-info.java", """
@org.osgi.annotation.bundle.Export
@org.osgi.annotation.versioning.Version(\"%s\")
package %s;
""", "org.osgi.annotation.versioning.Version");

private static final ILogger logger = Logger.getLogger(PackageInfoStyle.class);

Expand Down Expand Up @@ -85,6 +89,10 @@ public static PackageInfoStyle findExisting(File dir) throws IOException {
return null;
}

/*
* we now just use the new style so we deprecated this.
*/
@Deprecated()
public static PackageInfoStyle calculatePackageInfoStyle(IProject project) {
IJavaProject javaProject = JavaCore.create(project);
if (javaProject == null)
Expand Down
100 changes: 100 additions & 0 deletions bndtools.core/src/bndtools/editor/exports/AddExportProposal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package bndtools.editor.exports;

import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageDeclaration;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.text.edits.TextEdit;

public class AddExportProposal implements IJavaCompletionProposal {
private static final String ORG_OSGI_ANNOTATION_BUNDLE_EXPORT = "org.osgi.annotation.bundle.Export";

final ICompilationUnit unit;

public AddExportProposal(ICompilationUnit unit) {
this.unit = unit;
}

boolean isApplicable() {
if (unit.getElementName()
.equals("package-info.java")) {
IPackageDeclaration pd = unit.getPackageDeclaration(null);
IAnnotation annotation = pd.getAnnotation(ORG_OSGI_ANNOTATION_BUNDLE_EXPORT);
return annotation == null;
} else
return false;
}

@Override
public void apply(IDocument document) {
try {
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
parser.setSource(unit);
parser.setResolveBindings(true);

CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
AST ast = astRoot.getAST();

ASTRewrite rewriter = ASTRewrite.create(ast);
PackageDeclaration packageDeclaration = astRoot.getPackage();

if (packageDeclaration != null) {
Annotation annotation = ast.newMarkerAnnotation();
annotation.setTypeName(ast.newSimpleName(ORG_OSGI_ANNOTATION_BUNDLE_EXPORT));
rewriter.getListRewrite(packageDeclaration, PackageDeclaration.ANNOTATIONS_PROPERTY)
.insertFirst(annotation, null);

TextEdit edits = rewriter.rewriteAST();
unit.applyTextEdit(edits, null);
unit.getBuffer()
.setContents(astRoot.toString());
}
} catch (JavaModelException e) {
e.printStackTrace();
// Handle exception
}
}

@Override
public Point getSelection(IDocument document) {
return null; // Return the new selection after insertion, if applicable
}

@Override
public String getAdditionalProposalInfo() {
return "Add Export & Version annotation";
}

@Override
public String getDisplayString() {
return "Add Export annotation";
}

@Override
public Image getImage() {
return null; // You can return an image to be displayed with the
// proposal
}

@Override
public IContextInformation getContextInformation() {
return null; // Context information related to this proposal, if
// applicable
}

@Override
public int getRelevance() {
return 1000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ private static void generatePackageInfos(final Collection<? extends FileVersionT
if (locations != null && locations.length > 0) {
IContainer container = locations[0];

PackageInfoStyle packageInfoStyle = PackageInfoStyle
.calculatePackageInfoStyle(container.getProject());
PackageInfoStyle packageInfoStyle = PackageInfoStyle.SpecAnnotation;
IFile pkgInfoFile = container.getFile(new Path(packageInfoStyle.getFileName()));

try {
Expand Down
3 changes: 2 additions & 1 deletion bndtools.core/src/bndtools/perspective/BndPerspective.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ public void createInitialLayout(IPageLayout layout) {
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWPROJECT);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWWORKSPACE);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWBNDRUN);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWWRAPPROJECT);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWBND);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWBLUEPRINT_XML);
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWPACKAGE_INFO);
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewPackageCreationWizard"); //$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewClassCreationWizard"); //$NON-NLS-1$
layout.addNewWizardShortcut(PartConstants.WIZARD_ID_NEWDSCOMPONENT);
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard"); //$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewEnumCreationWizard"); //$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard"); //$NON-NLS-1$
Expand Down
41 changes: 41 additions & 0 deletions bndtools.core/src/bndtools/utils/JobSupport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package bndtools.utils;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Display;

import aQute.bnd.exceptions.ConsumerWithException;
import aQute.bnd.exceptions.FunctionWithException;
import bndtools.Plugin;

public class JobSupport {
public static <T> void background(String message, FunctionWithException<IProgressMonitor, ? extends T> background,
ConsumerWithException<? super T> onDisplayThread) {

Job job = new Job(message) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
T result = background.apply(monitor);
if (monitor.isCanceled())
return Status.CANCEL_STATUS;

Display.getDefault()
.asyncExec(() -> {
try {
onDisplayThread.accept(result);
} catch (Exception e) {
}
});
return Status.OK_STATUS;
} catch (Exception e) {
return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, message, e);
}
}
};
job.schedule();
}

}
26 changes: 23 additions & 3 deletions bndtools.core/src/org/bndtools/core/ui/icons/Icons.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,29 @@

public final class Icons {

private static final String ICONS_MISSING_GIF = "icons/missing.gif";
private static ISharedImages shared = PlatformUI.getWorkbench()
.getSharedImages();
private static final String ICONS_MISSING_GIF = "icons/missing.gif";
private static final ISharedImages shared;
static {
ISharedImages images;
try {
images = PlatformUI.getWorkbench()
.getSharedImages();
} catch (Throwable e) {
images = new ISharedImages() {
@Override
public Image getImage(String symbolicName) {
return null;
}

@Override
public ImageDescriptor getImageDescriptor(String symbolicName) {
return null;
}
};
}
shared = images;

}

private static class Key {
final String name;
Expand Down
Loading

0 comments on commit 326f3cd

Please sign in to comment.