Package org.apache.maven.model

Examples of org.apache.maven.model.Model


        return model;
    }

    @Override
    public void onNodeCompleted(FactoryBuilderSupport builder, Object parent, Object node) {
        Model model = (Model)node;
    }
View Full Code Here


        final MavenXpp3Reader reader = new MavenXpp3Reader();

        for (final Iterator iterator = this.getPoms().iterator(); iterator.hasNext();)
        {
            final File pom = (File)iterator.next();
            final Model model = reader.read(new FileReader(pom));
            String groupId = model.getGroupId();
            for (Parent parent = model.getParent(); groupId == null && model.getParent() != null;
                parent = model.getParent())
            {
                groupId = parent.getGroupId();
            }
            String version = model.getVersion();
            for (Parent parent = model.getParent(); version == null && model.getParent() != null;
                parent = model.getParent())
            {
                version = parent.getVersion();
            }
            final Artifact artifact =
                this.artifactFactory.createArtifact(
                    groupId,
                    model.getArtifactId(),
                    version,
                    null,
                    model.getPackaging());
            final File pomParent = pom.getParentFile();
            final String finalName = model.getArtifactId() + "-" + version;
            final File explodedDirectory = new File(pomParent, "target/" + finalName);
            final File artifactFile = new File(explodedDirectory + "." + model.getPackaging());
            if (explodedDirectory.isDirectory() && artifactFile.exists() &&
                !finalName.equals(this.project.getBuild().getFinalName()))
            {
                artifacts.add(artifact);
                artifact.setFile(artifactFile);
View Full Code Here

    private void writeMinimalPom(final File bootstrapPomFile)
        throws MojoExecutionException, IOException
    {
        if (this.project != null)
        {
            Model model = this.project.getModel();
            if (model == null)
            {
                throw new MojoExecutionException("Model could not be retrieved from current project");
            }

            // - remove the parent
            final Parent parent = model.getParent();
            final List dependencies = new ArrayList(model.getDependencies());
            final String groupId = model.getGroupId();
            final Artifact artifact = this.project.getArtifact();
            final Build build = this.project.getBuild();
            final List developers = new ArrayList(model.getDevelopers());
            final List contributors = new ArrayList(model.getContributors());
            model.setGroupId(this.getBootstrapGroupId(artifact));
            model.setParent(null);
            model.setBuild(null);
            model.setDependencies(Collections.EMPTY_LIST);
            model.setDevelopers(Collections.EMPTY_LIST);
            model.setContributors(Collections.EMPTY_LIST);
            final FileWriter fileWriter = new FileWriter(bootstrapPomFile);
            this.project.writeModel(fileWriter);
            fileWriter.flush();

            // - set any removed items back to the way it was since we've written the POM
            model.setParent(parent);
            model.setGroupId(groupId);
            model.setDependencies(dependencies);
            model.setBuild(build);
            model.setDevelopers(developers);
            model.setContributors(contributors);
        }
    }
View Full Code Here

     */
    private Artifact buildArtifact(final File pom)
        throws FileNotFoundException, IOException, XmlPullParserException
    {
        final MavenXpp3Reader reader = new MavenXpp3Reader();
        final Model model = reader.read(new FileReader(pom));
        String groupId = model.getGroupId();
        for (Parent parent = model.getParent(); groupId == null && model.getParent() != null;
            parent = model.getParent())
        {
            groupId = parent.getGroupId();
        }
        String version = model.getVersion();
        for (Parent parent = model.getParent(); version == null && model.getParent() != null;
            parent = model.getParent())
        {
            version = parent.getVersion();
        }
        return this.artifactFactory.createArtifact(
            groupId,
            model.getArtifactId(),
            version,
            null,
            model.getPackaging());
    }
View Full Code Here

{

    public void testShouldInterpretChildPathAdjustmentBasedOnModulePaths()
        throws IOException
    {
        Model parentModel = new Model();
        parentModel.addModule( "../child" );

        MavenProject parentProject = new MavenProject( parentModel );

        Model childModel = new Model();
        childModel.setArtifactId( "artifact" );

        MavenProject childProject = new MavenProject( childModel );
       
        File childFile = new File( System.getProperty( "java.io.tmpdir" ), "maven-project-tests" + System.currentTimeMillis() + "/child/pom.xml" );
View Full Code Here

        parent.setGroupId( "test-group" );
        parent.setVersion( "1000" );
        parent.setArtifactId( "test-artifact" );

        Model model = new Model();

        model.setParent( parent );
        model.setArtifactId( "real-artifact" );

        MavenProject project = new MavenProject( model );

        assertEquals( "groupId proto-inheritance failed.", "test-group", project.getGroupId() );
        assertEquals( "artifactId is masked.", "real-artifact", project.getArtifactId() );
View Full Code Here

    }

    public void testGetModulePathAdjustment()
        throws IOException
    {
        Model moduleModel = new Model();

        MavenProject module = new MavenProject( moduleModel );
        module.setFile( new File( "module-dir/pom.xml" ) );

        Model parentModel = new Model();
        parentModel.addModule( "../module-dir" );

        MavenProject parent = new MavenProject( parentModel );
        parent.setFile( new File( "parent-dir/pom.xml" ) );

        String pathAdjustment = parent.getModulePathAdjustment( module );
View Full Code Here

            }
            profileProps.putAll( profileActivationContext.getUserProperties() );
            profileActivationContext.setUserProperties( profileProps );
        }

        Model inputModel = readModel( request.getModelSource(), request.getPomFile(), request, problems );

        problems.setRootModel( inputModel );

        ModelData resultData = new ModelData( inputModel );
        ModelData superData = new ModelData( getSuperModel() );

        Collection<String> parentIds = new LinkedHashSet<String>();
        parentIds.add( ModelProblemUtils.toId( inputModel ) );

        List<ModelData> lineage = new ArrayList<ModelData>();

        for ( ModelData currentData = resultData; currentData != null; )
        {
            lineage.add( currentData );

            Model tmpModel = currentData.getModel();

            Model rawModel = tmpModel.clone();
            currentData.setRawModel( rawModel );

            problems.setSource( tmpModel );

            modelNormalizer.mergeDuplicates( tmpModel, request, problems );

            List<Profile> activePomProfiles =
                profileSelector.getActiveProfiles( rawModel.getProfiles(), profileActivationContext, problems );
            currentData.setActiveProfiles( activePomProfiles );

            for ( Profile activeProfile : activePomProfiles )
            {
                profileInjector.injectProfile( tmpModel, activeProfile, request, problems );
            }

            if ( currentData == resultData )
            {
                for ( Profile activeProfile : activeExternalProfiles )
                {
                    profileInjector.injectProfile( tmpModel, activeProfile, request, problems );
                }
            }

            if ( currentData == superData )
            {
                break;
            }

            configureResolver( request.getModelResolver(), tmpModel, problems );

            currentData = readParent( tmpModel, request, problems );

            if ( currentData == null )
            {
                currentData = superData;
            }
            else if ( !parentIds.add( currentData.getId() ) )
            {
                String message = "The parents form a cycle: ";
                for ( String modelId : parentIds )
                {
                    message += modelId + " -> ";
                }
                message += currentData.getId();

                problems.add( ModelProblem.Severity.FATAL, message, null, null );
                throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
                                                  problems.getProblems() );
            }
        }

        problems.setSource( inputModel );
        checkPluginVersions( lineage, request, problems );

        assembleInheritance( lineage, request, problems );

        Model resultModel = resultData.getModel();

        problems.setSource( resultModel );
        problems.setRootModel( resultModel );

        resultModel = interpolateModel( resultModel, request, problems );
        resultData.setModel( resultModel );

        modelUrlNormalizer.normalize( resultModel, request );

        resultData.setGroupId( resultModel.getGroupId() );
        resultData.setArtifactId( resultModel.getArtifactId() );
        resultData.setVersion( resultModel.getVersion() );

        result.setProblems( problems.getProblems() );

        result.setEffectiveModel( resultModel );
View Full Code Here

    private ModelBuildingResult build( ModelBuildingRequest request, ModelBuildingResult result,
                                       Collection<String> imports )
        throws ModelBuildingException
    {
        Model resultModel = result.getEffectiveModel();

        DefaultModelProblemCollector problems = new DefaultModelProblemCollector( result.getProblems() );
        problems.setSource( resultModel );
        problems.setRootModel( resultModel );

        modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(), request );

        pluginManagementInjector.injectManagement( resultModel, request, problems );

        fireEvent( resultModel, request, problems, ModelBuildingEventCatapult.BUILD_EXTENSIONS_ASSEMBLED );
View Full Code Here

    private Model readModel( ModelSource modelSource, File pomFile, ModelBuildingRequest request,
                             DefaultModelProblemCollector problems )
        throws ModelBuildingException
    {
        Model model;

        if ( modelSource == null )
        {
            if ( pomFile != null )
            {
                modelSource = new FileModelSource( pomFile );
            }
            else
            {
                throw new IllegalArgumentException( "neither model source nor input file are specified" );
            }
        }

        problems.setSource( modelSource.getLocation() );
        try
        {
            boolean strict = request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0;
            InputSource source = request.isLocationTracking() ? new InputSource() : null;

            Map<String, Object> options = new HashMap<String, Object>();
            options.put( ModelProcessor.IS_STRICT, Boolean.valueOf( strict ) );
            options.put( ModelProcessor.INPUT_SOURCE, source );
            options.put( ModelProcessor.SOURCE, modelSource );

            try
            {
                model = modelProcessor.read( modelSource.getInputStream(), options );
            }
            catch ( ModelParseException e )
            {
                if ( !strict )
                {
                    throw e;
                }

                options.put( ModelProcessor.IS_STRICT, Boolean.FALSE );

                try
                {
                    model = modelProcessor.read( modelSource.getInputStream(), options );
                }
                catch ( ModelParseException ne )
                {
                    // still unreadable even in non-strict mode, rethrow original error
                    throw e;
                }

                if ( pomFile != null )
                {
                    problems.add( Severity.ERROR, "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(),
                                  null, e );
                }
                else
                {
                    problems.add( Severity.WARNING, "Malformed POM " + modelSource.getLocation() + ": "
                        + e.getMessage(), null, e );
                }
            }

            if ( source != null )
            {
                source.setModelId( ModelProblemUtils.toId( model ) );
                source.setLocation( modelSource.getLocation() );
            }
        }
        catch ( ModelParseException e )
        {
            problems.add( Severity.FATAL, "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(),
                          null, e );
            throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
                                              problems.getProblems() );
        }
        catch ( IOException e )
        {
            String msg = e.getMessage();
            if ( msg == null || msg.length() <= 0 )
            {
                // NOTE: There's java.nio.charset.MalformedInputException and sun.io.MalformedInputException
                if ( e.getClass().getName().endsWith( "MalformedInputException" ) )
                {
                    msg = "Some input bytes do not match the file encoding.";
                }
                else
                {
                    msg = e.getClass().getSimpleName();
                }
            }
            problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + msg, null, e );
            throw new ModelBuildingException( problems.getRootModel(), problems.getRootModelId(),
                                              problems.getProblems() );
        }

        model.setPomFile( pomFile );

        problems.setSource( model );
        modelValidator.validateRawModel( model, request, problems );

        if ( problems.hasFatalErrors() )
View Full Code Here

TOP

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

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.