List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message, Throwable cause)
MojoExecutionException
exception wrapping an underlying Throwable
and providing a message
. From source file:com.cloudera.cdk.maven.plugins.PackageAppMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { try {/*from w ww. j a va2s .c o m*/ String buildDirectory = mavenProject.getBuild().getDirectory(); FileUtils.copyInputStreamToFile( getClass().getClassLoader().getResourceAsStream("assembly/oozie-app.xml"), new File(buildDirectory + "/assembly/oozie-app.xml")); } catch (IOException e) { throw new MojoExecutionException("Error copying assembly", e); } executeMojo( plugin(groupId("org.apache.maven.plugins"), artifactId("maven-assembly-plugin"), version("2.3")), goal("single"), configuration(element("descriptors", element("descriptor", "${project.build.directory}/assembly/oozie-app.xml"))), executionEnvironment(mavenProject, mavenSession, pluginManager)); if (generateWorkflowXml) { File outputDir = new File(mavenProject.getBuild().getDirectory(), applicationName); File workflowXml = new File(outputDir, "workflow.xml"); String hadoopFs = hadoopConfiguration.getProperty("fs.default.name"); if (hadoopFs == null) { throw new MojoExecutionException("Missing property 'fs.default.name' in " + "hadoopConfiguration"); } String hadoopJobTracker = hadoopConfiguration.getProperty("mapred.job.tracker"); if (hadoopJobTracker == null) { throw new MojoExecutionException( "Missing property 'mapred.job.tracker' in " + "hadoopConfiguration"); } List<Path> libJars = new ArrayList<Path>(); if (addDependenciesToDistributedCache) { File lib = new File(outputDir, "lib"); Collection<File> deps = FileUtils.listFiles(lib, new String[] { "jar" }, false); for (File dep : deps) { Path libJarPath = new Path(new Path(getAppPath(), "lib"), dep.getName()); libJarPath = new Path(hadoopFs, libJarPath); libJars.add(libJarPath); } } Workflow workflow = new Workflow(workflowXml, schemaVersion, workflowName, toolClass, args, hadoopConfiguration, hadoopFs, hadoopJobTracker, libJars); WorkflowXmlWriter workflowXmlWriter = new WorkflowXmlWriter(encoding); workflowXmlWriter.write(workflow); } if ("coordinator".equals(applicationType)) { File outputDir = new File(mavenProject.getBuild().getDirectory(), applicationName); File coordinatorXml = new File(outputDir, "coordinator.xml"); try { FileUtils.copyFile(coordinatorFile, coordinatorXml); } catch (IOException e) { throw new MojoExecutionException("Error copying coordinator file", e); } } }
From source file:com.cloudera.cdk.maven.plugins.RunToolMojo.java
License:Apache License
private URL toURL(File file) throws MojoExecutionException { try {/*from w ww .j a v a 2 s. c om*/ return file.toURI().toURL(); } catch (MalformedURLException e) { throw new MojoExecutionException("Can't convert file to URL: " + file, e); } }
From source file:com.cloudera.cdk.maven.plugins.WorkflowXmlWriter.java
License:Apache License
protected Writer initializeWriter(final File destinationFile) throws MojoExecutionException { try {//from ww w . j a v a 2s . co m return WriterFactory.newXmlWriter(destinationFile); } catch (IOException e) { throw new MojoExecutionException( "Exception while opening file[" + destinationFile.getAbsolutePath() + "]", e); } }
From source file:com.codecrate.webstart.GenerateJnlpMojo.java
License:Apache License
void createJnlpFile(BufferedWriter writer) throws MojoExecutionException { try {//w w w . j a va2s . c o m addLine(writer, "<?xml version=\"1.0\" encoding=\"utf-8\"?>"); addLine(writer, "<jnlp"); addLine(writer, " spec=\"" + spec + "\" "); addLine(writer, " codebase=\"" + codebase + "\" "); addLine(writer, " href=\"" + jnlpFile + "\">"); addLine(writer, " <information>"); addLine(writer, " <title>" + title + "</title>"); addLine(writer, " <vendor>" + vendor + "</vendor>"); addLine(writer, " <homepage href=\"" + homepage + "\" />"); addLine(writer, " <description>" + description + "</description>"); if (offlineAllowed) { addLine(writer, " <offline-allowed/>"); } addLine(writer, " </information>"); if (allPermissions) { addLine(writer, " <security>"); addLine(writer, " <all-permissions/>"); addLine(writer, " </security>"); } addLine(writer, " <resources>"); addLine(writer, " <j2se version=\"" + j2seVersion + "\" />"); processArtifact(mavenProject.getArtifact(), writer); for (Iterator iterator = projectArtifacts.iterator(); iterator.hasNext();) { Artifact artifact = (Artifact) iterator.next(); processArtifact(artifact, writer); } addLine(writer, " </resources>"); addLine(writer, " <application-desc main-class=\"" + mainClass + "\" />"); addLine(writer, "</jnlp>"); writer.close(); } catch (IOException e) { throw new MojoExecutionException("Unable to write JNLP file", e); } }
From source file:com.codecrate.webstart.GenerateJnlpMojo.java
License:Apache License
private void createDistribution() throws MojoExecutionException { File toFile = new File(outputDirectory, finalName); getLog().info("Creating archive distribution: " + toFile); try {/* w w w. j a v a 2 s . co m*/ if (toFile.exists()) { toFile.delete(); } Zip zip = new Zip(); zip.setProject(getProject()); zip.setBasedir(workDirectory); zip.setDestFile(toFile); zip.execute(); projectHelper.attachArtifact(mavenProject, "zip", toFile); } catch (Exception e) { throw new MojoExecutionException("Unable to create archive distribution of webstart app", e); } }
From source file:com.codehaus.mojo.email.SendMailMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { try {//from w ww . j a v a 2 s .c om if (this.messageFile != null) { this.message = FileUtils.fileRead(this.messageFile, this.charset); } Server server = getServerSettings(host + ":" + port); List<String> bccList = SplitUtils.splits(bcc, bccFile); while (true) { List<String> bccTokens = new ArrayList<String>(); for (int i = 0; i < this.maxBccCountPerSend; ++i) { if (bccList.size() != 0) { bccTokens.add(bccList.get(0)); bccList.remove(0); } } //very hacky here where we repeat the 'to', 'cc' list per bcc block send(server, bccTokens); if (bccList.size() == 0) { break; } } } catch (Exception e) { throw new MojoExecutionException("Unable to send out email", e); } }
From source file:com.coderplus.apacheutils.translators.resolvers.DefaultArtifactsResolver.java
License:Apache License
public Set<Artifact> resolve(Set<Artifact> artifacts, org.eclipse.aether.RepositorySystem repoSystem) throws MojoExecutionException { Set<Artifact> resolvedArtifacts = new HashSet<Artifact>(); for (Artifact artifact : artifacts) { try {//from w w w.jav a2 s .co m ArtifactRequest request = new ArtifactRequest(RepositoryUtils.toArtifact(artifact), RepositoryUtils.toRepos(remoteRepositories), ""); ArtifactResult result = repoSystem .resolveArtifact(LegacyLocalRepositoryManager.overlay(local, null, null), request); if (result.getArtifact() != null) { resolvedArtifacts.add(RepositoryUtils.toArtifact(result.getArtifact())); } else { throw new Exception("No valid artifact resolved"); } } catch (Exception ex) { // an error occurred during resolution, log it an continue if (stopOnFailure) { throw new MojoExecutionException("error resolving: " + artifact.getId(), ex); } } } return resolvedArtifacts; }
From source file:com.coderplus.plugins.RenameMojo.java
License:Open Source License
private void copy(File srcFile, File destFile) throws MojoExecutionException { if (!srcFile.exists()) { if (ignoreFileNotFoundOnIncremental && buildContext.isIncremental()) { getLog().warn("sourceFile " + srcFile.getAbsolutePath() + " not found during incremental build"); } else {/*from w w w. j a v a 2 s .c o m*/ getLog().error("sourceFile " + srcFile.getAbsolutePath() + " does not exist"); } } else if (destFile == null) { getLog().error("destinationFile not specified"); } else if (destFile.exists() && (destFile.isFile() == srcFile.isFile()) && !overWrite) { getLog().error(destFile.getAbsolutePath() + " already exists and overWrite not set"); } else { try { FileUtils.rename(srcFile, destFile); getLog().info("Renamed " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath()); buildContext.refresh(destFile); } catch (IOException e) { throw new MojoExecutionException( "could not rename " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath(), e); } } }
From source file:com.codesynthesis.xsd.mapping_maven_plugin.AbstractCXXMappingMojo.java
protected void generateTree(Set<String> files, File toolDirectory) throws MojoExecutionException { Commandline cl = new Commandline(); cl.setExecutable(toolDirectory.getAbsolutePath() + "/bin/xsd"); cl.addArguments(new String[] { mappingType() }); addLicensing(cl);/*from ww w . ja v a 2 s . co m*/ addOptions(cl); cl.addArguments(getOptions()); addOtherOptions(cl); cl.addArguments(files.toArray(new String[0])); try { if (verbose) { getLog().info(cl.toString()); } else { getLog().debug(cl.toString()); } // TODO: maybe should report or do something with return value. int returnValue = CommandLineUtils.executeCommandLine(cl, new StreamConsumer() { public void consumeLine(final String line) { if (verbose) { getLog().info(line); } else { getLog().debug(line); } } }, new StreamConsumer() { public void consumeLine(final String line) { getLog().warn(line); } }); } catch (CommandLineException e) { throw new MojoExecutionException("Error running mapping-tools.", e); } }
From source file:com.codesynthesis.xsd.mapping_maven_plugin.AbstractCXXMappingMojo.java
public void execute() throws MojoExecutionException { if (!xsdInputDirectory.exists()) { getLog().info("XSD: input directory not found, no classes to process for JNI generation"); return;// w w w. j av a2 s . c o m } try { if (outputDirectory != null) outputDirectory.mkdirs(); SourceInclusionScanner scanner = new StaleSourceScanner(xsdStaleMillis, getIncludes(), getExcludes()); if (xsdTimestampFile != null && xsdTimestampDirectory != null) { if (!xsdTimestampDirectory.exists()) xsdTimestampDirectory.mkdirs(); // if( !xsdTimestampDirectory.exists() || xsdTimestampFile.isEmpty() ) tracking isn't going to work, always rebuild - warning? scanner.addSourceMapping(new SingleTargetSourceMapping(".xsd", xsdTimestampFile)); } else { Set<String> fileExts = new HashSet<String>(); fileExts.add(sourceSuffix); fileExts.add(headerSuffix); // TODO: what should we check for stale? Do we need to check all? // if( genInline ){ // fileExts.add( inlineSuffix ); // } xsdTimestampDirectory = outputDirectory; scanner.addSourceMapping(new SuffixMapping(".xsd", fileExts)); } Set<File> schemas = scanner.getIncludedSources(xsdInputDirectory, xsdTimestampDirectory); File toolDirectory = new File(mavenProject.getBuild().getDirectory(), toolsId); if (extendedUse) unpackFileBasedResources(toolDirectory); if (!schemas.isEmpty()) { Set<String> files = new HashSet<String>(); for (Iterator<File> i = schemas.iterator(); i.hasNext();) { files.add(i.next().getPath()); } if (!files.isEmpty()) { if (!extendedUse) unpackFileBasedResources(toolDirectory); generateTree(files, toolDirectory); if (xsdTimestampFile != null && xsdTimestampDirectory != null) { File timeStamp = new File(xsdTimestampDirectory, xsdTimestampFile); if (!timeStamp.exists()) try { timeStamp.createNewFile(); } catch (IOException e) { getLog().warn("XSD: Unable to touch timestamp file"); } else if (!timeStamp.setLastModified(System.currentTimeMillis())) getLog().warn("XSD: Unable to touch timestamp file"); } } } if (!extendedUse) cleanupFileBasedResources(toolDirectory); updateProject(); } catch (InclusionScanException e) { throw new MojoExecutionException("XSD: scanning for updated files failed", e); } }