List of usage examples for org.apache.maven.project MavenProject getParentArtifact
public Artifact getParentArtifact()
From source file:guru.nidi.maven.tools.dependency.DotCreator.java
License:Apache License
public void writeComplete(Artifact artifact) throws IOException { final Collection<Artifact> res = calcDependencies(artifact); if (res != null) { final PrintWriter out = new PrintWriter( new OutputStreamWriter(new FileOutputStream(fileFor(artifact, ".dot")), "utf-8")); out.println("digraph " + quoted(artifact) + "{"); out.println("node [shape=box];"); out.println("subgraph {"); out.println("label=Legend;"); out.println("node [shape=plaintext];"); String label = ""; for (Map.Entry<String, DepInfo> dep : deps.entrySet()) { if (dep.getValue().order > 2 && parameters.isInScope(dep.getKey())) { out.println("edge [color=" + dep.getValue().color + "]; \"" + dep.getKey() + "\"->\"" + label + "\";"); label += " "; }//from ww w . j a v a 2 s . com } out.println("}"); out.println("rankdir=LR;"); out.println(quoted(artifact) + " [label=" + label(artifact) + ",URL=\"/" + toString(artifact) + ".html\"];"); try { final MavenProject project = mavenContext.projectFromArtifact(artifact); final Artifact parent = project.getParentArtifact(); if (parent != null) { out.println("{ rank=same; " + quoted(artifact) + "; " + quoted(parent) + "; }"); out.println(quoted(parent) + " [label=" + label(parent) + ",URL=\"/" + toString(parent) + ".html\"];"); out.println(quoted(artifact) + "->" + quoted(parent) + ";"); writeComplete(parent); } //TODO how to find modules? // if (project.getModules()!=null){ // for(String module: project.getModules()){ // new DefaultArtifact(project.getGroupId(),module,) // } // } } catch (ProjectBuildingException e) { System.out.println(e.getMessage()); } writeDependencies(out, artifact, res, new HashSet<String>(), parameters.getMaxDepth()); out.println("}"); out.close(); } }
From source file:io.github.patrickpilch.dependencylicensechecker.DependencyChecker.java
License:Open Source License
private List<License> getArtifactLicenses(final Artifact artifact) throws ProjectResolutionException { try {//from w w w.j a v a 2 s . c o m MavenProject projectArtifact = generateMavenProject(artifact); List<License> licenses = projectArtifact.getLicenses(); if (licenses == null || licenses.isEmpty()) { Artifact parentArtifact = projectArtifact.getParentArtifact(); return (parentArtifact == null) ? Collections.emptyList() : getArtifactLicenses(parentArtifact); } else { return licenses; } } catch (Exception e) { throw new ProjectResolutionException(artifact, e); } }
From source file:org.buildforce.build.maven.plugins.RemoveDependenciesFromLocalRepositoryMojo.java
License:Apache License
private void removeAncestors() throws MojoExecutionException { MavenProject parent = project.getParent(); MavenProject last = project; while (parent != null) { Artifact parentArtifact = last.getParentArtifact(); File localArtifactFile = new File(localRepository.getBasedir(), localRepository.pathOf(parentArtifact)); File localMetadataFile = new File(localArtifactFile.getParentFile(), MAVEN_METADATA_LOCAL); if (localMetadataFile.exists()) { boolean deletedSuccessfully = localMetadataFile.delete(); if (!deletedSuccessfully) throw new MojoExecutionException( "Failed to remove " + localMetadataFile.getAbsolutePath() + "!"); else//from w w w.j a va 2s . c om getLog().info("Removed maven-metadata-local.xml for parent " + parentArtifact.getGroupId() + ":" + parentArtifact.getArtifactId() + ":" + parentArtifact.getVersion() + ": " + localMetadataFile.getAbsolutePath()); } parent = parent.getParent(); } }
From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java
License:Open Source License
MavenProject resolveParentProject(RepositorySystemSession repositorySession, MavenProject child, ProjectBuildingRequest configuration) throws CoreException { configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); configuration.setRepositorySession(repositorySession); try {/*from w ww . ja v a2 s. c o m*/ configuration.setRemoteRepositories(child.getRemoteArtifactRepositories()); File parentFile = child.getParentFile(); if (parentFile != null) { return lookup(ProjectBuilder.class).build(parentFile, configuration).getProject(); } Artifact parentArtifact = child.getParentArtifact(); if (parentArtifact != null) { return lookup(ProjectBuilder.class).build(parentArtifact, configuration).getProject(); } } catch (ProjectBuildingException ex) { log.error("Could not read parent project", ex); } return null; }
From source file:org.eclipse.m2e.core.internal.project.registry.DefaultMavenDependencyResolver.java
License:Open Source License
public static void addParentRequirements(Set<RequiredCapability> requirements, MavenProject mavenProject) { Artifact parentArtifact = mavenProject.getParentArtifact(); if (parentArtifact != null) { requirements.add(MavenRequiredCapability.createMavenParent(new ArtifactKey(parentArtifact))); }/*from w w w .j a v a 2 s .com*/ }
From source file:org.hoydaa.maven.plugins.ParentCheckerMojo.java
License:Apache License
public void execute() throws MojoExecutionException { MavenProject tProject = project; while (tProject != null) { Artifact parentArtifact = tProject.getParentArtifact(); if (null == parentArtifact || checkArtifacts == null || !hasValidParent(tProject)) { getLog().info("This parent '" + parentArtifact + "' is not in the list of artifacts '" + checkArtifacts + "' to be checked, skipping..."); } else {/*from w w w.j a v a 2 s . co m*/ try { // get newer versions of the parent, if there is one. ArtifactVersion currentVersion = tProject.getParentArtifact().getSelectedVersion(); List<ArtifactVersion> availableVersions = artifactMetadataSource.retrieveAvailableVersions( artifactFactory.createParentArtifact(parentArtifact.getGroupId(), parentArtifact.getArtifactId(), parentArtifact.getVersion()), localRepository, remoteArtifactRepositories); List<ArtifactVersion> newVersions = getNewerVersions(currentVersion, availableVersions); // if there is newer versions available if (newVersions.size() > 0) { boolean forcedUpdateExists = false; getLog().warn("New versions available for your parent POM " + parentArtifact.toString() + " of project '" + tProject.getArtifact().toString() + "'!"); for (ArtifactVersion version : newVersions) { boolean forced = isForced(version, tProject); forcedUpdateExists = forcedUpdateExists || forced; getLog().warn(version.toString() + " (" + (forced ? "FORCED" : "not forced") + ")"); } if (forceUpgrade) { throw new MojoExecutionException(getWarningText(newVersions, tProject) + " You have to upgrade your parent POM to the latest version!"); } else if (forcedUpdateExists) { throw new MojoExecutionException(getWarningText(newVersions, tProject) + " You have to upgrade your parent POM to the latest forced update at least!"); } else { getLog().warn(getWarningText(newVersions, tProject)); } } else { getLog().info("Your parent POM's are all up-to-date, good to do dude."); } } catch (ArtifactMetadataRetrievalException e) { e.printStackTrace(); } catch (OverConstrainedVersionException e) { e.printStackTrace(); } catch (ProjectBuildingException e) { e.printStackTrace(); } } Artifact temp = tProject.getParentArtifact(); tProject = tProject.getParent(); if (null != tProject) tProject.setArtifact(temp); } }
From source file:org.hoydaa.maven.plugins.ParentCheckerMojo.java
License:Apache License
private MavenProject getProjectForParent(ArtifactVersion version, MavenProject project) throws ProjectBuildingException { Artifact parentTemp = artifactFactory.createParentArtifact(project.getParentArtifact().getGroupId(), project.getParentArtifact().getArtifactId(), version.toString()); return mavenProjectBuilder.buildFromRepository(parentTemp, remoteArtifactRepositories, localRepository); }
From source file:org.hoydaa.maven.plugins.ParentCheckerMojo.java
License:Apache License
private String getWarningText(List<ArtifactVersion> newVersions, MavenProject project) { return "Parent POM '" + project.getParentArtifact().toString() + "' of project '" + project.getArtifact().toString() + "' is " + newVersions.size() + " versions behind, you have to upgrade it to " + newVersions.get(newVersions.size() - 1) + "!"; }
From source file:org.hoydaa.maven.plugins.ParentCheckerMojo.java
License:Apache License
private boolean hasValidParent(MavenProject project) { for (org.hoydaa.maven.plugins.Artifact artifact : checkArtifacts) { if (artifact.getGroupId().equals(project.getParentArtifact().getGroupId()) && artifact.getArtifactId().equals(project.getParentArtifact().getArtifactId())) { return true; }// ww w.j a va2 s . co m } return false; }
From source file:org.kloeckner.maven.plugin.VersionRange.java
License:Apache License
private Map<String, String> getOriginalVersionMap(MavenProject projects) { HashMap<String, String> hashMap = new HashMap<String, String>(); // TODO depmgmt, parent ... if (projects.getParentArtifact() != null) { hashMap.put(// ww w .j ava 2s. c om ArtifactUtils.versionlessKey(projects.getParentArtifact().getGroupId(), projects.getParentArtifact().getArtifactId()), projects.getParentArtifact().getArtifactId()); } hashMap.putAll(buildVersionsMap(projects.getDependencies())); if (projects.getDependencyManagement() != null) { hashMap.putAll(buildVersionsMap(projects.getDependencyManagement().getDependencies())); } for (Profile profile : projects.getActiveProfiles()) { hashMap.putAll(buildVersionsMap(profile.getDependencies())); if (profile.getDependencyManagement() != null) { hashMap.putAll(buildVersionsMap(profile.getDependencyManagement().getDependencies())); } } return hashMap; }