org.wildfly.swarm.tools.BuildTool Java Examples

The following examples show how to use org.wildfly.swarm.tools.BuildTool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StartMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
List<Path> dependencies(final Path archiveContent,
                        final boolean scanDependencies) throws MojoFailureException {
    final List<Path> elements = new ArrayList<>();
    final Set<Artifact> artifacts = this.project.getArtifacts();
    boolean hasSwarmDeps = false;
    for (Artifact each : artifacts) {
        if (each.getGroupId().equals(DependencyManager.WILDFLY_SWARM_GROUP_ID)
                && each.getArtifactId().equals(DependencyManager.WILDFLY_SWARM_BOOTSTRAP_ARTIFACT_ID)) {
            hasSwarmDeps = true;
        }
        if (each.getGroupId().equals("org.jboss.logmanager")
                && each.getArtifactId().equals("jboss-logmanager")) {
            continue;
        }
        if (each.getScope().equals("provided")) {
            continue;
        }
        elements.add(each.getFile().toPath());
    }

    elements.add(Paths.get(this.project.getBuild().getOutputDirectory()));

    if (fractionDetectMode != BuildTool.FractionDetectionMode.never) {
        if (fractionDetectMode == BuildTool.FractionDetectionMode.force ||
                !hasSwarmDeps) {
            elements.addAll(findNeededFractions(artifacts, archiveContent, scanDependencies));
        }
    } else if (!hasSwarmDeps) {
        getLog().warn("No WildFly Swarm dependencies found and fraction detection disabled");
    }

    return elements;
}
 
Example #2
Source File: Main.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
private static void addSwarmFractions(BuildTool tool, final List<String> deps) {
    deps.stream().map(f -> f.split(":"))
            .map(parts -> {
                switch (parts.length) {
                    case 1:
                        final FractionDescriptor desc = FractionList.get()
                                .getFractionDescriptor("org.wildfly.swarm", parts[0]);
                        if (desc != null) {

                            return desc;
                        } else {
                            System.err.println("Warning: Unknown fraction: " + parts[0]);

                            return null;
                        }
                    case 2:

                        return new FractionDescriptor("org.wildfly.swarm", parts[0], parts[1]);
                    case 3:

                        return new FractionDescriptor(parts[0], parts[1], parts[2]);
                    default:
                        System.err.println("Warning: Invalid fraction specifier: " + String.join(":", parts));

                        return null;
                }
            })
            .filter(f -> f != null)
            .forEach(f -> tool.fraction(f.toArtifactSpec()));
}
 
Example #3
Source File: Main.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private static void addSwarmFractions(BuildTool tool, final List<String> deps) {
    deps.stream().map(f -> f.split(":"))
            .map(parts -> {
                switch (parts.length) {
                    case 1:
                        final FractionDescriptor desc = FractionList.get()
                                .getFractionDescriptor("io.thorntail", parts[0]);
                        if (desc != null) {

                            return desc;
                        } else {
                            System.err.println("Warning: Unknown fraction: " + parts[0]);

                            return null;
                        }
                    case 2:

                        return new FractionDescriptor("io.thorntail", parts[0], parts[1]);
                    case 3:

                        return new FractionDescriptor(parts[0], parts[1], parts[2]);
                    default:
                        System.err.println("Warning: Invalid fraction specifier: " + String.join(":", parts));

                        return null;
                }
            })
            .filter(f -> f != null)
            .forEach(f -> tool.fraction(ArtifactSpec.fromFractionDescriptor(f)));
}
 
Example #4
Source File: FatJarBuilder.java    From thorntail with Apache License 2.0 4 votes vote down vote up
private File doBuild() throws Exception {
    final String type = "war";

    // NOTE: we don't know which deps are transitive!!!
    long start = System.currentTimeMillis();
    List<ArtifactOrFile> classPathEntries = analyzeClasspath();
    System.out.println("Classpath analyzing time: " + (System.currentTimeMillis() - start + " ms"));

    File war = buildWar(classPathEntries);
    final BuildTool tool = new BuildTool(new CachingArtifactResolvingHelper(), true)
            .projectArtifact("tt",
                    "thorntail-user-app",
                    "0.1-SNAPSHOT",
                    type,
                    war,
                    "users.war")
            .properties(System.getProperties())
            .fractionDetectionMode(BuildTool.FractionDetectionMode.when_missing)
            .hollow(false)
            .logger(new StdoutLogger());

    String mainClass = System.getProperty("thorntail.runner.main-class");
    if (mainClass != null) {
        tool.mainClass(mainClass);
    }

    tool.declaredDependencies(declaredDependencies(classPathEntries));


    this.classPathUrls.parallelStream()
            .filter(url -> !url.toString().matches(".*\\.[^/]*"))
            .forEach(r -> tool.resourceDirectory(r.getFile()));

    File uberjarResourcesDir = File.createTempFile("thorntail-runner-uberjar-resources", "placeholder");
    uberjarResourcesDir.deleteOnExit();
    tool.uberjarResourcesDirectory(uberjarResourcesDir.toPath());

    String currentDir = Paths.get(".").toAbsolutePath().normalize().toString();
    File fileModules = Paths.get(currentDir, "target", "classes", "modules").toFile();
    if (fileModules.exists()) {
      tool.additionalModule(fileModules.getAbsolutePath());
    }

    File jar = tool.build(target.getName(), target.getParentFile().toPath());

    tool.repackageWar(war);

    ArtifactResolutionCache.INSTANCE.store();

    return jar;
}
 
