Package org.apache.maven.bootstrap.model

Examples of org.apache.maven.bootstrap.model.Repository


            repositories.addAll( ( (Model) i.next() ).getRepositories() );
        }

        for ( Iterator i = repositories.iterator(); i.hasNext(); )
        {
            Repository remoteRepo = (Repository) i.next();

            boolean snapshot = isSnapshot( dep );
            if ( snapshot && !remoteRepo.isSnapshots() )
            {
                continue;
            }
            if ( !snapshot && !remoteRepo.isReleases() )
            {
                continue;
            }

            // The username and password parameters are not being used here.
            String url = remoteRepo.getBasedir() + "/" + remoteRepo.getArtifactPath( dep );

            // Attempt to retrieve the artifact and set the checksum if retrieval
            // of the checksum file was successful.
            try
            {
                String version = dep.getVersion();
                if ( snapshot )
                {
                    String filename = "maven-metadata-" + remoteRepo.getId() + ".xml";
                    File localFile = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
                                                                           dep.getVersion(), dep.getType(),
                                                                           "maven-metadata-local.xml" );
                    File remoteFile = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
                                                                            dep.getVersion(), dep.getType(), filename );
                    String metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
                                                                      dep.getVersion(), dep.getType(),
                                                                      "maven-metadata.xml" );
                    String metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
                    log( "Downloading " + metaUrl );
                    try
                    {
                        HttpUtils.getFile( metaUrl, remoteFile, ignoreErrors, true, proxyHost, proxyPort, proxyUserName,
                                           proxyPassword, false );
                    }
                    catch ( IOException e )
                    {
                        log( "WARNING: remote metadata version not found, using local: " + e.getMessage() );
                        remoteFile.delete();
                    }

                    File file = localFile;
                    if ( remoteFile.exists() )
                    {
                        if ( !localFile.exists() )
                        {
                            file = remoteFile;
                        }
                        else
                        {
                            RepositoryMetadata localMetadata = RepositoryMetadata.read( localFile );

                            RepositoryMetadata remoteMetadata = RepositoryMetadata.read( remoteFile );

                            if ( remoteMetadata.getLastUpdatedUtc() > localMetadata.getLastUpdatedUtc() )
                            {
                                file = remoteFile;
                            }
                            else
                            {
                                file = localFile;
                            }
                        }
                    }

                    if ( file.exists() )
                    {
                        log( "Using metadata: " + file );

                        RepositoryMetadata metadata = RepositoryMetadata.read( file );

                        if ( !file.equals( localFile ) )
                        {
                            version = metadata.constructVersion( version );
                        }
                        log( "Resolved version: " + version );
                        dep.setResolvedVersion( version );
                        if ( !version.endsWith( "SNAPSHOT" ) )
                        {
                            String ver =
                                version.substring( version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 );
                            String extension = url.substring( url.length() - 4 );
                            url = getSnapshotMetadataFile( url, ver + extension );
                        }
                        else if ( destinationFile.exists() )
                        {
                            // It's already there
                            return true;
                        }
                    }
                }
                if ( !"pom".equals( dep.getType() ) )
                {
                    String name = dep.getArtifactId() + "-" + dep.getResolvedVersion() + ".pom";
                    File file = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
                                                                      dep.getVersion(), dep.getType(), name );

                    file.getParentFile().mkdirs();

                    if ( !file.exists() || version.indexOf( "SNAPSHOT" ) >= 0 )
                    {
                        String filename = dep.getArtifactId() + "-" + version + ".pom";
                        String metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
                                                                          dep.getVersion(), dep.getType(), filename );
                        String metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
                        log( "Downloading " + metaUrl );

                        try
                        {
                            HttpUtils.getFile( metaUrl, file, ignoreErrors, false, proxyHost, proxyPort, proxyUserName,
View Full Code Here


        }

        if ( remoteRepositories.isEmpty() )
        {
            // TODO: use super POM?
            remoteRepositories.add( new Repository( "central", REPO_URL, Repository.LAYOUT_DEFAULT, false, true ) );
            // TODO: use maven root POM?
            remoteRepositories.add( new Repository( "apache.snapshots", "http://people.apache.org/repo/m2-snapshot-repository/",
                                                    Repository.LAYOUT_DEFAULT, true, false ) );
        }

        return remoteRepositories;
    }
