-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding tests for Maven plugin * Adding complete test infrastructure for Maven plugin. * Plugin is able to work with DI maven container. Refers to issue #9
- Loading branch information
Showing
17 changed files
with
707 additions
and
0 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/maven/generator/DefaultWorker.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,35 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
import javax.inject.Named; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
@API(status = API.Status.EXPERIMENTAL) | ||
@Named | ||
final class DefaultWorker implements Worker { | ||
|
||
@Override | ||
public String toString() { | ||
return "default"; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/maven/generator/PackagePlugMojo.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,57 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.ResolutionScope; | ||
import org.apiguardian.api.API; | ||
import org.apiguardian.api.API.Status; | ||
|
||
import javax.inject.Inject; | ||
|
||
/** | ||
* A main mojo to generate plug modules | ||
* | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
@Mojo( | ||
name = PackagePlugMojo.GOAL, | ||
defaultPhase = LifecyclePhase.PACKAGE, | ||
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, | ||
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME | ||
) | ||
public final class PackagePlugMojo extends AbstractMojo { | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
@API(status = Status.STABLE) | ||
public static final String GOAL = "package-plug"; | ||
|
||
private final Worker worker; | ||
|
||
@Inject | ||
PackagePlugMojo(Worker worker) { | ||
this.worker = worker; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
getLog().debug("Worker is: " + worker); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/maven/generator/Worker.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,27 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
@API(status = API.Status.EXPERIMENTAL) | ||
interface Worker { | ||
} |
24 changes: 24 additions & 0 deletions
24
plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/maven/generator/package-info.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,24 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
45 changes: 45 additions & 0 deletions
45
...n-plugin/src/test/java/pl/wavesoftware/plugs/maven/generator/DefaultMojoConfigurator.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,45 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.plugin.testing.MojoRule; | ||
import org.apache.maven.project.MavenProject; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
final class DefaultMojoConfigurator implements MojoConfigurator { | ||
@Override | ||
public MavenSession getMavenSession(MojoRule rule, Path pomDirectory) throws Exception { | ||
// setup with pom | ||
MavenProject project = rule.readMavenProject(pomDirectory.toFile()); | ||
|
||
// Generate session | ||
return rule.newMavenSession(project); | ||
} | ||
|
||
@Override | ||
public MojoExecution getMojoExecution(MojoRule rule, String goal) { | ||
// Generate Execution and Mojo for testing | ||
return rule.newMojoExecution(goal); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
plugs-maven-plugin/src/test/java/pl/wavesoftware/plugs/maven/generator/MojoBuilder.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,31 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
public interface MojoBuilder<T extends AbstractMojo> { | ||
MojoBuilder<T> withPomDirectory(Path pomDirectory); | ||
MojoBuilder<T> withUsingResources(boolean setting); | ||
T build(String goal); | ||
} |
28 changes: 28 additions & 0 deletions
28
...-maven-plugin/src/test/java/pl/wavesoftware/plugs/maven/generator/MojoBuilderFactory.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,28 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
public interface MojoBuilderFactory { | ||
MojoBuilderFactory configurator(MojoConfigurator configurator); | ||
<T extends AbstractMojo> MojoBuilder<T> builder(Class<T> mojoType); | ||
} |
46 changes: 46 additions & 0 deletions
46
...en-plugin/src/test/java/pl/wavesoftware/plugs/maven/generator/MojoBuilderFactoryImpl.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,46 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* 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. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.testing.MojoRule; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
final class MojoBuilderFactoryImpl implements MojoBuilderFactory { | ||
|
||
private final MojoRule rule; | ||
|
||
private MojoConfigurator configurator = new DefaultMojoConfigurator(); | ||
|
||
MojoBuilderFactoryImpl(MojoRule rule) { | ||
this.rule = rule; | ||
} | ||
|
||
@Override | ||
public MojoBuilderFactory configurator(MojoConfigurator configurator) { | ||
this.configurator = configurator; | ||
return this; | ||
} | ||
|
||
@Override | ||
public <T extends AbstractMojo> MojoBuilder<T> builder(Class<T> mojoType) { | ||
return new MojoBuilderImpl<>(rule, mojoType, configurator); | ||
} | ||
} |
Oops, something went wrong.