commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1505711 - in /commons/dev/plugins/commonsdev-example-plugin: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/commons/ src/main/java/org/apache/commons/dev_plugins/ src/main/java/org/ap...
Date Mon, 22 Jul 2013 15:12:17 GMT
Author: sebb
Date: Mon Jul 22 15:12:16 2013
New Revision: 1505711

URL: http://svn.apache.org/r1505711
Log:
Add example developer plugin

Added:
    commons/dev/plugins/commonsdev-example-plugin/pom.xml   (with props)
    commons/dev/plugins/commonsdev-example-plugin/src/
    commons/dev/plugins/commonsdev-example-plugin/src/main/
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/ExampleMojo.java
  (with props)
    commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/HelpMojo.java
  (with props)
    commons/dev/plugins/commonsdev-example-plugin/src/test/
    commons/dev/plugins/commonsdev-example-plugin/src/test/java/

Added: commons/dev/plugins/commonsdev-example-plugin/pom.xml
URL: http://svn.apache.org/viewvc/commons/dev/plugins/commonsdev-example-plugin/pom.xml?rev=1505711&view=auto
==============================================================================
--- commons/dev/plugins/commonsdev-example-plugin/pom.xml (added)
+++ commons/dev/plugins/commonsdev-example-plugin/pom.xml Mon Jul 22 15:12:16 2013
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-parent</artifactId>
+      <version>32</version>
+  </parent>
+ 
+  <groupId>org.apache.commons.dev_plugins</groupId>
+  <artifactId>commonsdev-example-plugin</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Apache Commons Developer Example Maven Mojo</name>
+  <packaging>maven-plugin</packaging>
+  <inceptionYear>2013</inceptionYear>
+
+  <description>
+  This Apache Commons Developer Example plugin for Maven is just an example
+  </description>
+
+  <distributionManagement>
+    <repository>
+      <!-- Must use the same name, i.e. apache.releases.https  -->
+      <id>apache.releases.https</id>
+      <name>Apache Release Distribution Repository</name>
+      <!-- We override the default release repo to ensure there are no accidental deployments
 -->
+      <url>${commons.dev.plugins.repo}</url>
+      <!-- c.f. distMgmtSnapshotsUrl -->
+    </repository>
+  </distributionManagement>
+
+ <!-- Is this section needed? -->
+  <scm>
+             <connection>scm:svn:http://svn.apache.org/repos/asf/commons/dev/plugins/commons-example-plugin/trunk/</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/commons/dev/plugins/commons-example-plugin/trunk/</developerConnection>
+                                <url>http://svn.apache.org/viewvc/commons/dev/plugins/commons-example-plugin/trunk/</url>
+  </scm>
+
+  <prerequisites>
+    <maven>${mavenVersion}</maven>
+  </prerequisites>
+
+   <properties>
+    <mavenVersion>2.2.1</mavenVersion>
+    <mavenPluginPluginVersion>3.2</mavenPluginPluginVersion>
+    <maven.compiler.source>1.5</maven.compiler.source>
+    <maven.compiler.target>1.5</maven.compiler.target>
+    <!-- Avoid problems with jar & osgi builds in CP -->
+    <commons.manifestfile />
+  </properties>
+
+  <dependencies>
+
+    <!-- Needed by AbstractExecMojo for command execution etc. -->
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>3.0.7</version>
+    </dependency>
+    <!-- needed to fetch login credentials from settings.xml -->
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-9</version>
+      <scope>provided</scope>
+    </dependency>
+    <!-- needed to decode login credentials from settings.xml -->
+    <dependency>
+      <groupId>org.sonatype.plexus</groupId>
+      <artifactId>plexus-sec-dispatcher</artifactId>
+      <version>1.4</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Following dependencies are for building/running Mojos -->
+
+    <!-- for our own help Mojo -->
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-help-plugin</artifactId>
+      <version>2.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>${mavenVersion}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-container-default</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+      <version>${mavenPluginPluginVersion}</version>
+      <!-- annotations are not needed for plugin execution so you can remove this dependency
+           for execution with using provided scope -->
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-plugin-plugin</artifactId>
+          <version>${mavenPluginPluginVersion}</version>
+          <configuration>
+            <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <configuration>
+          <!-- see http://jira.codehaus.org/browse/MNG-5346 -->
+          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+        </configuration>
+        <executions>
+          <execution>
+            <id>generate-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <!-- The generated Mojo does not handle annotations properly,
+               and does not show any "User property" names.
+               Since this is misleading, it is better to drop the goal
+               The Maven Help plugin does show property names, so we create
+               our own Help Mojo that extends it.
+          <execution>
+            <id>generated-helpmojo</id>
+            <goals>
+              <goal>helpmojo</goal>
+            </goals>
+          </execution>
+           -->
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+</project>

