Skip to content

Commit

Permalink
[MINVOKER-286] Remove unused code corresponding to goals.txt, profile…
Browse files Browse the repository at this point in the history
…s.txt
  • Loading branch information
slawekjaranowski authored and slachiewicz committed Dec 1, 2021
1 parent 8b02cb6 commit e4236a7
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomWriter;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -102,7 +101,6 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -958,26 +956,6 @@ protected void doFailIfNoProjects()
abstract void processResults( InvokerSession invokerSession )
throws MojoFailureException;

/**
* Creates a new reader for the specified file, using the plugin's {@link #encoding} parameter.
*
* @param file The file to create a reader for, must not be <code>null</code>.
* @return The reader for the file, never <code>null</code>.
* @throws java.io.IOException If the specified file was not found or the configured encoding is not supported.
*/
private Reader newReader( File file )
throws IOException
{
if ( StringUtils.isNotEmpty( encoding ) )
{
return ReaderFactory.newReader( file, encoding );
}
else
{
return ReaderFactory.newPlatformReader( file );
}
}

/**
* Collects all projects locally reachable from the specified project. The method will as such try to read the POM
* and recursively follow its parent/module elements.
Expand Down Expand Up @@ -2018,10 +1996,6 @@ private boolean runBuild( File basedir, File pomFile, File settingsFile, File ac
}
}

List<String> goals = getGoals( basedir );

List<String> profiles = getProfiles( basedir );

Map<String, Object> context = new LinkedHashMap<>();

boolean selectorResult = true;
Expand Down Expand Up @@ -2354,48 +2328,6 @@ else if ( !invokerProperties.isExpectedResult( result.getExitCode(), invocationI
}
}

/**
* Gets the goal list for the specified project.
*
* @param basedir The base directory of the project, must not be <code>null</code>.
* @return The list of goals to run when building the project, may be empty but never <code>null</code>.
* @throws org.apache.maven.plugin.MojoExecutionException If the profile file could not be read.
*/
List<String> getGoals( final File basedir )
throws MojoExecutionException
{
try
{
// FIXME: Currently we have null for goalsFile which has been removed.
// This might mean we can remove getGoals() at all ? Check this.
return getTokens( basedir, null, goals );
}
catch ( IOException e )
{
throw new MojoExecutionException( "error reading goals", e );
}
}

/**
* Gets the profile list for the specified project.
*
* @param basedir The base directory of the project, must not be <code>null</code>.
* @return The list of profiles to activate when building the project, may be empty but never <code>null</code>.
* @throws org.apache.maven.plugin.MojoExecutionException If the profile file could not be read.
*/
List<String> getProfiles( File basedir )
throws MojoExecutionException
{
try
{
return getTokens( basedir, null, profiles );
}
catch ( IOException e )
{
throw new MojoExecutionException( "error reading profiles", e );
}
}

private List<String> calculateIncludes()
{
if ( invokerTest != null )
Expand Down Expand Up @@ -2671,86 +2603,6 @@ private static String toUrl( String filename )
return url;
}

/**
* Gets goal/profile names for the specified project, either directly from the plugin configuration or from an
* external token file.
*
* @param basedir The base directory of the test project, must not be <code>null</code>.
* @param filename The (simple) name of an optional file in the project base directory from which to read
* goals/profiles, may be <code>null</code>.
* @param defaultTokens The list of tokens to return in case the specified token file does not exist, may be
* <code>null</code>.
* @return The list of goal/profile names, may be empty but never <code>null</code>.
* @throws java.io.IOException If the token file exists but could not be parsed.
*/
private List<String> getTokens( File basedir, String filename, List<String> defaultTokens )
throws IOException
{
List<String> tokens = ( defaultTokens != null ) ? defaultTokens : new ArrayList<String>();

if ( StringUtils.isNotEmpty( filename ) )
{
File tokenFile = new File( basedir, filename );

if ( tokenFile.exists() )
{
tokens = readTokens( tokenFile );
}
}

return tokens;
}

/**
* Reads the tokens from the specified file. Tokens are separated either by line terminators or commas. During
* parsing, the file contents will be interpolated.
*
* @param tokenFile The file to read the tokens from, must not be <code>null</code>.
* @return The list of tokens, may be empty but never <code>null</code>.
* @throws java.io.IOException If the token file could not be read.
*/
private List<String> readTokens( final File tokenFile )
throws IOException
{
List<String> result = new ArrayList<>();

Map<String, Object> composite = getInterpolationValueSource( false );

try ( BufferedReader reader =
new BufferedReader( new InterpolationFilterReader( newReader( tokenFile ), composite ) ) )
{
for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
result.addAll( collectListFromCSV( line ) );
}
}

return result;
}

