mirror of https://github.com/apache/maven.git
MNG-1979 throw IllegalStateException when calling methods in wrong order.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@400260 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c3addfbe1a
commit
a1b2df1fd1
|
@ -152,6 +152,8 @@ public class MavenEmbedder
|
||||||
*/
|
*/
|
||||||
private boolean alignWithUserInstallation;
|
private boolean alignWithUserInstallation;
|
||||||
|
|
||||||
|
private boolean started = false;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Accessors
|
// Accessors
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -254,11 +256,11 @@ public class MavenEmbedder
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated not used.
|
*
|
||||||
*/
|
*/
|
||||||
public File getLocalRepositoryDirectory()
|
public File getLocalRepositoryDirectory()
|
||||||
{
|
{
|
||||||
return localRepositoryDirectory;
|
return new File(getLocalRepositoryPath(settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactRepository getLocalRepository()
|
public ArtifactRepository getLocalRepository()
|
||||||
|
@ -284,15 +286,25 @@ public class MavenEmbedder
|
||||||
// Model
|
// Model
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read the model.
|
||||||
|
* requires a start()-ed embedder.
|
||||||
|
*/
|
||||||
public Model readModel( File model )
|
public Model readModel( File model )
|
||||||
throws XmlPullParserException, FileNotFoundException, IOException
|
throws XmlPullParserException, FileNotFoundException, IOException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return modelReader.read( new FileReader( model ) );
|
return modelReader.read( new FileReader( model ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write the model.
|
||||||
|
* requires a start()-ed embedder.
|
||||||
|
*/
|
||||||
public void writeModel( Writer writer, Model model )
|
public void writeModel( Writer writer, Model model )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
modelWriter.write( writer, model );
|
modelWriter.write( writer, model );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,27 +312,35 @@ public class MavenEmbedder
|
||||||
// Project
|
// Project
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read the project.
|
||||||
|
* requires a start()-ed embedder.
|
||||||
|
*/
|
||||||
public MavenProject readProject( File mavenProject )
|
public MavenProject readProject( File mavenProject )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenProjectBuilder.build( mavenProject, localRepository, profileManager );
|
return mavenProjectBuilder.build( mavenProject, localRepository, profileManager );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenProject readProjectWithDependencies( File mavenProject, TransferListener transferListener )
|
public MavenProject readProjectWithDependencies( File mavenProject, TransferListener transferListener )
|
||||||
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
|
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager, transferListener );
|
return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager, transferListener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenProject readProjectWithDependencies( File mavenProject )
|
public MavenProject readProjectWithDependencies( File mavenProject )
|
||||||
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
|
throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager );
|
return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List collectProjects( File basedir, String[] includes, String[] excludes )
|
public List collectProjects( File basedir, String[] includes, String[] excludes )
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
List projects = new ArrayList();
|
List projects = new ArrayList();
|
||||||
|
|
||||||
List poms = getPomFiles( basedir, includes, excludes );
|
List poms = getPomFiles( basedir, includes, excludes );
|
||||||
|
@ -351,17 +371,20 @@ public class MavenEmbedder
|
||||||
|
|
||||||
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
|
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return artifactFactory.createArtifact( groupId, artifactId, version, scope, type );
|
return artifactFactory.createArtifact( groupId, artifactId, version, scope, type );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier )
|
public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier )
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
return artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
artifactResolver.resolve( artifact, remoteRepositories, localRepository );
|
artifactResolver.resolve( artifact, remoteRepositories, localRepository );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,6 +438,7 @@ public class MavenEmbedder
|
||||||
public List getLifecyclePhases()
|
public List getLifecyclePhases()
|
||||||
throws MavenEmbedderException
|
throws MavenEmbedderException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
List phases = new ArrayList();
|
List phases = new ArrayList();
|
||||||
|
|
||||||
ComponentDescriptor descriptor = embedder.getContainer().getComponentDescriptor( LifecycleExecutor.ROLE );
|
ComponentDescriptor descriptor = embedder.getContainer().getComponentDescriptor( LifecycleExecutor.ROLE );
|
||||||
|
@ -473,6 +497,7 @@ public class MavenEmbedder
|
||||||
|
|
||||||
public ArtifactRepository createRepository( String url, String repositoryId )
|
public ArtifactRepository createRepository( String url, String repositoryId )
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
// snapshots vs releases
|
// snapshots vs releases
|
||||||
// offline = to turning the update policy off
|
// offline = to turning the update policy off
|
||||||
|
|
||||||
|
@ -607,6 +632,8 @@ public class MavenEmbedder
|
||||||
|
|
||||||
profileManager.loadSettingsProfiles( settings );
|
profileManager.loadSettingsProfiles( settings );
|
||||||
|
|
||||||
|
started = true;
|
||||||
|
|
||||||
localRepository = createLocalRepository( settings );
|
localRepository = createLocalRepository( settings );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -636,6 +663,7 @@ public class MavenEmbedder
|
||||||
public void stop()
|
public void stop()
|
||||||
throws MavenEmbedderException
|
throws MavenEmbedderException
|
||||||
{
|
{
|
||||||
|
started = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
embedder.release( mavenProjectBuilder );
|
embedder.release( mavenProjectBuilder );
|
||||||
|
@ -657,6 +685,7 @@ public class MavenEmbedder
|
||||||
public void execute( MavenExecutionRequest request )
|
public void execute( MavenExecutionRequest request )
|
||||||
throws MavenExecutionException
|
throws MavenExecutionException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
maven.execute( request );
|
maven.execute( request );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,6 +697,7 @@ public class MavenEmbedder
|
||||||
Boolean pluginUpdateOverride )
|
Boolean pluginUpdateOverride )
|
||||||
throws SettingsConfigurationException
|
throws SettingsConfigurationException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenTools.buildSettings( userSettingsPath,
|
return mavenTools.buildSettings( userSettingsPath,
|
||||||
globalSettingsPath,
|
globalSettingsPath,
|
||||||
interactive,
|
interactive,
|
||||||
|
@ -681,6 +711,7 @@ public class MavenEmbedder
|
||||||
Boolean pluginUpdateOverride )
|
Boolean pluginUpdateOverride )
|
||||||
throws SettingsConfigurationException
|
throws SettingsConfigurationException
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenTools.buildSettings( userSettingsPath,
|
return mavenTools.buildSettings( userSettingsPath,
|
||||||
globalSettingsPath,
|
globalSettingsPath,
|
||||||
pluginUpdateOverride );
|
pluginUpdateOverride );
|
||||||
|
@ -689,16 +720,25 @@ public class MavenEmbedder
|
||||||
|
|
||||||
public File getUserSettingsPath( String optionalSettingsPath )
|
public File getUserSettingsPath( String optionalSettingsPath )
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenTools.getUserSettingsPath( optionalSettingsPath );
|
return mavenTools.getUserSettingsPath( optionalSettingsPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getGlobalSettingsPath()
|
public File getGlobalSettingsPath()
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenTools.getGlobalSettingsPath();
|
return mavenTools.getGlobalSettingsPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocalRepositoryPath( Settings settings )
|
public String getLocalRepositoryPath( Settings settings )
|
||||||
{
|
{
|
||||||
|
checkStarted();
|
||||||
return mavenTools.getLocalRepositoryPath( settings );
|
return mavenTools.getLocalRepositoryPath( settings );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkStarted() {
|
||||||
|
if (!started) {
|
||||||
|
throw new IllegalStateException("The embedder is not started, you need to call start() on the embedder prior to calling this method");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue