Index: continuum-model/src/main/mdo/continuum.xml =================================================================== --- continuum-model/src/main/mdo/continuum.xml (revision 548492) +++ continuum-model/src/main/mdo/continuum.xml (working copy) @@ -959,6 +959,7 @@ Profile + org.apache.maven.continuum.model.system 1.1.0+ @@ -1006,6 +1007,15 @@ Installation + + environmentVariables + 1.1.1+ + + Installation + + * + + @@ -1014,16 +1024,21 @@ org.apache.maven.continuum.model.system 1.1.0+ - - version - 1.1.0+ + + type + 1.1.1+ String - - path - 1.1.0+ + + varValue + 1.1.1+ String + + varName + 1.1.1+ + String + name 1.1.0+ Index: continuum-model/pom.xml =================================================================== --- continuum-model/pom.xml (revision 548492) +++ continuum-model/pom.xml (working copy) @@ -43,7 +43,7 @@ - 1.1.0 + 1.1.1 false src/main/mdo/continuum.xml Index: continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileException.java =================================================================== --- continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileException.java (revision 0) +++ continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileException.java (revision 0) @@ -0,0 +1,45 @@ +package org.apache.maven.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. + */ +/** + * @author olamy + * @since 15 juin 07 + * @version $Id$ + */ +public class ProfileException + extends Exception +{ + + public ProfileException( String message, Throwable throwable ) + { + super( message, throwable ); + } + + public ProfileException( String message ) + { + super( message ); + } + + public ProfileException( Throwable throwable ) + { + super( throwable ); + } + +} Property changes on: continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileException.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java =================================================================== --- continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java (revision 0) +++ continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java (revision 0) @@ -0,0 +1,65 @@ +package org.apache.maven.continuum.profile; + +import java.util.List; + +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.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. + */ + +/** + * @author olamy + * @since 15 juin 07 + * @version $Id$ + */ +public interface ProfileService +{ + String ROLE = ProfileService.class.getName(); + + public Profile getProfile( int profileId ) + throws ProfileException; + + public void deleteProfile( int profileId ) + throws ProfileException; + + public void updateProfile( Profile profile ) + throws ProfileException; + + /** + * Add an empty profile without builder, jdk and envVars + * @param profile + * @return + * @throws ProfileException + */ + public Profile addProfile( Profile profile ) + throws ProfileException; + + public List getAllProfiles() + throws ProfileException; + + public void setJdkInProfile( Profile profile, Installation jdk ) + throws ProfileException; + + public void setBuilderInProfile( Profile profile, Installation builder ) + throws ProfileException; + + public void addEnvVarInProfile( Profile profile, Installation envVar ) + throws ProfileException; +} Property changes on: continuum-api/src/main/java/org/apache/maven/continuum/profile/ProfileService.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java =================================================================== --- continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java (revision 548492) +++ continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java (working copy) @@ -20,12 +20,14 @@ */ import org.apache.maven.continuum.configuration.ConfigurationService; +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildResult; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectGroup; import org.apache.maven.continuum.model.project.ProjectNotifier; import org.apache.maven.continuum.model.project.Schedule; +import org.apache.maven.continuum.profile.ProfileService; import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; import org.apache.maven.continuum.release.ContinuumReleaseManager; import org.codehaus.plexus.util.dag.CycleDetectedException; @@ -279,10 +281,10 @@ * @return a holder with the projects, project groups and errors occurred during the project adding * @throws ContinuumException */ - ContinuumProjectBuildingResult addMavenTwoProject( String metadataUrl, int projectGroupId, boolean checkProtocol, + ContinuumProjectBuildingResult addMavenTwoProject( String metadataUrl, int projectGroupId, boolean checkProtocol, boolean useCredentialsCache ) throws ContinuumException; - + /** * Add a Maven 1 project to the list of projects. * @@ -337,7 +339,7 @@ * @return a holder with the projects, project groups and errors occurred during the project adding * @throws ContinuumException */ - ContinuumProjectBuildingResult addMavenOneProject( String metadataUrl, int projectGroupId, boolean checkProtocol, + ContinuumProjectBuildingResult addMavenOneProject( String metadataUrl, int projectGroupId, boolean checkProtocol, boolean useCredentialsCache ) throws ContinuumException; @@ -499,9 +501,16 @@ void reloadConfiguration() throws ContinuumException; - // ---------------------------------------------------------------------- // Continuum Release // ---------------------------------------------------------------------- ContinuumReleaseManager getReleaseManager(); + + // ---------------------------------------------------------------------- + // Installation + // ---------------------------------------------------------------------- + + InstallationService getInstallationService(); + + ProfileService getProfileService(); } Index: continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationException.java =================================================================== --- continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationException.java (revision 0) +++ continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationException.java (revision 0) @@ -0,0 +1,37 @@ +package org.apache.maven.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. + */ +/** + * @author olamy + * @since 13 juin 07 + * @version $Id$ + */ +public class InstallationException + extends Exception +{ + public InstallationException( String message ) + { + super( message ); + } + + public InstallationException( String message, Throwable cause ) + { + super( message, cause ); + } +} Property changes on: continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationException.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java =================================================================== --- continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java (revision 0) +++ continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java (revision 0) @@ -0,0 +1,77 @@ +package org.apache.maven.continuum.installation; + +import java.util.List; + +import org.apache.maven.continuum.model.system.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. + */ +/** + * @author olamy + * @since 13 juin 07 + * @version $Id$ + */ +public interface InstallationService +{ + String ROLE = InstallationService.class.getName(); + + String JDK_TYPE = "jdk"; + + String MAVEN2_TYPE = "maven2"; + + String MAVEN1_TYPE = "maven1"; + + String ANT_TYPE = "ant"; + + String ENVVAR_TYPE = "envvar"; + + public Installation add( Installation installation ) + throws InstallationException; + + public void update( Installation installation ) + throws InstallationException; + + public void delete( Installation installation ) + throws InstallationException; + + public Installation getInstallation( String name ) + throws InstallationException; + + public List getAllInstallations() + throws InstallationException; + + public String getEnvVar( String type ); + + /** + * @param installation + * @return output of JAVA_HOME/bin/java -version (JAVA_HOME = installation.getVarValue() + * @throws InstallationException + */ + public List getJdkInformations( Installation installation ) + throws InstallationException; + + /** + * + * @return output of JAVA_HOME/bin/java -version + * @throws InstallationException + */ + public List getDefaultJdkInformations() + throws InstallationException; + +} Property changes on: continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java =================================================================== --- continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java (revision 548492) +++ continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java (working copy) @@ -19,20 +19,20 @@ * under the License. */ +import java.util.Collection; +import java.util.List; +import java.util.Map; + import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildResult; -import org.apache.maven.continuum.model.project.Profile; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectGroup; import org.apache.maven.continuum.model.project.ProjectNotifier; import org.apache.maven.continuum.model.project.Schedule; import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; import org.apache.maven.continuum.model.system.SystemConfiguration; -import java.util.Collection; -import java.util.List; -import java.util.Map; - /** * @author Trygve Laugstøl * @version $Id$ @@ -51,40 +51,42 @@ Map getDefaultBuildDefinitions(); /** - * returns the default build definition of the project, if the project doesn't have on declared the default - * of the project group will be returned - *

- * this should be the most common usage of the default build definition accessing methods - * + * returns the default build definition of the project, if the project + * doesn't have on declared the default of the project group will be + * returned

this should be the most common usage of the default build + * definition accessing methods + * * @param projectId * @return * @throws ContinuumStoreException * @throws ContinuumObjectNotFoundException - * + * */ BuildDefinition getDefaultBuildDefinition( int projectId ) throws ContinuumStoreException, ContinuumObjectNotFoundException; /** - * returns the default build definition for the project without consulting the project group - * + * returns the default build definition for the project without consulting + * the project group + * * @param projectId * @return * @throws ContinuumStoreException * @throws ContinuumObjectNotFoundException - * + * */ BuildDefinition getDefaultBuildDefinitionForProject( int projectId ) throws ContinuumStoreException, ContinuumObjectNotFoundException; /** - * returns the default build definition for the project group and there should always be one declared - * + * returns the default build definition for the project group and there + * should always be one declared + * * @param projectGroupId * @return * @throws ContinuumStoreException * @throws ContinuumObjectNotFoundException - * + * */ BuildDefinition getDefaultBuildDefinitionForProjectGroup( int projectGroupId ) throws ContinuumStoreException, ContinuumObjectNotFoundException; @@ -131,14 +133,40 @@ Schedule storeSchedule( Schedule schedule ) throws ContinuumStoreException; + // ---------------------------------------------------------------- + // Profile + // ---------------------------------------------------------------- List getAllProfilesByName(); Profile addProfile( Profile profile ); - Installation addInstallation( Installation installation ); + Installation addInstallation( Installation installation ) + throws ContinuumStoreException; - List getAllInstallations(); + Profile getProfile( int profileId ) + throws ContinuumObjectNotFoundException, ContinuumStoreException; + void updateProfile( Profile profile ) + throws ContinuumStoreException; + + void removeProfile( Profile profile ); + + // ---------------------------------------------------------------- + // Installation + // ---------------------------------------------------------------- + + List getAllInstallations() + throws ContinuumStoreException; + + void removeInstallation( Installation installation ) + throws ContinuumStoreException, ContinuumObjectNotFoundException; + + void updateInstallation( Installation installation ) + throws ContinuumStoreException, ContinuumObjectNotFoundException; + + Installation getInstallationByName( String installationName ) + throws ContinuumStoreException, ContinuumObjectNotFoundException; + List getAllBuildsForAProjectByDate( int projectId ); Project getProject( int projectId ) @@ -162,17 +190,12 @@ void updateProject( Project project ) throws ContinuumStoreException; - void updateProfile( Profile profile ) - throws ContinuumStoreException; - void updateSchedule( Schedule schedule ) throws ContinuumStoreException; Project getProjectWithBuilds( int projectId ) throws ContinuumStoreException, ContinuumObjectNotFoundException; - void removeProfile( Profile profile ); - void removeSchedule( Schedule schedule ); Project getProjectWithCheckoutResult( int projectId ) @@ -207,9 +230,6 @@ Schedule getSchedule( int scheduleId ) throws ContinuumObjectNotFoundException, ContinuumStoreException; - Profile getProfile( int profileId ) - throws ContinuumObjectNotFoundException, ContinuumStoreException; - ProjectGroup getProjectGroupByGroupId( String groupId ) throws ContinuumStoreException, ContinuumObjectNotFoundException; Index: pom.xml =================================================================== --- pom.xml (revision 548492) +++ pom.xml (working copy) @@ -456,7 +456,7 @@ org.codehaus.plexus plexus-utils - 1.4 + 1.4.3-SNAPSHOT org.codehaus.plexus Index: continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildDefinitionAction.java =================================================================== --- continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildDefinitionAction.java (revision 548492) +++ continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildDefinitionAction.java (working copy) @@ -19,19 +19,21 @@ * under the License. */ +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import org.apache.maven.continuum.ContinuumException; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.Schedule; +import org.apache.maven.continuum.model.system.Profile; +import org.apache.maven.continuum.profile.ProfileException; import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; import org.apache.maven.continuum.web.exception.ContinuumActionException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - /** * BuildDefinitionAction: * @@ -66,12 +68,14 @@ private Map schedules; - private Map profiles; + private List profiles; private boolean groupBuildDefinition = false; private String projectGroupName = ""; + private int profileId; + public void prepare() throws Exception { @@ -94,7 +98,7 @@ // todo: missing from continuum, investigate if ( profiles == null ) { - profiles = new HashMap(); + profiles = this.getContinuum().getProfileService().getAllProfiles(); } } @@ -145,6 +149,11 @@ buildFresh = buildDefinition.isBuildFresh(); scheduleId = buildDefinition.getSchedule().getId(); defaultBuildDefinition = buildDefinition.isDefaultForProject(); + Profile profile = buildDefinition.getProfile(); + if ( profile != null ) + { + profileId = profile.getId(); + } } else { @@ -180,7 +189,7 @@ } public String saveBuildDefinition() - throws ContinuumException + throws ContinuumException, ProfileException { if ( projectId != 0 && !groupBuildDefinition ) { @@ -193,7 +202,7 @@ } public String saveToProject() - throws ContinuumException + throws ContinuumException, ProfileException { try @@ -226,7 +235,7 @@ } public String saveToGroup() - throws ContinuumException + throws ContinuumException, ProfileException { try { @@ -322,7 +331,7 @@ } private BuildDefinition getBuildDefinitionFromInput() - throws ContinuumActionException + throws ContinuumActionException, ProfileException { Schedule schedule; @@ -349,7 +358,14 @@ buildDefinition.setBuildFresh( buildFresh ); buildDefinition.setDefaultForProject( defaultBuildDefinition ); buildDefinition.setSchedule( schedule ); - + if ( profileId != -1 ) + { + Profile profile = getContinuum().getProfileService().getProfile( profileId ); + if ( profile != null ) + { + buildDefinition.setProfile( profile ); + } + } return buildDefinition; } @@ -473,12 +489,12 @@ this.schedules = schedules; } - public Map getProfiles() + public List getProfiles() { return profiles; } - public void setProfiles( Map profiles ) + public void setProfiles( List profiles ) { this.profiles = profiles; } @@ -510,4 +526,14 @@ return projectGroupName; } + + public int getProfileId() + { + return profileId; + } + + public void setProfileId( int profileId ) + { + this.profileId = profileId; + } } Index: continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddProjectAction.java =================================================================== --- continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddProjectAction.java (revision 548492) +++ continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddProjectAction.java (working copy) @@ -24,12 +24,16 @@ import org.apache.maven.continuum.ContinuumException; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectGroup; +import org.apache.maven.continuum.model.system.Profile; +import org.apache.maven.continuum.profile.ProfileException; +import org.apache.maven.continuum.profile.ProfileService; import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; import org.codehaus.plexus.util.StringUtils; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; /** * @author Nick Gonzalez @@ -65,6 +69,13 @@ private boolean projectScmUseCache; + private List profiles; + + /** + * @plexus.requirement role-hint="default" + */ + private ProfileService profileService; + public void validate() { boolean projectNameAlreadyExist = false; @@ -138,7 +149,7 @@ } public String input() - throws ContinuumException + throws ContinuumException, ProfileException { try { @@ -171,10 +182,10 @@ if ( !disableGroupSelection ) { - selectedProjectGroup = - getContinuum().getProjectGroupByGroupId( Continuum.DEFAULT_PROJECT_GROUP_GROUP_ID ).getId(); + selectedProjectGroup = getContinuum().getProjectGroupByGroupId( Continuum.DEFAULT_PROJECT_GROUP_GROUP_ID ) + .getId(); } - + this.profiles = profileService.getAllProfiles(); return SUCCESS; } @@ -297,4 +308,14 @@ { this.projectScmUseCache = projectScmUseCache; } + + public List getProfiles() + { + return profiles; + } + + public void setProfiles( List profiles ) + { + this.profiles = profiles; + } } Index: continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java =================================================================== --- continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java (revision 0) +++ continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java (revision 0) @@ -0,0 +1,217 @@ +package org.apache.maven.continuum.web.action.admin; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; + +import org.apache.maven.continuum.installation.InstallationService; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.web.action.ContinuumActionSupport; + +import com.opensymphony.xwork.Preparable; + +/* + * 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 olamy + * @since 14 juin 07 + * @version $Id$ + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="installation" + */ +public class InstallationAction + extends ContinuumActionSupport + implements Preparable +{ + + /** + * @plexus.requirement role-hint="default" + */ + private InstallationService installationService; + + private List installations; + + private Installation installation; + + private Map typesLabels; + + private List types; + + private boolean varNameUpdatable = true; + + private boolean nameUpdatable = true; + + // ----------------------------------------------------- + // Webwork methods + // ----------------------------------------------------- + + public void prepare() + throws Exception + { + super.prepare(); + } + + public String list() + throws Exception + { + this.installations = installationService.getAllInstallations(); + return SUCCESS; + } + + public String edit() + throws Exception + { + this.installation = installationService.getInstallation( installation.getName() ); + + if ( this.installation != null ) + { + this.nameUpdatable = false; + // we can update env var name only with env var type + if ( !InstallationService.ENVVAR_TYPE.equals( this.installation.getType() ) ) + { + this.varNameUpdatable = false; + } + } + return SUCCESS; + } + + public String input() + throws Exception + { + return INPUT; + } + + public String save() + throws Exception + { + Installation installationToSave = installationService.getInstallation( this.installation.getName() ); + if ( installationToSave == null ) + { + installationService.add( installation ); + } + else + { + installationToSave.setName( installation.getName() ); + installationToSave.setVarName( installation.getVarName() ); + installationToSave.setVarValue( installation.getVarValue() ); + installationService.update( installationToSave ); + } + this.installations = installationService.getAllInstallations(); + return SUCCESS; + } + + public String delete() + throws Exception + { + Installation installationToDelete = installationService.getInstallation( installation.getName() ); + installationService.delete( installationToDelete ); + this.installations = installationService.getAllInstallations(); + return SUCCESS; + } + + // ----------------------------------------------------- + // getter/setters + // ----------------------------------------------------- + public List getInstallations() + { + return installations; + } + + public void setInstallations( List installations ) + { + this.installations = installations; + } + + public Installation getInstallation() + { + return installation; + } + + public void setInstallation( Installation installation ) + { + this.installation = installation; + } + + public Map getTypesLabels() + { + if ( this.typesLabels == null ) + { + this.typesLabels = new LinkedHashMap(); + ResourceBundle resourceBundle = getTexts( "localization/Continuum" ); + this.typesLabels.put( InstallationService.JDK_TYPE, resourceBundle + .getString( "installation.jdk.type.label" ) ); + this.typesLabels.put( InstallationService.MAVEN2_TYPE, resourceBundle + .getString( "installation.maven2.type.label" ) ); + this.typesLabels.put( InstallationService.MAVEN1_TYPE, resourceBundle + .getString( "installation.maven1.type.label" ) ); + this.typesLabels.put( InstallationService.ANT_TYPE, resourceBundle + .getString( "installation.ant.type.label" ) ); + this.typesLabels.put( InstallationService.ENVVAR_TYPE, resourceBundle + .getString( "installation.envvar.type.label" ) ); + } + return typesLabels; + } + + public void setTypesLabels( Map typesLabels ) + { + this.typesLabels = typesLabels; + } + + public boolean isVarNameUpdatable() + { + return varNameUpdatable; + } + + public void setVarNameUpdatable( boolean varNameUpdatable ) + { + this.varNameUpdatable = varNameUpdatable; + } + + public List getTypes() + { + if ( this.types == null ) + { + this.types = new ArrayList(); + this.types.add( InstallationService.JDK_TYPE ); + this.types.add( InstallationService.MAVEN2_TYPE ); + this.types.add( InstallationService.MAVEN1_TYPE ); + this.types.add( InstallationService.ANT_TYPE ); + this.types.add( InstallationService.ENVVAR_TYPE ); + + } + return types; + } + + public void setTypes( List types ) + { + this.types = types; + } + + public boolean isNameUpdatable() + { + return nameUpdatable; + } + + public void setNameUpdatable( boolean nameUpdatable ) + { + this.nameUpdatable = nameUpdatable; + } + +} Property changes on: continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java =================================================================== --- continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java (revision 0) +++ continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java (revision 0) @@ -0,0 +1,255 @@ +package org.apache.maven.continuum.web.action.admin; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +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.apache.maven.continuum.web.action.ContinuumActionSupport; +import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; +import org.codehaus.plexus.util.StringUtils; + +/* + * 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 olamy + * @since 7 juin 07 + * @version $Id$ + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="profileAdministration" + */ +public class ProfileAction + extends ContinuumActionSupport + +{ + /** + * @plexus.requirement role-hint="default" + */ + private ProfileService profileService; + + /** + * @plexus.requirement role-hint="default" + */ + private InstallationService installationService; + + private List profiles; + + private Profile profile; + + private String installationName; + + private List allInstallations; + + private List profileInstallations; + + // ------------------------------------------------------- + // Webwork Methods + // ------------------------------------------------------- + + public String input() + throws Exception + { + this.allInstallations = installationService.getAllInstallations(); + return INPUT; + } + + public String list() + throws Exception + { + this.profiles = profileService.getAllProfiles(); + return SUCCESS; + } + + public String edit() + throws Exception + { + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "edit profile with id " + profile.getId() ); + } + this.profile = profileService.getProfile( profile.getId() ); + return SUCCESS; + } + + public String save() + throws Exception + { + Profile stored = profileService.getProfile( profile.getId() ); + if ( stored == null ) + { + profileService.addProfile( profile ); + } + else + { + //profileToStore.setName( profile.getName() ); + profileService.updateProfile( profile ); + } + this.profiles = profileService.getAllProfiles(); + return SUCCESS; + } + + public String delete() + throws Exception + { + profileService.deleteProfile( profile.getId() ); + this.profiles = profileService.getAllProfiles(); + return SUCCESS; + } + + public String addInstallation() + throws Exception + { + Installation installation = installationService.getInstallation( this.installationName ); + if ( InstallationService.JDK_TYPE.equals( installation.getType() ) ) + { + profileService.setJdkInProfile( profile, installation ); + } + else if ( InstallationService.MAVEN1_TYPE.equals( installation.getType() ) + || InstallationService.MAVEN2_TYPE.equals( installation.getType() ) + || InstallationService.ANT_TYPE.equals( installation.getType() ) ) + { + profileService.setBuilderInProfile( profile, installation ); + } + else + { + profileService.addEnvVarInProfile( profile, installation ); + } + this.profile = profileService.getProfile( profile.getId() ); + return SUCCESS; + } + + public String removeInstallation() + throws Exception + { + + Installation installation = installationService.getInstallation( this.installationName ); + Profile stored = profileService.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 + // TODO move this in ProfileService + List storedEnvVars = stored.getEnvironmentVariables(); + List newEnvVars = new ArrayList(); + for ( Iterator iterator = storedEnvVars.iterator(); iterator.hasNext(); ) + { + Installation storedInstallation = iterator.next(); + if ( !StringUtils.equals( storedInstallation.getName(), installation.getName() ) ) + { + newEnvVars.add( storedInstallation ); + } + } + stored.setEnvironmentVariables( newEnvVars ); + } + profileService.updateProfile( stored ); + this.profile = profileService.getProfile( profile.getId() ); + return SUCCESS; + } + + // ------------------------------------------------------- + // Webwork setter/getter + // ------------------------------------------------------- + + public List getProfiles() + { + return profiles; + } + + public void setProfiles( List profiles ) + { + this.profiles = profiles; + } + + public Profile getProfile() + { + return profile; + } + + public void setProfile( Profile profile ) + { + this.profile = profile; + } + + public List getAllInstallations() + throws Exception + { + if ( this.allInstallations == null ) + { + this.allInstallations = installationService.getAllInstallations(); + } + return allInstallations; + } + + public void setAllInstallations( List allInstallations ) + { + this.allInstallations = allInstallations; + } + + public List getProfileInstallations() + { + if (this.profile != null) + { + if ( this.profileInstallations == null ) + { + this.profileInstallations = new ArrayList(); + if ( this.profile.getJdk() != null ) + { + this.profileInstallations.add( this.profile.getJdk() ); + } + if ( this.profile.getBuilder() != null ) + { + this.profileInstallations.add( this.profile.getBuilder() ); + } + if ( this.profile.getEnvironmentVariables() != null && !this.profile.getEnvironmentVariables().isEmpty() ) + { + this.profileInstallations.addAll( this.profile.getEnvironmentVariables() ); + } + } + return profileInstallations; + } + return Collections.EMPTY_LIST; + } + + public void setProfileInstallations( List profileInstallations ) + { + this.profileInstallations = profileInstallations; + } + + public String getInstallationName() + { + return installationName; + } + + public void setInstallationName( String installationName ) + { + this.installationName = installationName; + } +} Property changes on: continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/component/BuildDefinitionSummaryAction.java =================================================================== --- continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/component/BuildDefinitionSummaryAction.java (revision 548492) +++ continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/component/BuildDefinitionSummaryAction.java (working copy) @@ -54,6 +54,8 @@ private List groupBuildDefinitionSummaries = new ArrayList(); private List allBuildDefinitionSummaries = new ArrayList(); + + //profileName public String summarizeForProject() { @@ -138,7 +140,6 @@ return summaryList; } - private List gatherGroupBuildDefinitionSummaries( int projectGroupId ) throws ContinuumException { @@ -170,7 +171,10 @@ bds.setScheduleName( bd.getSchedule().getName() ); bds.setIsDefault( bd.isDefaultForProject() ); bds.setIsBuildFresh( bd.isBuildFresh() ); - + if ( bd.getProfile() != null ) + { + bds.setProfileName( bd.getProfile().getName() ); + } return bds; } Index: continuum-webapp/src/main/resources/localization/Continuum.properties =================================================================== --- continuum-webapp/src/main/resources/localization/Continuum.properties (revision 548492) +++ continuum-webapp/src/main/resources/localization/Continuum.properties (working copy) @@ -64,6 +64,8 @@ menu.administration = Administration menu.administration.configuration = Configuration menu.administration.appearance = Appearance +menu.administration.profile = Profiles +menu.administration.installations = Installations menu.administration.schedules = Schedules menu.administration.users = Users menu.administration.userGroups = User Groups @@ -300,6 +302,7 @@ projectView.buildDefinition.buildFile = Build File projectView.buildDefinition.profile = Profile projectView.buildDefinition.schedule = Schedule +buildDefinition.profile.label = Profile projectView.buildDefinition.from = From projectView.buildDefinition.default = Default projectView.buildDefinition.buildFresh = Build Fresh @@ -572,3 +575,42 @@ userGroup.name.message = Enter the user group name userGroup.description.label = Description userGroup.description.message = Enter the description + +# ---------------------------------------------------------------------- +# Page: Profiles List +# ---------------------------------------------------------------------- +profilesList.page.title= Build Profiles + +# ---------------------------------------------------------------------- +# Page: Profile Edit +# ---------------------------------------------------------------------- +profile.page.title= Continuum - Build Profile +profile.section.title = Profile +profile.name.label= Profile Name +profile.jdk.name.label = Jdk name +profile.jdk.name.message = The JDK name +profile.jdk.path.label = Jdk path +profile.jdk.path.message = The JDK Path (JAVA_HOME value) + +# ---------------------------------------------------------------------- +# Page: Installations List +# ---------------------------------------------------------------------- +installationsList.page.title = Installations +installationsList.section.title = Installations + +# ---------------------------------------------------------------------- +# Page: Installation Edit +# ---------------------------------------------------------------------- +installation.page.title = Continuum - Installation +installation.section.title = Continuum - Installation +installation.name.label = Name +installation.type.label = Type +installation.value.label = Value/Path +installation.varName.label = Environment Variable Name (only needed for type Environment Variable) +installation.jdk.type.label = JDK +installation.maven2.type.label = Maven 2 +installation.maven1.type.label = Maven 1 +installation.envvar.type.label = Environment Variable +installation.ant.type.label = ANT + + Index: continuum-webapp/src/main/resources/xwork.xml =================================================================== --- continuum-webapp/src/main/resources/xwork.xml (revision 548492) +++ continuum-webapp/src/main/resources/xwork.xml (working copy) @@ -457,7 +457,7 @@ /WEB-INF/jsp/admin/appearance.jsp - + /WEB-INF/jsp/admin/editAppearance.jsp @@ -481,6 +481,69 @@ /admin + + + + + /WEB-INF/jsp/admin/profilesList.jsp + + + + /WEB-INF/jsp/admin/editProfile.jsp + + + + /WEB-INF/jsp/admin/editProfile.jsp + /WEB-INF/jsp/admin/editProfile.jsp + + + + /WEB-INF/jsp/admin/profilesList.jsp + /WEB-INF/jsp/admin/profilesList.jsp + + + + /WEB-INF/jsp/admin/profilesList.jsp + /WEB-INF/jsp/admin/editProfile.jsp + + + + /WEB-INF/jsp/admin/editProfile.jsp + /WEB-INF/jsp/admin/editProfile.jsp + + + + /WEB-INF/jsp/admin/editProfile.jsp + /WEB-INF/jsp/admin/editProfile.jsp + + + + + /WEB-INF/jsp/admin/installationsList.jsp + + + + /WEB-INF/jsp/admin/editInstallation.jsp + + + + /WEB-INF/jsp/admin/editInstallation.jsp + /WEB-INF/jsp/admin/editInstallation.jsp + + + + /WEB-INF/jsp/admin/editInstallation.jsp + /WEB-INF/jsp/admin/installationsList.jsp + + + /WEB-INF/jsp/admin/installationsList.jsp + /WEB-INF/jsp/admin/installationsList.jsp + + Index: continuum-webapp/src/main/resources/template/profile/select.ftl =================================================================== --- continuum-webapp/src/main/resources/template/profile/select.ftl (revision 0) +++ continuum-webapp/src/main/resources/template/profile/select.ftl (revision 0) @@ -0,0 +1 @@ +<#include "/${parameters.templateDir}/simple/select.ftl" /> \ No newline at end of file Property changes on: continuum-webapp/src/main/resources/template/profile/select.ftl ___________________________________________________________________ Name: svn:executable + * Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/components/buildDefinitionGroupSummaryComponent.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/components/buildDefinitionGroupSummaryComponent.jsp (revision 548492) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/components/buildDefinitionGroupSummaryComponent.jsp (working copy) @@ -38,7 +38,6 @@ - @@ -50,6 +49,7 @@ ${pageScope.buildDefinitionSummary.scheduleName} + @@ -68,7 +68,7 @@

- + ${pageScope.buildDefinitionSummary.projectGroupId} ${pageScope.buildDefinitionSummary.id} Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp (revision 548492) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp (working copy) @@ -42,7 +42,7 @@ - + ${pageScope.project.name} Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/components/buildDefinitionSummaryComponent.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/components/buildDefinitionSummaryComponent.jsp (revision 548492) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/components/buildDefinitionSummaryComponent.jsp (working copy) @@ -35,7 +35,6 @@ - @@ -47,6 +46,7 @@ ${pageScope.buildDefinitionSummary.scheduleName} + Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/navigations/Menu.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/navigations/Menu.jsp (revision 548492) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/navigations/Menu.jsp (working copy) @@ -109,6 +109,18 @@ + +
+ + + +
+ +
+ + + +
Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editProfile.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editProfile.jsp (revision 0) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editProfile.jsp (revision 0) @@ -0,0 +1,115 @@ +<%-- + ~ 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. + --%> + +<%@ taglib uri="/webwork" prefix="ww" %> +<%@ taglib uri="continuum" prefix="c1" %> +<%@ taglib uri="http://www.extremecomponents.org" prefix="ec" %> +<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%> + + + + + <ww:text name="profile.page.title"/> + + + + +
+

+ +

+ +
+ +

Action Error

+
+

+ +

+
+ + + +
+ + +
+ + + + + + +
+
+ +
+ +
+
+
+ +
+ + + + + + + +
+ + + + "> + + + () + + + + &installationName="> + <ww:text name='delete'/> + + + + +
+
+ + + +
+
+ +
+
+
+ +
+ Property changes on: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editProfile.jsp ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editInstallation.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editInstallation.jsp (revision 0) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editInstallation.jsp (revision 0) @@ -0,0 +1,83 @@ +<%-- + ~ 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. + --%> + +<%@ taglib uri="/webwork" prefix="ww" %> +<%@ taglib uri="continuum" prefix="c1" %> + + + + + <ww:text name="installation.page.title"/> + + + + +
+

+ +

+ + + + +

Action Error

+
+

+ +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+ +
+ Property changes on: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/editInstallation.jsp ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/profilesList.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/profilesList.jsp (revision 0) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/profilesList.jsp (revision 0) @@ -0,0 +1,77 @@ +<%-- + ~ 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. + --%> + +<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%> +<%@ taglib uri="/webwork" prefix="ww" %> +<%@ taglib uri="continuum" prefix="c1" %> +<%@ taglib uri="http://www.extremecomponents.org" prefix="ec" %> + + + + + <ww:text name="profilesList.page.title"/> + + +
+ + + + + +
    + +
  • ()
  • +
    + +
  • ()
  • +
    + + +
  • +
    +
    +
+ +
\ No newline at end of file Property changes on: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/profilesList.jsp ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/installationsList.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/installationsList.jsp (revision 0) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/installationsList.jsp (revision 0) @@ -0,0 +1,69 @@ +<%-- + ~ 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. + --%> + +<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%> +<%@ taglib uri="/webwork" prefix="ww" %> +<%@ taglib uri="continuum" prefix="c1" %> +<%@ taglib uri="http://www.extremecomponents.org" prefix="ec" %> + + + + + <ww:text name="installationsList.page.title"/> + + +
+

+ +

+ + + + + + + + + + "> + <ww:text name='edit'/> + + + + "> + <ww:text name='delete'/> + + + + +
+ + + +
+ +
+ +
\ No newline at end of file Property changes on: continuum-webapp/src/main/webapp/WEB-INF/jsp/admin/installationsList.jsp ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/addMavenTwoProject.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/addMavenTwoProject.jsp (revision 548492) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/addMavenTwoProject.jsp (working copy) @@ -73,7 +73,8 @@ - + Index: continuum-webapp/src/main/webapp/WEB-INF/jsp/buildDefinitionEdit.jsp =================================================================== --- continuum-webapp/src/main/webapp/WEB-INF/jsp/buildDefinitionEdit.jsp (revision 548492) +++ continuum-webapp/src/main/webapp/WEB-INF/jsp/buildDefinitionEdit.jsp (working copy) @@ -30,7 +30,7 @@

- + @@ -73,6 +73,8 @@ +
Index: continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java =================================================================== --- continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java (revision 548492) +++ continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java (working copy) @@ -1,38 +1,41 @@ package org.apache.maven.continuum.management; /* - * 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. + * 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.continuum.store.AbstractContinuumStoreTestCase; -import org.apache.maven.continuum.store.ContinuumStoreException; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; - -import javax.xml.stream.XMLStreamException; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.StringReader; import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import javax.xml.stream.XMLStreamException; + +import org.apache.maven.continuum.store.AbstractContinuumStoreTestCase; +import org.apache.maven.continuum.store.ContinuumStoreException; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.custommonkey.xmlunit.Diff; +import org.jdom.Document; +import org.jdom.input.SAXBuilder; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + /** * Test the database management tool. */ @@ -72,7 +75,7 @@ */ public void testBackupBuilds() - throws IOException, ContinuumStoreException, XMLStreamException + throws IOException, ContinuumStoreException, XMLStreamException, Exception { createBuildDatabase(); @@ -89,8 +92,10 @@ IOUtil.copy( getClass().getResourceAsStream( "/expected.xml" ), sw ); - assertEquals( "Check database content", removeTimestampVariance( sw.toString() ), - removeTimestampVariance( FileUtils.fileRead( backupFile ) ) ); + //assertEquals( "Check database content", removeTimestampVariance( sw.toString() ), + // removeTimestampVariance( FileUtils.fileRead( backupFile ) ) ); + assertXmlIdentical( removeTimestampVariance( sw.toString() ), removeTimestampVariance( FileUtils + .fileRead( backupFile ) ) ); } public void testEraseBuilds() @@ -126,8 +131,10 @@ IOUtil.copy( getClass().getResourceAsStream( "/expected.xml" ), sw ); - assertEquals( "Check database content", removeTimestampVariance( sw.toString() ), - removeTimestampVariance( FileUtils.fileRead( backupFile ) ) ); + //assertEquals( "Check database content", removeTimestampVariance( sw.toString() ), + // removeTimestampVariance( FileUtils.fileRead( backupFile ) ) ); + assertXmlIdentical( removeTimestampVariance( sw.toString() ), removeTimestampVariance( FileUtils + .fileRead( backupFile ) ) ); } private static File createBackupDirectory() @@ -142,26 +149,51 @@ private static String removeTimestampVariance( String content ) { - return fixXmlQuotes( removeTagContent( - removeTagContent( removeTagContent( removeTagContent( content, "startTime" ), "endTime" ), "date" ), - "id" ) ); + /*return fixXmlQuotes( removeTagContent( removeTagContent( removeTagContent( removeTagContent( content, + "startTime" ), + "endTime" ), "date" ), "id" ) );*/ + + return removeTagContent( removeTagContent( removeTagContent( removeTagContent( content, "startTime" ), + "endTime" ), "date" ), "id" ); } - private static String fixXmlQuotes( String s ) + public void assertXmlIdentical( String expected, String test ) + throws Exception { - if ( s.startsWith( "" ) ) - { - return "" + - s.substring( "".length() ); - } - return cleanLineEndings( s ); + String expectedXml = prettyXmlPrint( expected ); + String testXml = prettyXmlPrint( test ); + Diff diff = new Diff( expectedXml, testXml ); + StringBuffer diffMessage = new StringBuffer(); + assertTrue( " xml diff not identical " + diff.appendMessage( diffMessage ).toString(), diff.identical() ); } - private static String cleanLineEndings( String s ) +/* + public void assertXmlSimilar( String expected, String test ) + throws Exception { - return s.replaceAll( "\r\n", "\n" ); + String expectedXml = XMLOutputHelper.prettyXmlPrint( expected ); + String testXml = XMLOutputHelper.prettyXmlPrint( test ); + Diff diff = new Diff( expectedXml, testXml ); + StringBuffer diffMessage = new StringBuffer(); + assertTrue( " xml diff not similar " + diff.appendMessage( diffMessage ).toString(), diff.similar() ); } +*/ + public String prettyXmlPrint( String xml ) + throws Exception + { + SAXBuilder saxBuilder = new SAXBuilder(); + Document document = saxBuilder.build( new StringReader( xml ) ); + XMLOutputter outp = new XMLOutputter(); + outp.setFormat( Format.getPrettyFormat() ); + + StringWriter sw = new StringWriter(); + + outp.output( document, sw ); + return sw.getBuffer().toString(); + + } + private static String removeTagContent( String content, String field ) { return content.replaceAll( "<" + field + ">.*", "<" + field + ">" ); Index: continuum-data-management/data-management-jdo/src/test/resources/expected.xml =================================================================== --- continuum-data-management/data-management-jdo/src/test/resources/expected.xml (revision 548492) +++ continuum-data-management/data-management-jdo/src/test/resources/expected.xml (working copy) @@ -404,18 +404,18 @@ - 1.3 - /usr/local/java-1.3 + /usr/local/java-1.3 + JAVA_HOME JDK 1.3 - 1.4 - /usr/local/java-1.4 + /usr/local/java-1.4 + JAVA_HOME JDK 1.4 - 2.0-alpha-3 - /usr/local/maven-2.0-alpha-3 + /usr/local/maven-2.0-alpha-3 + M2_HOME Maven 2.0 alpha 3 Index: continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java =================================================================== --- continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java (revision 548492) +++ continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java (working copy) @@ -19,24 +19,6 @@ * under the License. */ -import org.apache.maven.continuum.model.project.BuildDefinition; -import org.apache.maven.continuum.model.project.ContinuumDatabase; -import org.apache.maven.continuum.model.project.Profile; -import org.apache.maven.continuum.model.project.Project; -import org.apache.maven.continuum.model.project.ProjectGroup; -import org.apache.maven.continuum.model.project.Schedule; -import org.apache.maven.continuum.model.project.io.stax.ContinuumStaxReader; -import org.apache.maven.continuum.model.project.io.stax.ContinuumStaxWriter; -import org.apache.maven.continuum.model.system.Installation; -import org.apache.maven.continuum.store.ContinuumStore; -import org.apache.maven.continuum.store.ContinuumStoreException; -import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory; -import org.codehaus.plexus.jdo.PlexusJdoUtils; -import org.codehaus.plexus.util.IOUtil; - -import javax.jdo.JDOHelper; -import javax.jdo.PersistenceManagerFactory; -import javax.xml.stream.XMLStreamException; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; @@ -53,6 +35,25 @@ import java.util.Map; import java.util.Properties; +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManagerFactory; +import javax.xml.stream.XMLStreamException; + +import org.apache.maven.continuum.model.project.BuildDefinition; +import org.apache.maven.continuum.model.project.ContinuumDatabase; +import org.apache.maven.continuum.model.project.Project; +import org.apache.maven.continuum.model.project.ProjectGroup; +import org.apache.maven.continuum.model.project.Schedule; +import org.apache.maven.continuum.model.project.io.stax.ContinuumStaxReader; +import org.apache.maven.continuum.model.project.io.stax.ContinuumStaxWriter; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; +import org.apache.maven.continuum.store.ContinuumStore; +import org.apache.maven.continuum.store.ContinuumStoreException; +import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory; +import org.codehaus.plexus.jdo.PlexusJdoUtils; +import org.codehaus.plexus.util.IOUtil; + /** * JDO implementation the database management tool API. * @@ -89,8 +90,14 @@ // TODO: need these to lazy load to conserve memory while we stream out the model Collection projectGroups = store.getAllProjectGroupsWithTheLot(); database.setProjectGroups( new ArrayList( projectGroups ) ); - - database.setInstallations( store.getAllInstallations() ); + try + { + database.setInstallations( store.getAllInstallations() ); + } + catch ( ContinuumStoreException e ) + { + throw new DataManagementException( e ); + } database.setSchedules( store.getAllSchedulesByName() ); database.setProfiles( store.getAllProfilesByName() ); Index: continuum-data-management/data-management-jdo/pom.xml =================================================================== --- continuum-data-management/data-management-jdo/pom.xml (revision 548492) +++ continuum-data-management/data-management-jdo/pom.xml (working copy) @@ -88,5 +88,17 @@ + + xmlunit + xmlunit + 1.0 + test + + + jdom + jdom + 1.0 + test + Index: continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java =================================================================== --- continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java (revision 0) +++ continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java (revision 0) @@ -0,0 +1,56 @@ +package org.apache.maven.continuum.initialization; + +/* + * 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.continuum.AbstractContinuumTest; +import org.apache.maven.continuum.model.project.Schedule; +import org.apache.maven.continuum.store.ContinuumStore; + +/** + * @author olamy + * @since 4 juin 07 + * @version $Id$ + */ +public class DefaultContinuumInitializerTest + extends AbstractContinuumTest +{ + + protected void setUp() + throws Exception + { + super.setUp(); + ContinuumInitializer continuumInitializer = (ContinuumInitializer) lookup( ContinuumInitializer.ROLE, "default" ); + continuumInitializer.initialize(); + } + + public ContinuumStore getContinuumStore() + throws Exception + { + return (ContinuumStore) lookup( ContinuumStore.ROLE, "jdo" ); + } + + public void testDefaultSchedule() + throws Exception + { + Schedule schedule = getContinuumStore().getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME ); + assertNotNull( schedule ); + } + +} Property changes on: continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java =================================================================== --- continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java (revision 0) +++ continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java (revision 0) @@ -0,0 +1,227 @@ +package org.apache.maven.continuum.profile; + +import java.util.List; + +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; + +/* + * 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 olamy + * @since 15 juin 07 + * @version $Id$ + */ +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(); + getStore().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(); + defaultProfile.setName( "default profile" ); + Profile getted = getProfileService().addProfile( defaultProfile ); + assertNotNull( getProfileService().getProfile( getted.getId() ) ); + } + + 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 all = getProfileService().getAllProfiles(); + assertNotNull( all ); + assertFalse( all.isEmpty() ); + assertEquals( 2, all.size() ); + } + + public void updateProfile() + 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 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 ); + } + +} Property changes on: continuum-core/src/test/java/org/apache/maven/continuum/profile/DefaultProfileServiceTest.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java =================================================================== --- continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java (revision 0) +++ continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java (revision 0) @@ -0,0 +1,158 @@ +package org.apache.maven.continuum.installation; + +import java.util.List; + +import org.apache.maven.continuum.AbstractContinuumTest; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.store.ContinuumStore; + +/* + * 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 olamy + * @since 13 juin 07 + * @version $Id$ + */ +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(); + getStore().eraseDatabase(); + if ( getInstallationService().getInstallation( DEFAULT_INSTALLATION_NAME ) == null ) + { + defaultInstallation = createDefault(); + ContinuumStore store = getStore(); + defaultInstallation = store.addInstallation( defaultInstallation ); + } + } + + private Installation createDefault() + { + 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 + { + this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE ); + Installation getted = getInstallationService().getInstallation( NEW_INSTALLATION_NAME ); + assertNotNull( getted ); + assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() ); + assertEquals( "bar", getted.getVarValue() ); + } + + public void testgetOne() + throws Exception + { + Installation getted = getInstallationService().getInstallation( DEFAULT_INSTALLATION_NAME ); + assertNotNull( getted ); + assertEquals( defaultInstallation.getType(), getted.getType() ); + assertEquals( defaultInstallation.getName(), getted.getName() ); + assertEquals( defaultInstallation.getVarName(), getted.getVarName() ); + assertEquals( defaultInstallation.getVarValue(), getted.getVarValue() ); + } + + public void testRemove() + throws Exception + { + String name = "toremove"; + this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE ); + Installation getted = getInstallationService().getInstallation( name ); + assertNotNull( getted ); + getInstallationService().delete( getted ); + getted = getInstallationService().getInstallation( name ); + assertNull( getted ); + + } + + public void testUpdate() + throws Exception + { + String name = "toupdate"; + this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE ); + Installation getted = getInstallationService().getInstallation( name ); + 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( name ); + 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 infos = installationService.getDefaultJdkInformations(); + assertNotNull( infos ); + } + + public void testgetJdkInformations() + throws Exception + { + InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" ); + String javaHome = System.getProperty( "JAVA_HOME" ); + Installation installation = new Installation(); + installation.setName( "test" ); + installation.setType( InstallationService.JDK_TYPE ); + installation.setVarValue( javaHome ); + + List infos = installationService.getJdkInformations( installation ); + assertNotNull( infos ); + } +} Property changes on: continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java (working copy) @@ -19,11 +19,23 @@ * under the License. */ +import java.io.StringWriter; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + import org.apache.maven.continuum.Continuum; import org.apache.maven.continuum.configuration.ConfigurationService; +import org.apache.maven.continuum.installation.InstallationException; +import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildResult; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectNotifier; +import org.apache.maven.continuum.model.system.Profile; import org.apache.maven.continuum.notification.AbstractContinuumNotifier; import org.apache.maven.continuum.notification.ContinuumNotificationDispatcher; import org.apache.maven.continuum.notification.ContinuumRecipientSource; @@ -40,15 +52,6 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.velocity.VelocityComponent; -import java.io.StringWriter; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - /** * @author Jason van Zyl * @version $Id$ @@ -86,10 +89,13 @@ */ private MailSender mailSender; + /** + * @plexus.requirement role-hint="default" + */ + //private ShellCommandHelper shellCommandHelper; // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- - /** * @plexus.configuration */ @@ -186,13 +192,16 @@ { Project project = (Project) context.get( ContinuumNotificationDispatcher.CONTEXT_PROJECT ); - ProjectNotifier projectNotifier = - (ProjectNotifier) context.get( ContinuumNotificationDispatcher.CONTEXT_PROJECT_NOTIFIER ); + ProjectNotifier projectNotifier = (ProjectNotifier) context + .get( ContinuumNotificationDispatcher.CONTEXT_PROJECT_NOTIFIER ); BuildResult build = (BuildResult) context.get( ContinuumNotificationDispatcher.CONTEXT_BUILD ); String buildOutput = (String) context.get( ContinuumNotificationDispatcher.CONTEXT_BUILD_OUTPUT ); + BuildDefinition buildDefinition = (BuildDefinition) context + .get( ContinuumNotificationDispatcher.CONTEXT_BUILD_DEFINITION ); + // ---------------------------------------------------------------------- // If there wasn't any building done, don't notify // ---------------------------------------------------------------------- @@ -208,14 +217,17 @@ if ( source.equals( ContinuumNotificationDispatcher.MESSAGE_ID_BUILD_COMPLETE ) ) { - buildComplete( project, projectNotifier, build, buildOutput, source, recipients, configuration ); + buildComplete( project, projectNotifier, build, buildOutput, source, recipients, configuration, + buildDefinition ); } } - private void buildComplete( Project project, ProjectNotifier projectNotifier, BuildResult build, String buildOutput, - String source, Set recipients, Map configuration ) + private void buildComplete( Project project, ProjectNotifier projectNotifier, BuildResult build, + String buildOutput, String source, Set recipients, Map configuration, + BuildDefinition buildDefinition ) throws NotificationException { + // ---------------------------------------------------------------------- // Check if the mail should be sent at all // ---------------------------------------------------------------------- @@ -255,8 +267,8 @@ context.put( "build", build ); - context.put( "changesSinceLastSuccess", - continuum.getChangesSinceLastSuccess( project.getId(), build.getId() ) ); + context.put( "changesSinceLastSuccess", continuum.getChangesSinceLastSuccess( project.getId(), build + .getId() ) ); context.put( "buildOutput", buildOutput ); @@ -283,9 +295,14 @@ context.put( "osName", osName ); - context.put( "javaVersion", - System.getProperty( "java.version" ) + "(" + System.getProperty( "java.vendor" ) + ")" ); + context.put( "javaVersion", System.getProperty( "java.version" ) + "(" + + System.getProperty( "java.vendor" ) + ")" ); + // TODO only in case of a java project ? + context.put( "javaHomeInformations", getJavaHomeInformations( buildDefinition ) ); + + // TODO add other informations on profile : builder version other envVars used + // ---------------------------------------------------------------------- // Generate // ---------------------------------------------------------------------- @@ -323,6 +340,21 @@ // // ---------------------------------------------------------------------- + private List getJavaHomeInformations( BuildDefinition buildDefinition ) + throws InstallationException + { + if ( buildDefinition == null ) + { + return continuum.getInstallationService().getDefaultJdkInformations(); + } + Profile profile = buildDefinition.getProfile(); + if ( profile == null ) + { + return continuum.getInstallationService().getDefaultJdkInformations(); + } + return continuum.getInstallationService().getJdkInformations( profile.getJdk() ); + } + private String generateSubject( Project project, BuildResult build ) { int state = project.getState(); @@ -370,8 +402,9 @@ if ( fromMailbox == null ) { getLogger() - .warn( project.getName() + - ": Project is missing nag email and global from mailbox is missing, not sending mail." ); + .warn( + project.getName() + + ": Project is missing nag email and global from mailbox is missing, not sending mail." ); return; } @@ -464,8 +497,8 @@ if ( currentBuild != null && build.getId() != currentBuild.getId() ) { - throw new NotificationException( "INTERNAL ERROR: The current build wasn't the first in the build list. " + - "Current build: '" + currentBuild.getId() + "', " + "first build: '" + build.getId() + "'." ); + throw new NotificationException( "INTERNAL ERROR: The current build wasn't the first in the build list. " + + "Current build: '" + currentBuild.getId() + "', " + "first build: '" + build.getId() + "'." ); } return (BuildResult) builds.get( builds.size() - 2 ); Index: continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java (working copy) @@ -177,6 +177,8 @@ } storedDefinition.setSchedule( schedule ); + + storedDefinition.setProfile( buildDefinition.getProfile() ); store.storeBuildDefinition( storedDefinition ); Index: continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java (revision 0) +++ continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java (revision 0) @@ -0,0 +1,176 @@ +package org.apache.maven.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 java.util.List; + +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; +import org.apache.maven.continuum.store.ContinuumObjectNotFoundException; +import org.apache.maven.continuum.store.ContinuumStore; +import org.apache.maven.continuum.store.ContinuumStoreException; + +/** + * @author olamy + * @since 15 juin 07 + * @version $Id$ + * @plexus.component role="org.apache.maven.continuum.profile.ProfileService" + * TODO use some cache mechanism to prevent always reading from store ? + */ +public class DefaultProfileService + implements ProfileService +{ + + /** + * @plexus.requirement role-hint="jdo" + */ + private ContinuumStore store; + + /** + * @see org.apache.maven.continuum.profile.ProfileService#updateProfile(org.apache.maven.continuum.model.system.Profile) + */ + public void updateProfile( Profile profile ) + throws ProfileException + { + 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() ); + store.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 + { + // TODO check if one with the same name already here + profile.setBuilder( null ); + profile.setJdk( null ); + profile.setEnvironmentVariables( null ); + return store.addProfile( profile ); + } + + /** + * @see org.apache.maven.continuum.profile.ProfileService#deletedProfile(int) + */ + public void deleteProfile( int profileId ) + throws ProfileException + { + store.removeProfile( getProfile( profileId ) ); + } + + /** + * @see org.apache.maven.continuum.profile.ProfileService#getAllProfiles() + */ + public List getAllProfiles() + throws ProfileException + { + return store.getAllProfilesByName(); + } + + /** + * @see org.apache.maven.continuum.profile.ProfileService#getProfile(int) + */ + public Profile getProfile( int profileId ) + throws ProfileException + { + try + { + return store.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 + { + store.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 + { + store.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 + { + store.updateProfile( stored ); + } + catch ( ContinuumStoreException e ) + { + throw new ProfileException( e.getMessage(), e ); + } + } + +} Property changes on: continuum-core/src/main/java/org/apache/maven/continuum/profile/DefaultProfileService.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-core/src/main/java/org/apache/maven/continuum/utils/shell/ShellCommandHelper.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/utils/shell/ShellCommandHelper.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/utils/shell/ShellCommandHelper.java (working copy) @@ -20,6 +20,7 @@ */ import java.io.File; +import java.util.Map; /** * @author Trygve Laugstøl @@ -30,11 +31,11 @@ String ROLE = ShellCommandHelper.class.getName(); ExecutionResult executeShellCommand( File workingDirectory, String executable, String arguments, File output, - long idCommand ) + long idCommand, Map environments ) throws Exception; ExecutionResult executeShellCommand( File workingDirectory, String executable, String[] arguments, File output, - long idCommand ) + long idCommand, Map environments ) throws Exception; boolean isRunning( long idCommand ); Index: continuum-core/src/main/java/org/apache/maven/continuum/utils/shell/DefaultShellCommandHelper.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/utils/shell/DefaultShellCommandHelper.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/utils/shell/DefaultShellCommandHelper.java (working copy) @@ -28,6 +28,9 @@ import java.io.File; import java.io.FileWriter; import java.io.Writer; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; /** * @author Trygve Laugstøl @@ -45,8 +48,8 @@ // ShellCommandHelper Implementation // ---------------------------------------------------------------------- - public ExecutionResult executeShellCommand( File workingDirectory, String executable, String arguments, File output, - long idCommand ) + public ExecutionResult executeShellCommand( File workingDirectory, String executable, String arguments, + File output, long idCommand, Map environments ) throws Exception { Commandline cl = new Commandline(); @@ -55,11 +58,11 @@ argument.setLine( arguments ); - return executeShellCommand( workingDirectory, executable, argument.getParts(), output, idCommand ); + return executeShellCommand( workingDirectory, executable, argument.getParts(), output, idCommand, environments ); } public ExecutionResult executeShellCommand( File workingDirectory, String executable, String[] arguments, - File output, long idCommand ) + File output, long idCommand, Map environments ) throws Exception { // ---------------------------------------------------------------------- @@ -70,10 +73,22 @@ cl.setPid( idCommand ); - cl.addSystemEnvironment(); + cl.addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); + if ( environments != null && !environments.isEmpty() ) + { + for ( Iterator iterator = environments.keySet().iterator(); iterator.hasNext(); ) + { + String key = iterator.next(); + String value = environments.get( key ); + cl.addEnvironment( key, value ); + } + } + + cl.addSystemEnvironment(); + cl.setExecutable( executable ); cl.setWorkingDirectory( workingDirectory.getAbsolutePath() ); @@ -87,6 +102,7 @@ getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); + getLogger().debug( "EnvironmentVariables " + Arrays.asList( cl.getEnvironmentVariables() ) ); // ---------------------------------------------------------------------- // Index: continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java (revision 0) +++ continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java (revision 0) @@ -0,0 +1,279 @@ +package org.apache.maven.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 java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.store.ContinuumStore; +import org.apache.maven.continuum.store.ContinuumStoreException; +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; + +/** + * @author olamy + * @since 13 juin 07 + * @version $Id$ + * @plexus.component role="org.apache.maven.continuum.installation.InstallationService" + * TODO use some cache mechanism to prevent always reading from store ? + */ +public class DefaultInstallationService + implements InstallationService, Initializable +{ + + /** + * @plexus.requirement role-hint="jdo" + */ + private ContinuumStore store; + + private Map typesValues; + + // --------------------------------------------- + // Plexus lifecycle + // --------------------------------------------- + + public void initialize() + throws InitializationException + { + // TODO move this in a component configuration + this.typesValues = new HashMap(); + this.typesValues.put( InstallationService.ANT_TYPE, "ANT_HOME" ); + this.typesValues.put( InstallationService.ENVVAR_TYPE, null ); + this.typesValues.put( InstallationService.JDK_TYPE, "JAVA_HOME" ); + this.typesValues.put( InstallationService.MAVEN1_TYPE, "MAVEN_HOME" ); + this.typesValues.put( InstallationService.MAVEN2_TYPE, "M2_HOME" ); + } + + /** + * @see org.apache.maven.continuum.installation.InstallationService#add(org.apache.maven.continuum.model.system.Installation) + */ + public Installation add( Installation installation ) + throws InstallationException + { + try + { + String envVarName = this.typesValues.get( installation.getType() ); + // override with the defined var name for defined types + if ( StringUtils.isNotEmpty( envVarName ) ) + { + installation.setVarName( envVarName ); + } + return store.addInstallation( installation ); + } + catch ( ContinuumStoreException e ) + { + throw new InstallationException( e.getMessage(), e ); + } + } + + /** + * @see org.apache.maven.continuum.installation.InstallationService#delete(org.apache.maven.continuum.model.system.Installation) + */ + public void delete( Installation installation ) + throws InstallationException + { + // TODO remove the installations attached to profiles : jdo failed + try + { + store.removeInstallation( installation ); + } + catch ( ContinuumStoreException e ) + { + throw new InstallationException( e.getMessage(), e ); + } + + } + + /** + * @see org.apache.maven.continuum.installation.InstallationService#getAllInstallations() + */ + public List getAllInstallations() + throws InstallationException + { + try + { + List installations = store.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(java.lang.String) + */ + public Installation getInstallation( String name ) + throws InstallationException + { + try + { + return store.getInstallationByName( name ); + } + 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.getName() ); + if ( stored == null ) + { + throw new InstallationException( "installation with name " + installation.getName() + " not exists" ); + } + + stored.setName( installation.getName() ); + stored.setType( installation.getType() ); + String envVarName = this.typesValues.get( 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() ); + store.updateInstallation( stored ); + } + catch ( ContinuumStoreException e ) + { + throw new InstallationException( e.getMessage(), e ); + } + + } + + /** + * @see org.apache.maven.continuum.installation.InstallationService#getTypeEnvVar(java.lang.String) + */ + public String getEnvVar( String type ) + { + return (String) this.typesValues.get( type ); + } + + // ------------------------------------------------------------- + // versions informations on jdk and builders (mvn, maven, ant ) + // ------------------------------------------------------------- + + /** + * @see org.apache.maven.continuum.installation.InstallationService#getDefaultJdkInformations() + */ + public List getDefaultJdkInformations() + throws InstallationException + { + try + { + Properties systemEnvVars = CommandLineUtils.getSystemEnvVars( false ); + + String javaHome = (String) systemEnvVars.get( "JAVA_HOME" ); + return getJavaHomeInformations( javaHome ); + } + catch ( IOException e ) + { + throw new InstallationException( e.getMessage(), e ); + } + catch ( CommandLineException e ) + { + throw new InstallationException( e.getMessage(), e ); + } + } + + /** + * @see org.apache.maven.continuum.installation.InstallationService#getJdkInformations(org.apache.maven.continuum.model.system.Installation) + */ + public List getJdkInformations( Installation installation ) + throws InstallationException + { + if ( StringUtils.isEmpty( installation.getVarValue() ) ) + { + return getDefaultJdkInformations(); + } + try + { + return getJavaHomeInformations( installation.getVarValue() ); + } + catch ( CommandLineException e ) + { + throw new InstallationException( e.getMessage(), e ); + } + } + + private List getJavaHomeInformations( String javaHome ) + throws CommandLineException + { + Commandline commandline = new Commandline(); + + String executable = javaHome + File.separator + "bin" + File.separator + "java"; + /* + if ( Os.isFamily( Os.FAMILY_DOS ) ) + { + executable = "%JAVA_HOME%\\bin\\java"; + } + else + { + executable = "$JAVA_HOME/bin/java"; + } + */ + commandline.setExecutable( executable ); + commandline.addArguments( new String[] { "-version" } ); + final List cliOutput = new ArrayList(); + //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; + } +} Property changes on: continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id Name: svn:eol-style + LF Index: continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/execution/ant/AntBuildExecutor.java (working copy) @@ -23,11 +23,17 @@ import org.apache.maven.continuum.execution.ContinuumBuildExecutionResult; import org.apache.maven.continuum.execution.ContinuumBuildExecutor; import org.apache.maven.continuum.execution.ContinuumBuildExecutorException; +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.Project; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; import org.codehaus.plexus.util.StringUtils; import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * @author Trygve Laugstøl @@ -66,21 +72,45 @@ // TODO: get from installation // String executable = project.getExecutable(); String executable = "ant"; - + String arguments = ""; - + String buildFile = buildDefinition.getBuildFile(); - if (!StringUtils.isEmpty(buildFile)) { + if ( !StringUtils.isEmpty( buildFile ) ) + { arguments = "-f " + buildFile + " "; } - arguments += StringUtils.clean( buildDefinition.getArguments() ) + " " + - StringUtils.clean( buildDefinition.getGoals() ); + arguments += StringUtils.clean( buildDefinition.getArguments() ) + " " + + StringUtils.clean( buildDefinition.getGoals() ); - return executeShellCommand( project, executable, arguments, buildOutput ); + return executeShellCommand( project, executable, arguments, buildOutput, getEnvironments( buildDefinition ) ); } + protected Map getEnvironments( BuildDefinition buildDefinition ) + { + Profile profile = buildDefinition.getProfile(); + if ( profile == null ) + { + return Collections.EMPTY_MAP; + } + Map envVars = new HashMap(); + String javaHome = getJavaHomeValue( buildDefinition ); + if ( !StringUtils.isEmpty( javaHome ) ) + { + envVars.put( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), javaHome ); + } + Installation builder = profile.getBuilder(); + if ( builder != null ) + { + envVars.put( getInstallationService().getEnvVar( InstallationService.ANT_TYPE ), builder.getVarValue() ); + } + envVars.putAll( getEnvironmentVariable( buildDefinition ) ); + return envVars; + + } + public void updateProjectFromCheckOut( File workingDirectory, Project p, BuildDefinition buildDefinition ) throws ContinuumBuildExecutorException { Index: continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/execution/AbstractBuildExecutor.java (working copy) @@ -19,9 +19,12 @@ * under the License. */ +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.scm.TestResult; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; import org.apache.maven.continuum.utils.WorkingDirectoryService; import org.apache.maven.continuum.utils.shell.ExecutionResult; import org.apache.maven.continuum.utils.shell.ShellCommandHelper; @@ -34,9 +37,11 @@ import org.codehaus.plexus.util.cli.CommandLineException; import java.io.File; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Collections; +import java.util.Map; /** * @author Trygve Laugstøl @@ -66,6 +71,11 @@ private WorkingDirectoryService workingDirectoryService; /** + * @plexus.requirement + */ + private InstallationService installationService; + + /** * @plexus.configuration */ private String defaultExecutable; @@ -102,8 +112,9 @@ { if ( StringUtils.isEmpty( defaultExecutable ) ) { - getLogger().warn( "The default executable for build executor '" + id + "' is not set. " + - "This will cause a problem unless the project has a executable configured." ); + getLogger().warn( + "The default executable for build executor '" + id + "' is not set. " + + "This will cause a problem unless the project has a executable configured." ); } else { @@ -112,12 +123,14 @@ if ( resolvedExecutable == null ) { getLogger().warn( - "Could not find the executable '" + defaultExecutable + "' in the " + "path '" + path + "'." ); + "Could not find the executable '" + defaultExecutable + "' in the " + "path '" + + path + "'." ); } else { - getLogger().info( "Resolved the executable '" + defaultExecutable + "' to " + "'" + - resolvedExecutable.getAbsolutePath() + "'." ); + getLogger().info( + "Resolved the executable '" + defaultExecutable + "' to " + "'" + + resolvedExecutable.getAbsolutePath() + "'." ); } } } @@ -128,7 +141,7 @@ // ---------------------------------------------------------------------- protected ContinuumBuildExecutionResult executeShellCommand( Project project, String executable, String arguments, - File output ) + File output, Map environments ) throws ContinuumBuildExecutorException { // ---------------------------------------------------------------------- @@ -190,7 +203,8 @@ try { ExecutionResult result = shellCommandHelper.executeShellCommand( workingDirectory, actualExecutable, - arguments, output, project.getId() ); + arguments, output, project.getId(), + environments ); getLogger().info( "Exit code: " + result.getExitCode() ); @@ -205,18 +219,55 @@ else { throw new ContinuumBuildExecutorException( - "Error while executing shell command. The most common error is that '" + executable + "' " - + "is not in your path.", - e ); + "Error while executing shell command. The most common error is that '" + + executable + "' " + "is not in your path.", e ); } } catch ( Exception e ) { - throw new ContinuumBuildExecutorException( "Error while executing shell command. " + - "The most common error is that '" + executable + "' " + "is not in your path.", e ); + throw new ContinuumBuildExecutorException( "Error while executing shell command. " + + "The most common error is that '" + executable + "' " + "is not in your path.", e ); } } + protected abstract Map getEnvironments( BuildDefinition buildDefinition ); + + protected String getJavaHomeValue( BuildDefinition buildDefinition ) + { + Profile profile = buildDefinition.getProfile(); + if ( profile == null ) + { + return null; + } + Installation jdk = profile.getJdk(); + if ( jdk == null ) + { + return null; + } + return jdk.getVarValue(); + } + + protected Map getEnvironmentVariable( BuildDefinition buildDefinition ) + { + Profile profile = buildDefinition.getProfile(); + Map envVars = new HashMap(); + if ( profile == null ) + { + return envVars; + } + List environmentVariables = profile.getEnvironmentVariables(); + if ( environmentVariables.isEmpty() ) + { + return envVars; + } + for ( Iterator iterator = environmentVariables.iterator(); iterator.hasNext(); ) + { + Installation installation = iterator.next(); + envVars.put( installation.getVarName(), installation.getVarValue() ); + } + return envVars; + } + public boolean isBuilding( Project project ) { return shellCommandHelper.isRunning( project.getId() ); @@ -239,8 +290,19 @@ return workingDirectoryService.getWorkingDirectory( project ); } - public TestResult getTestResults(Project project) - throws ContinuumBuildExecutorException { + public TestResult getTestResults( Project project ) + throws ContinuumBuildExecutorException + { return null; } + + public InstallationService getInstallationService() + { + return installationService; + } + + public void setInstallationService( InstallationService installationService ) + { + this.installationService = installationService; + } } Index: continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m1/MavenOneBuildExecutor.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m1/MavenOneBuildExecutor.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m1/MavenOneBuildExecutor.java (working copy) @@ -23,11 +23,17 @@ import org.apache.maven.continuum.execution.ContinuumBuildExecutionResult; import org.apache.maven.continuum.execution.ContinuumBuildExecutor; import org.apache.maven.continuum.execution.ContinuumBuildExecutorException; +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.Project; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; import org.codehaus.plexus.util.StringUtils; import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * @author Trygve Laugstøl @@ -78,9 +84,32 @@ arguments += StringUtils.clean( buildDefinition.getArguments() ) + " " + StringUtils.clean( buildDefinition.getGoals() ); - return executeShellCommand( project, executable, arguments, buildOutput ); + return executeShellCommand( project, executable, arguments, buildOutput, getEnvironments( buildDefinition ) ); } + protected Map getEnvironments( BuildDefinition buildDefinition ) + { + Profile profile = buildDefinition.getProfile(); + if ( profile == null ) + { + return Collections.EMPTY_MAP; + } + Map envVars = new HashMap(); + String javaHome = getJavaHomeValue( buildDefinition ); + if ( !StringUtils.isEmpty( javaHome ) ) + { + envVars.put( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), javaHome ); + } + Installation builder = profile.getBuilder(); + if ( builder != null ) + { + envVars.put( getInstallationService().getEnvVar( InstallationService.MAVEN1_TYPE ), builder.getVarValue() ); + } + envVars.putAll( getEnvironmentVariable( buildDefinition ) ); + return envVars; + + } + public void updateProjectFromCheckOut( File workingDirectory, Project project, BuildDefinition buildDefinition ) throws ContinuumBuildExecutorException { Index: continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/execution/maven/m2/MavenTwoBuildExecutor.java (working copy) @@ -19,17 +19,31 @@ * under the License. */ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +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 org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.continuum.execution.AbstractBuildExecutor; import org.apache.maven.continuum.execution.ContinuumBuildExecutionResult; import org.apache.maven.continuum.execution.ContinuumBuildExecutor; import org.apache.maven.continuum.execution.ContinuumBuildExecutorException; +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.scm.SuiteResult; import org.apache.maven.continuum.model.scm.TestCaseFailure; import org.apache.maven.continuum.model.scm.TestResult; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; @@ -40,14 +54,6 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - /** * @author Trygve Laugstøl * @version $Id$ @@ -107,10 +113,12 @@ arguments = "-f " + buildFile + " "; } - arguments += - StringUtils.clean( buildDefinition.getArguments() ) + " " + StringUtils.clean( buildDefinition.getGoals() ); + arguments += StringUtils.clean( buildDefinition.getArguments() ) + " " + + StringUtils.clean( buildDefinition.getGoals() ); + Map environments = new HashMap(); + Profile profile = buildDefinition.getProfile(); - return executeShellCommand( project, executable, arguments, buildOutput ); + return executeShellCommand( project, executable, arguments, buildOutput, getEnvironments( buildDefinition ) ); } public void updateProjectFromCheckOut( File workingDirectory, Project project, BuildDefinition buildDefinition ) @@ -173,8 +181,8 @@ if ( result.hasErrors() ) { - throw new ContinuumBuildExecutorException( - "Unable to read the Maven project descriptor '" + f + "': " + result.getErrorsAsString() ); + throw new ContinuumBuildExecutorException( "Unable to read the Maven project descriptor '" + f + "': " + + result.getErrorsAsString() ); } // Maven could help us out a lot more here by knowing how to get the deployment artifacts from a project. @@ -277,8 +285,9 @@ { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir( workingDir ); - scanner.setIncludes( - new String[]{"**/target/surefire-reports/TEST-*.xml", "**/target/surefire-it-reports/TEST-*.xml"} ); + scanner.setIncludes( new String[] { + "**/target/surefire-reports/TEST-*.xml", + "**/target/surefire-it-reports/TEST-*.xml" } ); scanner.scan(); TestResult testResult = new TestResult(); @@ -301,8 +310,8 @@ suite.setName( parser.getAttributeValue( null, "name" ) ); - int suiteFailureCount = Integer.parseInt( parser.getAttributeValue( null, "errors" ) ) + - Integer.parseInt( parser.getAttributeValue( null, "failures" ) ); + int suiteFailureCount = Integer.parseInt( parser.getAttributeValue( null, "errors" ) ) + + Integer.parseInt( parser.getAttributeValue( null, "failures" ) ); long suiteTotalTime = (long) ( 1000 * Double.parseDouble( parser.getAttributeValue( null, "time" ) ) ); @@ -319,10 +328,10 @@ { parser.next(); } - while ( parser.getEventType() != XmlPullParser.START_TAG && - parser.getEventType() != XmlPullParser.END_TAG ); - if ( parser.getEventType() == XmlPullParser.START_TAG && - ( "error".equals( parser.getName() ) || "failure".equals( parser.getName() ) ) ) + while ( parser.getEventType() != XmlPullParser.START_TAG + && parser.getEventType() != XmlPullParser.END_TAG ); + if ( parser.getEventType() == XmlPullParser.START_TAG + && ( "error".equals( parser.getName() ) || "failure".equals( parser.getName() ) ) ) { TestCaseFailure failure = new TestCaseFailure(); failure.setName( name ); @@ -364,4 +373,27 @@ return testResult; } + + protected Map getEnvironments( BuildDefinition buildDefinition ) + { + Profile profile = buildDefinition.getProfile(); + if ( profile == null ) + { + return Collections.EMPTY_MAP; + } + Map envVars = new HashMap(); + String javaHome = getJavaHomeValue( buildDefinition ); + if ( !StringUtils.isEmpty( javaHome ) ) + { + envVars.put( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), javaHome ); + } + Installation builder = profile.getBuilder(); + if ( builder != null ) + { + envVars.put( getInstallationService().getEnvVar( InstallationService.MAVEN2_TYPE ), builder.getVarValue() ); + } + envVars.putAll( getEnvironmentVariable( buildDefinition ) ); + return envVars; + + } } Index: continuum-core/src/main/java/org/apache/maven/continuum/execution/shell/ShellBuildExecutor.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/execution/shell/ShellBuildExecutor.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/execution/shell/ShellBuildExecutor.java (working copy) @@ -19,15 +19,21 @@ * under the License. */ +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.apache.maven.continuum.execution.AbstractBuildExecutor; import org.apache.maven.continuum.execution.ContinuumBuildExecutionResult; import org.apache.maven.continuum.execution.ContinuumBuildExecutor; import org.apache.maven.continuum.execution.ContinuumBuildExecutorException; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.Project; +import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; +import org.codehaus.plexus.util.StringUtils; -import java.io.File; - /** * @author Trygve Laugstøl * @version $Id$ @@ -64,9 +70,33 @@ // TODO: this should be validated earlier? String executable = buildDefinition.getBuildFile(); - return executeShellCommand( project, executable, buildDefinition.getArguments(), buildOutput ); + return executeShellCommand( project, executable, buildDefinition.getArguments(), buildOutput, + getEnvironments( buildDefinition ) ); } + protected Map getEnvironments( BuildDefinition buildDefinition ) + { + Profile profile = buildDefinition.getProfile(); + if ( profile == null ) + { + return Collections.EMPTY_MAP; + } + Map envVars = new HashMap(); + String javaHome = getJavaHomeValue( buildDefinition ); + if ( !StringUtils.isEmpty( javaHome ) ) + { + // TODO what todo with this ? + } + Installation builder = profile.getBuilder(); + if ( builder != null ) + { + // TODO what todo with this ? + } + envVars.putAll( getEnvironmentVariable( buildDefinition ) ); + return envVars; + + } + public void updateProjectFromCheckOut( File workingDirectory, Project project, BuildDefinition buildDefinition ) throws ContinuumBuildExecutorException { Index: continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java =================================================================== --- continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java (revision 548492) +++ continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java (working copy) @@ -33,6 +33,7 @@ import org.apache.maven.continuum.initialization.ContinuumInitializationException; import org.apache.maven.continuum.initialization.ContinuumInitializer; import org.apache.maven.continuum.initialization.DefaultContinuumInitializer; +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildResult; import org.apache.maven.continuum.model.project.Project; @@ -40,6 +41,7 @@ import org.apache.maven.continuum.model.project.ProjectNotifier; import org.apache.maven.continuum.model.project.Schedule; import org.apache.maven.continuum.model.scm.ScmResult; +import org.apache.maven.continuum.profile.ProfileService; import org.apache.maven.continuum.project.ContinuumProjectState; import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; import org.apache.maven.continuum.project.builder.maven.MavenOneContinuumProjectBuilder; @@ -120,6 +122,16 @@ * @plexus.requirement */ private SchedulesActivator schedulesActivator; + + /** + * @plexus.requirement + */ + private InstallationService installationService; + + /** + * @plexus.requirement + */ + private ProfileService profileService; // ---------------------------------------------------------------------- // Moved from core @@ -2767,4 +2779,14 @@ } } + public InstallationService getInstallationService() + { + return installationService; + } + + public ProfileService getProfileService() + { + return profileService; + } + } Index: continuum-core/src/main/resources/META-INF/plexus/components.xml =================================================================== --- continuum-core/src/main/resources/META-INF/plexus/components.xml (revision 548492) +++ continuum-core/src/main/resources/META-INF/plexus/components.xml (working copy) @@ -100,6 +100,9 @@ org.apache.maven.project.MavenProjectHelper + + org.apache.maven.continuum.installation.InstallationService + @@ -124,6 +127,9 @@ org.apache.maven.continuum.utils.WorkingDirectoryService + + org.apache.maven.continuum.installation.InstallationService + @@ -142,6 +148,9 @@ org.apache.maven.continuum.utils.WorkingDirectoryService + + org.apache.maven.continuum.installation.InstallationService + ant @@ -162,6 +171,9 @@ org.apache.maven.continuum.utils.WorkingDirectoryService + + org.apache.maven.continuum.installation.InstallationService + Index: continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm =================================================================== --- continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm (revision 548492) +++ continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm (working copy) @@ -30,7 +30,10 @@ Exit code: $build.exitCode Building machine hostname: $buildHost Operating system : $osName - Java version : $javaVersion + Java Home version : + #foreach ( $javaHomeInformation in $javaHomeInformations ) + $javaHomeInformation + #end #if ( $build.scmResult ) **************************************************************************** Index: continuum-core/pom.xml =================================================================== --- continuum-core/pom.xml (revision 548492) +++ continuum-core/pom.xml (working copy) @@ -231,6 +231,16 @@ **/BuildProjectTaskExecutorTest.java + + + JAVA_HOME + ${JAVA_HOME} + + + M2_HOME + ${M2_HOME} + + Index: continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java =================================================================== --- continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java (revision 548492) +++ continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java (working copy) @@ -19,9 +19,17 @@ * under the License. */ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.jdo.JDODetachedFieldAccessException; + +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildResult; -import org.apache.maven.continuum.model.project.Profile; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectDependency; import org.apache.maven.continuum.model.project.ProjectDeveloper; @@ -29,13 +37,9 @@ import org.apache.maven.continuum.model.project.ProjectNotifier; import org.apache.maven.continuum.model.project.Schedule; import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; +import org.codehaus.plexus.logging.LoggerManager; -import javax.jdo.JDODetachedFieldAccessException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - /** * @author Brett Porter * @version $Id$ @@ -270,7 +274,7 @@ public void testGetAllProjects() { List projects = store.getAllProjectsByName(); - assertEquals( "check items", Arrays.asList( new Project[]{testProject1, testProject2} ), projects ); + assertEquals( "check items", Arrays.asList( new Project[] { testProject1, testProject2 } ), projects ); Project project = (Project) projects.get( 1 ); assertProjectEquals( testProject2, project ); @@ -334,11 +338,12 @@ } public void testAddProfile() + throws Exception { List installations = store.getAllInstallations(); Profile newProfile = createTestProfile( "testAddProfile", "testAddProfile desc", 5, false, false, - (Installation) installations.get( 1 ), - (Installation) installations.get( 2 ) ); + (Installation) installations.get( 1 ), (Installation) installations + .get( 2 ) ); Profile copy = createTestProfile( newProfile ); store.addProfile( newProfile ); copy.setId( newProfile.getId() ); @@ -402,7 +407,16 @@ assertInstallationEquals( testProfile3.getJdk(), profile.getJdk() ); } +/* + public void testGetgetProfileByName() + throws ContinuumStoreException + { + Profile profile = store.getProfileByName( "name1" ); + assertNotNull( profile ); + } +*/ public void testGetAllInstallations() + throws Exception { List installations = store.getAllInstallations(); @@ -417,6 +431,158 @@ assertInstallationEquals( testInstallationMaven20a3, installation ); } + public void testUpdateInstallation() + throws Exception + { + String name = "installationTest"; + Installation testOne = createTestInstallation( name, InstallationService.JDK_TYPE, "varName", "varValue" ); + testOne = store.addInstallation( testOne ); + + Installation fromStore = store.getInstallationByName( name ); + assertInstallationEquals( testOne, fromStore ); + + fromStore.setVarName( "JAVA_HOME" ); + fromStore.setVarValue( "/usr/local/jdk1.5.0_08" ); + store.updateInstallation( fromStore ); + + Installation updatedFromStore = store.getInstallationByName( name ); + + assertInstallationEquals( fromStore, updatedFromStore ); + } + + public void testRemoveInstallation() + throws Exception + { + String name = "installationTestRemove"; + Installation testOne = createTestInstallation( name, InstallationService.JDK_TYPE, "varName", "varValue" ); + testOne = store.addInstallation( testOne ); + + store.removeInstallation( testOne ); + Installation fromStore = store.getInstallationByName( name ); + assertNull( fromStore ); + } + + public void testRemoveLinkedInstallations() + throws Exception + { + String nameFirstInst = "linkedFirstInstallationTestRemove"; + String nameSecondInst = "linkedSecondInstallationTestRemove"; + String nameFirstEnvVar = "firstEnvVar"; + String nameSecondEnvVar = "secondEnvVar"; + + Installation testOne = createTestInstallation( nameFirstInst, InstallationService.JDK_TYPE, "varName", + "varValue" ); + + Installation testTwo = createTestInstallation( nameSecondInst, InstallationService.MAVEN2_TYPE, "varName", + "varValue" ); + + Installation firstEnvVar = createTestInstallation( nameFirstEnvVar, InstallationService.MAVEN2_TYPE, "varName", + "varValue" ); + + Installation secondEnvVar = createTestInstallation( nameSecondEnvVar, InstallationService.MAVEN2_TYPE, + "varName", "varValue" ); + + testOne = store.addInstallation( testOne ); + testTwo = store.addInstallation( testTwo ); + + firstEnvVar = store.addInstallation( firstEnvVar ); + secondEnvVar = store.addInstallation( secondEnvVar ); + + List envVars = new ArrayList( 2 ); + envVars.add( firstEnvVar ); + envVars.add( secondEnvVar ); + + Profile firstProfile = createTestProfile( "first", "", 1, true, true, testOne, testTwo, envVars ); + + Profile secondProfile = createTestProfile( "first", "", 1, true, true, testOne, testTwo, envVars ); + + firstProfile = store.addProfile( firstProfile ); + secondProfile = store.addProfile( secondProfile ); + + Profile firstGetted = store.getProfile( firstProfile.getId() ); + Profile secondGetted = store.getProfile( secondProfile.getId() ); + + assertNotNull( firstGetted ); + assertNotNull( firstGetted.getJdk() ); + assertEquals( nameFirstInst, firstGetted.getJdk().getName() ); + + assertNotNull( secondGetted ); + assertNotNull( secondGetted.getJdk() ); + assertEquals( nameFirstInst, secondGetted.getJdk().getName() ); + + assertNotNull( firstGetted.getBuilder() ); + assertEquals( nameSecondInst, firstGetted.getBuilder().getName() ); + assertEquals( 2, firstGetted.getEnvironmentVariables().size() ); + + assertNotNull( secondGetted.getBuilder() ); + assertEquals( nameSecondInst, secondGetted.getBuilder().getName() ); + assertEquals( 2, secondGetted.getEnvironmentVariables().size() ); + + store.removeInstallation( testOne ); + + Installation fromStore = store.getInstallationByName( nameFirstInst ); + assertNull( fromStore ); + + firstGetted = store.getProfile( firstProfile.getId() ); + secondGetted = store.getProfile( secondProfile.getId() ); + assertNotNull( firstGetted ); + assertNull( firstGetted.getJdk() ); + assertNotNull( firstGetted.getBuilder() ); + assertEquals( 2, firstGetted.getEnvironmentVariables().size() ); + assertNotNull( secondGetted ); + assertNull( secondGetted.getJdk() ); + assertNotNull( secondGetted.getBuilder() ); + assertEquals( 2, secondGetted.getEnvironmentVariables().size() ); + // removing builder + store.removeInstallation( testTwo ); + + firstGetted = store.getProfile( firstProfile.getId() ); + secondGetted = store.getProfile( secondProfile.getId() ); + + assertNotNull( firstGetted ); + assertNull( firstGetted.getJdk() ); + assertNull( firstGetted.getBuilder() ); + assertEquals( 2, firstGetted.getEnvironmentVariables().size() ); + + assertNotNull( secondGetted ); + assertNull( secondGetted.getJdk() ); + assertNull( secondGetted.getBuilder() ); + assertEquals( 2, secondGetted.getEnvironmentVariables().size() ); + + // removing firstEnvVar + store.removeInstallation( firstEnvVar ); + firstGetted = store.getProfile( firstProfile.getId() ); + secondGetted = store.getProfile( secondProfile.getId() ); + assertNotNull( firstGetted ); + assertNull( firstGetted.getJdk() ); + assertNull( firstGetted.getBuilder() ); + assertEquals( 1, firstGetted.getEnvironmentVariables().size() ); + Installation env = (Installation) firstGetted.getEnvironmentVariables().get( 0 ); + assertEquals( nameSecondEnvVar, env.getName() ); + + assertNotNull( secondGetted ); + assertNull( secondGetted.getJdk() ); + assertNull( secondGetted.getBuilder() ); + assertEquals( 1, secondGetted.getEnvironmentVariables().size() ); + env = (Installation) secondGetted.getEnvironmentVariables().get( 0 ); + assertEquals( nameSecondEnvVar, env.getName() ); + + // removing secondEnvVar + store.removeInstallation( secondEnvVar ); + firstGetted = store.getProfile( firstProfile.getId() ); + secondGetted = store.getProfile( secondProfile.getId() ); + assertNotNull( firstGetted ); + assertNull( firstGetted.getJdk() ); + assertNull( firstGetted.getBuilder() ); + assertEquals( 0, firstGetted.getEnvironmentVariables().size() ); + + + assertNotNull( secondGetted ); + assertNull( secondGetted.getJdk() ); + assertNull( secondGetted.getBuilder() ); + assertEquals( 0, secondGetted.getEnvironmentVariables().size() ); + } + public void testDeleteProject() throws ContinuumStoreException { @@ -525,7 +691,8 @@ public void testGetProjectGroupWithDetails() throws ContinuumStoreException { - ProjectGroup retrievedGroup = store.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup.getId() ); + ProjectGroup retrievedGroup = store.getProjectGroupWithBuildDetailsByProjectGroupId( defaultProjectGroup + .getId() ); assertProjectGroupEquals( defaultProjectGroup, retrievedGroup ); assertNotifiersEqual( defaultProjectGroup.getNotifiers(), retrievedGroup.getNotifiers() ); assertBuildDefinitionsEqual( retrievedGroup.getBuildDefinitions(), defaultProjectGroup.getBuildDefinitions() ); Index: continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java =================================================================== --- continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java (revision 548492) +++ continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java (working copy) @@ -19,9 +19,15 @@ * under the License. */ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.maven.continuum.installation.InstallationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildResult; -import org.apache.maven.continuum.model.project.Profile; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectDependency; import org.apache.maven.continuum.model.project.ProjectDeveloper; @@ -32,17 +38,12 @@ import org.apache.maven.continuum.model.scm.ChangeSet; import org.apache.maven.continuum.model.scm.ScmResult; import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; import org.apache.maven.continuum.model.system.SystemConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory; import org.codehaus.plexus.jdo.JdoFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - /** * Base class for tests using the continuum store. */ @@ -120,15 +121,17 @@ } protected void createBuildDatabase() + throws Exception { createBuildDatabase( true ); } protected void createBuildDatabase( boolean addToStore ) + throws Exception { // Setting up test data - defaultProjectGroup = - createTestProjectGroup( "Default Group", "The Default Group", "org.apache.maven.test.default" ); + defaultProjectGroup = createTestProjectGroup( "Default Group", "The Default Group", + "org.apache.maven.test.default" ); testProjectGroup2 = createTestProjectGroup( "test group 2", "test group 2 desc", "test group 2 groupId" ); @@ -143,10 +146,12 @@ testSchedule2 = createTestSchedule( "name2", "description2", 2, "cronExpression2", true ); testSchedule3 = createTestSchedule( "name3", "description3", 3, "cronExpression3", true ); - testInstallationJava13 = createTestInstallation( "JDK 1.3", "/usr/local/java-1.3", "1.3" ); - testInstallationJava14 = createTestInstallation( "JDK 1.4", "/usr/local/java-1.4", "1.4" ); - testInstallationMaven20a3 = - createTestInstallation( "Maven 2.0 alpha 3", "/usr/local/maven-2.0-alpha-3", "2.0-alpha-3" ); + testInstallationJava13 = createTestInstallation( "JDK 1.3", InstallationService.JDK_TYPE, "JAVA_HOME", + "/usr/local/java-1.3" ); + testInstallationJava14 = createTestInstallation( "JDK 1.4", InstallationService.JDK_TYPE, "JAVA_HOME", + "/usr/local/java-1.4" ); + testInstallationMaven20a3 = createTestInstallation( "Maven 2.0 alpha 3", InstallationService.MAVEN2_TYPE, + "M2_HOME", "/usr/local/maven-2.0-alpha-3" ); testGroupNotifier1 = createTestNotifier( 1, true, false, true, "type1" ); testGroupNotifier2 = createTestNotifier( 2, false, true, false, "type2" ); @@ -243,12 +248,12 @@ installationJava13 = store.addInstallation( installationJava13 ); } - testProfile1 = - createTestProfile( "name1", "description1", 1, true, true, installationJava13, installationMaven20a3 ); - testProfile2 = - createTestProfile( "name2", "description2", 2, false, true, installationJava14, installationMaven20a3 ); - testProfile3 = - createTestProfile( "name3", "description3", 3, true, false, installationJava14, installationMaven20a3 ); + testProfile1 = createTestProfile( "name1", "description1", 1, true, true, installationJava13, + installationMaven20a3 ); + testProfile2 = createTestProfile( "name2", "description2", 2, false, true, installationJava14, + installationMaven20a3 ); + testProfile3 = createTestProfile( "name3", "description3", 3, true, false, installationJava14, + installationMaven20a3 ); Profile profile1 = createTestProfile( testProfile1 ); if ( addToStore ) @@ -271,23 +276,23 @@ } testProfile3.setId( profile3.getId() ); - BuildDefinition testGroupBuildDefinition1 = - createTestBuildDefinition( "arguments1", "buildFile1", "goals1", profile1, schedule2, false, false ); - BuildDefinition testGroupBuildDefinition2 = - createTestBuildDefinition( "arguments2", "buildFile2", "goals2", profile1, schedule1, false, false ); - BuildDefinition testGroupBuildDefinition3 = - createTestBuildDefinition( "arguments3", "buildFile3", "goals3", profile2, schedule1, false, false ); - BuildDefinition testGroupBuildDefinition4 = - createTestBuildDefinition( null, null, "deploy", null, null, false, false ); + BuildDefinition testGroupBuildDefinition1 = createTestBuildDefinition( "arguments1", "buildFile1", "goals1", + profile1, schedule2, false, false ); + BuildDefinition testGroupBuildDefinition2 = createTestBuildDefinition( "arguments2", "buildFile2", "goals2", + profile1, schedule1, false, false ); + BuildDefinition testGroupBuildDefinition3 = createTestBuildDefinition( "arguments3", "buildFile3", "goals3", + profile2, schedule1, false, false ); + BuildDefinition testGroupBuildDefinition4 = createTestBuildDefinition( null, null, "deploy", null, null, false, + false ); - BuildDefinition testBuildDefinition1 = - createTestBuildDefinition( "arguments11", "buildFile11", "goals11", profile2, schedule1, false, false ); - BuildDefinition testBuildDefinition2 = - createTestBuildDefinition( "arguments12", "buildFile12", "goals12", profile2, schedule2, false, false ); - BuildDefinition testBuildDefinition3 = - createTestBuildDefinition( "arguments13", "buildFile13", "goals13", profile1, schedule2, false, false ); - BuildDefinition testBuildDefinition4 = - createTestBuildDefinition( null, null, "deploy", null, null, false, false ); + BuildDefinition testBuildDefinition1 = createTestBuildDefinition( "arguments11", "buildFile11", "goals11", + profile2, schedule1, false, false ); + BuildDefinition testBuildDefinition2 = createTestBuildDefinition( "arguments12", "buildFile12", "goals12", + profile2, schedule2, false, false ); + BuildDefinition testBuildDefinition3 = createTestBuildDefinition( "arguments13", "buildFile13", "goals13", + profile1, schedule2, false, false ); + BuildDefinition testBuildDefinition4 = createTestBuildDefinition( null, null, "deploy", null, null, false, + false ); ProjectGroup group = createTestProjectGroup( defaultProjectGroup ); @@ -634,9 +639,9 @@ protected static BuildDefinition createTestBuildDefinition( BuildDefinition buildDefinition ) { return createTestBuildDefinition( buildDefinition.getArguments(), buildDefinition.getBuildFile(), - buildDefinition.getGoals(), buildDefinition.getProfile(), - buildDefinition.getSchedule(), buildDefinition.isDefaultForProject(), - buildDefinition.isBuildFresh() ); + buildDefinition.getGoals(), buildDefinition.getProfile(), buildDefinition + .getSchedule(), buildDefinition.isDefaultForProject(), buildDefinition + .isBuildFresh() ); } protected static BuildDefinition createTestBuildDefinition( String arguments, String buildFile, String goals, @@ -680,8 +685,8 @@ private static ScmResult createTestScmResult( ScmResult scmResult, String base ) { - return createTestScmResult( scmResult.getCommandOutput(), scmResult.getProviderMessage(), scmResult.isSuccess(), - base ); + return createTestScmResult( scmResult.getCommandOutput(), scmResult.getProviderMessage(), + scmResult.isSuccess(), base ); } private static ScmResult createTestScmResult( String commandOutput, String providerMessage, boolean success, @@ -743,24 +748,25 @@ return result; } - private static Installation createTestInstallation( String name, String path, String version ) + protected static Installation createTestInstallation( String name, String type, String varName, String varValue ) { Installation installation = new Installation(); installation.setName( name ); - installation.setPath( path ); - installation.setVersion( version ); + installation.setVarName( varName ); + installation.setVarValue( varValue ); return installation; } protected static Installation createTestInstallation( Installation installation ) { - return createTestInstallation( installation.getName(), installation.getPath(), installation.getVersion() ); + return createTestInstallation( installation.getName(), installation.getType(), installation.getVarName(), + installation.getVarValue() ); } protected static Schedule createTestSchedule( Schedule schedule ) { - return createTestSchedule( schedule.getName(), schedule.getDescription(), schedule.getDelay(), - schedule.getCronExpression(), schedule.isActive() ); + return createTestSchedule( schedule.getName(), schedule.getDescription(), schedule.getDelay(), schedule + .getCronExpression(), schedule.isActive() ); } protected static Schedule createTestSchedule( String name, String description, int delay, String cronExpression, @@ -777,9 +783,8 @@ protected static Profile createTestProfile( Profile profile ) { - return createTestProfile( profile.getName(), profile.getDescription(), profile.getScmMode(), - profile.isBuildWithoutChanges(), profile.isActive(), profile.getJdk(), - profile.getBuilder() ); + return createTestProfile( profile.getName(), profile.getDescription(), profile.getScmMode(), profile + .isBuildWithoutChanges(), profile.isActive(), profile.getJdk(), profile.getBuilder() ); // createTestInstallation( profile.getJdk() ), // createTestInstallation( profile.getBuilder() ) ); } @@ -798,6 +803,22 @@ profile.setJdk( jdk ); return profile; } + + protected static Profile createTestProfile( String name, String description, int scmMode, + boolean buildWithoutChanges, boolean active, Installation jdk, + Installation builder, List envVars ) + { + Profile profile = new Profile(); + profile.setActive( active ); + profile.setBuildWithoutChanges( buildWithoutChanges ); + profile.setScmMode( scmMode ); + profile.setDescription( description ); + profile.setName( name ); + profile.setBuilder( builder ); + profile.setJdk( jdk ); + profile.setEnvironmentVariables( envVars ); + return profile; + } protected static ProjectGroup createTestProjectGroup( ProjectGroup group ) { @@ -815,9 +836,9 @@ protected static Project createTestProject( Project project ) { - return createTestProject( project.getArtifactId(), project.getBuildNumber(), project.getDescription(), - project.getGroupId(), project.getName(), project.getScmUrl(), project.getState(), - project.getUrl(), project.getVersion(), project.getWorkingDirectory() ); + return createTestProject( project.getArtifactId(), project.getBuildNumber(), project.getDescription(), project + .getGroupId(), project.getName(), project.getScmUrl(), project.getState(), project.getUrl(), project + .getVersion(), project.getWorkingDirectory() ); } private static Project createTestProject( String artifactId, int buildNumber, String description, String groupId, @@ -846,16 +867,15 @@ assertEquals( "compare expectedProject - name", expectedProject.getName(), project.getName() ); assertEquals( "compare expectedProject - desc", expectedProject.getDescription(), project.getDescription() ); assertEquals( "compare expectedProject - groupId", expectedProject.getGroupId(), project.getGroupId() ); - assertEquals( "compare expectedProject - artifactId", expectedProject.getArtifactId(), - project.getArtifactId() ); - assertEquals( "compare expectedProject - buildNumber", expectedProject.getBuildNumber(), - project.getBuildNumber() ); + assertEquals( "compare expectedProject - artifactId", expectedProject.getArtifactId(), project.getArtifactId() ); + assertEquals( "compare expectedProject - buildNumber", expectedProject.getBuildNumber(), project + .getBuildNumber() ); assertEquals( "compare expectedProject - scmUrl", expectedProject.getScmUrl(), project.getScmUrl() ); assertEquals( "compare expectedProject - state", expectedProject.getState(), project.getState() ); assertEquals( "compare expectedProject - url", expectedProject.getUrl(), project.getUrl() ); assertEquals( "compare expectedProject - version", expectedProject.getVersion(), project.getVersion() ); - assertEquals( "compare expectedProject - workingDirectory", expectedProject.getWorkingDirectory(), - project.getWorkingDirectory() ); + assertEquals( "compare expectedProject - workingDirectory", expectedProject.getWorkingDirectory(), project + .getWorkingDirectory() ); } protected static void assertProjectGroupEquals( ProjectGroup expectedGroup, ProjectGroup actualGroup ) @@ -876,11 +896,10 @@ assertNotSame( expectedSchedule, actualSchedule ); assertEquals( "compare schedule - id", expectedSchedule.getId(), actualSchedule.getId() ); assertEquals( "compare schedule - name", expectedSchedule.getName(), actualSchedule.getName() ); - assertEquals( "compare schedule - desc", expectedSchedule.getDescription(), - actualSchedule.getDescription() ); + assertEquals( "compare schedule - desc", expectedSchedule.getDescription(), actualSchedule.getDescription() ); assertEquals( "compare schedule - delay", expectedSchedule.getDelay(), actualSchedule.getDelay() ); - assertEquals( "compare schedule - cron", expectedSchedule.getCronExpression(), - actualSchedule.getCronExpression() ); + assertEquals( "compare schedule - cron", expectedSchedule.getCronExpression(), actualSchedule + .getCronExpression() ); assertEquals( "compare schedule - active", expectedSchedule.isActive(), actualSchedule.isActive() ); } } @@ -894,17 +913,18 @@ assertEquals( "compare profile - name", expectedProfile.getName(), actualProfile.getName() ); assertEquals( "compare profile - desc", expectedProfile.getDescription(), actualProfile.getDescription() ); assertEquals( "compare profile - scmMode", expectedProfile.getScmMode(), actualProfile.getScmMode() ); - assertEquals( "compare profile - build w/o changes", expectedProfile.isBuildWithoutChanges(), - actualProfile.isBuildWithoutChanges() ); + assertEquals( "compare profile - build w/o changes", expectedProfile.isBuildWithoutChanges(), actualProfile + .isBuildWithoutChanges() ); assertEquals( "compare profile - active", expectedProfile.isActive(), actualProfile.isActive() ); } } protected static void assertInstallationEquals( Installation expected, Installation actual ) { + assertNotNull( actual ); assertEquals( "compare installation - name", expected.getName(), actual.getName() ); - assertEquals( "compare installation - path", expected.getPath(), actual.getPath() ); - assertEquals( "compare installation - version", expected.getVersion(), actual.getVersion() ); + assertEquals( "compare installation - varName", expected.getVarName(), actual.getVarName() ); + assertEquals( "compare installation - varValue", expected.getVarValue(), actual.getVarValue() ); } protected static void assertBuildResultEquals( BuildResult expected, BuildResult actual ) @@ -926,8 +946,7 @@ assertEquals( "compare SCM result - changes size", actual.getChanges().size(), expected.getChanges().size() ); for ( int i = 0; i < actual.getChanges().size(); i++ ) { - assertChangeSetEquals( (ChangeSet) expected.getChanges().get( i ), - (ChangeSet) actual.getChanges().get( i ) ); + assertChangeSetEquals( (ChangeSet) expected.getChanges().get( i ), (ChangeSet) actual.getChanges().get( i ) ); } } @@ -940,8 +959,7 @@ assertEquals( "compare change set result - files size", expected.getFiles().size(), actual.getFiles().size() ); for ( int i = 0; i < actual.getFiles().size(); i++ ) { - assertChangeFileEquals( (ChangeFile) expected.getFiles().get( i ), - (ChangeFile) actual.getFiles().get( i ) ); + assertChangeFileEquals( (ChangeFile) expected.getFiles().get( i ), (ChangeFile) actual.getFiles().get( i ) ); } } @@ -988,8 +1006,8 @@ actualBuildDefinition.getArguments() ); assertEquals( "compare build definition - build file", expectedBuildDefinition.getBuildFile(), actualBuildDefinition.getBuildFile() ); - assertEquals( "compare build definition - goals", expectedBuildDefinition.getGoals(), - actualBuildDefinition.getGoals() ); + assertEquals( "compare build definition - goals", expectedBuildDefinition.getGoals(), actualBuildDefinition + .getGoals() ); assertEquals( "compare build definition - build fresh", expectedBuildDefinition.isBuildFresh(), actualBuildDefinition.isBuildFresh() ); assertEquals( "compare build definition - defaultForProject", expectedBuildDefinition.isDefaultForProject(), @@ -1000,8 +1018,8 @@ { for ( int i = 0; i < actualDevelopers.size(); i++ ) { - assertDeveloperEquals( (ProjectDeveloper) expectedDevelopers.get( i ), - (ProjectDeveloper) actualDevelopers.get( i ) ); + assertDeveloperEquals( (ProjectDeveloper) expectedDevelopers.get( i ), (ProjectDeveloper) actualDevelopers + .get( i ) ); } } @@ -1010,8 +1028,8 @@ assertEquals( "compare developer - name", expectedDeveloper.getName(), actualDeveloper.getName() ); assertEquals( "compare developer - email", expectedDeveloper.getEmail(), actualDeveloper.getEmail() ); assertEquals( "compare developer - scmId", expectedDeveloper.getScmId(), actualDeveloper.getScmId() ); - assertEquals( "compare developer - continuumId", expectedDeveloper.getContinuumId(), - actualDeveloper.getContinuumId() ); + assertEquals( "compare developer - continuumId", expectedDeveloper.getContinuumId(), actualDeveloper + .getContinuumId() ); } protected static void assertDependenciesEqual( List expectedDependencies, List actualDependencies ) @@ -1027,8 +1045,8 @@ ProjectDependency actualDependency ) { assertEquals( "compare dependency - groupId", expectedDependency.getGroupId(), actualDependency.getGroupId() ); - assertEquals( "compare dependency - artifactId", expectedDependency.getArtifactId(), - actualDependency.getArtifactId() ); + assertEquals( "compare dependency - artifactId", expectedDependency.getArtifactId(), actualDependency + .getArtifactId() ); assertEquals( "compare dependency - version", expectedDependency.getVersion(), actualDependency.getVersion() ); } @@ -1039,8 +1057,8 @@ protected static ProjectDeveloper createTestDeveloper( ProjectDeveloper developer ) { - return createTestDeveloper( developer.getContinuumId(), developer.getEmail(), developer.getName(), - developer.getScmId() ); + return createTestDeveloper( developer.getContinuumId(), developer.getEmail(), developer.getName(), developer + .getScmId() ); } protected static ProjectDependency createTestDependency( String groupId, String artifactId, String version ) @@ -1070,8 +1088,7 @@ protected ContinuumStore createStore() throws Exception { - DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, - "continuum" ); + DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "continuum" ); jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); Index: continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java =================================================================== --- continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java (revision 548492) +++ continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java (working copy) @@ -19,9 +19,25 @@ * under the License. */ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.jdo.Extent; +import javax.jdo.FetchPlan; +import javax.jdo.JDOHelper; +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; +import javax.jdo.Transaction; + import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildResult; -import org.apache.maven.continuum.model.project.Profile; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectDependency; import org.apache.maven.continuum.model.project.ProjectDeveloper; @@ -35,6 +51,7 @@ import org.apache.maven.continuum.model.scm.TestCaseFailure; import org.apache.maven.continuum.model.scm.TestResult; import org.apache.maven.continuum.model.system.Installation; +import org.apache.maven.continuum.model.system.Profile; import org.apache.maven.continuum.model.system.SystemConfiguration; import org.apache.maven.continuum.project.ContinuumProjectState; import org.codehaus.plexus.jdo.JdoFactory; @@ -43,28 +60,14 @@ import org.codehaus.plexus.jdo.PlexusStoreException; 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 javax.jdo.Extent; -import javax.jdo.FetchPlan; -import javax.jdo.JDOHelper; -import javax.jdo.JDOUserException; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import javax.jdo.Query; -import javax.jdo.Transaction; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - /** * @author Trygve Laugstøl * @author Brett Porter * @version $Id$ - * @plexus.component role="org.apache.maven.continuum.store.ContinuumStore" role-hint="jdo" + * @plexus.component role="org.apache.maven.continuum.store.ContinuumStore" + * role-hint="jdo" */ public class JdoContinuumStore extends AbstractContinuumStore @@ -203,9 +206,9 @@ } /** - * get the combined list of projectId and build definitions, including the ones - * inherited by their project group - * + * get the combined list of projectId and build definitions, including the + * ones inherited by their project group + * * @param scheduleId * @return * @throws ContinuumStoreException @@ -224,7 +227,8 @@ aggregate.putAll( projectSource ); } - // iterate through the project groups and make sure we are not walking over projects that + // iterate through the project groups and make sure we are not walking + // over projects that // might define their own build definitions if ( projectGroupSource != null ) { @@ -432,7 +436,8 @@ build = (BuildResult) makePersistent( pm, build, false ); - // TODO: these are in the wrong spot - set them on success (though currently some depend on latest build being the one in progress) + // TODO: these are in the wrong spot - set them on success (though + // currently some depend on latest build being the one in progress) project.setLatestBuildId( build.getId() ); project.setState( build.getState() ); @@ -577,7 +582,7 @@ getLogger().debug( "no default build definition on project, trying project group" ); } - //project group should have default build definition defined + // project group should have default build definition defined if ( bd == null ) { ProjectGroup projectGroup = getProjectGroupByProjectId( projectId ); @@ -619,7 +624,6 @@ throw new ContinuumObjectNotFoundException( "no default build definition declared for project " + projectId ); } - public BuildDefinition getDefaultBuildDefinitionForProjectGroup( int projectGroupId ) throws ContinuumStoreException, ContinuumObjectNotFoundException { @@ -663,7 +667,7 @@ List result = (List) query.execute(); - //result = (List) pm.detachCopyAll( result ); + // result = (List) pm.detachCopyAll( result ); Map builds = new HashMap(); @@ -903,16 +907,66 @@ return schedule; } + // ---------------------------------------------------------------- + // Profile + // ---------------------------------------------------------------- + public List getAllProfilesByName() { return getAllObjectsDetached( Profile.class, "name ascending", null ); } + public Profile getProfileByName( String profileName ) + throws ContinuumStoreException + { + PersistenceManager pm = getPersistenceManager(); + + Transaction tx = pm.currentTransaction(); + + try + { + tx.begin(); + + Extent extent = pm.getExtent( Profile.class, true ); + + Query query = pm.newQuery( extent ); + + query.declareImports( "import java.lang.String" ); + + query.declareParameters( "String name" ); + + query.setFilter( "this.name == name" ); + + Collection result = (Collection) query.execute( profileName ); + + if ( result.size() == 0 ) + { + tx.commit(); + + return null; + } + + Object object = pm.detachCopy( result.iterator().next() ); + + tx.commit(); + + return (Profile) object; + } + finally + { + rollback( tx ); + } + } + public Profile addProfile( Profile profile ) { return (Profile) addObject( profile ); } + // ---------------------------------------------------------------- + // Installation + // ---------------------------------------------------------------- + public Installation addInstallation( Installation installation ) { return (Installation) addObject( installation ); @@ -920,9 +974,163 @@ public List getAllInstallations() { - return getAllObjectsDetached( Installation.class, "name ascending, version ascending", null ); + return getAllObjectsDetached( Installation.class, "name ascending", null ); } + public void removeInstallation( Installation installation ) + throws ContinuumStoreException, ContinuumObjectNotFoundException + { + // first delete link beetwen profile and this installation + // then removing this + //attachAndDelete( installation ); + PersistenceManager pm = getPersistenceManager(); + + Transaction tx = pm.currentTransaction(); + + try + { + // this must be done in the same transaction + tx.begin(); + + // first removing linked jdk + + Extent extent = pm.getExtent( Profile.class, true ); + + Query query = pm.newQuery( extent ); + + query.declareImports( "import java.lang.String" ); + + query.declareParameters( "String name" ); + + query.setFilter( "this.jdk.name == name" ); + + Collection result = (Collection) query.execute( installation.getName() ); + + if ( result.size() != 0 ) + { + for ( Iterator iterator = result.iterator(); iterator.hasNext(); ) + { + Profile profile = iterator.next(); + profile.setJdk( null ); + pm.makePersistent( profile ); + } + } + + // removing linked builder + query = pm.newQuery( extent ); + + query.declareImports( "import java.lang.String" ); + + query.declareParameters( "String name" ); + + query.setFilter( "this.builder.name == name" ); + + result = (Collection) query.execute( installation.getName() ); + + if ( result.size() != 0 ) + { + for ( Iterator iterator = result.iterator(); iterator.hasNext(); ) + { + Profile profile = iterator.next(); + profile.setBuilder( null ); + pm.makePersistent( profile ); + } + } + + // removing linked env Var + query = pm.newQuery( extent ); + + query.declareImports( "import java.lang.String" ); + query.declareImports( "import " + Installation.class.getName() ); + + query.declareParameters( "Installation installation" ); + + query.setFilter( "environmentVariables.contains(installation)" ); + + //query = pm + // .newQuery( "SELECT FROM profile WHERE environmentVariables.contains(installation) && installation.name == name" ); + + result = (Collection) query.execute( installation ); + + if ( result.size() != 0 ) + { + for ( Iterator iterator = result.iterator(); iterator.hasNext(); ) + { + Profile profile = iterator.next(); + List newEnvironmentVariables = new ArrayList(); + for ( Iterator iteInstallation = profile.getEnvironmentVariables().iterator(); iteInstallation + .hasNext(); ) + { + Installation current = iteInstallation.next(); + if ( !StringUtils.equals( current.getName(), installation.getName() ) ) + { + newEnvironmentVariables.add( current ); + } + } + profile.setEnvironmentVariables( newEnvironmentVariables ); + pm.makePersistent( profile ); + } + } + + pm.deletePersistent( installation ); + + tx.commit(); + + } + finally + { + rollback( tx ); + } + } + + public void updateInstallation( Installation installation ) + throws ContinuumStoreException, ContinuumObjectNotFoundException + { + updateObject( installation ); + } + + public Installation getInstallationByName( String name ) + throws ContinuumStoreException, ContinuumObjectNotFoundException + { + PersistenceManager pm = getPersistenceManager(); + + Transaction tx = pm.currentTransaction(); + + try + { + tx.begin(); + + Extent extent = pm.getExtent( Installation.class, true ); + + Query query = pm.newQuery( extent ); + + query.declareImports( "import java.lang.String" ); + + query.declareParameters( "String name" ); + + query.setFilter( "this.name == name" ); + + Collection result = (Collection) query.execute( name ); + + if ( result.size() == 0 ) + { + tx.commit(); + + return null; + } + + Object object = pm.detachCopy( result.iterator().next() ); + + tx.commit(); + + return (Installation) object; + } + finally + { + rollback( tx ); + } + } + public List getAllBuildsForAProjectByDate( int projectId ) { PersistenceManager pm = getPersistenceManager(); @@ -933,8 +1141,8 @@ { tx.begin(); - Query query = pm.newQuery( "SELECT FROM " + BuildResult.class.getName() + - " WHERE project.id == projectId PARAMETERS int projectId ORDER BY endTime DESC" ); + Query query = pm.newQuery( "SELECT FROM " + BuildResult.class.getName() + + " WHERE project.id == projectId PARAMETERS int projectId ORDER BY endTime DESC" ); query.declareImports( "import java.lang.Integer" ); @@ -1172,12 +1380,14 @@ } catch ( Exception e ) { - //Do nothing + // Do nothing } if ( pg != null ) { - // TODO: why do we need to do this? if not - build results are not removed and a integrity constraint is violated. I assume its because of the fetch groups + // TODO: why do we need to do this? if not - build results are not + // removed and a integrity constraint is violated. I assume its + // because of the fetch groups for ( Iterator i = pg.getProjects().iterator(); i.hasNext(); ) { removeProject( (Project) i.next() ); @@ -1352,8 +1562,8 @@ } catch ( ContinuumStoreException e ) { - throw new ContinuumObjectNotFoundException( - "unable to find project group containing project with id: " + projectId ); + throw new ContinuumObjectNotFoundException( "unable to find project group containing project with id: " + + projectId ); } } @@ -1381,7 +1591,7 @@ else if ( systemConfs.size() > 1 ) { throw new ContinuumStoreException( - "Database is corrupted. There are more than one systemConfiguration object." ); + "Database is corrupted. There are more than one systemConfiguration object." ); } else { @@ -1411,10 +1621,13 @@ public Collection getAllProjectGroupsWithTheLot() { - List fetchGroups = Arrays.asList( new String[]{PROJECT_WITH_BUILDS_FETCH_GROUP, - PROJECTGROUP_PROJECTS_FETCH_GROUP, BUILD_RESULT_WITH_DETAILS_FETCH_GROUP, - PROJECT_WITH_CHECKOUT_RESULT_FETCH_GROUP, PROJECT_ALL_DETAILS_FETCH_GROUP, - PROJECT_BUILD_DETAILS_FETCH_GROUP} ); + List fetchGroups = Arrays.asList( new String[] { + PROJECT_WITH_BUILDS_FETCH_GROUP, + PROJECTGROUP_PROJECTS_FETCH_GROUP, + BUILD_RESULT_WITH_DETAILS_FETCH_GROUP, + PROJECT_WITH_CHECKOUT_RESULT_FETCH_GROUP, + PROJECT_ALL_DETAILS_FETCH_GROUP, + PROJECT_BUILD_DETAILS_FETCH_GROUP } ); return PlexusJdoUtils.getAllObjectsDetached( getPersistenceManager(), ProjectGroup.class, "name ascending", fetchGroups ); } @@ -1442,8 +1655,9 @@ /** * Close the PersistenceManagerFactory. - * - * @param numTry The number of try. The maximum try is 5. + * + * @param numTry + * The number of try. The maximum try is 5. */ private void closePersistenceManagerFactory( PersistenceManagerFactory pmf, int numTry ) { @@ -1469,7 +1683,7 @@ } catch ( InterruptedException ie ) { - //nothing to do + // nothing to do } closePersistenceManagerFactory( pmf, numTry + 1 );