Search in sources :

Example 1 with Parent

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;
}
Also used : MavenBuild(org.eclipse.che.maven.data.MavenBuild) MavenKey(org.eclipse.che.maven.data.MavenKey) Parent(org.apache.maven.model.Parent) MavenParent(org.eclipse.che.maven.data.MavenParent) MavenBuild(org.eclipse.che.maven.data.MavenBuild) Build(org.apache.maven.model.Build) MavenModel(org.eclipse.che.maven.data.MavenModel) Model(org.apache.maven.model.Model)

Example 2 with Parent

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;
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) MavenModel(org.eclipse.che.maven.data.MavenModel) Parent(org.apache.maven.model.Parent) MavenParent(org.eclipse.che.maven.data.MavenParent) HashMap(java.util.HashMap) MavenParent(org.eclipse.che.maven.data.MavenParent) Properties(java.util.Properties) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with Parent

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);
}
Also used : DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ModelBuilder(org.apache.maven.model.building.ModelBuilder) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Parent(org.apache.maven.model.Parent) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Model(org.apache.maven.model.Model) File(java.io.File) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 4 with Parent

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());
}
Also used : Parent(org.apache.maven.model.Parent) InputStream(java.io.InputStream) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with Parent

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);
            }
        }
    }
}
Also used : Parent(org.apache.maven.model.Parent) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Aggregations

Parent (org.apache.maven.model.Parent)26 Model (org.apache.maven.model.Model)13 Build (org.apache.maven.model.Build)5 File (java.io.File)4 Properties (java.util.Properties)4 Test (org.junit.Test)4 Artifact (org.apache.maven.artifact.Artifact)3 Dependency (org.apache.maven.model.Dependency)3 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)3 ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)2 ReleasePhase (com.itemis.maven.plugins.unleash.ReleasePhase)2 THashMap (gnu.trove.THashMap)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 DependencyManagement (org.apache.maven.model.DependencyManagement)2 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)2 MavenKey (org.eclipse.che.maven.data.MavenKey)2 MavenModel (org.eclipse.che.maven.data.MavenModel)2