[ http://jira.codehaus.org/browse/MNG-2200?page=comments#action_68007 ]
Dan Rollo commented on MNG-2200: -------------------------------- Hi John, I noticed the "Fix Version" for this has been changed to v2.1. Is there some reason the patch I mention above could not be applied to v2.0.5? Getting this fixed would allow me to do some real unit tests of the Maven Plugins I've written for CruiseControl. Without being able to override the default local repository in the Embedder, there's no safe/clean way to setUp and tearDown the local repo during unit testing. If there's anything I can do to help get this into v2.0.5, please let me know. Thanks, Dan > [m2.0.3] Embedder - no way to override the "localRepository", .start() and > alignWithUserInstallation broken > ----------------------------------------------------------------------------------------------------------- > > Key: MNG-2200 > URL: http://jira.codehaus.org/browse/MNG-2200 > Project: Maven 2 > Type: Bug > Components: Embedding > Versions: 2.0.3 > Environment: All > Reporter: Dan Rollo > Fix For: 2.1 > > > There is no way to override the "localRepository" used by MavenEmbedder. > Some code from MavenEmbedder.java: > public void setLocalRepositoryDirectory( File localRepositoryDirectory ) > { > this.localRepositoryDirectory = localRepositoryDirectory; > } > ... > public void start() > throws MavenEmbedderException > { > detectUserInstallation(); > ... > private void detectUserInstallation() > { > if ( new File( userHome, ".m2" ).exists() ) > { > alignWithUserInstallation = true; > } > } > /** > * Create the Settings that will be used with the embedder. If we are > aligning with the user > * installation then we lookup the standard settings builder and use that > to create our > * settings. Otherwise we constructs a settings object and populate the > information > * ourselves. > * > * @throws MavenEmbedderException > * @throws ComponentLookupException > */ > private void createMavenSettings() > throws MavenEmbedderException, ComponentLookupException > { > if ( alignWithUserInstallation ) > { > // > ---------------------------------------------------------------------- > // We will use the standard method for creating the settings. This > // method reproduces the method of building the settings from the > CLI > // mode of operation. > // > ---------------------------------------------------------------------- > settingsBuilder = (MavenSettingsBuilder) embedder.lookup( > MavenSettingsBuilder.ROLE ); > ... > } > else > { > if ( localRepository == null ) > { > throw new IllegalArgumentException( "When not aligning with a > user install you must specify a local repository location using the > setLocalRepositoryDirectory( File ) method." ); > } > settings = new Settings(); > settings.setLocalRepository( > localRepositoryDirectory.getAbsolutePath() ); > ... > The detectUserInstallation() method will never allow me to override the > localRepository if an ".m2" user > directory exists (even if I call setAlignWithUserInstallation(false) and/or > call setLocalRepositoryDirectory() before calling start() ). The current > logic in the start() method always sets the field "alignWithUserInstallation" > to true > if ".m2" exists. > Jason has confirmed this is a bug (on the maven user list), which he is > working on, but on a major branch due to be merged at some point in the > future. That said, I think this issue can easily be fixed quickly with the > code change below applied to the method detectUserInstallation(): > private void detectUserInstallation() > { > if ( new File( userHome, ".m2" ).exists() ) > { > alignWithUserInstallation = true; > } > } > changed to (added another condition in the if): > private void detectUserInstallation() > { > if ( new File( userHome, ".m2" ).exists() && localRepositoryDirectory > == null ) > { > alignWithUserInstallation = true; > } > } > If the next Embedder release will occur very soon and will include Jason's > fixes, this bug is likely already fixed. However, if the merging of Jason's > branch is a long way off, please consider fixing this bug for the next > release. > thanks > Dan -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira