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();
}
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();
}
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"));
}
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"));
}
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;
}
Aggregations