View Full Code Here

        String groupId = model.getGroupId();

        String type = model.getPackaging();

        Repository localRepository = resolver.getLocalRepository();
        File file = localRepository.getArtifactFile(
            new Dependency( groupId, artifactId, version, type, Collections.EMPTY_LIST ) );

        System.out.println( "Installing: " + file );

        FileUtils.copyFile( jar, file );

        installPomFile( model, pom );

        RepositoryMetadata metadata = new RepositoryMetadata();
        metadata.setReleaseVersion( version );
        metadata.setLatestVersion( version );
        file = localRepository.getMetadataFile( groupId, artifactId, null, type, "maven-metadata-local.xml" );
        metadata.write( file );

        metadata = new RepositoryMetadata();
        metadata.setLocalCopy( true );
        metadata.setLastUpdated( getCurrentUtcDate() );
        file = localRepository.getMetadataFile( groupId, artifactId, version, type, "maven-metadata-local.xml" );
        metadata.write( file );
    }
View Full Code Here

        String version = model.getVersion();

        String groupId = model.getGroupId();

        Repository localRepository = resolver.getLocalRepository();
        File pom = localRepository.getMetadataFile( groupId, artifactId, version, model.getPackaging(),
                                                    artifactId + "-" + version + ".pom" );

        System.out.println( "Installing POM: " + pom );

        FileUtils.copyFile( source, pom );
