You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2012/01/03 16:58:56 UTC
svn commit: r1226842 - in
/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven:
execution/SettingsAdapter.java settings/SettingsUtils.java
Author: stephenc
Date: Tue Jan 3 15:58:55 2012
New Revision: 1226842
URL: http://svn.apache.org/viewvc?rev=1226842&view=rev
Log:
[MNG-5224] REGRESSION: Injected Settings in a Mojo are missing the profiles from settings.xml
o This is the fix, manually tested. Now I just have to figure out a good way to test the via a unit/integration test
Modified:
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java?rev=1226842&r1=1226841&r2=1226842&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java (original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java Tue Jan 3 15:58:55 2012
@@ -29,6 +29,7 @@ import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.RuntimeInfo;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.SettingsUtils;
/**
* Adapt a {@link MavenExecutionRequest} to a {@link Settings} object for use in the Maven core.
@@ -103,7 +104,12 @@ class SettingsAdapter
@Override
public List<Profile> getProfiles()
{
- return new ArrayList<Profile>();
+ List<Profile> result = new ArrayList<Profile>();
+ for ( org.apache.maven.model.Profile profile : request.getProfiles() )
+ {
+ result.add( SettingsUtils.convertToSettingsProfile( profile ) );
+ }
+ return result;
}
@Override
Modified: maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java?rev=1226842&r1=1226841&r2=1226842&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java (original)
+++ maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java Tue Jan 3 15:58:55 2012
@@ -19,11 +19,11 @@ package org.apache.maven.settings;
* under the License.
*/
-import java.util.List;
-
import org.apache.maven.model.ActivationFile;
import org.apache.maven.settings.merge.MavenSettingsMerger;
+import java.util.List;
+
/**
* Several convenience methods to handle settings
*
@@ -51,6 +51,88 @@ public final class SettingsUtils
* @param settingsProfile
* @return a profile
*/
+ public static Profile convertToSettingsProfile( org.apache.maven.model.Profile modelProfile )
+ {
+ Profile profile = new Profile();
+
+ profile.setId( modelProfile.getId() );
+
+ org.apache.maven.model.Activation modelActivation = modelProfile.getActivation();
+
+ if ( modelActivation != null )
+ {
+ Activation activation = new Activation();
+
+ activation.setActiveByDefault( modelActivation.isActiveByDefault() );
+
+ activation.setJdk( modelActivation.getJdk() );
+
+ org.apache.maven.model.ActivationProperty modelProp = modelActivation.getProperty();
+
+ if ( modelProp != null )
+ {
+ ActivationProperty prop = new ActivationProperty();
+ prop.setName( modelProp.getName() );
+ prop.setValue( modelProp.getValue() );
+ activation.setProperty( prop );
+ }
+
+ org.apache.maven.model.ActivationOS modelOs = modelActivation.getOs();
+
+ if ( modelOs != null )
+ {
+ ActivationOS os = new ActivationOS();
+
+ os.setArch( modelOs.getArch() );
+ os.setFamily( modelOs.getFamily() );
+ os.setName( modelOs.getName() );
+ os.setVersion( modelOs.getVersion() );
+
+ activation.setOs( os );
+ }
+
+ ActivationFile modelFile = modelActivation.getFile();
+
+ if ( modelFile != null )
+ {
+ org.apache.maven.settings.ActivationFile file = new org.apache.maven.settings.ActivationFile();
+
+ file.setExists( modelFile.getExists() );
+ file.setMissing( modelFile.getMissing() );
+
+ activation.setFile( file );
+ }
+
+ profile.setActivation( activation );
+ }
+
+ profile.setProperties( modelProfile.getProperties() );
+
+ List<org.apache.maven.model.Repository> repos = modelProfile.getRepositories();
+ if ( repos != null )
+ {
+ for ( org.apache.maven.model.Repository repo : repos )
+ {
+ profile.addRepository( convertToSettingsRepository( repo ) );
+ }
+ }
+
+ List<org.apache.maven.model.Repository> pluginRepos = modelProfile.getPluginRepositories();
+ if ( pluginRepos != null )
+ {
+ for ( org.apache.maven.model.Repository pluginRepo : pluginRepos )
+ {
+ profile.addPluginRepository( convertToSettingsRepository( pluginRepo ) );
+ }
+ }
+
+ return profile;
+ }
+
+ /**
+ * @param settingsProfile
+ * @return a profile
+ */
public static org.apache.maven.model.Profile convertFromSettingsProfile( Profile settingsProfile )
{
org.apache.maven.model.Profile profile = new org.apache.maven.model.Profile();
@@ -172,6 +254,44 @@ public final class SettingsUtils
}
/**
+ * @param modelRepo
+ * @return a repository
+ */
+ private static Repository convertToSettingsRepository( org.apache.maven.model.Repository modelRepo )
+ {
+ Repository repo = new Repository();
+
+ repo.setId( modelRepo.getId() );
+ repo.setLayout( modelRepo.getLayout() );
+ repo.setName( modelRepo.getName() );
+ repo.setUrl( modelRepo.getUrl() );
+
+ if ( modelRepo.getSnapshots() != null )
+ {
+ repo.setSnapshots( convertRepositoryPolicy( modelRepo.getSnapshots() ) );
+ }
+ if ( modelRepo.getReleases() != null )
+ {
+ repo.setReleases( convertRepositoryPolicy( modelRepo.getReleases() ) );
+ }
+
+ return repo;
+ }
+
+ /**
+ * @param modelPolicy
+ * @return a RepositoryPolicy
+ */
+ private static RepositoryPolicy convertRepositoryPolicy( org.apache.maven.model.RepositoryPolicy modelPolicy )
+ {
+ RepositoryPolicy policy = new RepositoryPolicy();
+ policy.setEnabled( modelPolicy.isEnabled() );
+ policy.setUpdatePolicy( modelPolicy.getUpdatePolicy() );
+ policy.setChecksumPolicy( modelPolicy.getChecksumPolicy() );
+ return policy;
+ }
+
+ /**
* @param settings could be null
* @return a new instance of settings or null if settings was null.
*/