Propchange: commons/dev/plugins/commonsdev-example-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/ExampleMojo.java
URL: http://svn.apache.org/viewvc/commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/ExampleMojo.java?rev=1505711&view=auto
==============================================================================
--- commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/ExampleMojo.java
(added)
+++ commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/ExampleMojo.java
Mon Jul 22 15:12:16 2013
@@ -0,0 +1,116 @@
+/*
+ * 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.
+ * 
+ */
+
+package org.apache.commons.dev_plugins.example;
+
+import java.util.Properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
+
+/**
+ * Example MOJO that displays some information from settings and project.
+ */
+@Mojo (name = "example")
+public class ExampleMojo  extends AbstractMojo  implements Contextualizable {
+
+    private static final String[] EXPECTED_PROPERTIES = {
+        "maven.compiler.source",
+        "maven.compiler.target",
+        };
+    
+    private static final String[] UNEXPECTED_PROPERTIES = {
+        "maven.compile.source",
+        "maven.compile.target",
+        };
+
+    @Component
+    private MavenProject project;
+
+    @Component
+    private Settings settings;
+
+    // @Component does not work for the container
+    private PlexusContainer container;
+
+    /**
+     * Whether to decode the passwords and passPhrases found in settings.xml
+     */
+    @Parameter( property="example.decodePassword", defaultValue="false")
+    private boolean decodePassword;
+
+    // Canonical way to get the container
+    public void contextualize( Context context ) throws ContextException {  
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        System.out.println("Id: " + project.getId());
+        System.out.println("Parent: " + project.getParent().getId());
+        final Properties properties = project.getProperties();
+        for(String prop : EXPECTED_PROPERTIES) {
+            final String property = properties.getProperty(prop);
+            System.out.println(prop + ": " + (property == null ? "*MISSING*" : property));
           
+        }
+        for(String prop : UNEXPECTED_PROPERTIES) {
+            final String property = properties.getProperty(prop);
+            if (property != null) {
+                System.out.println("Unexpected: "+ prop + ": " + property);            
+            }
+        }
+        System.out.println("Servers:");
+        for (Server server :settings.getServers()) {
+            final String encryptedPassphrase = server.getPassphrase();
+            final String encryptedString;
+            if (encryptedPassphrase != null) {
+                encryptedString = encryptedPassphrase;
+            } else {
+                encryptedString=server.getPassword();
+            }
+            String pass = "";
+            if (encryptedString != null) {
+                if (decodePassword) {
+                    try {
+                        final SecDispatcher sd = (SecDispatcher) container.lookup( SecDispatcher.ROLE,
"maven" );
+                        pass = " " + sd.decrypt(encryptedString);
+                    } catch (Exception e) {
+                        throw new MojoExecutionException("Failed to decode password", e);
+                    }
+                    
+                } else {
+                    pass = " " + encryptedString;
+                }
+            }
+            System.out.println("\t" + server.getId() + " " + server.getUsername() + pass);
+        }
+    }
+
+}

Propchange: commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/ExampleMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/ExampleMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/HelpMojo.java
URL: http://svn.apache.org/viewvc/commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/HelpMojo.java?rev=1505711&view=auto
==============================================================================
--- commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/HelpMojo.java
(added)
+++ commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/HelpMojo.java
Mon Jul 22 15:12:16 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ * 
+ */
+
+package org.apache.commons.dev_plugins.example;
+
+import java.lang.reflect.Field;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.help.DescribeMojo;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Help Mojo that extends the standard Maven help plugin describe goal.
+ * This is needed because the generated help mojo 
+ * does not handle annotation property names at present.
+ */
+@Mojo (name = "help")
+public class HelpMojo extends DescribeMojo {
+
+    @Component
+    private MavenProject myProject; // Must not use same name as DescribeMojo
+
+   /**
+     * @throws MojoExecutionException  
+     * @throws MojoFailureException 
+     */
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        Field f = null;
+        boolean isAccessible = true; // assume accessible
+        try {
+            // Unfortunately the plugin field is private
+            f = DescribeMojo.class.getDeclaredField("plugin");
+            isAccessible = f.isAccessible();
+            if (!isAccessible) {
+                f.setAccessible(true);
+            }
+            String plugin = myProject.getGroupId() + ":" + myProject.getArtifactId();
+            f.set(this, plugin);
+            super.execute();        
+        } catch (Exception e) {
+            throw new MojoExecutionException("Could not set up plugin details");
+        } finally {
+            if (f != null && !isAccessible) {
+                f.setAccessible(isAccessible); // reset accessibility (prob not needed)
+            }
+        }
+    }
+}

Propchange: commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/HelpMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/dev/plugins/commonsdev-example-plugin/src/main/java/org/apache/commons/dev_plugins/example/HelpMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message