Search in sources :

Example 76 with Dependency

use of org.apache.maven.model.Dependency in project gradle by gradle.

the class MavenPomFileGenerator method addDependency.

private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) {
    Dependency mavenDependency = new Dependency();
    mavenDependency.setGroupId(dependency.getGroupId());
    mavenDependency.setArtifactId(artifactId);
    mavenDependency.setVersion(mapToMavenSyntax(dependency.getVersion()));
    mavenDependency.setType(type);
    mavenDependency.setScope(scope);
    mavenDependency.setClassifier(classifier);
    for (ExcludeRule excludeRule : dependency.getExcludeRules()) {
        Exclusion exclusion = new Exclusion();
        exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*"));
        exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*"));
        mavenDependency.addExclusion(exclusion);
    }
    getModel().addDependency(mavenDependency);
}
Also used : Exclusion(org.apache.maven.model.Exclusion) MavenDependency(org.gradle.api.publish.maven.MavenDependency) Dependency(org.apache.maven.model.Dependency) ExcludeRule(org.gradle.api.artifacts.ExcludeRule)

Example 77 with Dependency

use of org.apache.maven.model.Dependency in project meecrowave by apache.

the class MeecrowaveBundleMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().warn(getClass().getSimpleName() + " skipped");
        return;
    }
    final File distroFolder = new File(buildDirectory, rootName == null ? artifactId + "-distribution" : rootName);
    if (distroFolder.exists()) {
        delete(distroFolder);
    }
    Stream.of("bin", "conf", "logs", "lib").forEach(i -> new File(distroFolder, i).mkdirs());
    // TODO: add .bat support
    for (final String ext : asList("sh", "bat")) {
        try (final BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bin/meecrowave." + ext)))) {
            write(new File(distroFolder, "bin/meecrowave." + ext), StrSubstitutor.replace(reader.lines().collect(joining("\n")), new HashMap<String, String>() {

                {
                    put("main", main);
                }
            }));
        } catch (final IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    copyProvidedFiles(distroFolder);
    write(new File(distroFolder, "logs/you_can_safely_delete.txt"), DELETE_TEXT);
    final Collection<String> includedArtifacts = project.getArtifacts().stream().filter(this::isIncluded).map(a -> {
        addLib(distroFolder, a.getFile());
        return a.getArtifactId();
    }).collect(toList());
    if (app.exists()) {
        addLib(distroFolder, app);
    }
    if (enforceCommonsCli && !includedArtifacts.contains("commons-cli")) {
        addLib(distroFolder, resolve("commons-cli", "commons-cli", "1.4", ""));
    }
    if (libs != null) {
        libs.forEach(l -> {
            final String[] c = l.split(":");
            if (c.length != 3 && c.length != 4) {
                throw new IllegalArgumentException("libs syntax is groupId:artifactId:version[:classifier]");
            }
            addLib(distroFolder, resolve(c[0], c[1], c[2], c.length == 4 ? c[3] : ""));
        });
    }
    if (enforceMeecrowave && !includedArtifacts.contains("meecrowave-core")) {
        final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
        request.setMavenProject(new MavenProject() {

            {
                getDependencies().add(new Dependency() {

                    {
                        setGroupId("org.apache.meecrowave");
                        setArtifactId("meecrowave-core");
                        setVersion(findVersion());
                    }
                });
            }
        });
        request.setRepositorySession(session);
        try {
            dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor() {

                @Override
                public boolean visitEnter(final DependencyNode node) {
                    return true;
                }

                @Override
                public boolean visitLeave(final DependencyNode node) {
                    final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
                    if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId())) {
                        addLib(distroFolder, artifact.getFile());
                    }
                    return true;
                }
            });
        } catch (final DependencyResolutionException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    final Path prefix = skipArchiveRootFolder ? distroFolder.toPath() : distroFolder.getParentFile().toPath();
    for (final String format : formats) {
        getLog().info(format + "-ing Custom Meecrowave Distribution");
        final File output = new File(buildDirectory, artifactId + "-meecrowave-distribution." + format);
        switch(format.toLowerCase(ENGLISH)) {
            case "tar.gz":
                try (final TarArchiveOutputStream tarGz = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(output)))) {
                    tarGz.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
                    for (final String entry : distroFolder.list()) {
                        tarGz(tarGz, new File(distroFolder, entry), prefix);
                    }
                } catch (final IOException e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
                break;
            case "zip":
                try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new FileOutputStream(output))) {
                    for (final String entry : distroFolder.list()) {
                        zip(zos, new File(distroFolder, entry), prefix);
                    }
                } catch (final IOException e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
                break;
            default:
                throw new IllegalArgumentException(format + " is not supported");
        }
        attach(format, output);
    }
    if (!keepExplodedFolder) {
        delete(distroFolder);
    }
}
Also used : ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) Parameter(org.apache.maven.plugins.annotations.Parameter) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) MavenProject(org.apache.maven.project.MavenProject) Arrays.asList(java.util.Arrays.asList) ProjectDependenciesResolver(org.apache.maven.project.ProjectDependenciesResolver) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Artifact(org.apache.maven.artifact.Artifact) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) Path(java.nio.file.Path) ENGLISH(java.util.Locale.ENGLISH) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Stream(java.util.stream.Stream) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) GZIPOutputStream(java.util.zip.GZIPOutputStream) AbstractMojo(org.apache.maven.plugin.AbstractMojo) RepositorySystem(org.eclipse.aether.RepositorySystem) MavenProjectHelper(org.apache.maven.project.MavenProjectHelper) Dependency(org.apache.maven.model.Dependency) Component(org.apache.maven.plugins.annotations.Component) HashMap(java.util.HashMap) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) StandardCopyOption(java.nio.file.StandardCopyOption) Mojo(org.apache.maven.plugins.annotations.Mojo) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Properties(java.util.Properties) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) InputStreamReader(java.io.InputStreamReader) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RUNTIME_PLUS_SYSTEM(org.apache.maven.plugins.annotations.ResolutionScope.RUNTIME_PLUS_SYSTEM) Collectors.toList(java.util.stream.Collectors.toList) ArtifactResolver(org.eclipse.aether.impl.ArtifactResolver) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) BufferedReader(java.io.BufferedReader) InputStream(java.io.InputStream) HashMap(java.util.HashMap) MavenProject(org.apache.maven.project.MavenProject) GZIPOutputStream(java.util.zip.GZIPOutputStream) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) IOException(java.io.IOException) Dependency(org.apache.maven.model.Dependency) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File)

