-
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 complete test infrastructure for Maven plugin. * Plugin is able to work with DI maven container. Refers to issue #9
- Loading branch information
Showing
16 changed files
with
447 additions
and
31 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
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 |
---|---|---|
|
@@ -16,12 +16,15 @@ | |
|
||
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 2019-01-10 | ||
* @since 0.1.0 | ||
*/ | ||
@API(status = API.Status.EXPERIMENTAL) | ||
@Named | ||
final class DefaultWorker implements Worker { | ||
|
||
|
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 |
---|---|---|
|
@@ -20,20 +20,28 @@ | |
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 = "package-plug", | ||
name = PackagePlugMojo.GOAL, | ||
defaultPhase = LifecyclePhase.PACKAGE, | ||
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, | ||
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME | ||
) | ||
final class PackagePlugMojo extends AbstractMojo { | ||
public final class PackagePlugMojo extends AbstractMojo { | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
@API(status = Status.STABLE) | ||
public static final String GOAL = "package-plug"; | ||
|
||
private final Worker worker; | ||
|
||
|
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 |
---|---|---|
|
@@ -16,9 +16,12 @@ | |
|
||
package pl.wavesoftware.plugs.maven.generator; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 2019-01-10 | ||
* @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); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
plugs-maven-plugin/src/test/java/pl/wavesoftware/plugs/maven/generator/MojoBuilderImpl.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,92 @@ | ||
/* | ||
* 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.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.plugin.testing.MojoRule; | ||
|
||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute; | ||
import static pl.wavesoftware.eid.utils.EidPreconditions.checkNotNull; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
final class MojoBuilderImpl<T extends AbstractMojo> | ||
implements MojoBuilder<T> { | ||
|
||
private final MojoRule mojoRule; | ||
private final Class<T> type; | ||
private final MojoConfigurator configurator; | ||
|
||
private Path pomDirectory = Paths.get("."); | ||
private boolean usingResources = true; | ||
|
||
MojoBuilderImpl(MojoRule mojoRule, Class<T> type, MojoConfigurator configurator) { | ||
this.mojoRule = mojoRule; | ||
this.type = type; | ||
this.configurator = configurator; | ||
} | ||
|
||
@Override | ||
public MojoBuilder<T> withPomDirectory(Path pomDirectory) { | ||
this.pomDirectory = pomDirectory; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MojoBuilder<T> withUsingResources(boolean setting) { | ||
this.usingResources = setting; | ||
return this; | ||
} | ||
|
||
@Override | ||
public T build(String goal) { | ||
return tryToExecute(() -> { | ||
MavenSession session = configurator.getMavenSession( | ||
mojoRule, getPomDirectory() | ||
); | ||
MojoExecution execution = configurator.getMojoExecution( | ||
mojoRule, | ||
goal | ||
); | ||
org.apache.maven.plugin.Mojo mojo = | ||
mojoRule.lookupConfiguredMojo(session, execution); | ||
return type.cast(mojo); | ||
}, "20190111:223034"); | ||
} | ||
|
||
private Path getPomDirectory() throws URISyntaxException { | ||
if (usingResources) { | ||
URL url = checkNotNull( | ||
type.getClassLoader().getResource(pomDirectory.toString()), | ||
"20190111:224609" | ||
); | ||
File file = new File(url.toURI()); | ||
return file.toPath(); | ||
} | ||
return pomDirectory; | ||
} | ||
} |
Oops, something went wrong.