Search in sources :

Example 1 with ArtifactSources

use of io.quarkus.bootstrap.workspace.ArtifactSources in project quarkus by quarkusio.

the class QuarkusModelBuilderTest method shouldLoadSimpleModuleDevModel.

@Test
public void shouldLoadSimpleModuleDevModel() throws URISyntaxException, IOException {
    File projectDir = getResourcesProject("builder/simple-module-project");
    final ApplicationModel quarkusModel = QuarkusGradleModelFactory.create(projectDir, "DEVELOPMENT");
    assertNotNull(quarkusModel);
    assertNotNull(quarkusModel.getApplicationModule());
    assertThat(quarkusModel.getWorkspaceModules()).isEmpty();
    final ResolvedDependency appArtifact = quarkusModel.getAppArtifact();
    assertThat(appArtifact).isNotNull();
    assertThat(appArtifact.getWorkspaceModule()).isNotNull();
    final ArtifactSources testSources = appArtifact.getWorkspaceModule().getTestSources();
    assertThat(testSources).isNotNull();
}
Also used : ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with ArtifactSources

use of io.quarkus.bootstrap.workspace.ArtifactSources in project quarkus by quarkusio.

the class QuarkusModelBuilderTest method shouldLoadSimpleModuleTestModel.

@Test
public void shouldLoadSimpleModuleTestModel() throws URISyntaxException, IOException {
    File projectDir = getResourcesProject("builder/simple-module-project");
    final ApplicationModel quarkusModel = QuarkusGradleModelFactory.create(projectDir, "TEST");
    assertNotNull(quarkusModel);
    assertNotNull(quarkusModel.getApplicationModule());
    assertThat(quarkusModel.getWorkspaceModules()).isEmpty();
    final ResolvedDependency appArtifact = quarkusModel.getAppArtifact();
    assertThat(appArtifact).isNotNull();
    assertThat(appArtifact.getWorkspaceModule()).isNotNull();
    final ArtifactSources testSources = appArtifact.getWorkspaceModule().getTestSources();
    assertThat(testSources).isNotNull();
}
Also used : ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with ArtifactSources

use of io.quarkus.bootstrap.workspace.ArtifactSources in project quarkus by quarkusio.

the class QuarkusModelBuilderTest method shouldLoadMultiModuleDevModel.

@Test
public void shouldLoadMultiModuleDevModel() throws URISyntaxException, IOException {
    File projectDir = getResourcesProject("builder/multi-module-project");
    final ApplicationModel quarkusModel = QuarkusGradleModelFactory.create(new File(projectDir, "application"), "DEVELOPMENT");
    assertNotNull(quarkusModel);
    assertProjectModule(quarkusModel.getApplicationModule(), new File(projectDir, quarkusModel.getApplicationModule().getId().getArtifactId()), true);
    final Collection<WorkspaceModule> projectModules = quarkusModel.getWorkspaceModules();
    assertEquals(projectModules.size(), 1);
    for (WorkspaceModule p : projectModules) {
        assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), false);
    }
    final ResolvedDependency appArtifact = quarkusModel.getAppArtifact();
    assertThat(appArtifact).isNotNull();
    assertThat(appArtifact.getWorkspaceModule()).isNotNull();
    final ArtifactSources testSources = appArtifact.getWorkspaceModule().getTestSources();
    assertThat(testSources).isNotNull();
    assertThat(testSources.getSourceDirs().size()).isEqualTo(1);
    final SourceDir testSrcDir = testSources.getSourceDirs().iterator().next();
    assertThat(testSrcDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("java"));
    assertThat(testSources.getResourceDirs().size()).isEqualTo(1);
    final SourceDir testResourcesDir = testSources.getResourceDirs().iterator().next();
    assertThat(testResourcesDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("resources"));
}
Also used : SourceDir(io.quarkus.bootstrap.workspace.SourceDir) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with ArtifactSources

use of io.quarkus.bootstrap.workspace.ArtifactSources in project quarkus by quarkusio.

the class QuarkusModelBuilderTest method shouldLoadMultiModuleTestModel.