Example 78 with Dependency

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

the class AbstractKieCiTest method pomWithMvnDeps.

private String pomWithMvnDeps(Dependency releaseId, Dependency... dependencies) {
    String pom = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n" + "  <modelVersion>4.0.0</modelVersion>\n" + "\n" + "  <groupId>" + releaseId.getGroupId() + "</groupId>\n" + "  <artifactId>" + releaseId.getArtifactId() + "</artifactId>\n" + "  <version>" + releaseId.getVersion() + "</version>\n" + "\n";
    if (dependencies != null && dependencies.length > 0) {
        pom += "<dependencies>\n";
        for (Dependency dep : dependencies) {
            pom += "<dependency>\n";
            pom += "  <groupId>" + dep.getGroupId() + "</groupId>\n";
            pom += "  <artifactId>" + dep.getArtifactId() + "</artifactId>\n";
            pom += "  <version>" + dep.getVersion() + "</version>\n";
            if (!"".equals(dep.getScope()) && !"compile".equals(dep.getScope())) {
                pom += "  <scope>" + dep.getScope() + "</scope>\n";
            }
            if ("system".equals(dep.getScope())) {
                pom += "  <systemPath>" + dep.getSystemPath() + "</systemPath>\n";
            }
            pom += "</dependency>\n";
        }
        pom += "</dependencies>\n";
    }
    pom += "</project>";
    return pom;
}
Also used : Dependency(org.apache.maven.model.Dependency)

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