1   /*
2    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3    *
4    * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
5    *
6    * Oracle licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a 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
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   *
18   * 
19   * This file incorporates work covered by the following copyright and
20   * permission notice:
21   *
22   * Copyright 2006 Guillaume Nodet
23   *
24   * Licensed under the Apache License, Version 2.0 (the "License");
25   * you may not use this file except in compliance with the License.
26   * You may obtain a copy of the License at
27   *
28   *      http://www.apache.org/licenses/LICENSE-2.0
29   *
30   * Unless required by applicable law or agreed to in writing, software
31   * distributed under the License is distributed on an "AS IS" BASIS,
32   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33   * See the License for the specific language governing permissions and
34   * limitations under the License.
35   */
36  
37  package org.codehaus.mojo.jaxws;
38  
39  import java.io.File;
40  import java.util.List;
41  import java.util.stream.Collectors;
42  
43  import org.apache.maven.artifact.Artifact;
44  import org.apache.maven.plugins.annotations.LifecyclePhase;
45  import org.apache.maven.plugins.annotations.Mojo;
46  import org.apache.maven.plugins.annotations.Parameter;
47  import org.apache.maven.plugins.annotations.ResolutionScope;
48  
49  /**
50   * Parses wsdl and binding files and generates Java code needed to access it.
51   *
52   * @author Kohsuke Kawaguchi
53   */
54  @Mojo( name = "wsimport", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
55          requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
56  public class MainWsImportMojo
57      extends WsImportMojo
58  {
59  
60      /**
61       * Specify where to place output generated classes. Use <code>xnocompile</code>
62       * to turn this off.
63       */
64      @Parameter( defaultValue = "${project.build.outputDirectory}" )
65      private File destDir;
66  
67      /**
68       * Specify where to place generated source files, keep is turned on with this option.
69       */
70      @Parameter( defaultValue = "${project.build.directory}/generated-sources/wsimport" )
71      private File sourceDestDir;
72  
73      /**
74       * Specify where to generate JWS implementation file.
75       */
76      @Parameter( defaultValue = "${project.build.sourceDirectory}" )
77      private File implDestDir;
78  
79      /**
80       * Either ${build.outputDirectory} or ${build.testOutputDirectory}.
81       */
82      @Override
83      protected File getDestDir()
84      {
85          return destDir;
86      }
87  
88      @Override
89      protected File getSourceDestDir()
90      {
91          return sourceDestDir;
92      }
93  
94      @Override
95      protected File getDefaultSrcOut()
96      {
97          return new File( project.getBuild().getDirectory(), "generated-sources/wsimport" );
98      }
99  
100     @Override
101     protected File getImplDestDir()
102     {
103         return implDestDir;
104     }
105 
106     @Override
107     protected List<String> getWSDLFileLookupClasspathElements()
108     {
109         return project.getDependencyArtifacts().stream()
110                 .filter( a -> (Artifact.SCOPE_COMPILE.equals( a.getScope() )
111                         || Artifact.SCOPE_PROVIDED.equals( a.getScope() )
112                         || Artifact.SCOPE_SYSTEM.equals( a.getScope()) )
113                         && null != a.getFile() )
114                 .map( a -> a.getFile().getPath() ).collect( Collectors.toList() );
115     }
116 }