Search in sources :

Example 1 with Repository

use of org.apache.maven.model.Repository in project che by eclipse.

the class MavenModelUtil method convertToMavenRepository.

public static Repository convertToMavenRepository(MavenRemoteRepository repository) {
    Repository result = new Repository();
    result.setId(repository.getId());
    result.setName(repository.getName());
    result.setUrl(repository.getUrl());
    if (repository.getLayout() == null) {
        result.setLayout("default");
    } else {
        result.setLayout(repository.getLayout());
    }
    if (repository.getSnapshotsPolicy() != null) {
        result.setSnapshots(convertToMavenPolicy(repository.getSnapshotsPolicy()));
    }
    if (repository.getReleasesPolicy() != null) {
        result.setReleases(convertToMavenPolicy(repository.getReleasesPolicy()));
    }
    return result;
}
Also used : Repository(org.apache.maven.model.Repository) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository)

Example 2 with Repository

use of org.apache.maven.model.Repository in project bazel by bazelbuild.

the class Resolver method resolveEffectiveModel.

/**
   * Resolves all dependencies from a given "model source," which could be either a URL or a local
   * file.
   * @return the model.
   */
@Nullable
public Model resolveEffectiveModel(ModelSource modelSource, Set<String> exclusions, Rule parent) {
    Model model = modelResolver.getEffectiveModel(modelSource, handler);
    if (model == null) {
        return null;
    }
    for (Repository repo : model.getRepositories()) {
        modelResolver.addRepository(repo);
    }
    for (Dependency dependency : model.getDependencies()) {
        if (!dependency.getScope().equals(COMPILE_SCOPE)) {
            continue;
        }
        if (dependency.isOptional()) {
            continue;
        }
        if (exclusions.contains(dependency.getGroupId() + ":" + dependency.getArtifactId())) {
            continue;
        }
        try {
            Rule artifactRule = new Rule(getArtifact(dependency), dependency.getExclusions());
            HashSet<String> localDepExclusions = new HashSet<>(exclusions);
            localDepExclusions.addAll(artifactRule.getExclusions());
            boolean isNewDependency = addArtifact(artifactRule, model.toString());
            if (isNewDependency) {
                ModelSource depModelSource = modelResolver.resolveModel(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
                if (depModelSource != null) {
                    artifactRule.setRepository(depModelSource.getLocation(), handler);
                    artifactRule.setSha1(downloadSha1(artifactRule));
                    resolveEffectiveModel(depModelSource, localDepExclusions, artifactRule);
                } else {
                    handler.handle(Event.error("Could not get a model for " + dependency));
                }
            }
            if (parent != null) {
                parent.addDependency(artifactRule);
                parent.getDependencies().addAll(artifactRule.getDependencies());
            } else {
                addArtifact(artifactRule, modelSource.getLocation());
            }
        } catch (UnresolvableModelException | InvalidArtifactCoordinateException e) {
            handler.handle(Event.error("Could not resolve dependency " + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion() + ": " + e.getMessage()));
        }
    }
    return model;
}
Also used : Repository(org.apache.maven.model.Repository) Model(org.apache.maven.model.Model) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) Dependency(org.apache.maven.model.Dependency) FileModelSource(org.apache.maven.model.building.FileModelSource) ModelSource(org.apache.maven.model.building.ModelSource) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Example 3 with Repository

use of org.apache.maven.model.Repository in project maven-plugins by apache.

the class AbstractAntTestMavenProjectStub method getRepositories.

/**
     * @see org.apache.maven.project.MavenProject#getRepositories()
     */
public List getRepositories() {
    Repository repo = new Repository();
    repo.setId("central");
    repo.setName("central");
    repo.setUrl("http://repo1.maven.org/maven2");
    return Collections.singletonList(repo);
}
Also used : Repository(org.apache.maven.model.Repository)

Example 4 with Repository

use of org.apache.maven.model.Repository in project maven-plugins by apache.

the class MavenJDOMWriter method iterateRepository.

// -- void iterateReportSet(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
     * Method iterateRepository
     *
     * @param counter
     * @param childTag
     * @param parentTag
     * @param list
     * @param parent
     */
protected void iterateRepository(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) {
    boolean shouldExist = list != null && list.size() > 0;
    Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        Counter innerCount = new Counter(counter.getDepth() + 1);
        while (it.hasNext()) {
            Repository value = (Repository) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updateRepository(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}
Also used : Repository(org.apache.maven.model.Repository) DeploymentRepository(org.apache.maven.model.DeploymentRepository) Element(org.jdom.Element) Iterator(java.util.Iterator)

Example 5 with Repository

use of org.apache.maven.model.Repository in project bazel by bazelbuild.

the class MavenConnector method getMavenCentral.

public static Repository getMavenCentral() {
    Repository repository = new Repository();
    repository.setId("central");
    repository.setName("default");
    repository.setUrl(MAVEN_CENTRAL_URL);
    return repository;
}
Also used : LocalRepository(org.eclipse.aether.repository.LocalRepository) Repository(org.apache.maven.model.Repository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Aggregations

Repository (org.apache.maven.model.Repository)9 HashSet (java.util.HashSet)2 Dependency (org.apache.maven.model.Dependency)2 Model (org.apache.maven.model.Model)2 UnresolvableModelException (org.apache.maven.model.resolution.UnresolvableModelException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Nullable (javax.annotation.Nullable)1 Artifact (org.apache.maven.artifact.Artifact)1 Build (org.apache.maven.model.Build)1 CiManagement (org.apache.maven.model.CiManagement)1 Contributor (org.apache.maven.model.Contributor)1 DependencyManagement (org.apache.maven.model.DependencyManagement)1 DeploymentRepository (org.apache.maven.model.DeploymentRepository)1 Developer (org.apache.maven.model.Developer)1 DistributionManagement (org.apache.maven.model.DistributionManagement)1 IssueManagement (org.apache.maven.model.IssueManagement)1