/**
* Gets a list of comma separated tokens from the specified line.
*
* @param csv The line with comma separated tokens, may be <code>null</code>.
* @return The list of tokens from the line, may be empty but never <code>null</code>.
*/
private List<String> collectListFromCSV( final String csv )
{
final List<String> result = new ArrayList<>();

if ( ( csv != null ) && ( csv.trim().length() > 0 ) )
{
final StringTokenizer st = new StringTokenizer( csv, "," );

while ( st.hasMoreTokens() )
{
result.add( st.nextToken().trim() );
}
}

return result;
}

/**
* Interpolates the specified POM/settings file to a temporary file. The destination file may be same as the input
* file, i.e. interpolation can be performed in-place.
Expand Down
2 changes: 0 additions & 2 deletions src/site/apt/examples/filtering.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ Filtering Files
| +- pom.xml <- Filtered
+- pom.xml <- Filtered
+- invoker.properties <- Filtered
+- goals.txt <- Filtered
+- profiles.txt <- Filtered
+------------------

Below is the corresponding POM snippet for the plugin configuration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import java.io.File;
import java.io.Reader;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;

Expand Down Expand Up @@ -57,7 +55,6 @@ protected MavenProjectStub buildMavenProjectStub()
}

public void testCompositeMap()
throws Exception
{

Properties properties = new Properties();
Expand Down Expand Up @@ -108,19 +105,4 @@ public void testPomInterpolation()
IOUtil.close( reader );
}
}

public void testProfilesWithNoFile()
throws Exception
{

InvokerMojo invokerMojo = new InvokerMojo();
setVariableValueToObject( invokerMojo, "profiles", Collections.singletonList( "zloug" ) );
setVariableValueToObject( invokerMojo, "settings", new Settings() );
String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
+ "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
List<String> profiles = invokerMojo.getProfiles( new File( dirPath ) );
assertTrue( profiles.contains( "zloug" ) );
assertEquals( 1, profiles.size() );

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class InvokerMojoTest extends AbstractMojoTestCase
{

private static final String DUMMY_PROJECT = "dummy" + File.separator + "pom.xml";
private static final String GOALS_FROM_FILE_PROJECT = "goals-from-file" + File.separator + "pom.xml";
private static final String WITH_POM_DIR_PROJECT = "with-pom-project-dir" + File.separator + "pom.xml";
private static final String INTERPOLATION_PROJECT = "interpolation" + File.separator + "pom.xml";
private static final String PROFILES_FROM_FILE_PROJECT = "profiles-from-file";
private static final String WITHOUT_POM_PROJECT = "without-pom-project-dir";

private MavenProject getMavenProject()
{
Expand Down Expand Up @@ -107,8 +107,8 @@ public void testFullPatternInvokerTest() throws Exception
assertThat( jobs )
.map( BuildJob::getProject )
.containsExactlyInAnyOrder(
DUMMY_PROJECT, GOALS_FROM_FILE_PROJECT,
INTERPOLATION_PROJECT, PROFILES_FROM_FILE_PROJECT );
DUMMY_PROJECT, WITH_POM_DIR_PROJECT, WITHOUT_POM_PROJECT,
INTERPOLATION_PROJECT );
}

public void testSetupInProjectList() throws Exception
Expand All @@ -131,7 +131,7 @@ public void testSetupInProjectList() throws Exception
assertThat( jobs )
.map( BuildJob::getProject )
.containsExactlyInAnyOrder(
DUMMY_PROJECT, GOALS_FROM_FILE_PROJECT, INTERPOLATION_PROJECT );
DUMMY_PROJECT, WITH_POM_DIR_PROJECT, INTERPOLATION_PROJECT );

// and we have one setup project
assertThat( jobs )
Expand All @@ -150,7 +150,7 @@ public void testSetupProjectIsFiltered() throws Exception
setVariableValueToObject( invokerMojo, "project", getMavenProject() );
setVariableValueToObject( invokerMojo, "settings", new Settings() );
setVariableValueToObject( invokerMojo, "setupIncludes", Collections.singletonList( "dum*/pom.xml" ) );
setVariableValueToObject( invokerMojo, "invokerTest", "*from-file*" );
setVariableValueToObject( invokerMojo, "invokerTest", "*project-dir*" );


// when
Expand All @@ -162,7 +162,7 @@ public void testSetupProjectIsFiltered() throws Exception
assertThat( jobs )
.map( BuildJob::getProject )
.containsExactlyInAnyOrder(
GOALS_FROM_FILE_PROJECT, PROFILES_FROM_FILE_PROJECT );
WITH_POM_DIR_PROJECT, WITHOUT_POM_PROJECT );

// and we don't have a setup project
assertThat( jobs )
Expand Down
48 changes: 0 additions & 48 deletions src/test/resources/unit/goals-from-file/verify.bsh

This file was deleted.

Empty file.
1 change: 0 additions & 1 deletion src/test/resources/unit/profiles-from-file/profiles.txt

This file was deleted.

16 changes: 16 additions & 0 deletions src/test/resources/unit/without-pom-project-dir/mark.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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.

0 comments on commit e4236a7

Please sign in to comment.