-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] [MPLUGINTESTING-93] - Prepare documentation / examples for JUnit 5 and Maven 3 #50
Draft
aamotharald
wants to merge
6
commits into
apache:maven-plugin-testing-3.x
Choose a base branch
from
aamotharald:contribution/MPLUGINTESTING-93
base: maven-plugin-testing-3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b0d067
Allow a plugin defintion without configuration elements
aamotharald c564d7d
Documented deprecation of the JUnit4 testing approach
aamotharald 60451e3
Deleted jUnit5 folder and moved the junit5 sample tests over
aamotharald cb1a5e8
relocated JUnit5 classes to have no package name change when migratin…
aamotharald 4769e13
backmerge - resolved conflicts and took all changes from @jesse over
aamotharald c58431e
backporting from master branch
aamotharald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/Basedir.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.maven.api.plugin.testing; | ||
|
||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* Mojo parameters container | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Inherited | ||
public @interface Basedir { | ||
String value() default ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...ss/src/main/java/org/apache/maven/api/plugin/testing/ResolverExpressionEvaluatorStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* 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.maven.api.plugin.testing; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.maven.artifact.repository.MavenArtifactRepository; | ||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; | ||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; | ||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; | ||
|
||
/** | ||
* Stub for {@link ExpressionEvaluator} | ||
* | ||
* @author jesse | ||
*/ | ||
public class ResolverExpressionEvaluatorStub implements ExpressionEvaluator { | ||
/** {@inheritDoc} */ | ||
@Override | ||
public Object evaluate(String expr) throws ExpressionEvaluationException { | ||
|
||
Object value = null; | ||
|
||
if (expr == null) { | ||
return null; | ||
} | ||
|
||
String expression = stripTokens(expr); | ||
|
||
if (expression.equals(expr)) { | ||
int index = expr.indexOf("${"); | ||
if (index >= 0) { | ||
int lastIndex = expr.indexOf("}", index); | ||
if (lastIndex >= 0) { | ||
String retVal = expr.substring(0, index); | ||
|
||
if (index > 0 && expr.charAt(index - 1) == '$') { | ||
retVal += expr.substring(index + 1, lastIndex + 1); | ||
} else { | ||
retVal += evaluate(expr.substring(index, lastIndex + 1)); | ||
} | ||
|
||
retVal += evaluate(expr.substring(lastIndex + 1)); | ||
return retVal; | ||
} | ||
} | ||
|
||
// Was not an expression | ||
if (expression.indexOf("$$") > -1) { | ||
return expression.replaceAll("\\$\\$", "\\$"); | ||
} | ||
} | ||
|
||
if ("basedir".equals(expression) || "project.basedir".equals(expression)) { | ||
return MojoExtension.getBasedir(); | ||
} else if (expression.startsWith("basedir") || expression.startsWith("project.basedir")) { | ||
int pathSeparator = expression.indexOf("/"); | ||
|
||
if (pathSeparator > 0) { | ||
value = MojoExtension.getBasedir() + expression.substring(pathSeparator); | ||
} else { | ||
System.out.println("Got expression '" + expression + "' that was not recognised"); | ||
} | ||
return value; | ||
} else if ("localRepository".equals(expression)) { | ||
File localRepo = new File(MojoExtension.getBasedir(), "target/local-repo"); | ||
return new MavenArtifactRepository( | ||
"localRepository", | ||
"file://" + localRepo.getAbsolutePath(), | ||
new DefaultRepositoryLayout(), | ||
null, | ||
null); | ||
} else { | ||
return expr; | ||
} | ||
} | ||
|
||
private String stripTokens(String expr) { | ||
if (expr.startsWith("${") && expr.indexOf("}") == expr.length() - 1) { | ||
expr = expr.substring(2, expr.length() - 1); | ||
} | ||
|
||
return expr; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public File alignToBaseDirectory(File file) { | ||
if (file.getAbsolutePath().startsWith(MojoExtension.getBasedir())) { | ||
return file; | ||
} else if (file.isAbsolute()) { | ||
return file; | ||
} else { | ||
return new File(MojoExtension.getBasedir(), file.getPath()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may collide with Maven 4 apis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @slachiewicz ,
yes this might collide and this I am doing by intent.
Consider the following use case:
Somebody uses
@InjectMojo
on maven version 3 and creates JUnit Jupiter test cases to test his/her Mojo.Then he/she decides to migrate to Maven4.
As the codelines differ between maven3/maven4, there might be glitches / issues. But the migration will be a lot less cumbersome if you don't have to rename all the imports just because the package changes from maven3 to maven4. This is why I would like to have the same Packages on Maven3/4.
Does that make sense or should we strictly separate the packages and make the maven3-4 migration cumbersome for the consumers?
PS: I made some experiments and at least for my limited use cases the migration from maven3 to 4 with this setup went really smooth. Still thinking how to deal with One Exception which got relocated between 3 to 4 which I plan to provide some further solution.