List of usage examples for org.apache.maven.project MavenProject getParentArtifact
public Artifact getParentArtifact()
From source file:org.springframework.ide.eclipse.roo.ui.internal.maven.LegacyRooProjectConfigurator.java
License:Open Source License
/** * {@inheritDoc}// w ww .j a va2 s .co m */ @Override protected void doConfigure(MavenProject mavenProject, IProject project, ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { // first apply Roo project nature boolean hasNature = false; for (Artifact art : mavenProject.getArtifacts()) { if (art.getArtifactId().startsWith("org.springframework.roo") && art.getGroupId().equals("org.springframework.roo")) { SpringCoreUtils.addProjectNature(project, SpringCore.NATURE_ID, monitor); SpringCoreUtils.addProjectNature(project, RooCoreActivator.NATURE_ID, monitor); hasNature = true; } } if (!hasNature) { hasNature = (configureNature(project, mavenProject, SpringCore.NATURE_ID, true, monitor) && configureNature(project, mavenProject, RooCoreActivator.NATURE_ID, true, monitor)); } if (hasNature) { Artifact parent = mavenProject.getParentArtifact(); if (parent != null) { // traverse the parent chain IMavenProjectFacade facade = projectManager.getMavenProject(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); doConfigure(facade.getMavenProject(), facade.getProject(), request, monitor); } else { // open the Roo Shell for the project new OpenShellJob(project).schedule(); } } }
From source file:org.springframework.ide.eclipse.roo.ui.internal.maven.RooProjectConfigurator.java
License:Open Source License
/** * {@inheritDoc}/*from w w w .j a v a 2s.c om*/ */ @Override protected void doConfigure(MavenProject mavenProject, IProject project, ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { // first apply Roo project nature boolean hasNature = false; for (Artifact art : mavenProject.getArtifacts()) { if (art.getArtifactId().startsWith("org.springframework.roo") && art.getGroupId().equals("org.springframework.roo")) { SpringCoreUtils.addProjectNature(project, SpringCore.NATURE_ID, monitor); SpringCoreUtils.addProjectNature(project, RooCoreActivator.NATURE_ID, monitor); hasNature = true; } } if (!hasNature) { hasNature = (configureNature(project, mavenProject, SpringCore.NATURE_ID, true, monitor) && configureNature(project, mavenProject, RooCoreActivator.NATURE_ID, true, monitor)); } if (hasNature) { Artifact parent = mavenProject.getParentArtifact(); if (parent != null) { // traverse the parent chain IMavenProjectFacade facade = projectManager.getMavenProject(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); if (facade != null && facade.getMavenProject() != null && facade.getProject() != null) { doConfigure(facade.getMavenProject(), facade.getProject(), request, monitor); } } else { // open the Roo Shell for the project new OpenShellJob(project).schedule(); } } }
From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java
License:Open Source License
MavenProject resolveParentProject(RepositorySystemSession repositorySession, MavenProject child, ProjectBuildingRequest configuration) throws MavenException { configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); configuration.setRepositorySession(repositorySession); try {/*from w ww .j a v a2 s . co 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) { MavenProject parent = lookup(ProjectBuilder.class).build(parentArtifact, configuration) .getProject(); parentFile = parentArtifact.getFile(); // file is resolved as // side-effect of the // prior call // compensate for apparent bug in maven 3.0.4 which does not set // parent.file and parent.artifact.file if (parent.getFile() == null) { parent.setFile(parentFile); } if (parent.getArtifact().getFile() == null) { parent.getArtifact().setFile(parentFile); } return parent; } } catch (ProjectBuildingException ex) { log.error("Could not read parent project", ex); } return null; }
From source file:org.srcdeps.mvn.enforcer.SrcdepsEnforcer.java
License:Apache License
@Override public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws LifecycleExecutionException { final MavenProject project = event.getProject(); log.info("srcdeps enforcer checks for violations in {}:{}", project.getGroupId(), project.getArtifactId()); final Maven maven = configurationProducer.getConfiguration().getMaven(); final List<MojoExecution> mojoExecutions = event.getExecutionPlan(); final List<String> goals = new ArrayList<>(mojoExecutions.size()); for (MojoExecution mojoExecution : mojoExecutions) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); goals.add(mojoDescriptor.getFullGoalName()); goals.add(mojoDescriptor.getGoal()); }//from w w w . j ava2 s .c o m final List<String> profiles = new ArrayList<>(); final List<Profile> activeProfiles = project.getActiveProfiles(); for (Profile profile : activeProfiles) { final String id = profile.getId(); profiles.add(id); } final Properties props = new Properties(); props.putAll(project.getProperties()); props.putAll(System.getProperties()); String[] firstViolation = assertFailWithout(maven.getFailWithout(), goals, profiles, props); if (firstViolation == null) { firstViolation = assertFailWith(maven.getFailWith(), goals, profiles, props); } if (firstViolation != null) { /* check if there are srcdeps */ Artifact parent = project.getParentArtifact(); if (parent != null) { assertNotSrcdeps(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), firstViolation); } DependencyManagement dm; List<Dependency> deps; if ((dm = project.getDependencyManagement()) != null && (deps = dm.getDependencies()) != null) { assertNotSrcdeps(deps, firstViolation); } if ((deps = project.getDependencies()) != null) { assertNotSrcdeps(deps, firstViolation); } } }
From source file:pl.project13.maven.git.GitDirLocator.java
License:Open Source License
/** * Search up all the maven parent project heirarchy until a .git * directory is found.//from ww w . j a va 2s . c o m * * @return File which represents the location of the .git directory or NULL if none found. */ @Nullable private File findProjectGitDirectory() { MavenProject currentProject = this.mavenProject; while (currentProject != null) { File dir = getProjectGitDir(currentProject); if (isExistingDirectory(dir)) { return dir; } // If the path exists but is not a directory it might be a git submodule "gitdir" link. File gitDirLinkPath = processGitDirFile(dir); // If the linkPath was found from the file and it exists then use it. if (isExistingDirectory(gitDirLinkPath)) { return gitDirLinkPath; } /** * project.getParent always returns NULL for me, but if getParentArtifact returns * not null then there is actually a parent - seems like a bug in maven to me. */ if (currentProject.getParent() == null && currentProject.getParentArtifact() != null) { Optional<MavenProject> maybeFoundParentProject = getReactorParentProject(currentProject); if (maybeFoundParentProject.isPresent()) currentProject = maybeFoundParentProject.get(); } else { // Get the parent, or NULL if no parent AND no parentArtifact. currentProject = currentProject.getParent(); } } return null; }
From source file:pl.project13.maven.git.GitDirLocator.java
License:Open Source License
/** * Find a project in the reactor by its artifact, I'm new to maven coding * so there may be a better way to do this, it would not be necessary * if project.getParent() actually worked. * * @return MavenProject parent project or NULL if no parent available *///www . j a v a 2 s .c o m private Optional<MavenProject> getReactorParentProject(@NotNull MavenProject project) { Artifact parentArtifact = project.getParentArtifact(); if (parentArtifact != null) { for (MavenProject reactorProject : this.reactorProjects) { if (reactorProject.getArtifactId().equals(parentArtifact.getArtifactId())) { return Optional.of(reactorProject); } } } return Optional.absent(); }