Skip to content

Commit

Permalink
Merge pull request #11 from avaje/components
Browse files Browse the repository at this point in the history
Add components.xml/Remove duplicate inject mojo
  • Loading branch information
SentryMan authored Apr 22, 2024
2 parents 6675364 + aa2c86c commit 2bc2b5a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 207 deletions.
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ This plugin uses the JDK 22 [Class-File API](https://openjdk.org/jeps/457). As t
<plugin>
<groupId>io.avaje</groupId>
<artifactId>avaje-provides-maven-plugin</artifactId>
<version>${version}</version>
<executions>
<execution>
<goals>
<!-- Will generate files that will disable avaje APT module-info spi validation -->
<goal>provides</goal>
<!-- Will transform a module-info after compilation -->
<goal>module-spi</goal>
</goals>
</execution>
</executions>
<version>${version}</version>
<extensions>true</extensions>
</plugin>
```

Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<version>0.10-SNAPSHOT</version>
<properties>
<maven.compiler.release>22</maven.compiler.release>
<avaje.inject.version>10.0-RC1</avaje.inject.version>
</properties>

<dependencies>
Expand All @@ -33,7 +34,8 @@
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject</artifactId>
<version>9.12</version>
<version>10.0-RC2</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
184 changes: 0 additions & 184 deletions src/main/java/io/avaje/inject/mojo/AutoProvidesMojo.java

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/java/io/avaje/inject/mojo/AvajeModule.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.avaje.inject.mojo;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;

/** Mojo that disables avaje's apt module validation */
@Mojo(
name = "disable-apt-validation",
defaultPhase = LifecyclePhase.PROCESS_RESOURCES,
requiresDependencyResolution = ResolutionScope.COMPILE)
public class DisableModuleValidationMojo extends AbstractMojo {

private static final String DISABLING_AVAJE_MODULE_VERIFICATION =
"disabling avaje module verification";

@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

@Override
public void execute() throws MojoExecutionException {
final var directory = new File(project.getBuild().getDirectory());
if (!directory.exists()) {
directory.mkdirs();
}

try (var flagFile = createFileWriter("avaje-plugin-exists.txt"); ) {

flagFile.append(DISABLING_AVAJE_MODULE_VERIFICATION);
getLog().info(DISABLING_AVAJE_MODULE_VERIFICATION);

} catch (final IOException e) {
throw new MojoExecutionException("Failed to write spi classes", e);
}
}

private FileWriter createFileWriter(String string) throws IOException {
return new FileWriter(new File(project.getBuild().getDirectory(), string));
}
}
8 changes: 2 additions & 6 deletions src/main/java/io/avaje/inject/mojo/ModuleSPIMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.lang.classfile.attribute.ModuleAttribute;
import java.lang.classfile.attribute.ModuleAttribute.ModuleAttributeBuilder;
import java.lang.classfile.attribute.ModuleProvideInfo;
import java.lang.classfile.attribute.ModuleRequireInfo;
import java.lang.classfile.constantpool.Utf8Entry;
import java.lang.classfile.attribute.ModuleAttribute.ModuleAttributeBuilder;
import java.lang.constant.ClassDesc;
import java.lang.constant.ModuleDesc;
import java.lang.reflect.AccessFlag;
Expand All @@ -33,14 +33,10 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;

/** Plugin that transforms the project module-info class file to register META-INF/services. */
@Mojo(
name = "module-spi",
defaultPhase = LifecyclePhase.PROCESS_CLASSES,
requiresDependencyResolution = ResolutionScope.COMPILE)
@Mojo(name = "add-module-spi", defaultPhase = LifecyclePhase.PROCESS_CLASSES)
public class ModuleSPIMojo extends AbstractMojo {

private static final String IO_AVAJE_JSONB_PLUGIN = "io.avaje.jsonb.plugin";
Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/META-INF/plexus/components.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>avaje-inject-maven-plugin</role-hint>
<configuration>
<id>avaje-provides-maven-plugin</id>
<phases>
<phase>avaje-inject-maven-plugin-not-used-phase</phase>
</phases>
<default-phases>
<process-resources>
io.avaje:avaje-provides-maven-plugin:${project.version}:disable-apt-validation
</process-resources>
<process-sources>
io.avaje:avaje-inject-maven-plugin:10.0-RC2:provides
</process-sources>
<process-classes>
io.avaje:avaje-provides-maven-plugin:${project.version}:add-module-spi
</process-classes>
</default-phases>
</configuration>
</component>
</components>
</component-set>

0 comments on commit 2bc2b5a

Please sign in to comment.