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:cn.wanghaomiao.maven.plugin.seimi.packaging.AbstractWarPackagingTask.java
License:Apache License
/** * Copy the specified file if the target location has not yet already been used and filter its content with the * configured filter properties./*from w w w . ja va 2s.c o m*/ * <p/> * The <tt>targetFileName</tt> is the relative path according to the root of the generated web application. * * @param sourceId the source id * @param context the context to use * @param file the file to copy * @param targetFilename the relative path according to the root of the webapp * @return true if the file has been copied, false otherwise * @throws IOException if an error occurred while copying * @throws MojoExecutionException if an error occurred while retrieving the filter properties */ protected boolean copyFilteredFile(String sourceId, final WarPackagingContext context, File file, String targetFilename) throws IOException, MojoExecutionException { if (context.getWebappStructure().registerFile(sourceId, targetFilename)) { final File targetFile = new File(context.getWebappDirectory(), targetFilename); final String encoding; try { if (isXmlFile(file)) { // For xml-files we extract the encoding from the files encoding = getEncoding(file); } else { // For all others we use the configured encoding encoding = context.getResourceEncoding(); } // fix for MWAR-36, ensures that the parent dir are created first targetFile.getParentFile().mkdirs(); context.getMavenFileFilter().copyFile(file, targetFile, true, context.getFilterWrappers(), encoding); } catch (MavenFilteringException e) { throw new MojoExecutionException(e.getMessage(), e); } // CHECKSTYLE_OFF: LineLength // Add the file to the protected list context.getLog() .debug(" + " + targetFilename + " has been copied (filtered encoding='" + encoding + "')."); // CHECKSTYLE_ON: LineLength return true; } else { context.getLog().debug( " - " + targetFilename + " wasn't copied because it has already been packaged (filtered)."); return false; } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.AbstractWarPackagingTask.java
License:Apache License
/** * Unpacks the specified file to the specified directory. * * @param context the packaging context// w w w.j a v a2 s .c o m * @param file the file to unpack * @param unpackDirectory the directory to use for th unpacked file * @throws MojoExecutionException if an error occurred while unpacking the file */ protected void doUnpack(WarPackagingContext context, File file, File unpackDirectory) throws MojoExecutionException { String archiveExt = FileUtils.getExtension(file.getAbsolutePath()).toLowerCase(); try { UnArchiver unArchiver = context.getArchiverManager().getUnArchiver(archiveExt); unArchiver.setSourceFile(file); unArchiver.setUseJvmChmod(context.isUseJvmChmod()); unArchiver.setDestDirectory(unpackDirectory); unArchiver.setOverwrite(true); unArchiver.extract(); } catch (ArchiverException e) { throw new MojoExecutionException("Error unpacking file [" + file.getAbsolutePath() + "]" + "to [" + unpackDirectory.getAbsolutePath() + "]", e); } catch (NoSuchArchiverException e) { context.getLog().warn("Skip unpacking dependency file [" + file.getAbsolutePath() + " with unknown extension [" + archiveExt + "]"); } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.ArtifactsPackagingTask.java
License:Apache License
/** * {@inheritDoc}//w w w. j ava2 s. c o m */ public void performPackaging(WarPackagingContext context) throws MojoExecutionException { try { final ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); final List<String> duplicates = findDuplicates(context, artifacts); for (Artifact artifact : artifacts) { String targetFileName = getArtifactFinalName(context, artifact); context.getLog().debug("Processing: " + targetFileName); if (duplicates.contains(targetFileName)) { context.getLog().debug("Duplicate found: " + targetFileName); targetFileName = artifact.getGroupId() + "-" + targetFileName; context.getLog().debug("Renamed to: " + targetFileName); } context.getWebappStructure().registerTargetFileName(artifact, targetFileName); if (!artifact.isOptional() && filter.include(artifact)) { try { String type = artifact.getType(); if ("tld".equals(type)) { copyFile(id, context, artifact.getFile(), TLD_PATH + targetFileName); } else if ("aar".equals(type)) { copyFile(id, context, artifact.getFile(), SERVICES_PATH + targetFileName); } else if ("mar".equals(type)) { copyFile(id, context, artifact.getFile(), MODULES_PATH + targetFileName); } else if ("xar".equals(type)) { copyFile(id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName); } else if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type) || "test-jar".equals(type) || "bundle".equals(type)) { copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName); } else if ("par".equals(type)) { targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar"; copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName); } else if ("war".equals(type)) { // Nothing to do here, it is an overlay and it's already handled context.getLog() .debug("war artifacts are handled as overlays, ignoring [" + artifact + "]"); } else if ("zip".equals(type)) { // Nothing to do here, it is an overlay and it's already handled context.getLog() .debug("zip artifacts are handled as overlays, ignoring [" + artifact + "]"); } else { context.getLog().debug("Artifact of type [" + type + "] is not supported, ignoring [" + artifact + "]"); } } catch (IOException e) { throw new MojoExecutionException("Failed to copy file for artifact [" + artifact + "]", e); } } } } catch (InterpolationException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.ClassesPackagingTask.java
License:Apache License
/** * {@inheritDoc}/*from w w w . j av a 2 s. c om*/ */ public void performPackaging(WarPackagingContext context) throws MojoExecutionException { final File webappClassesDirectory = new File(context.getWebappDirectory(), CLASSES_PATH); if (!webappClassesDirectory.exists()) { webappClassesDirectory.mkdirs(); } if (context.getClassesDirectory().exists() && !context.getClassesDirectory().equals(webappClassesDirectory)) { if (context.archiveClasses()) { generateJarArchive(context); } else { final PathSet sources = getFilesToIncludes(context.getClassesDirectory(), null, null); try { copyFiles(currentProjectOverlay.getId(), context, context.getClassesDirectory(), sources, CLASSES_PATH, false); } catch (IOException e) { throw new MojoExecutionException("Could not copy webapp classes [" + context.getClassesDirectory().getAbsolutePath() + "]", e); } } } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.ClassesPackagingTask.java
License:Apache License
/** * @param context The warPackingContext. * @throws MojoExecutionException In casae of an error. *///from w ww. java 2 s. c om protected void generateJarArchive(WarPackagingContext context) throws MojoExecutionException { MavenProject project = context.getProject(); ArtifactFactory factory = context.getArtifactFactory(); Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar"); String archiveName; try { archiveName = getArtifactFinalName(context, artifact); } catch (InterpolationException e) { throw new MojoExecutionException("Could not get the final name of the artifact [" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e); } final String targetFilename = LIB_PATH + archiveName; if (context.getWebappStructure().registerFile(currentProjectOverlay.getId(), targetFilename)) { final File libDirectory = new File(context.getWebappDirectory(), LIB_PATH); final File jarFile = new File(libDirectory, archiveName); final ClassesPackager packager = new ClassesPackager(); packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), context.getSession(), project, context.getArchive()); } else { context.getLog().warn( "Could not generate archive classes file [" + targetFilename + "] has already been copied."); } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.CopyUserManifestTask.java
License:Apache License
public void performPackaging(WarPackagingContext context) throws MojoExecutionException, MojoFailureException { File userManifest = context.getArchive().getManifestFile(); if (userManifest != null) { try {/* ww w .ja v a 2 s. c o m*/ getLog().info("Copying manifest..."); File metainfDir = new File(context.getWebappDirectory(), META_INF_PATH); copyFile(context, userManifest, new File(metainfDir, "MANIFEST.MF"), "META-INF/MANIFEST.MF", true); } catch (IOException e) { throw new MojoExecutionException("Error copying user manifest", e); } } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.OverlayPackagingTask.java
License:Apache License
/** * {@inheritDoc}//from ww w .j a v a 2 s. c o m */ public void performPackaging(WarPackagingContext context) throws MojoExecutionException { context.getLog() .debug("OverlayPackagingTask performPackaging overlay.getTargetPath() " + overlay.getTargetPath()); if (overlay.shouldSkip()) { context.getLog().info("Skipping overlay [" + overlay + "]"); } else { try { context.getLog().info("Processing overlay [" + overlay + "]"); // Step1: Extract if necessary final File tmpDir = unpackOverlay(context, overlay); // Step2: setup final PathSet includes = getFilesToIncludes(tmpDir, overlay.getIncludes(), overlay.getExcludes()); // Copy if (null == overlay.getTargetPath()) { copyFiles(overlay.getId(), context, tmpDir, includes, overlay.isFiltered()); } else { // overlay.getTargetPath() must ended with / // if not we add it String targetPath = overlay.getTargetPath(); if (!targetPath.endsWith("/")) { targetPath = targetPath + "/"; } copyFiles(overlay.getId(), context, tmpDir, includes, targetPath, overlay.isFiltered()); } } catch (IOException e) { throw new MojoExecutionException("Failed to copy file for overlay [" + overlay + "]", e); } } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.SaveWebappStructurePostPackagingTask.java
License:Apache License
/** * {@inheritDoc}//from w ww. java 2 s . com */ public void performPostPackaging(WarPackagingContext context) throws MojoExecutionException, MojoFailureException { if (targetFile == null) { context.getLog().debug("Cache usage is disabled, not saving webapp structure."); } else { try { serialier.toXml(context.getWebappStructure(), targetFile); context.getLog().debug("Cache saved successfully."); } catch (IOException e) { throw new MojoExecutionException("Could not save webapp structure", e); } } }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.WarProjectPackagingTask.java
License:Apache License
/** * Handles the webapp sources./*from ww w . jav a 2 s . c om*/ * * @param context the packaging context * @throws MojoExecutionException if the sources could not be copied */ protected void handeWebAppSourceDirectory(WarPackagingContext context) throws MojoExecutionException { // CHECKSTYLE_OFF: LineLength if (!context.getWebappSourceDirectory().exists()) { context.getLog().debug("webapp sources directory does not exist - skipping."); } else if (!context.getWebappSourceDirectory().getAbsolutePath() .equals(context.getWebappDirectory().getPath())) { context.getLog().info("Copying webapp resources [" + context.getWebappSourceDirectory() + "]"); final PathSet sources = getFilesToIncludes(context.getWebappSourceDirectory(), context.getWebappSourceIncludes(), context.getWebappSourceExcludes(), context.isWebappSourceIncludeEmptyDirectories()); try { copyFiles(id, context, context.getWebappSourceDirectory(), sources, false); } catch (IOException e) { throw new MojoExecutionException( "Could not copy webapp sources [" + context.getWebappDirectory().getAbsolutePath() + "]", e); } } // CHECKSTYLE_ON: LineLength }
From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.WarProjectPackagingTask.java
License:Apache License
/** * Handles the deployment descriptors, if specified. Note that the behavior here is slightly different since the * customized entry always win, even if an overlay has already packaged a web.xml previously. * * @param context the packaging context/*from www .j a v a2 s . com*/ * @param webinfDir the web-inf directory * @param metainfDir the meta-inf directory * @throws MojoFailureException if the web.xml is specified but does not exist * @throws MojoExecutionException if an error occurred while copying the descriptors */ protected void handleDeploymentDescriptors(WarPackagingContext context, File webinfDir, File metainfDir) throws MojoFailureException, MojoExecutionException { try { if (webXml != null && StringUtils.isNotEmpty(webXml.getName())) { if (!webXml.exists()) { throw new MojoFailureException("The specified web.xml file '" + webXml + "' does not exist"); } // Making sure that it won't get overlayed context.getWebappStructure().registerFileForced(id, WEB_INF_PATH + "/web.xml"); if (context.isFilteringDeploymentDescriptors()) { context.getMavenFileFilter().copyFile(webXml, new File(webinfDir, "web.xml"), true, context.getFilterWrappers(), getEncoding(webXml)); } else { copyFile(context, webXml, new File(webinfDir, "web.xml"), "WEB-INF/web.xml", true); } } else { // the webXml can be the default one File defaultWebXml = new File(context.getWebappSourceDirectory(), WEB_INF_PATH + "/web.xml"); // if exists we can filter it if (defaultWebXml.exists() && context.isFilteringDeploymentDescriptors()) { context.getWebappStructure().registerFile(id, WEB_INF_PATH + "/web.xml"); context.getMavenFileFilter().copyFile(defaultWebXml, new File(webinfDir, "web.xml"), true, context.getFilterWrappers(), getEncoding(defaultWebXml)); } } if (containerConfigXML != null && StringUtils.isNotEmpty(containerConfigXML.getName())) { String xmlFileName = containerConfigXML.getName(); context.getWebappStructure().registerFileForced(id, META_INF_PATH + "/" + xmlFileName); if (context.isFilteringDeploymentDescriptors()) { context.getMavenFileFilter().copyFile(containerConfigXML, new File(metainfDir, xmlFileName), true, context.getFilterWrappers(), getEncoding(containerConfigXML)); } else { copyFile(context, containerConfigXML, new File(metainfDir, xmlFileName), "META-INF/" + xmlFileName, true); } } } catch (IOException e) { throw new MojoExecutionException("Failed to copy deployment descriptor", e); } catch (MavenFilteringException e) { throw new MojoExecutionException("Failed to copy deployment descriptor", e); } }