Skip to content

Commit

Permalink
component mojo: prevent duplicate interfaces and components
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Jun 27, 2024
1 parent 3a92282 commit 05adcd0
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import com.squareup.javapoet.TypeSpec;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import javax.lang.model.element.Modifier;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -60,6 +62,8 @@ public class ComponentMojo extends AbstractMojo
private File outputDirectory;

private final Log log = getLog();
private final Set<Integer> seenInterfaces = new HashSet<>();
private final Set<Integer> seenComponents = new HashSet<>();

@Override
public void execute() throws MojoExecutionException, MojoFailureException
Expand Down Expand Up @@ -119,6 +123,12 @@ private void executeOne(File file, TypeSpec.Builder interfaceType, TypeSpec.Buil
throw new MojoExecutionException("interface id out of range for " + interfaceName);
}

if (seenInterfaces.contains(interfaceId))
{
throw new MojoExecutionException("duplicate interface id " + interfaceId);
}
seenInterfaces.add(interfaceId);

addField(interfaceType, interfaceName.toUpperCase(Locale.ENGLISH), interfaceId, null);

for (var entry2 : tbl.entrySet())
Expand All @@ -139,6 +149,12 @@ private void executeOne(File file, TypeSpec.Builder interfaceType, TypeSpec.Buil
var comment = interfaceId + ":" + id;
int componentId = (interfaceId << 16) | id;

if (seenComponents.contains(componentId))
{
throw new MojoExecutionException("duplicate component id " + comment);
}
seenComponents.add(componentId);

addField(componentType, fullName, componentId, comment);
}
}
Expand Down

0 comments on commit 05adcd0

Please sign in to comment.