You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/07/05 12:29:52 UTC

[maven-antrun-plugin] branch master updated: [MANTRUN-228] Add schema for Ant Tasks

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-antrun-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 8e5b3c6  [MANTRUN-228] Add schema for Ant Tasks
8e5b3c6 is described below

commit 8e5b3c613e96c20881347ec16813864a2d8ef0bb
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun Jul 5 14:29:44 2020 +0200

    [MANTRUN-228] Add schema for Ant Tasks
---
 pom.xml                                            |  39 ++++++++
 .../invoker.properties                             |   0
 .../pom.xml                                        |   5 +-
 .../test.txt                                       |   0
 .../verify.bsh                                     |   0
 .../invoker.properties                             |   0
 .../pom.xml                                        |   6 +-
 .../test.txt                                       |   0
 .../verify.bsh                                     |   0
 .../apache/maven/ant/tasks/AttachArtifactTask.java |  68 +++++---------
 .../maven/ant/tasks/DependencyFilesetsTask.java    |  89 ++++++------------
 .../apache/maven/plugins/antrun/AntRunMojo.java    |  53 +++++++++--
 src/main/mdo/antrun.mdo                            | 104 +++++++++++++++++++++
 13 files changed, 245 insertions(+), 119 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6edde36..7076667 100644
--- a/pom.xml
+++ b/pom.xml
@@ -134,5 +134,44 @@ under the License.
         </plugin>
       </plugins>
     </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.modello</groupId>
+        <artifactId>modello-maven-plugin</artifactId>
+        <version>1.10.0</version>
+        <configuration>
+          <models>
+            <model>src/main/mdo/antrun.mdo</model>
+          </models>
+          <version>1.0.0</version>
+        </configuration>
+        <executions>
+          <execution>
+            <id>sources</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>java</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>resources</id>
+            <phase>pre-site</phase>
+            <goals>
+              <goal>xsd</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>target/generated-site/resources/xsd</outputDirectory>
+            </configuration>
+          </execution>
+          <execution>
+            <id>documentation</id>
+            <phase>pre-site</phase>
+            <goals>
+              <goal>xdoc</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
   </build>
 </project>
diff --git a/src/it/attach-artifact-test-with-prefix/invoker.properties b/src/it/attach-artifact-test-with-prefix-antlib/invoker.properties
similarity index 100%
copy from src/it/attach-artifact-test-with-prefix/invoker.properties
copy to src/it/attach-artifact-test-with-prefix-antlib/invoker.properties
diff --git a/src/it/attach-artifact-test-with-prefix/pom.xml b/src/it/attach-artifact-test-with-prefix-antlib/pom.xml
similarity index 90%
copy from src/it/attach-artifact-test-with-prefix/pom.xml
copy to src/it/attach-artifact-test-with-prefix-antlib/pom.xml
index 63f14a4..ebdc2c0 100644
--- a/src/it/attach-artifact-test-with-prefix/pom.xml
+++ b/src/it/attach-artifact-test-with-prefix-antlib/pom.xml
@@ -20,7 +20,7 @@ under the License.
 -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.maven.plugins.antrun</groupId>
   <artifactId>attach-artifact-test-with-prefix</artifactId>
@@ -39,8 +39,7 @@ under the License.
               <goal>run</goal>
             </goals>
             <configuration>
-              <customTaskPrefix>mvn</customTaskPrefix>
-              <target>
+              <target xmlns:mvn="antlib:org.apache.maven.ant.tasks">
                 <mvn:attachartifact file="test.txt" classifier="cl" />
               </target>
             </configuration>
