From f5bb81c387aa459385dcf721bbce00f49bbbeb0b Mon Sep 17 00:00:00 2001 From: Alexander Ries Date: Thu, 14 Jan 2016 14:07:45 +0100 Subject: [PATCH] added ManifestLinker to com.sap.sse.gwt and using it now in dashboard bundle --- .../META-INF/MANIFEST.MF | 4 +- .../RibDashboard.html | 2 +- .../WEB-INF/web.xml | 5 + .../gwt/client/RibDashboardEntryPoint.java | 4 - .../linker/DashboardManifestLinker.java | 22 +++ .../gwt/client/linker/cache.manifest.template | 14 ++ .../dashboards/gwt/RibDashboard.gwt.xml | 4 + java/com.sap.sse.gwt/META-INF/MANIFEST.MF | 9 +- .../sse/gwt/client/linker/ManifestLinker.java | 135 ++++++++++++++++++ 9 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/DashboardManifestLinker.java create mode 100644 java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/cache.manifest.template create mode 100644 java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/linker/ManifestLinker.java diff --git a/java/com.sap.sailing.dashboards.gwt/META-INF/MANIFEST.MF b/java/com.sap.sailing.dashboards.gwt/META-INF/MANIFEST.MF index 7af263e912b..53b9b480d53 100644 --- a/java/com.sap.sailing.dashboards.gwt/META-INF/MANIFEST.MF +++ b/java/com.sap.sailing.dashboards.gwt/META-INF/MANIFEST.MF @@ -25,10 +25,12 @@ Require-Bundle: com.sap.sailing.domain, com.sap.sse.gwt.adminconsole, org.apache.commons.math;bundle-version="2.1.0" Bundle-ActivationPolicy: lazy -Import-Package: com.sap.sse.util, +Import-Package: com.google.gwt.core.ext.linker, + com.sap.sse.util, javax.servlet;version="3.1.0", javax.servlet.descriptor;version="3.1.0", javax.servlet.http;version="3.1.0", + org.apache.commons.io, org.osgi.framework;version="1.5.0", org.osgi.util.tracker Web-ContextPath: /dashboards diff --git a/java/com.sap.sailing.dashboards.gwt/RibDashboard.html b/java/com.sap.sailing.dashboards.gwt/RibDashboard.html index d1f7fa68c2b..44d3171f5e4 100644 --- a/java/com.sap.sailing.dashboards.gwt/RibDashboard.html +++ b/java/com.sap.sailing.dashboards.gwt/RibDashboard.html @@ -5,7 +5,7 @@ - + diff --git a/java/com.sap.sailing.dashboards.gwt/WEB-INF/web.xml b/java/com.sap.sailing.dashboards.gwt/WEB-INF/web.xml index c6c14b60dbb..9f1d66d19d6 100644 --- a/java/com.sap.sailing.dashboards.gwt/WEB-INF/web.xml +++ b/java/com.sap.sailing.dashboards.gwt/WEB-INF/web.xml @@ -48,4 +48,9 @@ /com.sap.sailing.dashboards.gwt.RibDashboard/remote_logging + + manifest + text/cache-manifest + + diff --git a/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/RibDashboardEntryPoint.java b/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/RibDashboardEntryPoint.java index d1ca55aa36a..82aabb4338f 100644 --- a/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/RibDashboardEntryPoint.java +++ b/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/RibDashboardEntryPoint.java @@ -3,7 +3,6 @@ package com.sap.sailing.dashboards.gwt.client; import com.google.gwt.user.client.ui.RootLayoutPanel; import com.googlecode.mgwt.ui.client.MGWT; import com.googlecode.mgwt.ui.client.MGWTSettings; -import com.googlecode.mgwt.ui.client.MGWTSettings.StatusBarStyle; import com.googlecode.mgwt.ui.client.MGWTSettings.ViewPort; import com.googlecode.mgwt.ui.client.MGWTStyle; import com.sap.sailing.dashboards.gwt.client.dashboardpanel.DashboardPanel; @@ -34,9 +33,6 @@ public class RibDashboardEntryPoint extends AbstractEntryPoint { viewPort.setUserScaleAble(false).setMinimumScale(1.0).setMinimumScale(1.0).setMaximumScale(1.0); MGWTSettings settings = new MGWTSettings(); settings.setViewPort(viewPort); - settings.setFullscreen(true); - settings.setPreventScrolling(true); - settings.setStatusBarStyle(StatusBarStyle.BLACK_TRANSLUCENT); MGWT.applySettings(settings); } diff --git a/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/DashboardManifestLinker.java b/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/DashboardManifestLinker.java new file mode 100644 index 00000000000..a630e5cbe1b --- /dev/null +++ b/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/DashboardManifestLinker.java @@ -0,0 +1,22 @@ +package com.sap.sailing.dashboards.gwt.client.linker; + +import com.google.gwt.core.ext.linker.Shardable; +import com.sap.sse.gwt.client.linker.ManifestLinker; + +/** + * @author Alexander Ries (D062114) + * + */ + +@Shardable +public class DashboardManifestLinker extends ManifestLinker { + + @Override + protected String[] staticCachedFiles() { + return new String[] { "/dashboards/RibDashboard.html", + "/dashboards/RibDashboard.css", + "/dashboards/images/dashboardicon.png", + "/dashboards/js/jquery-1.5.2.min.js", + "/sailing-fontface-1.0.cache.css"}; + } +} diff --git a/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/cache.manifest.template b/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/cache.manifest.template new file mode 100644 index 00000000000..dd838fa13be --- /dev/null +++ b/java/com.sap.sailing.dashboards.gwt/src/main/java/com/sap/sailing/dashboards/gwt/client/linker/cache.manifest.template @@ -0,0 +1,14 @@ +CACHE MANIFEST +# Unique id #$UNIQUEID$ +# Build version $BUILDVERSION$ +# Change this every time for cache to invalidate. +# Do not delete the sections, as safari requires this file structure!!! + +NETWORK: +* + +CACHE: +$STATICAPPFILES$ +$GENAPPFILES$ + +FALLBACK: \ No newline at end of file diff --git a/java/com.sap.sailing.dashboards.gwt/src/main/resources/com/sap/sailing/dashboards/gwt/RibDashboard.gwt.xml b/java/com.sap.sailing.dashboards.gwt/src/main/resources/com/sap/sailing/dashboards/gwt/RibDashboard.gwt.xml index 8dfe25e1e71..e445bf428b1 100644 --- a/java/com.sap.sailing.dashboards.gwt/src/main/resources/com/sap/sailing/dashboards/gwt/RibDashboard.gwt.xml +++ b/java/com.sap.sailing.dashboards.gwt/src/main/resources/com/sap/sailing/dashboards/gwt/RibDashboard.gwt.xml @@ -57,6 +57,10 @@ + + + + diff --git a/java/com.sap.sse.gwt/META-INF/MANIFEST.MF b/java/com.sap.sse.gwt/META-INF/MANIFEST.MF index 0d827bce8f4..febe9d19157 100644 --- a/java/com.sap.sse.gwt/META-INF/MANIFEST.MF +++ b/java/com.sap.sse.gwt/META-INF/MANIFEST.MF @@ -9,9 +9,13 @@ Require-Bundle: com.google.gwt.osgi;bundle-version="2.7.0", com.sap.sse.common, com.sap.sse.filestorage Bundle-ActivationPolicy: lazy -Import-Package: javax.servlet;version="2.6.0", - javax.servlet.http;version="2.6.0", +Import-Package: com.google.gwt.core.ext, + com.google.gwt.core.ext.linker, + com.google.gwt.core.ext.linker.impl, + javax.servlet;version="2.6.0", javax.servlet.descriptor;version="2.6.0", + javax.servlet.http;version="2.6.0", + org.apache.commons.io, org.json.simple, org.json.simple.parser, org.osgi.framework, @@ -30,6 +34,7 @@ Export-Package: com.google.gwt.user.client.rpc.core.java.util, com.sap.sse.gwt.client.dialog, com.sap.sse.gwt.client.event, com.sap.sse.gwt.client.filestorage, + com.sap.sse.gwt.client.linker, com.sap.sse.gwt.client.media, com.sap.sse.gwt.client.mutationobserver, com.sap.sse.gwt.client.mvp, diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/linker/ManifestLinker.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/linker/ManifestLinker.java new file mode 100644 index 00000000000..2e26ee6790c --- /dev/null +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/linker/ManifestLinker.java @@ -0,0 +1,135 @@ +package com.sap.sse.gwt.client.linker; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Date; + +import org.apache.commons.io.IOUtils; + +import com.google.gwt.core.ext.LinkerContext; +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; +import com.google.gwt.core.ext.linker.AbstractLinker; +import com.google.gwt.core.ext.linker.Artifact; +import com.google.gwt.core.ext.linker.ArtifactSet; +import com.google.gwt.core.ext.linker.EmittedArtifact; +import com.google.gwt.core.ext.linker.LinkerOrder; +import com.google.gwt.core.ext.linker.impl.SelectionInformation; + +/** + * This class creates an application manifest file for HTML 5 Offline Application Caching in the + * output folder of your client side gwt compilation results.

