Permalink
Browse files

[MNG-4384] add an example mojo

git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk@1095366 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent d5a7bb7 commit 1e313ff4ad6a923c7b0e604018ed8f5e30a17492 @brettporter brettporter committed Apr 20, 2011
@@ -0,0 +1,39 @@
+<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>
+ <groupId>org.apache.maven.examples</groupId>
+ <artifactId>maven-security-mojo</artifactId>
+ <packaging>maven-plugin</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>maven-security-mojo Maven Mojo</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.plexus</groupId>
+ <artifactId>plexus-sec-dispatcher</artifactId>
+ <version>1.3</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <prefix>sec</prefix>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
@@ -0,0 +1,52 @@
+package org.apache.maven.examples;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
+
+/**
+ * Goal which decrypts a password using Maven settings.
+ *
+ * @goal decrypt
+ */
+public class MyMojo
+ extends AbstractMojo
+{
+ /**
+ * Password to decrypt.
+ * @parameter expression="${password}"
+ * @required
+ */
+ private String password;
+
+ /** @component role-hint="mojo" */
+ private SecDispatcher securityDispatcher;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ try {
+ // obviously, using it instead of echoing it is recommended :)
+ getLog().info( securityDispatcher.decrypt( password ) );
+ } catch ( SecDispatcherException e ) {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ }
+}
@@ -0,0 +1,24 @@
+<component-set>
+ <components>
+ <component>
+ <role>org.sonatype.plexus.components.sec.dispatcher.SecDispatcher</role>
+ <role-hint>mojo</role-hint>
+ <implementation>org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher</implementation>
+ <description>Maven Security dispatcher</description>
+ <requirements>
+ <requirement>
+ <role>org.sonatype.plexus.components.cipher.PlexusCipher</role>
+ <field-name>_cipher</field-name>
+ </requirement>
+ </requirements>
+ <configuration>
+ <_configuration-file>~/.m2/settings-security.xml</_configuration-file>
+ </configuration>
+ </component>
+ <component>
+ <role>org.sonatype.plexus.components.cipher.PlexusCipher</role>
+ <role-hint>mojo</role-hint>
+ <implementation>org.sonatype.plexus.components.cipher.DefaultPlexusCipher</implementation>
+ </component>
+ </components>
+</component-set>

0 comments on commit 1e313ff

Please sign in to comment.