diff --git a/src/it/attach-artifact-test-with-prefix/test.txt b/src/it/attach-artifact-test-with-prefix-antlib/test.txt
similarity index 100%
copy from src/it/attach-artifact-test-with-prefix/test.txt
copy to src/it/attach-artifact-test-with-prefix-antlib/test.txt
diff --git a/src/it/attach-artifact-test-with-prefix/verify.bsh b/src/it/attach-artifact-test-with-prefix-antlib/verify.bsh
similarity index 100%
copy from src/it/attach-artifact-test-with-prefix/verify.bsh
copy to src/it/attach-artifact-test-with-prefix-antlib/verify.bsh
diff --git a/src/it/attach-artifact-test-with-prefix/invoker.properties b/src/it/attach-artifact-test-with-prefix-antrun/invoker.properties
similarity index 100%
rename from src/it/attach-artifact-test-with-prefix/invoker.properties
rename to src/it/attach-artifact-test-with-prefix-antrun/invoker.properties
diff --git a/src/it/attach-artifact-test-with-prefix/pom.xml b/src/it/attach-artifact-test-with-prefix-antrun/pom.xml
similarity index 86%
rename from src/it/attach-artifact-test-with-prefix/pom.xml
rename to src/it/attach-artifact-test-with-prefix-antrun/pom.xml
index 63f14a4..372a038 100644
--- a/src/it/attach-artifact-test-with-prefix/pom.xml
+++ b/src/it/attach-artifact-test-with-prefix-antrun/pom.xml
@@ -20,7 +20,8 @@ under the License.
 -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd
+                      http://maven.apache.org/ANTRUN    https://maven.apache.org/xsd/antrun-1.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.maven.plugins.antrun</groupId>
   <artifactId>attach-artifact-test-with-prefix</artifactId>
@@ -39,8 +40,7 @@ under the License.
               <goal>run</goal>
             </goals>
             <configuration>
-              <customTaskPrefix>mvn</customTaskPrefix>
-              <target>
+              <target xmlns:mvn="http://maven.apache.org/ANTRUN">
                 <mvn:attachartifact file="test.txt" classifier="cl" />
               </target>
             </configuration>
diff --git a/src/it/attach-artifact-test-with-prefix/test.txt b/src/it/attach-artifact-test-with-prefix-antrun/test.txt
similarity index 100%
rename from src/it/attach-artifact-test-with-prefix/test.txt
rename to src/it/attach-artifact-test-with-prefix-antrun/test.txt
diff --git a/src/it/attach-artifact-test-with-prefix/verify.bsh b/src/it/attach-artifact-test-with-prefix-antrun/verify.bsh
similarity index 100%
rename from src/it/attach-artifact-test-with-prefix/verify.bsh
rename to src/it/attach-artifact-test-with-prefix-antrun/verify.bsh
diff --git a/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java b/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java
index f57b21a..8e1f781 100644
--- a/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java
+++ b/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java
@@ -21,6 +21,7 @@ package org.apache.maven.ant.tasks;
 
 import org.apache.maven.plugins.antrun.AntRunMojo;
 import org.apache.maven.plugins.antrun.MavenAntRunProject;
+import org.apache.maven.plugins.antrun.taskconfig.AttachArtifactConfiguration;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.tools.ant.BuildException;
@@ -48,25 +49,12 @@ public class AttachArtifactTask
     @SuppressWarnings( "FieldCanBeLocal" )
     private String mavenProjectHelperRefId = AntRunMojo.DEFAULT_MAVEN_PROJECT_HELPER_REFID;
 
-    /**
-     * The file to attach.
-     */
-    private File file;
-
-    /**
-     * The classifier of the artifact to attach
-     */
-    private String classifier;
+    private AttachArtifactConfiguration configuration = new AttachArtifactConfiguration();
 
-    /**
-     * The type of the artifact to attach.  Defaults to file extension.
-     */
-    private String type;
-
-    /** {@inheritDoc} */
     @Override
     public void execute()
     {
+        File file = configuration.getFile();
         if ( file == null )
         {
             throw new BuildException( "File is a required parameter." );
@@ -82,6 +70,7 @@ public class AttachArtifactTask
             throw new BuildException( "Maven project reference not found: " + mavenProjectRefId );
         }
 
+        String type = configuration.getType();
         if ( type == null )
         {
             type = FileUtils.getExtension( file.getName() );
@@ -95,28 +84,13 @@ public class AttachArtifactTask
             throw new BuildException( "Maven project helper reference not found: " + mavenProjectHelperRefId );
         }
 
+        String classifier = configuration.getClassifier();
         log( "Attaching " + file + " as an attached artifact", Project.MSG_VERBOSE );
         MavenProjectHelper projectHelper = getProject().getReference( mavenProjectHelperRefId );
         projectHelper.attachArtifact( mavenProject, type, classifier, file );
     }
 
     /**
-     * @return {@link #file}
-     */
-    public File getFile()
-    {
-        return file;
-    }
-
-    /**
-     * @param file {@link #file}
-     */
-    public void setFile( File file )
-    {
-        this.file = file;
-    }
-
-    /**
      * @return {@link #mavenProjectRefId}
      */
     public String getMavenProjectRefId()
