List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.agilejava.docbkx.maven.AbstractFoMojo.java
License:Apache License
private OutputStream openFileForOutput(File file) throws MojoExecutionException { try {/* w ww. j a va 2 s. c o m*/ return new BufferedOutputStream(new FileOutputStream(file)); } catch (FileNotFoundException fnfe) { throw new MojoExecutionException("Failed to open " + file + " for output."); } }
From source file:com.agilejava.docbkx.maven.AbstractWebhelpMojo.java
License:Apache License
/** * DOCUMENT ME!//from ww w. j a va 2s . co m * * @param result DOCUMENT ME! * * @throws MojoExecutionException DOCUMENT ME! */ public void postProcessResult(File result) throws MojoExecutionException { super.postProcessResult(result); if (getLog().isDebugEnabled()) getLog().debug("webhelp indexing on: " + targetBaseDir); copyTemplate(); // Creating a DirList with index page excluded, and all other html pages included DirList nsiDoc = new DirList(targetBaseDir, new String[] { "ix01.html", "^.*\\.html?$" }, 1); //new String[]{"ix01.html","^.*\\.html?$"} // topic files listed in the given directory ArrayList htmlFiles = nsiDoc.getListFiles(); if (htmlFiles.isEmpty()) { throw new MojoExecutionException("No file *.html listed in: " + targetBaseDir); } // Get the list of all html files with relative paths ArrayList htmlFilesPathRel = nsiDoc.getListFilesRelTo(targetBaseDir.getAbsolutePath()); if (htmlFilesPathRel == null) { throw new MojoExecutionException("No relative html files calculated."); } // Create the list of the existing html files (index starts at 0) searchBaseDir.mkdirs(); final File htmlList = new File(searchBaseDir, HTML_INFO_LIST); WriteJSFiles.WriteHTMLList(htmlList.getAbsolutePath(), htmlFilesPathRel, stemming); // Parse each html file to retrieve the words: // ------------------------------------------ // Retrieve the clean-up properties for indexing retrieveCleanUpProps(); SaxHTMLIndex spe = new SaxHTMLIndex(cleanUpStrings, cleanUpChars); // use clean-up props files System.setProperty("org.xml.sax.driver", "org.ccil.cowan.tagsoup.Parser"); System.setProperty("javax.xml.parsers.SAXParserFactory", "org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl"); if (spe.init(tempDico) == 0) { //create a html file description list ArrayList filesDescription = new ArrayList(); String indexerLanguage = getProperty("webhelpIndexerLanguage"); indexerLanguage = ((indexerLanguage == null) ? "en" : indexerLanguage); //TODO: change this when updating webhelpindexer in order to use the new WriteJSFiles.WriteIndex method if (getLog().isDebugEnabled()) getLog().debug("Indexer language is: " + indexerLanguage); // parse each html files for (int f = 0; f < htmlFiles.size(); f++) { File ftemp = (File) htmlFiles.get(f); if (getLog().isDebugEnabled()) getLog().debug("Parsing html file: " + ftemp.getAbsolutePath()); //tempMap.put(key, value); //The HTML file information are added in the list of FileInfoObject DocFileInfo docFileInfoTemp = new DocFileInfo(spe.runExtractData(ftemp, indexerLanguage, stemming)); ftemp = docFileInfoTemp.getFullpath(); String stemp = ftemp.toString(); int i = stemp.indexOf(targetBaseDir.getAbsolutePath()); if (i != 0) { System.out.println("the documentation root does not match with the documentation input!"); return; } int ad = 1; if (stemp.equals(targetBaseDir.getAbsolutePath())) ad = 0; stemp = stemp.substring(i + targetBaseDir.getAbsolutePath().length() + ad); //i is redundant (i==0 always) ftemp = new File(stemp); docFileInfoTemp.setFullpath(ftemp); filesDescription.add(docFileInfoTemp); } /*remove empty strings from the map*/ if (tempDico.containsKey("")) { tempDico.remove(""); } // write the index files if (tempDico.isEmpty()) { throw new MojoExecutionException("No words have been indexed in: " + targetBaseDir); } File indexFile = new File(searchBaseDir, indexName); WriteJSFiles.WriteIndex(indexFile.getAbsolutePath(), tempDico, indexerLanguage); // write the html list file with title and shortdesc //create the list of the existing html files (index starts at 0) File htmlInfoList = new File(searchBaseDir, HTML_INFO_LIST); WriteJSFiles.WriteHTMLInfoList(htmlInfoList.getAbsolutePath(), filesDescription); } else { throw new MojoExecutionException("Parser initialization failed, wrong base dir"); } }
From source file:com.agilejava.maven.docbkx.GeneratorMojo.java
License:Apache License
/** * Completes configuration.//from w ww. j a va 2 s . c om */ private void completeConfiguration() throws MojoExecutionException { if (distribution == null) { boolean found = false; Set artifacts = project.getDependencyArtifacts(); if (artifacts != null) { Iterator i = artifacts.iterator(); while (i.hasNext()) { Artifact artifact = (Artifact) i.next(); if ("net.sf.docbook".equals(artifact.getGroupId()) && "docbook-xsl".equals(artifact.getArtifactId())) { distribution = artifact.getFile(); version = artifact.getVersion(); found = true; getLog().debug("Docbook artifact used for generation: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" + artifact.getClassifier()); break; } } } if (!found) { throw new MojoExecutionException("Unable to find a valid docbook depencency artifact"); } } if (stylesheetPath == null) { // ${type}/docbook.xsl stylesheetPath = type + "/docbook.xsl"; } if (stylesheetTargetLocation == null) { // ${stylesheetTargetRoot}/${stylesheetPath} stylesheetTargetLocation = stylesheetTargetRoot + "/" + stylesheetPath; } }
From source file:com.akathist.maven.plugins.launch4j.Launch4jMojo.java
License:Open Source License
/** * Decides which platform-specific bundle we need, based on the current operating system. *///from w w w . ja v a 2s. c o m private Artifact chooseBinaryBits() throws MojoExecutionException { String plat; String os = System.getProperty("os.name"); getLog().debug("OS = " + os); // See here for possible values of os.name: // http://lopica.sourceforge.net/os.html if (os.startsWith("Windows")) { plat = "win32"; } else if ("Linux".equals(os)) { plat = "linux"; } else if ("Solaris".equals(os) || "SunOS".equals(os)) { plat = "solaris"; } else if ("Mac OS X".equals(os) || "Darwin".equals(os)) { plat = "mac"; } else { throw new MojoExecutionException("Sorry, Launch4j doesn't support the '" + os + "' OS."); } return factory.createArtifactWithClassifier(LAUNCH4J_GROUP_ID, LAUNCH4J_ARTIFACT_ID, getLaunch4jVersion(), "jar", "workdir-" + plat); }
From source file:com.akathist.maven.plugins.launch4j.Launch4jMojo.java
License:Open Source License
/** * The Launch4j version used by the plugin. * We want to download the platform-specific bundle whose version matches the Launch4j version, * so we have to figure out what version the plugin is using. * /*from www .j a v a 2s . com*/ * @return * @throws MojoExecutionException */ private String getLaunch4jVersion() throws MojoExecutionException { String version = null; for (Artifact artifact : pluginArtifacts) { if (LAUNCH4J_GROUP_ID.equals(artifact.getGroupId()) && LAUNCH4J_ARTIFACT_ID.equals(artifact.getArtifactId()) && "core".equals(artifact.getClassifier())) { version = artifact.getVersion(); getLog().debug("Found launch4j version " + version); break; } } if (version == null) { throw new MojoExecutionException("Impossible to find which Launch4j version to use"); } return version; }
From source file:com.alexeyhanin.maven.yajaxb.plugin.SchemagenMojo.java
License:Apache License
public void execute() throws MojoExecutionException { if ("pom".equals(project.getPackaging())) { return;/*from w ww .ja v a 2 s .c om*/ } if (includes == null) { throw new MojoExecutionException("No includes defined"); } final Set<String> sources = new LinkedHashSet<String>(); final List<String> sourceRoots = project.getCompileSourceRoots(); for (String sourceRoot : sourceRoots) { try { sources.addAll( FileUtils.getFileNames(new File(sourceRoot), StringUtils.join(includes.iterator(), ", "), StringUtils.join(excludes.iterator(), ", "), true)); } catch (IOException ex) { throw new MojoExecutionException("Error scanning source root: \'" + sourceRoot + "\' " + "", ex); } } if (getLog().isInfoEnabled()) { getLog().info(String.format("Included %d source files: %s", sources.size(), StringUtils.join(sources.iterator(), " "))); } if (!outputDirectory.exists() && !outputDirectory.mkdirs()) { throw new MojoExecutionException( "Unable to create output directory: " + outputDirectory.getAbsolutePath()); } final List<String> classpathElements; try { classpathElements = project.getCompileClasspathElements(); } catch (DependencyResolutionRequiredException ex) { throw new MojoExecutionException("Failed to retrieve classpath", ex); } if (episode != null) { if (!episode.getParentFile().exists()) { episode.getParentFile().mkdirs(); } } final List<String> args = new ArrayList<String>(sources.size() + 10); args.add("-d"); args.add(outputDirectory.getAbsolutePath()); if (!classpathElements.isEmpty()) { args.add("-classpath"); args.add(StringUtils.join(classpathElements.iterator(), File.pathSeparator)); } if (episode != null) { args.add("-episode"); args.add(episode.getAbsolutePath()); } args.addAll(sources); try { SchemaGenerator.run(args.toArray(new String[args.size()])); } catch (Exception ex) { throw new MojoExecutionException("Error running schema generator", ex); } }
From source file:com.alexnederlof.jasperreport.JasperReporter.java
License:Apache License
/** * Check if the output directory exist and is writable. If not, try to create * an output dir and see if that is writable. * //from w w w . j a va 2 s. c o m * @param outputDirectory * @throws MojoExecutionException */ private void checkOutDirWritable(File outputDirectory) throws MojoExecutionException { if (outputDirectory.exists()) { if (outputDirectory.canWrite()) { return; } else { throw new MojoExecutionException("The output dir exists but was not writable. " + "Try running maven with the 'clean' goal."); } } checkIfOutpuCanBeCreated(); checkIfOutputDirIsWritable(); if (verbose) { getLog().info("Output dir check OK"); } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
private boolean validate() throws MojoExecutionException { // validate sanity of the current m2 project if (Arrays.binarySearch(WTP_SUPPORTED_VERSIONS, wtpversion) < 0) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.unsupportedwtp", new Object[] { //$NON-NLS-1$ wtpversion, StringUtils.join(WTP_SUPPORTED_VERSIONS, " ") })); //$NON-NLS-1$ }// ww w .ja v a 2 s . c o m assertNotEmpty(executedProject.getGroupId(), POM_ELT_GROUP_ID); assertNotEmpty(executedProject.getArtifactId(), POM_ELT_ARTIFACT_ID); if (executedProject.getFile() == null || !executedProject.getFile().exists()) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.missingpom")); //$NON-NLS-1$ } if ("pom".equals(packaging) && eclipseProjectDir == null) //$NON-NLS-1$ { getLog().info(Messages.getString("EclipsePlugin.pompackaging")); //$NON-NLS-1$ return false; } if ("eclipse-plugin".equals(packaging)) { pde = true; } if (eclipseProjectDir == null) { eclipseProjectDir = executedProject.getFile().getParentFile(); } if (!eclipseProjectDir.exists() && !eclipseProjectDir.mkdirs()) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.cantcreatedir", eclipseProjectDir)); //$NON-NLS-1$ } if (!eclipseProjectDir.equals(executedProject.getFile().getParentFile())) { if (!eclipseProjectDir.isDirectory()) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.notadir", eclipseProjectDir)); //$NON-NLS-1$ } eclipseProjectDir = new File(eclipseProjectDir, executedProject.getArtifactId()); if (!eclipseProjectDir.isDirectory() && !eclipseProjectDir.mkdirs()) { throw new MojoExecutionException( Messages.getString("EclipsePlugin.cantcreatedir", eclipseProjectDir)); //$NON-NLS-1$ } } validateExtras(); return true; }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
private void writeAdditionalConfig() throws MojoExecutionException { if (additionalConfig != null) { for (int j = 0; j < additionalConfig.length; j++) { EclipseConfigFile file = additionalConfig[j]; File projectRelativeFile = new File(eclipseProjectDir, file.getName()); if (projectRelativeFile.isDirectory()) { // just ignore? getLog().warn(Messages.getString("EclipsePlugin.foundadir", //$NON-NLS-1$ projectRelativeFile.getAbsolutePath())); }// ww w .j av a 2 s. c om try { projectRelativeFile.getParentFile().mkdirs(); if (file.getContent() == null) { if (file.getLocation() != null) { InputStream inStream = locator.getResourceAsInputStream(file.getLocation()); OutputStream outStream = new FileOutputStream(projectRelativeFile); try { IOUtil.copy(inStream, outStream); } finally { IOUtil.close(inStream); IOUtil.close(outStream); } } else { URL url = file.getURL(); String endPointUrl = url.getProtocol() + "://" + url.getAuthority(); // Repository Id should be ignored by Wagon ... Repository repository = new Repository("additonal-configs", endPointUrl); Wagon wagon = wagonManager.getWagon(repository); ; if (logger.isDebugEnabled()) { Debug debug = new Debug(); wagon.addSessionListener(debug); wagon.addTransferListener(debug); } wagon.setTimeout(1000); Settings settings = mavenSettingsBuilder.buildSettings(); ProxyInfo proxyInfo = null; if (settings != null && settings.getActiveProxy() != null) { Proxy settingsProxy = settings.getActiveProxy(); proxyInfo = new ProxyInfo(); proxyInfo.setHost(settingsProxy.getHost()); proxyInfo.setType(settingsProxy.getProtocol()); proxyInfo.setPort(settingsProxy.getPort()); proxyInfo.setNonProxyHosts(settingsProxy.getNonProxyHosts()); proxyInfo.setUserName(settingsProxy.getUsername()); proxyInfo.setPassword(settingsProxy.getPassword()); } if (proxyInfo != null) { wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId()), proxyInfo); } else { wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId())); } wagon.get(url.getPath(), projectRelativeFile); } } else { FileUtils.fileWrite(projectRelativeFile.getAbsolutePath(), file.getContent()); } } catch (WagonException e) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.remoteexception", //$NON-NLS-1$ new Object[] { file.getURL(), e.getMessage() })); } catch (IOException e) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.cantwritetofile", //$NON-NLS-1$ projectRelativeFile.getAbsolutePath())); } catch (ResourceNotFoundException e) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.cantfindresource", //$NON-NLS-1$ file.getLocation())); } catch (XmlPullParserException e) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.settingsxmlfailure", //$NON-NLS-1$ e.getMessage())); } } } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
private void assertNotEmpty(String string, String elementName) throws MojoExecutionException { if (string == null) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.missingelement", elementName)); //$NON-NLS-1$ }// ww w . ja va2s . co m }