From a3af1904a86ea9278ada8934824d6d330f67512e Mon Sep 17 00:00:00 2001 From: Matthieu Brouillard Date: Tue, 29 Sep 2020 17:41:17 +0200 Subject: [PATCH] Fixed #44 - introduction of a maven extension sample --- itf-fixedversion-extension-example/pom.xml | 195 ++++++++++++++++++ .../FixedVersionModelProcessor.java | 65 ++++++ .../extensions/tests/FixedVersionIT.java | 48 +++++ .../.mvn/extensions.xml | 29 +++ .../should_use_fixed_version/pom.xml | 33 +++ pom.xml | 6 + 6 files changed, 376 insertions(+) create mode 100644 itf-fixedversion-extension-example/pom.xml create mode 100644 itf-fixedversion-extension-example/src/main/java/com/soebes/itf/maven/extensions/FixedVersionModelProcessor.java create mode 100644 itf-fixedversion-extension-example/src/test/java/com/soebes/itf/maven/extensions/tests/FixedVersionIT.java create mode 100644 itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/.mvn/extensions.xml create mode 100644 itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/pom.xml diff --git a/itf-fixedversion-extension-example/pom.xml b/itf-fixedversion-extension-example/pom.xml new file mode 100644 index 0000000000..89805d3f0e --- /dev/null +++ b/itf-fixedversion-extension-example/pom.xml @@ -0,0 +1,195 @@ + + + + + + + 4.0.0 + + + com.soebes.itf.jupiter.extension + itf-extension + 0.10.0-SNAPSHOT + + + itf-fixedversion-extension + + + + org.apache.maven + maven-model + + + org.apache.maven + maven-model-builder + + + org.slf4j + slf4j-nop + 1.7.5 + test + + + org.slf4j + slf4j-api + 1.7.5 + provided + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.assertj + assertj-core + test + + + com.soebes.itf.jupiter.extension + itf-assertj + ${project.version} + test + + + com.soebes.itf.jupiter.extension + itf-jupiter-extension + ${project.version} + test + + + + + + + src/test/resources + false + + + src/test/resources-its + true + + + + + + org.sonatype.plugins + sisu-maven-plugin + 1.1 + + + generate-index + + main-index + + + + + + org.codehaus.plexus + plexus-component-metadata + 1.7.1 + + + + generate-metadata + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.6.0 + + + default-descriptor + process-classes + + + generate-helpmojo + + helpmojo + + + + + + org.codehaus.plexus + plexus-component-metadata + 2.1.0 + + + org.apache.maven.plugins + maven-invoker-plugin + + + install-artifacts + + install + + + + ${project.build.directory}/itf-repo + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + 5 + true + + **/*IT.java + + + ${maven.version} + ${maven.home} + + + + junit.jupiter.execution.parallel.enabled = true + junit.jupiter.execution.parallel.mode.default = concurrent + + + + + + + integration-test + verify + + + + + + + \ No newline at end of file diff --git a/itf-fixedversion-extension-example/src/main/java/com/soebes/itf/maven/extensions/FixedVersionModelProcessor.java b/itf-fixedversion-extension-example/src/main/java/com/soebes/itf/maven/extensions/FixedVersionModelProcessor.java new file mode 100644 index 0000000000..972ede1855 --- /dev/null +++ b/itf-fixedversion-extension-example/src/main/java/com/soebes/itf/maven/extensions/FixedVersionModelProcessor.java @@ -0,0 +1,65 @@ +package com.soebes.itf.maven.extensions; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.model.Model; +import org.apache.maven.model.building.DefaultModelProcessor; +import org.apache.maven.model.building.ModelProcessor; +import org.codehaus.plexus.component.annotations.Component; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.util.Map; + +@Component(role = ModelProcessor.class) +public class FixedVersionModelProcessor extends DefaultModelProcessor { + private final Logger LOGGER = LoggerFactory.getLogger( getClass() ); + + @Override + public Model read(File input, Map options) throws IOException { + return provisionModel(super.read(input, options), options); + } + + @Override + public Model read(Reader input, Map options) throws IOException { + return provisionModel(super.read(input, options), options); + } + + @Override + public Model read(InputStream input, Map options) throws IOException { + return provisionModel(super.read(input, options), options); + } + + private Model provisionModel(Model model, Map options) throws IOException { + String oldVersion = model.getVersion(); + String newVersion = "1.0-fixed"; + + if (oldVersion != null) { + LOGGER.info("changing {} version from {} to {}", model.getArtifactId(), oldVersion, newVersion); + model.setVersion(newVersion); + } + + return model; + } +} \ No newline at end of file diff --git a/itf-fixedversion-extension-example/src/test/java/com/soebes/itf/maven/extensions/tests/FixedVersionIT.java b/itf-fixedversion-extension-example/src/test/java/com/soebes/itf/maven/extensions/tests/FixedVersionIT.java new file mode 100644 index 0000000000..7f222acf64 --- /dev/null +++ b/itf-fixedversion-extension-example/src/test/java/com/soebes/itf/maven/extensions/tests/FixedVersionIT.java @@ -0,0 +1,48 @@ +package com.soebes.itf.maven.extensions.tests; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.soebes.itf.jupiter.extension.MavenJupiterExtension; +import com.soebes.itf.jupiter.extension.MavenOption; +import com.soebes.itf.jupiter.extension.MavenTest; +import com.soebes.itf.jupiter.maven.MavenExecutionResult; +import org.junit.jupiter.api.DisplayName; + +import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; +import static com.soebes.itf.jupiter.extension.MavenCLIOptions.DEBUG; +import static com.soebes.itf.jupiter.extension.MavenCLIOptions.NO_TRANSFER_PROGRESS; + +@MavenJupiterExtension +public class FixedVersionIT { + @MavenTest + @MavenOption(NO_TRANSFER_PROGRESS) + @MavenOption(DEBUG) + @DisplayName("Simple test with fixed-version extension.") + public void should_use_fixed_version(MavenExecutionResult result) { + assertThat(result).isSuccessful(); + + // TODO correct ITF so that Model is taken from execution not from POM file + // and thus version will not be 0 but the one set by the fixed-version extension + assertThat(result.getMavenProjectResult().getModel().getVersion()).isEqualTo("0"); + + // TODO use the check below when correction is done + // assertThat(result.getMavenProjectResult().getModel().getVersion()).isEqualTo("1.0-fixed"); + } +} diff --git a/itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/.mvn/extensions.xml b/itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/.mvn/extensions.xml new file mode 100644 index 0000000000..af214d481d --- /dev/null +++ b/itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/.mvn/extensions.xml @@ -0,0 +1,29 @@ + + + + + + + com.soebes.itf.jupiter.extension + itf-fixedversion-extension + @project.version@ + + \ No newline at end of file diff --git a/itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/pom.xml b/itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/pom.xml new file mode 100644 index 0000000000..138d32e102 --- /dev/null +++ b/itf-fixedversion-extension-example/src/test/resources-its/com/soebes/itf/maven/extensions/tests/FixedVersionIT/should_use_fixed_version/pom.xml @@ -0,0 +1,33 @@ + + + + + + 4.0.0 + + com.soebes.itf.maven.plugin.its + simple-use-fixed-version-extension + 0 + pom + + ITF Maven Plugin - FixedVersionIT#should_use_fixed_version :: ${project.version} + Version of this project should be fixed and provided by an extension. + + diff --git a/pom.xml b/pom.xml index c9f25d08be..8ec038532a 100644 --- a/pom.xml +++ b/pom.xml @@ -133,6 +133,11 @@ maven-model 3.1.0 + + org.apache.maven + maven-model-builder + 3.1.0 + net.bytebuddy byte-buddy @@ -228,6 +233,7 @@ itf-jupiter-extension itf-assertj itf-extension-maven + itf-fixedversion-extension-example itf-examples itf-documentation