mirror of https://github.com/apache/maven.git
Removed old profile activators.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@748211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de818bc154
commit
ed13b8620d
|
@ -1,151 +0,0 @@
|
|||
package org.apache.maven.profiles.activation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.model.Activation;
|
||||
import org.apache.maven.model.ActivationFile;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
|
||||
import org.codehaus.plexus.logging.LogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component(role = ProfileActivator.class, hint = "file")
|
||||
public class FileProfileActivator
|
||||
implements ProfileActivator, LogEnabled
|
||||
{
|
||||
|
||||
private Logger logger;
|
||||
|
||||
public boolean canDetermineActivation( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
return ( profile.getActivation() != null ) && ( profile.getActivation().getFile() != null );
|
||||
}
|
||||
|
||||
public boolean isActive( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
ActivationFile actFile = activation.getFile();
|
||||
|
||||
if ( actFile != null )
|
||||
{
|
||||
// check if the file exists, if it does then the profile will be active
|
||||
String fileString = actFile.getExists();
|
||||
|
||||
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
|
||||
try
|
||||
{
|
||||
interpolator.addValueSource( new EnvarBasedValueSource() );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
interpolator.addValueSource( new MapBasedValueSource( System.getProperties() ) );
|
||||
|
||||
if ( StringUtils.isNotEmpty( fileString ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" );
|
||||
}
|
||||
catch ( InterpolationException e )
|
||||
{
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
logger.debug( "Failed to interpolate exists file location for profile activator: " + fileString,
|
||||
e );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn( "Failed to interpolate exists file location for profile activator: " + fileString +
|
||||
". Run in debug mode (-X) for more information." );
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = FileUtils.fileExists( fileString );
|
||||
|
||||
if ( logger != null )
|
||||
{
|
||||
logger.debug(
|
||||
"FileProfileActivator: Checking file existence for: " + fileString + ". Result: " + result );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// check if the file is missing, if it is then the profile will be active
|
||||
fileString = actFile.getMissing();
|
||||
|
||||
if ( StringUtils.isNotEmpty( fileString ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
fileString = StringUtils.replace( interpolator.interpolate( fileString, "" ), "\\", "/" );
|
||||
}
|
||||
catch ( InterpolationException e )
|
||||
{
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
logger.debug(
|
||||
"Failed to interpolate missing file location for profile activator: " + fileString, e );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn( "Failed to interpolate missing file location for profile activator: " +
|
||||
fileString + ". Run in debug mode (-X) for more information." );
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = !FileUtils.fileExists( fileString );
|
||||
|
||||
if ( logger != null )
|
||||
{
|
||||
logger.debug(
|
||||
"FileProfileActivator: Checking file is missing for: " + fileString + ". Result: " + result );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( logger != null )
|
||||
{
|
||||
logger.debug( "FileProfileActivator: no file specified. Skipping activation." );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void enableLogging( Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
package org.apache.maven.profiles.activation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.model.Activation;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@Component(role = ProfileActivator.class, hint = "jdk-prefix")
|
||||
public class JdkPrefixProfileActivator
|
||||
extends DetectedProfileActivator
|
||||
{
|
||||
|
||||
public static final String JDK_VERSION = "java.version";
|
||||
|
||||
public boolean isActive( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
String jdk = activation.getJdk();
|
||||
|
||||
Properties props = context.getExecutionProperties();
|
||||
String javaVersion = props.getProperty( JDK_VERSION );
|
||||
if ( javaVersion == null )
|
||||
{
|
||||
getLogger().warn(
|
||||
"Cannot locate java version property: " + JDK_VERSION + ". NOT enabling profile: " + profile.getId() );
|
||||
return false;
|
||||
}
|
||||
|
||||
return isActive( javaVersion, jdk );
|
||||
}
|
||||
|
||||
public boolean isActive( String jdkVersion, String expression )
|
||||
{
|
||||
boolean reverse = false;
|
||||
|
||||
if ( expression.startsWith( "!" ) )
|
||||
{
|
||||
reverse = true;
|
||||
expression = expression.substring( 1 );
|
||||
}
|
||||
|
||||
// null case is covered by canDetermineActivation(), so we can do a straight startsWith() here.
|
||||
boolean result = false;
|
||||
if ( expression.endsWith( "+" ) )
|
||||
{
|
||||
result = compareTo( asIntArray( jdkVersion ), asIntArray( expression ) ) >= 0;
|
||||
}
|
||||
else if ( expression.endsWith( "-" ) )
|
||||
{
|
||||
result = compareTo( asIntArray( jdkVersion ), asIntArray( expression ) ) <= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// null case is covered by canDetermineActivation(), so we can do a straight startsWith() here.
|
||||
result = jdkVersion.startsWith( expression );
|
||||
}
|
||||
|
||||
if ( reverse )
|
||||
{
|
||||
return !result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canDetectActivation( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
return ( profile.getActivation() != null ) && StringUtils.isNotEmpty( profile.getActivation().getJdk() );
|
||||
}
|
||||
|
||||
private static void parseNum( List pList, StringBuffer pBuffer )
|
||||
{
|
||||
if ( pBuffer.length() > 0 )
|
||||
{
|
||||
pList.add( new Integer( pBuffer.toString() ) );
|
||||
pBuffer.setLength( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transforms a string like "1.5.0_06" into
|
||||
* new int[]{1, 5, 0, 6}.
|
||||
*/
|
||||
private static int[] asIntArray( String pVersion )
|
||||
{
|
||||
List nums = new ArrayList();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while ( pVersion.length() > 0 )
|
||||
{
|
||||
char c = pVersion.charAt( 0 );
|
||||
pVersion = pVersion.substring( 1 );
|
||||
if ( Character.isDigit( c ) )
|
||||
{
|
||||
sb.append( c );
|
||||
}
|
||||
else
|
||||
{
|
||||
parseNum( nums, sb );
|
||||
}
|
||||
}
|
||||
parseNum( nums, sb );
|
||||
int[] result = new int[nums.size()];
|
||||
for ( int i = 0; i < result.length; i++ )
|
||||
{
|
||||
result[i] = ( (Integer) nums.get( i ) ).intValue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method compares to integer arrays, as created
|
||||
* by {@link #asIntArray(String)}.
|
||||
*/
|
||||
private static int compareTo( int[] pVersion1, int[] pVersion2 )
|
||||
{
|
||||
int len = Math.max( pVersion1.length, pVersion2.length );
|
||||
for ( int i = 0; i < len; i++ )
|
||||
{
|
||||
int n1 = pVersion1.length > i ? pVersion1[i] : 0;
|
||||
int n2 = pVersion2.length > i ? pVersion2[i] : 0;
|
||||
int result = n1 - n2;
|
||||
if ( result != 0 )
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
package org.apache.maven.profiles.activation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.model.Activation;
|
||||
import org.apache.maven.model.ActivationOS;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.Os;
|
||||
|
||||
@Component(role = ProfileActivator.class, hint = "os")
|
||||
public class OperatingSystemProfileActivator
|
||||
implements ProfileActivator
|
||||
{
|
||||
|
||||
public boolean canDetermineActivation( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
return ( activation != null ) && ( activation.getOs() != null );
|
||||
}
|
||||
|
||||
public boolean isActive( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
ActivationOS os = activation.getOs();
|
||||
|
||||
boolean result = ensureAtLeastOneNonNull( os );
|
||||
|
||||
if ( result && ( os.getFamily() != null ) )
|
||||
{
|
||||
result = determineFamilyMatch( os.getFamily() );
|
||||
}
|
||||
if ( result && ( os.getName() != null ) )
|
||||
{
|
||||
result = determineNameMatch( os.getName() );
|
||||
}
|
||||
if ( result && ( os.getArch() != null ) )
|
||||
{
|
||||
result = determineArchMatch( os.getArch() );
|
||||
}
|
||||
if ( result && ( os.getVersion() != null ) )
|
||||
{
|
||||
result = determineVersionMatch( os.getVersion() );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean ensureAtLeastOneNonNull( ActivationOS os )
|
||||
{
|
||||
return ( os.getArch() != null ) || ( os.getFamily() != null ) || ( os.getName() != null ) ||
|
||||
( os.getVersion() != null );
|
||||
}
|
||||
|
||||
private boolean determineVersionMatch( String version )
|
||||
{
|
||||
String test = version;
|
||||
boolean reverse = false;
|
||||
|
||||
if ( test.startsWith( "!" ) )
|
||||
{
|
||||
reverse = true;
|
||||
test = test.substring( 1 );
|
||||
}
|
||||
|
||||
boolean result = Os.isVersion( test );
|
||||
|
||||
if ( reverse )
|
||||
{
|
||||
return !result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean determineArchMatch( String arch )
|
||||
{
|
||||
String test = arch;
|
||||
boolean reverse = false;
|
||||
|
||||
if ( test.startsWith( "!" ) )
|
||||
{
|
||||
reverse = true;
|
||||
test = test.substring( 1 );
|
||||
}
|
||||
|
||||
boolean result = Os.isArch( test );
|
||||
|
||||
if ( reverse )
|
||||
{
|
||||
return !result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean determineNameMatch( String name )
|
||||
{
|
||||
String test = name;
|
||||
boolean reverse = false;
|
||||
|
||||
if ( test.startsWith( "!" ) )
|
||||
{
|
||||
reverse = true;
|
||||
test = test.substring( 1 );
|
||||
}
|
||||
|
||||
boolean result = Os.isName( test );
|
||||
|
||||
if ( reverse )
|
||||
{
|
||||
return !result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean determineFamilyMatch( String family )
|
||||
{
|
||||
String test = family;
|
||||
boolean reverse = false;
|
||||
|
||||
if ( test.startsWith( "!" ) )
|
||||
{
|
||||
reverse = true;
|
||||
test = test.substring( 1 );
|
||||
}
|
||||
|
||||
boolean result = Os.isFamily( test );
|
||||
|
||||
if ( reverse )
|
||||
{
|
||||
return !result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package org.apache.maven.profiles.activation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.model.Activation;
|
||||
import org.apache.maven.model.ActivationProperty;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component(role = ProfileActivator.class, hint = "system-property")
|
||||
public class SystemPropertyProfileActivator
|
||||
extends DetectedProfileActivator
|
||||
{
|
||||
|
||||
protected boolean canDetectActivation( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
return ( profile.getActivation() != null ) && ( profile.getActivation().getProperty() != null );
|
||||
}
|
||||
|
||||
public boolean isActive( Profile profile, ProfileActivationContext context )
|
||||
{
|
||||
Activation activation = profile.getActivation();
|
||||
|
||||
ActivationProperty property = activation.getProperty();
|
||||
|
||||
if ( property != null )
|
||||
{
|
||||
String name = property.getName();
|
||||
boolean reverseName = false;
|
||||
|
||||
if ( name.startsWith( "!" ) )
|
||||
{
|
||||
reverseName = true;
|
||||
name = name.substring( 1 );
|
||||
}
|
||||
|
||||
Properties execProperties = context.getExecutionProperties();
|
||||
String sysValue = execProperties.getProperty( name );
|
||||
|
||||
String propValue = property.getValue();
|
||||
if ( StringUtils.isNotEmpty( propValue ) )
|
||||
{
|
||||
boolean reverseValue = false;
|
||||
if ( propValue.startsWith( "!" ) )
|
||||
{
|
||||
reverseValue = true;
|
||||
propValue = propValue.substring( 1 );
|
||||
}
|
||||
|
||||
// we have a value, so it has to match the system value...
|
||||
boolean result = propValue.equals( sysValue );
|
||||
|
||||
if ( reverseValue )
|
||||
{
|
||||
return !result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean result = StringUtils.isNotEmpty( sysValue );
|
||||
|
||||
if ( reverseName )
|
||||
{
|
||||
return !result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package org.apache.maven.profiles.activation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.model.Activation;
|
||||
import org.apache.maven.model.Profile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test case for the {@link FileProfileActivator}.
|
||||
*
|
||||
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class FileProfileActivatorTest
|
||||
extends TestCase
|
||||
{
|
||||
private FileProfileActivator activator = new FileProfileActivator();
|
||||
|
||||
public void testFileActivationProfile()
|
||||
throws ProfileActivationException, IOException
|
||||
{
|
||||
org.apache.maven.model.ActivationFile activationFile = new org.apache.maven.model.ActivationFile();
|
||||
|
||||
File tempFile = File.createTempFile( "FileProfileActivatorTest.", ".txt" );
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
// Assume that junit exists
|
||||
activationFile.setExists( tempFile.getAbsolutePath() );
|
||||
|
||||
Activation fileActivation = new Activation();
|
||||
fileActivation.setFile( activationFile );
|
||||
|
||||
Profile profile = new Profile();
|
||||
profile.setActivation( fileActivation );
|
||||
|
||||
Properties props = new Properties();
|
||||
ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
|
||||
|
||||
assertTrue( activator.isActive( profile, ctx ) );
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package org.apache.maven.profiles.activation;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
/** Test case for the {@link JdkPrefixProfileActivator}.
|
||||
*/
|
||||
public class JdkPrefixProfileActivatorTest extends TestCase
|
||||
{
|
||||
/** Test for the basic match "equals".
|
||||
*/
|
||||
public void testBasicMatch()
|
||||
{
|
||||
JdkPrefixProfileActivator activator = new JdkPrefixProfileActivator();
|
||||
assertTrue( activator.isActive( "1.5", "1.5" ) );
|
||||
assertFalse( activator.isActive( "1.4", "1.5" ) );
|
||||
assertFalse( activator.isActive( "1.6", "1.5" ) );
|
||||
assertTrue( activator.isActive( "1.5.0_06", "1.5" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "1.5.1" ) );
|
||||
assertFalse( activator.isActive( "1.5", "!1.5" ) );
|
||||
assertTrue( activator.isActive( "1.4", "!1.5" ) );
|
||||
assertTrue( activator.isActive( "1.6", "!1.5" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "!1.5" ) );
|
||||
assertTrue( activator.isActive( "1.5.0_06", "!1.5.1" ) );
|
||||
}
|
||||
|
||||
/** Test for the match "greather than or equal".
|
||||
*/
|
||||
public void testGreatherThanOrEqualMatch()
|
||||
{
|
||||
JdkPrefixProfileActivator activator = new JdkPrefixProfileActivator();
|
||||
assertTrue( activator.isActive( "1.5.0_06", "1.5+" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "!1.5+" ) );
|
||||
assertTrue( activator.isActive( "1.5.0_06", "1.4+" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "!1.4+" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "1.6+" ) );
|
||||
assertTrue( activator.isActive( "1.5.0_06", "!1.6+" ) );
|
||||
assertTrue( activator.isActive( "1.5.0_06", "1.5.0.0+" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "!1.5.0.0+" ) );
|
||||
assertTrue( activator.isActive( "1.5.0_06", "1.5.0.6+" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "!1.5.0.6+" ) );
|
||||
assertFalse( activator.isActive( "1.5.0_06", "1.5.0.7+" ) );
|
||||
assertTrue( activator.isActive( "1.5.0_06", "!1.5.0.7+" ) );
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package org.apache.maven.profiles.activation;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.model.Activation;
|
||||
import org.apache.maven.model.ActivationProperty;
|
||||
import org.apache.maven.model.Profile;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SystemPropertyProfileActivatorTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
private SystemPropertyProfileActivator activator = new SystemPropertyProfileActivator();
|
||||
|
||||
public void testCanDetect_ShouldReturnTrueWhenActivationPropertyIsPresent()
|
||||
throws Exception
|
||||
{
|
||||
ActivationProperty prop = new ActivationProperty();
|
||||
prop.setName( "test" );
|
||||
|
||||
Activation activation = new Activation();
|
||||
|
||||
activation.setProperty( prop );
|
||||
|
||||
Profile profile = new Profile();
|
||||
|
||||
profile.setActivation( activation );
|
||||
|
||||
Properties props = new Properties();
|
||||
ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
|
||||
|
||||
assertTrue( activator.canDetermineActivation( profile, ctx ) );
|
||||
}
|
||||
|
||||
public void testCanDetect_ShouldReturnFalseWhenActivationPropertyIsNotPresent()
|
||||
throws Exception
|
||||
{
|
||||
Activation activation = new Activation();
|
||||
|
||||
Profile profile = new Profile();
|
||||
|
||||
profile.setActivation( activation );
|
||||
|
||||
Properties props = new Properties();
|
||||
ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
|
||||
|
||||
assertFalse( activator.canDetermineActivation( profile, ctx ) );
|
||||
}
|
||||
|
||||
public void testIsActive_ShouldReturnTrueWhenPropertyNameSpecifiedAndPresent()
|
||||
throws Exception
|
||||
{
|
||||
ActivationProperty prop = new ActivationProperty();
|
||||
prop.setName( "test" );
|
||||
|
||||
Activation activation = new Activation();
|
||||
|
||||
activation.setProperty( prop );
|
||||
|
||||
Profile profile = new Profile();
|
||||
|
||||
profile.setActivation( activation );
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty( "test", "true" );
|
||||
ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
|
||||
|
||||
assertTrue( activator.isActive( profile, ctx ) );
|
||||
}
|
||||
|
||||
public void testIsActive_ShouldReturnFalseWhenPropertyNameSpecifiedAndMissing()
|
||||
throws Exception
|
||||
{
|
||||
ActivationProperty prop = new ActivationProperty();
|
||||
prop.setName( "test" );
|
||||
|
||||
Activation activation = new Activation();
|
||||
|
||||
activation.setProperty( prop );
|
||||
|
||||
Profile profile = new Profile();
|
||||
|
||||
profile.setActivation( activation );
|
||||
|
||||
Properties props = new Properties();
|
||||
ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false );
|
||||
|
||||
assertFalse( activator.isActive( profile, ctx ) );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue