List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.jfrog.jade.plugins.idea.IdeaModuleMojo.java
License:Apache License
public void rewriteModule() throws MojoExecutionException { MavenProject executedProject = getExecutedProject(); File moduleFile = new File(executedProject.getBasedir(), getIdeProjectName() + ".iml"); try {//w ww .j ava2 s . c o m Document document = readXmlDocument(moduleFile, "module.xml"); Element module = document.getRootElement(); // TODO: how can we let the WAR/EJBs plugin hook in and provide this? // TODO: merge in ejb-module, etc. if ("war".equals(executedProject.getPackaging())) { addWebModule(module); } else if ("ejb".equals(executedProject.getPackaging())) { addEjbModule(module); } else if ("ear".equals(executedProject.getPackaging())) { addEarModule(module); } else if (isIdeaPlugin()) { addPluginModule(module); } Element component = findComponent(module, "NewModuleRootManager"); Element output = findElement(component, "output"); output.addAttribute("url", getModuleFileUrl(executedProject.getBuild().getOutputDirectory())); Element outputTest = findElement(component, "output-test"); outputTest.addAttribute("url", getModuleFileUrl(executedProject.getBuild().getTestOutputDirectory())); Element content = findElement(component, "content"); removeOldElements(content, "sourceFolder"); for (Iterator i = executedProject.getCompileSourceRoots().iterator(); i.hasNext();) { String directory = (String) i.next(); addSourceFolder(content, directory, false); } for (Iterator i = executedProject.getTestCompileSourceRoots().iterator(); i.hasNext();) { String directory = (String) i.next(); addSourceFolder(content, directory, true); } for (Iterator i = executedProject.getBuild().getResources().iterator(); i.hasNext();) { Resource resource = (Resource) i.next(); String directory = resource.getDirectory(); if (resource.getTargetPath() == null && !resource.isFiltering()) { addSourceFolder(content, directory, false); } else { getLog().info( "Not adding resource directory as it has an incompatible target path or filtering: " + directory); } } for (Iterator i = executedProject.getBuild().getTestResources().iterator(); i.hasNext();) { Resource resource = (Resource) i.next(); String directory = resource.getDirectory(); if (resource.getTargetPath() == null && !resource.isFiltering()) { addSourceFolder(content, directory, true); } else { getLog().info( "Not adding test resource directory as it has an incompatible target path or filtering: " + directory); } } removeOldElements(content, "excludeFolder"); //For excludeFolder File target = new File(executedProject.getBuild().getDirectory()); File classes = new File(executedProject.getBuild().getOutputDirectory()); File testClasses = new File(executedProject.getBuild().getTestOutputDirectory()); List sourceFolders = content.elements("sourceFolder"); List<String> filteredExcludes = new ArrayList<String>(); filteredExcludes.addAll(getExcludedDirectories(target, filteredExcludes, sourceFolders)); filteredExcludes.addAll(getExcludedDirectories(classes, filteredExcludes, sourceFolders)); filteredExcludes.addAll(getExcludedDirectories(testClasses, filteredExcludes, sourceFolders)); if (getExclude() != null) { String[] dirs = getExclude().split("[,\\s]+"); for (int i = 0; i < dirs.length; i++) { File excludedDir = new File(executedProject.getBasedir(), dirs[i]); filteredExcludes.addAll(getExcludedDirectories(excludedDir, filteredExcludes, sourceFolders)); } } // even though we just ran all the directories in the filteredExcludes List through the intelligent // getExcludedDirectories method, we never actually were guaranteed the order that they were added was // in the order required to make the most optimized exclude list. In addition, the smart logic from // that method is entirely skipped if the directory doesn't currently exist. A simple string matching // will do pretty much the same thing and make the list more concise. List<String> actuallyExcluded = new ArrayList<String>(); Collections.sort(filteredExcludes); for (Iterator i = filteredExcludes.iterator(); i.hasNext();) { String dirToExclude = i.next().toString(); String dirToExcludeTemp = dirToExclude.replace('\\', '/'); boolean addExclude = true; for (Iterator iterator = actuallyExcluded.iterator(); iterator.hasNext();) { String dir = iterator.next().toString(); String dirTemp = dir.replace('\\', '/'); if (dirToExcludeTemp.startsWith(dirTemp + "/")) { addExclude = false; break; } else if (dir.startsWith(dirToExcludeTemp + "/")) { actuallyExcluded.remove(dir); } } if (addExclude) { actuallyExcluded.add(dirToExclude); addExcludeFolder(content, dirToExclude); } } rewriteDependencies(component); writeXmlDocument(moduleFile, document); } catch (DocumentException e) { throw new MojoExecutionException("Error parsing existing IML file " + moduleFile.getAbsolutePath(), e); } catch (IOException e) { throw new MojoExecutionException("Error parsing existing IML file " + moduleFile.getAbsolutePath(), e); } }
From source file:org.jfrog.jade.plugins.idea.IdeaProjectMojo.java
License:Apache License
public void rewriteProject() throws MojoExecutionException { MavenProject executedProject = getExecutedProject(); String ideProjectName = getIdeProjectName(); File projectFile = new File(executedProject.getBasedir(), ideProjectName + ".ipr"); try {/*from ww w. ja v a 2 s . com*/ Document document = readXmlDocument(projectFile, "project.xml"); Element module = document.getRootElement(); // Set the jdk name if set if (getJdkName() != null) { setJdkName(module, getJdkName()); } else { String javaVersion = System.getProperty("java.version"); String defaultJdkName; if (getIdeaVersion().startsWith("4")) { defaultJdkName = "java version "" + javaVersion + """; } else { defaultJdkName = javaVersion.substring(0, 3); } getLog().info("jdkName is not set, using [java version" + javaVersion + "] as default."); setJdkName(module, defaultJdkName); } setWildcardResourcePatterns(module, getWildcardResourcePatterns()); Element component = findComponent(module, "ProjectModuleManager"); Element modules = findElement(component, "modules"); removeOldElements(modules, "module"); List<MavenProject> collectedProjects = executedProject.getCollectedProjects(); if (collectedProjects != null && !collectedProjects.isEmpty()) { Element m = createElement(modules, "module"); String projectPath = new File(executedProject.getBasedir(), getNameProvider().getProjectName(executedProject) + ".iml").getAbsolutePath(); m.addAttribute("filepath", "$PROJECT_DIR$/" + toRelative(executedProject.getBasedir(), projectPath)); // For groupId group name generation, if no name provider provided // Need to find the groupId common denominator between all projects int commonUntilIdx = 0; if (groupIdBaseGrouping && !getNameProvider().hasGroupDefinitions()) { String rootGroupId = null; for (MavenProject project : collectedProjects) { String groupId = project.getGroupId(); if (rootGroupId == null) { rootGroupId = groupId; } else { int minLength = Math.min(rootGroupId.length(), groupId.length()); int idx = 0; for (; idx < minLength; idx++) { if (rootGroupId.charAt(idx) != groupId.charAt(idx)) break; } if (idx == 0) { rootGroupId = ""; break; } rootGroupId = rootGroupId.substring(0, idx); } } if (rootGroupId != null) { commonUntilIdx = rootGroupId.length(); } } for (MavenProject p : collectedProjects) { m = createElement(modules, "module"); String modulePath = new File(p.getBasedir(), getNameProvider().getProjectName(p) + ".iml") .getAbsolutePath(); m.addAttribute("filepath", "$PROJECT_DIR$/" + toRelative(executedProject.getBasedir(), modulePath)); if (groupIdBaseGrouping) { String groupId = p.getGroupId(); if (groupId != null) { String groupName = getNameProvider().getGroupName(groupId); if (groupName == null) { // Find the most parent of all groupName = groupId.substring(commonUntilIdx); if (groupName.length() > 0 && groupName.charAt(0) == '.') { groupName = groupName.substring(1); } } if (groupName.length() > 0) { groupName = groupName.replace('.', '/'); m.addAttribute("group", groupName); } } } } // Add externalModules if (externalModules != null) { for (String externalModule : externalModules) { m = createElement(modules, "module"); m.addAttribute("filepath", externalModule); m.addAttribute("group", "External"); } } } else { Element m = createElement(modules, "module"); String modulePath = new File(executedProject.getBasedir(), getNameProvider().getProjectName(executedProject) + ".iml").getAbsolutePath(); m.addAttribute("filepath", "$PROJECT_DIR$/" + toRelative(executedProject.getBasedir(), modulePath)); } // add any PathMacros we've come across if (getMacros() != null && module.elements("UsedPathMacros").size() > 0) { Element usedPathMacros = (Element) module.elements("UsedPathMacros").get(0); removeOldElements(usedPathMacros, "macro"); for (Iterator iterator = getMacros().iterator(); iterator.hasNext();) { String macro = (String) iterator.next(); Element macroElement = createElement(usedPathMacros, "macro"); macroElement.addAttribute("name", macro); } } writeXmlDocument(projectFile, document); } catch (DocumentException e) { throw new MojoExecutionException("Error parsing existing IPR file: " + projectFile.getAbsolutePath(), e); } catch (IOException e) { throw new MojoExecutionException("Error parsing existing IPR file: " + projectFile.getAbsolutePath(), e); } }
From source file:org.jfrog.jade.plugins.idea.IdeaWorkspaceMojo.java
License:Apache License
public void rewriteWorkspace() throws MojoExecutionException { MavenProject executedProject = getExecutedProject(); String ideName = getIdeProjectName(); File workspaceFile = new File(executedProject.getBasedir(), ideName + ".iws"); try {// w w w . j a va 2 s. c o m Document document = readXmlDocument(workspaceFile, "workspace.xml"); Element module = document.getRootElement(); setProjectScmType(module); writeXmlDocument(workspaceFile, document); } catch (DocumentException e) { throw new MojoExecutionException("Error parsing existing IWS file: " + workspaceFile.getAbsolutePath(), e); } catch (IOException e) { throw new MojoExecutionException("Unable to create workspace file", e); } }
From source file:org.jooby.JoobyMojo.java
License:Apache License
@SuppressWarnings("unchecked") private static Watcher setupCompiler(final MavenProject project, final String compiler, final Consumer<String> task) throws MojoFailureException { File eclipseClasspath = new File(project.getBasedir(), ".classpath"); if ("off".equalsIgnoreCase(compiler) || eclipseClasspath.exists()) { return null; }/*w ww . j av a 2s . co m*/ List<File> resources = resources(project.getResources()); resources.add(0, new File(project.getBuild().getSourceDirectory())); List<Path> paths = resources.stream().filter(File::exists).map(File::toPath).collect(Collectors.toList()); try { ClassLoader backloader = Thread.currentThread().getContextClassLoader(); return new Watcher((kind, path) -> { ClassLoader currentloader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(backloader); if (path.toString().endsWith(".java")) { task.accept("compile"); } else if (path.toString().endsWith(".conf") || path.toString().endsWith(".properties")) { task.accept("compile"); } } finally { Thread.currentThread().setContextClassLoader(currentloader); } }, paths.toArray(new Path[paths.size()])); } catch (Exception ex) { throw new MojoFailureException("Can't compile source code", ex); } }
From source file:org.jsweet.JSweetJettyWatchMojo.java
License:Apache License
public void execute() throws MojoFailureException, MojoExecutionException { MavenProject project = getMavenProject(); setOutDir(project.getBasedir() + "/src/main/webapp/" + getRelativeOutDir()); setCandiesJsOut(new File(project.getBasedir() + "/src/main/webapp/" + getRelativeOutDir())); getLog().info("Starting transpiler thread ..."); getLog().info("Transpilator output directory " + getOutDir()); transpilerThread = new TranspilerThread(this, createJSweetTranspiler(project)); transpilerThread.start();// w w w. jav a 2 s .c om while (!transpilerThread.isRunning()) { Thread.yield(); } /* */ getLog().info("Starting jetty thread ... "); jettyThread = new JettyThread(this); jettyThread.start(); while (!jettyThread.isRunning()) { Thread.yield(); } /* */ WatchService jsweetWatcher = createJSweetWatcher(project); WatchService jettyWatcher = createJettyWatcher(project); /* */ for (;;) { /* */ int jettyWatchReturn = jettyWatch(jettyWatcher); if (jettyWatchReturn == -1) { try { jettyWatcher.close(); jettyWatcher = createJettyWatcher(project); } catch (IOException ioException) { getLog().info(ioException); } } /* */ Thread.yield(); /* */ int jsweetWatchReturn = jsweetWatch(jsweetWatcher); if (jsweetWatchReturn == -1) { try { jsweetWatcher.close(); jsweetWatcher = createJSweetWatcher(project); } catch (IOException ioException) { getLog().info(ioException); } } /* */ Thread.yield(); /* */ } }
From source file:org.jszip.maven.RunMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (runPackages == null || runPackages.length == 0) { runPackages = new String[] { "war" }; }/*from ww w .j a v a2 s .co m*/ injectMissingArtifacts(project, executedProject); if (!Arrays.asList(runPackages).contains(project.getPackaging())) { getLog().info("Skipping JSZip run: module " + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()) + " as not specified in runPackages"); return; } if (StringUtils.isNotBlank(runModule) && !project.getArtifactId().equals(runModule) && !ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()).equals(runModule)) { getLog().info("Skipping JSZip run: module " + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()) + " as requested runModule is " + runModule); return; } getLog().info("Starting JSZip run: module " + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId())); MavenProject project = this.project; long lastResourceChange = System.currentTimeMillis(); long lastClassChange = System.currentTimeMillis(); long lastPomChange = getPomsLastModified(); Server server = new Server(); if (connectors == null || connectors.length == 0) { SelectChannelConnector selectChannelConnector = new SelectChannelConnector(); selectChannelConnector.setPort(8080); connectors = new Connector[] { selectChannelConnector }; } server.setConnectors(connectors); ContextHandlerCollection contexts = new ContextHandlerCollection(); HandlerCollection handlerCollection = new HandlerCollection(true); DefaultHandler defaultHandler = new DefaultHandler(); handlerCollection.setHandlers(new Handler[] { contexts, defaultHandler }); server.setHandler(handlerCollection); try { server.start(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } List<MavenProject> reactorProjects = this.reactorProjects; WebAppContext webAppContext; Resource webXml; List<Resource> resources; try { resources = new ArrayList<Resource>(); addCssEngineResources(project, reactorProjects, mappings, resources); for (Artifact a : getOverlayArtifacts(project, scope)) { addOverlayResources(reactorProjects, resources, a); } if (warSourceDirectory == null) { warSourceDirectory = new File(project.getBasedir(), "src/main/webapp"); } if (warSourceDirectory.isDirectory()) { resources.add(Resource.newResource(warSourceDirectory)); } Collections.reverse(resources); getLog().debug("Overlays:"); int index = 0; for (Resource r : resources) { getLog().debug(" [" + index++ + "] = " + r); } final ResourceCollection resourceCollection = new ResourceCollection( resources.toArray(new Resource[resources.size()])); webAppContext = new JettyWebAppContext(); webAppContext.setWar(warSourceDirectory.getAbsolutePath()); webAppContext.setBaseResource(resourceCollection); WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext); for (String s : getClasspathElements(project, scope)) { classLoader.addClassPath(s); } webAppContext.setClassLoader(classLoader); contexts.setHandlers(new Handler[] { webAppContext }); contexts.start(); webAppContext.start(); Resource webInf = webAppContext.getWebInf(); webXml = webInf != null ? webInf.getResource("web.xml") : null; } catch (MojoExecutionException e) { throw e; } catch (MojoFailureException e) { throw e; } catch (ArtifactFilterException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (MalformedURLException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } long webXmlLastModified = webXml == null ? 0L : webXml.lastModified(); try { getLog().info("Context started. Will restart if changes to poms detected."); long nextClasspathCheck = System.currentTimeMillis() + classpathCheckInterval; while (true) { long nextCheck = System.currentTimeMillis() + 500; long pomsLastModified = getPomsLastModified(); boolean pomsChanged = lastPomChange < pomsLastModified; boolean overlaysChanged = false; boolean classPathChanged = webXmlLastModified < (webXml == null ? 0L : webXml.lastModified()); if (nextClasspathCheck < System.currentTimeMillis()) { long classChange = classpathLastModified(project); if (classChange > lastClassChange) { classPathChanged = true; lastClassChange = classChange; } nextClasspathCheck = System.currentTimeMillis() + classpathCheckInterval; } if (!classPathChanged && !overlaysChanged && !pomsChanged) { try { lastResourceChange = processResourceSourceChanges(reactorProjects, project, lastResourceChange); } catch (ArtifactFilterException e) { getLog().debug("Couldn't process resource changes", e); } try { Thread.sleep(Math.max(100L, nextCheck - System.currentTimeMillis())); } catch (InterruptedException e) { getLog().debug("Interrupted", e); } continue; } if (pomsChanged) { getLog().info("Change in poms detected, re-parsing to evaluate impact..."); // we will now process this change, // so from now on don't re-process // even if we have issues processing lastPomChange = pomsLastModified; List<MavenProject> newReactorProjects; try { newReactorProjects = buildReactorProjects(); } catch (ProjectBuildingException e) { getLog().info("Re-parse aborted due to malformed pom.xml file(s)", e); continue; } catch (CycleDetectedException e) { getLog().info("Re-parse aborted due to dependency cycle in project model", e); continue; } catch (DuplicateProjectException e) { getLog().info("Re-parse aborted due to duplicate projects in project model", e); continue; } catch (Exception e) { getLog().info("Re-parse aborted due a problem that prevented sorting the project model", e); continue; } if (!buildPlanEqual(newReactorProjects, this.reactorProjects)) { throw new BuildPlanModifiedException("A pom.xml change has impacted the build plan."); } MavenProject newProject = findProject(newReactorProjects, this.project); if (newProject == null) { throw new BuildPlanModifiedException("A pom.xml change appears to have removed " + this.project.getId() + " from the build plan."); } newProject.setArtifacts(resolve(newProject, "runtime")); getLog().debug("Comparing effective classpath of new and old models"); try { classPathChanged = classPathChanged || classpathsEqual(project, newProject, scope); } catch (DependencyResolutionRequiredException e) { getLog().info("Re-parse aborted due to dependency resolution problems", e); continue; } if (classPathChanged) { getLog().info("Effective classpath of " + project.getId() + " has changed."); } else { getLog().debug("Effective classpath is unchanged."); } getLog().debug("Comparing effective overlays of new and old models"); try { overlaysChanged = overlaysEqual(project, newProject); } catch (OverConstrainedVersionException e) { getLog().info("Re-parse aborted due to dependency resolution problems", e); continue; } catch (ArtifactFilterException e) { getLog().info("Re-parse aborted due to overlay resolution problems", e); continue; } if (overlaysChanged) { getLog().info("Overlay modules of " + project.getId() + " have changed."); } else { getLog().debug("Overlay modules are unchanged."); } getLog().debug("Comparing overlays paths of new and old models"); try { List<Resource> newResources = new ArrayList<Resource>(); // TODO newMappings addCssEngineResources(newProject, newReactorProjects, mappings, resources); for (Artifact a : getOverlayArtifacts(project, scope)) { addOverlayResources(newReactorProjects, newResources, a); } if (warSourceDirectory.isDirectory()) { newResources.add(Resource.newResource(warSourceDirectory)); } Collections.reverse(newResources); getLog().debug("New overlays:"); int index = 0; for (Resource r : newResources) { getLog().debug(" [" + index++ + "] = " + r); } boolean overlayPathsChanged = !resources.equals(newResources); if (overlayPathsChanged) { getLog().info("Overlay module paths of " + project.getId() + " have changed."); } else { getLog().debug("Overlay module paths are unchanged."); } overlaysChanged = overlaysChanged || overlayPathsChanged; } catch (ArtifactFilterException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } catch (PluginConfigurationException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } catch (PluginContainerException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } catch (IOException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } project = newProject; reactorProjects = newReactorProjects; } if (!overlaysChanged && !classPathChanged) { continue; } getLog().info("Restarting context to take account of changes..."); try { webAppContext.stop(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } if (classPathChanged) { getLog().info("Updating classpath..."); try { WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext); for (String s : getClasspathElements(project, scope)) { classLoader.addClassPath(s); } webAppContext.setClassLoader(classLoader); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } if (overlaysChanged || classPathChanged) { getLog().info("Updating overlays..."); try { resources = new ArrayList<Resource>(); addCssEngineResources(project, reactorProjects, mappings, resources); for (Artifact a : getOverlayArtifacts(project, scope)) { addOverlayResources(reactorProjects, resources, a); } if (warSourceDirectory.isDirectory()) { resources.add(Resource.newResource(warSourceDirectory)); } Collections.reverse(resources); getLog().debug("Overlays:"); int index = 0; for (Resource r : resources) { getLog().debug(" [" + index++ + "] = " + r); } final ResourceCollection resourceCollection = new ResourceCollection( resources.toArray(new Resource[resources.size()])); webAppContext.setBaseResource(resourceCollection); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } try { webAppContext.start(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } webXmlLastModified = webXml == null ? 0L : webXml.lastModified(); getLog().info("Context restarted."); } } finally { try { server.stop(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } }
From source file:org.jvnet.hudson.plugins.mavendepsupdate.util.ReactorReader.java
License:Apache License
public File findArtifact(Artifact artifact) { // very simple resolution here: is the artifact in reactor projects ? String projectKey = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());/*from ww w . java 2 s . c om*/ MavenProject project = projectsByGAV.get(projectKey); if (project != null) { return project.getBasedir(); } return null; }
From source file:org.jvnet.maven.plugin.antrun.AbstractAntMojo.java
License:Apache License
/** * @param antTasks/*from www . ja va 2 s . co m*/ * @param mavenProject * @throws MojoExecutionException */ protected void executeTasks(Target antTasks, MavenProject mavenProject, List pluginArtifacts) throws MojoExecutionException { if (antTasks == null) { getLog().info("No ant tasks defined - SKIPPED"); return; } try { //TODO refactor - place the manipulation of the expressionEvaluator into a separated class. ExpressionEvaluator exprEvaluator = (ExpressionEvaluator) antTasks.getProject() .getReference(AntTargetConverter.MAVEN_EXPRESSION_EVALUATOR_ID); Project antProject = antTasks.getProject(); PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(antProject); propertyHelper.setNext(new AntPropertyHelper(exprEvaluator, mavenProject.getArtifacts(), getLog())); DefaultLogger antLogger = new DefaultLogger(); antLogger.setOutputPrintStream(System.out); antLogger.setErrorPrintStream(System.err); antLogger.setMessageOutputLevel(getLog().isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO); antProject.addBuildListener(antLogger); antProject.setBaseDir(mavenProject.getBasedir()); Path p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator)); /* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */ antProject.addReference("maven.dependency.classpath", p); antProject.addReference("maven.compile.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.runtime.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.test.classpath", p); /* set maven.plugin.classpath with plugin dependencies */ antProject.addReference("maven.plugin.classpath", getPathFromArtifacts(pluginArtifacts, antProject)); if (getLog().isInfoEnabled()) { getLog().info("Executing tasks"); } configureProject(antProject); antTasks.execute(); if (getLog().isInfoEnabled()) { getLog().info("Executed tasks"); } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("DependencyResolutionRequiredException: " + e.getMessage(), e); } catch (BuildException e) { throw new MojoExecutionException("An Ant BuildException has occured: " + e.getMessage(), e); } catch (Exception e) { throw new MojoExecutionException("Error executing ant tasks: " + e.getMessage(), e); } }
From source file:org.kathrynhuxtable.maven.plugins.docbkxwrapper.Merger.java
License:Apache License
/** * DOCUMENT ME!// w w w . ja v a2s . c om * * @param templateFile TODO * @param localRepository DOCUMENT ME! * @param repositories DOCUMENT ME! * @param i18n DOCUMENT ME! * @param inputEncoding DOCUMENT ME! * @param outputEncoding DOCUMENT ME! * @param siteDirectory TODO * @param project DOCUMENT ME! * @param siteTool DOCUMENT ME! * @param reactorProjects DOCUMENT ME! * * @throws MojoExecutionException DOCUMENT ME! * * @see org.apache.maven.plugin.AbstractMojo#execute() */ public void initialize(File templateFile, ArtifactRepository localRepository, List<?> repositories, I18N i18n, String inputEncoding, String outputEncoding, File siteDirectory, MavenProject project, SiteTool siteTool, List<?> reactorProjects) throws MojoExecutionException { this.i18n = i18n; this.project = project; ve = initializeVelocityEngine(); template = getVelocityTemplate(ve, templateFile); initializeI18N(i18n); attributes = initializeAttributes(inputEncoding, outputEncoding, project); try { decorationModel = siteTool.getDecorationModel(project, reactorProjects, localRepository, repositories, getRelativeFilePath(project.getBasedir(), siteDirectory), Locale.getDefault(), inputEncoding, outputEncoding); } catch (SiteToolException e) { throw new MojoExecutionException("SiteToolException: " + e.getMessage(), e); } }
From source file:org.kevoree.tools.nativeCode.mavenplugin.utils.MavenHelper.java
License:LGPL
public static Model createModel(String groupId, String artifactId, String version, Parent parent, MavenProject parentProject) throws IOException { Model model = new Model(); model.setArtifactId(artifactId);/*from w w w . ja v a 2 s. c o m*/ model.setGroupId(groupId); model.setVersion(version); model.setModelVersion("4.0.0"); model.setParent(parent); model.setName(""); File parentBase = parentProject.getBasedir(); File pomFile = new File(parentBase, artifactId + "/pom.xml"); model.setPomFile(pomFile); return model; }