continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r702088 - in /continuum/branches/continuum-1.2.x: continuum-commons/src/main/java/org/apache/continuum/installation/ continuum-commons/src/main/java/org/apache/continuum/profile/ continuum-commons/src/test/java/org/apache/continuum/ continu...
Date Mon, 06 Oct 2008 10:51:05 GMT
Author: ctan
Date: Mon Oct  6 03:51:04 2008
New Revision: 702088

URL: http://svn.apache.org/viewvc?rev=702088&view=rev
Log:
moved DefaultInstallationService and DefaultProfileService to continuum-commons

Added:
    continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/installation/
    continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/installation/DefaultInstallationService.java
    continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/profile/
    continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/profile/DefaultProfileService.java
    continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/
    continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/installation/
    continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/installation/DefaultInstallationServiceTest.java
    continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/profile/
    continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/profile/DefaultProfileServiceTest.java
Removed:
    continuum/branches/continuum-1.2.x/continuum-core/src/main/java/org/apache/maven/continuum/installation/
    continuum/branches/continuum-1.2.x/continuum-core/src/main/java/org/apache/maven/continuum/profile/
    continuum/branches/continuum-1.2.x/continuum-core/src/test/java/org/apache/maven/continuum/installation/
    continuum/branches/continuum-1.2.x/continuum-core/src/test/java/org/apache/maven/continuum/profile/

