List of usage examples for org.apache.maven.project MavenProject getModel
public Model getModel()
From source file:org.gosu_lang.tools.maven.GosuArtifactMojo.java
License:Apache License
public void execute() throws MojoExecutionException { MavenProject project = (MavenProject) getPluginContext().get("project"); @SuppressWarnings("unchecked") List<Dependency> dependencies = (List<Dependency>) project.getModel().getDependencies(); for (Dependency dep : dependencies) { String artifactId = dep.getArtifactId(); String groupId = dep.getGroupId(); if (GOSU_GROUPID.equals(groupId) && (CORE_API_ARTIFACTID.equals(artifactId) || CORE_ARTIFACTID.equals(artifactId))) { throw new MojoExecutionException( "Your project cannot explicitly depend on Gosu artifacts with this plugin in use (" + dep + ")"); }/*from ww w .ja v a 2 s . c o m*/ } @SuppressWarnings("unchecked") Set<Artifact> artifacts = (Set<Artifact>) project.getDependencyArtifacts(); Artifact artifact = _factory.createArtifact(GOSU_GROUPID, CORE_API_ARTIFACTID, gosuVersion, "compile", "jar"); getLog().info("Inserting " + artifact + " into the compile classpath."); if (!artifacts.contains(artifact)) { artifacts.add(artifact); } if (includeImpl) { artifact = _factory.createArtifact(GOSU_GROUPID, CORE_ARTIFACTID, gosuVersion, "compile", "jar"); getLog().info("Inserting " + artifact + " into the compile classpath. Naughty!"); if (!artifacts.contains(artifact)) { artifacts.add(artifact); } } }
From source file:org.gradle.api.publication.maven.internal.pom.DefaultMavenPom.java
License:Apache License
public DefaultMavenPom setMavenProject(MavenProject mavenProject) { this.model = mavenProject.getModel(); return this; }
From source file:org.grails.maven.plugin.tools.DefaultGrailsServices.java
License:Apache License
public MavenProject createPOM(final String groupId, final GrailsProject grailsProjectDescriptor, final String mtgGroupId, final String grailsPluginArtifactId, final String mtgVersion, final boolean addEclipseSettings) { final MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }/* w ww .j a v a 2s . co m*/ final PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("grails-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("grailsHome", "${env.GRAILS_HOME}"); pom.getModel().getProperties().setProperty("grailsVersion", grailsProjectDescriptor.getAppGrailsVersion()); // Add our own plugin final Plugin grailsPlugin = new Plugin(); grailsPlugin.setGroupId(mtgGroupId); grailsPlugin.setArtifactId(grailsPluginArtifactId); grailsPlugin.setVersion(mtgVersion); grailsPlugin.setExtensions(true); pom.addPlugin(grailsPlugin); // Add compiler plugin settings final Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); final Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); final Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); final Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { final Plugin warPlugin = new Plugin(); warPlugin.setGroupId("org.apache.maven.plugins"); warPlugin.setArtifactId("maven-war-plugin"); final Xpp3Dom warConfig = new Xpp3Dom("configuration"); final Xpp3Dom warSourceDirectory = new Xpp3Dom("warSourceDirectory"); warSourceDirectory.setValue("web-app"); warConfig.addChild(warSourceDirectory); warPlugin.setConfiguration(warConfig); pluginMgt.addPlugin(warPlugin); final Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); final Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); final Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); final Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); // Xpp3Dom additionalProjectFacets = new Xpp3Dom( // "additionalProjectFacets"); // Xpp3Dom jstWeb = new Xpp3Dom("jst.web"); // jstWeb.setValue("2.5"); // additionalProjectFacets.addChild(jstWeb); // configuration.addChild(additionalProjectFacets); final Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("war"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(grailsProjectDescriptor.getAppName()); pom.setName(grailsProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(grailsProjectDescriptor.getAppVersion()); if (!grailsProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + grailsProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + grailsProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected Properties getDefaultProperties(MavenProject currentProject) { Properties properties = new Properties(); String bsn;/* ww w . j a v a 2 s .c o m*/ try { bsn = getMaven2OsgiConverter().getBundleSymbolicName(currentProject.getArtifact()); } catch (Exception e) { bsn = currentProject.getGroupId() + "." + currentProject.getArtifactId(); } // Setup defaults properties.put(MAVEN_SYMBOLICNAME, bsn); properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn); properties.put(Analyzer.IMPORT_PACKAGE, "*"); properties.put(Analyzer.BUNDLE_VERSION, getMaven2OsgiConverter().getVersion(currentProject.getVersion())); // remove the extraneous Include-Resource and Private-Package entries from generated manifest properties.put(Constants.REMOVEHEADERS, Analyzer.INCLUDE_RESOURCE + ',' + Analyzer.PRIVATE_PACKAGE); header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription()); StringBuffer licenseText = printLicenses(currentProject.getLicenses()); if (licenseText != null) { header(properties, Analyzer.BUNDLE_LICENSE, licenseText); } header(properties, Analyzer.BUNDLE_NAME, currentProject.getName()); if (currentProject.getOrganization() != null) { if (currentProject.getOrganization().getName() != null) { String organizationName = currentProject.getOrganization().getName(); header(properties, Analyzer.BUNDLE_VENDOR, organizationName); properties.put("project.organization.name", organizationName); properties.put("pom.organization.name", organizationName); } if (currentProject.getOrganization().getUrl() != null) { String organizationUrl = currentProject.getOrganization().getUrl(); header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl); properties.put("project.organization.url", organizationUrl); properties.put("pom.organization.url", organizationUrl); } } properties.putAll(currentProject.getProperties()); properties.putAll(currentProject.getModel().getProperties()); if (m_mavenSession != null) { try { // don't pass upper-case session settings to bnd as they end up in the manifest Properties sessionProperties = m_mavenSession.getExecutionProperties(); for (Enumeration e = sessionProperties.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); if (key.length() > 0 && !Character.isUpperCase(key.charAt(0))) { properties.put(key, sessionProperties.getProperty(key)); } } } catch (Exception e) { getLog().warn("Problem with Maven session properties: " + e.getLocalizedMessage()); } } properties.putAll(getProperties(currentProject.getModel(), "project.build.")); properties.putAll(getProperties(currentProject.getModel(), "pom.")); properties.putAll(getProperties(currentProject.getModel(), "project.")); properties.put("project.baseDir", getBase(currentProject)); properties.put("project.build.directory", getBuildDirectory()); properties.put("project.build.outputdirectory", getOutputDirectory()); properties.put("classifier", classifier == null ? "" : classifier); getLog().info("BlueprintPlugin"); // Add default plugins header(properties, Analyzer.PLUGIN, SpringXMLType.class.getName()); //header( properties, Analyzer.PLUGIN, BlueprintPlugin.class.getName() + "," + SpringXMLType.class.getName() ); return properties; }
From source file:org.hudsonci.maven.eventspy_30.handler.ProfileLogger.java
License:Open Source License
@SuppressWarnings("unused") public static void log(final ExecutionEvent event) { if (disabled) return;/*w w w. j a v a 2 s. co m*/ for (MavenProject project : event.getSession().getProjects()) { log.debug("*** Examining profiles for {}.", project.getName()); logProfileList(project.getActiveProfiles(), "active"); logProfileList(project.getModel().getProfiles(), "model"); //logProfiles( event.getSession().getProjectBuildingRequest().getProfiles(), "ProjectBuildingRequest" ); logProfileList(project.getProjectBuildingRequest().getProfiles(), "ProjectBuildingRequest"); log.debug("InjectedProfileIds"); for (Entry<String, List<String>> entry : project.getInjectedProfileIds().entrySet()) { log.debug(" from {} are {}", entry.getKey(), entry.getValue()); } Settings settings = event.getSession().getSettings(); logSettingsProfileList(settings.getProfiles(), "session-settings"); log.debug("Collected projects: {}", project.getCollectedProjects()); log.debug("Project references: {}", project.getProjectReferences()); } }
From source file:org.hudsonci.maven.eventspy_30.ProfileCollector.java
License:Open Source License
private void collectFromProjectUp(final MavenProject project) { // At the top of the hierarchy, stop recursion. if (null == project) { return;//from w ww . j a va 2 s . c o m } collectResolvedProfiles(project, project.getModel().getProfiles()); // Walk up hierarchy. collectFromProjectUp(project.getParent()); }
From source file:org.jasig.maven.notice.LicenseResolvingNodeVisitor.java
License:Apache License
public boolean visit(DependencyNode node) { if (DependencyNode.INCLUDED == node.getState()) { final Artifact artifact = node.getArtifact(); //Only resolve an artifact once, if already visited just skip it if (!visitedArtifacts.add(artifact)) { return true; }/*ww w. ja va 2s . c o m*/ String name = null; String licenseName = null; //Look for a matching mapping first final ResolvedLicense resolvedLicense = this.loadLicenseMapping(artifact); if (resolvedLicense != null && resolvedLicense.getVersionType() != null) { final ArtifactLicense artifactLicense = resolvedLicense.getArtifactLicense(); name = StringUtils.trimToNull(artifactLicense.getName()); licenseName = StringUtils.trimToNull(artifactLicense.getLicense()); } //If name or license are still null try loading from the project if (name == null || licenseName == null) { final MavenProject artifactProject = this.loadProject(artifact); if (artifactProject != null) { if (name == null) { name = artifactProject.getName(); } if (licenseName == null) { final Model model = artifactProject.getModel(); final List<License> licenses = model.getLicenses(); if (licenses.size() == 1) { licenseName = licenses.get(0).getName(); } else if (licenses.size() > 1) { final StringBuilder licenseNameBuilder = new StringBuilder(); for (final Iterator<License> licenseItr = licenses.iterator(); licenseItr.hasNext();) { final License license = licenseItr.next(); licenseNameBuilder.append(license.getName()); if (licenseItr.hasNext()) { licenseNameBuilder.append(" or "); } } licenseName = licenseNameBuilder.toString(); } } } } //Try fall-back match for name & license, hitting this implies the resolved license was an all-versions match if (resolvedLicense != null && (licenseName == null || name == null)) { final ArtifactLicense artifactLicense = resolvedLicense.getArtifactLicense(); if (name == null) { name = StringUtils.trimToNull(artifactLicense.getName()); } if (licenseName == null) { if (artifactLicense != null) { licenseName = StringUtils.trimToNull(artifactLicense.getLicense()); } } } //If no name is found fall back to groupId:artifactId if (name == null) { name = artifact.getGroupId() + ":" + artifact.getArtifactId(); } //Record the artifact resolution outcome if (licenseName == null) { this.unresolvedArtifacts.add(artifact); } else { this.resolvedLicenses.put(name, licenseName); } } return true; }
From source file:org.jboss.forge.addon.maven.projects.MavenFacetImpl.java
License:Open Source License
private String createDefaultPOM() { MavenXpp3Writer writer = new MavenXpp3Writer(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); org.apache.maven.project.MavenProject mavenProject = new org.apache.maven.project.MavenProject(); mavenProject.setModelVersion("4.0.0"); try {/*from w ww . java2 s .c om*/ writer.write(baos, mavenProject.getModel()); return baos.toString(); } catch (IOException e) { // Should not happen throw new RuntimeException("Failed to create default pom.xml", e); } }
From source file:org.jboss.maven.extension.dependency.DependencyManagementLifecycleParticipant.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { // The dependency management overrider needs to know which projects // are in the reactor, and therefore should not be overridden. StringBuilder reactorProjects = new StringBuilder(); for (MavenProject project : session.getProjects()) { reactorProjects.append(project.getGroupId() + ":" + project.getArtifactId() + ","); }//from w w w . j av a 2 s. c o m System.setProperty("reactorProjectGAs", reactorProjects.toString()); // Apply model modifiers to the projects' models for (MavenProject project : session.getProjects()) { logger.debug("Checking project '" + project.getId() + "'"); int modelChangeCount = 0; Model currModel = project.getModel(); // Run the modifiers against the built model for (ModelModifier currModifier : afterProjectsReadModifierList) { boolean modelChanged = currModifier.updateModel(currModel); if (modelChanged) { modelChangeCount++; } } // If something changed, then it will be useful to output extra info if (sessionChangeCount >= 1 || modelChangeCount >= 1) { logger.debug("Session/Model changed at least once, writing informational files"); try { MetaInfWriter.writeResource(currModel, new EffectivePomGenerator()); } catch (IOException e) { logger.error( "Could not write the effective POM of model '" + currModel.getId() + "' due to " + e); } } } }
From source file:org.jboss.maven.plugins.qstools.checkers.ModuleDefinedChecker.java
License:Apache License
@Override public void checkProject(MavenProject project, Document doc, Map<String, List<Violation>> results) throws Exception { File rootDir = project.getBasedir(); List<String> submodules = new ArrayList<String>(); for (File f : rootDir.listFiles()) { if (f.isDirectory() && isProjectSubdir(f)) { submodules.add(f.getName()); }/*w w w. j a v a 2 s.com*/ } submodules.removeAll( getConfigurationProvider().getQuickstartsRules(project.getGroupId()).getIgnoredModules()); for (String dir : submodules) { boolean contains = project.getModules().contains(dir); if (!contains) { //If doesn't contains, look in other profiles for (Profile profile : project.getModel().getProfiles()) { contains = profile.getModules().contains(dir); if (contains) { break; } } } if (!contains) { String msg = "The following dir [%s] is not listed as one of project submodules"; addViolation(project.getFile(), results, 0, String.format(msg, dir)); } } }