List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.coderplus.plugins.CopyMojo.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 {// ww w . j av a 2 s.c o m getLog().error("sourceFile " + srcFile.getAbsolutePath() + " does not exist"); } } else if (srcFile.isDirectory()) { getLog().error("sourceFile " + srcFile.getAbsolutePath() + " is not a file"); } else if (destFile == null) { getLog().error("destinationFile not specified"); } else if (destFile.exists() && destFile.isFile() && !overWrite) { getLog().error(destFile.getAbsolutePath() + " already exists and overWrite not set"); } else { try { if (buildContext.isIncremental() && destFile.exists() && !buildContext.hasDelta(srcFile) && FileUtils.contentEquals(srcFile, destFile)) { getLog().info("No changes detected in " + srcFile.getAbsolutePath()); return; } FileUtils.copyFile(srcFile, destFile); getLog().info("Copied " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath()); buildContext.refresh(destFile); } catch (IOException e) { throw new MojoExecutionException( "could not copy " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath()); } } }
From source file:com.codesynthesis.xsd.mapping_maven_plugin.AbstractCXXMappingMojo.java
protected void unpackFileBasedResources(File toolDirectory) throws MojoExecutionException { getLog().info("unpacking xsd binaries"); Artifact artifact = findToolsArtifact(); getLog().info("Using mapping-tools " + artifact); File pluginJar = artifact.getFile(); getLog().info("Extracting " + pluginJar + " to " + toolDirectory); zipUnArchiver.setSourceFile(pluginJar); // bug: having trouble with extract method of unarchiver - nothing being extracted, or crashing on log file when creating the archiver directly. // zipUnArchiver.setDestDirectory( toolDirectory ); // zipUnArchiver.setOverwrite(true); // zipUnArchiver.extract(); zipUnArchiver.extract("bin", toolDirectory); // TODO: Still deciding if this content should be optional // if( visualStudioUse ) zipUnArchiver.extract("etc", toolDirectory); if (!toolDirectory.exists()) throw new MojoExecutionException("Error extracting resources from mapping-tools."); }
From source file:com.codesynthesis.xsd.mapping_maven_plugin.AbstractCXXMappingMojo.java
protected Artifact findToolsArtifact() throws MojoExecutionException { //return (Artifact) mavenPlugin.getArtifactMap().get(ArtifactUtils.versionlessKey(mavenPlugin.getGroupId(), toolsId)); if (null != artifacts) { for (Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();) { Artifact artifact = (Artifact) artifactIterator.next(); if (artifact.getGroupId().equals(pluginGroupId) && artifact.getArtifactId().equals(toolsId)) { // && artifact.getClassifier().equals( os. ) return artifact; }/*from w w w . j av a 2 s . c o m*/ } } getLog().error(String.format("Tools Artifact %1$s:%2$s not found", pluginGroupId, toolsId)); throw new MojoExecutionException("Unable to find mapping-tools dependency"); }
From source file:com.codetroopers.maven.mergeprops.MergeProperty.java
License:Apache License
private void saveToFile(final Map<String, Properties> mergedProperties) throws MojoExecutionException { final String targetPropertiesFileName = merge.getTarget(); final String suffix = extractFileSuffix(targetPropertiesFileName); final String prefix = extractFilePrefix(targetPropertiesFileName); File generated = new File(resourcePath); if (!generated.exists()) { final boolean mkdirs = generated.mkdirs(); if (!mkdirs) { throw new MojoExecutionException("Could not create directory : " + resourcePath); }/*from w w w . jav a2s . co m*/ } for (Map.Entry<String, Properties> propertiesEntry : mergedProperties.entrySet()) { File out = new File( resourcePath + File.separator + prefix + "_" + propertiesEntry.getKey() + "." + suffix); OutputStream output = null; try { if (out.exists() && !out.delete()) { throw new MojoExecutionException("Could not remove file: " + out.getAbsolutePath()); } if (!out.createNewFile()) { throw new MojoExecutionException("Could not create file: " + out.getAbsolutePath()); } output = new FileOutputStream(out); propertiesEntry.getValue().store(output, out.getName()); } catch (FileNotFoundException e) { throw new MojoExecutionException("Could not find file: " + out.getAbsolutePath(), e); } catch (IOException e) { throw new MojoExecutionException("Could not write to file: " + out.getAbsolutePath(), e); } finally { if (output != null) { try { output.close(); } catch (IOException e) { // no can do } } } } }