@@ -132,35 +106,35 @@ public class AttachArtifactTask
         this.mavenProjectRefId = mavenProjectRefId;
     }
 
-    /**
-     * @return {@link #classifier}
-     */
+    /* Fields delegated to AttachArtifactConfiguration */
+    
+    public File getFile()
+    {
+        return this.configuration.getFile();
+    }
+
+    public void setFile( File file )
+    {
+        this.configuration.setFile( file );
+    }
+
     public String getClassifier()
     {
-        return classifier;
+        return this.configuration.getClassifier();
     }
 
-    /**
-     * @param classifier {@link #classifier}
-     */
     public void setClassifier( String classifier )
     {
-        this.classifier = classifier;
+        this.configuration.setClassifier( classifier );
     }
 
-    /**
-     * @return {@link #type}
-     */
     public String getType()
     {
-        return type;
+        return this.configuration.getType();
     }
 
-    /**
-     * @param type {@link #type}
-     */
     public void setType( String type )
     {
-        this.type = type;
+        this.configuration.setType( type );
     }
 }
diff --git a/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java b/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java
index 38849e8..ceb74f6 100644
--- a/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java
+++ b/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java
@@ -25,6 +25,7 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
 import org.apache.maven.plugins.antrun.AntRunMojo;
+import org.apache.maven.plugins.antrun.taskconfig.DependencyFilesetsConfiguration;
 import org.apache.maven.project.MavenProject;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
@@ -43,60 +44,12 @@ import java.util.Set;
 public class DependencyFilesetsTask
     extends Task
 {
-
-    /**
-     * The default project dependencies id.
-     */
-    public static final String DEFAULT_PROJECT_DEPENDENCIES_ID = "maven.project.dependencies";
-
     /**
      * The project ref Id of the project being used.
      */
     private String mavenProjectId = AntRunMojo.DEFAULT_MAVEN_PROJECT_REFID;
 
-    /**
-     * The id to store the dependencies fileset.
-     */
-    private String projectDependenciesId = DEFAULT_PROJECT_DEPENDENCIES_ID;
-
-    /**
-     * @return {@link #projectDependenciesId}
-     */
-    public String getProjectDependenciesId()
-    {
-        return projectDependenciesId;
-    }
-
-    /**
-     * @param projectDependenciesId {@link #projectDependenciesId}
-     */
-    public void setProjectDependenciesId( String projectDependenciesId )
-    {
-        this.projectDependenciesId = projectDependenciesId;
-    }
-
-    /**
-     * The string to prepend to all dependency filesets.
-     */
-    private String prefix = "";
-
-    /**
-     * A comma separated list of artifact types to include.
-     */
-    private String types = "";
-
-    /**
-     * A comma separated list of dependency scopes to include.
-     */
-    private String scopes = "";
-
-    /**
-     * Create instance.
-     */
-    public DependencyFilesetsTask()
-    {
-
-    }
+    private DependencyFilesetsConfiguration configuration = new DependencyFilesetsConfiguration();
 
     /** {@inheritDoc} */
     @Override
@@ -138,7 +91,7 @@ public class DependencyFilesetsTask
             getProject().addReference( fileSetName, singleArtifactFileSet );
         }
 
