1 | package org.apache.maven.continuum.core.action; |
2 | |
3 | /* |
4 | * Licensed to the Apache Software Foundation (ASF) under one |
5 | * or more contributor license agreements. See the NOTICE file |
6 | * distributed with this work for additional information |
7 | * regarding copyright ownership. The ASF licenses this file |
8 | * to you under the Apache License, Version 2.0 (the |
9 | * "License"); you may not use this file except in compliance |
10 | * with the License. You may obtain a copy of the License at |
11 | * |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | * |
14 | * Unless required by applicable law or agreed to in writing, |
15 | * software distributed under the License is distributed on an |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
17 | * KIND, either express or implied. See the License for the |
18 | * specific language governing permissions and limitations |
19 | * under the License. |
20 | */ |
21 | |
22 | import java.io.File; |
23 | import java.util.List; |
24 | import java.util.Map; |
25 | |
26 | import org.apache.continuum.model.repository.LocalRepository; |
27 | import org.apache.maven.artifact.Artifact; |
28 | import org.apache.maven.artifact.deployer.ArtifactDeployer; |
29 | import org.apache.maven.artifact.repository.ArtifactRepository; |
30 | import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; |
31 | import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; |
32 | import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; |
33 | import org.apache.maven.continuum.configuration.ConfigurationService; |
34 | import org.apache.maven.continuum.execution.ContinuumBuildExecutor; |
35 | import org.apache.maven.continuum.execution.manager.BuildExecutorManager; |
36 | import org.apache.maven.continuum.execution.maven.m2.MavenBuilderHelper; |
37 | import org.apache.maven.continuum.model.project.BuildDefinition; |
38 | import org.apache.maven.continuum.model.project.Project; |
39 | import org.apache.maven.continuum.project.ContinuumProjectState; |
40 | import org.apache.maven.continuum.utils.WorkingDirectoryService; |
41 | |
42 | /** |
43 | * @author <a href="mailto:brett@apache.org">Brett Porter</a> |
44 | * @version $Id: DeployArtifactContinuumAction.java 771177 2009-05-04 05:02:26Z evenisse $ |
45 | * @plexus.component role="org.codehaus.plexus.action.Action" |
46 | * role-hint="deploy-artifact" |
47 | */ |
48 | public class DeployArtifactContinuumAction |
49 | extends AbstractContinuumAction |
50 | { |
51 | /** |
52 | * @plexus.requirement |
53 | */ |
54 | private ConfigurationService configurationService; |
55 | |
56 | /** |
57 | * @plexus.requirement |
58 | */ |
59 | private BuildExecutorManager buildExecutorManager; |
60 | |
61 | /** |
62 | * @plexus.requirement |
63 | */ |
64 | private WorkingDirectoryService workingDirectoryService; |
65 | |
66 | /** |
67 | * @plexus.requirement |
68 | */ |
69 | private ArtifactDeployer artifactDeployer; |
70 | |
71 | /** |
72 | * @plexus.requirement |
73 | */ |
74 | private MavenBuilderHelper builderHelper; |
75 | |
76 | /** |
77 | * @plexus.requirement |
78 | */ |
79 | private ArtifactRepositoryFactory artifactRepositoryFactory; |
80 | |
81 | public void execute( Map context ) |
82 | throws Exception |
83 | { |
84 | // ---------------------------------------------------------------------- |
85 | // Get parameters from the context |
86 | // ---------------------------------------------------------------------- |
87 | |
88 | File deploymentRepositoryDirectory = configurationService.getDeploymentRepositoryDirectory(); |
89 | |
90 | if ( deploymentRepositoryDirectory != null ) |
91 | { |
92 | |
93 | Project project = getProject( context ); |
94 | |
95 | ContinuumBuildExecutor buildExecutor = buildExecutorManager.getBuildExecutor( project.getExecutorId() ); |
96 | |
97 | // ---------------------------------------------------------------------- |
98 | // This is really a precondition for this action to execute |
99 | // ---------------------------------------------------------------------- |
100 | |
101 | if ( project.getState() == ContinuumProjectState.OK ) |
102 | { |
103 | BuildDefinition buildDefinition = getBuildDefinition( context ); |
104 | |
105 | List<Artifact> artifacts = buildExecutor.getDeployableArtifacts( project, |
106 | workingDirectoryService.getWorkingDirectory( |
107 | project ), buildDefinition ); |
108 | |
109 | LocalRepository repository = project.getProjectGroup().getLocalRepository(); |
110 | |
111 | builderHelper.setLocalRepository( repository ); |
112 | |
113 | ArtifactRepository localRepository = builderHelper.getLocalRepository(); |
114 | |
115 | for ( Artifact artifact : artifacts ) |
116 | { |
117 | ArtifactRepositoryLayout repositoryLayout = new DefaultRepositoryLayout(); |
118 | |
119 | if ( !deploymentRepositoryDirectory.exists() ) |
120 | { |
121 | deploymentRepositoryDirectory.mkdirs(); |
122 | } |
123 | |
124 | String location = deploymentRepositoryDirectory.toURL().toExternalForm(); |
125 | |
126 | ArtifactRepository deploymentRepository = |
127 | artifactRepositoryFactory.createDeploymentArtifactRepository( "deployment-repository", location, |
128 | repositoryLayout, true ); |
129 | |
130 | artifactDeployer.deploy( artifact.getFile(), artifact, deploymentRepository, localRepository ); |
131 | } |
132 | } |
133 | } |
134 | } |
135 | } |