org.apache.maven.model.Parent Java Examples
The following examples show how to use
org.apache.maven.model.Parent.
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: AbstractVersionsStep.java From unleash-maven-plugin with Eclipse Public License 1.0 | 6 votes |
private void setParentVersion(MavenProject project, Document document) { Parent parent = project.getModel().getParent(); if (parent != null) { Map<ReleasePhase, ArtifactCoordinates> coordinatesByPhase = this.metadata .getArtifactCoordinatesByPhase(parent.getGroupId(), parent.getArtifactId()); ArtifactCoordinates oldCoordinates = coordinatesByPhase.get(previousReleasePhase()); ArtifactCoordinates newCoordinates = coordinatesByPhase.get(currentReleasePhase()); // null indicates that the parent is not part of the reactor projects since no release version had been calculated // for it if (newCoordinates != null) { logParentVersionUpdate(project, oldCoordinates, newCoordinates); PomUtil.setParentVersion(project.getModel(), document, newCoordinates.getVersion()); } } }
Example #2
Source File: NewGraniteProjectWizard.java From aem-eclipse-developer-tools with Apache License 2.0 | 6 votes |
private void fixParentProject(IProject p, IProject parentProject) throws CoreException { IFile existingPom = p.getFile("pom.xml"); Model model = MavenPlugin.getMavenModelManager().readMavenModel(existingPom); Model parent = MavenPlugin.getMavenModelManager().readMavenModel(parentProject.getFile("pom.xml")); //Parent oldParent = model.getParent(); Parent newParent = new Parent(); newParent.setGroupId(parent.getGroupId()); newParent.setArtifactId(parent.getArtifactId()); newParent.setRelativePath(calculateRelativePath(p, parentProject)); newParent.setVersion(parent.getVersion()); model.setParent(newParent); // outright deletion doesn't work on windows as the process has a ref to the file itself // so creating a temp '_newpom_.xml' final IFile newPom = p.getFile("_newpom_.xml"); MavenPlugin.getMavenModelManager().createMavenModel(newPom, model); // then copying that content over to the pom.xml existingPom.setContents(newPom.getContents(), true, true, new NullProgressMonitor()); // and deleting the temp pom newPom.delete(true, false, new NullProgressMonitor()); }
Example #3
Source File: MSF4JProjectImporter.java From msf4j with Apache License 2.0 | 6 votes |
private void saveMavenParentInfo(MavenProjectInfo projectInfo) throws IOException, XmlPullParserException { File mavenProjectPomLocation = projectInfo.getPomFile();// project.getFile(POM_FILE).getLocation().toFile(); MavenProject mavenProject = null; mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation); Parent msf4jParent = new Parent(); msf4jParent.setGroupId(MSF4J_SERVICE_PARENT_GROUP_ID); msf4jParent.setArtifactId(MSF4J_SERVICE_PARENT_ARTIFACT_ID); msf4jParent.setVersion(MSF4JArtifactConstants.getMSF4JServiceParentVersion()); mavenProject.getModel().setParent(msf4jParent); Properties generatedProperties = mavenProject.getModel().getProperties(); generatedProperties.clear(); mavenProject.getModel().addProperty(MSF4J_MAIN_CLASS_PROPERTY, DEFAULT_MAIN_CLASS_PROPERTY_VALUE); MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation); }
Example #4
Source File: ParentPOMPropagatingArtifactDescriptorReaderDelegate.java From mvn2nix-maven-plugin with MIT License | 6 votes |
@Override public void populateResult(RepositorySystemSession session, ArtifactDescriptorResult result, Model model) { super.populateResult(session, result, model); Parent parent = model.getParent(); if (parent != null) { DefaultArtifact art = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "pom", parent.getVersion()); Dependency dep = new Dependency(art, "compile"); result.addDependency(dep); } }
Example #5
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Returns all the models that have a specified groupId and artifactId as parent. * * @param reactor The map of models keyed by path. * @param groupId The groupId of the parent. * @param artifactId The artifactId of the parent. * @return a map of models that have a specified groupId and artifactId as parent keyed by path. */ public static Map<String, Model> getChildModels( Map<String, Model> reactor, String groupId, String artifactId ) { final Map<String, Model> result = new LinkedHashMap<String, Model>(); for ( Map.Entry<String, Model> entry : reactor.entrySet() ) { final String path = entry.getKey(); final Model model = entry.getValue(); final Parent parent = model.getParent(); if ( parent != null && groupId.equals( parent.getGroupId() ) && artifactId.equals( parent.getArtifactId() ) ) { result.put( path, model ); } } return result; }
Example #6
Source File: FlattenModelResolver.java From flatten-maven-plugin with Apache License 2.0 | 6 votes |
/** * Resolves the POM for the specified parent. * * @param parent the parent coordinates to resolve, must not be {@code null} * @return The source of the requested POM, never {@code null} * @since Apache-Maven-3.2.2 (MNG-5639) */ public ModelSource resolveModel( Parent parent ) throws UnresolvableModelException { String groupId = parent.getGroupId(); String artifactId = parent.getArtifactId(); String version = parent.getVersion(); // resolve version range (if present) if ( isRestrictedVersionRange( version, groupId, artifactId ) ) { version = resolveParentVersionRange( groupId, artifactId, version ); } return resolveModel( groupId, artifactId, version ); }
Example #7
Source File: GAVTest.java From maven-git-versioning-extension with MIT License | 6 votes |
@Test void of_model_withParent_withInheritance() { // Given Model model = new Model(); model.setArtifactId("artifact"); Parent parent = new Parent(); parent.setGroupId("parentGroup"); parent.setArtifactId("parentArtifact"); parent.setVersion("parentVersion"); model.setParent(parent); // When GAV gav = GAV.of(model); // Then assertThat(gav).isNotNull(); assertThat(gav.getGroupId()).isEqualTo("parentGroup"); assertThat(gav.getArtifactId()).isEqualTo("artifact"); assertThat(gav.getVersion()).isEqualTo("parentVersion"); }
Example #8
Source File: GAVTest.java From maven-git-versioning-extension with MIT License | 6 votes |
@Test void of_model_withParent_noInheritance() { // Given Model model = new Model(); model.setGroupId("group"); model.setArtifactId("artifact"); model.setVersion("version"); Parent parent = new Parent(); parent.setGroupId("parentGroup"); parent.setArtifactId("parentArtifact"); parent.setVersion("parentVersion"); model.setParent(parent); // When GAV gav = GAV.of(model); // Then assertThat(gav).isNotNull(); assertThat(gav.getGroupId()).isEqualTo("group"); assertThat(gav.getArtifactId()).isEqualTo("artifact"); assertThat(gav.getVersion()).isEqualTo("version"); }
Example #9
Source File: MavenDetailsPage.java From developer-studio with Apache License 2.0 | 6 votes |
private void setParentMavenInfo(Parent info) { if (info != null) { setParentProjectName(info.getArtifactId()); setParentGroupID(info.getGroupId()); setParentArtifactID(info.getArtifactId()); setParentVersion(info.getVersion()); setParentRelativePath(info.getRelativePath()); txtParentArtifactId.setText(getParentArtifactID()); txtParentGroupId.setText(getParentGroupID()); txtParentVersion.setText(getParentVersion()); String parentRelativePath2 = getParentRelativePath(); if (hasParentProject && parentRelativePath2 != null) { txtRelativePath.setText(parentRelativePath2); } else { txtRelativePath.setText(""); } } }
Example #10
Source File: GAV.java From maven-git-versioning-extension with MIT License | 6 votes |
public static GAV of(Model model) { String groupId = model.getGroupId(); String artifactId = model.getArtifactId(); String version = model.getVersion(); Parent parent = model.getParent(); if (parent != null) { if (groupId == null) { groupId = parent.getGroupId(); } if (version == null) { version = parent.getVersion(); } } return new GAV(groupId, artifactId, version); }
Example #11
Source File: PomUtil.java From unleash-maven-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Changes the project's parent version of the POM as well as directly in the XML document preserving the whole * document formatting. * * @param model the POM where to adapt the project's parent version. * @param document the POM as an XML document in which the project's parent version shall be adapted. * @param newParentVersion the new version to set for the project parent. */ public static void setParentVersion(Model model, Document document, String newParentVersion) { Preconditions.checkArgument(hasChildNode(document, NODE_NAME_PROJECT), "The document doesn't seem to be a POM model, project element is missing."); // first step: update parent version of the in-memory model Parent parent = model.getParent(); if (parent != null) { parent.setVersion(newParentVersion); } // second step: update the parent version in the DOM document that will be serialized for later building Node parentNode = document.getDocumentElement().getElementsByTagName(PomUtil.NODE_NAME_PARENT).item(0); if (parentNode != null) { NodeList children = parentNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (Objects.equal(child.getNodeName(), PomUtil.NODE_NAME_VERSION)) { child.setTextContent(newParentVersion); } } } }
Example #12
Source File: SetupProjectHelper.java From fabric8-forge with Apache License 2.0 | 6 votes |
@Deprecated public static boolean isFunktionParentPom(Project project) { MavenFacet mavenFacet = project.getFacet(MavenFacet.class); if (mavenFacet != null) { Model model = mavenFacet.getModel(); if (model != null) { Parent parent = model.getParent(); if (parent != null) { String groupId = parent.getGroupId(); if (groupId != null && groupId.startsWith("io.fabric8.funktion")) { return true; } } } } return false; }
Example #13
Source File: BaseCycloneDxMojo.java From cyclonedx-maven-plugin with Apache License 2.0 | 6 votes |
/** * Retrieves the parent pom for an artifact (if any). The parent pom may contain license, * description, and other metadata whereas the artifact itself may not. * @param artifact the artifact to retrieve the parent pom for * @param project the maven project the artifact is part of */ private MavenProject retrieveParentProject(final Artifact artifact, final MavenProject project) { if (artifact.getFile() == null || artifact.getFile().getParentFile() == null || !isDescribedArtifact(artifact)) { return null; } final Model model = project.getModel(); if (model.getParent() != null) { final Parent parent = model.getParent(); // Navigate out of version, artifactId, and first (possibly only) level of groupId final StringBuilder getout = new StringBuilder("../../../"); final int periods = artifact.getGroupId().length() - artifact.getGroupId().replace(".", "").length(); for (int i= 0; i< periods; i++) { getout.append("../"); } final File parentFile = new File(artifact.getFile().getParentFile(), getout + parent.getGroupId().replace(".", "/") + "/" + parent.getArtifactId() + "/" + parent.getVersion() + "/" + parent.getArtifactId() + "-" + parent.getVersion() + ".pom"); if (parentFile.exists() && parentFile.isFile()) { try { return readPom(parentFile.getCanonicalFile()); } catch (Exception e) { getLog().error("An error occurred retrieving an artifacts parent pom", e); } } } return null; }
Example #14
Source File: LocationAwareMavenXpp3Writer.java From netbeans with Apache License 2.0 | 6 votes |
private void writeParent(Parent parent, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); flush(serializer); StringBuffer b = b(serializer); int start = b.length(); if (parent.getGroupId() != null) { writeValue(serializer, "groupId", parent.getGroupId(), parent); } if (parent.getArtifactId() != null) { writeValue(serializer, "artifactId", parent.getArtifactId(), parent); } if (parent.getVersion() != null) { writeValue(serializer, "version", parent.getVersion(), parent); } if ((parent.getRelativePath() != null) && !parent.getRelativePath().equals("../pom.xml")) { writeValue(serializer, "relativePath", parent.getRelativePath(), parent); } serializer.endTag(NAMESPACE, tagName).flush(); logLocation(parent, "", start, b.length()); }
Example #15
Source File: ParentInjectionState.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
public void initialise( Properties userProps ) { final String gav = userProps.getProperty( PARENT_INJECTION_PROPERTY ); if ( gav != null ) { ProjectVersionRef ref = SimpleProjectVersionRef.parse( gav ); parent = new Parent(); parent.setGroupId( ref.getGroupId() ); parent.setArtifactId( ref.getArtifactId() ); parent.setVersion( ref.getVersionString() ); parent.setRelativePath( "" ); } else { parent = null; } }
Example #16
Source File: QuarkusJsonPlatformDescriptorResolver.java From quarkus with Apache License 2.0 | 6 votes |
private static String getVersion(Model model) { if (model == null) { return null; } String version = model.getVersion(); if (version != null) { return version; } final Parent parent = model.getParent(); if (parent != null) { version = parent.getVersion(); if (version != null) { return version; } } throw new IllegalStateException("Failed to determine the version for the POM of " + model.getArtifactId()); }
Example #17
Source File: LocalProject.java From quarkus with Apache License 2.0 | 6 votes |
private static Model loadRootModel(Path pomXml) throws BootstrapMavenException { Model model = null; while (pomXml != null && Files.exists(pomXml)) { model = readModel(pomXml); final Parent parent = model.getParent(); if (parent != null && parent.getRelativePath() != null && !parent.getRelativePath().isEmpty()) { pomXml = pomXml.getParent().resolve(parent.getRelativePath()).normalize(); if (Files.isDirectory(pomXml)) { pomXml = pomXml.resolve(POM_XML); } } else { final Path parentDir = pomXml.getParent().getParent(); pomXml = parentDir == null ? null : parentDir.resolve(POM_XML); } } return model; }
Example #18
Source File: MvnProjectBuilder.java From quarkus with Apache License 2.0 | 6 votes |
public MvnProjectBuilder addModule(String path, String artifactId, boolean initParent) { model.addModule(path); final MvnProjectBuilder module = new MvnProjectBuilder(artifactId, this); if (initParent) { final Parent parentModel = new Parent(); module.model.setParent(parentModel); parentModel.setGroupId(model.getGroupId()); parentModel.setArtifactId(model.getArtifactId()); parentModel.setVersion(model.getVersion()); final Path rootDir = Paths.get("").toAbsolutePath(); final Path moduleDir = rootDir.resolve(path).normalize(); if (!moduleDir.getParent().equals(rootDir)) { parentModel.setRelativePath(moduleDir.relativize(rootDir).toString()); } } modules.add(module); return module; }
Example #19
Source File: MavenHelper.java From cyclonedx-gradle-plugin with Apache License 2.0 | 6 votes |
/** * Retrieves the parent pom for an artifact (if any). The parent pom may contain license, * description, and other metadata whereas the artifact itself may not. * @param artifact the artifact to retrieve the parent pom for * @param project the maven project the artifact is part of */ private MavenProject retrieveParentProject(ResolvedArtifact artifact, MavenProject project) { if (artifact.getFile() == null || artifact.getFile().getParentFile() == null || !isDescribedArtifact(artifact)) { return null; } final Model model = project.getModel(); if (model.getParent() != null) { final Parent parent = model.getParent(); // Navigate out of version, artifactId, and first (possibly only) level of groupId final StringBuilder getout = new StringBuilder("../../../"); final ModuleVersionIdentifier mid = artifact.getModuleVersion().getId(); final int periods = mid.getGroup().length() - mid.getGroup().replace(".", "").length(); for (int i= 0; i< periods; i++) { getout.append("../"); } final File parentFile = new File(artifact.getFile().getParentFile(), getout + parent.getGroupId().replace(".", "/") + "/" + parent.getArtifactId() + "/" + parent.getVersion() + "/" + parent.getArtifactId() + "-" + parent.getVersion() + ".pom"); if (parentFile.exists() && parentFile.isFile()) { try { return readPom(parentFile.getCanonicalFile()); } catch (Exception e) { logger.error("An error occurred retrieving an artifacts parent pom", e); } } } return null; }
Example #20
Source File: QuarkusJsonPlatformDescriptorResolver.java From quarkus with Apache License 2.0 | 6 votes |
private static String getGroupId(Model model) { if (model == null) { return null; } String groupId = model.getGroupId(); if (groupId != null) { return groupId; } final Parent parent = model.getParent(); if (parent != null) { groupId = parent.getGroupId(); if (groupId != null) { return groupId; } } throw new IllegalStateException("Failed to determine the groupId for the POM of " + model.getArtifactId()); }
Example #21
Source File: CommandRequirements.java From helidon-build-tools with Apache License 2.0 | 6 votes |
/** * Require that a valid Maven project configuration exists. * * @param commonOptions The options. */ static void requireValidMavenProjectConfig(CommonOptions commonOptions) { try { Path projectDir = commonOptions.project(); Path pomFile = PomUtils.toPomFile(projectDir); Path projectConfigFile = ProjectConfig.toDotHelidon(projectDir); if (!Files.exists(projectConfigFile)) { // Find the helidon version if we can and create the config file Model model = PomUtils.readPomModel(pomFile); Parent parent = model.getParent(); String helidonVersion = null; if (parent != null && parent.getGroupId().startsWith("io.helidon.")) { helidonVersion = parent.getVersion(); } ensureProjectConfig(projectDir, helidonVersion); } } catch (IllegalArgumentException e) { String message = e.getMessage(); if (message.contains("does not exist")) { message = NOT_A_PROJECT_DIR; } Requirements.failed(message); } }
Example #22
Source File: MavenDetailsPage.java From developer-studio with Apache License 2.0 | 5 votes |
/** * Create the wizard. */ public MavenDetailsPage(ProjectDataModel projectDataModel) { super("wizardPage"); setTitle("Maven Information"); setDescription("Maven information for the project"); this.dataModel = projectDataModel; this.mavenProjectInfo = projectDataModel.getMavenInfo(); dataModel.addObserver(this); hasParentProject = false; parentProjectlist = new HashMap<String, Parent>(); }
Example #23
Source File: MSF4JArtifactProjectNature.java From msf4j with Apache License 2.0 | 5 votes |
/** * Update created pom.xml file with necessary dependencies and plug-ins so * that it works with WSO2 MSF4J server * * @throws IOException * @throws XmlPullParserException * */ private void updatePom(IProject project) throws IOException, XmlPullParserException { File mavenProjectPomLocation = project.getFile(POM_FILE).getLocation().toFile(); MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation); Parent msf4jParent = new Parent(); msf4jParent.setGroupId(MSF4J_SERVICE_PARENT_GROUP_ID); msf4jParent.setArtifactId(MSF4J_SERVICE_PARENT_ARTIFACT_ID); msf4jParent.setVersion(MSF4JArtifactConstants.getMSF4JServiceParentVersion()); mavenProject.getModel().setParent(msf4jParent); Properties generatedProperties = mavenProject.getModel().getProperties(); generatedProperties.clear(); }
Example #24
Source File: AbstractVersionsDependencyUpdaterMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
protected Artifact toArtifact( Parent model ) throws MojoExecutionException { Dependency d = new Dependency(); d.setArtifactId( model.getArtifactId() ); d.setGroupId( model.getGroupId() ); d.setVersion( model.getVersion() ); d.setType( "pom" ); d.setScope( Artifact.SCOPE_COMPILE ); return this.toArtifact( d ); }
Example #25
Source File: MavenDetailsPage.java From developer-studio with Apache License 2.0 | 5 votes |
private void loadParentProjectInfo() throws Exception { List<Parent> parentMavenProjects = getParentMavenProjects(new ArrayList<Parent>()); parentProjectInfoCombo.removeAll(); parentProjectInfoCombo.update(); for (Parent parent : parentMavenProjects) { parentProjectlist.put(parent.getArtifactId(), parent); parentProjectInfoCombo.add(parent.getArtifactId()); } if (parentProjectInfoCombo.getSelectionIndex() == -1) { parentProjectInfoCombo.select(0); } hasLoadedProjectList = true; }
Example #26
Source File: ModelUtils.java From quarkus with Apache License 2.0 | 5 votes |
public static String getGroupId(Model model) { String groupId = model.getGroupId(); if (groupId != null) { return groupId; } final Parent parent = model.getParent(); if (parent != null) { groupId = parent.getGroupId(); if (groupId != null) { return groupId; } } throw new IllegalStateException("Failed to determine groupId for project model"); }
Example #27
Source File: MavenDetailsPage.java From developer-studio with Apache License 2.0 | 5 votes |
private Parent getParentFromPreferernceStore() { Parent parent = new Parent(); parent.setGroupId(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui", GLOBAL_PARENT_MAVEN_GROUP_ID, null, null)); parent.setArtifactId(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui", GLOBAL_PARENT_MAVEN_ARTIFACTID, null, null)); parent.setVersion(preferencesService.getString("org.wso2.developerstudio.eclipse.platform.ui", GLOBAL_PARENT_MAVEN_VERSION, null, null)); parent.setRelativePath(null); return parent; }
Example #28
Source File: MavenDetailsPage.java From developer-studio with Apache License 2.0 | 5 votes |
private void updateParent() { Parent parent = new Parent(); parent.setArtifactId(getParentArtifactID()); parent.setGroupId(getParentGroupID()); parent.setVersion(getParentVersion()); parent.setRelativePath(getParentRelativePath()); mavenProjectInfo.setParentProject(parent); dataModel.setMavenInfo(mavenProjectInfo); }
Example #29
Source File: MavenUploadHandlerTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test public void testValidatPom_parentVersion() { Model model = new Model(); model.setParent(new Parent()); model.getParent().setVersion("2.0"); model.setGroupId("testGroup"); model.setArtifactId("testArtifact"); underTest.validatePom(model); }
Example #30
Source File: MavenUploadHandlerTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test public void testValidatPom_parentGroup() { Model model = new Model(); model.setParent(new Parent()); model.getParent().setGroupId("parentGroup"); model.setArtifactId("testArtifact"); model.setVersion("1.0"); underTest.validatePom(model); }