View Javadoc
1   package org.apache.maven.resolver.internal.ant.tasks;
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 org.apache.maven.resolver.internal.ant.AntRepoSys;
23  import org.apache.maven.resolver.internal.ant.types.RemoteRepository;
24  import org.apache.tools.ant.BuildException;
25  import org.apache.tools.ant.types.Reference;
26  
27  /**
28   */
29  public class Deploy
30      extends AbstractDistTask
31  {
32  
33      private RemoteRepository repository;
34  
35      private RemoteRepository snapshotRepository;
36  
37      @Override
38      protected void validate()
39      {
40          super.validate();
41  
42          if ( repository == null )
43          {
44              throw new BuildException( "You must specify the <remoteRepo id=\"...\" url=\"...\"> element"
45                  + " to denote the target repository for the deployment" );
46          }
47          else
48          {
49              repository.validate( this );
50          }
51          if ( snapshotRepository != null )
52          {
53              snapshotRepository.validate( this );
54          }
55      }
56  
57      public void addRemoteRepo( RemoteRepository repository )
58      {
59          if ( this.repository != null )
60          {
61              throw new BuildException( "You must not specify multiple <remoteRepo> elements" );
62          }
63          this.repository = repository;
64      }
65  
66      public void setRemoteRepoRef( Reference ref )
67      {
68          if ( repository == null )
69          {
70              repository = new RemoteRepository();
71              repository.setProject( getProject() );
72          }
73          repository.setRefid( ref );
74      }
75  
76      public void addSnapshotRepo( RemoteRepository snapshotRepository )
77      {
78          if ( this.snapshotRepository != null )
79          {
80              throw new BuildException( "You must not specify multiple <snapshotRepo> elements" );
81          }
82          this.snapshotRepository = snapshotRepository;
83      }
84  
85      public void setSnapshotRepoRef( Reference ref )
86      {
87          if ( snapshotRepository == null )
88          {
89              snapshotRepository = new RemoteRepository();
90              snapshotRepository.setProject( getProject() );
91          }
92          snapshotRepository.setRefid( ref );
93      }
94  
95      @Override
96      public void execute()
97          throws BuildException
98      {
99          validate();
100 
101         AntRepoSys.getInstance( getProject() ).deploy( this, getPom(), getArtifacts(), repository, snapshotRepository );
102     }
103 
104 }