Search in sources :

Example 6 with ApplicationEnvironment

use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.

the class ArtifactManager method determineVersionViaApplicationEnvironment.

String determineVersionViaApplicationEnvironment(String groupId, String artifactId, String packaging, String classifier) throws IOException {
    ApplicationEnvironment env = ApplicationEnvironment.get();
    if (classifier.isEmpty()) {
        classifier = null;
    }
    for (String dep : env.getDependencies()) {
        String[] parts = dep.split(COLON);
        String depGroupId = parts[0];
        String depArtifactId = parts[1];
        String depPackaging = parts[2];
        String depVersion = null;
        String depClassifier = null;
        if (parts.length == 4) {
            depVersion = parts[3];
        } else {
            depClassifier = parts[3];
            depVersion = parts[4];
        }
        if (groupId.equals(depGroupId)) {
            if (artifactId.equals(depArtifactId)) {
                if (packaging.equals(depPackaging)) {
                    if (classifier == null) {
                        if (depClassifier == null) {
                            return depVersion;
                        }
                    } else {
                        if (depClassifier != null && classifier.equals(depClassifier)) {
                            return depVersion;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ApplicationEnvironment(org.wildfly.swarm.bootstrap.env.ApplicationEnvironment)

Example 7 with ApplicationEnvironment

use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.

the class BootstrapModuleFinder method buildModule.

@Override
public void buildModule(ModuleSpec.Builder builder, ModuleLoader delegateLoader) throws ModuleLoadException {
    try (AutoCloseable handle = Performance.accumulate("module: Bootstrap")) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Loading module");
        }
        ApplicationEnvironment env = ApplicationEnvironment.get();
        PathFilter filter = new PathFilter() {

            @Override
            public boolean accept(String path) {
                return path.endsWith("/module.xml");
            }
        };
        env.bootstrapArtifactsAsCoordinates().forEach((coords) -> {
            try {
                File artifact = MavenResolvers.get().resolveJarArtifact(coords);
                if (artifact == null) {
                    throw new RuntimeException("Unable to resolve artifact from coordinates: " + coords);
                }
                JarFile jar = JarFileManager.INSTANCE.addJarFile(artifact);
                ResourceLoader originaloader = ResourceLoaders.createJarResourceLoader(artifact.getName(), jar);
                builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createFilteredResourceLoader(filter, originaloader)));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        builder.addDependency(DependencySpec.createLocalDependencySpec());
        builder.addDependency(DependencySpec.createModuleDependencySpec("org.jboss.modules"));
        builder.addDependency(DependencySpec.createModuleDependencySpec("org.jboss.shrinkwrap"));
        builder.addDependency(DependencySpec.createModuleDependencySpec("org.yaml.snakeyaml"));
        HashSet<String> paths = new HashSet<>();
        paths.add("org/wildfly/swarm/bootstrap/env");
        paths.add("org/wildfly/swarm/bootstrap/logging");
        paths.add("org/wildfly/swarm/bootstrap/modules");
        paths.add("org/wildfly/swarm/bootstrap/performance");
        paths.add("org/wildfly/swarm/bootstrap/util");
        builder.addDependency(DependencySpec.createSystemDependencySpec(paths, true));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ResourceLoader(org.jboss.modules.ResourceLoader) PathFilter(org.jboss.modules.filter.PathFilter) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ApplicationEnvironment(org.wildfly.swarm.bootstrap.env.ApplicationEnvironment) JarFile(java.util.jar.JarFile) File(java.io.File) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException) HashSet(java.util.HashSet)

Example 8 with ApplicationEnvironment

use of org.wildfly.swarm.bootstrap.env.ApplicationEnvironment in project wildfly-swarm by wildfly-swarm.

the class ApplicationModuleFinderTest method testDependencyHasClassifier.

@Test
public void testDependencyHasClassifier() {
    // Mocks
    ApplicationEnvironment env = mock(ApplicationEnvironment.class);
    when(env.getDependencies()).thenReturn(Collections.singleton("org.jboss.forge.addon:ui-spi:jar:forge-addon:3.4.0.Final"));
    ModuleSpec.Builder builder = mock(ModuleSpec.Builder.class);
    ApplicationModuleFinder sut = new ApplicationModuleFinder();
    sut.addDependencies(builder, env);
    verify(builder, times(1)).addResourceRoot(any());
}
Also used : ModuleSpec(org.jboss.modules.ModuleSpec) ApplicationEnvironment(org.wildfly.swarm.bootstrap.env.ApplicationEnvironment) Test(org.junit.Test)

Aggregations

ApplicationEnvironment (org.wildfly.swarm.bootstrap.env.ApplicationEnvironment)8 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 ModuleLoadException (org.jboss.modules.ModuleLoadException)2 ModuleSpec (org.jboss.modules.ModuleSpec)2 ExplodedImporter (org.jboss.shrinkwrap.api.importer.ExplodedImporter)2 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)2 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)2 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 JarFile (java.util.jar.JarFile)1