Example #5
Source File: ThorntailExtension.java    From thorntail with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BuildTool.FractionDetectionMode getFractionDetectionMode() {
    return fractionDetectMode;
}
 
Example #6
Source File: ThorntailExtension.java    From thorntail with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setFractionDetectionMode(BuildTool.FractionDetectionMode fractionDetectMode) {
    this.fractionDetectMode = fractionDetectMode;
}
 
Example #7
Source File: PackageTask.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@OutputFile
File getOutputFile() {
    return BuildTool.getOutputFile(getBaseName() + UBERJAR_SUFFIX + ".jar", getOutputDirectory());
}
 
Example #8
Source File: StartMojo.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
List<Path> dependencies(final Path archiveContent,
                        final boolean scanDependencies) throws MojoFailureException {
    final List<Path> elements = new ArrayList<>();
    final Set<Artifact> artifacts = this.project.getArtifacts();
    boolean hasSwarmDeps = false;

    List<Artifact> artifactsSorted = new ArrayList<>(artifacts.size());
    for (Artifact artifact : artifacts) {
        if (artifact.getGroupId().equals(FractionDescriptor.THORNTAIL_GROUP_ID)
                && artifact.getArtifactId().equals(DependencyManager.WILDFLY_SWARM_BOOTSTRAP_ARTIFACT_ID)) {
            artifactsSorted.add(0, artifact);
        } else {
            artifactsSorted.add(artifact);
        }
    }

    final DeclaredDependencies declaredDependencies = new DeclaredDependencies();

    for (Artifact each : artifactsSorted) {

        String parentDep = each.getDependencyTrail().get(1);

        declaredDependencies.add(DeclaredDependencies.createSpec(parentDep), DeclaredDependencies.createSpec(each.toString()));

        if (each.getGroupId().equals(FractionDescriptor.THORNTAIL_GROUP_ID)
                && each.getArtifactId().equals(DependencyManager.WILDFLY_SWARM_BOOTSTRAP_ARTIFACT_ID)) {
            hasSwarmDeps = true;
        }
        if (each.getGroupId().equals("org.jboss.logmanager")
                && each.getArtifactId().equals("jboss-logmanager")) {
            continue;
        }
        if (each.getScope().equals("provided")) {
            continue;
        }
        elements.add(each.getFile().toPath());
    }

    if (declaredDependencies.getDirectDeps().size() > 0) {
        try {

            // multi-start doesn't have a projectBuildDir

            File tmp = this.projectBuildDir != null ?
                    Files.createTempFile(Paths.get(this.projectBuildDir), TempFileManager.WFSWARM_TMP_PREFIX, "-cp.txt").toFile() :
                    Files.createTempFile(TempFileManager.WFSWARM_TMP_PREFIX, "-cp.txt").toFile();

            tmp.deleteOnExit();
            getPluginContext().put("thorntail-cp-file", tmp);
            declaredDependencies.writeTo(tmp);
            getLog().debug("dependency info stored at: " + tmp.getAbsolutePath());
            this.properties.setProperty("thorntail.cp.info", tmp.getAbsolutePath());

        } catch (IOException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    elements.add(Paths.get(this.project.getBuild().getOutputDirectory()));

    if (fractionDetectMode != BuildTool.FractionDetectionMode.never) {
        if (fractionDetectMode == BuildTool.FractionDetectionMode.force ||
                !hasSwarmDeps) {
            List<Path> fractionDeps = findNeededFractions(artifactsSorted, archiveContent, scanDependencies);
            for (Path p : fractionDeps) {
                if (!elements.contains(p)) {
                    elements.add(p);
                }
            }
        }
    } else if (!hasSwarmDeps) {
        getLog().warn("No Thorntail dependencies found and fraction detection disabled");
    }

    return elements;
}
 
Example #9
Source File: PackageMojo.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    initProperties(false);

    final BuildTool tool = new BuildTool();

    tool.projectArtifact(
            this.project.getArtifact().getGroupId(),
            this.project.getArtifact().getArtifactId(),
            this.project.getArtifact().getBaseVersion(),
            this.project.getArtifact().getType(),
            this.project.getArtifact().getFile());


    this.project.getArtifacts()
            .forEach(dep -> tool.dependency(dep.getScope(),
                    dep.getGroupId(),
                    dep.getArtifactId(),
                    dep.getBaseVersion(),
                    dep.getType(),
                    dep.getClassifier(),
                    dep.getFile(),
                    dep.getDependencyTrail().size() == 2));

    List<Resource> resources = this.project.getResources();
    for (Resource each : resources) {
        tool.resourceDirectory(each.getDirectory());
    }

    for (String additionalModule : additionalModules) {
        File source = new File(this.project.getBuild().getOutputDirectory(), additionalModule);
        if (source.exists()) {
            tool.additionalModule(source.getAbsolutePath());
        }
    }

    tool
            .properties(this.properties)
            .mainClass(this.mainClass)
            .bundleDependencies(this.bundleDependencies);

    MavenArtifactResolvingHelper resolvingHelper = new MavenArtifactResolvingHelper(this.resolver,
            this.repositorySystem,
            this.repositorySystemSession);
    this.remoteRepositories.forEach(resolvingHelper::remoteRepository);

    tool.artifactResolvingHelper(resolvingHelper);

    try {
        File jar = tool.build(this.project.getBuild().getFinalName(), Paths.get(this.projectBuildDir));

        Artifact primaryArtifact = this.project.getArtifact();

        ArtifactHandler handler = new DefaultArtifactHandler("jar");
        Artifact swarmJarArtifact = new DefaultArtifact(
                primaryArtifact.getGroupId(),
                primaryArtifact.getArtifactId(),
                primaryArtifact.getBaseVersion(),
                primaryArtifact.getScope(),
                "jar",
                "swarm",
                handler
        );

        swarmJarArtifact.setFile(jar);

        this.project.addAttachedArtifact(swarmJarArtifact);
    } catch (Exception e) {
        throw new MojoFailureException("Unable to create -swarm.jar", e);
    }
}
 
Example #10
Source File: Build.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public File run() throws Exception {
    final String[] parts = this.source.getName().split("\\.(?=[^\\.]+$)");
    final String baseName = parts[0];
    final String type = parts[1] == null ? "jar" : parts[1];
    final MavenRemoteRepository jbossPublic =
            MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group",
                    "http://repository.jboss.org/nexus/content/groups/public/",
                    "default");
    jbossPublic.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
    jbossPublic.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);

    final ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
            .withMavenCentralRepo(true)
            .withRemoteRepo(jbossPublic);

    final BuildTool tool = new BuildTool()
            .artifactResolvingHelper(new ShrinkwrapArtifactResolvingHelper(resolver))
            .projectArtifact("", baseName, "", type, this.source)
            .resolveTransitiveDependencies(true)
            .properties(this.properties);

    if (this.autoDetectFractions) {
        this.swarmDependencies.addAll(new PackageAnalyzer(this.source).detectNeededFractions());
    } else {
        System.err.println("Skipping fraction auto-detection");
    }

    for (String dep : this.swarmDependencies) {
        tool.dependency("compile", "org.wildfly.swarm", dep, this.version, "jar", null, null, true);
    }

    final String jarName = this.name != null ? this.name : baseName;
    final String outDir = this.outputDir.getCanonicalPath();
    System.err.println(String.format("Building %s/%s-swarm.jar with fractions: %s",
            outDir,
            jarName,
            String.join(", ",
                    allRequiredFractions()
                            .stream()
                            .sorted()
                            .collect(Collectors.toList()))));

    return tool.build(jarName, Paths.get(outDir));
}
 
Example #11
Source File: ThorntailConfiguration.java    From thorntail with Apache License 2.0 2 votes vote down vote up
/**
 * Get the fraction detection mode for the Thorntail application.
 *
 * @return the fraction detection mode for this project.
 */
BuildTool.FractionDetectionMode getFractionDetectionMode();
 
Example #12
Source File: ThorntailConfiguration.java    From thorntail with Apache License 2.0 2 votes vote down vote up
/**
 * Set the fraction detection mode for this project.
 *
 * @param mode the fraction detection mode for this project.
 */
void setFractionDetectionMode(BuildTool.FractionDetectionMode mode);