List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:org.gephi.maven.ModuleUtils.java
License:Apache License
/** * Investigate modules dependencies and return a map where keys are * top-level modules and values are all modules that it depends on plus the * key module./*from www. java 2s .com*/ * * @param modules list of modules * @param log log * @return map that represents the tree of modules */ protected static Map<MavenProject, List<MavenProject>> getModulesTree(List<MavenProject> modules, Log log) { Map<MavenProject, List<MavenProject>> result = new LinkedHashMap<MavenProject, List<MavenProject>>(); for (MavenProject proj : modules) { List<Dependency> dependencies = proj.getDependencies(); log.debug("Investigating the " + dependencies.size() + " dependencies of project '" + proj.getName() + "'"); // Init List<MavenProject> deps = new ArrayList<MavenProject>(); deps.add(proj); result.put(proj, deps); // Add all module-based dependencies for (Dependency d : dependencies) { for (MavenProject projDependency : modules) { if (projDependency != proj && projDependency.getArtifactId().equals(d.getArtifactId()) && projDependency.getGroupId().equals(d.getGroupId()) && projDependency.getVersion().equals(d.getVersion())) { log.debug("Found a dependency that matches another module '" + proj.getName() + "' -> '" + projDependency.getName() + "'"); deps.add(projDependency); } } } } // Remove modules that are entirely dependencies of others List<MavenProject> toBeRemoved = new ArrayList<MavenProject>(); for (MavenProject proj : modules) { List<MavenProject> projDeps = result.get(proj); for (MavenProject proj2 : modules) { if (proj != proj2) { if (result.get(proj2).containsAll(projDeps)) { log.debug("Remove '" + proj.getName() + "' from list of top modules because is a dependency of '" + proj2.getName() + "'"); toBeRemoved.add(proj); break; } } } } for (MavenProject mp : toBeRemoved) { result.remove(mp); } return result; }
From source file:org.gephi.maven.Validate.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { manifestUtils = new ManifestUtils(sourceManifestFile, getLog()); if (reactorProjects != null && reactorProjects.size() > 0) { getLog().debug("Found " + reactorProjects.size() + " projects in reactor"); List<MavenProject> modules = new ArrayList<MavenProject>(); for (MavenProject proj : reactorProjects) { if (proj.getPackaging().equals("nbm")) { getLog().debug("Found 'nbm' project '" + proj.getName() + "' with artifactId=" + proj.getArtifactId() + " and groupId=" + proj.getGroupId()); modules.add(proj);// ww w . ja v a 2 s . c om } } if (modules.isEmpty()) { throw new MojoExecutionException( "No 'nbm' modules have been detected, make sure to add folders to <modules> into pom"); } else if (modules.size() == 1) { // Unique NBM module executeSingleModuleProject(modules.get(0)); } else { executeMultiModuleProject(modules); } } else { throw new MojoExecutionException("The project should be a reactor project"); } }
From source file:org.glassfish.jersey.tools.plugins.GenerateJerseyModuleListMojo.java
License:Open Source License
private Map<String, List<MavenProject>> categorizeModules(List<MavenProject> projects) { Map<String, List<MavenProject>> categorizedProjects = new HashMap<String, List<MavenProject>>(); for (MavenProject project : projects) { String groupId = project.getGroupId(); if (categorizedProjects.containsKey(groupId)) { categorizedProjects.get(groupId).add(project); } else {//from w w w . jav a 2 s . co m List<MavenProject> actualList = new LinkedList<MavenProject>(); actualList.add(project); categorizedProjects.put(groupId, actualList); } } return categorizedProjects; }
From source file:org.glassfish.jersey.tools.plugins.GenerateJerseyModuleListMojo.java
License:Open Source License
/** * Build the project-info link path by including all the artifactId up to (excluding) the root parent * @param project project for which the path should be determined. * @return path consisting of hierarchically nested maven artifact IDs. Used for referencing to the project-info on java.net *///from w w w. j a v a2 s .c om private String getLinkPath(MavenProject project) { String path = ""; MavenProject parent = project.getParent(); while (parent != null && !(parent.getArtifactId().equals("project") && parent.getGroupId().equals("org.glassfish.jersey"))) { path = parent.getArtifactId() + "/" + path; parent = parent.getParent(); } return path; }
From source file:org.guvnor.ala.build.maven.executor.MavenBuildExecConfigExecutor.java
License:Apache License
@Override public Optional<BinaryConfig> apply(final MavenBuild mavenBuild, final MavenBuildExecConfig mavenBuildExecConfig) { final Project project = mavenBuild.getProject(); final MavenProject mavenProject = build(project, mavenBuild.getGoals(), mavenBuild.getProperties()); final Path path = FileSystems.getFileSystem(URI.create("file://default")) .getPath(project.getTempDir() + "/target/" + project.getExpectedBinary()); final MavenBinary binary = new MavenProjectBinaryImpl(path, project, mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); buildRegistry.registerBinary(binary); return Optional.of(binary); }
From source file:org.guvnor.common.services.project.backend.server.ModuleRepositoryResolverImpl.java
License:Apache License
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact(final String pomXML, final MavenRepositoryMetadata... filter) { GAVPreferences gavPreferences = gavPreferencesProvider.get(); gavPreferences.load();/* www .jav a2 s . c om*/ if (gavPreferences.isConflictingGAVCheckDisabled()) { return Collections.EMPTY_SET; } final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); final GAV gav = new GAV(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); //Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } return repositoriesResolvingArtifact; }
From source file:org.guvnor.common.services.project.backend.server.ProjectRepositoryResolverImpl.java
License:Apache License
@Override public Set<MavenRepositoryMetadata> getRepositoriesResolvingArtifact(final String pomXML, final MavenRepositoryMetadata... filter) { if (isCheckConflictingGAVDisabled) { return Collections.EMPTY_SET; }/*from w w w . ja v a2s. c o m*/ final InputStream pomStream = new ByteArrayInputStream(pomXML.getBytes(StandardCharsets.UTF_8)); final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pomStream); final GAV gav = new GAV(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); final Set<MavenRepositoryMetadata> repositoriesResolvingArtifact = new HashSet<MavenRepositoryMetadata>(); repositoriesResolvingArtifact.addAll(getRepositoriesResolvingArtifact(gav, mavenProject)); //Filter results if necessary if (filter != null && filter.length > 0) { repositoriesResolvingArtifact.retainAll(Arrays.asList(filter)); } return repositoriesResolvingArtifact; }
From source file:org.guvnor.common.services.project.backend.server.RepositoryResolverTestUtils.java
License:Apache License
/** * Install a Maven Project to the local Maven Repository * @param mavenProject/*from w ww. j a va 2 s . co m*/ * @param pomXml */ public static void installArtifact(final MavenProject mavenProject, final String pomXml) { final ReleaseId releaseId = new ReleaseIdImpl(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); final Aether aether = new Aether(mavenProject); final MavenRepository mavenRepository = new MavenRepository(aether) { //Nothing to override, just a sub-class to expose Constructor }; mavenRepository.deployArtifact(releaseId, "content".getBytes(), pomXml.getBytes()); }
From source file:org.guvnor.common.services.project.backend.server.RepositoryResolverTestUtils.java
License:Apache License
/** * Deploy a Maven Project to the 'Remote' Maven Repository defined in the Project's {code}<distribtionManagement>{code} section. * @param mavenProject//from w w w .j a v a 2 s.com * @param pomXml */ public static void deployArtifact(final MavenProject mavenProject, final String pomXml) { final ReleaseId releaseId = new ReleaseIdImpl(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); //Create temporary files for the JAR and POM final Aether aether = new Aether(mavenProject); final File jarFile = new File(System.getProperty("java.io.tmpdir"), toFileName(releaseId, null) + ".jar"); try { FileOutputStream fos = new FileOutputStream(jarFile); fos.write("content".getBytes()); fos.flush(); fos.close(); } catch (IOException e) { throw new RuntimeException(e); } final File pomFile = new File(System.getProperty("java.io.tmpdir"), toFileName(releaseId, null) + ".pom"); try { FileOutputStream fos = new FileOutputStream(pomFile); fos.write(pomXml.getBytes()); fos.flush(); fos.close(); } catch (IOException e) { throw new RuntimeException(e); } //Artifact representing the JAR Artifact jarArtifact = new DefaultArtifact(releaseId.getGroupId(), releaseId.getArtifactId(), "jar", releaseId.getVersion()); jarArtifact = jarArtifact.setFile(jarFile); //Artifact representing the POM Artifact pomArtifact = new SubArtifact(jarArtifact, "", "pom"); pomArtifact = pomArtifact.setFile(pomFile); //Read <distributionManagement> section final DistributionManagement distributionManagement = mavenProject.getDistributionManagement(); if (distributionManagement != null) { final DeployRequest deployRequest = new DeployRequest(); deployRequest.addArtifact(jarArtifact).addArtifact(pomArtifact).setRepository( getRemoteRepoFromDeployment(distributionManagement.getRepository(), aether.getSession())); try { aether.getSystem().deploy(aether.getSession(), deployRequest); } catch (DeploymentException e) { throw new RuntimeException(e); } } }
From source file:org.heneveld.maven.license_audit.GenerateNoticesMojo.java
@Override protected void generateOutput() throws MojoExecutionException { SimpleMultiMap<String, Object> projectsByGroup = new SimpleMultiMap<String, Object>(); if (!projectErrors.isEmpty()) { throw new MojoExecutionException( "Refusing to generate output; there are project errors: " + projectErrors); }/*from w w w . j a va 2 s .c o m*/ for (String id : projectByIdCache.keySet()) { MavenProject p = projectByIdCache.get(id); String groupId = p.getGroupId(); projectsByGroup.put(groupId, p); } // load extras ProjectsOverrides extras = loadExtras(); for (String id : extras.getProjects()) { Map<String, Object> projectOverrides = overrides.getOverridesForProject(id); Map<String, Object> projectData = new LinkedHashMap<String, Object>(extras.getOverridesForProject(id)); if (projectOverrides != null) { // anything from extras is merged on top of any existing overrides projectOverrides = new LinkedHashMap<String, Object>(projectOverrides); projectOverrides.putAll(projectData); projectData = projectOverrides; } projectsByGroup.put(id, projectData); } // if the overrides declares a parent project, prefer it: // TODO allow overrides to be subsumed; only include if it is subsuming. for (String overrideId : overrides.getProjects()) { Set<Object> projectsMatchingPrefix = new LinkedHashSet<Object>(); Iterator<String> pki = projectsByGroup.keySet().iterator(); while (pki.hasNext()) { String pk = pki.next(); if (pk.startsWith(overrideId + ".")) { projectsMatchingPrefix.addAll(projectsByGroup.get(pk)); pki.remove(); } } if (!projectsMatchingPrefix.isEmpty()) { projectsByGroup.put(overrideId, overrides.getOverridesForProject(overrideId)); projectsByGroup.putAll(overrideId, projectsMatchingPrefix); } } List<String> ids = new ArrayList<String>(); getLog().debug( "Generating notices, projects=" + projectsByGroup.keySet() + "; extras=" + extras.getProjects()); if (onlyExtras) { ids.addAll(extras.getProjects()); } else { ids.addAll(projectsByGroup.keySet()); } Collections.sort(ids, new Comparator<String>() { public int compare(String o1, String o2) { return o1.toLowerCase().compareTo(o2.toLowerCase()); } }); for (String id : ids) { Set<Object> projects = projectsByGroup.get(id); Set<String> internal = getFields(projects, "internal"); if (!internal.isEmpty() && "true".equalsIgnoreCase(internal.iterator().next())) { continue; } if (projects == null) throw new MojoExecutionException("Could not find project '" + id + "'."); String name = join(getFields(projects, "name"), " / "); if (name == null || name.length() == 0) name = id; output("This project includes the software: " + name); outputIfLastNonEmpty(" Available at: ", getUrls(id, projects)); outputIfLastNonEmpty(" Developed by: ", getOrganizations(projects)); String files = joinOr(getFields(projects, "files"), "; ", null); if (files == null) { // if not listed, assume it's the id; but empty string means never show files = id; } if (!name.equals(files)) { // don't show if it's the same as what we just showed outputIfLastNonEmpty(" Inclusive of: ", files); } outputIfLastNonEmpty(" Version used: ", joinOr(getVersions(id, projects), "; ", null)); Set<String> l = getLicenses(id, projects); output(" Used under the following license" + (l.size() > 1 ? "s:\n " : ": ") + join(l, "\n ")); List<String> notices = getFieldsAsList(projects, "notice"); notices.addAll(getFieldsAsList(projects, "notices")); if (!notices.isEmpty()) { // TODO currently requires note entries to be one per line; // ideally accept long lines and maps, both formatted nicely. output(" " + join(notices, "\n ")); } output(""); } }