You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2008/01/08 14:40:20 UTC
svn commit: r609976 - in
/maven/components/branches/maven-2.0.x/maven-project/src:
main/java/org/apache/maven/profiles/activation/FileProfileActivator.java
test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java
Author: vsiveton
Date: Tue Jan 8 05:40:17 2008
New Revision: 609976
URL: http://svn.apache.org/viewvc?rev=609976&view=rev
Log:
MNG-2809: Can't activate a profile by checking for the presence of a file in ${user.home}
o used RegexBasedInterpolator to interpolate some system properties
o added a test case
Modified:
maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java
maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java
Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java?rev=609976&r1=609975&r2=609976&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java (original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java Tue Jan 8 05:40:17 2008
@@ -19,10 +19,16 @@
* under the License.
*/
+import java.io.IOException;
+
import org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationFile;
import org.apache.maven.model.Profile;
import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.interpolation.EnvarBasedValueSource;
+import org.codehaus.plexus.util.interpolation.MapBasedValueSource;
+import org.codehaus.plexus.util.interpolation.RegexBasedInterpolator;
public class FileProfileActivator
extends DetectedProfileActivator
@@ -43,16 +49,29 @@
// check if the file exists, if it does then the profile will be active
String fileString = actFile.getExists();
- if ( fileString != null && !"".equals( fileString ) )
+ RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
+ try
+ {
+ interpolator.addValueSource( new EnvarBasedValueSource() );
+ }
+ catch ( IOException e )
+ {
+ // ignored
+ }
+ interpolator.addValueSource( new MapBasedValueSource( System.getProperties() ) );
+
+ if ( StringUtils.isNotEmpty( fileString ) )
{
+ fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" );
return FileUtils.fileExists( fileString );
}
// check if the file is missing, if it is then the profile will be active
fileString = actFile.getMissing();
- if ( fileString != null && !"".equals( fileString ) )
+ if ( StringUtils.isNotEmpty( fileString ) )
{
+ fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" );
return !FileUtils.fileExists( fileString );
}
}
Modified: maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java?rev=609976&r1=609975&r2=609976&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java (original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/profiles/DefaultProfileManagerTest.java Tue Jan 8 05:40:17 2008
@@ -31,169 +31,174 @@
public class DefaultProfileManagerTest
extends PlexusTestCase
{
-
- public void testShouldActivateDefaultProfile() throws ProfileActivationException
+ public void testShouldActivateDefaultProfile()
+ throws ProfileActivationException
{
Profile notActivated = new Profile();
- notActivated.setId("notActivated");
-
+ notActivated.setId( "notActivated" );
+
Activation nonActivation = new Activation();
-
- nonActivation.setJdk("19.2");
-
+
+ nonActivation.setJdk( "19.2" );
+
notActivated.setActivation( nonActivation );
-
+
Profile defaultActivated = new Profile();
- defaultActivated.setId("defaultActivated");
-
+ defaultActivated.setId( "defaultActivated" );
+
Activation defaultActivation = new Activation();
-
- defaultActivation.setActiveByDefault(true);
-
+
+ defaultActivation.setActiveByDefault( true );
+
defaultActivated.setActivation( defaultActivation );
-
- ProfileManager profileManager = new DefaultProfileManager(getContainer());
-
- profileManager.addProfile(notActivated);
- profileManager.addProfile(defaultActivated);
-
+
+ ProfileManager profileManager = new DefaultProfileManager( getContainer() );
+
+ profileManager.addProfile( notActivated );
+ profileManager.addProfile( defaultActivated );
+
List active = profileManager.getActiveProfiles();
-
+
assertNotNull( active );
assertEquals( 1, active.size() );
- assertEquals("defaultActivated", ((Profile)active.get(0)).getId());
+ assertEquals( "defaultActivated", ( (Profile) active.get( 0 ) ).getId() );
}
- public void testShouldNotActivateDefaultProfile() throws ProfileActivationException
+ public void testShouldNotActivateDefaultProfile()
+ throws ProfileActivationException
{
Profile syspropActivated = new Profile();
- syspropActivated.setId("syspropActivated");
-
+ syspropActivated.setId( "syspropActivated" );
+
Activation syspropActivation = new Activation();
-
+
ActivationProperty syspropProperty = new ActivationProperty();
- syspropProperty.setName("java.version");
-
- syspropActivation.setProperty(syspropProperty);
-
+ syspropProperty.setName( "java.version" );
+
+ syspropActivation.setProperty( syspropProperty );
+
syspropActivated.setActivation( syspropActivation );
-
+
Profile defaultActivated = new Profile();
- defaultActivated.setId("defaultActivated");
-
+ defaultActivated.setId( "defaultActivated" );
+
Activation defaultActivation = new Activation();
-
- defaultActivation.setActiveByDefault(true);
-
+
+ defaultActivation.setActiveByDefault( true );
+
defaultActivated.setActivation( defaultActivation );
-
- ProfileManager profileManager = new DefaultProfileManager(getContainer());
-
- profileManager.addProfile(syspropActivated);
- profileManager.addProfile(defaultActivated);
-
+
+ ProfileManager profileManager = new DefaultProfileManager( getContainer() );
+
+ profileManager.addProfile( syspropActivated );
+ profileManager.addProfile( defaultActivated );
+
List active = profileManager.getActiveProfiles();
-
+
assertNotNull( active );
assertEquals( 1, active.size() );
- assertEquals("syspropActivated", ((Profile)active.get(0)).getId());
+ assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() );
}
- public void testShouldNotActivateReversalOfPresentSystemProperty() throws ProfileActivationException
+ public void testShouldNotActivateReversalOfPresentSystemProperty()
+ throws ProfileActivationException
{
Profile syspropActivated = new Profile();
- syspropActivated.setId("syspropActivated");
-
+ syspropActivated.setId( "syspropActivated" );
+
Activation syspropActivation = new Activation();
-
+
ActivationProperty syspropProperty = new ActivationProperty();
- syspropProperty.setName("!java.version");
-
- syspropActivation.setProperty(syspropProperty);
-
+ syspropProperty.setName( "!java.version" );
+
+ syspropActivation.setProperty( syspropProperty );
+
syspropActivated.setActivation( syspropActivation );
-
- ProfileManager profileManager = new DefaultProfileManager(getContainer());
-
- profileManager.addProfile(syspropActivated);
-
+
+ ProfileManager profileManager = new DefaultProfileManager( getContainer() );
+
+ profileManager.addProfile( syspropActivated );
+
List active = profileManager.getActiveProfiles();
-
+
assertNotNull( active );
assertEquals( 0, active.size() );
}
- public void testShouldOverrideAndActivateInactiveProfile() throws ProfileActivationException
+ public void testShouldOverrideAndActivateInactiveProfile()
+ throws ProfileActivationException
{
Profile syspropActivated = new Profile();
- syspropActivated.setId("syspropActivated");
-
+ syspropActivated.setId( "syspropActivated" );
+
Activation syspropActivation = new Activation();
-
+
ActivationProperty syspropProperty = new ActivationProperty();
- syspropProperty.setName("!java.version");
-
- syspropActivation.setProperty(syspropProperty);
-
+ syspropProperty.setName( "!java.version" );
+
+ syspropActivation.setProperty( syspropProperty );
+
syspropActivated.setActivation( syspropActivation );
-
- ProfileManager profileManager = new DefaultProfileManager(getContainer());
-
- profileManager.addProfile(syspropActivated);
-
- profileManager.explicitlyActivate("syspropActivated");
-
+
+ ProfileManager profileManager = new DefaultProfileManager( getContainer() );
+
+ profileManager.addProfile( syspropActivated );
+
+ profileManager.explicitlyActivate( "syspropActivated" );
+
List active = profileManager.getActiveProfiles();
-
+
assertNotNull( active );
assertEquals( 1, active.size() );
- assertEquals( "syspropActivated", ((Profile)active.get(0)).getId());
+ assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() );
}
- public void testShouldOverrideAndDeactivateActiveProfile() throws ProfileActivationException
+ public void testShouldOverrideAndDeactivateActiveProfile()
+ throws ProfileActivationException
{
Profile syspropActivated = new Profile();
- syspropActivated.setId("syspropActivated");
-
+ syspropActivated.setId( "syspropActivated" );
+
Activation syspropActivation = new Activation();
-
+
ActivationProperty syspropProperty = new ActivationProperty();
- syspropProperty.setName("java.version");
-
- syspropActivation.setProperty(syspropProperty);
-
+ syspropProperty.setName( "java.version" );
+
+ syspropActivation.setProperty( syspropProperty );
+
syspropActivated.setActivation( syspropActivation );
-
- ProfileManager profileManager = new DefaultProfileManager(getContainer());
-
- profileManager.addProfile(syspropActivated);
-
- profileManager.explicitlyDeactivate("syspropActivated");
-
+
+ ProfileManager profileManager = new DefaultProfileManager( getContainer() );
+
+ profileManager.addProfile( syspropActivated );
+
+ profileManager.explicitlyDeactivate( "syspropActivated" );
+
List active = profileManager.getActiveProfiles();
-
+
assertNotNull( active );
assertEquals( 0, active.size() );
}
- public void testOsActivationProfile() throws ProfileActivationException
+ public void testOsActivationProfile()
+ throws ProfileActivationException
{
Profile osActivated = new Profile();
- osActivated.setId("os-profile");
+ osActivated.setId( "os-profile" );
Activation osActivation = new Activation();
ActivationOS activationOS = new ActivationOS();
- activationOS.setName("!dddd");
+ activationOS.setName( "!dddd" );
- osActivation.setOs(activationOS);
+ osActivation.setOs( activationOS );
- osActivated.setActivation(osActivation);
+ osActivated.setActivation( osActivation );
- ProfileManager profileManager = new DefaultProfileManager(getContainer());
+ ProfileManager profileManager = new DefaultProfileManager( getContainer() );
- profileManager.addProfile(osActivated);
+ profileManager.addProfile( osActivated );
List active = profileManager.getActiveProfiles();
@@ -201,4 +206,30 @@
assertEquals( 1, active.size() );
}
+ public void testFileActivationProfile()
+ throws ProfileActivationException
+ {
+ Profile osActivated = new Profile();
+ osActivated.setId( "os-profile" );
+
+ Activation fileActivation = new Activation();
+
+ org.apache.maven.model.ActivationFile activationFile = new org.apache.maven.model.ActivationFile();
+
+ // Assume that junit exists
+ activationFile.setExists( "${user.home}/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar" );
+
+ fileActivation.setFile( activationFile );
+
+ osActivated.setActivation( fileActivation );
+
+ ProfileManager profileManager = new DefaultProfileManager( getContainer() );
+
+ profileManager.addProfile( osActivated );
+
+ List active = profileManager.getActiveProfiles();
+
+ assertNotNull( active );
+ assertEquals( 1, active.size() );
+ }
}