Search in sources :

Example 41 with Dependency

use of org.apache.maven.model.Dependency in project drools by kiegroup.

the class KieRepositoryScannerTest method testKieScannerScopesNotRequired.

@Test
public void testKieScannerScopesNotRequired() throws Exception {
    MavenRepository repository = getMavenRepository();
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseIdWithDep = ks.newReleaseId("org.kie", "test-with-dep", "1.0-SNAPSHOT");
    Dependency dep1 = dependencyWithScope("org.kie", "test-dep1-in-test-scope", "1.0-SNAPSHOT", "test");
    Dependency dep2 = dependencyWithScope("org.kie", "test-dep2-in-provided-scope", "1.0-SNAPSHOT", "provided");
    Dependency dep3 = dependencyWithScope("org.kie", "test-dep3-in-system-scope", "1.0-SNAPSHOT", "system");
    dep3.setSystemPath(fileManager.getRootDirectory().getAbsolutePath());
    // to ensure KieBuilder is able to build correctly:
    repository.installArtifact(ks.newReleaseId("org.kie", "test-dep3-in-system-scope", "1.0-SNAPSHOT"), new byte[] {}, new byte[] {});
    InternalKieModule kJar2 = createKieJarWithDependencies(ks, releaseIdWithDep, false, "rule1", dep1, dep2, dep3);
    KieContainer kieContainer = ks.newKieContainer(releaseIdWithDep);
    // DROOLS-1051 following should not throw NPE because dependencies are not in scope of scanner
    KieScanner scanner = ks.newKieScanner(kieContainer);
    assertNotNull(scanner);
}
Also used : MavenRepository.getMavenRepository(org.appformer.maven.integration.MavenRepository.getMavenRepository) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) MavenRepository(org.appformer.maven.integration.MavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) Dependency(org.apache.maven.model.Dependency) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 42 with Dependency

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

the class PomIntegrationTest method testMultipleInvocation.

@Test
public void testMultipleInvocation() throws Exception {
    // Setup: deps: com.example:with-deps:jar:1.0 -> com.othercorp:no-deps:jar:1.0
    BuildRule dep = createMavenPublishable("//example:dep", "com.othercorp:no-deps:1.0", null);
    MavenPublishable item = createMavenPublishable("//example:has-deps", "com.example:with-deps:1.0", null, dep);
    Path pomPath = tmp.getRoot().resolve("pom.xml");
    assertFalse(Files.exists(pomPath));
    // Basic case
    Pom.generatePomFile(pathResolver, item, pomPath);
    Model pomModel = parse(pomPath);
    assertEquals("com.example", pomModel.getGroupId());
    assertEquals("with-deps", pomModel.getArtifactId());
    assertEquals("1.0", pomModel.getVersion());
    List<Dependency> dependencies = pomModel.getDependencies();
    assertEquals(1, dependencies.size());
    Dependency dependency = dependencies.get(0);
    assertEquals("com.othercorp", dependency.getGroupId());
    assertEquals("no-deps", dependency.getArtifactId());
    assertEquals("1.0", dependency.getVersion());
    // Corrupt dependency data and ensure buck restores that
    removeDependencies(pomModel, pomPath);
    Pom.generatePomFile(pathResolver, item, pomPath);
    pomModel = parse(pomPath);
    // Add extra pom data and ensure buck preserves that
    pomModel.setUrl(URL);
    serializePom(pomModel, pomPath);
    Pom.generatePomFile(pathResolver, item, pomPath);
    pomModel = parse(pomPath);
    assertEquals(URL, pomModel.getUrl());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Model(org.apache.maven.model.Model) BuildRule(com.facebook.buck.rules.BuildRule) Dependency(org.apache.maven.model.Dependency) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) Test(org.junit.Test)

Example 43 with Dependency

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

the class PomIntegrationTest method shouldUseTemplateIfProvided.

@Test
public void shouldUseTemplateIfProvided() throws Exception {
    MavenPublishable withoutTemplate = createMavenPublishable("//example:no-template", "example.com:project:1.0.0", null);
    Model noTemplate = parse(Pom.generatePomFile(pathResolver, withoutTemplate));
    MavenPublishable withTemplate = createMavenPublishable("//example:template", "example.com:project:1.0.0", new FakeSourcePath(TestDataHelper.getTestDataDirectory(getClass()).resolve("poms/template-pom.xml").toString()));
    Model templated = parse(Pom.generatePomFile(pathResolver, withTemplate));
    // Template sets developers and an example dep. Check that these aren't in the non-templated
    // version
    assertTrue(noTemplate.getDevelopers().isEmpty());
    assertTrue(noTemplate.getDependencies().isEmpty());
    // Now check the same fields in the templated version.
    Developer seenDev = Iterables.getOnlyElement(templated.getDevelopers());
    assertEquals("susan", seenDev.getId());
    assertEquals("Susan The Developer", seenDev.getName());
    assertEquals(ImmutableList.of("Owner"), seenDev.getRoles());
    Dependency seenDep = Iterables.getOnlyElement(templated.getDependencies());
    assertEquals("com.google.guava", seenDep.getGroupId());
    assertEquals("guava", seenDep.getArtifactId());
    assertEquals("19.0", seenDep.getVersion());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Model(org.apache.maven.model.Model) Developer(org.apache.maven.model.Developer) Dependency(org.apache.maven.model.Dependency) MavenPublishable(com.facebook.buck.jvm.java.MavenPublishable) Test(org.junit.Test)

Example 44 with Dependency

use of org.apache.maven.model.Dependency 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 45 with Dependency

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

the class Pom method updateModel.

private void updateModel(Artifact mavenCoordinates, Iterable<Artifact> deps) {
    model.setGroupId(mavenCoordinates.getGroupId());
    model.setArtifactId(mavenCoordinates.getArtifactId());
    model.setVersion(mavenCoordinates.getVersion());
    if (Strings.isNullOrEmpty(model.getName())) {
        // better than nothing
        model.setName(mavenCoordinates.getArtifactId());
    }
    // Dependencies
    ImmutableMap<DepKey, Dependency> depIndex = Maps.uniqueIndex(getModel().getDependencies(), DepKey::new);
    for (Artifact artifactDep : deps) {
        DepKey key = new DepKey(artifactDep);
        Dependency dependency = depIndex.get(key);
        if (dependency == null) {
            dependency = key.createDependency();
            getModel().addDependency(dependency);
        }
        updateDependency(dependency, artifactDep);
    }
}
Also used : Dependency(org.apache.maven.model.Dependency) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

Dependency (org.apache.maven.model.Dependency)78 ArrayList (java.util.ArrayList)24 Artifact (org.apache.maven.artifact.Artifact)18 File (java.io.File)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 MavenProject (org.apache.maven.project.MavenProject)8 IOException (java.io.IOException)7 Exclusion (org.apache.maven.model.Exclusion)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)7 WebappStructure (org.apache.maven.plugins.war.util.WebappStructure)7 HashMap (java.util.HashMap)6 DependencyManagement (org.apache.maven.model.DependencyManagement)5 Model (org.apache.maven.model.Model)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Plugin (org.apache.maven.model.Plugin)4 List (java.util.List)3 Properties (java.util.Properties)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3