View Javadoc

1   package org.codehaus.mojo.wagon;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.io.IOException;
19  
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.wagon.ConnectionException;
22  import org.apache.maven.wagon.Wagon;
23  import org.apache.maven.wagon.WagonException;
24  
25  /**
26   * Provides base functionality for dealing with I/O using single wagon.
27   *
28   */
29  public abstract class AbstractSingleWagonMojo extends AbstractWagonMojo {
30  
31      /**
32       * URL to upload to or download from or list. Must exist and point to a directory.
33       *
34       * @parameter expression="${wagon.url}"
35       * @required
36       */
37      private String url;
38  
39      /**
40       * settings.xml's server id for the URL. This is used when wagon needs extra authentication information.
41       *
42       * @parameter expression="${wagon.serverId}" default-value="serverId";
43       */
44      private String serverId;
45  
46      @Override
47      public void execute() throws MojoExecutionException {
48          if (this.skip) {
49              this.getLog().info("Skip execution.");
50              return;
51          }
52  
53          Wagon wagon = null;
54          try {
55              wagon = createWagon(serverId, url);
56              execute(wagon);
57          } catch (WagonException e) {
58              throw new MojoExecutionException("Error handling resource", e);
59          } catch (IOException e) {
60              throw new MojoExecutionException("Error handling resource", e);
61          } finally {
62              disconnectQuietly(wagon);
63          }
64      }
65  
66      protected void disconnectQuietly(Wagon wagon) {
67          if (wagon == null) {
68              return;
69          }
70          try {
71              wagon.disconnect();
72          } catch (ConnectionException e) {
73              getLog().debug("Error disconnecting wagon - ignored", e);
74          }
75      }
76  
77      /**
78       * Perform the necessary action. To be implemented in the child mojo.
79       *
80       * @param wagon
81       * @throws MojoExecutionException
82       * @throws WagonException
83       */
84      protected abstract void execute(Wagon wagon) throws MojoExecutionException, WagonException, IOException;
85  
86  }