Java Code Examples for org.wildfly.swarm.tools.BuildTool#additionalModule()

The following examples show how to use org.wildfly.swarm.tools.BuildTool#additionalModule() . 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: 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 2
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);
    }
}