added ManifestLinker to com.sap.sse.gwt and using it now in dashboard bundle

This commit is contained in:
Alexander Ries committed 2016-01-14 14:07:45 +01:00
1 parent e19faed1ab
commit f5bb81c387
9 files changed
+191 -8

No files matched your search

@@ -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
@@ -5,7 +5,7 @@
<!-- with a "Quirks Mode" doctype may lead to some -->
<!-- differences in layout. -->
<html>
<html manifest="com.sap.sailing.dashboards.gwt.RibDashboard/appcache.manifest">
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
@@ -48,4 +48,9 @@
<url-pattern>/com.sap.sailing.dashboards.gwt.RibDashboard/remote_logging</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>manifest</extension>
<mime-type>text/cache-manifest</mime-type>
</mime-mapping>
</web-app>
@@ -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<StringMessages> {
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);
}
@@ -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"};
}
}
@@ -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:
@@ -57,6 +57,10 @@
<set-configuration-property name="CssResource.legacy" value="true" />
<extend-property name="locale" values="de" />
<define-linker name="manifest" class="com.sap.sailing.dashboards.gwt.client.linker.DashboardManifestLinker"/>
<add-linker name="manifest"/>
<source path='client' />
<source path='shared' />
<source path="dispatch"/>
+7 -2
View File
@@ -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,
@@ -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.</br></br>
* Follow those steps to use HTML 5 Offline Application Caching in your bundle:
* <ol>
* <li>Add {@code manifest="YOURMODULENAME/appcache.manifest"} to the {@code <html>} tag in your base html file.</li>
* <li>Subclass {@link ManifestLinker} and override the method {@link #staticCachedFiles()}.</li>
* <li>Define a mime type mapping for the <code>manifest</code> extension in your web.xml file.
* <pre>
* {@code <mime-mapping>
* <extension>manifest</extension>
* <mime-type>text/cache-manifest</mime-type>
* </mime-mapping>
* }</pre>
* </li>
* <li>Define the subclassed linker in your gwt.xml file and add the linker.</li>
* <pre>
* {@code <define-linker name="manifest" class="YOUR SUBCLASSED LINKER"/>
* <add-linker name="manifest"/>
* }</pre>
* <li>Make sure to import the those packages into your MANIFEST.MF file.</li>
* com.google.gwt.core.ext</br>
* com.google.gwt.core.ext.linker</br>
* com.google.gwt.core.ext.linker.impl
* </ol>
*
* @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;
}
}