Java Examples for org.codehaus.mojo.gwt.GwtModule

The following java examples will help you to understand the usage of org.codehaus.mojo.gwt.GwtModule. These source code samples are taken from different open source projects.

Example 1
Project: codehaus-mojo-master  File: CompileMojo.java View source code
/**
     * Try to find out, if there are stale sources. If aren't some, we don't have to compile... ...this heuristic
     * doesn't take into account, that there could be updated dependencies. But for this case, as 'clean compile' could
     * be executed which would force a compilation.
     *
     * @param module Name of the GWT module to compile
     * @param output Output path
     * @return true if compilation is required (i.e. stale sources are found)
     * @throws MojoExecutionException When sources scanning fails
     * @author Alexander Gordt
     */
private boolean compilationRequired(String module, File output) throws MojoExecutionException {
    try {
        GwtModule gwtModule = readModule(module);
        if (gwtModule.getEntryPoints().size() == 0) {
            getLog().debug(gwtModule.getName() + " has no EntryPoint - compilation skipped");
            // with '[ERROR] Module has no entry points defined'
            return false;
        }
        if (force) {
            return true;
        }
        String modulePath = gwtModule.getPath();
        String outputTarget = modulePath + "/" + modulePath + ".nocache.js";
        // Require compilation if no js file present in target.
        if (!new File(output, outputTarget).exists()) {
            return true;
        }
        // js file allreay exists, but may not be up-to-date with project source files
        SingleTargetSourceMapping singleTargetMapping = new SingleTargetSourceMapping(".java", outputTarget);
        StaleSourceScanner scanner = new StaleSourceScanner();
        scanner.addSourceMapping(singleTargetMapping);
        SingleTargetSourceMapping gwtModuleMapping = new SingleTargetSourceMapping(".gwt.xml", outputTarget);
        scanner.addSourceMapping(gwtModuleMapping);
        SingleTargetSourceMapping uiBinderMapping = new SingleTargetSourceMapping(".ui.xml", outputTarget);
        scanner.addSourceMapping(uiBinderMapping);
        Collection<File> compileSourceRoots = new HashSet<File>();
        classpathBuilder.addSourcesWithActiveProjects(getProject(), compileSourceRoots, SCOPE_COMPILE);
        classpathBuilder.addResourcesWithActiveProjects(getProject(), compileSourceRoots, SCOPE_COMPILE);
        for (File sourceRoot : compileSourceRoots) {
            if (!sourceRoot.isDirectory()) {
                continue;
            }
            try {
                if (!scanner.getIncludedSources(sourceRoot, output).isEmpty()) {
                    getLog().debug("found stale source in " + sourceRoot + " compared with " + output);
                    return true;
                }
            } catch (InclusionScanException e) {
                throw new MojoExecutionException("Error scanning source root: \'" + sourceRoot + "\' " + "for stale files to recompile.", e);
            }
        }
        getLog().info(module + " is up to date. GWT compilation skipped");
        return false;
    } catch (GwtModuleReaderException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Example 2
Project: SPIFF-master  File: InitializeMojo.java View source code
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Properties p = project.getProperties();
    setCompilerAttr();
    if (project.getPackaging() == "spiffyui-client") {
        setDefaultPath(ATTR_WWW, "www");
    } else {
        setDefaultPath(ATTR_WWW, project.getArtifactId() + "-" + project.getVersion());
    }
    setDefaultPath(ATTR_GENERATEDSRC, "generated-sources/gwt");
    GwtModuleReader gmr = new SpiffyGwtModuleReader(project, getLog(), new ClasspathBuilder(), userAgents, locales);
    List<String> modules = gmr.getGwtModules();
    /*
         Our module reader will create a new module with our special suffix.  That
         means there will be two modules in the project, but we only want our new
         one so we take the other one out of the list.
         */
    if (modules.size() > 1) {
        for (int i = modules.size() - 1; i >= 0; i--) {
            if (!modules.get(i).endsWith(SPIFFY_TMP_SUFFIX)) {
                modules.remove(modules.get(i));
            }
        }
    }
    /* ensure there is only one module, and record it for posterity */
    switch(modules.size()) {
        case 0:
            throw new MojoExecutionException("No GWT modules detected");
        case 1:
            try {
                GwtModule module = gmr.readModule(modules.get(0));
                String[] sources = module.getSources();
                p.setProperty("spiffyui.gwt.module.name", module.getName());
                String path = new File(p.getProperty(ATTR_WWW), module.getPath()).getAbsolutePath();
                if (path.endsWith(SPIFFY_TMP_SUFFIX)) {
                    path = path.substring(0, path.length() - SPIFFY_TMP_SUFFIX.length());
                }
                p.setProperty("spiffyui.gwt.module.path", path);
                if (sources != null && sources.length > 0) {
                    /*
                         Users can specify a different sources path in their module.
                         In that case we want to use that package.  If they haven't
                         specified that directory they get the client directory by
                         default.
                         */
                    p.setProperty("spiffyui.gwt.module.package", module.getPackage() + "." + sources[0]);
                } else {
                    p.setProperty("spiffyui.gwt.module.package", module.getPackage() + ".client");
                }
            } catch (Exception e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            break;
        default:
            throw new MojoExecutionException("Only one GWT module allowed, but " + modules.size() + " detected: " + modules);
    }
}
Example 3
Project: gwt-maven-plugin-master  File: CompileMojo.java View source code
/**
     * Try to find out, if there are stale sources. If aren't some, we don't have to compile... ...this heuristic
     * doesn't take into account, that there could be updated dependencies. But for this case, as 'clean compile' could
     * be executed which would force a compilation.
     *
     * @param module Name of the GWT module to compile
     * @param output Output path
     * @return true if compilation is required (i.e. stale sources are found)
     * @throws MojoExecutionException When sources scanning fails
     * @author Alexander Gordt
     */
private boolean compilationRequired(String module, File output) throws MojoExecutionException {
    getLog().debug("**Checking if compilation is required for " + module);
    try {
        GwtModule gwtModule = readModule(module);
        if (gwtModule.getEntryPoints().size() == 0) {
            getLog().info(gwtModule.getName() + " has no EntryPoint - compilation skipped");
            // with '[ERROR] Module has no entry points defined'
            return false;
        }
        getLog().debug("Module has an entrypoint");
        if (force) {
            return true;
        }
        getLog().debug("Compilation not forced");
        String modulePath = gwtModule.getPath();
        String outputTarget = modulePath + "/" + modulePath + ".nocache.js";
        File outputTargetFile = new File(output, outputTarget);
        // Require compilation if no js file present in target.
        if (!outputTargetFile.exists()) {
            return true;
        }
        getLog().debug("Output file exists");
        File moduleFile = gwtModule.getSourceFile();
        if (moduleFile == null) {
            //the module was read from something like an InputStream; always recompile this because we can't make any other choice
            return true;
        }
        getLog().debug("There is a module source file (not an input stream");
        //If input is newer than target, recompile
        if (moduleFile.lastModified() > outputTargetFile.lastModified()) {
            getLog().debug("Module file has been modified since the output file was created; recompiling");
            return true;
        }
        getLog().debug("The module XML hasn't been updated");
        // js file already exists, but may not be up-to-date with project source files
        SingleTargetSourceMapping singleTargetMapping = new SingleTargetSourceMapping(".java", outputTarget);
        StaleSourceScanner scanner = new StaleSourceScanner();
        scanner.addSourceMapping(singleTargetMapping);
        SingleTargetSourceMapping uiBinderMapping = new SingleTargetSourceMapping(".ui.xml", outputTarget);
        scanner.addSourceMapping(uiBinderMapping);
        Collection<File> compileSourceRoots = new HashSet<File>();
        for (String sourceRoot : getProject().getCompileSourceRoots()) {
            for (String sourcePackage : gwtModule.getSources()) {
                String packagePath = gwtModule.getPackage().replace('.', File.separatorChar);
                File sourceDirectory = new File(sourceRoot + File.separatorChar + packagePath + File.separator + sourcePackage);
                if (sourceDirectory.exists()) {
                    getLog().debug(" Looking in a source directory " + sourceDirectory.getAbsolutePath() + " for possible changes");
                    compileSourceRoots.add(sourceDirectory);
                }
            }
        }
        for (File sourceRoot : compileSourceRoots) {
            if (!sourceRoot.isDirectory()) {
                continue;
            }
            try {
                if (!scanner.getIncludedSources(sourceRoot, output).isEmpty()) {
                    getLog().debug("found stale source in " + sourceRoot + " compared with " + output);
                    return true;
                }
            } catch (InclusionScanException e) {
                throw new MojoExecutionException("Error scanning source root: \'" + sourceRoot + "\' " + "for stale files to recompile.", e);
            }
        }
        getLog().info(module + " is up to date. GWT compilation skipped");
        return false;
    } catch (GwtModuleReaderException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Example 4
Project: spiffyui-master  File: InitializeMojo.java View source code
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Properties p = project.getProperties();
    setCompilerAttr();
    if (project.getPackaging() == "spiffyui-client") {
        setDefaultPath(ATTR_WWW, "www");
    } else {
        setDefaultPath(ATTR_WWW, project.getArtifactId() + "-" + project.getVersion());
    }
    setDefaultPath(ATTR_GENERATEDSRC, "generated-sources/gwt");
    GwtModuleReader gmr = new SpiffyGwtModuleReader(project, getLog(), new ClasspathBuilder(), userAgents, locales);
    List<String> modules = gmr.getGwtModules();
    /*
         Our module reader will create a new module with our special suffix.  That
         means there will be two modules in the project, but we only want our new
         one so we take the other one out of the list.
         */
    if (modules.size() > 1) {
        for (int i = modules.size() - 1; i >= 0; i--) {
            if (!modules.get(i).endsWith(SPIFFY_TMP_SUFFIX)) {
                modules.remove(modules.get(i));
            }
        }
    }
    /* ensure there is only one module, and record it for posterity */
    switch(modules.size()) {
        case 0:
            throw new MojoExecutionException("No GWT modules detected");
        case 1:
            try {
                GwtModule module = gmr.readModule(modules.get(0));
                String[] sources = module.getSources();
                p.setProperty("spiffyui.gwt.module.name", module.getName());
                String path = new File(p.getProperty(ATTR_WWW), module.getPath()).getAbsolutePath();
                if (path.endsWith(SPIFFY_TMP_SUFFIX)) {
                    path = path.substring(0, path.length() - SPIFFY_TMP_SUFFIX.length());
                }
                p.setProperty("spiffyui.gwt.module.path", path);
                if (sources != null && sources.length > 0) {
                    /*
                         Users can specify a different sources path in their module.
                         In that case we want to use that package.  If they haven't
                         specified that directory they get the client directory by
                         default.
                         */
                    p.setProperty("spiffyui.gwt.module.package", module.getPackage() + "." + sources[0]);
                } else {
                    p.setProperty("spiffyui.gwt.module.package", module.getPackage() + ".client");
                }
            } catch (Exception e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            break;
        default:
            throw new MojoExecutionException("Only one GWT module allowed, but " + modules.size() + " detected: " + modules);
    }
}