Java Code Examples for org.apache.maven.project.MavenProject#getGroupId()
The following examples show how to use
org.apache.maven.project.MavenProject#getGroupId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bom.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
public static Bom readBom(Path pomFile) throws MavenRepositoryException { RepositorySystem system = RepositoryUtility.newRepositorySystem(); RepositorySystemSession session = RepositoryUtility.newSession(system); MavenProject mavenProject = RepositoryUtility.createMavenProject(pomFile, session); String coordinates = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion(); DependencyManagement dependencyManagement = mavenProject.getDependencyManagement(); List<org.apache.maven.model.Dependency> dependencies = dependencyManagement.getDependencies(); ArtifactTypeRegistry registry = session.getArtifactTypeRegistry(); ImmutableList<Artifact> artifacts = dependencies.stream() .map(dependency -> RepositoryUtils.toDependency(dependency, registry)) .map(Dependency::getArtifact) .filter(artifact -> !shouldSkipBomMember(artifact)) .collect(ImmutableList.toImmutableList()); Bom bom = new Bom(coordinates, artifacts); return bom; }
Example 2
Source File: UnchangedProjectsRemover.java From gitflow-incremental-builder with MIT License | 6 votes |
private static boolean matchesSelector(MavenProject project, String selector, File reactorDirectory) { if (selector.contains(":")) { // [groupId]:artifactId String id = ':' + project.getArtifactId(); if (id.equals(selector)) { return true; } id = project.getGroupId() + id; if (id.equals(selector)) { return true; } } else if (reactorDirectory != null) { // relative path, e.g. "sub", "../sub" or "." File selectedProject = new File(new File(reactorDirectory, selector).toURI().normalize()); if (selectedProject.isFile()) { return selectedProject.equals(project.getFile()); } else if (selectedProject.isDirectory()) { return selectedProject.equals(project.getBasedir()); } } return false; }
Example 3
Source File: Analyzer.java From revapi with Apache License 2.0 | 6 votes |
public static String getProjectArtifactCoordinates(MavenProject project, String versionOverride) { org.apache.maven.artifact.Artifact artifact = project.getArtifact(); String extension = artifact.getArtifactHandler().getExtension(); String version = versionOverride == null ? project.getVersion() : versionOverride; if (artifact.hasClassifier()) { return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + artifact.getClassifier() + ":" + version; } else { return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + version; } }
Example 4
Source File: MavenExecutorImpl.java From developer-studio with Apache License 2.0 | 6 votes |
public boolean setMavenParent(File mavenProjectLocation, File parentMavenProjectLocation) throws Exception { if (parentMavenProjectLocation==null){ setMavenParent(mavenProjectLocation, (MavenProjectType)null); }else{ File parentProjectPomFile = new File(parentMavenProjectLocation,"pom.xml"); MavenProject parentProject = MavenUtils.getMavenProject(parentProjectPomFile); String relativeLocation = FileUtils.getRelativePath(parentMavenProjectLocation,mavenProjectLocation); if (!parentProject.getModules().contains(relativeLocation)){ parentProject.getModules().add(relativeLocation); } MavenUtils.saveMavenProject(parentProject, parentProjectPomFile); MavenProjectType parentMavenProject=new MavenProjectType(parentProject.getGroupId(),parentProject.getArtifactId(),parentProject.getVersion()); String relativePath = FileUtils.getRelativePath(mavenProjectLocation, parentProjectPomFile).replace('\\', '/'); parentMavenProject.setRelativePath(relativePath); setMavenParent(mavenProjectLocation, parentMavenProject); } return true; }
Example 5
Source File: MvnPluginReport.java From steady with Apache License 2.0 | 5 votes |
/** * Builds the set of {@link Application}s to be considered in the result report. * * If the given {@link MavenProject} has the packaging type 'POM', applications * corresponding to all its sub-modules will be added to this set. * * Depending on the configuration option {@link CoreConfiguration#REP_OVERRIDE_VER}, * the application version is either taken from the POM or from configuration * setting {@link CoreConfiguration#APP_CTX_VERSI}. * * @param _prj * @param _ids */ private void collectApplicationModules(MavenProject _prj, Set<Application> _ids) { // The version as specified in the POM of the given project final String pom_version = _prj.getVersion(); // The version specified with configuration option {@link CoreConfiguration#APP_CTX_VERSI} final String app_ctx_version = this.goal.getGoalContext().getApplication().getVersion(); // The application module to be added final Application app = new Application(_prj.getGroupId(), _prj.getArtifactId(), pom_version); // Override version found in the respective pom.xml with the version of the application context // This becomes necessary if module scan results are NOT uploaded with the version found in the POM, // but with one specified in other ways, e.g., per -Dvulas.core.appContext.version if(this.vulasConfiguration.getConfiguration().getBoolean(CoreConfiguration.REP_OVERRIDE_VER, false) && !pom_version.equals(app_ctx_version)) { app.setVersion(app_ctx_version); this.getLog().warn("Report will include application version " + app + " rather than version [" + pom_version + "] specified in its POM"); } _ids.add(app); if(_prj.getPackaging().equalsIgnoreCase("pom")) { for(MavenProject module: _prj.getCollectedProjects()) { this.collectApplicationModules(module, _ids); } } }
Example 6
Source File: AbstractRapidoidMojo.java From rapidoid with Apache License 2.0 | 5 votes |
private String pickMainClass(List<String> mainClasses, MavenProject project) { // the.group.id.Main String byGroupId = project.getGroupId() + ".Main"; if (mainClasses.contains(byGroupId)) return byGroupId; List<String> namedMain = U.list(); List<String> withGroupIdPkg = U.list(); for (String name : mainClasses) { if (name.equals("Main")) return "Main"; if (name.endsWith(".Main")) { namedMain.add(name); } if (name.startsWith(project.getGroupId() + ".")) { withGroupIdPkg.add(name); } } // the.group.id.foo.bar.Main getLog().info("Candidates by group ID: " + withGroupIdPkg); if (withGroupIdPkg.size() == 1) return U.single(withGroupIdPkg); // foo.bar.Main getLog().info("Candidates named Main: " + namedMain); if (namedMain.size() == 1) return U.single(namedMain); namedMain.retainAll(withGroupIdPkg); getLog().info("Candidates by group ID - named Main: " + namedMain); if (namedMain.size() == 1) return U.single(namedMain); // the.group.id.foo.bar.Main (the shortest name) withGroupIdPkg.sort((s1, s2) -> s1.length() - s2.length()); getLog().info("Candidates by group ID - picking one with the shortest name: " + withGroupIdPkg); return U.first(withGroupIdPkg); }
Example 7
Source File: MojoToReportOptionsConverter.java From pitest with Apache License 2.0 | 5 votes |
private void useHistoryFileInTempDir(final ReportOptions data) { String tempDir = System.getProperty("java.io.tmpdir"); MavenProject project = this.mojo.getProject(); String name = project.getGroupId() + "." + project.getArtifactId() + "." + project.getVersion() + "_pitest_history.bin"; File historyFile = new File(tempDir, name); log.info("Will read and write history at " + historyFile); if (this.mojo.getHistoryInputFile() == null) { data.setHistoryInputLocation(historyFile); } if (this.mojo.getHistoryOutputFile() == null) { data.setHistoryOutputLocation(historyFile); } }
Example 8
Source File: CalculateVersions.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
@Override public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException { this.log.info("Calculating required versions for all modules."); for (MavenProject project : this.reactorProjects) { this.log.info("\tVersions of module " + ProjectToString.EXCLUDE_VERSION.apply(project) + ":"); ArtifactCoordinates preReleaseCoordinates = this.metadata .getArtifactCoordinatesByPhase(project.getGroupId(), project.getArtifactId()).get(ReleasePhase.PRE_RELEASE); this.log.info("\t\t" + ReleasePhase.PRE_RELEASE + " = " + preReleaseCoordinates.getVersion()); Optional<Prompter> prompterToUse = this.settings.isInteractiveMode() ? Optional.of(this.prompter) : Optional.<Prompter> absent(); String releaseVersion = calculateReleaseVersion(project.getVersion(), prompterToUse); ArtifactCoordinates releaseCoordinates = new ArtifactCoordinates(project.getGroupId(), project.getArtifactId(), releaseVersion, PomUtil.ARTIFACT_TYPE_POM); this.metadata.addArtifactCoordinates(releaseCoordinates, ReleasePhase.RELEASE); this.log.info("\t\t" + ReleasePhase.RELEASE + " = " + releaseVersion); String nextDevVersion = calculateDevelopmentVersion(project.getVersion(), prompterToUse); ArtifactCoordinates postReleaseCoordinates = new ArtifactCoordinates(project.getGroupId(), project.getArtifactId(), nextDevVersion, PomUtil.ARTIFACT_TYPE_POM); this.metadata.addArtifactCoordinates(postReleaseCoordinates, ReleasePhase.POST_RELEASE); this.log.info("\t\t" + ReleasePhase.POST_RELEASE + " = " + nextDevVersion); } }
Example 9
Source File: UpdateReleasePropertiesMojo.java From revapi with Apache License 2.0 | 5 votes |
@Override void updateProjectVersion(MavenProject project, Version version) throws MojoExecutionException { File rpf = getReleasePropertiesFile(); Properties ps = readProperties(rpf); String relProp; String devProp; if (isSingleVersionForAllModules()) { relProp = "project.rel." + project.getGroupId() + ":" + project.getArtifactId(); devProp = "project.dev." + project.getGroupId() + ":" + project.getArtifactId(); } else { relProp = "releaseVersion"; devProp = "developmentVersion"; } ps.setProperty(relProp, version.toString()); Version dev = version.clone(); dev.setPatch(dev.getPatch() + 1); dev.setSuffix(releaseVersionSuffix == null ? "SNAPSHOT" : releaseVersionSuffix + "-SNAPSHOT"); ps.setProperty(devProp, dev.toString()); try (FileOutputStream out = new FileOutputStream(rpf)) { ps.store(out, null); } catch (IOException e) { throw new MojoExecutionException("Failed to write to the release.properties file.", e); } }
Example 10
Source File: AbstractWSO2ProjectCreationWizard.java From developer-studio with Apache License 2.0 | 5 votes |
public String getMavenGroupId(File pomLocation) { String groupId = "org.wso2.carbon"; if (pomLocation != null && pomLocation.exists()) { try { MavenProject mavenProject = MavenUtils.getMavenProject(pomLocation); groupId = mavenProject.getGroupId(); } catch (Exception e) { log.error("error reading pom file", e); } } return groupId; }
Example 11
Source File: SmartBuilderImpl.java From takari-smart-builder with Apache License 2.0 | 4 votes |
private static String projectGA(MavenProject project) { return project.getGroupId() + ":" + project.getArtifactId(); }
Example 12
Source File: ReactorBuildStats.java From takari-smart-builder with Apache License 2.0 | 4 votes |
private static String projectGA(MavenProject project) { return project.getGroupId() + ":" + project.getArtifactId(); }
Example 13
Source File: ArkPluginMojoTest.java From sofa-ark with Apache License 2.0 | 4 votes |
@Test public void testShadeJar(@Mocked final MavenProject projectOne, @Mocked final MavenProject projectTwo, @Mocked final Artifact artifact) { ArkPluginMojo arkPluginMojo = new ArkPluginMojo(); arkPluginMojo.setShades(new LinkedHashSet<>(Collections .singleton("com.alipay.sofa:test-demo:1.0.0"))); new Expectations() { { projectOne.getGroupId(); result = "com.alipay.sofa"; minTimes = 0; projectOne.getArtifactId(); result = "test-demo"; minTimes = 0; projectTwo.getGroupId(); result = "com.alipay.sofa"; minTimes = 0; projectTwo.getArtifactId(); result = ""; minTimes = 0; artifact.getGroupId(); result = "com.alipay.sofa"; minTimes = 0; artifact.getArtifactId(); result = "test-demo"; artifact.getVersion(); result = "1.0.0"; minTimes = 0; } }; arkPluginMojo.setProject(projectOne); try { arkPluginMojo.isShadeJar(artifact); } catch (Exception ex) { Assert.assertTrue(ex.getMessage().equals("Can't shade jar-self.")); } arkPluginMojo.setProject(projectTwo); Assert.assertTrue(arkPluginMojo.isShadeJar(artifact)); }
Example 14
Source File: ReactorModelPool.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
public void addProject( MavenProject project ) { Coordinates coordinates = new Coordinates( project.getGroupId(), project.getArtifactId(), project.getVersion() ); models.put( coordinates, project.getFile() ); }
Example 15
Source File: GenerateProcess.java From dew with Apache License 2.0 | 4 votes |
/** * Process. * * @param mojo the mojo * @param mavenProject the maven project * @param mavenSession the maven session * @param pluginManager the plugin manager * @param language the language * @param inputSpec the input spec * @return the file */ public static File process(SDKGenMojo mojo, MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager, String language, String inputSpec) { log.info("Generate SDK by {}", language); /*MavenHelper.invoke("io.swagger.core.v3", "swagger-maven-plugin", "2.1.1", "resolve", new HashMap<>() { { put("outputFileName", output.getParent()); put("goals", new HashMap<>() { { put("goal", "-P release"); } }); put("mavenOpts", ""); } }, mavenProject, mavenSession, pluginManager);*/ String groupId = mavenProject.getGroupId(); String artifactId = mavenProject.getArtifactId() + ".sdk"; String basePackage = NameHelper.formatPackage(groupId + "." + mavenProject.getArtifactId() + ".sdk"); setAndGetIfNotExist(mojo, "apiPackage", basePackage + ".api"); setAndGetIfNotExist(mojo, "modelPackage", basePackage + ".model"); setAndGetIfNotExist(mojo, "invokerPackage", basePackage + ".invoker"); setAndGetIfNotExist(mojo, "groupId", groupId); setAndGetIfNotExist(mojo, "artifactId", artifactId); setAndGetIfNotExist(mojo, "artifactVersion", mavenProject.getVersion()); setValueToParentField(mojo, "language", language); setValueToParentField(mojo, "inputSpec", inputSpec); String lang; switch (language) { case "group.idealworld.dew.sdkgen.lang.java.DewJavaClientCodegen": lang = "java"; break; default: lang = language; } String finalLang = lang; setAndGetIfNotExist(mojo, "configOptions", new HashMap<String, Object>() { { put("sourceFolder", "src/main/" + finalLang); } }); return (File) $.bean.getValue(mojo, "output"); }
Example 16
Source File: Info.java From netbeans with Apache License 2.0 | 4 votes |
@Messages({ "# {0} - dir basename", "LBL_misconfigured_project={0} [unloadable]", "# {0} - path to project", "TXT_Maven_project_at=Maven project at {0}" }) private String getDisplayName(NbMavenProject nb) { MavenProject pr = nb.getMavenProject(); if (NbMavenProject.isErrorPlaceholder(pr)) { return LBL_misconfigured_project(project.getProjectDirectory().getNameExt()); } String custom = project.getLookup().lookup(AuxiliaryProperties.class).get(Constants.HINT_DISPLAY_NAME, true); if (custom == null) { custom = NbPreferences.forModule(Info.class).get(MavenSettings.PROP_PROJECTNODE_NAME_PATTERN, null); } if (custom != null) { //we evaluate because of global property and property in nb-configuration.xml file. The pom.xml originating value should be already resolved. ExpressionEvaluator evaluator = PluginPropertyUtils.createEvaluator(project); try { Object s = evaluator.evaluate(custom); if (s != null) { //just make sure the name gets resolved String ss = s.toString().replace("${project.name)", "" + pr.getGroupId() + ":" + pr.getArtifactId()); return ss; } } catch (ExpressionEvaluationException ex) { //now just continue to the default processing LOG.log(Level.INFO, "bad display name expression:" + custom, ex); } } String toReturn = pr.getName(); if (toReturn == null) { String grId = pr.getGroupId(); String artId = pr.getArtifactId(); if (grId != null && artId != null) { toReturn = grId + ":" + artId; //NOI18N } else { toReturn = TXT_Maven_project_at(FileUtil.getFileDisplayName(project.getProjectDirectory())); } } return toReturn; }
Example 17
Source File: Utils.java From deadcode4j with Apache License 2.0 | 2 votes |
/** * Returns <i>groupId:artifactId</i> for the specified project. * * @since 1.2.0 */ @Nonnull public static String getKeyFor(@Nonnull MavenProject project) { return project.getGroupId() + ":" + project.getArtifactId(); }