List of usage examples for org.apache.maven.project MavenProject getParentFile
public File getParentFile()
From source file:fr.fastconnect.factory.tibco.bw.maven.InitializeMojo.java
License:Apache License
protected static File getParent(MavenProject project, Log logger) throws IOException, XmlPullParserException { File result = null;/*from w w w .j av a 2 s. com*/ MavenProject parent = project.getParent(); if (parent == null) { return result; // no parent: return null } File parentPOM = parent.getFile(); File parentBasedir = null; if (parentPOM != null && parentPOM.getParentFile() != null && parentPOM.getParentFile().exists() && parentPOM.getParentFile().isDirectory()) { parentBasedir = parentPOM.getParentFile(); } if (parentPOM != null) { logger.debug("parentPOM: " + parentPOM.getAbsolutePath()); } while (parentBasedir != null && parentBasedir.exists()) { logger.debug("parentBasedir: " + parentBasedir.getAbsolutePath()); if (findParentPath(parentBasedir, logger)) { logger.debug("parentFound"); result = parentBasedir; break; } logger.debug("parentNotFound"); if (parent != null) { logger.debug(parent.getArtifactId()); parentBasedir = parent.getParentFile(); // use <relativePath> to retrieve real parent file if (parentBasedir == null && parent.getParent() != null) { parentBasedir = parent.getParent().getFile(); } if (parentBasedir != null) { logger.debug(parentBasedir.getAbsolutePath()); } if (parentBasedir != null && parentBasedir.exists() && parentBasedir.isFile()) { parentBasedir = parentBasedir.getParentFile(); } parent = parent.getParent(); } } return result; }
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 {/* w w w. j a va 2 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.scada.build.helper.AbstractSetQualifierMojo.java
License:Open Source License
private void checkNonRelativeParent(final MavenProject project) { if (project.getModel().getParent() == null) { // no parent return;//from w ww. ja v a 2s . c om } if (project.getParentFile() != null) { // is a local parent return; } final Parent parent = project.getModel().getParent(); final String prefix = String.format("%s:%s:", parent.getGroupId(), parent.getArtifactId()); for (final String entry : this.forceUpdateParentQualifiers) { if (entry.startsWith(prefix)) { final String qualifier = entry.substring(prefix.length()); final String newVersion = makeVersion(parent.getVersion(), qualifier); getLog().info(String.format("Force update parent of %s to %s -> %s", project.getId(), parent.getId(), newVersion)); addChange(project.getFile(), new ModelModifier() { @Override public boolean apply(final Model model) { model.getParent().setVersion(newVersion); return true; } }); } } }
From source file:org.eclipse.scada.build.helper.DefaultPomHelper.java
License:Open Source License
private boolean hasLocalParent(final MavenProject project) { if (project.getParentFile() != null) { return true; }/* www . j a v a 2 s . co m*/ return false; }
From source file:org.eclipse.scada.build.helper.DefaultPomHelper.java
License:Open Source License
@Override public void visitModulesWithParent(final Collection<MavenProject> projects, final MavenProject parentProject, final ProjectVisitor visitor) throws Exception { for (final MavenProject project : projects) { if (project.getParentFile() == null) { continue; }//from w w w .j av a2 s . c o m if (project.getParentFile().equals(parentProject.getFile())) { visitor.visit(project); } } }
From source file:org.jboss.maven.plugins.qstools.fixers.ArtifactIdNameFixer.java
License:Apache License
@Override public void fix(MavenProject project, MavenSession mavenSession, List<MavenProject> reactorProjects, Log log) throws QSToolsException { try {/*from www .j a v a 2s . c om*/ Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId()); List<ArtifactIdNameUtil.PomInformation> pomsWithInvalidArtifactIds = artifactIdNameUtil .findAllIncorrectArtifactIdNames(reactorProjects, rules); // Update each incorrect artifactId for (ArtifactIdNameUtil.PomInformation pi : pomsWithInvalidArtifactIds) { Document doc = PositionalXMLReader.readXML(new FileInputStream(pi.getProject().getFile())); Node artifactIdNode = (Node) xPath.evaluate("/project/artifactId", doc, XPathConstants.NODE); artifactIdNode.setTextContent(pi.getExpectedArtifactId()); XMLUtil.writeXML(doc, pi.getProject().getFile()); } // Update all the parents, to use the changed artifactId for (MavenProject subProject : reactorProjects) { Document doc = PositionalXMLReader.readXML(new FileInputStream(subProject.getFile())); Node parentArtifactIdNode = (Node) xPath.evaluate("/project/parent/artifactId", doc, XPathConstants.NODE); if (parentArtifactIdNode != null && subProject.getParentFile() != null) { Document parentDoc = PositionalXMLReader .readXML(new FileInputStream(subProject.getParentFile())); Node artifactIdNode = (Node) xPath.evaluate("/project/artifactId", parentDoc, XPathConstants.NODE); if (!parentArtifactIdNode.getTextContent().equals(artifactIdNode.getTextContent())) { parentArtifactIdNode.setTextContent(artifactIdNode.getTextContent()); } } // Update each incorrect artifactId dependency for (ArtifactIdNameUtil.PomInformation pi : pomsWithInvalidArtifactIds) { // It can have more than one occurrence on the same file NodeList artfactIdNodes = (NodeList) xPath.evaluate( "//artifactId[text()='" + pi.getActualArtifactId() + "']", doc, XPathConstants.NODESET); for (int x = 0; x < artfactIdNodes.getLength(); x++) { Node artfactIdNode = artfactIdNodes.item(x); if (artfactIdNode != null) { artfactIdNode.setTextContent(pi.getExpectedArtifactId()); } } } XMLUtil.writeXML(doc, subProject.getFile()); } } catch (Exception e) { throw new QSToolsException(e); } }
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 w w. ja v a 2 s .c om*/ 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.vaadin.netbeans.impl.VaadinSupportImpl.java
License:Apache License
@Override public String getVaadinVersion() { NbMavenProject mvnProject = getProject().getLookup().lookup(NbMavenProject.class); MavenProject mavenProject = mvnProject.getMavenProject(); FileObject pom = FileUtil.toFileObject(FileUtil.normalizeFile(mavenProject.getFile())); String version = getVaadinVersion(pom); if (version == null) { version = getVaadinVersion(FileUtil.toFileObject(FileUtil.normalizeFile(mavenProject.getParentFile()))); }//from ww w.ja v a 2 s. c o m if (version == null) { LOG.severe( "Unknown project structure: cannot get version " + "neither from the project nor from parents"); } return version; }