List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
private void buildAspectjDeps(IdeDependency[] deps) throws MojoExecutionException { Xpp3Dom configuration = getAspectjConfiguration(executedProject); if (configuration != null) { Xpp3Dom aspectLibrariesParent = configuration.getChild(ASPECT_LIBRARIES); if (aspectLibrariesParent != null) { Xpp3Dom[] aspectLibraries = aspectLibrariesParent.getChildren(ASPECT_LIBRARY); outerLoop: for (int i = 0; i < aspectLibraries.length; i++) { String artifactId = aspectLibraries[i].getChild(POM_ELT_ARTIFACT_ID).getValue(); String groupId = aspectLibraries[i].getChild(POM_ELT_GROUP_ID).getValue(); for (int j = 0; j < deps.length; j++) { if (deps[j].getArtifactId().equals(artifactId) && deps[j].getGroupId().equals(groupId)) { deps[j].setAjdtDependency(true); continue outerLoop; }// w ww . j av a 2 s .c o m } throw new MojoExecutionException("AspectLibrary is not a dependency of project"); } } } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
private void buildAjdtWeaveDeps(IdeDependency[] deps) throws MojoExecutionException { Xpp3Dom configuration = getAspectjConfiguration(executedProject); if (configuration != null) { Xpp3Dom weaveDependenciesParent = configuration.getChild(WEAVE_DEPENDENCIES); if (weaveDependenciesParent != null) { Xpp3Dom[] weaveDependencies = weaveDependenciesParent.getChildren(WEAVE_DEPENDENCY); outerLoop: for (int i = 0; i < weaveDependencies.length; i++) { String artifactId = weaveDependencies[i].getChild(POM_ELT_ARTIFACT_ID).getValue(); String groupId = weaveDependencies[i].getChild(POM_ELT_GROUP_ID).getValue(); for (int j = 0; j < deps.length; j++) { if (deps[j].getArtifactId().equals(artifactId) && deps[j].getGroupId().equals(groupId)) { deps[j].setAjdtWeaveDependency(true); continue outerLoop; }// w ww. j a va2s. c om } throw new MojoExecutionException("WeaveDependency is not a dependency of project"); } } } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.AbstractEclipseManifestWriter.java
License:Apache License
/** * If the existing manifest file located in <code>getMetaInfBaseDirectory()</code> already has a correct * MANIFEST_VERSION and CLASS_PATH value then do nothing. * <p/>//from w ww . j a va 2 s . c om * Otherwise generate a <b>NEW</b> (i.e the old one is overwritten) which only contains values for MANIFEST_VERSION * and CLASS_PATH, all other previous entries are not kept. * * @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) */ public void write() throws MojoExecutionException { String metaInfBaseDirectory = getMetaInfBaseDirectory(this.config.getProject()); if (metaInfBaseDirectory == null) { // TODO: if this really is an error, shouldn't we stop the build?? throw new MojoExecutionException(Messages.getString("EclipseCleanMojo.nofilefound", new Object[] { EclipseManifestWriter.META_INF_DIRECTORY })); } File manifestFile = new File( metaInfBaseDirectory + File.separatorChar + EclipseManifestWriter.META_INF_DIRECTORY + File.separatorChar + EclipseManifestWriter.MANIFEST_MF_FILENAME); Manifest manifest = createNewManifest(); if (shouldNewManifestFileBeWritten(manifest, manifestFile)) { log.info("Writing manifest..."); manifestFile.getParentFile().mkdirs(); try { FileOutputStream stream = new FileOutputStream(manifestFile); manifest.write(stream); stream.close(); } catch (Exception e) { this.log.error(Messages.getString("EclipsePlugin.cantwritetofile", new Object[] { manifestFile.getAbsolutePath() })); } } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseLaunchConfigurationWriter.java
License:Apache License
public void write() throws MojoExecutionException { if (!initialized) { throw new MojoExecutionException("Not initialized"); }/*from w w w.j a va 2 s .c om*/ Writer w; try { File extToolsDir = new File(config.getEclipseProjectDirectory(), FILE_DOT_EXTERNAL_TOOL_BUILDERS); if (!extToolsDir.exists() && !extToolsDir.mkdir()) { throw new MojoExecutionException("Error creating directory " + extToolsDir); } w = new OutputStreamWriter(new FileOutputStream(new File(extToolsDir, 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); writer.startElement("launchConfiguration"); writer.addAttribute("type", getLaunchConfigurationType()); writeAttribute(writer, "org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND", isLaunchInBackground()); writeAttribute(writer, "org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS", StringUtils.join(getRunBuildKinds(), ",")); // i think this one means if the ATTR_RUN_BUILD_KINDS is not default. writeAttribute(writer, "org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED", true); writeAttribute(writer, "org.eclipse.debug.core.appendEnvironmentVariables", isAppendEnvironmentVariables()); writeAttribute(writer, "org.eclipse.jdt.launching.PROJECT_ATTR", config.getEclipseProjectName()); writeAttribute(writer, "org.eclipse.jdt.launching.DEFAULT_CLASSPATH", true); writeAttribute(writer, "org.eclipse.ui.externaltools.ATTR_LOCATION", getBuilderLocation()); if (getWorkingDirectory() != null) { writeAttribute(writer, "org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY", getWorkingDirectory()); } if (getRefreshScope() != null) { writeAttribute(writer, "org.eclipse.debug.core.ATTR_REFRESH_SCOPE", getRefreshScope()); } writeAttribute(writer, "org.eclipse.debug.core.capture_output", isCaptureOutput()); String workingSet = "<?xml version='1.0'?>" + "<launchConfigurationWorkingSet editPageId='org.eclipse.ui.resourceWorkingSetPage'" + " factoryID='org.eclipse.ui.internal.WorkingSetFactory'" + " label='workingSet'" + " name='workingSet'>"; for (Iterator it = getMonitoredResources().iterator(); it.hasNext();) { MonitoredResource monitoredResource = (MonitoredResource) it.next(); workingSet += monitoredResource.print(); } workingSet += "</launchConfigurationWorkingSet>"; writeAttribute(writer, "org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE", "${working_set:" + workingSet + "}"); addAttributes(writer); writer.endElement(); IOUtil.close(w); }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseOSGiManifestWriter.java
License:Apache License
/** @see com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException { // check for existence if (!config.getOSGIManifestFile().exists()) { log.warn(Messages.getString("EclipseOSGiManifestWriter.nomanifestfile", config.getOSGIManifestFile().getAbsolutePath())); return;/*w ww.j av a 2 s . co m*/ } StringBuffer manifestSb = rewriteManifest(config.getOSGIManifestFile()); Writer out = null; try { out = new OutputStreamWriter(new FileOutputStream(config.getOSGIManifestFile()), "UTF-8"); out.write(manifestSb.toString()); } catch (FileNotFoundException e) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.cantwritetofile", config.getOSGIManifestFile().getAbsolutePath())); } catch (IOException e) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.cantwritetofile", config.getOSGIManifestFile().getAbsolutePath()), e); } finally { IOUtil.close(out); } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseOSGiManifestWriter.java
License:Apache License
protected StringBuffer rewriteManifest(File manifestFile) throws MojoExecutionException { // warning: we read and rewrite the file line by line in order to preserve formatting boolean inBundleClasspathEntry = false; StringBuffer manifestSb = new StringBuffer(); try {//w w w .j a v a 2s . c o m BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(manifestFile), "UTF-8")); String line; while ((line = in.readLine()) != null) { if (inBundleClasspathEntry && line.indexOf(":") > -1) { inBundleClasspathEntry = false; } else if (inBundleClasspathEntry) { // skip it continue; } // Note that this could be the empty string, if we encounter // a field that we weren't expecting to be multi-line. String name = line.substring(0, line.indexOf(":") + 1); if (name.equalsIgnoreCase(ENTRY_BUNDLE_CLASSPATH)) { inBundleClasspathEntry = true; } else if (name.equalsIgnoreCase(ENTRY_BUNDLE_NAME)) { manifestSb.append(ENTRY_BUNDLE_NAME); manifestSb.append(" "); manifestSb.append(config.getProject().getName()); manifestSb.append(NEWLINE); } else if (name.equalsIgnoreCase(ENTRY_BUNDLE_SYMBOLICNAME)) { manifestSb.append(ENTRY_BUNDLE_SYMBOLICNAME); manifestSb.append(" "); manifestSb.append(config.getEclipseProjectName()); manifestSb.append(";singleton:=true"); manifestSb.append(NEWLINE); } else if (name.equalsIgnoreCase(ENTRY_BUNDLE_VERSION)) { manifestSb.append(ENTRY_BUNDLE_VERSION); manifestSb.append(" "); manifestSb.append(getNormalizedVersion(config.getProject().getVersion())); manifestSb.append(NEWLINE); } else if (name.equalsIgnoreCase(ENTRY_BUNDLE_VENDOR) && config.getProject().getOrganization() != null) { manifestSb.append(ENTRY_BUNDLE_VENDOR); manifestSb.append(" "); manifestSb.append(config.getProject().getOrganization().getName()); manifestSb.append(NEWLINE); } else { manifestSb.append(line + NEWLINE); } } IOUtil.close(in); } catch (IOException e) { throw new MojoExecutionException( Messages.getString("EclipsePlugin.cantreadfile", manifestFile.getAbsolutePath())); } manifestSb.append(addBundleClasspathEntries()); // OSGi manifest headers need to end with a line break manifestSb.append(NEWLINE); return manifestSb; }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java
License:Apache License
/** * Delete a file, handling log messages and exceptions * * @param f File to be deleted/*from www . j a va 2 s . co m*/ * @throws MojoExecutionException only if a file exists and can't be deleted */ public static void delete(File f, Log log) throws MojoExecutionException { if (f.isDirectory()) { log.info(Messages.getString("EclipseCleanMojo.deletingDirectory", f.getName())); //$NON-NLS-1$ } else { log.info(Messages.getString("EclipseCleanMojo.deletingFile", f.getName())); //$NON-NLS-1$ } if (f.exists()) { if (!f.delete()) { try { FileUtils.forceDelete(f); } catch (IOException e) { throw new MojoExecutionException(Messages.getString("EclipseCleanMojo.failedtodelete", //$NON-NLS-1$ new Object[] { f.getName(), f.getAbsolutePath() })); } } } else { log.debug(Messages.getString("EclipseCleanMojo.nofilefound", f.getName())); //$NON-NLS-1$ } }
From source file:com.alibaba.citrus.maven.inherit.InheritMojo.java
License:Apache License
/** Maven plugin entry-point */ public void execute() throws MojoExecutionException { // pre-load available plugin metadata - local and dependencies PluginXml targetPlugin = loadPluginMetadata(m_outputDirectory); // select maven source directories JavaDocBuilder builder = new JavaDocBuilder(); for (Iterator i = m_project.getCompileSourceRoots().iterator(); i.hasNext();) { builder.addSourceTree(new File((String) i.next())); }/*w w w . j av a2s.com*/ // scan local source for javadoc tags JavaSource[] javaSources = builder.getSources(); for (int i = 0; i < javaSources.length; i++) { JavaClass mojoClass = javaSources[i].getClasses()[0]; // need plugin inheritance DocletTag extendsTag = mojoClass.getTagByName(EXTENDS_PLUGIN); if (null != extendsTag) { String pluginName = extendsTag.getValue(); getLog().info("Extending " + pluginName + " plugin"); // lookup using simple plugin name (ie. compiler, archetype, etc.) PluginXml superPlugin = getDependentPluginMetaData(pluginName); if (null == superPlugin) { throw new MojoExecutionException(pluginName + " plugin is not a dependency"); } else { mergePluginMojo(mojoClass, targetPlugin, superPlugin); } } } try { targetPlugin.write(); } catch (IOException e) { throw new MojoExecutionException("cannot update local plugin metadata", e); } }
From source file:com.alibaba.citrus.maven.inherit.InheritMojo.java
License:Apache License
/** * Inherits a mojo descriptor from a dependent plugin and merge it with the local plugin metadata * * @param mojoClass local mojo code requiring inheritance * @param targetPlugin local plugin metadata * @param superPlugin plugin metadata being extended * @throws MojoExecutionException//from w w w . j ava2s . c o m */ private void mergePluginMojo(JavaClass mojoClass, PluginXml targetPlugin, PluginXml superPlugin) throws MojoExecutionException { DocletTag goalTag = mojoClass.getTagByName(GOAL); if (null == goalTag) { return; } DocletTag superGoalTag = mojoClass.getTagByName(EXTENDS_GOAL); if (null == superGoalTag) { superGoalTag = goalTag; } String goal = goalTag.getValue(); String superGoal = superGoalTag.getValue(); getLog().info(superGoal + " => " + goal); Xpp3Dom targetMojoXml = targetPlugin.findMojo(goal); Xpp3Dom superMojoXml = superPlugin.findMojo(superGoal); if (null == superMojoXml) { throw new MojoExecutionException("cannot find " + superGoal + " goal in " + superPlugin); } PluginXml.mergeMojo(targetMojoXml, superMojoXml); }
From source file:com.alibaba.maven.plugin.springext.ConfigurationConvertMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { ClassLoader cl = createClassLoader(); Class c;//from w w w . j av a 2 s . c o m try { c = cl.loadClass("com.alibaba.citrus.springext.util.ConvertToUnqualifiedStyle"); } catch (ClassNotFoundException e) { throw new MojoExecutionException("Webx 3.2.x is needed to support unqualified-style configurations"); } ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { // set new class loader as a context class loader Thread.currentThread().setContextClassLoader(cl); Object o = c.getConstructor(File[].class, boolean.class, boolean.class).newInstance(getSources(), forceConvert, !noBackup); c.getMethod("convert").invoke(o); } catch (Exception e) { throw new MojoExecutionException("Failed to do conversion", e); } finally { // restore original class loader Thread.currentThread().setContextClassLoader(contextClassLoader); } }