Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warns the user if specified mainClass is not a valid Java class. #228

Merged
merged 9 commits into from Apr 23, 2018
@@ -30,6 +30,8 @@
/** Immutable configuration options for the builder process. */
public class BuildConfiguration {

public static final String VALID_JAVA_CLASS_REGEX = "([\\p{L}_$][\\p{L}\\p{N}_$]*\\.)*[\\p{L}_$][\\p{L}\\p{N}_$]*";
Copy link
Member

@loosebazooka loosebazooka Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh confusing, can you comment on top of this, what this means?

Copy link
Member

@loosebazooka loosebazooka Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually never mind, the tests are good.


public static class Builder {

// All the parameters below are set to their default values.
@@ -153,4 +153,14 @@ public void testBuilder_missingValues() {
ex.getMessage());
}
}

@Test
public void testValidJavaClassRegex() {
Assert.assertTrue("my.Class".matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX));
Assert.assertTrue("my.java_Class$valid".matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX));
Assert.assertFalse("${start-class}".matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX));
Copy link
Member

@loosebazooka loosebazooka Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you verify that is123.valid works?
and that mutliple package items work? abc.xyz.Valid

Assert.assertFalse("123not.Valid".matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX));
Assert.assertFalse("{class}".matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX));
Assert.assertFalse("not valid".matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX));
}
}
@@ -122,6 +122,9 @@ public void buildImage() throws InvalidImageReferenceException, IOException {
throw new GradleException("Could not find main class specified in a 'jar' task");
}
}
if (!mainClass.matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX)) {
getLogger().warn("'mainClass' is not a valid Java class : " + mainClass);
}

SourceFilesConfiguration sourceFilesConfiguration = getSourceFilesConfiguration();

@@ -131,6 +131,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
"add a `mainClass` configuration to jib-maven-plugin");
}
}
if (!mainClass.matches(BuildConfiguration.VALID_JAVA_CLASS_REGEX)) {
getLog().warn("'mainClass' is not a valid Java class : " + mainClass);
}

SourceFilesConfiguration sourceFilesConfiguration =
projectProperties.getSourceFilesConfiguration();
@@ -293,7 +296,7 @@ private void validateParameters() throws MojoFailureException {
throw new MojoFailureException("Invalid configuration parameters");
}
}
// Validates 'imageFormat'
// Validates 'imageFormat'.
boolean validFormat = false;
for (ImageFormat format : ImageFormat.values()) {
if (imageFormat.equals(format.name())) {