Search in sources :

Example 16 with Parent

use of org.apache.maven.model.Parent in project pom-manipulation-ext by release-engineering.

the class ProjectVersionManipulatorTest method updateEffectiveAndOriginalModelParentVersions.

@Test
public void updateEffectiveAndOriginalModelParentVersions() throws Exception {
    final Model parent = new Model();
    parent.setGroupId("org.foo");
    parent.setArtifactId("bar-parent");
    parent.setVersion("1.0");
    final Model orig = new Model();
    orig.setArtifactId("bar");
    final Parent origParent = new Parent();
    origParent.setGroupId(parent.getGroupId());
    origParent.setArtifactId(parent.getArtifactId());
    origParent.setVersion(parent.getVersion());
    orig.setParent(origParent);
    final Model eff = orig.clone();
    final String suff = "redhat-1";
    final String mv = orig.getVersion() + "." + suff;
    final Map<ProjectVersionRef, String> versionsByGA = new HashMap<>();
    // Not putting original group/artifact/version as they are group & version are null which causes problems with ProjectVersionRef
    versionsByGA.put(new SimpleProjectVersionRef(origParent.getGroupId(), origParent.getArtifactId(), origParent.getVersion()), mv);
    final List<MavenProject> projects = new ArrayList<>();
    MavenProject project = new MavenProject(parent.clone());
    project.setOriginalModel(parent);
    projects.add(project);
    project = new MavenProject(eff);
    project.setOriginalModel(orig);
    projects.add(project);
    final Set<MavenProject> changes = newVersioningModifier().applyVersioningChanges(projects, versionsByGA);
    assertThat(changes.size(), equalTo(2));
    for (final MavenProject p : changes) {
        if (p.getArtifactId().equals("bar")) {
            assertThat(p.getOriginalModel().getParent().getVersion(), equalTo(mv));
            assertThat(p.getModel().getParent().getVersion(), equalTo(mv));
            assertThat(p.getOriginalModel().getVersion(), nullValue());
            assertThat(p.getModel().getVersion(), nullValue());
        } else {
            assertThat(p.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(p.getModel().getVersion(), equalTo(mv));
        }
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Parent(org.apache.maven.model.Parent) HashMap(java.util.HashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) ArrayList(java.util.ArrayList) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 17 with Parent

use of org.apache.maven.model.Parent in project pom-manipulation-ext by release-engineering.

the class IdUtils method g.

public static String g(final Model model) {
    String g = model.getGroupId();
    final Parent p = model.getParent();
    if (p != null) {
        if (g == null) {
            g = p.getGroupId();
        }
    }
    return g;
}
Also used : Parent(org.apache.maven.model.Parent)

Example 18 with Parent

use of org.apache.maven.model.Parent in project motech by motech.

the class PomInformationTest method shouldParsePomFile.

@Test
public void shouldParsePomFile() throws IOException {
    Properties properties = new Properties();
    properties.put("test.properties", "test");
    properties.put("modules.root.dir", "${basedir}/../..");
    // Because we use <version> and <groupId> tags in our tested pom, the parsing method should add this as properties
    properties.put("project.version", "0-27-SNAPSHOT");
    properties.put("project.groupId", "testGroupId");
    Dependency dependency = new Dependency(new DefaultArtifact("${project.groupId}", "motech-osgi-platform", "", "jar", "${project.version}"), JavaScopes.RUNTIME);
    try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("pom/pom.xml")) {
        pomInformation = new PomInformation();
        pomInformation.parsePom(inputStream);
    }
    assertEquals(properties, pomInformation.getProperties());
    Parent parentFromParsing = pomInformation.getParent();
    assertEquals("0.27-SNAPSHOT", parentFromParsing.getVersion());
    assertEquals("motech", parentFromParsing.getArtifactId());
    assertEquals("org.motechproject", parentFromParsing.getGroupId());
    assertTrue(pomInformation.getDependencies().contains(dependency));
}
Also used : Parent(org.apache.maven.model.Parent) InputStream(java.io.InputStream) Dependency(org.sonatype.aether.graph.Dependency) Properties(java.util.Properties) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) Test(org.junit.Test)

Example 19 with Parent

use of org.apache.maven.model.Parent in project CzechIdMng by bcvsolutions.

the class MavenManager method getVersion.

/**
 * Get model (~ module) version.
 *
 * @param model maven model
 * @return version
 * @since 10.7.0
 */
public String getVersion(Model model) {
    Parent parent = model.getParent();
    String version = model.getVersion();
    // module defined
    if (StringUtils.isNotEmpty(version)) {
        return version;
    }
    // try from parent
    if (parent == null) {
        return null;
    }
    // 
    return parent.getVersion();
}
Also used : Parent(org.apache.maven.model.Parent)

Example 20 with Parent

use of org.apache.maven.model.Parent in project tesb-studio-se by Talend.

the class CreateMavenBundlePom method create.

/*
     * (non-Javadoc)
     *
     * @see org.talend.designer.maven.tools.creator.CreateMavenBundleTemplatePom#create(org.eclipse.core.runtime.
     * IProgressMonitor)
     */
@Override
public void create(IProgressMonitor monitor) throws Exception {
    IFile curPomFile = getPomFile();
    if (curPomFile == null) {
        return;
    }
    bundleModel = createModel();
    // patch for TESB-23953: find "tdm-lib-di-" and remove in route, only keep 'tdm-camel'
    boolean containsTdmCamelDependency = false;
    Dependency tdmDIDependency = null;
    Dependency logbackClassicDependency = null;
    Dependency logbackCoreDependency = null;
    List<Dependency> dependencies = bundleModel.getDependencies();
    for (int i = 0; i < dependencies.size(); i++) {
        String artifactId = dependencies.get(i).getArtifactId();
        if (artifactId.startsWith("tdm-lib-di-")) {
            tdmDIDependency = dependencies.get(i);
        }
        if (artifactId.startsWith("tdm-camel-")) {
            containsTdmCamelDependency = true;
        }
        if (artifactId.equals("logback-classic")) {
            logbackClassicDependency = dependencies.get(i);
        }
        if (artifactId.equals("logback-core")) {
            logbackCoreDependency = dependencies.get(i);
        }
    }
    if (containsTdmCamelDependency && tdmDIDependency != null) {
        bundleModel.getDependencies().remove(tdmDIDependency);
    }
    if (logbackClassicDependency != null) {
        bundleModel.getDependencies().remove(logbackClassicDependency);
    }
    if (logbackCoreDependency != null) {
        bundleModel.getDependencies().remove(logbackCoreDependency);
    }
    IContainer parent = curPomFile.getParent();
    Model pom = new Model();
    boolean route = "CAMEL".equals(getJobProcessor().getProcess().getComponentsType()) && ERepositoryObjectType.getType(getJobProcessor().getProperty()).equals(ERepositoryObjectType.PROCESS_ROUTE);
    Parent parentPom = new Parent();
    parentPom.setGroupId(bundleModel.getGroupId());
    parentPom.setArtifactId(bundleModel.getArtifactId() + "-Kar");
    parentPom.setVersion(bundleModel.getVersion());
    parentPom.setRelativePath("/");
    if (route) {
        RouteProcess routeProcess = (RouteProcess) getJobProcessor().getProcess();
        boolean publishAsSnapshot = BooleanUtils.toBoolean((String) routeProcess.getAdditionalProperties().get(MavenConstants.NAME_PUBLISH_AS_SNAPSHOT));
        File featurePom = new File(parent.getLocation().toOSString() + File.separator + "pom-feature.xml");
        Model featureModel = new Model();
        featureModel.setModelVersion("4.0.0");
        featureModel.setParent(parentPom);
        featureModel.setGroupId(bundleModel.getGroupId());
        featureModel.setArtifactId(bundleModel.getArtifactId() + "-feature");
        featureModel.setName(bundleModel.getName() + " Feature");
        featureModel.setVersion(bundleModel.getVersion());
        featureModel.setPackaging("pom");
        featureModel.setProperties(bundleModel.getProperties());
        featureModel.addProperty("cloud.publisher.skip", "false");
        Build featureModelBuild = new Build();
        featureModelBuild.addPlugin(addFeaturesMavenPlugin(bundleModel.getProperties().getProperty("talend.job.finalName")));
        featureModelBuild.addPlugin(addOsgiHelperMavenPlugin());
        // featureModelBuild.addPlugin(addDeployFeatureMavenPlugin(featureModel.getArtifactId(), featureModel.getVersion(), publishAsSnapshot));
        // featureModelBuild.addPlugin(addSkipDeployFeatureMavenPlugin());
        featureModelBuild.addPlugin(addSkipMavenCleanPlugin());
        featureModelBuild.addPlugin(addSkipDockerMavenPlugin());
        featureModel.setBuild(featureModelBuild);
        // featureModel.addProfile(addProfileForNexus(publishAsSnapshot, featureModel));
        PomUtil.savePom(monitor, featureModel, featurePom);
    }
    pom.setModelVersion("4.0.0");
    pom.setParent(bundleModel.getParent());
    pom.setGroupId(bundleModel.getGroupId());
    pom.setArtifactId(bundleModel.getArtifactId() + "-Kar");
    pom.setName(bundleModel.getName() + " Kar");
    pom.setVersion(bundleModel.getVersion());
    pom.setPackaging("pom");
    pom.addModule("pom-bundle.xml");
    if (route) {
        pom.addModule("pom-feature.xml");
    }
    pom.setDependencies(bundleModel.getDependencies());
    if (pom.getBuild() == null) {
        pom.setBuild(new Build());
    }
    pom.addProfile(addProfileForCloud());
    File pomBundle = new File(parent.getLocation().toOSString() + File.separator + "pom-bundle.xml");
    bundleModel.addProperty(JOB_FINAL_NAME, "${talend.job.name}-${project.version}");
    bundleModel.addProperty("cloud.publisher.skip", "true");
    bundleModel.setParent(parentPom);
    bundleModel.setName(bundleModel.getName() + " Bundle");
    if (bundleModel.getBuild() == null) {
        bundleModel.setBuild(new Build());
    }
    bundleModel.getBuild().addPlugin(addSkipDockerMavenPlugin());
    updateBundleMainfest(bundleModel);
    PomUtil.savePom(monitor, bundleModel, pomBundle);
    PomUtil.savePom(monitor, pom, curPomFile);
    parent.refreshLocal(IResource.DEPTH_ONE, monitor);
    afterCreate(monitor);
}
Also used : IFile(org.eclipse.core.resources.IFile) Parent(org.apache.maven.model.Parent) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) RouteProcess(org.talend.camel.designer.ui.editor.RouteProcess) Dependency(org.apache.maven.model.Dependency) IContainer(org.eclipse.core.resources.IContainer) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

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