Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions maven-plugin-testing-harness/src/site/apt/index.apt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
------
Testing Project Artifact
------
Vincent Siveton
------
February 2008
------

~~ 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.

Testing Project Artifact

<<Note>>: This example improves the {{{../getting-started/index.html}cookbook}} to play with artifact handler.

Sometimes, your Mojo uses project artifact and ArtifactHandler mechanisms. For instance, you could need to
filter on Java projects, i.e.:

+---+
title: Testing Project Artifact
author: Vincent Siveton
date: February 2008

<!-- 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. -->
## Testing Project Artifact


**Note**: This example improves the [cookbook](../getting-started/index.html) to play with artifact handler.


Sometimes, your Mojo uses project artifact and ArtifactHandler mechanisms. For instance, you could need to filter on Java projects, i.e.:



```
public class MyMojo
extends AbstractMojo
{
Expand All @@ -54,11 +52,13 @@ public class MyMojo
...
}
}
+---+
```

### Create Stubs

* Create Stubs

+---+

```
public class MyArtifactHandlerStub
extends DefaultArtifactHandler
{
Expand All @@ -79,9 +79,10 @@ public class MyArtifactHandlerStub
this.language = language;
}
}
+---+
```


+---+
```
public class MyArtifactStub
extends ArtifactStub
{
Expand Down Expand Up @@ -189,9 +190,10 @@ public class MyArtifactStub
this.handler = handler;
}
}
+---+
```

+---+

```
public class MyProjectStub
extends MavenProjectStub
{
Expand All @@ -212,4 +214,6 @@ public class MyProjectStub

...
}
+---+
```


Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
------
Testing Complex Mojo Parameters
------
Vincent Siveton
------
February 2008
------

~~ 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.

Testing Complex Mojo Parameters

<<Note>>: This example improves the {{{../getting-started/index.html}cookbook}} for testing complex Mojo parameters.

In real plugin development, you will use specific Maven objects like <<<MavenProject>>>, <<<ArtifactRepository>>> or
<<<MavenSettings>>>. You could use them by defining stubs.
title: Testing Complex Mojo Parameters
author: Vincent Siveton
date: February 2008

<!-- 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. -->
## Testing Complex Mojo Parameters


**Note**: This example improves the [cookbook](../getting-started/index.html) for testing complex Mojo parameters.


In real plugin development, you will use specific Maven objects like `MavenProject`, `ArtifactRepository` or `MavenSettings`. You could use them by defining stubs.


Suppose that you have the following dependencies in the maven-my-plugin pom:

+---+


```
<project>
...
<dependencies>
Expand All @@ -49,11 +48,13 @@ Testing Complex Mojo Parameters
...
</dependencies>
</project>
+---+
```

You will add the following in the `MyMojo`:


You will add the following in the <<<MyMojo>>>:

+---+
```
public class MyMojo
extends AbstractMojo
{
Expand All @@ -77,14 +78,16 @@ public class MyMojo

...
}
+---+
```

* Create Stubs
### Create Stubs

You need to create stub objects to run <<<MyMojoTest#testSomething()>>>. By convention, the package name should
reflect the stubs, i.e. in our case <<<org.apache.maven.plugin.my.stubs>>>.

+---+
You need to create stub objects to run `MyMojoTest#testSomething()`. By convention, the package name should reflect the stubs, i.e. in our case `org.apache.maven.plugin.my.stubs`.



```
public class MyProjectStub
extends MavenProjectStub
{
Expand Down Expand Up @@ -136,9 +139,10 @@ public class MyProjectStub
return new File( super.getBasedir() + "/src/test/resources/unit/project-to-test/" );
}
}
+---+
```

+---+

```
public class SettingsStub
extends Settings
{
Expand All @@ -148,11 +152,14 @@ public class SettingsStub
return Collections.EMPTY_LIST;
}
}
+---+
```


* Configure <<<project-to-test>>> pom
### Configure `project-to-test` pom

+---+


```
<project>
...
<build>
Expand All @@ -174,4 +181,6 @@ public class SettingsStub
</plugins>
</build>
</project>
+---+
```


Loading