use of org.apache.maven.model.Parent in project che by eclipse.
the class MavenModelUtil method convertToMavenModel.
public static Model convertToMavenModel(MavenModel model) {
Model result = new Model();
result.setArtifactId(model.getMavenKey().getArtifactId());
result.setGroupId(model.getMavenKey().getGroupId());
result.setVersion(model.getMavenKey().getVersion());
result.setPackaging(model.getPackaging());
result.setName(model.getName());
if (model.getParent() != null) {
Parent parent = new Parent();
MavenKey parentKey = model.getParent().getMavenKey();
parent.setArtifactId(parentKey.getArtifactId());
parent.setGroupId(parentKey.getGroupId());
parent.setVersion(parentKey.getVersion());
parent.setRelativePath(model.getParent().getRelativePath());
result.setParent(parent);
}
result.setProperties(model.getProperties());
result.setModules(model.getModules());
result.setBuild(new Build());
MavenBuild modelBuild = model.getBuild();
convertToMavenBuildBase(modelBuild, result.getBuild());
result.getBuild().setSourceDirectory(modelBuild.getSources().get(0));
result.getBuild().setTestSourceDirectory(modelBuild.getTestSources().get(0));
result.setProfiles(convertToMavenProfiles(model.getProfiles()));
return result;
}
use of org.apache.maven.model.Parent in project che by eclipse.
the class MavenModelUtil method convertModel.
public static MavenModel convertModel(Model model, List<String> sources, List<String> testSources, Collection<Artifact> dependencies, Collection<Artifact> extensions, File localRepo) {
MavenModel result = new MavenModel();
result.setMavenKey(new MavenKey(model.getGroupId(), model.getArtifactId(), model.getVersion()));
Parent parent = model.getParent();
if (parent != null) {
result.setParent(new MavenParent(new MavenKey(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()), parent.getRelativePath()));
}
result.setName(model.getName());
result.setPackaging(model.getPackaging());
result.setProperties(model.getProperties() != null ? model.getProperties() : new Properties());
result.setModules(model.getModules());
result.setPlugins(convertPlugins(model));
Map<Artifact, MavenArtifact> convertedArtifacts = new HashMap<>();
result.setExtensions(convertArtifacts(extensions, convertedArtifacts, localRepo));
result.setDependencies(convertArtifacts(dependencies, convertedArtifacts, localRepo));
result.setRemoteRepositories(convertRepositories(model.getRepositories()));
result.setProfiles(convertProfiles(model.getProfiles()));
convertBuild(result.getBuild(), model.getBuild(), sources, testSources);
return result;
}
use of org.apache.maven.model.Parent in project gate-core by GateNLP.
the class SimpleMavenCache method cacheParents.
private void cacheParents(File pom, RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository> repos) throws ModelBuildingException, IOException, ArtifactResolutionException {
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setProcessPlugins(false);
req.setPomFile(pom);
req.setModelResolver(new SimpleModelResolver(repoSystem, repoSession, repos));
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
ModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
Model model = modelBuilder.build(req).getEffectiveModel();
Parent parent = model.getParent();
if (parent == null)
return;
Artifact pomArtifact = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "pom", parent.getVersion());
ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, repos, null);
ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest);
// but copy it to a file named for the original requested version number
File file = getArtifactFile(artifactRequest.getArtifact());
FileUtils.copyFile(artifactResult.getArtifact().getFile(), file);
cacheParents(artifactResult.getArtifact().getFile(), repoSystem, repoSession, repos);
}
use of org.apache.maven.model.Parent in project motech by motech.
the class PomInformationTest method shouldParseParentPomFile.
@Test
public void shouldParseParentPomFile() throws IOException {
Properties properties = new Properties();
properties.put("test.properties", "testParent");
// Because we use <version> and <artifactId> tags in our tested pom, the parsing method should add this as properties
properties.put("project.version", "0-27-SNAPSHOT");
properties.put("project.artifactId", "motech-platform-server-api");
try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("pom/parentPom.xml")) {
pomInformation = new PomInformation();
pomInformation.parseParentPom(inputStream);
}
PomInformation parentPom = pomInformation.getParentPomInformation();
assertEquals(properties, parentPom.getProperties());
Parent parentFromParsing = parentPom.getParent();
assertEquals("0.27-SNAPSHOT", parentFromParsing.getVersion());
assertEquals("motech", parentFromParsing.getArtifactId());
assertEquals("org.motechproject", parentFromParsing.getGroupId());
}
use of org.apache.maven.model.Parent in project unleash-maven-plugin by shillner.
the class PomUtil method setParentVersion.
/**
* 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);
}
}
}
}
Aggregations