-        getProject().addReference( ( getPrefix() + projectDependenciesId ), dependenciesFileSet );
+        getProject().addReference( ( getPrefix() + getProjectDependenciesId() ), dependenciesFileSet );
     }
 
     /**
@@ -162,6 +115,7 @@ public class DependencyFilesetsTask
      */
     public String getPrefix()
     {
+        String prefix = configuration.getPrefix();
         if ( prefix == null )
         {
             prefix = "";
@@ -175,7 +129,7 @@ public class DependencyFilesetsTask
      */
     public void setPrefix( String prefix )
     {
-        this.prefix = prefix;
+        this.configuration.setPrefix( prefix );
     }
 
     /**
@@ -183,7 +137,7 @@ public class DependencyFilesetsTask
      */
     public String getTypes()
     {
-        return types;
+        return this.configuration.getTypes();
     }
 
     /**
@@ -191,7 +145,7 @@ public class DependencyFilesetsTask
      */
     public void setTypes( String types )
     {
-        this.types = types;
+        this.configuration.setTypes( types );
     }
 
     /**
@@ -199,7 +153,7 @@ public class DependencyFilesetsTask
      */
     public String getScopes()
     {
-        return scopes;
+        return this.configuration.getScopes();
     }
 
     /**
@@ -207,7 +161,23 @@ public class DependencyFilesetsTask
      */
     public void setScopes( String scopes )
     {
-        this.scopes = scopes;
+        this.configuration.setScopes( scopes );
+    }
+
+    /**
+     * @return {@link #projectDependenciesId}
+     */
+    public String getProjectDependenciesId()
+    {
+        return this.configuration.getProjectDependenciesId();
+    }
+
+    /**
+     * @param projectDependenciesId {@link #projectDependenciesId}
+     */
+    public void setProjectDependenciesId( String projectDependenciesId )
+    {
+        this.configuration.setProjectDependenciesId( projectDependenciesId );
     }
 
     /**
@@ -218,26 +188,29 @@ public class DependencyFilesetsTask
      */
     public Set<Artifact> filterArtifacts( Set<Artifact> artifacts )
     {
+        String scopes = getScopes();
         if ( scopes == null )
         {
             scopes = "";
         }
+        
+        String types = getTypes();
         if ( types == null )
         {
             types = "";
         }
 
-        if ( scopes.equals( "" ) && types.equals( "" ) )
+        if ( "".equals( scopes ) && "".equals( types ) )
         {
             return artifacts;
         }
 
         AndArtifactFilter filter = new AndArtifactFilter();
-        if ( !scopes.equals( "" ) )
+        if ( !"".equals( scopes ) )
         {
             filter.add( new SpecificScopesArtifactFilter( getScopes() ) );
         }
-        if ( !types.equals( "" ) )
+        if ( !"".equals( types ) )
         {
             filter.add( new TypesArtifactFilter( getTypes() ) );
         }
diff --git a/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java b/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
index 84dc79b..a0f0892 100644
--- a/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
+++ b/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
@@ -153,14 +153,24 @@ public class AntRunMojo
     private String propertyPrefix;
 
     /**
-     * The xml tag prefix to use for the built in Ant tasks. This prefix needs to be prepended to each task referenced
-     * in the antrun target config. For example, a prefix of "mvn" means that the attachartifact task is referenced by
-     * "&lt;mvn:attachartifact&gt;" The default value of an empty string means that no prefix is used for the tasks.
-     *
+     * Maven will look in the target-tag for the namespace of <code>http://maven.apache.org/ANTRUN</code>
+     * or <code>antlib:org.apache.maven.ant.tasks</code>
+     * 
+     * <pre>
+     *   &lt;configuration&gt;
+     *     &lt;target xmlns:mvn="http://maven.apache.org/ANTRUN"&gt;
+     *       &lt;mvn:attachartifact/&gt;
+     *       &lt;mvn:dependencyfilesets/&gt;
+     *     &lt;/target&gt;
+     *   &lt;/configuration&gt;
+     * </pre>
+     * 
+     * @deprecated only here for backwards compatibility 
      * @since 1.5
      */
-    @Parameter( defaultValue = "" )
-    private String customTaskPrefix = "";
+    @Deprecated
+    @Parameter
+    private String customTaskPrefix;
 
     /**
      * The name of a property containing the list of all dependency versions. This is used for the removing the versions
@@ -514,7 +524,8 @@ public class AntRunMojo
         Typedef typedef = new Typedef();
         typedef.setProject( antProject );
         typedef.setResource( ANTLIB );
-        if ( !customTaskPrefix.isEmpty() )
+        
+        if ( getTaskPrefix() != null )
         {
             typedef.setURI( TASK_URI );
         }
@@ -535,11 +546,37 @@ public class AntRunMojo
         buildFile.getParentFile().mkdirs();
 
         AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();
-        xmlWriter.write( target, buildFile, customTaskPrefix, targetName );
+
+        String taskPrefix = getTaskPrefix();
+        if ( taskPrefix != null )
+        {
+            // replace namespace as Ant expects it to be
+            target.setAttribute( "xmlns:" + taskPrefix, TASK_URI );    
+        }
+
+        xmlWriter.write( target, buildFile, "", targetName );
 
         return buildFile;
     }
 
+    private String getTaskPrefix()
+    {
+        String taskPrefix = this.customTaskPrefix;
+        if ( taskPrefix == null )
+        {
+            for ( String name : target.getAttributeNames() )
+            {
+                if ( name.startsWith( "xmlns:" ) 
+                        && "http://maven.apache.org/ANTRUN".equals( target.getAttribute( name ) ) )
+                {
+                    taskPrefix = name.substring( "xmlns:".length() );
+                    break;
+                }
+            }
+        }
+        return taskPrefix;
+    }
+
     /**
      * @param buildException not null
      * @return the fragment XML part where the buildException occurs.
diff --git a/src/main/mdo/antrun.mdo b/src/main/mdo/antrun.mdo
new file mode 100644
index 0000000..4eb29c9
--- /dev/null
+++ b/src/main/mdo/antrun.mdo
@@ -0,0 +1,104 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<model xmlns="http://codehaus-plexus.github.io/MODELLO/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://codehaus-plexus.github.io/MODELLO/1.8.0 https://codehaus-plexus.github.io/modello/xsd/modello-1.8.0.xsd"
+  xml.namespace="http://maven.apache.org/ANTRUN"
+  xml.schemaLocation="https://maven.apache.org/xsd/antrun-${version}.xsd">
+  <id>antrun</id>
+  <name>AntRun</name>
+  
+  <defaults>
+    <default>
+      <key>package</key>
+      <value>org.apache.maven.plugins.antrun.taskconfig</value>
+    </default>
+  </defaults>
+
+  <classes>
+    <class rootElement="true" xml.tagName="attachartifact">
+      <name>AttachArtifactConfiguration</name>
+      <fields>
+        <!-- just a placeholder to generate proper XSD -->
+        <field java.getter="false" java.setter="false" xml.attribute="true" xml.tagName="file">
+          <name>_file_placeholder</name>
+          <type>String</type>
+          <required>true</required>
+          <description>The file to attach to the project</description>
+        </field>
+        <field xml.attribute="true">
+          <name>classifier</name>
+          <type>String</type>
+          <description>A classifier assigned to the artifact</description>
+        </field>
+        <field xml.attribute="true">
+          <name>type</name>
+          <type>String</type>
+          <description>The type of the artifact, zip, war, etc</description>
+        </field>
+      </fields>
+      <codeSegments>
+        <codeSegment>
+        <code><![CDATA[
+        private java.io.File file;
+        
+        public java.io.File getFile()
+        {
+          return this.file;
+        }
+        
+        public void setFile( java.io.File file )
+        {
+          this.file = file;        
+        }
+        ]]></code>
+        </codeSegment>
+      </codeSegments>
+    </class>
+    
+    <class rootElement="true" xml.tagName="dependencyfilesets">
+      <name>DependencyFilesetsConfiguration</name>
+      <fields>
+        <field xml.attribute="true">
+          <name>prefix</name>
+          <type>String</type>
+          <description>String to prepend to all fileset IDs</description>
+        </field>
+        <field xml.attribute="true">
+          <name>projectDependenciesId</name>
+          <type>String</type>
+          <defaultValue>maven.project.dependencies</defaultValue>
+          <description>RefId for the fileset containing all project dependencies</description>
+        </field>
+        <field xml.attribute="true">
+          <name>scopes</name>
+          <type>String</type>
+          <description>Comma separated list of artifact scopes to include</description>
+        </field>
+        <field xml.attribute="true">
+          <name>types</name>
+          <type>String</type>
+          <description>Comma separated list of artifact types to include</description>
+        </field>
+      </fields>
+    </class>
+  </classes>  
+</model>
\ No newline at end of file