Added: continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/installation/DefaultInstallationService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/installation/DefaultInstallationService.java?rev=702088&view=auto
==============================================================================
--- continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/installation/DefaultInstallationService.java (added)
+++ continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/installation/DefaultInstallationService.java Mon Oct  6 03:51:04 2008
@@ -0,0 +1,462 @@
+package org.apache.continuum.installation;
+
+/*
+ * 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.continuum.dao.InstallationDao;
+import org.apache.maven.continuum.execution.ExecutorConfigurator;
+import org.apache.maven.continuum.installation.AlreadyExistsInstallationException;
+import org.apache.maven.continuum.installation.InstallationException;
+import org.apache.maven.continuum.installation.InstallationService;
+import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
+import org.apache.maven.continuum.profile.ProfileException;
+import org.apache.maven.continuum.profile.ProfileService;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:olamy@codehaus.org">olamy</a>
+ * @version $Id: DefaultInstallationService.java 684085 2008-08-08 20:48:14Z evenisse $
+ * @plexus.component role="org.apache.maven.continuum.installation.InstallationService"
+ * TODO use some cache mechanism to prevent always reading from store ?
+ * @since 13 juin 07
+ */
+public class DefaultInstallationService
+    extends AbstractLogEnabled
+    implements InstallationService, Initializable
+{
+    /**
+     * @plexus.requirement
+     */
+    private InstallationDao installationDao;
+
+    /**
+     * @plexus.requirement role-hint="default"
+     */
+    private ProfileService profileService;
+
+    private Map<String, ExecutorConfigurator> typesValues;
+
+    // ---------------------------------------------
+    // Plexus lifecycle
+    // ---------------------------------------------
+
+    public void initialize()
+        throws InitializationException
+    {
+        this.typesValues = new HashMap<String, ExecutorConfigurator>();
+        this.typesValues.put( InstallationService.ANT_TYPE,
+                              new ExecutorConfigurator( "ant", "bin", "ANT_HOME", "-version" ) );
+
+        this.typesValues.put( InstallationService.ENVVAR_TYPE, null );
+        this.typesValues.put( InstallationService.JDK_TYPE,
+                              new ExecutorConfigurator( "java", "bin", "JAVA_HOME", "-version" ) );
+        this.typesValues.put( InstallationService.MAVEN1_TYPE,
+                              new ExecutorConfigurator( "maven", "bin", "MAVEN_HOME", "-v" ) );
+        this.typesValues
+            .put( InstallationService.MAVEN2_TYPE, new ExecutorConfigurator( "mvn", "bin", "M2_HOME", "-v" ) );
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#add(org.apache.maven.continuum.model.system.Installation)
+     */
+    public Installation add( Installation installation )
+        throws InstallationException, AlreadyExistsInstallationException
+    {
+        try
+        {
+            return this.add( installation, false );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // normally cannot happend here but anyway we throw the exception
+            throw new InstallationException( e.getMessage(), e );
+        }
+    }
+
+    public Installation add( Installation installation, boolean automaticProfile )
+        throws InstallationException, AlreadyExistsProfileException, AlreadyExistsInstallationException
+    {
+        if ( alreadyExistInstallationName( installation ) )
+        {
+            throw new AlreadyExistsInstallationException(
+                "Installation with name " + installation.getName() + " already exists" );
+        }
+        // TODO must be done in the same transaction
+        Installation storedOne = null;
+        try
+        {
+            String envVarName = this.getEnvVar( installation.getType() );
+            // override with the defined var name for defined types
+            if ( StringUtils.isNotEmpty( envVarName ) )
+            {
+                installation.setVarName( envVarName );
+            }
+            storedOne = installationDao.addInstallation( installation );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+        try
+        {
+            if ( automaticProfile )
+            {
+                Profile profile = new Profile();
+                profile.setName( storedOne.getName() );
+                profile = profileService.addProfile( profile );
+                profileService.addInstallationInProfile( profile, storedOne );
+            }
+        }
+        catch ( ProfileException e )
+        {
+            throw new InstallationException( "failed to create automatic Profile " + e.getMessage(), e );
+        }
+        return storedOne;
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#delete(org.apache.maven.continuum.model.system.Installation)
+     */
+    public void delete( Installation installation )
+        throws InstallationException
+    {
+        try
+        {
+            installationDao.removeInstallation( installation );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#getAllInstallations()
+     */
+    @SuppressWarnings("unchecked")
+    public List<Installation> getAllInstallations()
+        throws InstallationException
+    {
+        try
+        {
+            List installations = installationDao.getAllInstallations();
+            return installations == null ? Collections.EMPTY_LIST : installations;
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#getInstallation(int)
+     */
+    public Installation getInstallation( int installationId )
+        throws InstallationException
+    {
+        try
+        {
+            return installationDao.getInstallation( installationId );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#update(org.apache.maven.continuum.model.system.Installation)
+     */
+    public void update( Installation installation )
+        throws InstallationException
+    {
+        try
+        {
+            Installation stored = getInstallation( installation.getInstallationId() );
+            if ( stored == null )
+            {
+                throw new InstallationException( "installation with name " + installation.getName() + " not exists" );
+            }
+
+            stored.setName( installation.getName() );
+            stored.setType( installation.getType() );
+            String envVarName = this.getEnvVar( installation.getType() );
+            // override with the defined var name for defined types
+            if ( StringUtils.isNotEmpty( envVarName ) )
+            {
+                installation.setVarName( envVarName );
+            }
+            else
+            {
+                stored.setVarName( installation.getVarName() );
+            }
+            stored.setVarValue( installation.getVarValue() );
+            installationDao.updateInstallation( stored );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#getExecutorConfigurator(java.lang.String)
+     */
+    public ExecutorConfigurator getExecutorConfigurator( String type )
+    {
+        return this.typesValues.get( type );
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#getEnvVar(java.lang.String)
+     */
+    public String getEnvVar( String type )
+    {
+        ExecutorConfigurator executorConfigurator = this.typesValues.get( type );
+        return executorConfigurator == null ? null : executorConfigurator.getEnvVar();
+    }
+
+    // -------------------------------------------------------------
+    // versions informations on jdk and builders (mvn, maven, ant )
+    // -------------------------------------------------------------
+
+    /**
+     * TODO replace with calling getExecutorConfiguratorVersion
+     *
+     * @see org.apache.maven.continuum.installation.InstallationService#getDefaultJdkInformations()
+     */
+    public List<String> getDefaultJdkInformations()
+        throws InstallationException
+    {
+        try
+        {
+            Properties systemEnvVars = CommandLineUtils.getSystemEnvVars( false );
+
+            String javaHome = (String) systemEnvVars.get( "JAVA_HOME" );
+            // olamy : JAVA_HOME can not exists with a mac user
+            if ( StringUtils.isEmpty( javaHome ) )
+            {
+                return getJavaHomeInformations( System.getProperty( "java.home" ) );
+            }
+            return getJavaHomeInformations( javaHome );
+
+        }
+        catch ( IOException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+        catch ( CommandLineException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * TODO replace with calling getExecutorConfiguratorVersion
+     *
+     * @see org.apache.maven.continuum.installation.InstallationService#getJdkInformations(org.apache.maven.continuum.model.system.Installation)
+     */
+    public List<String> getJdkInformations( Installation installation )
+        throws InstallationException
+    {
+        if ( installation == null )
+        {
+            return getDefaultJdkInformations();
+        }
+        if ( StringUtils.isEmpty( installation.getVarValue() ) )
+        {
+            return getDefaultJdkInformations();
+        }
+        try
+        {
+            return getJavaHomeInformations( installation.getVarValue() );
+        }
+        catch ( CommandLineException e )
+        {
+            throw new InstallationException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @param javaHome
+     * @return
+     * @throws CommandLineException
+     */
+    private List<String> getJavaHomeInformations( String javaHome )
+        throws CommandLineException
+    {
+        Commandline commandline = new Commandline();
+
+        String executable = javaHome + File.separator + "bin" + File.separator + "java";
+
+        commandline.setExecutable( executable );
+        commandline.addArguments( new String[]{"-version"} );
+        final List<String> cliOutput = new ArrayList<String>();
+        //TODO ShellCommandHelper ?
+        int result = CommandLineUtils.executeCommandLine( commandline, new StreamConsumer()
+        {
+            public void consumeLine( String line )
+            {
+                cliOutput.add( line );
+            }
+        }, new StreamConsumer()
+        {
+            public void consumeLine( String line )
+            {
+                cliOutput.add( line );
+            }
+        } );
+        if ( result != 0 )
+        {
+            throw new CommandLineException( "cli to get JAVA_HOME informations return code " + result );
+        }
+        return cliOutput;
+    }
+
+    private Map<String, String> getEnvVars( Profile profile )
+    {
+        Map<String, String> environnments = new HashMap<String, String>();
+        if ( profile == null )
+        {
+            return environnments;
+        }
+        if ( profile.getBuilder() != null )
+        {
+            environnments.put( profile.getBuilder().getVarName(), profile.getBuilder().getVarValue() );
+        }
+        if ( profile.getJdk() != null )
+        {
+            environnments.put( profile.getJdk().getVarName(), profile.getJdk().getVarValue() );
+        }
+        if ( profile.getEnvironmentVariables() != null )
+        {
+            for ( Installation installation : (List<Installation>) profile.getEnvironmentVariables() )
+            {
+                environnments.put( installation.getVarName(), installation.getVarValue() );
+            }
+        }
+        return environnments;
+    }
+
+    /**
+     * @see org.apache.maven.continuum.installation.InstallationService#getExecutorConfiguratorVersion(java.lang.String,org.apache.maven.continuum.execution.ExecutorConfigurator,Profile)
+     */
+    @SuppressWarnings("unchecked")
+    public List<String> getExecutorConfiguratorVersion( String path, ExecutorConfigurator executorConfigurator,
+                                                        Profile profile )
+        throws InstallationException
+    {
+
+        if ( executorConfigurator == null )
+        {
+            return Collections.EMPTY_LIST;
+        }
+        if ( executorConfigurator.getExecutable() == null )
+        {
+            return Collections.EMPTY_LIST;
+        }
+        StringBuilder executable = new StringBuilder();
+        try
+        {
+            Commandline commandline = new Commandline();
+            if ( StringUtils.isNotEmpty( path ) )
+            {
+                executable.append( path ).append( File.separator );
+                executable.append( executorConfigurator.getRelativePath() + File.separator );
+                commandline.addEnvironment( executorConfigurator.getEnvVar(), path );
+            }
+            //Installations are env var they must be add if exists
+            Map<String, String> environments = getEnvVars( profile );
+            // no null check we use a private method just here
+            for ( Iterator<String> iterator = environments.keySet().iterator(); iterator.hasNext(); )
+            {
+                String key = iterator.next();
+                String value = environments.get( key );
+                commandline.addEnvironment( key, value );
+            }
+
+            executable = executable.append( executorConfigurator.getExecutable() );
+            commandline.setExecutable( executable.toString() );
+            commandline.addArguments( new String[]{executorConfigurator.getVersionArgument()} );
+            final List<String> cliOutput = new ArrayList<String>();
+            //TODO ShellCommandHelper ?
+            int result = CommandLineUtils.executeCommandLine( commandline, new StreamConsumer()
+            {
+                public void consumeLine( String line )
+                {
+                    cliOutput.add( line );
+                }
+            }, new StreamConsumer()
+            {
+                public void consumeLine( String line )
+                {
+                    cliOutput.add( line );
+                }
+            } );
+            if ( result != 0 )
+            {
+                throw new InstallationException( "cli to get " + executable + " version return code " + result );
+            }
+            return cliOutput;
+        }
+        catch ( CommandLineException e )
+        {
+            getLogger().error(
+                "fail to execute " + executable + " with arg " + executorConfigurator.getVersionArgument() );
+            throw new InstallationException( e.getMessage(), e );
+        }
+    }
+
+    private boolean alreadyExistInstallationName( Installation installation )
+        throws InstallationException
+    {
+        List<Installation> all = getAllInstallations();
+        for ( Installation install : all )
+        {
+            if ( org.apache.commons.lang.StringUtils.equals( installation.getName(), install.getName() ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/profile/DefaultProfileService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/profile/DefaultProfileService.java?rev=702088&view=auto
==============================================================================
--- continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/profile/DefaultProfileService.java (added)
+++ continuum/branches/continuum-1.2.x/continuum-commons/src/main/java/org/apache/continuum/profile/DefaultProfileService.java Mon Oct  6 03:51:04 2008
@@ -0,0 +1,316 @@
+package org.apache.continuum.profile;
+
+/*
+ * 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.commons.lang.StringUtils;
+import org.apache.continuum.dao.ProfileDao;
+import org.apache.maven.continuum.installation.InstallationService;
+import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
+import org.apache.maven.continuum.profile.ProfileException;
+import org.apache.maven.continuum.profile.ProfileService;
+import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:olamy@codehaus.org">olamy</a>
+ * @version $Id: DefaultProfileService.java 698412 2008-09-24 01:55:19Z ctan $
+ * @plexus.component role="org.apache.maven.continuum.profile.ProfileService"
+ * TODO use some cache mechanism to prevent always reading from store ?
+ * @since 15 juin 07
+ */
+public class DefaultProfileService
+    implements ProfileService
+{
+    /**
+     * @plexus.requirement
+     */
+    private ProfileDao profileDao;
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#updateProfile(org.apache.maven.continuum.model.system.Profile)
+     */
+    public void updateProfile( Profile profile )
+        throws ProfileException, AlreadyExistsProfileException
+    {
+
+        // already exists check should be done in the same transaction
+        // but we assume we don't have a huge load and a lot of concurrent access ;-)
+        if ( alreadyExistsProfileName( profile ) )
+        {
+            throw new AlreadyExistsProfileException( "profile with name " + profile.getName() + " already exists" );
+        }
+
+        try
+        {
+            Profile stored = getProfile( profile.getId() );
+            stored.setActive( profile.isActive() );
+            stored.setBuilder( profile.getBuilder() );
+            stored.setBuildWithoutChanges( profile.isBuildWithoutChanges() );
+            stored.setDescription( profile.getDescription() );
+            stored.setJdk( profile.getJdk() );
+            stored.setName( profile.getName() );
+            stored.setEnvironmentVariables( profile.getEnvironmentVariables() );
+            profileDao.updateProfile( stored );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }
+
+    public void updateProfileCheckDuplicateName( Profile profile, boolean checkDuplicateName )
+        throws ProfileException, AlreadyExistsProfileException
+    {
+        if ( checkDuplicateName )
+        {
+            // already exists check should be done in the same transaction
+            // but we assume we don't have a huge load and a lot of concurrent access ;-)
+            if ( alreadyExistsProfileName( profile ) )
+            {
+                throw new AlreadyExistsProfileException( "profile with name " + profile.getName() + " already exists" );
+            }
+        }
+        try
+        {
+            Profile stored = getProfile( profile.getId() );
+            stored.setActive( profile.isActive() );
+            stored.setBuilder( profile.getBuilder() );
+            stored.setBuildWithoutChanges( profile.isBuildWithoutChanges() );
+            stored.setDescription( profile.getDescription() );
+            stored.setJdk( profile.getJdk() );
+            stored.setName( profile.getName() );
+            stored.setEnvironmentVariables( profile.getEnvironmentVariables() );
+            profileDao.updateProfile( stored );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#addProfile(org.apache.maven.continuum.model.system.Profile)
+     */
+    public Profile addProfile( Profile profile )
+        throws ProfileException, AlreadyExistsProfileException
+    {
+        // already exists check should be done in the same transaction
+        // but we assume we don't have a huge load and a lot of concurrent access ;-)
+        if ( alreadyExistsProfileName( profile ) )
+        {
+            throw new AlreadyExistsProfileException( "profile with name " + profile.getName() + " already exists" );
+        }
+        profile.setBuilder( null );
+        profile.setJdk( null );
+        profile.setEnvironmentVariables( null );
+        return profileDao.addProfile( profile );
+    }
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#deleteProfile(int)
+     */
+    public void deleteProfile( int profileId )
+        throws ProfileException
+    {
+        try
+        {
+            profileDao.removeProfile( getProfile( profileId ) );
+        }
+        catch ( Exception e )
+        {
+            throw new ProfileException( "Cannot remove the profile", e );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#getAllProfiles()
+     */
+    public List<Profile> getAllProfiles()
+        throws ProfileException
+    {
+        return profileDao.getAllProfilesByName();
+    }
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#getProfile(int)
+     */
+    public Profile getProfile( int profileId )
+        throws ProfileException
+    {
+        try
+        {
+            return profileDao.getProfile( profileId );
+        }
+        catch ( ContinuumObjectNotFoundException e )
+        {
+            // really ignore ?
+            return null;
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#setBuilderInProfile(org.apache.maven.continuum.model.system.Profile,org.apache.maven.continuum.model.system.Installation)
+     */
+    public void setBuilderInProfile( Profile profile, Installation builder )
+        throws ProfileException
+    {
+        Profile stored = getProfile( profile.getId() );
+        stored.setBuilder( builder );
+        try
+        {
+            profileDao.updateProfile( stored );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#setJdkInProfile(org.apache.maven.continuum.model.system.Profile,org.apache.maven.continuum.model.system.Installation)
+     */
+    public void setJdkInProfile( Profile profile, Installation jdk )
+        throws ProfileException
+    {
+        Profile stored = getProfile( profile.getId() );
+        stored.setJdk( jdk );
+        try
+        {
+            profileDao.updateProfile( stored );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.continuum.profile.ProfileService#addEnvVarInProfile(org.apache.maven.continuum.model.system.Profile,org.apache.maven.continuum.model.system.Installation)
+     */
+    public void addEnvVarInProfile( Profile profile, Installation envVar )
+        throws ProfileException
+    {
+        Profile stored = getProfile( profile.getId() );
+        stored.addEnvironmentVariable( envVar );
+        try
+        {
+            profileDao.updateProfile( stored );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }
+
+    public void addInstallationInProfile( Profile profile, Installation installation )
+        throws ProfileException
+    {
+        if ( InstallationService.JDK_TYPE.equals( installation.getType() ) )
+        {
+            setJdkInProfile( profile, installation );
+        }
+        else if ( InstallationService.MAVEN1_TYPE.equals( installation.getType() ) ||
+            InstallationService.MAVEN2_TYPE.equals( installation.getType() ) ||
+            InstallationService.ANT_TYPE.equals( installation.getType() ) )
+        {
+            setBuilderInProfile( profile, installation );
+        }
+        else
+        {
+            addEnvVarInProfile( profile, installation );
+        }
+
+    }
+
+    public void removeInstallationFromProfile( Profile profile, Installation installation )
+        throws ProfileException
+    {
+        Profile stored = getProfile( profile.getId() );
+        if ( InstallationService.JDK_TYPE.equals( installation.getType() ) )
+        {
+            stored.setJdk( null );
+        }
+        else if ( InstallationService.MAVEN1_TYPE.equals( installation.getType() ) ||
+            InstallationService.MAVEN2_TYPE.equals( installation.getType() ) ||
+            InstallationService.ANT_TYPE.equals( installation.getType() ) )
+        {
+            stored.setBuilder( null );
+        }
+        else
+        {
+            // remove one
+            List<Installation> storedEnvVars = stored.getEnvironmentVariables();
+            List<Installation> newEnvVars = new ArrayList<Installation>();
+            for ( Installation storedInstallation : storedEnvVars )
+            {
+                if ( !StringUtils.equals( storedInstallation.getName(), installation.getName() ) )
+                {
+                    newEnvVars.add( storedInstallation );
+                }
+            }
+            stored.setEnvironmentVariables( newEnvVars );
+        }
+        try
+        {
+            updateProfileCheckDuplicateName( stored, false );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // normally cannot happend here but anyway we throw the exception
+            throw new ProfileException( e.getMessage(), e );
+        }
+    }
+
+
+    public Profile getProfileWithName( String profileName )
+        throws ProfileException
+    {
+        List<Profile> allProfiles = getAllProfiles();
+        for ( Profile profile : allProfiles )
+        {
+            if ( StringUtils.equals( profile.getName(), profileName ) )
+            {
+                return profile;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @param profile
+     * @return true if profile with same name (<b>case sensitive</b>) exists
+     * @throws ProfileException
+     */
+    private boolean alreadyExistsProfileName( Profile profile )
+        throws ProfileException
+    {
+        return getProfileWithName( profile.getName() ) != null;
+    }
+
+}

Added: continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/installation/DefaultInstallationServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/installation/DefaultInstallationServiceTest.java?rev=702088&view=auto
==============================================================================
--- continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/installation/DefaultInstallationServiceTest.java (added)
+++ continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/installation/DefaultInstallationServiceTest.java Mon Oct  6 03:51:04 2008
@@ -0,0 +1,242 @@
+package org.apache.continuum.installation;
+
+/*
+ * 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.continuum.dao.DaoUtils;
+import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.execution.ExecutorConfigurator;
+import org.apache.maven.continuum.installation.AlreadyExistsInstallationException;
+import org.apache.maven.continuum.installation.InstallationService;
+import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.ProfileService;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:olamy@codehaus.org">olamy</a>
+ * @version $Id: DefaultInstallationServiceTest.java 684085 2008-08-08 20:48:14Z evenisse $
+ * @since 13 juin 07
+ */
+public class DefaultInstallationServiceTest
+    extends AbstractContinuumTest
+{
+    private static final String DEFAULT_INSTALLATION_NAME = "defaultInstallation";
+
+    private static final String NEW_INSTALLATION_NAME = "newInstallation";
+
+    //public Installation defaultInstallation;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        DaoUtils daoUtils = (DaoUtils) lookup( DaoUtils.class.getName() );
+        daoUtils.eraseDatabase();
+        /*if ( getInstallationService().getAllInstallations().isEmpty() )
+        {
+            defaultInstallation = createDefault();
+            ContinuumStore store = getStore();
+            defaultInstallation = store.addInstallation( defaultInstallation );
+        }*/
+    }
+
+    private Installation createDefaultInstallation()
+    {
+        Installation installation = new Installation();
+        installation.setType( "description" );
+        installation.setName( DEFAULT_INSTALLATION_NAME );
+        installation.setVarName( "varName" );
+        installation.setVarValue( "varValue" );
+        return installation;
+    }
+
+    private InstallationService getInstallationService()
+        throws Exception
+    {
+        //Continuum continuum = (Continuum) lookup( Continuum.ROLE );
+        //return continuum.getInstallationService();
+        return (InstallationService) lookup( InstallationService.ROLE );
+    }
+
+    private Installation addInstallation( String name, String varName, String varValue, String type )
+        throws Exception
+    {
+
+        Installation installation = new Installation();
+        installation.setType( InstallationService.JDK_TYPE );
+        installation.setName( name );
+        installation.setVarName( varName );
+        installation.setVarValue( varValue );
+        return getInstallationService().add( installation );
+    }
+
+    public void testAddInstallation()
+        throws Exception
+    {
+        Installation added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
+        Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
+        assertNotNull( getted );
+        assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
+        assertEquals( "bar", getted.getVarValue() );
+        assertEquals( 1, getInstallationService().getAllInstallations().size() );
+    }
+
+    public void testAddDuplicateInstallation()
+        throws Exception
+    {
+        Installation added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
+        Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
+        assertNotNull( getted );
+        assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
+        assertEquals( "bar", getted.getVarValue() );
+        try
+        {
+            added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
+            fail( "not in AlreadyExistsInstallationException" );
+        }
+        catch ( AlreadyExistsInstallationException e )
+        {
+            // we must be here
+        }
+        assertEquals( 1, getInstallationService().getAllInstallations().size() );
+    }
+
+    public void testRemove()
+        throws Exception
+    {
+        String name = "toremove";
+        Installation added = this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE );
+        Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
+        assertNotNull( getted );
+        getInstallationService().delete( getted );
+        getted = getInstallationService().getInstallation( added.getInstallationId() );
+        assertNull( getted );
+
+    }
+
+    public void testUpdate()
+        throws Exception
+    {
+        String name = "toupdate";
+        Installation added = this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE );
+        Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
+        assertNotNull( getted );
+        assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
+        assertEquals( "bar", getted.getVarValue() );
+        getted.setVarName( "updatefoo" );
+        getted.setVarValue( "updatedbar" );
+        getInstallationService().update( getted );
+        getted = getInstallationService().getInstallation( added.getInstallationId() );
+        assertNotNull( getted );
+        assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
+        assertEquals( "updatedbar", getted.getVarValue() );
+    }
+
+    public void testgetDefaultJdkInformations()
+        throws Exception
+    {
+        InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
+        List<String> infos = installationService.getDefaultJdkInformations();
+        assertNotNull( infos );
+    }
+
+    public void testgetJdkInformations()
+        throws Exception
+    {
+        InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
+        String javaHome = System.getenv( "JAVA_HOME" );
+        if ( StringUtils.isEmpty( javaHome ) )
+        {
+            javaHome = System.getProperty( "java.home" );
+        }
+        Installation installation = new Installation();
+        installation.setName( "test" );
+        installation.setType( InstallationService.JDK_TYPE );
+        installation.setVarValue( javaHome );
+
+        List<String> infos = installationService.getJdkInformations( installation );
+        assertNotNull( infos );
+    }
+
+    public void testgetJdkInformationsWithCommonMethod()
+        throws Exception
+    {
+        InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
+        ExecutorConfigurator java = installationService.getExecutorConfigurator( InstallationService.JDK_TYPE );
+        String javaHome = System.getenv( "JAVA_HOME" );
+        if ( StringUtils.isEmpty( javaHome ) )
+        {
+            javaHome = System.getProperty( "java.home" );
+        }
+        List<String> infos = installationService.getExecutorConfiguratorVersion( javaHome, java, null );
+        System.out.println( infos );
+        assertNotNull( infos );
+    }
+
+    public void testgetMvnVersionWithCommonMethod()
+        throws Exception
+    {
+        InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
+        ExecutorConfigurator java = installationService.getExecutorConfigurator( InstallationService.MAVEN2_TYPE );
+        List<String> infos = installationService.getExecutorConfiguratorVersion( null, java, null );
+        assertNotNull( infos );
+    }
+
+    public void testAddInstallationAutomaticProfile()
+        throws Exception
+    {
+
+        Installation installation = new Installation();
+        installation.setType( InstallationService.JDK_TYPE );
+        installation.setName( "automaticJdk" );
+        installation.setVarName( "automaticvarName" );
+        installation.setVarValue( "automaticvarValue" );
+        installation = getInstallationService().add( installation, true );
+        ProfileService profileService = (ProfileService) lookup( ProfileService.ROLE, "default" );
+        List<Profile> profiles = profileService.getAllProfiles();
+        assertEquals( 1, profiles.size() );
+        Profile profile = (Profile) profiles.get( 0 );
+        assertEquals( "automaticJdk", profile.getName() );
+        Installation jdk = profile.getJdk();
+        assertNotNull( jdk );
+        assertEquals( "automaticJdk", jdk.getName() );
+    }
+
+    public void testUpdateName()
+        throws Exception
+    {
+        Installation installation = new Installation();
+        installation.setType( InstallationService.JDK_TYPE );
+        installation.setName( "automatic" );
+        installation.setVarName( "automaticvarName" );
+        installation.setVarValue( "automaticvarValue" );
+        installation = getInstallationService().add( installation, true );
+
+        installation.setName( "new name here" );
+        getInstallationService().update( installation );
+
+        Installation getted = getInstallationService().getInstallation( installation.getInstallationId() );
+        assertEquals( "new name here", getted.getName() );
+
+
+    }
+}

Added: continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/profile/DefaultProfileServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/profile/DefaultProfileServiceTest.java?rev=702088&view=auto
==============================================================================
--- continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/profile/DefaultProfileServiceTest.java (added)
+++ continuum/branches/continuum-1.2.x/continuum-commons/src/test/java/org/apache/continuum/profile/DefaultProfileServiceTest.java Mon Oct  6 03:51:04 2008
@@ -0,0 +1,312 @@
+package org.apache.continuum.profile;
+
+import org.apache.continuum.dao.DaoUtils;
+import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.installation.InstallationService;
+import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
+import org.apache.maven.continuum.profile.ProfileService;
+
+import java.util.List;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author <a href="mailto:olamy@codehaus.org">olamy</a>
+ * @version $Id: DefaultProfileServiceTest.java 684085 2008-08-08 20:48:14Z evenisse $
+ * @since 15 juin 07
+ */
+public class DefaultProfileServiceTest
+    extends AbstractContinuumTest
+{
+
+    Installation jdk1;
+
+    String jdk1Name = "jdk1";
+
+    Installation jdk2;
+
+    String jdk2Name = "jdk2";
+
+    Installation mvn205;
+
+    String mvn205Name = "mvn 2.0.5";
+
+    Installation mvn206;
+
+    String mvn206Name = "mvn 2.0.6";
+
+    Profile jdk1mvn205;
+
+    String jdk1mvn205Name = "jdk1 mvn 2.0.5";
+
+    Profile jdk2mvn206;
+
+    String jdk2mvn206Name = "jdk2 mvn 2.0.6";
+
+    Installation mvnOpts1;
+
+    String mvnOpts1Name = "mvnOpts1";
+
+    Installation mvnOpts2;
+
+    String mvnOpts2Name = "mvnOpts2";
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        DaoUtils daoUtils = (DaoUtils) lookup( DaoUtils.class.getName() );
+        daoUtils.eraseDatabase();
+
+        jdk1 = new Installation();
+        jdk1.setType( InstallationService.JDK_TYPE );
+        jdk1.setVarValue( "/foo/bar" );
+        jdk1.setName( jdk1Name );
+        jdk1 = getInstallationService().add( jdk1 );
+
+        jdk2 = new Installation();
+        jdk2.setType( InstallationService.JDK_TYPE );
+        jdk2.setVarValue( "/foo/bar/zloug" );
+        jdk2.setName( jdk2Name );
+        jdk2 = getInstallationService().add( jdk2 );
+
+        mvn205 = new Installation();
+        mvn205.setType( InstallationService.MAVEN2_TYPE );
+        mvn205.setVarValue( "/users/maven-2.0.5" );
+        mvn205.setName( mvn205Name );
+        mvn205 = getInstallationService().add( mvn205 );
+
+        mvn206 = new Installation();
+        mvn206.setType( InstallationService.MAVEN2_TYPE );
+        mvn206.setVarValue( "/users/maven-2.0.6" );
+        mvn206.setName( mvn206Name );
+        mvn206 = getInstallationService().add( mvn206 );
+
+        jdk1mvn205 = new Profile();
+        jdk1mvn205.setJdk( jdk1 );
+        jdk1mvn205.setBuilder( mvn205 );
+        jdk1mvn205.setName( jdk1mvn205Name );
+        getProfileService().addProfile( jdk1mvn205 );
+
+        jdk2mvn206 = new Profile();
+        jdk2mvn206.setJdk( jdk2 );
+        jdk2mvn206.setBuilder( mvn206 );
+        jdk2mvn206.setName( jdk2mvn206Name );
+        getProfileService().addProfile( jdk2mvn206 );
+
+        mvnOpts1 = new Installation();
+        mvnOpts1.setType( InstallationService.ENVVAR_TYPE );
+        mvnOpts1.setVarName( "MAVEN_OPTS" );
+        mvnOpts1.setVarValue( "-Xmx256m -Djava.awt.headless=true" );
+        mvnOpts1.setName( mvnOpts1Name );
+        mvnOpts1 = getInstallationService().add( mvnOpts1 );
+
+        mvnOpts2 = new Installation();
+        mvnOpts2.setType( InstallationService.ENVVAR_TYPE );
+        mvnOpts2.setVarName( "MAVEN_OPTS" );
+        mvnOpts2.setVarValue( "-Xmx1024m -Xms1024m" );
+        mvnOpts2.setName( mvnOpts2Name );
+        mvnOpts2 = getInstallationService().add( mvnOpts2 );
+
+    }
+
+    public InstallationService getInstallationService()
+        throws Exception
+    {
+        return (InstallationService) lookup( InstallationService.ROLE, "default" );
+    }
+
+    public ProfileService getProfileService()
+        throws Exception
+    {
+        return (ProfileService) lookup( ProfileService.ROLE, "default" );
+    }
+
+    public void testAddProfile()
+        throws Exception
+    {
+        Profile defaultProfile = new Profile();
+        String name = "default profile";
+        defaultProfile.setName( name );
+        Profile getted = getProfileService().addProfile( defaultProfile );
+        assertNotNull( getProfileService().getProfile( getted.getId() ) );
+        assertEquals( name, getProfileService().getProfile( getted.getId() ).getName() );
+        assertEquals( 3, getProfileService().getAllProfiles().size() );
+    }
+
+    public void testAddDuplicateProfile()
+        throws Exception
+    {
+        Profile defaultProfile = new Profile();
+        String name = "default profile";
+        defaultProfile.setName( name );
+        Profile getted = getProfileService().addProfile( defaultProfile );
+        assertNotNull( getProfileService().getProfile( getted.getId() ) );
+        assertEquals( name, getProfileService().getProfile( getted.getId() ).getName() );
+        assertEquals( 3, getProfileService().getAllProfiles().size() );
+
+        defaultProfile = new Profile();
+        defaultProfile.setName( name );
+        try
+        {
+            getted = getProfileService().addProfile( defaultProfile );
+            fail( "no AlreadyExistsProfileException with an already exist name " );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // we must be here
+        }
+        assertEquals( 3, getProfileService().getAllProfiles().size() );
+    }
+
+    public void testDeleteProfile()
+        throws Exception
+    {
+        Profile defaultProfile = new Profile();
+        defaultProfile.setName( "default profile" );
+        Profile getted = getProfileService().addProfile( defaultProfile );
+        int id = getted.getId();
+        assertNotNull( getProfileService().getProfile( id ) );
+        getProfileService().deleteProfile( id );
+        assertNull( getProfileService().getProfile( id ) );
+    }
+
+    public void testgetAllProfile()
+        throws Exception
+    {
+        List<Profile> all = getProfileService().getAllProfiles();
+        assertNotNull( all );
+        assertFalse( all.isEmpty() );
+        assertEquals( 2, all.size() );
+    }
+
+    public void testupdateProfile()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertEquals( jdk1mvn205Name, profile.getName() );
+        String newName = "new name";
+        profile.setName( newName );
+        getProfileService().updateProfile( profile );
+
+        Profile getted = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertNotNull( getted );
+        assertEquals( newName, getted.getName() );
+    }
+
+    public void testupdateProfileDuplicateName()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertEquals( jdk1mvn205Name, profile.getName() );
+        profile.setName( jdk2mvn206Name );
+
+        try
+        {
+            getProfileService().updateProfile( profile );
+            fail( "no AlreadyExistsProfileException with duplicate name" );
+        }
+        catch ( AlreadyExistsProfileException e )
+        {
+            // we must be here
+        }
+        Profile getted = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertNotNull( getted );
+        assertEquals( jdk1mvn205Name, getted.getName() );
+    }
+
+    public void testsetJdkInProfile()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        getProfileService().setJdkInProfile( profile, jdk2 );
+
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertEquals( jdk2.getName(), profile.getJdk().getName() );
+        assertEquals( jdk2.getVarValue(), profile.getJdk().getVarValue() );
+    }
+
+    public void testsetBuilderInProfile()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        getProfileService().setBuilderInProfile( profile, mvn206 );
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertEquals( mvn206.getName(), profile.getBuilder().getName() );
+        assertEquals( mvn206.getVarValue(), profile.getBuilder().getVarValue() );
+
+    }
+
+    public void testaddEnvVarInProfile()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        getProfileService().setBuilderInProfile( profile, mvn206 );
+        getProfileService().addEnvVarInProfile( profile, mvnOpts1 );
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertFalse( profile.getEnvironmentVariables().isEmpty() );
+        assertEquals( 1, profile.getEnvironmentVariables().size() );
+    }
+
+    public void testRemoveInstallationLinkedToAProfile()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        getProfileService().setJdkInProfile( profile, jdk2 );
+
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
+        installationService.delete( jdk2 );
+    }
+
+    public void testRemoveEnvVarFromProfile()
+        throws Exception
+    {
+        Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        getProfileService().setJdkInProfile( profile, jdk2 );
+        getProfileService().addEnvVarInProfile( profile, mvnOpts1 );
+        getProfileService().addEnvVarInProfile( profile, mvnOpts2 );
+
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertNotNull( profile.getJdk() );
+        assertEquals( 2, profile.getEnvironmentVariables().size() );
+
+        getProfileService().removeInstallationFromProfile( profile, mvnOpts1 );
+
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertNotNull( profile.getJdk() );
+        assertEquals( 1, profile.getEnvironmentVariables().size() );
+
+        getProfileService().removeInstallationFromProfile( profile, jdk2 );
+
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertNull( profile.getJdk() );
+        assertEquals( 1, profile.getEnvironmentVariables().size() );
+
+        getProfileService().removeInstallationFromProfile( profile, mvnOpts2 );
+        profile = getProfileService().getProfile( jdk1mvn205.getId() );
+        assertNull( profile.getJdk() );
+        assertEquals( 0, profile.getEnvironmentVariables().size() );
+    }
+
+
+}



Mime
View raw message