Examples of MavenProject


Examples of org.apache.maven.project.MavenProject

    private void addDependency(
        final Dependency dependency,
        final String scope)
    {
        final ArtifactRepository localRepository = this.getLocalRepository();
        final MavenProject project = this.getProject();
        if (project != null && localRepository != null)
        {
            if (dependency != null)
            {
                final Artifact artifact =
                    this.getFactory().createArtifact(
                        dependency.getGroupId(),
                        dependency.getArtifactId(),
                        dependency.getVersion(),
                        scope,
                        dependency.getType());
                final File file = new File(
                        localRepository.getBasedir(),
                        localRepository.pathOf(artifact));
                artifact.setFile(file);
                project.getDependencies().add(dependency);
                project.getArtifacts().add(artifact);
            }
        }
    }
View Full Code Here

Examples of org.apache.maven.project.MavenProject

            {
                projects.add(this.getRootProject());
                final Set artifacts = new LinkedHashSet();
                for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
                {
                    final MavenProject project = (MavenProject)iterator.next();
                    final Artifact artifact =
                        this.artifactFactory.createArtifact(
                            project.getGroupId(),
                            project.getArtifactId(),
                            project.getVersion(),
                            null,
                            project.getPackaging());
                    final String artifactPath = this.localRepository.pathOf(artifact);
                    final String artifactFileName = artifactPath.replaceAll(
                            ".*(\\\\|/+)",
                            "");
                    final String repositoryDirectoryPath =
                        artifactPath.substring(
                            0,
                            artifactPath.indexOf(artifactFileName));
                    final Build build = project.getBuild();
                    final File workDirectory = new File(build.getDirectory());
                    final File distributionDirectory =
                        new File(new File(
                                directory,
                                this.artifactDirectory), repositoryDirectoryPath);
                    if (workDirectory.exists())
                    {
                        final String finalName = build.getFinalName();
                        final String[] names = workDirectory.list();
                        if (names != null)
                        {
                            final int numberOfArtifacts = names.length;
                            for (int ctr = 0; ctr < numberOfArtifacts; ctr++)
                            {
                                final String name = names[ctr];
                                if (name.indexOf(finalName) != -1 && !name.equals(finalName))
                                {
                                    final File distributionFile = new File(distributionDirectory, name);
                                    this.bundleFile(
                                        artifact,
                                        new File(
                                            workDirectory,
                                            name),
                                        distributionFile);
                                }
                            }
                        }
                    }
                    else
                    {
                        this.artifactResolver.resolve(
                            artifact,
                            this.project.getRemoteArtifactRepositories(),
                            this.localRepository);
                    }

                    // - bundle the POM
                    final File repositoryPom =
                        this.constructPom(
                            new File(
                                this.localRepository.getBasedir(),
                                repositoryDirectoryPath),
                            artifact);
                    final File distributionPom = this.constructPom(
                            distributionDirectory,
                            artifact);
                    this.bundleFile(
                        artifact,
                        repositoryPom,
                        distributionPom);
                    artifacts.addAll(project.createArtifacts(
                            artifactFactory,
                            null,
                            null));
                }

                final ArtifactResolutionResult result =
                    this.artifactResolver.resolveTransitively(
                        artifacts,
                        this.project.getArtifact(),
                        this.project.getRemoteArtifactRepositories(),
                        this.localRepository,
                        this.artifactMetadataSource);

                artifacts.addAll(result.getArtifacts());

                // - remove the project artifacts
                for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
                {
                    final MavenProject project = (MavenProject)iterator.next();
                    final Artifact projectArtifact = project.getArtifact();
                    if (projectArtifact != null)
                    {
                        for (final Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();)
                        {
                            final Artifact artifact = (Artifact)artifactIterator.next();
View Full Code Here

Examples of org.apache.maven.project.MavenProject

    private MavenProject getRootProject()
        throws MojoExecutionException
    {
        if (this.rootProject == null)
        {
            final MavenProject firstParent = this.project.getParent();
            File rootFile = this.project.getFile();
            if (firstParent != null)
            {
                for (this.rootProject = firstParent, rootFile = new File(rootFile.getParentFile().getParentFile(), POM_FILE);
                     this.rootProject.getParent() != null;
View Full Code Here

Examples of org.apache.maven.project.MavenProject

     */
    private MavenProject getProject(final File pom)
        throws MojoExecutionException
    {
        // - first attempt to get the existing project from the session
        MavenProject project = this.getProjectFromSession(pom);
        if (project == null)
        {
            // - if we didn't find it in the session, create it
            try
            {
                project =
                    this.projectBuilder.build(
                        pom,
                        this.session.getLocalRepository(),
                        new DefaultProfileManager(this.session.getContainer()));
            }
            catch (Exception exception)
            {
                try
                {
                    // - if we failed, try to build from the repository
                    project =
                        this.projectBuilder.buildFromRepository(
                            this.buildArtifact(pom),
                            this.project.getRemoteArtifactRepositories(),
                            this.localRepository);
                }
                catch (final Throwable throwable)
                {
                    throw new MojoExecutionException("Project could not be built from pom file " + pom, exception);
                }
            }
        }
        if (this.getLog().isDebugEnabled())
        {
            this.getLog().debug("Processing project " + project.getId());
        }
        return project;
    }
View Full Code Here

Examples of org.apache.maven.project.MavenProject

     * @param pom the POM to find.
     * @return the maven project with the matching POM.
     */
    private MavenProject getProjectFromSession(final File pom)
    {
        MavenProject foundProject = null;
        for (final Iterator projectIterator = this.session.getSortedProjects().iterator(); projectIterator.hasNext();)
        {
            final MavenProject project = (MavenProject)projectIterator.next();
            final File projectPom = new File(
                    project.getBasedir(),
                    POM_FILE);
            if (projectPom.equals(pom))
            {
                foundProject = project;
            }
View Full Code Here

Examples of org.apache.maven.project.MavenProject

        final Set projects = new LinkedHashSet();
        final List poms = this.getPoms();
        for (ListIterator iterator = poms.listIterator(); iterator.hasNext();)
        {
            final File pom = (File)iterator.next();
            final MavenProject project = this.getProject(pom);
            if (project != null)
            {
                projects.add(project);
            }
        }
View Full Code Here

Examples of org.apache.maven.project.MavenProject

        writer.startElement("classpath");

        final Set projectArtifactIds = new LinkedHashSet();
        for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
        {
            final MavenProject project = (MavenProject)iterator.next();
            final Artifact projectArtifact =
                artifactFactory.createArtifact(
                    project.getGroupId(),
                    project.getArtifactId(),
                    project.getVersion(),
                    null,
                    project.getPackaging());
            projectArtifactIds.add(projectArtifact.getId());
        }

        // - write the source roots for the root project (if they are any)
        this.writeSourceRoots(this.project, rootDirectory, writer);

        final Set allArtifacts = new LinkedHashSet(this.project.createArtifacts(
            artifactFactory,
            null,
            null));
        for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
        {
            final MavenProject project = (MavenProject)iterator.next();
            this.writeSourceRoots(project, rootDirectory, writer);
            final Set artifacts = project.createArtifacts(
                    artifactFactory,
                    null,
                    null);

            // - get the direct dependencies
            for (final Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();)
            {
                final Artifact artifact = (Artifact)artifactIterator.next();

                // - don't attempt to resolve the artifact if its part of the project (we
                //   infer this if it has the same id has one of the projects or is in
                //   the same groupId).
                if (!projectArtifactIds.contains(artifact.getId()) &&
                    !project.getGroupId().equals(artifact.getGroupId()))
                {
                    artifactResolver.resolve(
                        artifact,
                        project.getRemoteArtifactRepositories(),
                        localRepository);
                    allArtifacts.add(artifact);
                }
                else
                {
                    allArtifacts.add(artifact);
                }
            }
        }

        // - remove the project artifacts
        for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
        {
            final MavenProject project = (MavenProject)iterator.next();
            final Artifact projectArtifact = project.getArtifact();
            if (projectArtifact != null)
            {
                for (final Iterator artifactIterator = allArtifacts.iterator(); artifactIterator.hasNext();)
                {
                    final Artifact artifact = (Artifact)artifactIterator.next();
View Full Code Here

Examples of org.apache.maven.project.MavenProject

        if (synapseCore == null) {
            throw new MojoExecutionException("Could not locate dependency on synapse-core");
        }
       
        log.debug("Loading project data for " + synapseCore + " ...");
        MavenProject synapseCoreProject;
        try {
            synapseCoreProject = projectBuilder.buildFromRepository(synapseCore,
                    remoteArtifactRepositories, localRepository);
        } catch (ProjectBuildingException e) {
            throw new MojoExecutionException("Unable to retrieve project information for "
                    + synapseCore, e);
        }
        Set<Artifact> synapseRuntimeDeps;
        try {
            synapseRuntimeDeps = synapseCoreProject.createArtifacts(artifactFactory,
                    Artifact.SCOPE_RUNTIME, new TypeArtifactFilter("jar"));
        } catch (InvalidDependencyVersionException e) {
            throw new MojoExecutionException("Unable to get project dependencies for "
                    + synapseCore, e);
        }
        log.debug("Direct runtime dependencies for " + synapseCore + " :");
        logArtifacts(synapseRuntimeDeps);
       
        log.debug("Resolving transitive dependencies for " + synapseCore + " ...");
        try {
            synapseRuntimeDeps = artifactCollector.collect(synapseRuntimeDeps,
                    synapseCoreProject.getArtifact(), synapseCoreProject.getManagedVersionMap(),
                    localRepository, remoteArtifactRepositories, artifactMetadataSource, null,
                    Collections.singletonList(new DebugResolutionListener(logger))).getArtifacts();
        } catch (ArtifactResolutionException e) {
            throw new MojoExecutionException("Unable to resolve transitive dependencies for "
                    + synapseCore);
View Full Code Here

Examples of org.apache.maven.project.MavenProject

        // We have no POM file.
        //
        if ( request.getPom() == null )
        {
            ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) );
            MavenProject project =
                projectBuilder.build( modelSource, request.getProjectBuildingRequest() ).getProject();
            project.setExecutionRoot( true );
            projects.add( project );
            request.setProjectPresent( false );
            return projects;
        }
       
View Full Code Here

Examples of org.apache.maven.project.MavenProject

        for ( MavenProject project : projects )
        {
            String projectId = ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() );

            MavenProject collision = index.get( projectId );

            if ( collision == null )
            {
                index.put( projectId, project );
            }
            else
            {
                List<File> pomFiles = collisions.get( projectId );

                if ( pomFiles == null )
                {
                    pomFiles = new ArrayList<File>( Arrays.asList( collision.getFile(), project.getFile() ) );
                    collisions.put( projectId, pomFiles );
                }
                else
                {
                    pomFiles.add( project.getFile() );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.