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

Implement IntelliJ suggestions #275

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ protected void logGeneratedStubs(File outputDirectory) {
}

/**
* This is a fix for http://jira.codehaus.org/browse/MGROOVY-187
* This is a fix for <a href="http://jira.codehaus.org/browse/MGROOVY-187">...</a>
* It modifies the dates of the created stubs to 1/1/1970, ensuring that the Java compiler will not overwrite perfectly
* good compiled Groovy just because it has a newer source stub. Basically, this prevents the stubs from causing a
* side-effect with the Java compiler, but still allows stubs to work with JavaDoc.
* side effect with the Java compiler, but still allows stubs to work with JavaDoc.
*
* @param stubs the files on which to reset the modified date
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -537,9 +536,9 @@ protected void copyStylesheet(final File outputDirectory) {
BufferedWriter bufferedWriter = null;
try {
if (stylesheetEncoding != null) {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(stylesheetFile), stylesheetEncoding));
bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(stylesheetFile.toPath()), stylesheetEncoding));
} else {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(stylesheetFile)));
bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(stylesheetFile.toPath())));
}
StringBuilder css = new StringBuilder();
String line;
Expand All @@ -548,9 +547,9 @@ protected void copyStylesheet(final File outputDirectory) {
}
File outfile = new File(outputDirectory, "stylesheet.css");
if (stylesheetEncoding != null) {
bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), stylesheetEncoding));
bufferedWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(outfile.toPath()), stylesheetEncoding));
} else {
bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile)));
bufferedWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(outfile.toPath())));
}
bufferedWriter.write(css.toString());
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ protected File generateArchive(File groovydocFiles, String jarFileName) throws A
File groovydocJar = new File(jarOutputDirectory, jarFileName);

if (groovydocJar.exists()) {
groovydocJar.delete();
if (!groovydocJar.delete()) {
getLog().warn("Unable to delete " + groovydocJar.getAbsolutePath());
}
}

MavenArchiver archiver = new MavenArchiver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ protected File generateArchive(File groovydocFiles, String jarFileName) throws A
File groovydocJar = new File(jarOutputDirectory, jarFileName);

if (groovydocJar.exists()) {
groovydocJar.delete();
if (!groovydocJar.delete()) {
getLog().warn("Unable to delete " + groovydocJar.getAbsolutePath());
}
}

MavenArchiver archiver = new MavenArchiver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@

import org.codehaus.gmavenplus.model.internal.Version;
import org.codehaus.gmavenplus.util.ClassWrangler;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedHashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class AbstractGroovyDocMojoTest {
private MavenProject project;

@Before
@SuppressWarnings("deprecation")
public void setup() throws Exception {
MockitoAnnotations.openMocks(this);
testMojo.mojoExecution = mojoExecution;
Expand All @@ -48,14 +47,12 @@ public void setup() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
public void testDontSkipGroovyDoc() throws Exception {
testMojo.doGroovyDocGeneration(new FileSet[]{new FileSet()}, emptyList(), new File(""));
verify(testMojo, times(1)).generateGroovyDoc(any(File.class), any(Class.class), any(Class.class), any(), anyList(), any());
}

@Test
@SuppressWarnings("deprecation")
public void testSkipGroovyDoc() throws Exception {
testMojo.skipGroovyDoc = true;
testMojo.doGroovyDocGeneration(new FileSet[]{new FileSet()}, emptyList(), new File(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void setup() {

@Test
public void testGetJavaVersion() {
assertTrue(testMojo.getJavaVersionString() != null && testMojo.getJavaVersionString().length() != 0);
assertTrue(testMojo.getJavaVersionString() != null && !testMojo.getJavaVersionString().isEmpty());
assertNotNull(testMojo.getJavaVersion());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public void testInitializeProperties() {
}

@Test
@SuppressWarnings("deprecation")
public void testInitializePropertiesNull() {
testMojo.project = null;
testMojo.session = null;
Expand All @@ -101,7 +100,6 @@ public void testInitializePropertiesNull() {
}

@Test
@SuppressWarnings("deprecation")
public void testInitializePropertiesAlreadyInProps() {
testMojo.properties = properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,31 @@ public void setup() {
}

@Test
@SuppressWarnings("deprecation")
public void testCallsExpectedMethods() throws Exception {
doNothing().when(compileMojo).doCompile(anySet(), anyList(), any(File.class));
compileMojo.execute();
verify(compileMojo, never()).logPluginClasspath();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testClassNotFoundExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new ClassNotFoundException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileMojo).doCompile(anySet(), anyList(), any(File.class));
compileMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInvocationTargetExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new InvocationTargetException(mock(Exception.class), INTENTIONAL_EXCEPTION_MESSAGE)).when(compileMojo).doCompile(anySet(), anyList(), any(File.class));
compileMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInstantiationExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new InstantiationException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileMojo).doCompile(anySet(), anyList(), any(File.class));
compileMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testIllegalAccessExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new IllegalAccessException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileMojo).doCompile(anySet(), anyList(), any(File.class));
compileMojo.execute();
Expand All @@ -105,7 +100,6 @@ public void testDependencyResolutionRequiredExceptionThrowsMojoExecutionExceptio
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testMalformedURLExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new MalformedURLException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileMojo).doCompile(anySet(), anyList(), any(File.class));
compileMojo.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,44 +63,38 @@ public void setup() {
}

@Test
@SuppressWarnings("deprecation")
public void testCallsExpectedMethods() throws Exception {
doNothing().when(compileTestsMojo).doCompile(anySet(), anyList(), any(File.class));
compileTestsMojo.execute();
verify(compileTestsMojo, times(1)).doCompile(anySet(), anyList(), any(File.class));
}

@Test
@SuppressWarnings("deprecation")
public void testSkipped() throws Exception {
compileTestsMojo.skipTests = true;
compileTestsMojo.execute();
verify(compileTestsMojo, never()).doCompile(anySet(), anyList(), any(File.class));
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testClassNotFoundExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new ClassNotFoundException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileTestsMojo).doCompile(anySet(), anyList(), any(File.class));
compileTestsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInvocationTargetExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new InvocationTargetException(mock(Exception.class), INTENTIONAL_EXCEPTION_MESSAGE)).when(compileTestsMojo).doCompile(anySet(), anyList(), any(File.class));
compileTestsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInstantiationExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new InstantiationException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileTestsMojo).doCompile(anySet(), anyList(), any(File.class));
compileTestsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testIllegalAccessExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new IllegalAccessException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileTestsMojo).doCompile(anySet(), anyList(), any(File.class));
compileTestsMojo.execute();
Expand All @@ -113,7 +107,6 @@ public void testDependencyResolutionRequiredExceptionThrowsMojoExecutionExceptio
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testMalformedURLExceptionThrowsMojoExecutionException() throws Exception {
doThrow(new MalformedURLException(INTENTIONAL_EXCEPTION_MESSAGE)).when(compileTestsMojo).doCompile(anySet(), anyList(), any(File.class));
compileTestsMojo.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public void testScriptPath() throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(file));
actualLine = reader.readLine();
FileUtils.closeQuietly(reader);
file.delete();
if (!file.delete()) {
System.err.println("Unable to delete " + file.getAbsolutePath());
}
}

assertEquals(line, actualLine);
Expand All @@ -110,7 +112,9 @@ public void testScriptURL() throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(file));
actualLine = reader.readLine();
FileUtils.closeQuietly(reader);
file.delete();
if (!file.delete()) {
System.err.println("Unable to delete " + file.getAbsolutePath());
}
}

assertEquals(line, actualLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void setup() {
}

@Test
@SuppressWarnings("deprecation")
public void testCallsExpectedMethods() throws Exception {
doReturn(true).when(generateStubsMojo).groovyVersionSupportsAction();
doNothing().when(generateStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
Expand All @@ -69,31 +68,27 @@ public void testCallsExpectedMethods() throws Exception {
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testClassNotFoundExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateStubsMojo).groovyVersionSupportsAction();
doThrow(new ClassNotFoundException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
generateStubsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInvocationTargetExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateStubsMojo).groovyVersionSupportsAction();
doThrow(new InvocationTargetException(mock(Exception.class), INTENTIONAL_EXCEPTION_MESSAGE)).when(generateStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
generateStubsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInstantiationExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateStubsMojo).groovyVersionSupportsAction();
doThrow(new InstantiationException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
generateStubsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testIllegalAccessExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateStubsMojo).groovyVersionSupportsAction();
doThrow(new IllegalAccessException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
Expand All @@ -107,7 +102,6 @@ public void testDependencyResolutionRequiredExceptionThrowsMojoExecutionExceptio
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testMalformedURLExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateStubsMojo).groovyVersionSupportsAction();
doThrow(new MalformedURLException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void setup() {
}

@Test
@SuppressWarnings("deprecation")
public void testCallsExpectedMethods() throws Exception {
doReturn(true).when(generateTestStubsMojo).groovyVersionSupportsAction();
doNothing().when(generateTestStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
Expand All @@ -69,7 +68,6 @@ public void testCallsExpectedMethods() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
public void testSkipped() throws Exception {
doReturn(true).when(generateTestStubsMojo).groovyVersionSupportsAction();
generateTestStubsMojo.skipTests = true;
Expand All @@ -78,31 +76,27 @@ public void testSkipped() throws Exception {
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testClassNotFoundExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateTestStubsMojo).groovyVersionSupportsAction();
doThrow(new ClassNotFoundException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateTestStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
generateTestStubsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInvocationTargetExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateTestStubsMojo).groovyVersionSupportsAction();
doThrow(new InvocationTargetException(mock(Exception.class), INTENTIONAL_EXCEPTION_MESSAGE)).when(generateTestStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
generateTestStubsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testInstantiationExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateTestStubsMojo).groovyVersionSupportsAction();
doThrow(new InstantiationException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateTestStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
generateTestStubsMojo.execute();
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testIllegalAccessExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateTestStubsMojo).groovyVersionSupportsAction();
doThrow(new IllegalAccessException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateTestStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
Expand All @@ -116,7 +110,6 @@ public void testDependencyResolutionRequiredExceptionThrowsMojoExecutionExceptio
}

@Test(expected = MojoExecutionException.class)
@SuppressWarnings("deprecation")
public void testMalformedURLExceptionThrowsMojoExecutionException() throws Exception {
doReturn(true).when(generateTestStubsMojo).groovyVersionSupportsAction();
doThrow(new MalformedURLException(INTENTIONAL_EXCEPTION_MESSAGE)).when(generateTestStubsMojo).doStubGeneration(anySet(), anyList(), any(File.class));
Expand Down