All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openscm.kundo.strategy.MavenModuleStrategy.groovy Maven / Gradle / Ivy

The newest version!
package org.openscm.kundo.strategy

/*
 * Copyright (C) 2008 The Ultimate People Company Ltd ("UPCO").
 *
 * Licensed 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.openscm.kundo.plugins.Module
import groovy.util.slurpersupport.GPathResult

/**
 * Maven Module Strategy
 * @author Nigel Garner
 * @version 1.0.0
 * 
 * Description: The Maven Module Strategy loads a list of modules based based on a maven pom file. 
 * 
 * 

Despite its afinity to Maven, the pom file is a very good metadata store that is a handy means of capturing * much more than just dependencies. One good example of this is profiled or project level sub modules of the build.

* *

The Maven Module Strategy creates a list of modules based on the maven pom file. The pom file is identified * from the 'pom.location' property in the BuildContext. Any project level modules will be loaded by default with * any profiled modules being dependent on the passed profile list.

*/ /* * @ant-target doReactor */ public class MavenModuleStrategy extends ModuleStrategy { /** * Constructor passes the ant instance in a call to super * @param ant AntBuilder instance */ MavenModuleStrategy( ant ) { super( ant ) } /** * Concrete implementation of the ModuleStrategy.loadModules() method * * Loads a list of modules based upon the projects Maven pom file. The pom file is obtained through the 'pom.location' * property in the BuildContext. The path to the pom should be either full or relative to the project directory. */ void loadModules( buildContext, childBuildFile, childTarget , inheritConfiguration, profiles ) { // if( childTarget.equals("install") && isDeployEnabled( defaultTarget ) ){ // log.info( message:'Ignoring reactor install target - this will be executed via deploy target dependency.') // return; // } // Slurp the pom file. The Factory should not be creating a MavenModuleStrategy if the pom file doesn't exist. def pom = buildContext.get( "pom.location" ) def project = slurpPom( pom ) // Closure to build a module from the project module element def addModule = { m -> log.debug( "Creating module with params $m" ) def Module module = new Module() module.name = m.text() module.buildFile = childBuildFile module.dir = m.text() module.target = childTarget module.inheritConfiguration = inheritConfiguration modules.add(module) } // Check for any top level modules and process accordingly project.modules.module.each{ m -> addModule( m ) } // For each of the profiles in the passed list.. profiles.each { pf-> // Find the matching profile inside the project def pfile = project.profiles.profile.find{ it.id.text().equals( pf ) } log.debug( "Identified profiles $pfile to load modules from." ) // Check that something was found if(pfile != null) { // For each of the modules inside that profile pfile.modules.module.each{ m-> // Add to the profile list. addModule( m ) } } } } /** * Slurps the project pom file to make it easily readable. * @param pomFile The location of the project pom. * @return GPathResult A slurped groovy representation of the pom file. */ def GPathResult slurpPom( pomFile ) { File pom = new File( pomFile ) return new XmlSlurper().parse( pom ) } /** * Checks to see if deploy is enabled as to whether processing should occur later. * @parm defaultTarget Target to be executed * @return boolean true if deploy is enabled. */ def boolean isDeployEnabled( defaultTarget ){ return defaultTarget.equals( "deploy" ) } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy