Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelBuildingResult;
import org.apache.maven.model.building.ModelCache;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.building.StringModelSource;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
import org.apache.maven.repository.internal.ModelCacheFactory;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
Expand Down Expand Up @@ -111,7 +113,8 @@ public class DefaultProjectBuilder
@Requirement
private ProjectDependenciesResolver dependencyResolver;

private final ReactorModelCache modelCache = new ReactorModelCache();
@Requirement
private ModelCacheFactory modelCacheFactory;

// ----------------------------------------------------------------------
// MavenProjectBuilder Implementation
Expand All @@ -122,7 +125,8 @@ public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request
throws ProjectBuildingException
{
return build( pomFile, new FileModelSource( pomFile ),
new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null ) );
new InternalConfig( request, null,
useGlobalModelCache() ? createModelCache( request.getRepositorySession() ) : null ) );
}

private boolean useGlobalModelCache()
Expand All @@ -135,7 +139,8 @@ public ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequ
throws ProjectBuildingException
{
return build( null, modelSource,
new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null ) );
new InternalConfig( request, null,
useGlobalModelCache() ? createModelCache( request.getRepositorySession() ) : null ) );
}

private ProjectBuildingResult build( File pomFile, ModelSource modelSource, InternalConfig config )
Expand Down Expand Up @@ -306,7 +311,8 @@ public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P
org.eclipse.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifact( artifact );
pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact );

InternalConfig config = new InternalConfig( request, null, useGlobalModelCache() ? getModelCache() : null );
InternalConfig config = new InternalConfig( request, null,
useGlobalModelCache() ? createModelCache( request.getRepositorySession() ) : null );

boolean localProject;

Expand Down Expand Up @@ -369,7 +375,7 @@ public List<ProjectBuildingResult> build( List<File> pomFiles, boolean recursive
ReactorModelPool modelPool = new ReactorModelPool();

InternalConfig config = new InternalConfig( request, modelPool,
useGlobalModelCache() ? getModelCache() : new ReactorModelCache() );
useGlobalModelCache() ? createModelCache( request.getRepositorySession() ) : new ReactorModelCache() );

Map<String, MavenProject> projectIndex = new HashMap<>( 256 );

Expand Down Expand Up @@ -1058,9 +1064,9 @@ class InternalConfig

private final ReactorModelPool modelPool;

private final ReactorModelCache modelCache;
private final ModelCache modelCache;

InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool, ReactorModelCache modelCache )
InternalConfig( ProjectBuildingRequest request, ReactorModelPool modelPool, ModelCache modelCache )
{
this.request = request;
this.modelPool = modelPool;
Expand All @@ -1073,9 +1079,9 @@ class InternalConfig

}

private ReactorModelCache getModelCache()
private ModelCache createModelCache( RepositorySystemSession session )
{
return this.modelCache;
return modelCacheFactory.createCache( session );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ protected MavenSession createMavenSession( File pom, Properties executionPropert
.setSystemProperties( executionProperties )
.setUserProperties( new Properties() );

initRepoSession( configuration );

List<MavenProject> projects = new ArrayList<>();

if ( pom != null )
Expand Down Expand Up @@ -174,8 +176,6 @@ protected MavenSession createMavenSession( File pom, Properties executionPropert
projects.add( project );
}

initRepoSession( configuration );

MavenSession session =
new MavenSession( getContainer(), configuration.getRepositorySession(), request,
new DefaultMavenExecutionResult() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public class DefaultArtifactDescriptorReader

private ModelBuilder modelBuilder;

private ModelCacheFactory modelCacheFactory;

public DefaultArtifactDescriptorReader()
{
// enable no-arg constructor
Expand All @@ -97,14 +99,16 @@ public DefaultArtifactDescriptorReader()
@Inject
DefaultArtifactDescriptorReader( RemoteRepositoryManager remoteRepositoryManager, VersionResolver versionResolver,
VersionRangeResolver versionRangeResolver, ArtifactResolver artifactResolver,
ModelBuilder modelBuilder, RepositoryEventDispatcher repositoryEventDispatcher )
ModelBuilder modelBuilder, RepositoryEventDispatcher repositoryEventDispatcher,
ModelCacheFactory modelCacheFactory )
{
setRemoteRepositoryManager( remoteRepositoryManager );
setVersionResolver( versionResolver );
setVersionRangeResolver( versionRangeResolver );
setArtifactResolver( artifactResolver );
setModelBuilder( modelBuilder );
setRepositoryEventDispatcher( repositoryEventDispatcher );
setModelCacheFactory( modelCacheFactory );
}

public void initService( ServiceLocator locator )
Expand All @@ -119,6 +123,7 @@ public void initService( ServiceLocator locator )
setModelBuilder( new DefaultModelBuilderFactory().newInstance() );
}
setRepositoryEventDispatcher( locator.getService( RepositoryEventDispatcher.class ) );
setModelCacheFactory( locator.getService( ModelCacheFactory.class ) );
}

public DefaultArtifactDescriptorReader setRemoteRepositoryManager( RemoteRepositoryManager remoteRepositoryManager )
Expand Down Expand Up @@ -162,6 +167,13 @@ public DefaultArtifactDescriptorReader setModelBuilder( ModelBuilder modelBuilde
return this;
}

public DefaultArtifactDescriptorReader setModelCacheFactory( ModelCacheFactory modelCacheFactory )
{
this.modelCacheFactory = Objects.requireNonNull( modelCacheFactory,
"modelCacheFactory cannot be null" );
return this;
}

public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session,
ArtifactDescriptorRequest request )
throws ArtifactDescriptorException
Expand Down Expand Up @@ -276,7 +288,7 @@ private Model loadPom( RepositorySystemSession session, ArtifactDescriptorReques
modelRequest.setTwoPhaseBuilding( false );
modelRequest.setSystemProperties( toProperties( session.getSystemProperties() ) );
modelRequest.setUserProperties( toProperties( session.getUserProperties() ) );
modelRequest.setModelCache( DefaultModelCache.newInstance( session ) );
modelRequest.setModelCache( modelCacheFactory.createCache( session ) );
modelRequest.setModelResolver( new DefaultModelResolver( session, trace.newChild( modelRequest ),
request.getRequestContext(), artifactResolver,
versionRangeResolver, remoteRepositoryManager,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.apache.maven.repository.internal;

/*
* 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 javax.inject.Named;
import javax.inject.Singleton;

import org.apache.maven.model.building.ModelCache;
import org.eclipse.aether.RepositorySystemSession;

/**
* Default implementation of {@link ModelCacheFactory}.
*/
@Singleton
@Named
public class DefaultModelCacheFactory implements ModelCacheFactory
{
@Override
public ModelCache createCache( RepositorySystemSession session )
{
return DefaultModelCache.newInstance( session );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ protected void configure()
.to( VersionsMetadataGeneratorFactory.class ).in( Singleton.class );
bind( ModelBuilder.class ) //
.toInstance( new DefaultModelBuilderFactory().newInstance() );
bind( ModelCacheFactory.class )
.to( DefaultModelCacheFactory.class ).in( Singleton.class );
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static DefaultServiceLocator newServiceLocator()
locator.addService( VersionRangeResolver.class, DefaultVersionRangeResolver.class );
locator.addService( MetadataGeneratorFactory.class, SnapshotMetadataGeneratorFactory.class );
locator.addService( MetadataGeneratorFactory.class, VersionsMetadataGeneratorFactory.class );
locator.addService( ModelCacheFactory.class, DefaultModelCacheFactory.class );
return locator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected void configure()
.to( VersionsMetadataGeneratorFactory.class ).in( Singleton.class );

bind( ModelBuilder.class ).toInstance( new DefaultModelBuilderFactory().newInstance() );
bind( ModelCacheFactory.class ).to( DefaultModelCacheFactory.class ).in( Singleton.class );
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.apache.maven.repository.internal;

/*
* 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.building.ModelCache;
import org.eclipse.aether.RepositorySystemSession;

/**
* Factory for {@link ModelCache} objects.
*/
public interface ModelCacheFactory
{

ModelCache createCache( RepositorySystemSession session );

}