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.alibaba.citrus.maven.eclipse.base.eclipse.writers.AbstractEclipseManifestWriter.java
License:Apache License
/** * Verify is the manifest sould be overwritten this sould take in account that the manifest should only be written * if the contents of the classpath was changed not the order. The classpath sorting oder should be ignored. * * @param manifest the newly created classpath * @param manifestFile the file where the manifest * @return if the new manifest file must be written * @throws MojoExecutionException/*from ww w . j ava 2 s. com*/ */ protected boolean shouldNewManifestFileBeWritten(Manifest manifest, File manifestFile) throws MojoExecutionException { try { Manifest existingManifest = readExistingManifest(manifestFile); if (areManifestsEqual(manifest, existingManifest)) { this.log.info( Messages.getString("EclipsePlugin.unchangedmanifest", manifestFile.getAbsolutePath())); return false; } } catch (Exception e) { throw new MojoExecutionException( Messages.getString("EclipseCleanMojo.nofilefound", manifestFile.getAbsolutePath()), e); } return true; }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseAjdtWriter.java
License:Apache License
/** @see com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException { // check if it's necessary to create project specific settings Properties ajdtSettings = new Properties(); IdeDependency[] deps = config.getDeps(); int ajdtDepCount = 0; int ajdtWeaveDepCount = 0; for (int i = 0; i < deps.length; i++) { if (deps[i].isAjdtDependency()) { addDependency(ajdtSettings, deps[i], ASPECT_DEP_PROP, ++ajdtDepCount); }//from ww w .j av a2 s. c om if (deps[i].isAjdtWeaveDependency()) { addDependency(ajdtSettings, deps[i], WEAVE_DEP_PROP, ++ajdtWeaveDepCount); } } // write the settings, if needed if (!ajdtSettings.isEmpty()) { File settingsDir = new File(config.getEclipseProjectDirectory(), DIR_DOT_SETTINGS); //$NON-NLS-1$ settingsDir.mkdirs(); ajdtSettings.put(PROP_ECLIPSE_PREFERENCES_VERSION, "1"); //$NON-NLS-1$ try { File oldAjdtSettingsFile; File ajdtSettingsFile = new File(settingsDir, FILE_AJDT_PREFS); if (ajdtSettingsFile.exists()) { oldAjdtSettingsFile = ajdtSettingsFile; Properties oldsettings = new Properties(); oldsettings.load(new FileInputStream(oldAjdtSettingsFile)); Properties newsettings = (Properties) oldsettings.clone(); newsettings.putAll(ajdtSettings); if (!oldsettings.equals(newsettings)) { newsettings.store(new FileOutputStream(ajdtSettingsFile), null); } } else { ajdtSettings.store(new FileOutputStream(ajdtSettingsFile), null); log.info(Messages.getString("EclipseSettingsWriter.wrotesettings", //$NON-NLS-1$ ajdtSettingsFile.getCanonicalPath())); } } catch (FileNotFoundException e) { throw new MojoExecutionException(Messages.getString("EclipseSettingsWriter.cannotcreatesettings"), e); //$NON-NLS-1$ } catch (IOException e) { throw new MojoExecutionException(Messages.getString("EclipseSettingsWriter.errorwritingsettings"), e); //$NON-NLS-1$ } } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseClasspathWriter.java
License:Apache License
/** @see com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException { Writer w;/*w w w . j av a 2 s .c o m*/ try { w = new OutputStreamWriter( new FileOutputStream(new File(config.getEclipseProjectDirectory(), FILE_DOT_CLASSPATH)), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); writer.startElement(ELT_CLASSPATH); String defaultOutput = IdeUtils.toRelativeAndFixSeparator(config.getProjectBaseDir(), config.getBuildOutputDirectory(), false); // ---------------------------------------------------------------------- // Source roots and resources // ---------------------------------------------------------------------- // List<EclipseSourceDir> List specialSources = new ArrayList(); // Map<String,List<EclipseSourceDir>> Map byOutputDir = new HashMap(); for (int j = 0; j < config.getSourceDirs().length; j++) { EclipseSourceDir dir = config.getSourceDirs()[j]; // List<EclipseSourceDir> List byOutputDirs = (List) byOutputDir.get(dir.getOutput()); if (byOutputDirs == null) { // ArrayList<EclipseSourceDir> byOutputDir.put(dir.getOutput() == null ? defaultOutput : dir.getOutput(), byOutputDirs = new ArrayList()); } byOutputDirs.add(dir); } for (int j = 0; j < config.getSourceDirs().length; j++) { EclipseSourceDir dir = config.getSourceDirs()[j]; log.debug("Processing classpath for: " + dir.toString() + "; default output=" + defaultOutput); boolean isSpecial = false; // handle resource with nested output folders if (dir.isResource()) { // Check if the output is a subdirectory of the default output, // and if the default output has any sources that copy there. if (dir.getOutput() != null // resource output dir is set && !dir.getOutput().equals(defaultOutput) // output dir is not default target/classes && dir.getOutput().startsWith(defaultOutput) // ... but is nested && byOutputDir.get(defaultOutput) != null // ??? && !((List) byOutputDir.get(defaultOutput)).isEmpty() // ??? ) { // do not specify as source since the output will be nested. Instead, mark // it as a todo, and handle it with a custom build.xml file later. log.debug("Marking as special to prevent output folder nesting: " + dir.getPath() + " (output=" + dir.getOutput() + ")"); isSpecial = true; specialSources.add(dir); } } writer.startElement(ELT_CLASSPATHENTRY); writer.addAttribute(ATTR_KIND, "src"); //$NON-NLS-1$ writer.addAttribute(ATTR_PATH, dir.getPath()); if (!isSpecial && dir.getOutput() != null && !defaultOutput.equals(dir.getOutput())) { writer.addAttribute(ATTR_OUTPUT, dir.getOutput()); } String includes = dir.getIncludeAsString(); if (StringUtils.isNotEmpty(includes)) { writer.addAttribute(ATTR_INCLUDING, includes); } String excludes = dir.getExcludeAsString(); if (StringUtils.isNotEmpty(excludes)) { writer.addAttribute(ATTR_EXCLUDING, excludes); } writer.endElement(); } // handle the special sources. if (!specialSources.isEmpty()) { log.info("Creating maven-eclipse.xml Ant file to handle resources"); try { Writer buildXmlWriter = new OutputStreamWriter( new FileOutputStream(new File(config.getEclipseProjectDirectory(), "maven-eclipse.xml")), "UTF-8"); PrettyPrintXMLWriter buildXmlPrinter = new PrettyPrintXMLWriter(buildXmlWriter); buildXmlPrinter.startElement("project"); buildXmlPrinter.addAttribute("default", "copy-resources"); buildXmlPrinter.startElement("target"); buildXmlPrinter.addAttribute(NAME, "init"); // initialize filtering tokens here buildXmlPrinter.endElement(); buildXmlPrinter.startElement("target"); buildXmlPrinter.addAttribute(NAME, "copy-resources"); buildXmlPrinter.addAttribute("depends", "init"); for (Iterator it = specialSources.iterator(); it.hasNext();) { // TODO: merge source dirs on output path+filtering to reduce // <copy> tags for speed. EclipseSourceDir dir = (EclipseSourceDir) it.next(); buildXmlPrinter.startElement("copy"); buildXmlPrinter.addAttribute("todir", dir.getOutput()); buildXmlPrinter.addAttribute("filtering", "" + dir.isFiltering()); buildXmlPrinter.startElement("fileset"); buildXmlPrinter.addAttribute("dir", dir.getPath()); if (dir.getIncludeAsString() != null) { buildXmlPrinter.addAttribute("includes", dir.getIncludeAsString()); } if (dir.getExcludeAsString() != null) { buildXmlPrinter.addAttribute("excludes", dir.getExcludeAsString()); } buildXmlPrinter.endElement(); buildXmlPrinter.endElement(); } buildXmlPrinter.endElement(); buildXmlPrinter.endElement(); IOUtil.close(buildXmlWriter); } catch (IOException e) { throw new MojoExecutionException( "Cannot create " + config.getEclipseProjectDirectory() + "/maven-eclipse.xml", e); } log.info("Creating external launcher file"); // now create the launcher new EclipseAntExternalLaunchConfigurationWriter() .init(log, config, "Maven_Ant_Builder.launch", "maven-eclipse.xml").write(); // finally add it to the project writer. config.getBuildCommands() .add(new BuildCommand("org.eclipse.ui.externaltools.ExternalToolBuilder", "LaunchConfigHandle", "<project>/" + EclipseLaunchConfigurationWriter.FILE_DOT_EXTERNAL_TOOL_BUILDERS + "Maven_Ant_Builder.launch")); } // ---------------------------------------------------------------------- // The default output // ---------------------------------------------------------------------- writer.startElement(ELT_CLASSPATHENTRY); writer.addAttribute(ATTR_KIND, ATTR_OUTPUT); writer.addAttribute(ATTR_PATH, defaultOutput); writer.endElement(); Set addedDependencies = new HashSet(); // ---------------------------------------------------------------------- // Java API dependencies that may complete the classpath container must // be declared BEFORE all other dependencies so that container access rules don't fail // ---------------------------------------------------------------------- IdeDependency[] depsToWrite = config.getDeps(); for (int j = 0; j < depsToWrite.length; j++) { IdeDependency dep = depsToWrite[j]; if (dep.isJavaApi()) { String depId = getDependencyId(dep); if (!addedDependencies.contains(depId)) { addDependency(writer, dep); addedDependencies.add(depId); } } } if (!config.isClasspathContainersLast()) { writeClasspathContainers(writer); } // ---------------------------------------------------------------------- // The project's dependencies // ---------------------------------------------------------------------- for (int j = 0; j < depsToWrite.length; j++) { IdeDependency dep = depsToWrite[j]; if (dep.isAddedToClasspath()) { String depId = getDependencyId(dep); /* avoid duplicates in the classpath for artifacts with different types (like ejbs or test-jars) */ if (!addedDependencies.contains(depId)) { addDependency(writer, dep); addedDependencies.add(depId); } } } if (config.isClasspathContainersLast()) { writeClasspathContainers(writer); } writer.endElement(); IOUtil.close(w); }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseProjectWriter.java
License:Apache License
/** @see com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException { Set projectnatures = new LinkedHashSet(); Set buildCommands = new LinkedHashSet(); Set linkedResources = new LinkedHashSet(); File dotProject = new File(config.getEclipseProjectDirectory(), FILE_DOT_PROJECT); if (dotProject.exists()) { log.info(Messages.getString("EclipsePlugin.keepexisting", dotProject.getAbsolutePath())); //$NON-NLS-1$ // parse existing file in order to keep manually-added entries Reader reader = null;/*from ww w . j a v a 2 s .c o m*/ try { reader = new InputStreamReader(new FileInputStream(dotProject), "UTF-8"); Xpp3Dom dom = Xpp3DomBuilder.build(reader); Xpp3Dom naturesElement = dom.getChild(ELT_NATURES); if (naturesElement != null) { Xpp3Dom[] existingNatures = naturesElement.getChildren(ELT_NATURE); for (int j = 0; j < existingNatures.length; j++) { // adds all the existing natures projectnatures.add(existingNatures[j].getValue()); } } Xpp3Dom buildSpec = dom.getChild(ELT_BUILD_SPEC); if (buildSpec != null) { Xpp3Dom[] existingBuildCommands = buildSpec.getChildren(ELT_BUILD_COMMAND); for (int j = 0; j < existingBuildCommands.length; j++) { Xpp3Dom buildCommandName = existingBuildCommands[j].getChild(ELT_NAME); if (buildCommandName != null) { buildCommands.add(new BuildCommand(existingBuildCommands[j])); } } } // Added the below code to preserve the Symbolic links Xpp3Dom linkedResourcesElement = dom.getChild(ELT_LINKED_RESOURCES); if (linkedResourcesElement != null) { Xpp3Dom[] existingLinks = linkedResourcesElement.getChildren(ELT_LINK); for (int j = 0; j < existingLinks.length; j++) { Xpp3Dom linkName = existingLinks[j].getChild(ELT_NAME); if (linkName != null) { // add all the existing symbolic links linkNames.add(existingLinks[j].getChild(ELT_NAME).getValue()); linkedResources.add(new LinkedResource(existingLinks[j])); } } } } catch (XmlPullParserException e) { log.warn(Messages.getString("EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath())); //$NON-NLS-1$ } catch (IOException e) { log.warn(Messages.getString("EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath())); //$NON-NLS-1$ } finally { IOUtil.close(reader); } } // adds new entries after the existing ones for (Iterator iter = config.getProjectnatures().iterator(); iter.hasNext();) { projectnatures.add(iter.next()); } for (Iterator iter = config.getBuildCommands().iterator(); iter.hasNext();) { buildCommands.add((BuildCommand) iter.next()); } for (Iterator iter = config.getLinkedResources().iterator(); iter.hasNext();) { linkedResources.add((LinkedResource) iter.next()); } Writer w; try { w = new OutputStreamWriter(new FileOutputStream(dotProject), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); writer.startElement("projectDescription"); //$NON-NLS-1$ writer.startElement(ELT_NAME); writer.writeText(config.getEclipseProjectName()); writer.endElement(); addComment(writer, config.getProject().getDescription()); writer.startElement("projects"); //$NON-NLS-1$ IdeDependency[] dependencies = config.getDeps(); // referenced projects should not be added for plugins if (!config.isPde()) { List duplicates = new ArrayList(); for (int j = 0; j < dependencies.length; j++) { IdeDependency dep = dependencies[j]; // Avoid duplicates entries when same project is refered using multiple types // (ejb, test-jar ...) if (dep.isReferencedProject() && !duplicates.contains(dep.getEclipseProjectName())) { writer.startElement("project"); //$NON-NLS-1$ writer.writeText(dep.getEclipseProjectName()); writer.endElement(); duplicates.add(dep.getEclipseProjectName()); } } } writer.endElement(); // projects writer.startElement(ELT_BUILD_SPEC); for (Iterator it = buildCommands.iterator(); it.hasNext();) { ((BuildCommand) it.next()).print(writer); } writer.endElement(); // buildSpec writer.startElement(ELT_NATURES); for (Iterator it = projectnatures.iterator(); it.hasNext();) { writer.startElement(ELT_NATURE); writer.writeText((String) it.next()); writer.endElement(); // name } writer.endElement(); // natures boolean addLinks = !config.getProjectBaseDir().equals(config.getEclipseProjectDirectory()); if (addLinks || (config.isPde() && dependencies.length > 0) || linkedResources.size() > 0) { writer.startElement("linkedResources"); //$NON-NLS-1$ // preserve the symbolic links if (linkedResources.size() > 0) { for (Iterator it = linkedResources.iterator(); it.hasNext();) { ((LinkedResource) it.next()).print(writer); } } if (addLinks) { addFileLink(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(), config.getProject().getFile()); addSourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(), config.getProject().getCompileSourceRoots()); addResourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(), config.getProject().getBuild().getResources()); addSourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(), config.getProject().getTestCompileSourceRoots()); addResourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(), config.getProject().getBuild().getTestResources()); } writeResourceLinksForPdeProject(writer, dependencies); writer.endElement(); // linkedResources } writer.endElement(); // projectDescription IOUtil.close(w); }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.rad.RadApplicationXMLWriter.java
License:Apache License
/** * write back a domtree to a xmlfile and use the pretty print for it so that it is human readable. * * @param xmlFile file to write to// www . j a v a 2 s . c om * @param xmlDomTree dom-tree to write * @throws MojoExecutionException if the file could not be written */ private void writePrettyXmlFile(File xmlFile, Xpp3Dom xmlDomTree) throws MojoExecutionException { Xpp3Dom original = readXMLFile(xmlFile); if (original != null && original.equals(xmlDomTree)) { log.info(Messages.getString("EclipsePlugin.unchangedmanifest", xmlFile.getAbsolutePath())); return; } Writer w = null; xmlFile.getParentFile().mkdirs(); try { w = new OutputStreamWriter(new FileOutputStream(xmlFile), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); Xpp3DomWriter.write(writer, xmlDomTree); IOUtil.close(w); }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.rad.RadEjbClasspathWriter.java
License:Apache License
/** * write the .classpath file to the project root directory. * * @param sourceDirs all eclipse source directorys * @param localRepository the local reposetory * @param buildOutputDirectory build output directory (target) * @throws MojoExecutionException when writing the config files was not possible * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File) *///from ww w.j a v a 2 s . co m public void write() throws MojoExecutionException { String packaging = config.getPackaging(); if (Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase(packaging)) { new File(config.getEclipseProjectDirectory(), TARGET_WEBSPHERE_CLASSES).mkdirs(); File classpathFile = new File(config.getEclipseProjectDirectory(), CLASSPATH_FILE); if (!classpathFile.exists()) { return; } Xpp3Dom classpath = readXMLFile(classpathFile); Xpp3Dom[] children = classpath.getChildren(); for (int index = 0; index < children.length; index++) { if (LIB.equals(children[index].getAttribute(KIND)) && TARGET_WEBSPHERE_CLASSES.equals(children[index].getAttribute("path"))) { return; // nothing to do! } } Xpp3Dom newEntry = new Xpp3Dom(CLASSPATHENTRY); newEntry.setAttribute(KIND, LIB); newEntry.setAttribute(PATH, TARGET_WEBSPHERE_CLASSES); classpath.addChild(newEntry); newEntry = new Xpp3Dom(CLASSPATHENTRY); newEntry.setAttribute(KIND, CON); newEntry.setAttribute(PATH, WEBSPHERE6CONTAINER); classpath.addChild(newEntry); children = classpath.getChildren(); for (int index = children.length - 1; index >= 0; index--) { if (children[index].getValue() == null) { children[index].setValue(""); } } removeDupicateWAS6Libs(classpath); classpath = orderClasspath(classpath); Writer w; try { w = new OutputStreamWriter(new FileOutputStream(classpathFile), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); Xpp3DomWriter.write(writer, classpath); IOUtil.close(w); } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.rad.RadJ2EEWriter.java
License:Apache License
/** * write the .j2ee file to the project root directory. * * @param sourceDirs all eclipse source directorys * @param localRepository the local reposetory * @param buildOutputDirectory build output directory (target) * @throws MojoExecutionException when writing the config files was not possible * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File) *///from ww w . ja v a 2s . c om public void write() throws MojoExecutionException { Writer w; String packaging = config.getPackaging(); if (Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase(packaging) || Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase(packaging) || Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase(packaging)) { try { w = new OutputStreamWriter( new FileOutputStream(new File(config.getEclipseProjectDirectory(), J2EE_FILENAME)), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); writeModuleTypeFacetCore(writer, packaging); IOUtil.close(w); } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.rad.RadLibCopier.java
License:Apache License
/** * Does the actual copy of the file and logging. * * @param artifact represents the file to copy. * @param destFile file name of destination file. * @param log to use for output./*from www.jav a 2s .co m*/ * @throws MojoExecutionException with a message if an error occurs. */ private void copyFile(File artifact, File destFile, Log log) throws MojoExecutionException { try { log.info("Copying " + artifact.getAbsolutePath() + " to " + destFile); FileUtils.copyFile(artifact, destFile); } catch (IOException e) { throw new MojoExecutionException("Error copying artifact from " + artifact + " to " + destFile, e); } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.rad.RadWebSettingsWriter.java
License:Apache License
/** * write the websettings file for RAD6 if needed. * * @throws MojoExecutionException when writing the config files was not possible */// w w w . j a v a 2s. c o m public void write() throws MojoExecutionException { Writer w; if (Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase(config.getPackaging())) { try { w = new OutputStreamWriter( new FileOutputStream(new File(config.getEclipseProjectDirectory(), WEBSETTINGS_FILENAME)), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); writeModuleTypeFacetCore(writer); IOUtil.close(w); } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.rad.RadWebsiteConfigWriter.java
License:Apache License
/** * write the website-config file for RAD6 if needed. * * @param sourceDirs all eclipse source directorys * @param localRepository the local reposetory * @param buildOutputDirectory build output directory (target) * @throws MojoExecutionException when writing the config files was not possible * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File) *//* w ww . ja v a2 s .c om*/ public void write() throws MojoExecutionException { Writer w; if (Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase(config.getPackaging())) { try { w = new OutputStreamWriter(new FileOutputStream( new File(config.getEclipseProjectDirectory(), WEBSITE_CONFIG_FILENAME)), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); writeModuleTypeFacetCore(writer); IOUtil.close(w); } }