/** * Checks that any jarResources defined in the jnlpFile elements are not also defined in * commonJarResources. * * @throws MojoExecutionException if a duplicate is found. */ private void checkForDuplicateJarResources() throws MojoExecutionException { if (this.commonJarResources == null || this.commonJarResources.isEmpty()) { return; } for (Iterator jnlpFileItr = this.jnlpFiles.iterator(); jnlpFileItr.hasNext(); ) { JnlpFile jnlpFile = (JnlpFile) jnlpFileItr.next(); List jnlpJarResources = jnlpFile.getJarResources(); for (Iterator jarResourceItr = jnlpJarResources.iterator(); jarResourceItr.hasNext(); ) { JarResource jarResource = (JarResource) jarResourceItr.next(); if (this.commonJarResources.contains(jarResource)) { String message = "Configuration Error: The jar resource element for artifact " + jarResource + " defined in common jar resources is duplicated in the jar " + "resources configuration of the jnlp file identified by the template file " + jnlpFile.getTemplateFilename() + "."; throw new MojoExecutionException(message); } } } }
/** * Checks the validity of a single jnlpFile configuration element. * * @param jnlpFile The configuration element to be checked. * @throws MojoExecutionException if the config element is invalid. */ private void checkJnlpFileConfiguration(JnlpFile jnlpFile) throws MojoExecutionException { if (StringUtils.isEmpty(jnlpFile.getOutputFilename())) { throw new MojoExecutionException( "Configuration error: An outputFilename must be specified for each jnlpFile element"); } if (jnlpFile.getTemplateFilename() == null) { getLog() .info( "No templateFilename found for " + jnlpFile.getOutputFilename() + ". Will use the default template."); } else { File templateFile = new File(getTemplateDirectory(), jnlpFile.getTemplateFilename()); if (!templateFile.isFile()) { throw new MojoExecutionException( "The specified JNLP template does not exist: [" + templateFile + "]"); } } checkJnlpJarResources(jnlpFile); }
private void generateJnlpFile(JnlpFile jnlpFile, String libPath) throws MojoExecutionException { File jnlpOutputFile = new File(getWorkDirectory(), jnlpFile.getOutputFilename()); Set jarResources = new LinkedHashSet(); jarResources.addAll(jnlpFile.getJarResources()); if (this.commonJarResources != null && !this.commonJarResources.isEmpty()) { for (Iterator itr = this.commonJarResources.iterator(); itr.hasNext(); ) { JarResource jarResource = (JarResource) itr.next(); jarResources.add(jarResource); } jarResources.addAll(this.commonJarResources); } JarResourcesGenerator jnlpGenerator = new JarResourcesGenerator( getProject(), getTemplateDirectory(), "default-jnlp-servlet-template.vm", jnlpOutputFile, jnlpFile.getTemplateFilename(), jarResources, jnlpFile.getMainClass(), getWebstartJarURLForVelocity(), libPath); jnlpGenerator.setExtraConfig(getGeneratorExtraConfig()); try { jnlpGenerator.generate(); } catch (Exception e) { throw new MojoExecutionException( "The following error occurred attempting to generate " + "the JNLP deployment descriptor: " + e, e); } }