Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check, that dev-mode is omitted on projects with pom packaging #1009

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
import static io.quarkus.test.utils.AwaitilityUtils.untilAsserted;
import static io.quarkus.ts.quarkus.cli.QuarkusCliUtils.defaultWithFixedStream;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand All @@ -27,6 +31,7 @@
import org.apache.http.HttpStatus;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.awaitility.core.ConditionTimeoutException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -264,6 +269,27 @@ public void verifyRestEasyReactiveAndClassicResteasyCollisionUserMsg() {
assertBuildError(buildResult, "io.quarkus:quarkus-resteasy");
}

@Test
public void devModeIgnoresPomPackaging() throws IOException {
QuarkusCliRestService app = cliClient.createApplication("pomApp", defaultWithFixedStream());
{//set packaging to POM
Path pom = getFileFromApplication(app, ROOT_FOLDER, "pom.xml").toPath();
List<String> content = Files.readAllLines(pom);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what about to use this maven lib:

<dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-model</artifactId>
            <scope>test</scope>
        </dependency>

And then parser / change the pom with something like

File pom = getFileFromApplication(app, ROOT_FOLDER, "pom.xml");
            MavenXpp3Reader reader = new MavenXpp3Reader();
            Model model = reader.read(new FileReader(pom));
            model.setPackaging("pom");

            MavenXpp3Writer mavenWriter = new MavenXpp3Writer();
            Writer writer = new FileWriter(pom.getPath());
            mavenWriter.write(writer, model);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need such advanced modifications. Read+replace is enough

for (int i = 0; i < content.size(); i++) {
String line = content.get(i);
if (line.endsWith("<artifactId>pomApp</artifactId>")) {
content.set(i, line + "<packaging>pom</packaging>");
break;
}
}
Files.write(pom, content);
}
// Start using DEV mode
assertEquals(Duration.ofSeconds(2), app.getConfiguration().getAsDuration("startup.timeout", null));
assertThrows(ConditionTimeoutException.class, app::start, "That application shouldn't start!");
app.logs().assertContains("Type of the artifact is POM, skipping dev goal");
}

private void assertBuildError(Result result, String expectedError) {
assertTrue(result.getOutput().contains(expectedError), "Unexpected build error message");
}
Expand Down Expand Up @@ -300,7 +326,6 @@ private void assertDockerJavaVersion(File dockerFile, String expectedVersion) {

Assertions.assertTrue(line.contains("openjdk-" + expectedVersion),
DOCKERFILE_JVM + " doesn't contains expected version " + expectedVersion);

} catch (FileNotFoundException e) {
fail(e.getMessage());
}
Expand Down
3 changes: 3 additions & 0 deletions quarkus-cli/src/test/resources/test.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
ts.global.generated-service.enabled=false
#this app is not expected to start, so let's fail right after
ts.pomApp.startup.timeout=PT2s
ts.pomApp.startup.check-poll-interval=PT1s