Skip to content

Commit

Permalink
Adding Maven generator for Plugs
Browse files Browse the repository at this point in the history
 * 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
cardil committed Jun 6, 2019
1 parent 5d0507c commit 78dc920
Show file tree
Hide file tree
Showing 17 changed files with 707 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugs-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<name>Plugs :: Plugs Core</name>

<dependencies>
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
</dependency>
<dependency>
<groupId>pl.wavesoftware</groupId>
<artifactId>eid-exceptions</artifactId>
Expand Down
46 changes: 46 additions & 0 deletions plugs-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,51 @@
</parent>

<artifactId>plugs-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Plugs :: Plugs Maven Plugin</name>

<dependencies>
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings-builder</artifactId>
<scope>provided</scope>
</dependency>

<!-- Tests -->
<dependency>
<groupId>pl.wavesoftware.plugs</groupId>
<artifactId>testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
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";
}
}
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);
}
}
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 {
}
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;
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);
}
}
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);
}
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);
}
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);
}
}
Loading

0 comments on commit 78dc920

Please sign in to comment.