remove dependency on settings from the project builder

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-21 17:17:36 +00:00
parent be6703f6da
commit aafbd6b61c
10 changed files with 56 additions and 52 deletions

View File

@ -18,7 +18,6 @@ package org.apache.maven.artifact.repository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Repository;
import org.apache.maven.settings.Settings;
/**
* @author jdcasey
@ -28,7 +27,7 @@ public interface ArtifactRepositoryFactory
public static final String ROLE = ArtifactRepositoryFactory.class.getName();
public ArtifactRepository createArtifactRepository( Repository modelRepository, Settings settings,
public ArtifactRepository createArtifactRepository( Repository modelRepository,
ArtifactRepositoryLayout repositoryLayout );
void setGlobalSnapshotPolicy( String snapshotPolicy );

View File

@ -20,9 +20,13 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Repository;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException;
/**
* @author jdcasey
@ -31,17 +35,36 @@ public class DefaultArtifactRepositoryFactory
extends AbstractLogEnabled
implements ArtifactRepositoryFactory
{
// TODO: use settings?
private String globalSnapshotPolicy = null;
public ArtifactRepository createArtifactRepository( Repository modelRepository, Settings settings,
// TODO: make this a store once object?
private MavenSettingsBuilder settingsBuilder;
public ArtifactRepository createArtifactRepository( Repository modelRepository,
ArtifactRepositoryLayout repositoryLayout )
{
Server repoProfile = null;
String repoId = modelRepository.getId();
if ( repoId != null && repoId.length() > 0 )
{
Settings settings = null;
try
{
settings = settingsBuilder.buildSettings();
}
catch ( IOException e )
{
getLogger().warn( "Error reading settings", e );
}
catch ( XmlPullParserException e )
{
getLogger().warn( "Error reading settings", e );
}
repoProfile = settings.getServer( modelRepository.getId() );
}
else

View File

@ -503,6 +503,6 @@ public class MavenCli
repo.setUrl( "file://" + profile.getLocalRepository() );
return repoFactory.createArtifactRepository( repo, settings, repositoryLayout );
return repoFactory.createArtifactRepository( repo, repositoryLayout );
}
}

View File

@ -38,8 +38,6 @@ import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@ -91,8 +89,6 @@ public class DefaultMavenProjectBuilder
private ModelInterpolator modelInterpolator;
private MavenSettingsBuilder mavenSettingsBuilder;
private ArtifactRepositoryFactory artifactRepositoryFactory;
private final Map modelCache = new HashMap();
@ -129,10 +125,6 @@ public class DefaultMavenProjectBuilder
// Always cache files in the source tree over those in the repository
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model );
Settings settings = readSettings();
boolean systemOnline = !settings.getActiveProfile().isOffline();
MavenProject project = build( model, localRepository, resolveDependencies );
// Only translate the base directory for files in the source tree
@ -149,32 +141,6 @@ public class DefaultMavenProjectBuilder
return project;
}
/**
* @return
* @throws ProjectBuildingException
* @todo shouldn't be re-reading all the time - perhaps cache, but check a timestamp so you can detect and reload on
* changes in a long running process
*/
private Settings readSettings()
throws ProjectBuildingException
{
Settings settings = null;
try
{
settings = mavenSettingsBuilder.buildSettings();
}
catch ( IOException e )
{
throw new ProjectBuildingException( "Cannot read settings.", e );
}
catch ( XmlPullParserException e )
{
throw new ProjectBuildingException( "Cannot read settings.", e );
}
return settings;
}
public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException
@ -370,7 +336,6 @@ public class DefaultMavenProjectBuilder
private List buildArtifactRepositories( List repositories )
throws ProjectBuildingException
{
Settings settings = readSettings();
List repos = new ArrayList();
@ -380,7 +345,7 @@ public class DefaultMavenProjectBuilder
ArtifactRepositoryLayout remoteRepoLayout = getRepositoryLayout( mavenRepo );
ArtifactRepository artifactRepo = artifactRepositoryFactory.createArtifactRepository( mavenRepo, settings,
ArtifactRepository artifactRepo = artifactRepositoryFactory.createArtifactRepository( mavenRepo,
remoteRepoLayout );
if ( !repos.contains( artifactRepo ) )
@ -396,8 +361,6 @@ public class DefaultMavenProjectBuilder
{
List remotePluginRepositories = new ArrayList();
Settings settings = readSettings();
for ( Iterator it = pluginRepositories.iterator(); it.hasNext(); )
{
Repository mavenRepo = (Repository) it.next();
@ -405,7 +368,6 @@ public class DefaultMavenProjectBuilder
ArtifactRepositoryLayout repositoryLayout = getRepositoryLayout( mavenRepo );
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( mavenRepo,
settings,
repositoryLayout );
remotePluginRepositories.add( pluginRepository );
@ -441,11 +403,9 @@ public class DefaultMavenProjectBuilder
return null;
}
Settings settings = readSettings();
ArtifactRepositoryLayout repositoryLayout = getRepositoryLayout( dmRepo );
ArtifactRepository dmArtifactRepository = artifactRepositoryFactory.createArtifactRepository( dmRepo, settings,
ArtifactRepository dmArtifactRepository = artifactRepositoryFactory.createArtifactRepository( dmRepo,
repositoryLayout );
return dmArtifactRepository;

View File

@ -19,6 +19,7 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.settings.Settings;
import java.io.File;
import java.util.List;

View File

@ -89,9 +89,6 @@
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
</requirement>
</requirements>
</component>
<!--
@ -251,6 +248,11 @@
<component>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
<implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
<requirements>
<requirement>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
</requirement>
</requirements>
</component>
<!-- ********************* FIXME *******************************************
| NOTE: This is also declared in plexus.xml for maven. We currently need it

View File

@ -45,6 +45,11 @@
<component>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
<implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
<requirements>
<requirement>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>

View File

@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.codehaus.plexus.ArtifactEnabledPlexusTestCase;
import java.io.File;

View File

@ -1,5 +1,21 @@
package org.apache.maven.plugin;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* 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
*
* 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.MavenTestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;

View File

@ -28,9 +28,6 @@
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
</requirement>
</requirements>
</component>
</components>