Improve build and local deployment
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 6 Mar 2024 16:09:24 +0000 (17:09 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 6 Mar 2024 16:09:24 +0000 (17:09 +0100)
12 files changed:
Makefile
Makefile-rcp.mk
org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsDeploymentImpl.java
org.argeo.init/src/org/argeo/init/RuntimeManagerMain.java
org.argeo.init/src/org/argeo/init/logging/ThinLoggerFinder.java
org.argeo.init/src/org/argeo/init/logging/ThinLogging.java
sdk/argeo-build
swt/org.argeo.swt.minidesktop/.project
swt/org.argeo.swt.minidesktop/OSGI-INF/miniDesktop.xml [new file with mode: 0644]
swt/org.argeo.swt.minidesktop/bnd.bnd
swt/org.argeo.swt.minidesktop/build.properties
swt/org.argeo.swt.minidesktop/src/org/argeo/minidesktop/MiniDesktopManager.java

index 9011b2dc0aa267d56969f17b19c082368e37144b..407f4214b3412eb99c4a08aefcb2129537423069 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,4 @@
 include sdk.mk
-.PHONY: clean all osgi
-
-all: osgi
-       $(MAKE) -f Makefile-rcp.mk all
-       
-install: osgi-install
-
-uninstall: osgi-uninstall
 
 A2_CATEGORY = org.argeo.cms
 
@@ -49,10 +41,18 @@ org.argeo.api.uuid \
 org.argeo.api.acr \
 org.argeo.api.cms
 
-clean:
-       rm -rf $(BUILD_BASE)
+all: osgi-all
+       $(MAKE) -f Makefile-rcp.mk all
+       
+clean: osgi-clean
        $(MAKE) -f Makefile-rcp.mk clean
 
-A2_BUNDLES_CLASSPATH = $(subst $(space),$(pathsep),$(strip $(A2_BUNDLES)))
+install: osgi-install
+       $(MAKE) -f Makefile-rcp.mk install
+
+uninstall: osgi-uninstall
+       $(MAKE) -f Makefile-rcp.mk uninstall
+
+include  $(SDK_SRC_BASE)/sdk/argeo-build/osgi.mk
 
-include  $(SDK_SRC_BASE)/sdk/argeo-build/osgi.mk
\ No newline at end of file
+.PHONY: clean all install uninstall
index 1fb93728c82474391695677a9bbce12c52a90d05..a9e262843550f864904cdc22dcc0c40c6275a5c1 100644 (file)
@@ -1,7 +1,4 @@
 include sdk.mk
-.PHONY: clean all osgi
-
-all: osgi 
 
 A2_CATEGORY = org.argeo.cms
 
@@ -19,9 +16,16 @@ osgi/api/org.argeo.tp.osgi \
 swt/rcp/org.argeo.tp.swt \
 lib/linux/x86_64/swt/rcp/org.argeo.tp.swt \
 
-clean:
-       rm -rf $(BUILD_BASE)
-
 VPATH = .:swt/rcp
 
-include  $(SDK_SRC_BASE)/sdk/argeo-build/osgi.mk
\ No newline at end of file
+all: osgi-all
+
+clean: osgi-clean
+       
+install: osgi-install
+
+uninstall: osgi-uninstall
+
+include  $(SDK_SRC_BASE)/sdk/argeo-build/osgi.mk
+
+.PHONY: clean all install uninstall
index 52f97fd8d4224d71a7fe9ec7c26a5bfd985b8d5e..0d53a09b090f2a33dedf5e500e5c164593675a54 100644 (file)
@@ -64,7 +64,10 @@ public class CmsDeploymentImpl implements CmsDeployment {
        public void setHttpServer(HttpServer httpServer) {
                Objects.requireNonNull(httpServer);
                if (this.httpServer.isDone())
-                       throw new IllegalStateException("HTTP server is already set");
+                       if (httpExpected)
+                               throw new IllegalStateException("HTTP server is already set");
+                       else
+                               return;// ignore
                // create contexts whose handlers had already been published
                synchronized (httpHandlers) {
                        synchronized (httpAuthenticators) {
@@ -107,7 +110,8 @@ public class CmsDeploymentImpl implements CmsDeployment {
                }
                if (!this.httpServer.isDone())
                        throw new IllegalStateException("HTTP server is not set");
-               HttpContext httpContext = httpServer.resultNow().createContext(contextPath);
+               // TODO use resultNow when switching to Java 21
+               HttpContext httpContext = httpServer.join().createContext(contextPath);
                // we want to set the authenticator BEFORE the handler actually becomes active
                httpContext.setAuthenticator(authenticator);
                httpContext.setHandler(httpHandler);
@@ -121,7 +125,8 @@ public class CmsDeploymentImpl implements CmsDeployment {
                httpHandlers.remove(contextPath);
                if (!httpServer.isDone())
                        return;
-               httpServer.resultNow().removeContext(contextPath);
+               // TODO use resultNow when switching to Java 21
+               httpServer.join().removeContext(contextPath);
                log.debug(() -> "Removed handler " + contextPath + " : " + httpHandler.getClass().getName());
        }
 
index 9c8692c4b3ca401634a4d365e0d9dd4c14daa46a..5a8331dfeeeb2cf2b4b0e32f2fd6139a7d860838 100644 (file)
@@ -59,9 +59,22 @@ public class RuntimeManagerMain implements RuntimeManager {
 
                logger.log(Level.TRACE, () -> "Runtime manager configuration: " + configuration);
 
+//             System.out.println("java.library.path=" + System.getProperty("java.library.path"));
        }
 
        public void run() {
+//             try {
+//                     for (Path p : Files.newDirectoryStream(Paths.get("/usr/local/lib/a2"), "*.so")) {
+//                             try {
+//                                     System.load(p.toString());
+//                             } catch (UnsatisfiedLinkError e) {
+//                                     e.printStackTrace();
+//                             }
+//                     }
+//             } catch (IOException e) {
+//                     e.printStackTrace();
+//             }
+
                OsgiRuntimeContext managerRuntimeContext = new OsgiRuntimeContext(configuration);
                try {
                        managerRuntimeContext.run();
index 5be74fef9aa1d130d18ec0e64cfbc80c90396a01..3fa2bc868848baa2ba1528cdd189e4f958a137c6 100644 (file)
@@ -30,7 +30,10 @@ public class ThinLoggerFinder extends LoggerFinder
        @Override
        public Logger getLogger(String name, Module module) {
                lazyInit();
-               return logging.getLogger(name, module);
+               Objects.requireNonNull(name);
+               Logger logger = logging.getLogger(name, module);
+               Objects.requireNonNull(logger);
+               return logger;
        }
 
        private static void init() {
index 2b2f6b3a74f3b6294aaf109ed299f22a370720a3..d615678cd886e63c63b06f95080d3c3d53593f17 100644 (file)
@@ -194,6 +194,7 @@ class ThinLogging implements Consumer<Map<String, Object>> {
                if (!loggers.containsKey(name)) {
                        ThinLogger logger = new ThinLogger(name, computeApplicableLevel(name));
                        loggers.put(name, logger);
+                       return logger;
                }
                return loggers.get(name);
        }
index 08bc9ba6656515e235eb269c31bc2b1e93748055..6f8e29e850f9fcfa5149e296e650355fab930752 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 08bc9ba6656515e235eb269c31bc2b1e93748055
+Subproject commit 6f8e29e850f9fcfa5149e296e650355fab930752
index b6c2c1ae476b0f53aa434cc1ceb9814396821b3e..764a285b21b0e9b087cd495a25aeb4ccb1353415 100644 (file)
                        <arguments>
                        </arguments>
                </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ds.core.builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
        </buildSpec>
        <natures>
                <nature>org.eclipse.pde.PluginNature</nature>
diff --git a/swt/org.argeo.swt.minidesktop/OSGI-INF/miniDesktop.xml b/swt/org.argeo.swt.minidesktop/OSGI-INF/miniDesktop.xml
new file mode 100644 (file)
index 0000000..51913c7
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.argeo.swt.minidesktop">
+   <implementation class="org.argeo.minidesktop.MiniDesktopManager"/>
+</scr:component>
index f3c13bec58e54fee4c8561e1cfec87b64e29ad74..1b43de5f74bd971c12081e6dbf500e9486c20a1e 100644 (file)
@@ -1,2 +1,5 @@
 Import-Package: org.eclipse.swt,\
 *
+
+Service-Component:\
+OSGI-INF/miniDesktop.xml,\
index 34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2..04bd7e126fa8cf025c3292204f420db11a8d207f 100644 (file)
@@ -1,4 +1,5 @@
+bin.includes = META-INF/,\
+               .,\
+               OSGI-INF/miniDesktop.xml
 source.. = src/
 output.. = bin/
-bin.includes = META-INF/,\
-               .
index adb2a55ba95f6393857c8a45877981204bed1642..6604b4f3e313a8371ebbdab3c39eb5e9b9fb79af 100644 (file)
@@ -44,82 +44,100 @@ public class MiniDesktopManager {
                this.stacking = stacking;
        }
 
+       public MiniDesktopManager() {
+               this(false, false);
+       }
+
+       public void start() {
+               init();
+       }
+
+       public void stop() {
+               dispose();
+               if (display != null) {
+                       display.dispose();
+                       display = null;
+               }
+       }
+
        public void init() {
                Display.setAppName("Mini SWT Desktop");
                display = Display.getCurrent();
                if (display != null)
                        throw new IllegalStateException("Already a display " + display);
-               display = new Display();
+               display = Display.getDefault();
 
-               if (display.getTouchEnabled()) {
-                       System.out.println("Touch enabled.");
-               }
-
-               images = new MiniDesktopImages(display);
+               display.syncExec(() -> {
+                       if (display.getTouchEnabled()) {
+                               System.out.println("Touch enabled.");
+                       }
 
-               int toolBarSize = 48;
+                       images = new MiniDesktopImages(display);
+
+                       int toolBarSize = 48;
+
+                       if (isFullscreen()) {
+                               rootShell = new Shell(display, SWT.NO_TRIM);
+                               rootShell.setFullScreen(true);
+                               Rectangle bounds = display.getBounds();
+                               rootShell.setLocation(0, 0);
+                               rootShell.setSize(bounds.width, bounds.height);
+                       } else {
+                               rootShell = new Shell(display, SWT.CLOSE | SWT.RESIZE);
+                               Rectangle shellArea = rootShell.computeTrim(200, 200, 800, 480);
+                               rootShell.setSize(shellArea.width, shellArea.height);
+                               rootShell.setText(Display.getAppName());
+                               rootShell.setImage(images.terminalIcon);
+                       }
 
-               if (isFullscreen()) {
-                       rootShell = new Shell(display, SWT.NO_TRIM);
-                       rootShell.setFullScreen(true);
-                       Rectangle bounds = display.getBounds();
-                       rootShell.setLocation(0, 0);
-                       rootShell.setSize(bounds.width, bounds.height);
-               } else {
-                       rootShell = new Shell(display, SWT.CLOSE | SWT.RESIZE);
-                       Rectangle shellArea = rootShell.computeTrim(200, 200, 800, 480);
-                       rootShell.setSize(shellArea.width, shellArea.height);
-                       rootShell.setText(Display.getAppName());
-                       rootShell.setImage(images.terminalIcon);
-               }
+                       rootShell.setLayout(noSpaceGridLayout(new GridLayout(2, false)));
+                       Composite toolBarArea = new Composite(rootShell, SWT.NONE);
+                       toolBarArea.setLayoutData(new GridData(toolBarSize, rootShell.getSize().y));
 
-               rootShell.setLayout(noSpaceGridLayout(new GridLayout(2, false)));
-               Composite toolBarArea = new Composite(rootShell, SWT.NONE);
-               toolBarArea.setLayoutData(new GridData(toolBarSize, rootShell.getSize().y));
-
-               ToolBar toolBar;
-               if (isFullscreen()) {
-                       toolBarShell = new Shell(rootShell, SWT.NO_TRIM | SWT.ON_TOP);
-                       toolBar = new ToolBar(toolBarShell, SWT.VERTICAL | SWT.FLAT | SWT.BORDER);
-                       createDock(toolBar);
-                       toolBarShell.pack();
-                       toolBarArea.setLayoutData(new GridData(toolBar.getSize().x, toolBar.getSize().y));
-               } else {
-                       toolBar = new ToolBar(toolBarArea, SWT.VERTICAL | SWT.FLAT | SWT.BORDER);
-                       createDock(toolBar);
-                       toolBarArea.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
-               }
+                       ToolBar toolBar;
+                       if (isFullscreen()) {
+                               toolBarShell = new Shell(rootShell, SWT.NO_TRIM | SWT.ON_TOP);
+                               toolBar = new ToolBar(toolBarShell, SWT.VERTICAL | SWT.FLAT | SWT.BORDER);
+                               createDock(toolBar);
+                               toolBarShell.pack();
+                               toolBarArea.setLayoutData(new GridData(toolBar.getSize().x, toolBar.getSize().y));
+                       } else {
+                               toolBar = new ToolBar(toolBarArea, SWT.VERTICAL | SWT.FLAT | SWT.BORDER);
+                               createDock(toolBar);
+                               toolBarArea.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+                       }
 
-               if (isStacking()) {
-                       tabFolder = new CTabFolder(rootShell, SWT.MULTI | SWT.BORDER | SWT.BOTTOM);
-                       tabFolder.setLayout(noSpaceGridLayout(new GridLayout()));
-                       tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
-                       Color selectionBackground = display.getSystemColor(SWT.COLOR_LIST_SELECTION);
-                       tabFolder.setSelectionBackground(selectionBackground);
-
-                       // background
-                       Control background = createBackground(tabFolder);
-                       CTabItem homeTabItem = new CTabItem(tabFolder, SWT.NONE);
-                       homeTabItem.setText("Home");
-                       homeTabItem.setImage(images.homeIcon);
-                       homeTabItem.setControl(background);
-                       tabFolder.setFocus();
-               } else {
-                       createBackground(rootShell);
-               }
+                       if (isStacking()) {
+                               tabFolder = new CTabFolder(rootShell, SWT.MULTI | SWT.BORDER | SWT.BOTTOM);
+                               tabFolder.setLayout(noSpaceGridLayout(new GridLayout()));
+                               tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+                               Color selectionBackground = display.getSystemColor(SWT.COLOR_LIST_SELECTION);
+                               tabFolder.setSelectionBackground(selectionBackground);
+
+                               // background
+                               Control background = createBackground(tabFolder);
+                               CTabItem homeTabItem = new CTabItem(tabFolder, SWT.NONE);
+                               homeTabItem.setText("Home");
+                               homeTabItem.setImage(images.homeIcon);
+                               homeTabItem.setControl(background);
+                               tabFolder.setFocus();
+                       } else {
+                               createBackground(rootShell);
+                       }
 
-               rootShell.open();
-               // rootShell.layout(true, true);
+                       rootShell.open();
+                       // rootShell.layout(true, true);
 
-               if (toolBarShell != null) {
-                       int toolBarShellY = (display.getBounds().height - toolBar.getSize().y) / 2;
-                       toolBarShell.setLocation(0, toolBarShellY);
-                       toolBarShell.open();
-               }
+                       if (toolBarShell != null) {
+                               int toolBarShellY = (display.getBounds().height - toolBar.getSize().y) / 2;
+                               toolBarShell.setLocation(0, toolBarShellY);
+                               toolBarShell.open();
+                       }
 
-               long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime();
-               System.out.println("SWT Mini Desktop Manager available in " + jvmUptime + " ms.");
+                       long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime();
+                       System.out.println("SWT Mini Desktop Manager available in " + jvmUptime + " ms.");
+               });
        }
 
        protected void createDock(ToolBar toolBar) {