1

我有一个自定义链接器来生成一个在 GWT 2.7 之前可以正常工作的清单文件。当我更改为 GWT 2.8 时,我注意到它停止生成文件 myapp.manifest。

在 module.gwt.xml 我有

<?xml version="1.0" encoding="UTF-8"?>
<module>
    <inherits name="com.google.gwt.user.User" />
    <inherits name="com.google.gwt.core.Core" />

    <source path="client" />
    <source path="shared" />
    <source path="constants" />

    <entry-point class="br.com.universo.client.AppStart" />

    <extend-property name="locale" values="pt" />
    <extend-property name="locale" values="en" />
    <set-property-fallback name="locale" value="en" />

    <define-linker class="br.com.universo.AppManifest"
        name="manifest" />
    <add-linker name="manifest" />


</module>

这是2.7上的编译日志

    [INFO] --- gwt-maven-plugin:2.7.0:compile (default) @ universo-bootstrap ---
    [INFO] auto discovered modules [br.com.universo.core.appCore, br.com.universo.app]
    [INFO] br.com.universo.core.appCore has no EntryPoint - compilation skipped
    [INFO] Compiling module br.com.universo.app
    [INFO]    Ignored 7 units with compilation errors in first pass.
    [INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
    [INFO]    Compiling 6 permutations
    [INFO]       Compiling permutation 0...
    [INFO]       Process output
    [INFO]          Compiling
    [INFO]             Compiling permutation 1...
    [INFO]       Compiling permutation 2...
    [INFO]          Compiling
    [INFO]             Compiling permutation 3...
    [INFO]       Compiling permutation 4...
    [INFO]       Compiling permutation 5...
    [INFO]    Compile of permutations succeeded
    [INFO]    Compilation succeeded -- 165.867s
    [INFO] MyApp OffLine Linker started
    [INFO] MyApp OffLine Linker ended
    [INFO] Linking into /universo/universo-bootstrap/target/universo-bootstrap-1.0-SNAPSHOT/app
    [INFO]    Link succeeded
    [INFO]    Linking succeeded -- 1.239s

在 GWT 2.8 上,我使用tbroyer gwt maven archetype modules-webapp。链接器类是在客户端模块下定义的,但在外部的包上

<source path="client" />

在编译日志中我看不到以下行:

[INFO] MyApp OffLine Linker started
[INFO] MyApp OffLine Linker ended

我想这表明它没有被调用?

[INFO] --- gwt-maven-plugin:1.0-rc-7:compile (default-compile) @ universo-client ---
[INFO] Compiling module br.com.universo.app
[INFO]    Compiling 9 permutations
[INFO]       Compiling permutation 0...
[INFO]       [WARN] Namespace option is not compatible with CodeSplitter, turning it off.
[INFO]       Compiling permutation 1...
[INFO]       Compiling permutation 2...
[INFO]       Compiling permutation 3...
[INFO]       Compiling permutation 4...
[INFO]       Compiling permutation 5...
[INFO]       Compiling permutation 6...
[INFO]       Compiling permutation 7...
[INFO]       Compiling permutation 8...
[INFO]    Compile of permutations succeeded
[INFO]    Compilation succeeded -- 104.171s
[INFO] Linking into /universo/universo-client/target/universo-client-1.0-SNAPSHOT/app
[INFO]    Link succeeded
[INFO]    Linking succeeded -- 1.818s

链接器类 AppManifest.java

package br.com.universo;

import java.util.Date;

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.ArtifactSet;
import com.google.gwt.core.ext.linker.EmittedArtifact;
import com.google.gwt.core.ext.linker.LinkerOrder;
import com.google.gwt.core.ext.linker.LinkerOrder.Order;
import com.google.gwt.core.ext.linker.Shardable;

@Shardable
@LinkerOrder(Order.POST)
public class AppManifest extends AbstractLinker {

    static final String[] cache = new String[] {
        "# Css"
        , "/css/base.css"
        , "/css/feedback.css"
        , "/css/layout.css"
        , "/css/prettyPhoto.css"
        , "/css/shortcodes.css"
        , "/css/slideshow.css"
        , "/css/style.css"
    }; 

    static final String[] network = new String[] {
        "*"
    };


    @Override
    public String getDescription() {
        return "MyApp OffLine Linker";
    }

     @Override
      public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException {
        System.out.println("MyApp OffLine Linker started");
        ArtifactSet artifactset = new ArtifactSet(artifacts);

        StringBuilder builder= new StringBuilder("CACHE MANIFEST\n");
        builder.append("# Cache Version " + new Date() + "\n\n");
        builder.append("CACHE:\n");

        for (String line : cache) {
            builder.append(line + "\n");            
        }
        builder.append("\n\n");

        for(EmittedArtifact emitted: artifacts.find(EmittedArtifact.class))
        {
            if(emitted.getPartialPath().endsWith(".symbolMap"))continue;
            if(emitted.getPartialPath().endsWith(".txt"))continue;
            builder.append(emitted.getPartialPath()).append("\n");
        }
        builder.append("\n\n");

        builder.append("NETWORK:\n");
        for (String line : network) {
            builder.append(line + "\n");            
        }
        builder.append("\n\n");

        builder.append("FALLBACK:\n");

        EmittedArtifact manifest = emitString(logger, builder.toString(), "myapp.manifest");
        artifactset.add(manifest);
        System.out.println("MyApp OffLine Linker ended");
        return artifactset;
      }

}

非常感谢任何帮助!

4

1 回答 1

0

我终于让它改变了我的 AppManifast.java。我在当前文档中注意到,当使用 @Shardable 注释时,您必须覆盖其他链接方法签名,因此我在类中添加了以下几行:

@Override
public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean onePermutation) throws UnableToCompleteException {
    return link(logger, context, artifacts);
}

我花了很长时间才发现...

于 2017-06-12T15:54:26.593 回答