List of usage examples for org.apache.maven.project MavenProject getModel
public Model getModel()
From source file:ch.sourcepond.maven.release.pom.ValidateNoSnapshotPlugins.java
License:Apache License
@Override public void alterModel(final Context updateContext) { final MavenProject project = updateContext.getProject(); for (final Plugin plugin : project.getModel().getBuild().getPlugins()) { final String substitutedVersionOrNull = substitution.getActualVersionOrNull(project, plugin); if (isSnapshot(substitutedVersionOrNull) && !isMultiModuleReleasePlugin(plugin)) { updateContext.addError(ERROR_FORMAT, project.getArtifactId(), plugin.getArtifactId(), substitutedVersionOrNull); }/*from w w w .j a v a 2 s .co m*/ } }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java
License:Apache License
/** * Returns a compiler plugin settings, considering also settings altered in plugin executions . * * @param project maven project/*from w w w . j a v a 2 s. com*/ * @return option value (may be null) */ public static String getCompilerPluginSetting(MavenProject project, String optionName) { String value = findCompilerPluginSettingInPlugins(project.getModel().getBuild().getPlugins(), optionName); if (value == null && project.getModel().getBuild().getPluginManagement() != null) { value = findCompilerPluginSettingInPlugins( project.getModel().getBuild().getPluginManagement().getPlugins(), optionName); } return value; }
From source file:com.ardoq.mavenImport.ProjectSync.java
private void syncProjectParent(MavenProject project, Component ardoqProjectComponent, Map<String, Integer> refTypes) { Parent parent = project.getModel().getParent(); if (parent != null) { try {/*from w w w .ja v a 2 s . com*/ String parentComponentId = syncProject(parent.getId()); if (ardoqProjectComponent.getId() != null && parentComponentId != null) { System.out.println("reference relation from project to parent " + ardoqProjectComponent.getId() + " " + parentComponentId); int refTypeParent = refTypes.get("Parent"); Reference parentRef = new Reference(ardoqSync.getWorkspace().getId(), "artifact", ardoqProjectComponent.getId(), parentComponentId, refTypeParent); ardoqSync.addReference(parentRef); } else { System.err.println("Error creating reference from " + ardoqProjectComponent.getId() + " to " + parentComponentId); } } catch (ArtifactResolutionException e) { throw new RuntimeException("Error reading Maven project parent: " + parent.getId(), e); } } }
From source file:com.github.jeluard.maven.ParentEnforcerRule.java
License:Apache License
@Override public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException { final MavenProject project; try {//from ww w . j ava2 s .co m project = (MavenProject) helper.evaluate("${project}"); } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Failed to access ${project} variable", e); } final String type = project.getArtifact().getType(); if (!ParentEnforcerRule.POM_ARTIFACT_TYPE.equals(type)) { helper.getLog().debug("Skipping non " + ParentEnforcerRule.POM_ARTIFACT_TYPE + " artifact."); return; } final Parent parent = new Parent(); parent.setGroupId(project.getGroupId()); parent.setArtifactId(project.getArtifactId()); parent.setVersion(project.getVersion()); try { validateSubModules(extractRootFolder(project), project.getModel(), parent); } catch (IOException e) { throw new EnforcerRuleException("Failed to process one of project's module", e); } }
From source file:com.jayway.maven.plugins.android.phase_prebuild.AarMavenLifecycleParticipant.java
License:Open Source License
/** * Add the dependent library classes to the project classpath. *///from ww w. j a v a 2 s . co m private void addClassesToClasspath(BuildHelper helper, MavenProject project, Artifact artifact) throws MavenExecutionException { // Work out where the dep will be extracted and calculate the file path to the classes jar. log.debug("Adding to classpath : " + artifact); // This is location where the GenerateSourcesMojo will extract the classes. final File classesJar = helper.getUnpackedClassesJar(artifact); log.info(" : " + classesJar); // In order to satisfy the LifecycleDependencyResolver on execution up to a phase that // has a Mojo requiring dependency resolution I need to create a dummy classesJar here. classesJar.getParentFile().mkdirs(); try { classesJar.createNewFile(); log.debug("Created dummy " + classesJar.getName() + " exist=" + classesJar.exists()); } catch (IOException e) { throw new MavenExecutionException("Could not add " + classesJar.getName() + " as dependency", e); } // Add the classes to the classpath final Dependency dependency = createSystemScopeDependency(artifact, classesJar); project.getModel().addDependency(dependency); }
From source file:com.jayway.maven.plugins.android.phase_prebuild.ClasspathModifierLifecycleParticipant.java
License:Open Source License
/** * Add jar files in libs into the project classpath. *///w w w . ja v a 2 s . com private void addLibsJarsToClassPath(UnpackedLibHelper helper, MavenProject project, Artifact artifact) throws MavenExecutionException { try { final File unpackLibFolder = helper.getUnpackedLibFolder(artifact); final File artifactFile = helper.getArtifactToFile(artifact); ZipFile zipFile = new ZipFile(artifactFile); Enumeration enumeration = zipFile.entries(); while (enumeration.hasMoreElements()) { ZipEntry entry = (ZipEntry) enumeration.nextElement(); String entryName = entry.getName(); // Only jar files under 'libs' directory to be processed. if (Pattern.matches("^libs/.+\\.jar$", entryName)) { final File libsJarFile = new File(unpackLibFolder, entryName); log.debug("Adding jar to classpath: " + libsJarFile); // In order to satisfy the LifecycleDependencyResolver on execution up to a phase that // has a Mojo requiring dependency resolution I need to create a dummy classesJar here. if (!libsJarFile.getParentFile().exists()) { libsJarFile.getParentFile().mkdirs(); } libsJarFile.createNewFile(); // Add the jar to the classpath. final Dependency dependency = createSystemScopeDependency(artifact, libsJarFile, libsJarFile.getName()); project.getModel().addDependency(dependency); } } } catch (MojoExecutionException e) { log.debug("Error extract jars"); } catch (ZipException e) { log.debug("Error"); } catch (IOException e) { log.debug("Error"); } }
From source file:com.jayway.maven.plugins.android.phase_prebuild.ClasspathModifierLifecycleParticipant.java
License:Open Source License
/** * Add the dependent library classes to the project classpath. *///w w w . j a v a 2 s .c o m private void addClassesToClasspath(UnpackedLibHelper helper, MavenProject project, Artifact artifact) throws MavenExecutionException { // Work out where the dep will be extracted and calculate the file path to the classes jar. // This is location where the GenerateSourcesMojo will extract the classes. final File classesJar = helper.getUnpackedClassesJar(artifact); log.debug("Adding to classpath : " + classesJar); // In order to satisfy the LifecycleDependencyResolver on execution up to a phase that // has a Mojo requiring dependency resolution I need to create a dummy classesJar here. classesJar.getParentFile().mkdirs(); try { classesJar.createNewFile(); log.debug("Created dummy " + classesJar.getName() + " exist=" + classesJar.exists()); } catch (IOException e) { throw new MavenExecutionException("Could not add " + classesJar.getName() + " as dependency", e); } // Add the classes to the classpath final Dependency dependency = createSystemScopeDependency(artifact, classesJar, null); project.getModel().addDependency(dependency); }
From source file:com.liferay.ide.maven.core.MavenUtil.java
License:Open Source License
public static boolean loadParentHierarchy(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException { boolean loadedParent = false; MavenProject mavenProject = facade.getMavenProject(monitor); try {/*from ww w. j a v a 2 s . co m*/ if (mavenProject.getModel().getParent() == null || mavenProject.getParent() != null) { // If the method is called without error, we can assume the project has been fully loaded // No need to continue. return false; } } catch (IllegalStateException e) { // The parent can not be loaded properly } while (mavenProject != null && mavenProject.getModel().getParent() != null) { if (monitor.isCanceled()) { break; } MavenProject parentProject = MavenPlugin.getMaven().resolveParentProject(mavenProject, monitor); if (parentProject != null) { mavenProject.setParent(parentProject); loadedParent = true; } mavenProject = parentProject; } return loadedParent; }
From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.BuildPropertiesFileHelper.java
License:Apache License
/** * Fetches the project properties and if <code>null</code> returns a new empty * properties instance that is associated with the project. * * @param project the project whose properties are requested. * @return the properties of the project. *//*from ww w . jav a 2 s .c o m*/ public Properties getProjectProperties(final MavenProject project) { Properties projectProperties = project.getProperties(); if (projectProperties == null) { projectProperties = new Properties(); project.getModel().setProperties(projectProperties); } return projectProperties; }
From source file:com.serli.maven.plugin.quality.mojo.LicenseMojo.java
License:Open Source License
private PrettyPrintXMLWriter printDependenciesLicense(PrettyPrintXMLWriter writer) { writer.startElement("dependenciesLicense"); if (resultLicenseMap != null && resultLicenseMap.size() > 0) { Set<LightLicense> keys = resultLicenseMap.keySet(); for (LightLicense license : keys) { writer.startElement("license"); String url = license.getUrl(); String name = license.getName(); if (StringUtils.isEmpty(name)) { name = "Unnamed"; }// w w w . j a va2s . c om if (StringUtils.isEmpty(url)) { url = "unavailable"; } writer.startElement("name"); writer.writeText(name); writer.endElement(); writer.startElement("url"); writer.writeText(url); writer.endElement(); SortedSet<MavenProjectComparable> sortedSet = resultLicenseMap.get(license); for (MavenProject artifact : sortedSet) { writer.startElement("dependency"); String id = artifact.getModel().getName(); if (StringUtils.isEmpty(id)) { id = artifact.getArtifactId(); } writer.startElement("name"); writer.writeText(id); writer.endElement(); writer.endElement(); } writer.endElement(); } } writer.startElement("unknownLicense"); for (MavenProject project : setArtifactNoLicense) { writer.startElement("dependency"); String id = project.getModel().getName(); if (StringUtils.isEmpty(id)) { id = project.getArtifactId(); } writer.startElement("name"); writer.writeText(id); writer.endElement(); writer.endElement(); } writer.endElement(); writer.endElement(); return writer; }