Commit 17594dc5 authored by Brian Long's avatar Brian Long
Browse files

added publish-app goal

parent adb43d46
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
package com.inteligr8.maven.aps.modeling.goal;

import java.io.IOException;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.component.annotations.Component;

import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
import com.inteligr8.alfresco.activiti.model.AppDefinitionPublishRepresentation;

@Mojo( name = "publish-app", threadSafe = true )
@Component( role = org.apache.maven.plugin.Mojo.class )
public class PublishAppGoal extends ApsAppAccessibleGoal {

	@Parameter( property = "aps-model.publish.comment", required = true, defaultValue = "Automated by 'aps-model-maven-plugin'" )
	protected String comment;
	
	@Override
	public void executeEnabled() throws MojoExecutionException, MojoFailureException {
		Long appId = this.findAppId(false);
		
		try {
			this.publishApp(appId);
		} catch (IOException ie) {
			throw new MojoExecutionException("The APS App could not be published", ie);
		}
	}
	
	private void publishApp(Long appId) throws IOException, MojoExecutionException {
		ApsPublicRestApiJerseyImpl api = this.getApsApi();
		
		AppDefinitionPublishRepresentation appDefPublish = new AppDefinitionPublishRepresentation();
		appDefPublish.setComment(this.comment);
		api.getAppDefinitionsApi().publish(appId, appDefPublish);
	}

}