Search in sources :

Example 6 with Repository

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

the class DefaultModelResolver method addUserRepository.

/**
   * Adds a user-specified repository to the list.
   */
public void addUserRepository(String url) {
    Repository repository = new Repository();
    repository.setUrl(url);
    repository.setId("user-defined repository");
    repository.setName("default");
    addRepository(repository);
}
Also used : Repository(org.apache.maven.model.Repository)

Example 7 with Repository

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

the class DefaultModelResolver method resolveModel.

@Override
public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException {
    String ruleName = Rule.name(groupId, artifactId);
    if (ruleNameToModelSource.containsKey(ruleName)) {
        return ruleNameToModelSource.get(ruleName);
    }
    for (Repository repository : repositories) {
        UrlModelSource modelSource = getModelSource(repository.getUrl(), groupId, artifactId, version);
        if (modelSource != null) {
            return modelSource;
        }
    }
    // TODO(kchodorow): use Java 8 features to make this a one-liner.
    List<String> attemptedUrls = Lists.newArrayList();
    for (Repository repository : repositories) {
        attemptedUrls.add(repository.getUrl());
    }
    throw new UnresolvableModelException("Could not find any repositories that knew how to " + "resolve " + groupId + ":" + artifactId + ":" + version + " (checked " + Joiner.on(", ").join(attemptedUrls) + ")", groupId, artifactId, version);
}
Also used : Repository(org.apache.maven.model.Repository) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) UrlModelSource(org.apache.maven.model.building.UrlModelSource)

Example 8 with Repository

use of org.apache.maven.model.Repository in project buck by facebook.

the class Pom method merge.

private Model merge(Model first, @Nullable Model second) {
    if (second == null) {
        return first;
    }
    Model model = first.clone();
    //---- Values from ModelBase
    List<String> modules = second.getModules();
    if (modules != null) {
        for (String module : modules) {
            model.addModule(module);
        }
    }
    DistributionManagement distributionManagement = second.getDistributionManagement();
    if (distributionManagement != null) {
        model.setDistributionManagement(distributionManagement);
    }
    Properties properties = second.getProperties();
    if (properties != null) {
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            model.addProperty((String) entry.getKey(), (String) entry.getValue());
        }
    }
    DependencyManagement dependencyManagement = second.getDependencyManagement();
    if (dependencyManagement != null) {
        model.setDependencyManagement(dependencyManagement);
    }
    List<Dependency> dependencies = second.getDependencies();
    if (dependencies != null) {
        for (Dependency dependency : dependencies) {
            model.addDependency(dependency);
        }
    }
    List<Repository> repositories = second.getRepositories();
    if (repositories != null) {
        for (Repository repository : repositories) {
            model.addRepository(repository);
        }
    }
    List<Repository> pluginRepositories = second.getPluginRepositories();
    if (pluginRepositories != null) {
        for (Repository pluginRepository : pluginRepositories) {
            model.addPluginRepository(pluginRepository);
        }
    }
    // Ignore reports, reporting, and locations
    //----- From Model
    Parent parent = second.getParent();
    if (parent != null) {
        model.setParent(parent);
    }
    Organization organization = second.getOrganization();
    if (organization != null) {
        model.setOrganization(organization);
    }
    List<License> licenses = second.getLicenses();
    Set<String> currentLicenseUrls = new HashSet<>();
    if (model.getLicenses() != null) {
        for (License license : model.getLicenses()) {
            currentLicenseUrls.add(license.getUrl());
        }
    }
    if (licenses != null) {
        for (License license : licenses) {
            if (!currentLicenseUrls.contains(license.getUrl())) {
                model.addLicense(license);
                currentLicenseUrls.add(license.getUrl());
            }
        }
    }
    List<Developer> developers = second.getDevelopers();
    Set<String> currentDevelopers = new HashSet<>();
    if (model.getDevelopers() != null) {
        for (Developer developer : model.getDevelopers()) {
            currentDevelopers.add(developer.getName());
        }
    }
    if (developers != null) {
        for (Developer developer : developers) {
            if (!currentDevelopers.contains(developer.getName())) {
                model.addDeveloper(developer);
                currentDevelopers.add(developer.getName());
            }
        }
    }
    List<Contributor> contributors = second.getContributors();
    Set<String> currentContributors = new HashSet<>();
    if (model.getContributors() != null) {
        for (Contributor contributor : model.getContributors()) {
            currentDevelopers.add(contributor.getName());
        }
    }
    if (contributors != null) {
        for (Contributor contributor : contributors) {
            if (!currentContributors.contains(contributor.getName())) {
                model.addContributor(contributor);
                currentContributors.add(contributor.getName());
            }
        }
    }
    List<MailingList> mailingLists = second.getMailingLists();
    if (mailingLists != null) {
        for (MailingList mailingList : mailingLists) {
            model.addMailingList(mailingList);
        }
    }
    Prerequisites prerequisites = second.getPrerequisites();
    if (prerequisites != null) {
        model.setPrerequisites(prerequisites);
    }
    Scm scm = second.getScm();
    if (scm != null) {
        model.setScm(scm);
    }
    String url = second.getUrl();
    if (url != null) {
        model.setUrl(url);
    }
    String description = second.getDescription();
    if (description != null) {
        model.setDescription(description);
    }
    IssueManagement issueManagement = second.getIssueManagement();
    if (issueManagement != null) {
        model.setIssueManagement(issueManagement);
    }
    CiManagement ciManagement = second.getCiManagement();
    if (ciManagement != null) {
        model.setCiManagement(ciManagement);
    }
    Build build = second.getBuild();
    if (build != null) {
        model.setBuild(build);
    }
    List<Profile> profiles = second.getProfiles();
    Set<String> currentProfileIds = new HashSet<>();
    if (model.getProfiles() != null) {
        for (Profile profile : model.getProfiles()) {
            currentProfileIds.add(profile.getId());
        }
    }
    if (profiles != null) {
        for (Profile profile : profiles) {
            if (!currentProfileIds.contains(profile.getId())) {
                model.addProfile(profile);
                currentProfileIds.add(profile.getId());
            }
        }
    }
    return model;
}
Also used : Organization(org.apache.maven.model.Organization) Parent(org.apache.maven.model.Parent) License(org.apache.maven.model.License) MailingList(org.apache.maven.model.MailingList) Developer(org.apache.maven.model.Developer) Contributor(org.apache.maven.model.Contributor) Properties(java.util.Properties) Profile(org.apache.maven.model.Profile) Prerequisites(org.apache.maven.model.Prerequisites) Build(org.apache.maven.model.Build) DependencyManagement(org.apache.maven.model.DependencyManagement) IssueManagement(org.apache.maven.model.IssueManagement) HashSet(java.util.HashSet) Dependency(org.apache.maven.model.Dependency) Repository(org.apache.maven.model.Repository) Model(org.apache.maven.model.Model) CiManagement(org.apache.maven.model.CiManagement) DistributionManagement(org.apache.maven.model.DistributionManagement) Scm(org.apache.maven.model.Scm) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with Repository

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

the class AntBuildWriter method writeGetDepsTarget.

/**
     * Write get-deps target in the writer only for a non-POM project
     *
     * @param writer
     */
private void writeGetDepsTarget(XMLWriter writer) {
    if (AntBuildWriterUtil.isPomPackaging(project)) {
        return;
    }
    XmlWriterUtil.writeCommentText(writer, "Download dependencies target", 1);
    writer.startElement("target");
    writer.addAttribute("name", "test-offline");
    writer.startElement("condition");
    writer.addAttribute("property", "maven.mode.offline");
    writer.startElement("equals");
    writer.addAttribute("arg1", "${maven.settings.offline}");
    writer.addAttribute("arg2", "true");
    // equals
    writer.endElement();
    // condition
    writer.endElement();
    // target
    writer.endElement();
    XmlWriterUtil.writeLineBreak(writer, 2, 1);
    writer.startElement("target");
    writer.addAttribute("name", "get-deps");
    AntBuildWriterUtil.addWrapAttribute(writer, "target", "depends", "test-offline", 2);
    AntBuildWriterUtil.addWrapAttribute(writer, "target", "description", "Download all dependencies", 2);
    // TODO: check, and
    AntBuildWriterUtil.addWrapAttribute(writer, "target", "unless", "maven.mode.offline", 2);
    // differs from m1
    writer.startElement("mkdir");
    writer.addAttribute("dir", "${maven.repo.local}");
    // mkdir
    writer.endElement();
    String basedir = project.getBasedir().getAbsolutePath();
    // TODO: proxy - probably better to use wagon!
    for (Object o : project.getTestArtifacts()) {
        Artifact artifact = (Artifact) o;
        if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
            continue;
        }
        String path = artifactResolverWrapper.getLocalArtifactPath(artifact);
        if (!new File(path).exists()) {
            File parentDirs = new File(path).getParentFile();
            if (parentDirs != null) {
                writer.startElement("mkdir");
                // Replace \ with / in the parent dir path
                writer.addAttribute("dir", "${maven.repo.local}/" + parentDirs.getPath().replace('\\', '/'));
                // mkdir
                writer.endElement();
            }
            for (Object o1 : project.getRepositories()) {
                Repository repository = (Repository) o1;
                String url = repository.getUrl();
                String localDir = getProjectRepoDirectory(url, basedir);
                if (localDir != null) {
                    if (localDir.length() > 0 && !localDir.endsWith("/")) {
                        localDir += '/';
                    }
                    writer.startElement("copy");
                    writer.addAttribute("file", localDir + path);
                    AntBuildWriterUtil.addWrapAttribute(writer, "copy", "tofile", "${maven.repo.local}/" + path, 3);
                    AntBuildWriterUtil.addWrapAttribute(writer, "copy", "failonerror", "false", 3);
                    // copy
                    writer.endElement();
                } else {
                    writer.startElement("get");
                    writer.addAttribute("src", url + '/' + path);
                    AntBuildWriterUtil.addWrapAttribute(writer, "get", "dest", "${maven.repo.local}/" + path, 3);
                    AntBuildWriterUtil.addWrapAttribute(writer, "get", "usetimestamp", "false", 3);
                    AntBuildWriterUtil.addWrapAttribute(writer, "get", "ignoreerrors", "true", 3);
                    // get
                    writer.endElement();
                }
            }
        }
    }
    // CHECKSTYLE_ON: LineLength
    // target
    writer.endElement();
    XmlWriterUtil.writeLineBreak(writer);
}
Also used : Repository(org.apache.maven.model.Repository) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

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