+ * Follow those steps to use HTML 5 Offline Application Caching in your bundle: + *
    + *
  1. Add {@code manifest="YOURMODULENAME/appcache.manifest"} to the {@code } tag in your base html file.
  2. + *
  3. Subclass {@link ManifestLinker} and override the method {@link #staticCachedFiles()}.
  4. + *
  5. Define a mime type mapping for the manifest extension in your web.xml file. + *
    + * {@code 
    + * manifest
    + * text/cache-manifest
    + * 
    + * }
    + *
  6. + *
  7. Define the subclassed linker in your gwt.xml file and add the linker.
  8. + *
    + * {@code 
    + * 
    + * }
    + *
  9. Make sure to import the those packages into your MANIFEST.MF file.
  10. + * com.google.gwt.core.ext
    + * com.google.gwt.core.ext.linker
    + * com.google.gwt.core.ext.linker.impl + *
+ * + * @author Alexander Ries + * + */ +@LinkerOrder(LinkerOrder.Order.POST) +public class ManifestLinker extends AbstractLinker { + + private static final String MANIFEST = "appcache.manifest"; + private static final String MANIFESTTEMPLATE = "cache.manifest.template"; + + @Override + public String getDescription() { + return ManifestLinker.class.getName(); + } + + @Override + public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation) throws UnableToCompleteException { + ArtifactSet result = new ArtifactSet(artifacts); + if (onePermutation) { + return result; + } + if (result.find(SelectionInformation.class).isEmpty()) { + logger.log(TreeLogger.INFO, "Warning: Clobbering " + MANIFEST + " to allow debugging. " + "Recompile before deploying your app!"); + artifacts = null; + } else { + result.add(emitLandingPageCacheManifest(context, logger, artifacts)); + } + return result; + } + + private Artifact emitLandingPageCacheManifest(LinkerContext context, TreeLogger logger, ArtifactSet artifacts) throws UnableToCompleteException { + StringBuilder publicSourcesSb = new StringBuilder(); + StringBuilder staticResoucesSb = new StringBuilder(); + if (artifacts != null) { + for (@SuppressWarnings("rawtypes") + Artifact artifact : artifacts) { + if (artifact instanceof EmittedArtifact) { + EmittedArtifact ea = (EmittedArtifact) artifact; + String pathName = ea.getPartialPath(); + if (pathName.endsWith("symbolMap") || + pathName.endsWith(".xml.gz") || + pathName.endsWith("rpc.log") || + pathName.endsWith("gwt.rpc") || + pathName.endsWith("manifest.txt") || + pathName.startsWith("rpcPolicyManifest")) { + } else { + publicSourcesSb.append(pathName + "\n"); + } + } + } + String[] cacheExtraFiles = getCacheExtraFiles(); + for (int i = 0; i < cacheExtraFiles.length; i++) { + staticResoucesSb.append(cacheExtraFiles[i]); + staticResoucesSb.append("\n"); + } + } + String cacheManifestString = createCache(logger, context, publicSourcesSb, staticResoucesSb); + return emitString(logger, cacheManifestString, MANIFEST); + } + + protected String createCache(TreeLogger logger, LinkerContext context, StringBuilder publicSourcesSb, StringBuilder staticResoucesSb) throws UnableToCompleteException { + try { + String manifest = IOUtils.toString(getClass().getResourceAsStream(appCacheManifestTemplate())); + manifest = manifest.replace("$UNIQUEID$", (new Date()).getTime() + "." + Math.random()).toString(); + manifest = manifest.replace("$STATICAPPFILES$", staticResoucesSb.toString()); + manifest = manifest.replace("$GENAPPFILES$", publicSourcesSb.toString()); + return manifest; + } catch (IOException e) { + //logger.log(TreeLogger.ERROR, "Could not read cache manifest template.", e); + throw new UnableToCompleteException(); + } + } + + private String[] getCacheExtraFiles() { + String[] cacheExtraFiles = staticCachedFiles(); + return cacheExtraFiles == null ? new String[0] : Arrays.copyOf(cacheExtraFiles, cacheExtraFiles.length); + } + + /** + * Override this method to provide static files for caching. + * Include at least your root HTML and CSS file. + * Also include all files referenced in your root HTML file. + * See {@link DashboardManifestLinker} as an example. + * */ + protected String[] staticCachedFiles() { + return null; + } + + protected String appCacheManifestTemplate() { + return MANIFESTTEMPLATE; + } +}