Remove Google Guava usage (move to Java7)

This commit is contained in:
Sylwester Lachiewicz 2017-11-08 22:29:50 +01:00 committed by Hervé Boutemy
parent d925081794
commit b8c06e61ab
12 changed files with 101 additions and 95 deletions

View File

@ -60,8 +60,6 @@ import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.WorkspaceReader;
import org.eclipse.aether.util.repository.ChainedWorkspaceReader;
import com.google.common.collect.Iterables;
/**
* @author Jason van Zyl
*/
@ -222,8 +220,7 @@ public class DefaultMaven
if ( graphResult.hasErrors() )
{
return addExceptionToResult( result, Iterables.toArray( graphResult.getProblems(),
ModelProblem.class )[0].getException() );
return addExceptionToResult( result, graphResult.getProblems().iterator().next().getException() );
}
try
@ -289,8 +286,7 @@ public class DefaultMaven
if ( graphResult.hasErrors() )
{
return addExceptionToResult( result, Iterables.toArray( graphResult.getProblems(),
ModelProblem.class )[0].getException() );
return addExceptionToResult( result, graphResult.getProblems().iterator().next().getException() );
}
try

View File

@ -43,8 +43,6 @@ import org.eclipse.aether.RepositoryCache;
import org.eclipse.aether.repository.WorkspaceReader;
import org.eclipse.aether.transfer.TransferListener;
import com.google.common.collect.Maps;
/**
* @author Jason van Zyl
*/
@ -1280,7 +1278,7 @@ public class DefaultMavenExecutionRequest
{
if ( data == null )
{
data = Maps.newHashMap();
data = new HashMap<>();
}
return data;

View File

@ -20,6 +20,7 @@ package org.apache.maven.execution.scope.internal;
*/
import java.util.Collection;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.Map;
@ -29,7 +30,6 @@ import org.apache.maven.execution.MojoExecutionListener;
import org.apache.maven.execution.scope.WeakMojoExecutionListener;
import org.apache.maven.plugin.MojoExecutionException;
import com.google.common.collect.Maps;
import com.google.inject.Key;
import com.google.inject.OutOfScopeException;
import com.google.inject.Provider;
@ -52,9 +52,9 @@ public class MojoExecutionScope
private static final class ScopeState
{
private final Map<Key<?>, Provider<?>> seeded = Maps.newHashMap();
private final Map<Key<?>, Provider<?>> seeded = new HashMap<>();
private final Map<Key<?>, Object> provided = Maps.newHashMap();
private final Map<Key<?>, Object> provided = new HashMap<>();
}
private final ThreadLocal<LinkedList<ScopeState>> values = new ThreadLocal<>();

View File

@ -19,15 +19,15 @@ package org.apache.maven.extension.internal;
* under the License.
*/
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* Provides information about artifacts (identified by groupId:artifactId string key) and classpath elements exported by
* Maven core itself and loaded Maven core extensions.
@ -52,8 +52,8 @@ public class CoreExports
{
packages.put( pkg, realm );
}
this.artifacts = ImmutableSet.copyOf( exportedArtifacts );
this.packages = ImmutableMap.copyOf( packages );
this.artifacts = Collections.unmodifiableSet( new HashSet<>( exportedArtifacts ) );
this.packages = Collections.unmodifiableMap( new HashMap<>( packages ) );
}
/**

View File

@ -19,7 +19,6 @@ package org.apache.maven.extension.internal;
* under the License.
*/
import com.google.common.collect.ImmutableSet;
import org.apache.maven.project.ExtensionDescriptor;
import org.apache.maven.project.ExtensionDescriptorBuilder;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
@ -29,7 +28,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
@ -50,8 +51,8 @@ public class CoreExtensionEntry
public CoreExtensionEntry( ClassRealm realm, Collection<String> artifacts, Collection<String> packages )
{
this.realm = realm;
this.artifacts = ImmutableSet.copyOf( artifacts );
this.packages = ImmutableSet.copyOf( packages );
this.artifacts = Collections.unmodifiableSet( new HashSet<>( artifacts ) );
this.packages = Collections.unmodifiableSet( new HashSet<>( packages ) );
}
/**

View File

@ -23,12 +23,12 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import org.apache.maven.DefaultMaven;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.ProjectCycleException;
@ -85,23 +85,17 @@ public class DefaultGraphBuilder
return result;
}
catch ( final ProjectBuildingException e )
catch ( final ProjectBuildingException | DuplicateProjectException | MavenExecutionException e )
{
return Result.error( Lists.newArrayList( new DefaultModelProblem( null, null, null, null, 0, 0, e ) ) );
return Result.error( Collections.singletonList
( new DefaultModelProblem ( null, null, null, null, 0, 0, e ) ) );
}
catch ( final CycleDetectedException e )
{
String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();
ProjectCycleException error = new ProjectCycleException( message, e );
return Result.error( Lists.newArrayList( new DefaultModelProblem( null, null, null, null, 0, 0, error ) ) );
}
catch ( final DuplicateProjectException e )
{
return Result.error( Lists.newArrayList( new DefaultModelProblem( null, null, null, null, 0, 0, e ) ) );
}
catch ( final MavenExecutionException e )
{
return Result.error( Lists.newArrayList( new DefaultModelProblem( null, null, null, null, 0, 0, e ) ) );
return Result.error( Collections.singletonList(
new DefaultModelProblem( null, null, null, null, 0, 0, error ) ) );
}
}

View File

@ -24,8 +24,6 @@ import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -122,7 +120,10 @@ public class DefaultLifecycles
for ( String name : lifecycleNames )
{
Lifecycle lifecycle = lifecycles.get( name );
Preconditions.checkNotNull( "A lifecycle must have an id.", lifecycle.getId() );
if ( lifecycle.getId() == null )
{
throw new NullPointerException( "A lifecycle must have an id." );
}
result.add( lifecycle );
}

View File

@ -59,7 +59,6 @@ import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import com.google.common.collect.ImmutableMap;
/**
* <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
@ -111,8 +110,8 @@ public class DefaultLifecycleExecutionPlanCalculator
this.defaultLifeCycles = defaultLifeCycles;
this.mojoDescriptorCreator = mojoDescriptorCreator;
this.lifecyclePluginResolver = lifecyclePluginResolver;
this.mojoExecutionConfigurators =
ImmutableMap.of( "default", (MojoExecutionConfigurator) new DefaultMojoExecutionConfigurator() );
this.mojoExecutionConfigurators = Collections.singletonMap(
"default", (MojoExecutionConfigurator) new DefaultMojoExecutionConfigurator() );
}
@Override

View File

@ -23,11 +23,10 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
@ -157,14 +156,15 @@ public class ProjectModelResolver
private static void removeMatchingRepository( Iterable<RemoteRepository> repositories, final String id )
{
Iterables.removeIf( repositories, new Predicate<RemoteRepository>()
Iterator iterator = repositories.iterator( );
while ( iterator.hasNext() )
{
@Override
public boolean apply( RemoteRepository remoteRepository )
RemoteRepository next = ( RemoteRepository ) iterator.next();
if ( next.getId().equals( id ) )
{
return remoteRepository.getId().equals( id );
iterator.remove();
}
} );
}
}
public ModelResolver newCopy()

View File

@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Key;
import com.google.inject.OutOfScopeException;
import com.google.inject.Provider;
@ -46,7 +45,7 @@ public class SessionScope
Memento( final Map<Key<?>, Provider<?>> seeded )
{
this.seeded = ImmutableMap.copyOf( seeded );
this.seeded = Collections.unmodifiableMap( new HashMap<>( seeded ) );
}
}

View File

@ -19,8 +19,6 @@ package org.apache.maven.cli;
* under the License.
*/
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.inject.AbstractModule;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
@ -101,6 +99,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@ -378,7 +377,7 @@ public class MavenCli
if ( configFile.isFile() )
{
for ( String arg : Files.toString( configFile, Charsets.UTF_8 ).split( "\\s+" ) )
for ( String arg : new String( Files.readAllBytes( configFile.toPath() ) ).split( "\\s+" ) )
{
if ( !arg.isEmpty() )
{

View File

@ -19,23 +19,14 @@ package org.apache.maven.model.building;
* under the License.
*/
import static com.google.common.base.Predicates.in;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.transform;
import static java.util.Collections.singleton;
import static java.util.EnumSet.of;
import static org.apache.maven.model.building.ModelProblem.Severity.ERROR;
import static org.apache.maven.model.building.ModelProblem.Severity.FATAL;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.apache.maven.model.building.ModelProblem.Severity;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import java.util.List;
/**
* There are various forms of results that are represented by this class:
@ -83,7 +74,17 @@ public class Result<T>
*/
public static <T> Result<T> success( T model, Result<?>... results )
{
return success( model, Iterables.concat( Iterables.transform( Arrays.asList( results ), GET_PROBLEMS ) ) );
final List<ModelProblem> problemsList = new ArrayList<>();
for ( Result<?> result1 : results )
{
for ( ModelProblem modelProblem : result1.getProblems() )
{
problemsList.add( modelProblem );
}
}
return success( model, problemsList );
}
/**
@ -108,7 +109,17 @@ public class Result<T>
public static <T> Result<T> error( Result<?>... results )
{
return error( Iterables.concat( Iterables.transform( Arrays.asList( results ), GET_PROBLEMS ) ) );
final List<ModelProblem> problemsList = new ArrayList<>( );
for ( Result<?> result1 : results )
{
for ( ModelProblem modelProblem : result1.getProblems( ) )
{
problemsList.add( modelProblem );
}
}
return error( problemsList );
}
/**
@ -153,13 +164,30 @@ public class Result<T>
*/
public static <T> Result<T> addProblems( Result<T> result, Iterable<? extends ModelProblem> problems )
{
return new Result<>( result.hasErrors() || hasErrors( problems ), result.get(), concat( result.getProblems(),
problems ) );
Collection<ModelProblem> list = new ArrayList<>();
for ( ModelProblem item : problems )
{
list.add( item );
}
for ( ModelProblem item : result.getProblems() )
{
list.add( item );
}
return new Result<>( result.hasErrors() || hasErrors( problems ), result.get(), list );
}
public static <T> Result<T> addProblems( Result<T> result, Result<?>... results )
{
return addProblems( result, Iterables.concat( Iterables.transform( Arrays.asList( results ), GET_PROBLEMS ) ) );
final List<ModelProblem> problemsList = new ArrayList<>();
for ( Result<?> result1 : results )
{
for ( ModelProblem modelProblem : result1.getProblems( ) )
{
problemsList.add( modelProblem );
}
}
return addProblems( result, problemsList );
}
/**
@ -169,37 +197,38 @@ public class Result<T>
*/
public static <T> Result<Iterable<T>> newResultSet( Iterable<? extends Result<? extends T>> results )
{
final boolean hasErrors = any( transform( results, new Function<Result<?>, Boolean>()
boolean hasErrors = false;
List<T> modelsList = new ArrayList<>();
List<ModelProblem> problemsList = new ArrayList<>();
for ( Result<? extends T> result : results )
{
@Override
public Boolean apply( Result<?> input )
modelsList.add( result.get() );
for ( ModelProblem modelProblem : result.getProblems() )
{
return input.hasErrors();
problemsList.add( modelProblem );
}
} ), Predicates.equalTo( true ) );
final Iterable<T> models = transform( results, new Function<Result<? extends T>, T>()
{
@Override
public T apply( Result<? extends T> input )
if ( result.hasErrors() )
{
return input.get();
hasErrors = true;
}
} );
final Iterable<ModelProblem> problems = concat( transform( results, GET_PROBLEMS ) );
return new Result<>( hasErrors, models, problems );
}
return new Result<>( hasErrors, ( Iterable<T> ) modelsList, problemsList );
}
// helper to determine if problems contain error
private static boolean hasErrors( Iterable<? extends ModelProblem> problems )
{
return any( transform( problems, new Function<ModelProblem, Severity>()
for ( ModelProblem input : problems )
{
@Override
public Severity apply( ModelProblem input )
if ( input.getSeverity().equals( ERROR ) || input.getSeverity().equals( FATAL ) )
{
return input.getSeverity();
return true;
}
} ), in( of( ERROR, FATAL ) ) );
}
return false;
}
/**
@ -233,14 +262,4 @@ public class Result<T>
{
return errors;
}
private static final Function<Result<?>, Iterable<? extends ModelProblem>> GET_PROBLEMS =
new Function<Result<?>, Iterable<? extends ModelProblem>>()
{
@Override
public Iterable<? extends ModelProblem> apply( Result<?> input )
{
return input.getProblems();
}
};
}