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

org.openscm.kundo.plugins.AbstractDependenciesDelegate.groovy Maven / Gradle / Ivy

package org.openscm.kundo.plugins

/*
 * 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 groovy.xml.NamespaceBuilder
import org.openscm.kundo.plugins.context.BuildContext
import org.openscm.kundo.common.logging.SimpleLogger
import org.apache.tools.ant.*

 /**
 * Abstract Load Dependencies Delegate
 * @author Ben Leedham
 * @version 1.0.0
 * 
 * Description: Sets up common dependency management elements for use by sevveral delegates
 * 
 */
/* 
 * @ant-target 
 */
abstract class AbstractDependenciesDelegate extends AbstractPluginTargetDelegate {
	
	protected static final  SUPPORTED_SCOPES = ["compile", "runtime" , "test", "provided"]
	protected def mvn
	
	/*
	 * The location of the project's pom file
	 * @ant-property-name project.pom.location
	 */
	protected String pomLocation
	
	/**
	 * Constructor
	 * @param ant			AntBuilder instance
	 * @param buildContext	BuildContext instance
	 */
	AbstractDependenciesDelegate( AntBuilder ant, BuildContext buildContext ){
		super( ant, buildContext)
		this.mvn = NamespaceBuilder.newInstance( ant, 'antlib:org.apache.maven.artifact.ant' )
	}
	

	/**
	 * Implementation of abstract method from AbstractPluginTargetDelegate
	 * to hold assertions that all global and local properties are available to the plugin.
	 * This method is automatically called prior to execution.
	 */
	void doCheck(){
		
		assert buildContext.get( "pom.location" ) != null
		assert buildContext.get( "pom.location" ) != ""
		
		def pomLocation = buildContext.get( "pom.location" )
		File pomFile = new File ( pomLocation )
		assert pomFile.exists()
		
	}
	
	void installDeploy( String artifactLocation, String pomLocation, String installDeploy ){
		
		if( artifactLocation == null || artifactLocation == "" ){
			File pomFile = new File( pomLocation )
			mvn."$installDeploy"() {
					pom ( file : pomLocation )
			}
 	 	} else {
			File pomFile = new File( pomLocation )
			File artifact = new File( artifactLocation )
			if( pomFile.exists() && artifact.exists() ){
				mvn."$installDeploy"( file : artifactLocation ){
					mvn.pom( file : pomLocation )
				}
			}else{
				throw new BuildException( "pom file does not exist at this location: $pomLocation or artifact does not exist at this location: $artifactLocation" )
			}
		}
	}
	
	/**
	 * Concrete implementation of the AbstractPluginTargetDelegate.execute() method
	 */
	abstract void doExecute()	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy