Search in sources :

Example 1 with FractionDescriptor

use of org.wildfly.swarm.fractions.FractionDescriptor in project wildfly-swarm by wildfly-swarm.

the class BuildTool method detectFractions.

private void detectFractions() throws Exception {
    final File tmpFile = File.createTempFile("buildtool", this.projectAsset.getName().replace("/", "_"));
    tmpFile.deleteOnExit();
    this.projectAsset.getArchive().as(ZipExporter.class).exportTo(tmpFile, true);
    final FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer().logger(log).source(tmpFile);
    if (testClass != null && !"".equals(testClass)) {
        analyzer.testClass(testClass);
    }
    final Collection<FractionDescriptor> detectedFractions = analyzer.detectNeededFractions();
    // don't overwrite fractions added by the user
    detectedFractions.removeAll(this.fractions.stream().map(ArtifactSpec::toFractionDescriptor).collect(Collectors.toSet()));
    this.log.info(String.format("Detected %sfractions: %s", this.fractions.isEmpty() ? "" : "additional ", String.join(", ", detectedFractions.stream().map(FractionDescriptor::av).sorted().collect(Collectors.toList()))));
    detectedFractions.stream().map(ArtifactSpec::fromFractionDescriptor).forEach(this::fraction);
}
Also used : FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) FractionDescriptor(org.wildfly.swarm.fractions.FractionDescriptor) JarFile(java.util.jar.JarFile) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File)

Example 2 with FractionDescriptor

use of org.wildfly.swarm.fractions.FractionDescriptor in project wildfly-swarm by wildfly-swarm.

the class StartMojo method findNeededFractions.

List<Path> findNeededFractions(final Set<Artifact> existingDeps, final Path source, final boolean scanDeps) throws MojoFailureException {
    getLog().info("Scanning for needed WildFly Swarm fractions with mode: " + fractionDetectMode);
    final Set<String> existingDepGASet = existingDeps.stream().map(d -> String.format("%s:%s", d.getGroupId(), d.getArtifactId())).collect(Collectors.toSet());
    final Set<FractionDescriptor> fractions;
    final FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer(FractionList.get()).source(source);
    if (scanDeps) {
        existingDeps.forEach(d -> analyzer.source(d.getFile()));
    }
    final Predicate<FractionDescriptor> notExistingDep = d -> !existingDepGASet.contains(String.format("%s:%s", d.getGroupId(), d.getArtifactId()));
    try {
        fractions = analyzer.detectNeededFractions().stream().filter(notExistingDep).collect(Collectors.toSet());
    } catch (IOException e) {
        throw new MojoFailureException("failed to scan for fractions", e);
    }
    getLog().info("Detected fractions: " + String.join(", ", fractions.stream().map(FractionDescriptor::av).sorted().collect(Collectors.toList())));
    fractions.addAll(this.additionalFractions.stream().map(f -> FractionDescriptor.fromGav(FractionList.get(), f)).collect(Collectors.toSet()));
    final Set<FractionDescriptor> allFractions = new HashSet<>(fractions);
    allFractions.addAll(fractions.stream().flatMap(f -> f.getDependencies().stream()).filter(notExistingDep).collect(Collectors.toSet()));
    getLog().info("Using fractions: " + String.join(", ", allFractions.stream().map(FractionDescriptor::gavOrAv).sorted().collect(Collectors.toList())));
    final Set<ArtifactSpec> specs = new HashSet<>();
    specs.addAll(existingDeps.stream().map(this::artifactToArtifactSpec).collect(Collectors.toList()));
    specs.addAll(allFractions.stream().map(ArtifactSpec::fromFractionDescriptor).collect(Collectors.toList()));
    try {
        return mavenArtifactResolvingHelper().resolveAll(specs).stream().map(s -> s.file.toPath()).collect(Collectors.toList());
    } catch (Exception e) {
        throw new MojoFailureException("failed to resolve fraction dependencies", e);
    }
}
Also used : DependencyManager(org.wildfly.swarm.tools.DependencyManager) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) Parameter(org.apache.maven.plugins.annotations.Parameter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Mojo(org.apache.maven.plugins.annotations.Mojo) StringTokenizer(java.util.StringTokenizer) Artifact(org.apache.maven.artifact.Artifact) ResolutionScope(org.apache.maven.plugins.annotations.ResolutionScope) Path(java.nio.file.Path) SwarmProcess(org.wildfly.swarm.tools.exec.SwarmProcess) Files(java.nio.file.Files) BootstrapProperties(org.wildfly.swarm.bootstrap.util.BootstrapProperties) Predicate(java.util.function.Predicate) DeclaredDependencies(org.wildfly.swarm.tools.DeclaredDependencies) SwarmExecutor(org.wildfly.swarm.tools.exec.SwarmExecutor) Set(java.util.Set) FractionDescriptor(org.wildfly.swarm.fractions.FractionDescriptor) IOException(java.io.IOException) BuildTool(org.wildfly.swarm.tools.BuildTool) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Collectors(java.util.stream.Collectors) File(java.io.File) FractionList(org.wildfly.swarm.fractions.FractionList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) TimeUnit(java.util.concurrent.TimeUnit) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) List(java.util.List) Paths(java.nio.file.Paths) TempFileManager(org.wildfly.swarm.bootstrap.util.TempFileManager) SwarmProperties(org.wildfly.swarm.spi.api.SwarmProperties) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) FractionDescriptor(org.wildfly.swarm.fractions.FractionDescriptor) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)2 FractionDescriptor (org.wildfly.swarm.fractions.FractionDescriptor)2 FractionUsageAnalyzer (org.wildfly.swarm.fractions.FractionUsageAnalyzer)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1 TimeUnit (java.util.concurrent.TimeUnit)1 Predicate (java.util.function.Predicate)1 JarFile (java.util.jar.JarFile)1 Collectors (java.util.stream.Collectors)1 ZipFile (net.lingala.zip4j.core.ZipFile)1 Artifact (org.apache.maven.artifact.Artifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1