Package org.apache.maven.model

Examples of org.apache.maven.model.Parent


                     description = "absolute location of a project to use as this project's direct parent",
                     required = false) final Resource<?> path,
            final PipeOut out)
   {
      MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);
      Parent parent = null;
      if (gav != null)
      {
         Assert.notNull(gav.getArtifactId(), "ArtifactId must not be null [" + gav.toCoordinates() + "]");
         Assert.notNull(gav.getGroupId(), "GroupId must not be null [" + gav.toCoordinates() + "]");
         Assert.notNull(gav.getVersion(), "Version must not be null [" + gav.toCoordinates() + "]");

         parent = new Parent();
         parent.setArtifactId(gav.getArtifactId());
         parent.setGroupId(gav.getGroupId());
         parent.setVersion(gav.getVersion());

         if (relativePath != null)
         {
            parent.setRelativePath(relativePath);
         }

         Model pom = mvn.getPOM();
         pom.setParent(parent);
         mvn.setPOM(pom);
      }
      else if ((path != null) && factory.containsProject(path.reify(DirectoryResource.class)))
      {
         Project parentProject = factory.findProject(path.reify(DirectoryResource.class));
         MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);

         parent = new Parent();
         parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
         parent.setGroupId(parentCore.getMavenProject().getGroupId());
         parent.setVersion(parentCore.getMavenProject().getVersion());

         if (relativePath != null)
         {
            parent.setRelativePath(relativePath);
         }

         Model pom = mvn.getPOM();
         pom.setParent(parent);
         mvn.setPOM(pom);
      }
      else if (relativePath != null)
      {
         PathspecParser parser = new PathspecParser(resources, shell.getCurrentProject().getProjectRoot(), relativePath);
         List<Resource<?>> resolvedResources = parser.resolve();
         if (!resolvedResources.isEmpty()
                  && factory.containsProject(resolvedResources.get(0).reify(DirectoryResource.class)))
         {
            Project parentProject = factory.findProject(resolvedResources.get(0).reify(DirectoryResource.class));
            MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);

            parent = new Parent();
            parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
            parent.setGroupId(parentCore.getMavenProject().getGroupId());
            parent.setVersion(parentCore.getMavenProject().getVersion());
            parent.setRelativePath(relativePath);

            Model pom = mvn.getPOM();
            pom.setParent(parent);
            mvn.setPOM(pom);
         }
         else
         {
            out.print(ShellColor.RED, "***ERROR***");
            out.println(" relative path did not resolve to a Project [" + relativePath + "]");
         }
      }
      else
      {
         out.print(ShellColor.RED, "***ERROR***");
         out.println(" you must specify a path to or dependency id of the parent project.");
      }

      if (parent != null)
      {
         String parentId = parent.getGroupId() + ":" + parent.getArtifactId() + ":"
                  + parent.getVersion() + " ("
                  + (parent.getRelativePath() == null ? " " : parent.getRelativePath() + ")");

         out.println("Set parent [ " + parentId + " ]");
      }
   }
