Search in sources :

Example 6 with ArtifactSpec

use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.

the class GradleArtifactResolvingHelper method doResolve.

private Collection<ResolvedArtifact> doResolve(final Collection<ArtifactSpec> deps, boolean transitive) {
    final Configuration config = this.project.getConfigurations().detachedConfiguration().setTransitive(transitive);
    final DependencySet dependencySet = config.getDependencies();
    deps.forEach(spec -> {
        if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) {
            dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false));
        } else {
            final DefaultExternalModuleDependency d = new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
            final DefaultDependencyArtifact da = new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
            d.addArtifact(da);
            dependencySet.add(d);
        }
    });
    if (transitive) {
        return config.getResolvedConfiguration().getResolvedArtifacts();
    }
    return config.getResolvedConfiguration().getFirstLevelModuleDependencies().stream().map(dep -> dep.getModuleArtifacts()).flatMap(artifacts -> artifacts.stream()).collect(Collectors.toList());
}
Also used : Iterator(java.util.Iterator) Project(org.gradle.api.Project) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Collection(java.util.Collection) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) Set(java.util.Set) DefaultProjectAccessListener(org.gradle.api.internal.project.DefaultProjectAccessListener) DependencySet(org.gradle.api.artifacts.DependencySet) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) DefaultDependencyArtifact(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) Configuration(org.gradle.api.artifacts.Configuration) Map(java.util.Map) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Collections(java.util.Collections) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) DefaultDependencyArtifact(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact) Configuration(org.gradle.api.artifacts.Configuration) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) DependencySet(org.gradle.api.artifacts.DependencySet) DefaultProjectAccessListener(org.gradle.api.internal.project.DefaultProjectAccessListener)

Example 7 with ArtifactSpec

use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.

the class PackageTask method packageForSwarm.

@TaskAction
public void packageForSwarm() throws Exception {
    final Project project = getProject();
    GradleArtifactResolvingHelper resolvingHelper = new GradleArtifactResolvingHelper(project);
    Properties propertiesFromExtension = getPropertiesFromExtension();
    List<File> moduleDirs = getModuleDirs();
    if (moduleDirs.isEmpty()) {
        Path resourcesOutputDir = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir().toPath().resolve(MODULE_DIR_NAME);
        if (Files.isDirectory(resourcesOutputDir)) {
            File moduleDir = resourcesOutputDir.toFile();
            moduleDirs.add(moduleDir);
        }
    }
    this.tool = new BuildTool(resolvingHelper).projectArtifact(this.jarTask.getGroup().toString(), this.jarTask.getBaseName(), this.jarTask.getVersion(), getPackaging(), getProjectArtifactFile()).mainClass(getMainClassName()).bundleDependencies(getBundleDependencies()).executable(getExecutable()).executableScript(getExecutableScript()).properties(propertiesFromExtension).properties(getPropertiesFromFile()).properties(PropertiesUtil.filteredSystemProperties(propertiesFromExtension, false)).fractionDetectionMode(getSwarmExtension().getFractionDetectMode()).hollow(getHollow()).additionalModules(moduleDirs.stream().filter(File::exists).map(File::getAbsolutePath).collect(Collectors.toList())).logger(new SimpleLogger() {

        @Override
        public void debug(String msg) {
            getLogger().debug(msg);
        }

        @Override
        public void info(String msg) {
            getLogger().info(msg);
        }

        @Override
        public void error(String msg) {
            getLogger().error(msg);
        }

        @Override
        public void error(String msg, Throwable t) {
            getLogger().error(msg, t);
        }
    });
    DeclaredDependencies declaredDependencies = new DeclaredDependencies();
    List<ArtifactSpec> explicitDependencies = new ArrayList<>();
    /* project.getConfigurations()
                .getByName("compile")
                .getAllDependencies()
                .forEach((artifact) -> {
                    String groupId = artifact.getGroup();
                    String artifactId = artifact.getName();
                    explicitDependencies.add(new ArtifactSpec("compile", groupId, artifactId, null, "jar", null, null));
                });

        project.getConfigurations()
                .getByName("compile")
                .getResolvedConfiguration()
                .getResolvedArtifacts()
                .forEach(e -> addDependency(declaredDependencies, explicitDependencies, e));*/
    ResolvedConfiguration resolvedConfiguration = project.getConfigurations().getByName("default").getResolvedConfiguration();
    Set<ResolvedDependency> directDeps = resolvedConfiguration.getFirstLevelModuleDependencies();
    for (ResolvedDependency directDep : directDeps) {
        assert directDep.getModuleArtifacts().iterator().hasNext() : "Expected module artifacts";
        ArtifactSpec parent = new ArtifactSpec("compile", directDep.getModule().getId().getGroup(), directDep.getModule().getId().getName(), directDep.getModule().getId().getVersion(), directDep.getModuleArtifacts().iterator().next().getExtension(), null, null);
        Set<ArtifactSpec> artifactSpecs = resolvingHelper.resolveAll(new HashSet<>(Collections.singletonList(parent)));
        artifactSpecs.forEach(a -> declaredDependencies.add(parent, a));
    }
    tool.declaredDependencies(declaredDependencies);
    final Boolean bundleDependencies = getBundleDependencies();
    if (bundleDependencies != null) {
        this.tool.bundleDependencies(bundleDependencies);
    }
    this.tool.build(getBaseName(), getOutputDirectory());
}
Also used : Path(java.nio.file.Path) DeclaredDependencies(org.wildfly.swarm.tools.DeclaredDependencies) ArrayList(java.util.ArrayList) ResolvedDependency(org.gradle.api.artifacts.ResolvedDependency) Properties(java.util.Properties) SimpleLogger(org.wildfly.swarm.spi.meta.SimpleLogger) Project(org.gradle.api.Project) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) BuildTool(org.wildfly.swarm.tools.BuildTool) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) InputFile(org.gradle.api.tasks.InputFile) TaskAction(org.gradle.api.tasks.TaskAction)