@Test
public void shouldLoadMultiModuleTestModel() throws URISyntaxException, IOException {
    File projectDir = getResourcesProject("builder/multi-module-project");
    final ApplicationModel quarkusModel = QuarkusGradleModelFactory.create(new File(projectDir, "application"), "TEST");
    assertNotNull(quarkusModel);
    assertProjectModule(quarkusModel.getApplicationModule(), new File(projectDir, quarkusModel.getApplicationModule().getId().getArtifactId()), true);
    final Collection<WorkspaceModule> projectModules = quarkusModel.getWorkspaceModules();
    assertEquals(projectModules.size(), 1);
    for (WorkspaceModule p : projectModules) {
        assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), false);
    }
    final ResolvedDependency appArtifact = quarkusModel.getAppArtifact();
    assertThat(appArtifact).isNotNull();
    assertThat(appArtifact.getWorkspaceModule()).isNotNull();
    final ArtifactSources testSources = appArtifact.getWorkspaceModule().getTestSources();
    assertThat(testSources).isNotNull();
    assertThat(testSources.getSourceDirs().size()).isEqualTo(1);
    final SourceDir testSrcDir = testSources.getSourceDirs().iterator().next();
    assertThat(testSrcDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("java"));
    assertThat(testSources.getResourceDirs().size()).isEqualTo(1);
    final SourceDir testResourcesDir = testSources.getResourceDirs().iterator().next();
    assertThat(testResourcesDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("resources"));
}
Also used : SourceDir(io.quarkus.bootstrap.workspace.SourceDir) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with ArtifactSources

use of io.quarkus.bootstrap.workspace.ArtifactSources in project quarkus by quarkusio.

the class IntegrationTestUtil method handleDevServices.