View Full Code Here


   public void removeParent(final PipeOut out)
   {
      MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);

      Model pom = mvn.getPOM();
      Parent parent = pom.getParent();

      if (parent != null)
      {
         String parentId = parent.getGroupId() + ":" + parent.getArtifactId() + ":"
                  + parent.getVersion() + " ("
                  + (parent.getRelativePath() == null ? " " : parent.getRelativePath() + ")");

         if (shell.promptBoolean("Are you sure you want to remove all parent information from this project? [ "
                  + parentId + "]", false))
         {
            out.println("Removed parent [ " + parentId + " ]");
View Full Code Here

     *
     * @param model The POM to extract missing artifact coordinates from, must not be <code>null</code>.
     */
    private void processModel( Model model )
    {
        Parent parent = model.getParent();

        if ( this.groupId == null )
        {
            this.groupId = model.getGroupId();
            if ( this.groupId == null && parent != null )
            {
                this.groupId = parent.getGroupId();
            }
        }
        if ( this.artifactId == null )
        {
            this.artifactId = model.getArtifactId();
        }
        if ( this.version == null )
        {
            this.version = model.getVersion();
            if ( this.version == null && parent != null )
            {
                this.version = parent.getVersion();
            }
        }
        if ( this.packaging == null )
        {
            this.packaging = model.getPackaging();
View Full Code Here

        if ( version == null && candidateModel.getParent() != null )
        {
            version = candidateModel.getParent().getVersion();
        }

        Parent parent = childModel.getParent();

        if ( groupId == null || !groupId.equals( parent.getGroupId() ) || artifactId == null
            || !artifactId.equals( parent.getArtifactId() ) )
        {
            StringBuilder buffer = new StringBuilder( 256 );
            buffer.append( "'parent.relativePath'" );
            if ( childModel != problems.getRootModel() )
            {
                buffer.append( " of POM " ).append( ModelProblemUtils.toSourceHint( childModel ) );
            }
            buffer.append( " points at " ).append( groupId ).append( ":" ).append( artifactId );
            buffer.append( " instead of " ).append( parent.getGroupId() ).append( ":" ).append( parent.getArtifactId() );
            buffer.append( ", please verify your project structure" );

            problems.setSource( childModel );
            problems.add( Severity.WARNING, buffer.toString(), parent.getLocation( "" ), null );
            return null;
        }
        if ( version == null || !version.equals( parent.getVersion() ) )
        {
            return null;
        }

        ModelData parentData = new ModelData( candidateModel, groupId, artifactId, version );
View Full Code Here

                                            DefaultModelProblemCollector problems )
        throws ModelBuildingException
    {
        problems.setSource( childModel );

        Parent parent = childModel.getParent();

        String groupId = parent.getGroupId();
        String artifactId = parent.getArtifactId();
        String version = parent.getVersion();

        ModelResolver modelResolver = request.getModelResolver();

        if ( modelResolver == null )
        {
            throw new IllegalArgumentException( "no model resolver provided, cannot resolve parent POM "
                + ModelProblemUtils.toId( groupId, artifactId, version ) + " for POM "
                + ModelProblemUtils.toSourceHint( childModel ) );
        }

        ModelSource modelSource;
        try
        {
            modelSource = modelResolver.resolveModel( groupId, artifactId, version );
        }
        catch ( UnresolvableModelException e )
        {
            StringBuilder buffer = new StringBuilder( 256 );
            buffer.append( "Non-resolvable parent POM" );
            if ( !containsCoordinates( e.getMessage(), groupId, artifactId, version ) )
            {
                buffer.append( " " ).append( ModelProblemUtils.toId( groupId, artifactId, version ) );
            }
            if ( childModel != problems.getRootModel() )
            {
                buffer.append( " for " ).append( ModelProblemUtils.toId( childModel ) );
            }
            buffer.append( ": " ).append( e.getMessage() );
            if ( childModel.getProjectDirectory() != null )
            {
                if ( parent.getRelativePath() == null || parent.getRelativePath().length() <= 0 )
                {
                    buffer.append( " and 'parent.relativePath' points at no local POM" );
                }
                else
                {
                    buffer.append( " and 'parent.relativePath' points at wrong local POM" );
                }
            }

            problems.add( Severity.FATAL, buffer.toString(), parent.getLocation( "" ), e );
            throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
                                              problems.getProblems() );
        }

        ModelBuildingRequest lenientRequest = request;
        if ( request.getValidationLevel() > ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
        {
            lenientRequest = new FilterModelBuildingRequest( request )
            {
                @Override
                public int getValidationLevel()
                {
                    return ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0;
                }
            };
        }

        Model parentModel = readModel( modelSource, null, lenientRequest, problems );

        ModelData parentData =
            new ModelData( parentModel, parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );

        return parentData;
    }
View Full Code Here

    public Artifact getParentArtifact()
    {
        if ( parentArtifact == null && model.getParent() != null )
        {
            Parent p = model.getParent();
            parentArtifact = repositorySystem.createProjectArtifact( p.getGroupId(), p.getArtifactId(), p.getVersion() );
        }
        return parentArtifact;
    }
View Full Code Here

                                  DefaultModelProblemCollector problems )
        throws ModelBuildingException
    {
        ModelData parentData;

        Parent parent = childModel.getParent();

        if ( parent != null )
        {
            String groupId = parent.getGroupId();
            String artifactId = parent.getArtifactId();
            String version = parent.getVersion();

            parentData = getCache( request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW );

            if ( parentData == null )
            {
View Full Code Here

        }

        if ( model.getParent() != null && model.getParent().getRelativePath() != null )
        {
            // resolve parent pom
            Parent parent = model.getParent();
            String groupId = parent.getGroupId();
            String artifactId = parent.getArtifactId();
            String version = parent.getVersion();

            ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
            Artifact parentArtifact = factory.createParentArtifact( groupId, artifactId, version );

            try
            {
                MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
                ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
                List remoteRepositories = createRemoteArtifactRepositories( model.getRepositories() );

                resolver.resolveTransitively( Collections.singleton( parentArtifact ),
                                              createDummyArtifact(), createLocalArtifactRepository(),
                                              remoteRepositories, metadataSource, null );
            }
            catch ( ArtifactResolutionException e )
            {
                // MANTTASKS-87: don't fail if parent pom is not resolved immediately
                log( "Error downloading parent pom " + parent.getId() + ": " + e.getMessage(), Project.MSG_WARN );
            }
            catch ( ArtifactNotFoundException e )
            {
                throw new BuildException( "Unable to download parent pom " + parent.getId() + " in remote repository: " + e.getMessage(), e );
            }
        }
    }
View Full Code Here

        }
    }

    protected void mergeModel_Parent( Model target, Model source, boolean sourceDominant, Map<Object, Object> context )
    {
        Parent src = source.getParent();
        if ( src != null )
        {
            Parent tgt = target.getParent();
            if ( tgt == null )
            {
                tgt = new Parent();
                target.setParent( tgt );
            }
            mergeParent( tgt, src, sourceDominant, context );
        }
    }
View Full Code Here

        {
            result.addMessage( "Packaging '" + model.getPackaging() + "' is invalid. Aggregator projects " +
                    "require 'pom' as packaging." );
        }
       
        Parent parent = model.getParent();
        if ( parent != null )
        {
            if ( parent.getGroupId().equals( model.getGroupId() ) &&
                    parent.getArtifactId().equals( model.getArtifactId() ) )
            {
                result.addMessage( "The parent element cannot have the same ID as the project." );
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.maven.model.Parent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.