Skip to content

Commit c616820

Browse files
committed
Check for empty main class
This is actually what happens when the pom doesn't have this property
1 parent 2928c93 commit c616820

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/main/java/org/scijava/maven/plugin/enforcer/MainClassExistsRule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public void execute() throws EnforcerRuleException {
8282
return;
8383
}
8484
String mainClass = properties.getProperty("main-class");
85+
if (mainClass.trim().isEmpty()) {
86+
return;
87+
}
8588

8689
// Get the build output directory (e.g., target/classes)
8790
String outputDirectory = project.getBuild().getOutputDirectory();

src/test/java/org/scijava/maven/plugin/enforcer/MainClassExistsRuleTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@
2929

3030
package org.scijava.maven.plugin.enforcer;
3131

32-
import static org.hamcrest.MatcherAssert.assertThat;
33-
import static org.hamcrest.Matchers.containsString;
34-
import static org.junit.Assert.assertTrue;
35-
36-
import java.io.File;
37-
import java.io.IOException;
38-
3932
import org.apache.maven.enforcer.rule.api.EnforcerLogger;
4033
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
4134
import org.apache.maven.model.Build;
@@ -44,9 +37,13 @@
4437
import org.junit.Before;
4538
import org.junit.Rule;
4639
import org.junit.Test;
47-
import org.junit.rules.ExpectedException;
4840
import org.junit.rules.TemporaryFolder;
4941

42+
import java.io.File;
43+
import java.io.IOException;
44+
45+
import static org.junit.Assert.assertTrue;
46+
5047
/**
5148
* Tests for {@link MainClassExistsRule}.
5249
*
@@ -91,15 +88,23 @@ public void setUp() throws Exception {
9188
}
9289

9390
@Test
94-
public void execute_NoMainClassProperty_Passes() throws Exception {
91+
public void TestNoMainClassProperty() throws Exception {
9592
// No "main-class" property set
9693
MainClassExistsRule rule = new MainClassExistsRuleMock(project);
9794
// Execute the rule and make sure it passes
9895
rule.execute();
9996
}
10097

98+
@Test
99+
public void TestEmptyMainClassProperty() throws Exception {
100+
// No "main-class" property set
101+
MainClassExistsRule rule = new MainClassExistsRuleMock(project);
102+
// Execute the rule and make sure it passes
103+
rule.execute();
104+
}
105+
101106
@Test
102-
public void execute_MainClassExists_Passes() throws Exception {
107+
public void TestMainClassExists() throws Exception {
103108
// Set main-class property
104109
project.getProperties().setProperty("main-class", "com.example.Main");
105110

@@ -112,7 +117,7 @@ public void execute_MainClassExists_Passes() throws Exception {
112117
}
113118

114119
@Test
115-
public void execute_MainClassDoesNotExist_ThrowsException() throws Exception {
120+
public void TestMainClassDoesNotExist() {
116121
// Set main-class property...
117122
project.getProperties().setProperty("main-class", "com.example.NonExistent");
118123

0 commit comments

Comments
 (0)