diff --git a/maven-release-plugin/src/it/projects/prepare/version-policy/pom.xml b/maven-release-plugin/src/it/projects/prepare/version-policy/pom.xml new file mode 100644 index 000000000..c896d0f22 --- /dev/null +++ b/maven-release-plugin/src/it/projects/prepare/version-policy/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + org.apache.maven.plugin.release.it + version-policy + 0.1.2-SNAPSHOT + + scm:dummytags|nul + scm:dummytags|nul + + + + + org.apache.maven.plugins + maven-release-plugin + @project.version@ + + DummyVersionPolicy + One + + + + org.apache.maven.its.release + maven-scm-provider-dummy + 1.0 + + + + org.apache.maven.its.release + maven-version-policy-dummy + 1.0 + + + + + + diff --git a/maven-release-plugin/src/it/projects/prepare/version-policy/verify.groovy b/maven-release-plugin/src/it/projects/prepare/version-policy/verify.groovy new file mode 100644 index 000000000..c8dce3a14 --- /dev/null +++ b/maven-release-plugin/src/it/projects/prepare/version-policy/verify.groovy @@ -0,0 +1,56 @@ +/* + * Conventional Commits Version Policy + * Copyright (C) 2022-2023 Niels Basjes + * + * Licensed 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 + * + * https://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. + */ + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.exists() + +assert 1 == buildLog.getText().count("[INPUT:Version] #0.1.2-SNAPSHOT#") + +assert 1 == buildLog.getText().count("[INPUT:Config] #One") + +// Only check the last part to avoid path separator issues on Windows and such +assert 1 == buildLog.getText().count("version-policy# [INPUT:WorkingDirectory]") + +// Do we get comments and tags? +assert 1 == buildLog.getText().count("[INPUT:Changeset[0].comment] #Commit 19#") +assert 1 == buildLog.getText().count("[INPUT:Changeset[0].tag] ##") + +assert 1 == buildLog.getText().count("[INPUT:Changeset[4].comment] #Commit 15#") +assert 1 == buildLog.getText().count("[INPUT:Changeset[4].tag] #tag 1,tag 2#") +assert 1 == buildLog.getText().count("[INPUT:Changeset[5].comment] #feat(it): This is a new feature.#") +assert 1 == buildLog.getText().count("[INPUT:Changeset[5].tag] ##") + +assert 1 == buildLog.getText().count("[INPUT:Changeset[13].comment] #Commit 6#") +assert 1 == buildLog.getText().count("[INPUT:Changeset[13].tag] #tag 4#") + +assert 1 == buildLog.getText().count("[INPUT:Changeset[17].comment] #Commit 2#") +assert 1 == buildLog.getText().count("[INPUT:Changeset[17].tag] #v1.2.3#") + +// The pom based version is NOT related to what the actual version will be. +File pomXml = new File( basedir, 'pom.xml' ) +assert pomXml.exists() +assert new XmlSlurper().parse( pomXml ).version.text() == "0.1.2-SNAPSHOT" + +// The actual version is hard coded +File pomXmlTag = new File( basedir, 'pom.xml.tag' ) +assert pomXmlTag.exists() +assert new XmlSlurper().parse( pomXmlTag ).version.text() == "1.2.3" + +// The next development version is hard coded +File pomXmlNext = new File( basedir, 'pom.xml.next' ) +assert pomXmlNext.exists() +assert new XmlSlurper().parse( pomXmlNext ).version.text() == "4.5.6-SNAPSHOT" diff --git a/maven-release-plugin/src/it/setup/maven-version-policy-dummy/invoker.properties b/maven-release-plugin/src/it/setup/maven-version-policy-dummy/invoker.properties new file mode 100644 index 000000000..d5d6ca5db --- /dev/null +++ b/maven-release-plugin/src/it/setup/maven-version-policy-dummy/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.goals = install diff --git a/maven-release-plugin/src/it/setup/maven-version-policy-dummy/pom.xml b/maven-release-plugin/src/it/setup/maven-version-policy-dummy/pom.xml new file mode 100644 index 000000000..09a489c55 --- /dev/null +++ b/maven-release-plugin/src/it/setup/maven-version-policy-dummy/pom.xml @@ -0,0 +1,102 @@ + + + + + 4.0.0 + + org.apache.maven.its.release + maven-version-policy-dummy + 1.0 + + Maven Version Policy Dummy + + Provides a dummy version policy. It will ALWAYS output version 1.2.3 and log the provided settings. + + + + 1.8 + 8 + UTF-8 + UTF-8 + ${target.java.version} + ${target.java.version} + ${target.java.release} + + + + + org.apache.maven.release + maven-release-api + @project.version@ + + + + org.apache.maven.scm + maven-scm-api + @scmVersion@ + + + + org.eclipse.sisu + org.eclipse.sisu.inject + @sisuVersion@ + provided + + + + javax.inject + javax.inject + 1 + + + + org.slf4j + slf4j-simple + @slf4jVersion@ + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @mavenCompilerPluginVersion@ + + UTF-8 + + + + org.eclipse.sisu + sisu-maven-plugin + @sisuVersion@ + + + index-project + + main-index + + + + + + + diff --git a/maven-release-plugin/src/it/setup/maven-version-policy-dummy/src/main/java/org/apache/maven/its/release/version/DummyVersionPolicy.java b/maven-release-plugin/src/it/setup/maven-version-policy-dummy/src/main/java/org/apache/maven/its/release/version/DummyVersionPolicy.java new file mode 100644 index 000000000..221d1bee3 --- /dev/null +++ b/maven-release-plugin/src/it/setup/maven-version-policy-dummy/src/main/java/org/apache/maven/its/release/version/DummyVersionPolicy.java @@ -0,0 +1,82 @@ +/* + * 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. + */ + +package org.apache.maven.its.release.version; + +import org.apache.maven.scm.ChangeSet; +import org.apache.maven.scm.ScmException; +import org.apache.maven.scm.ScmFileSet; +import org.apache.maven.scm.command.changelog.ChangeLogScmRequest; +import org.apache.maven.scm.command.changelog.ChangeLogScmResult; +import org.apache.maven.shared.release.policy.version.VersionPolicy; +import org.apache.maven.shared.release.policy.version.VersionPolicyRequest; +import org.apache.maven.shared.release.policy.version.VersionPolicyResult; +import org.apache.maven.shared.release.versions.VersionParseException; +import org.eclipse.sisu.Description; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Named; +import javax.inject.Singleton; +import java.io.File; + +@Singleton +@Named( "DummyVersionPolicy" ) +@Description( "A dummy VersionPolicy that always gives version 1.2.3. and only logs the provided input." ) +public class DummyVersionPolicy implements VersionPolicy +{ + private static final Logger LOG = LoggerFactory.getLogger( DummyVersionPolicy.class ); + + public VersionPolicyResult getReleaseVersion( VersionPolicyRequest request ) + { + LOG.info("[INPUT:Config] #{}# [INPUT:Config]", request.getConfig()); + LOG.info("[INPUT:Version] #{}# [INPUT:Version]", request.getVersion()); + LOG.info("[INPUT:WorkingDirectory] #{}# [INPUT:WorkingDirectory]", request.getWorkingDirectory()); + + ChangeLogScmRequest changeLogRequest = new ChangeLogScmRequest( + request.getScmRepository(), + new ScmFileSet(new File(request.getWorkingDirectory())) + ); + + ChangeLogScmResult changeLog; + try { + changeLog = request.getScmProvider().changeLog(changeLogRequest); + } catch (ScmException e) { + throw new RuntimeException(e); + } + + int index=0 ; + for (ChangeSet changeSet : changeLog.getChangeLog().getChangeSets()) { + LOG.info("[INPUT:Changeset[{}].comment] #{}#", index, changeSet.getComment()); + LOG.info("[INPUT:Changeset[{}].tag] #{}#", index, String.join(",", changeSet.getTags())); + index++; + } + + VersionPolicyResult result = new VersionPolicyResult(); + result.setVersion("1.2.3"); + return result; + } + + public VersionPolicyResult getDevelopmentVersion(VersionPolicyRequest request) + throws VersionParseException { + VersionPolicyResult result = new VersionPolicyResult(); + result.setVersion("4.5.6-SNAPSHOT"); + return result; + } +}