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.workspace.EclipseSettingsWriter.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 coreSettings = new Properties(); String source = IdeUtils.getCompilerSourceVersion(config.getProject()); String encoding = IdeUtils.getCompilerSourceEncoding(config.getProject()); String target = IdeUtils.getCompilerTargetVersion(config.getProject()); if (source != null) { coreSettings.put(PROP_JDT_CORE_COMPILER_SOURCE, source); coreSettings.put(PROP_JDT_CORE_COMPILER_COMPLIANCE, source); }/*from w ww . j a va 2 s. c om*/ if (encoding != null) { File basedir = config.getProject().getBasedir(); List compileSourceRoots = config.getProject().getCompileSourceRoots(); if (compileSourceRoots != null) { Iterator it = compileSourceRoots.iterator(); while (it.hasNext()) { String sourcePath = (String) it.next(); String relativePath = IdeUtils.toRelativeAndFixSeparator(basedir, new File(sourcePath), false); coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding); } } List testCompileSourceRoots = config.getProject().getTestCompileSourceRoots(); if (testCompileSourceRoots != null) { Iterator it = testCompileSourceRoots.iterator(); while (it.hasNext()) { String sourcePath = (String) it.next(); String relativePath = IdeUtils.toRelativeAndFixSeparator(basedir, new File(sourcePath), false); coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding); } } List resources = config.getProject().getResources(); if (resources != null) { Iterator it = resources.iterator(); while (it.hasNext()) { Resource resource = (Resource) it.next(); String relativePath = IdeUtils.toRelativeAndFixSeparator(basedir, new File(resource.getDirectory()), false); coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding); } } List testResources = config.getProject().getTestResources(); if (testResources != null) { Iterator it = testResources.iterator(); while (it.hasNext()) { Resource resource = (Resource) it.next(); String relativePath = IdeUtils.toRelativeAndFixSeparator(basedir, new File(resource.getDirectory()), false); coreSettings.put(PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding); } } } if (target != null && !JDK_1_2_SOURCES.equals(target)) { coreSettings.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", target); //$NON-NLS-1$ } // write the settings, if needed if (!coreSettings.isEmpty()) { File settingsDir = new File(config.getEclipseProjectDirectory(), EclipseWorkspaceWriter.DIR_DOT_SETTINGS); //$NON-NLS-1$ settingsDir.mkdirs(); coreSettings.put(PROP_ECLIPSE_PREFERENCES_VERSION, "1"); //$NON-NLS-1$ try { File oldCoreSettingsFile; File coreSettingsFile = new File(settingsDir, EclipseWorkspaceWriter.ECLIPSE_JDT_CORE_PREFS_FILE); if (coreSettingsFile.exists()) { oldCoreSettingsFile = coreSettingsFile; Properties oldsettings = new Properties(); oldsettings.load(new FileInputStream(oldCoreSettingsFile)); Properties newsettings = (Properties) oldsettings.clone(); newsettings.putAll(coreSettings); if (!oldsettings.equals(newsettings)) { newsettings.store(new FileOutputStream(coreSettingsFile), null); } } else { coreSettings.store(new FileOutputStream(coreSettingsFile), null); log.info(Messages.getString("EclipseSettingsWriter.wrotesettings", //$NON-NLS-1$ coreSettingsFile.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$ } } else { log.info(Messages.getString("EclipseSettingsWriter.usingdefaults")); //$NON-NLS-1$ } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.wtp.EclipseWtpComponentWriter.java
License:Apache License
/** @see com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException { // create a .settings directory (if not existing) File settingsDir = new File(config.getEclipseProjectDirectory(), DIR_WTP_SETTINGS); settingsDir.mkdirs();/*from w w w . j ava 2 s . c om*/ Writer w; try { w = new OutputStreamWriter(new FileOutputStream(new File(settingsDir, getComponentFileName())), "UTF-8"); } catch (IOException ex) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$ } // create a .component file and write out to it XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null); writeModuleTypeComponent(writer, config.getPackaging(), config.getBuildOutputDirectory(), config.getSourceDirs(), config.getLocalRepository()); IOUtil.close(w); }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.wtp.EclipseWtpFacetsWriter.java
License:Apache License
/** @see com.alibaba.citrus.maven.eclipse.base.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException { // create a .settings directory (if not existing) File settingsDir = new File(config.getEclipseProjectDirectory(), DIR_WTP_SETTINGS); settingsDir.mkdirs();/*from w w w . j av a 2 s.c om*/ Writer w; String packaging = config.getPackaging(); // Write out facet core xml try { w = new OutputStreamWriter(new FileOutputStream(new File(settingsDir, FILE_FACET_CORE_XML)), "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.wtp.EclipseWtpmodulesWriter.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 a v a 2 s . co m*/ try { w = new OutputStreamWriter( new FileOutputStream(new File(config.getEclipseProjectDirectory(), FILE_DOT_WTPMODULES)), "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_PROJECT_MODULES); writer.addAttribute(ATTR_MODULE_ID, "moduleCoreId"); //$NON-NLS-1$ writer.startElement(ELT_WB_MODULE); // we should use the configured eclipse project name. writer.addAttribute(ATTR_DEPLOY_NAME, this.config.getEclipseProjectName()); writer.startElement(ELT_MODULE_TYPE); writeModuleTypeAccordingToPackaging(config.getProject(), writer, config.getBuildOutputDirectory()); writer.endElement(); // module-type // source and resource paths. // deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps String target = "/"; //$NON-NLS-1$ if (Constants.PROJECT_PACKAGING_WAR.equals(config.getPackaging())) //$NON-NLS-1$ { String warSourceDirectory = IdeUtils.getPluginSetting(config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN, "warSourceDirectory", //$NON-NLS-1$ config.getProject().getBasedir() + "/src/main/webapp"); //$NON-NLS-1$ writer.startElement(ELT_WB_RESOURCE); writer.addAttribute(ATTR_DEPLOY_PATH, "/"); //$NON-NLS-1$ writer.addAttribute(ATTR_SOURCE_PATH, "/" //$NON-NLS-1$ + IdeUtils.toRelativeAndFixSeparator(config.getEclipseProjectDirectory(), new File(warSourceDirectory), false)); writer.endElement(); writeWarOrEarResources(writer, config.getProject(), config.getLocalRepository()); target = "/WEB-INF/classes"; //$NON-NLS-1$ } else if (Constants.PROJECT_PACKAGING_EAR.equals(config.getPackaging())) //$NON-NLS-1$ { writer.startElement(ELT_WB_RESOURCE); writer.addAttribute(ATTR_DEPLOY_PATH, "/"); //$NON-NLS-1$ writer.addAttribute(ATTR_SOURCE_PATH, "/"); //$NON-NLS-1$ writer.endElement(); writeWarOrEarResources(writer, config.getProject(), config.getLocalRepository()); } for (int j = 0; j < config.getSourceDirs().length; j++) { EclipseSourceDir dir = config.getSourceDirs()[j]; // test src/resources are not added to wtpmodules if (!dir.isTest()) { // <wb-resource deploy-path="/" source-path="/src/java" /> writer.startElement(ELT_WB_RESOURCE); writer.addAttribute(ATTR_DEPLOY_PATH, target); writer.addAttribute(ATTR_SOURCE_PATH, dir.getPath()); writer.endElement(); } } writer.endElement(); // wb-module writer.endElement(); // project-modules IOUtil.close(w); }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java
License:Apache License
/** * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with * the <code>resolved</code> property set to true. * * @return list of projects artifacts/*from w w w . ja va 2s. c o m*/ * @throws MojoExecutionException if unable to parse dependency versions */ private Set getProjectArtifacts() throws MojoExecutionException { // [MECLIPSE-388] Don't sort this, the order should be identical to getProject.getDependencies() Set artifacts = new LinkedHashSet(); for (Iterator dependencies = getProject().getDependencies().iterator(); dependencies.hasNext();) { Dependency dependency = (Dependency) dependencies.next(); String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); VersionRange versionRange; try { versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException(Messages.getString("AbstractIdeSupportMojo.unabletoparseversion", //$NON-NLS-1$ new Object[] { dependency.getArtifactId(), dependency.getVersion(), dependency.getManagementKey(), e.getMessage() }), e); } String type = dependency.getType(); if (type == null) { type = Constants.PROJECT_PACKAGING_JAR; } String classifier = dependency.getClassifier(); boolean optional = dependency.isOptional(); String scope = dependency.getScope(); if (scope == null) { scope = Artifact.SCOPE_COMPILE; } Artifact art = getArtifactFactory().createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, optional); if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) { art.setFile(new File(dependency.getSystemPath())); } handleExclusions(art, dependency); artifacts.add(art); } return artifacts; }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java
License:Apache License
private Map createManagedVersionMap(ArtifactFactory artifactFactory, String projectId, DependencyManagement dependencyManagement) throws MojoExecutionException { Map map;/* www . ja v a 2 s. c o m*/ if (dependencyManagement != null && dependencyManagement.getDependencies() != null) { map = new HashMap(); for (Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext();) { Dependency d = (Dependency) i.next(); try { VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion()); Artifact artifact = artifactFactory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope(), d.isOptional()); handleExclusions(artifact, d); map.put(d.getManagementKey(), artifact); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException( Messages.getString("AbstractIdeSupportMojo.unabletoparseversion", new Object[] { //$NON-NLS-1$ projectId, d.getVersion(), d.getManagementKey(), e.getMessage() }), e); } } } else { map = Collections.EMPTY_MAP; } return map; }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java
License:Apache License
public static String getCanonicalPath(File file) throws MojoExecutionException { try {/*from ww w .j av a 2s.c om*/ return file.getCanonicalPath(); } catch (IOException e) { throw new MojoExecutionException(Messages.getString("EclipsePlugin.cantcanonicalize", file //$NON-NLS-1$ .getAbsolutePath()), e); } }
From source file:com.alibaba.citrus.maven.inherit.InheritMojo.java
License:Apache License
/** * Loads plugin metadata for the given plugin location * * @param pluginDir root directory for the compiled plugin * @return plugin metadata//from ww w . j av a 2 s . co m * @throws MojoExecutionException */ private PluginXml loadPluginMetadata(File pluginDir) throws MojoExecutionException { File metadata = new File(pluginDir, "META-INF/maven/plugin.xml"); try { return new PluginXml(metadata); } catch (IOException e) { throw new MojoExecutionException("cannot read plugin metadata " + metadata, e); } catch (XmlPullParserException e) { throw new MojoExecutionException("cannot parse plugin metadata " + metadata, e); } }
From source file:com.alibaba.citrus.maven.inherit.InheritMojo.java
License:Apache License
/** * Unpacks a maven plugin artifact to the given directory * * @param artifact maven plugin//from ww w. j ava 2 s. c o m * @param unpackDir directory to unpack to * @throws MojoExecutionException */ private void unpackPlugin(Artifact artifact, File unpackDir) throws MojoExecutionException { File pluginFile = artifact.getFile(); unpackDir.mkdirs(); try { UnArchiver unArchiver = m_archiverManager.getUnArchiver(pluginFile); unArchiver.setDestDirectory(unpackDir); unArchiver.setSourceFile(pluginFile); unArchiver.extract(); } catch (NoSuchArchiverException e) { throw new MojoExecutionException("cannot find unarchiver for " + pluginFile, e); } catch (IOException e) { throw new MojoExecutionException("problem reading file " + pluginFile, e); } catch (ArchiverException e) { throw new MojoExecutionException("problem unpacking file " + pluginFile, e); } }
From source file:com.alibaba.maven.plugin.autoconfig.AutoconfigMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { if (skip) {// w w w .j a v a 2 s.c o m return; } String interactiveMode; if (interactive == null) { interactiveMode = "auto"; } else if (interactive) { interactiveMode = "on"; } else { interactiveMode = "off"; } if (dest.exists()) { if (charset == null) { charset = CharsetUtil.detectedSystemCharset(); } getLog().info("-------------------------------------------------"); getLog().info("Detected system charset encoding: " + charset); getLog().info("If your can't read the following text, specify correct one like this: "); getLog().info(""); getLog().info(" mvn -Dautoconfig.charset=yourcharset"); getLog().info(""); LogConfigurator.getConfigurator().configureDefault(false, charset); ConfigRuntimeImpl runtimeImpl = new ConfigRuntimeImpl(System.in, System.out, System.err, charset); runtimeImpl.setInteractiveMode(interactiveMode); runtimeImpl.setDests(new String[] { dest.getAbsolutePath() }); runtimeImpl.setType(type); if (descriptors != null) { runtimeImpl.setDescriptorPatterns(descriptors.getIncludes(), descriptors.getExcludes()); } if (packages != null) { runtimeImpl.setPackagePatterns(packages.getIncludes(), packages.getExcludes()); } if (userProperties != null) { runtimeImpl.setUserPropertiesFile(userProperties.getAbsolutePath(), null); } getLog().info("Configuring " + dest.getAbsolutePath() + ", interactiveMode=" + interactiveMode + ", strict=" + strict); getLog().info("-------------------------------------------------"); try { if (!runtimeImpl.start() && strict) { throw new RuntimeException("undefined placeholders"); } } catch (Exception e) { runtimeImpl.error(e); throw new MojoExecutionException("Autoconfig failed", e); } if (exploding && explodedDirectory != null) { unpack(dest, explodedDirectory); } } else { getLog().error("Dest directory or file for autoconfig does not exist: " + dest.getAbsolutePath()); } }