Example 8 with ArtifactSpec

use of org.wildfly.swarm.tools.ArtifactSpec in project wildfly-swarm by wildfly-swarm.

the class ShrinkwrapArtifactResolvingHelper method resolveAll.

@Override
public Set<ArtifactSpec> resolveAll(final Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) {
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }
    MavenResolutionStrategy transitivityStrategy = (transitive ? TransitiveStrategy.INSTANCE : NonTransitiveStrategy.INSTANCE);
    resetListeners();
    final MavenResolvedArtifact[] artifacts = withResolver(r -> {
        specs.forEach(spec -> r.addDependency(createMavenDependency(spec)));
        return r.resolve().using(transitivityStrategy).as(MavenResolvedArtifact.class);
    });
    return Arrays.stream(artifacts).map(artifact -> {
        final MavenCoordinate coord = artifact.getCoordinate();
        return new ArtifactSpec(artifact.getScope().toString(), coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), coord.getPackaging().getId(), coord.getClassifier(), artifact.asFile());
    }).collect(Collectors.toSet());
}
Also used : Arrays(java.util.Arrays) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) MavenChecksumPolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenChecksumPolicy) Settings(org.apache.maven.settings.Settings) PackagingType(org.jboss.shrinkwrap.resolver.api.maven.PackagingType) AtomicReference(java.util.concurrent.atomic.AtomicReference) Maven(org.jboss.shrinkwrap.resolver.api.maven.Maven) MavenRemoteRepository(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepository) ConfigurableMavenWorkingSessionImpl(org.jboss.shrinkwrap.resolver.impl.maven.ConfigurableMavenWorkingSessionImpl) TransitiveStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.TransitiveStrategy) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency) MavenCoordinates(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinates) Method(java.lang.reflect.Method) ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) MavenRemoteRepositories(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepositories) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Collection(java.util.Collection) SwarmInternalProperties(org.wildfly.swarm.spi.api.internal.SwarmInternalProperties) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InvocationTargetException(java.lang.reflect.InvocationTargetException) MavenDependencies(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencies) MavenWorkingSessionContainer(org.jboss.shrinkwrap.resolver.impl.maven.MavenWorkingSessionContainer) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) RepositoryListener(org.eclipse.aether.RepositoryListener) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem) MavenResolvedArtifact(org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact) MavenUpdatePolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenUpdatePolicy) NonTransitiveStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.NonTransitiveStrategy) MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate) Collections(java.util.Collections) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) MavenResolvedArtifact(org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate)

Aggregations

ArtifactSpec (org.wildfly.swarm.tools.ArtifactSpec)8 Set (java.util.Set)5 DeclaredDependencies (org.wildfly.swarm.tools.DeclaredDependencies)5 File (java.io.File)4 Collectors (java.util.stream.Collectors)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 ArtifactResolvingHelper (org.wildfly.swarm.tools.ArtifactResolvingHelper)3 BuildTool (org.wildfly.swarm.tools.BuildTool)3 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Artifact (org.apache.maven.artifact.Artifact)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Mojo (org.apache.maven.plugins.annotations.Mojo)2