View Full Code Here

        if ( onlineProperty != null && onlineProperty.equals( "false" ) )
        {
            online = false;
        }

        Repository localRepository =
            new Repository( "local", settings.getLocalRepository(), Repository.LAYOUT_DEFAULT, false, false );

        File repoLocalFile = new File( localRepository.getBasedir() );
        repoLocalFile.mkdirs();

        if ( !repoLocalFile.canWrite() )
        {
            throw new Exception( "Can't write to " + repoLocalFile );
        }

        ArtifactResolver resolver;
        if ( online )
        {
            OnlineArtifactDownloader downloader = new OnlineArtifactDownloader( localRepository );
            resolver = downloader;
            if ( settings.getActiveProxy() != null )
            {
                Proxy proxy = settings.getActiveProxy();
                downloader.setProxy( proxy.getHost(), proxy.getPort(), proxy.getUserName(), proxy.getPassword() );
            }

            List remoteRepos = downloader.getRemoteRepositories();
            List newRemoteRepos = new ArrayList();

            for ( Iterator i = remoteRepos.iterator(); i.hasNext(); )
            {
                Repository repo = (Repository) i.next();

                boolean foundMirror = false;
                for ( Iterator j = settings.getMirrors().iterator(); j.hasNext() && !foundMirror; )
                {
                    Mirror m = (Mirror) j.next();
                    if ( m.getMirrorOf().equals( repo.getId() ) )
                    {
                        newRemoteRepos.add( new Repository( m.getId(), m.getUrl(), repo.getLayout(), repo.isSnapshots(),
                                                            repo.isReleases() ) );
                        foundMirror = true;
                    }
                }
                if ( !foundMirror )
                {
View Full Code Here

        String groupId = model.getGroupId();

        String type = model.getPackaging();

        Repository localRepository = resolver.getLocalRepository();
        File file = localRepository.getArtifactFile(
            new Dependency( groupId, artifactId, version, type, Collections.EMPTY_LIST ) );

        System.out.println( "Installing: " + file );

        FileUtils.copyFile( jar, file );

        installPomFile( model, pom );

        RepositoryMetadata metadata = new RepositoryMetadata();
        metadata.setReleaseVersion( version );
        metadata.setLatestVersion( version );
        file = localRepository.getMetadataFile( groupId, artifactId, null, type, "maven-metadata-local.xml" );
        metadata.write( file );

        metadata = new RepositoryMetadata();
        metadata.setLocalCopy( true );
        metadata.setLastUpdated( getCurrentUtcDate() );
        file = localRepository.getMetadataFile( groupId, artifactId, version, type, "maven-metadata-local.xml" );
        metadata.write( file );
    }
View Full Code Here

        String version = model.getVersion();

        String groupId = model.getGroupId();

        Repository localRepository = resolver.getLocalRepository();
        File pom = localRepository.getMetadataFile( groupId, artifactId, version, model.getPackaging(),
                                                    artifactId + "-" + version + ".pom" );

        System.out.println( "Installing POM: " + pom );

        FileUtils.copyFile( source, pom );
View Full Code Here

        if ( onlineProperty != null && onlineProperty.equals( "false" ) )
        {
            online = false;
        }

        Repository localRepository =
            new Repository( "local", settings.getLocalRepository(), Repository.LAYOUT_DEFAULT, false, false );

        File repoLocalFile = new File( localRepository.getBasedir() );
        repoLocalFile.mkdirs();

        if ( !repoLocalFile.canWrite() )
        {
            throw new Exception( "Can't write to " + repoLocalFile );
        }

        ArtifactResolver resolver;
        if ( online )
        {
            OnlineArtifactDownloader downloader = new OnlineArtifactDownloader( localRepository );
            resolver = downloader;
            if ( settings.getActiveProxy() != null )
            {
                Proxy proxy = settings.getActiveProxy();
                downloader.setProxy( proxy.getHost(), proxy.getPort(), proxy.getUserName(), proxy.getPassword() );
            }

            List remoteRepos = downloader.getRemoteRepositories();
            List newRemoteRepos = new ArrayList();

            for ( Iterator i = remoteRepos.iterator(); i.hasNext(); )
            {
                Repository repo = (Repository) i.next();

                boolean foundMirror = false;
                for ( Iterator j = settings.getMirrors().iterator(); j.hasNext() && !foundMirror; )
                {
                    Mirror m = (Mirror) j.next();
                    if ( m.getMirrorOf().equals( repo.getId() ) )
                    {
                        newRemoteRepos.add( new Repository( m.getId(), m.getUrl(), repo.getLayout(), repo.isSnapshots(),
                                                            repo.isReleases() ) );
                        foundMirror = true;
                    }
                }
                if ( !foundMirror )
                {
View Full Code Here

    String artifactId = model.getArtifactId();
    String version = model.getVersion();
    String groupId = model.getGroupId();
    String type = model.getPackaging();

    Repository localRepository = resolver.getLocalRepository();

    File file =
      localRepository.getArtifactFile(new Dependency(groupId, artifactId, version, type, Collections.EMPTY_LIST));

    if (!type.equalsIgnoreCase("pom")) {
      copyFile(jar, file);
    }

    installPomFile(model, pom);

    RepositoryMetadata metadata = new RepositoryMetadata();
    metadata.setReleaseVersion(version);
    metadata.setLatestVersion(version);
    file = localRepository.getMetadataFile(groupId, artifactId, null, type, "maven-metadata-local.xml");
    metadata.write(file);

    metadata = new RepositoryMetadata();
    metadata.setLocalCopy(true);
    metadata.setLastUpdated(getCurrentUtcDate());
    file = localRepository.getMetadataFile(groupId, artifactId, version, type, "maven-metadata-local.xml");
    metadata.write(file);
  }
View Full Code Here

  private void installPomFile(Model model, File source) throws IOException {
    String artifactId = model.getArtifactId();
    String version = model.getVersion();
    String groupId = model.getGroupId();

    Repository localRepository = resolver.getLocalRepository();

    File pom = localRepository.getMetadataFile(groupId, artifactId, version, model.getPackaging(),
            artifactId + "-" + version + ".pom");

    copyFile(source, pom);
  }
View Full Code Here

TOP

Related Classes of org.apache.maven.bootstrap.model.Repository

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.