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

[MINVOKER-289] - Support for shared invoker's Update-Snapshots Flag #146

Merged
merged 1 commit into from Sep 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/it/MINVOKER-289/pom.xml
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.invoker</groupId>
<artifactId>update-snapshots</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<description>Test to check that update snapshots gets set in the shared maven invoker</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>@pom.version@</version>
<configuration>
<writeJunitReport>true</writeJunitReport>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<goals>
<goal>validate</goal>
</goals>
<updateSnapshots>true</updateSnapshots>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
32 changes: 32 additions & 0 deletions src/it/MINVOKER-289/src/it/project/pom.xml
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>update-snapshot</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
24 changes: 24 additions & 0 deletions src/it/MINVOKER-289/src/it/project/prebuild.bsh
@@ -0,0 +1,24 @@
/*
* 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 java.io.*;

// marker for parent build that this sub build was indeed run
File touchFile = new File( basedir, "touch.txt" );
touchFile.createNewFile();
36 changes: 36 additions & 0 deletions src/it/MINVOKER-289/verify.groovy
@@ -0,0 +1,36 @@
import java.lang.reflect.Array
import java.util.stream.Collectors

/*
* 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.
*/

assert new File( basedir, 'target/it/project/touch.txt' )

File buildLog = new File( basedir, 'build.log' )

String executionString = "Executing:"
int mavenCommandIndex = buildLog.text.indexOf( executionString )
String commandLine = buildLog.text.substring( mavenCommandIndex, buildLog.text.indexOf( System.lineSeparator(),
mavenCommandIndex ) )
commandLine = commandLine.substring(commandLine.indexOf("mvn"));
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved

assert Arrays.stream( commandLine.split( '\\s' ) )
.map( f -> f.replaceAll('\'', ''))
.filter(f -> f == '-U')
.count() > 0
Expand Up @@ -595,6 +595,11 @@ public abstract class AbstractInvokerMojo
* invoker.environmentVariables.&lt;variableName&gt; = variableValue
* invoker.environmentVariables.MY_ENV_NAME = myEnvValue
*
* # A boolean value indicating a check for missing releases and updated snapshots on remote repositories to be done
* # Passed to the invoker. Same as passing -U, --update-snapshots flag on the command line
* # Since plugin version 3.4.0
* invoker.updateSnapshots = true
*
* </pre>
*
* @since 1.2
Expand Down Expand Up @@ -677,6 +682,15 @@ public abstract class AbstractInvokerMojo
@Parameter( defaultValue = "false", property = "invoker.updateOnly" )
private boolean updateOnly = false;

/**
* Force a check for missing releases and updated snapshots on remote repositories. This is passed to the invoked
* maven projects (it is the same as if you were to use the -U, --update-snapshots flag on the command line).
*
* @since 3.4.0
*/
edwardUL99 marked this conversation as resolved.
Show resolved Hide resolved
@Parameter( defaultValue = "false", property = "invoker.updateSnapshots" )
private boolean updateSnapshots;

// internal state variables

/**
Expand Down Expand Up @@ -2684,6 +2698,7 @@ private InvokerProperties getInvokerProperties( final File projectDirectory, Pro
invokerProperties.setDefaultMavenOpts( mavenOpts );
invokerProperties.setDefaultTimeoutInSeconds( timeoutInSeconds );
invokerProperties.setDefaultEnvironmentVariables( environmentVariables );
invokerProperties.setDefaultUpdateSnapshots( updateSnapshots );


return invokerProperties;
Expand Down
Expand Up @@ -56,6 +56,7 @@ class InvokerProperties
private Integer defaultTimeoutInSeconds;
private Map<String, String> defaultEnvironmentVariables;
private File defaultMavenExecutable;
private Boolean defaultUpdateSnapshots;

private enum InvocationProperty
{
Expand All @@ -72,7 +73,8 @@ private enum InvocationProperty
DEBUG( "invoker.debug" ),
QUIET( "invoker.quiet" ),
SETTINGS_FILE( "invoker.settingsFile" ),
TIMEOUT_IN_SECONDS( "invoker.timeoutInSeconds" );
TIMEOUT_IN_SECONDS( "invoker.timeoutInSeconds" ),
UPDATE_SNAPSHOTS( "invoker.updateSnapshots" );

private final String key;

Expand Down Expand Up @@ -196,6 +198,15 @@ public void setDefaultEnvironmentVariables( Map<String, String> defaultEnvironme
this.defaultEnvironmentVariables = defaultEnvironmentVariables;
}

/**
* Default value for updateSnapshots
* @param defaultUpdateSnapshots a default value
*/
public void setDefaultUpdateSnapshots( boolean defaultUpdateSnapshots )
{
this.defaultUpdateSnapshots = defaultUpdateSnapshots;
}

/**
* Gets the invoker properties being wrapped.
*
Expand Down Expand Up @@ -476,6 +487,10 @@ public void configureInvocation( InvocationRequest request, int index )
.map( Integer::parseInt )
.orElse( defaultTimeoutInSeconds ) );

setIfNotNull( request::setUpdateSnapshots, get( InvocationProperty.UPDATE_SNAPSHOTS, index )
.map( Boolean::parseBoolean )
.orElse( defaultUpdateSnapshots ) );

edwardUL99 marked this conversation as resolved.
Show resolved Hide resolved
Optional.ofNullable( defaultEnvironmentVariables )
.ifPresent( evn -> evn.forEach( request::addShellEnvironment ) );

Expand Down
Expand Up @@ -454,6 +454,43 @@ public void testConfigureEnvironmentVariablesWithIndex()
verifyNoMoreInteractions( request );
}

@Test
public void testConfigureUpdateSnapshots()
{
Properties props = new Properties();
InvokerProperties facade = new InvokerProperties( props );

props.setProperty( "invoker.updateSnapshots", "true" );
facade.configureInvocation( request, 1 );
verify( request ).setUpdateSnapshots( true );
clearInvocations( request );
props.clear();

props.setProperty( "invoker.updateSnapshots", "false" );
facade.configureInvocation( request , 1 );
verify( request ).setUpdateSnapshots( false );

verifyNoMoreInteractions( request );
}

@Test
public void testConfigureUpdateSnapshotsDefault()
{
Properties props = new Properties();
InvokerProperties facade = new InvokerProperties( props );

facade.setDefaultUpdateSnapshots( true );
facade.configureInvocation( request, 1 );
verify( request ).setUpdateSnapshots( true );
clearInvocations( request );

facade.setDefaultUpdateSnapshots( false );
facade.configureInvocation( request, 1 );
verify( request ).setUpdateSnapshots( false );

verifyNoMoreInteractions( request );
}

@Test
public void testIsInvocationDefined()
{
Expand Down Expand Up @@ -541,5 +578,4 @@ public void testGetToolchainsWithIndex()
assertThat( toolchain.getType() ).isEqualTo( "jdk" );
assertThat( toolchain.getProvides() ).containsExactlyEntriesOf( Collections.singletonMap( "version", "11" ) );
}

}