static ArtifactLauncher.InitContext.DevServicesLaunchResult handleDevServices(ExtensionContext context, boolean isDockerAppLaunch) throws Exception {
    Class<?> requiredTestClass = context.getRequiredTestClass();
    Path testClassLocation = getTestClassesLocation(requiredTestClass);
    final Path appClassLocation = getAppClassLocationForTestLocation(testClassLocation.toString());
    final PathList.Builder rootBuilder = PathList.builder();
    if (!appClassLocation.equals(testClassLocation)) {
        rootBuilder.add(testClassLocation);
        // if test classes is a dir, we should also check whether test resources dir exists as a separate dir (gradle)
        // TODO: this whole app/test path resolution logic is pretty dumb, it needs be re-worked using proper workspace discovery
        final Path testResourcesLocation = PathTestHelper.getResourcesForClassesDirOrNull(testClassLocation, "test");
        if (testResourcesLocation != null) {
            rootBuilder.add(testResourcesLocation);
        }
    }
    final QuarkusBootstrap.Builder runnerBuilder = QuarkusBootstrap.builder().setIsolateDeployment(true).setMode(QuarkusBootstrap.Mode.TEST);
    final Path projectRoot = Paths.get("").normalize().toAbsolutePath();
    runnerBuilder.setProjectRoot(projectRoot);
    runnerBuilder.setTargetDirectory(PathTestHelper.getProjectBuildDir(projectRoot, testClassLocation));
    rootBuilder.add(appClassLocation);
    final Path appResourcesLocation = PathTestHelper.getResourcesForClassesDirOrNull(appClassLocation, "main");
    if (appResourcesLocation != null) {
        rootBuilder.add(appResourcesLocation);
    }
    // If gradle project running directly with IDE
    if (System.getProperty(BootstrapConstants.SERIALIZED_TEST_APP_MODEL) == null) {
        ApplicationModel model = BuildToolHelper.enableGradleAppModelForTest(projectRoot);
        if (model != null && model.getApplicationModule() != null) {
            final ArtifactSources testSources = model.getApplicationModule().getTestSources();
            if (testSources != null) {
                for (SourceDir src : testSources.getSourceDirs()) {
                    if (!Files.exists(src.getOutputDir())) {
                        final Path classes = src.getOutputDir();
                        if (!rootBuilder.contains(classes)) {
                            rootBuilder.add(classes);
                        }
                    }
                }
            }
            for (SourceDir src : model.getApplicationModule().getMainSources().getSourceDirs()) {
                if (!Files.exists(src.getOutputDir())) {
                    final Path classes = src.getOutputDir();
                    if (!rootBuilder.contains(classes)) {
                        rootBuilder.add(classes);
                    }
                }
            }
        }
    } else if (System.getProperty(BootstrapConstants.OUTPUT_SOURCES_DIR) != null) {
        final String[] sourceDirectories = System.getProperty(BootstrapConstants.OUTPUT_SOURCES_DIR).split(",");
        for (String sourceDirectory : sourceDirectories) {
            final Path directory = Paths.get(sourceDirectory);
            if (Files.exists(directory) && !rootBuilder.contains(directory)) {
                rootBuilder.add(directory);
            }
        }
    }
    runnerBuilder.setApplicationRoot(rootBuilder.build());
    CuratedApplication curatedApplication = runnerBuilder.setTest(true).build().bootstrap();
    Index testClassesIndex = TestClassIndexer.indexTestClasses(requiredTestClass);
    // we need to write the Index to make it reusable from other parts of the testing infrastructure that run in different ClassLoaders
    TestClassIndexer.writeIndex(testClassesIndex, requiredTestClass);
    Map<String, String> propertyMap = new HashMap<>();
    AugmentAction augmentAction;
    String networkId = null;
    if (isDockerAppLaunch) {
        // when the application is going to be launched as a docker container, we need to make containers started by DevServices
        // use a shared network that the application container can then use as well
        augmentAction = curatedApplication.createAugmentor("io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem$Factory", Collections.emptyMap());
    } else {
        augmentAction = curatedApplication.createAugmentor();
    }
    augmentAction.performCustomBuild(NativeDevServicesHandler.class.getName(), new BiConsumer<String, String>() {

        @Override
        public void accept(String s, String s2) {
            propertyMap.put(s, s2);
        }
    }, DevServicesLauncherConfigResultBuildItem.class.getName());
    boolean manageNetwork = false;
    if (isDockerAppLaunch) {
        // or else we run into various ClassLoader problems
        try {
            Class<?> networkClass = curatedApplication.getAugmentClassLoader().loadClass("org.testcontainers.containers.Network");
            Object sharedNetwork = networkClass.getField("SHARED").get(null);
            networkId = (String) networkClass.getMethod("getId").invoke(sharedNetwork);
        } catch (Exception e) {
            // use the network the use has specified or else just generate one if none is configured
            Config config = LauncherUtil.installAndGetSomeConfig();
            Optional<String> networkIdOpt = config.getOptionalValue("quarkus.test.container.network", String.class);
            if (networkIdOpt.isPresent()) {
                networkId = networkIdOpt.get();
            } else {
                networkId = "quarkus-integration-test-" + RandomStringUtils.random(5, true, false);
                manageNetwork = true;
            }
        }
    }
    DefaultDevServicesLaunchResult result = new DefaultDevServicesLaunchResult(propertyMap, networkId, manageNetwork, curatedApplication);
    createNetworkIfNecessary(result);
    return result;
}
Also used : DevServicesLauncherConfigResultBuildItem(io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem) HashMap(java.util.HashMap) Config(org.eclipse.microprofile.config.Config) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) Index(org.jboss.jandex.Index) Path(java.nio.file.Path) AugmentAction(io.quarkus.bootstrap.app.AugmentAction) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) Optional(java.util.Optional) PathList(io.quarkus.paths.PathList) URISyntaxException(java.net.URISyntaxException) JUnitException(org.junit.platform.commons.JUnitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources)

Aggregations

ArtifactSources (io.quarkus.bootstrap.workspace.ArtifactSources)10 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)7 SourceDir (io.quarkus.bootstrap.workspace.SourceDir)7 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)6 Path (java.nio.file.Path)5 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)4 PathList (io.quarkus.paths.PathList)4 File (java.io.File)4 Test (org.junit.jupiter.api.Test)4 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)3 QuarkusBootstrap (io.quarkus.bootstrap.app.QuarkusBootstrap)3 AugmentAction (io.quarkus.bootstrap.app.AugmentAction)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Index (org.jboss.jandex.Index)2 BootstrapConstants (io.quarkus.bootstrap.BootstrapConstants)1 AdditionalDependency (io.quarkus.bootstrap.app.AdditionalDependency)1 BootstrapMavenContext (io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext)1 MavenArtifactResolver (io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver)1