Skip to content
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 @@ -36,7 +36,6 @@
class JctDogfoodTest {

static final String MAIN_MODULE = "io.github.ascopes.jct";
static final String TEST_MODULE = "io.github.ascopes.jct.testing";

static final Path PROJECT_ROOT = projectBase()
.resolve("java-compiler-testing")
Expand All @@ -48,19 +47,10 @@ class JctDogfoodTest {
.resolve("main")
.resolve("java");

static final Path SRC_TEST_JAVA = PROJECT_ROOT
.resolve("src")
.resolve("test")
.resolve("java");

static final Path TARGET_CLASSES = PROJECT_ROOT
.resolve("target")
.resolve("classes");

static final Path TARGET_TEST_CLASSES = PROJECT_ROOT
.resolve("target")
.resolve("test-classes");

@DisplayName("JCT can compile itself as a legacy module source")
@JavacCompilerTest(minVersion = 11, configurers = JctCompilationConfigurer.class)
void jctCanCompileItselfAsLegacyModule(JctCompiler compiler) throws IOException {
Expand All @@ -83,63 +73,6 @@ void jctCanCompileItselfAsLegacyModule(JctCompiler compiler) throws IOException
}
}

@DisplayName("JCT can compile its unit tests as a legacy module source")
@JavacCompilerTest(minVersion = 11, configurers = JctCompilationConfigurer.class)
void jctCanCompileUnitTestsAsLegacyModule(JctCompiler compiler) throws IOException {
// Given
try (var workspace = Workspaces.newWorkspace()) {
workspace
.createSourcePathPackage()
.copyContentsFrom(SRC_TEST_JAVA);

// When
var compilation = compiler.compile(workspace);

// Then
assertThat(compilation)
.isSuccessful();

assertThat(compilation)
.classPathPackages()
.allFilesExist(getClassesFrom(TARGET_TEST_CLASSES));
}
}

@DisplayName("JCT can compile itself and its unit tests as a multiple-module source")
@JavacCompilerTest(minVersion = 11, configurers = JctCompilationConfigurer.class)
void jctCanCompileItselfAndUnitTestsAsMultiModule(JctCompiler compiler) throws IOException {
// Given
try (var workspace = Workspaces.newWorkspace()) {
workspace
.createSourcePathModule(MAIN_MODULE)
.copyContentsFrom(SRC_MAIN_JAVA);
workspace
.createSourcePathModule(TEST_MODULE)
.copyContentsFrom(SRC_TEST_JAVA);

// When
var compilation = compiler.compile(workspace);

// Then
var expectedMainFiles = getClassesFrom(TARGET_CLASSES);
var expectedTestFiles = getClassesFrom(TARGET_TEST_CLASSES);

assertThat(compilation)
.isSuccessful();

assertThat(compilation)
.classOutputModules()
.satisfies(
modules -> assertThat(modules.getModule(MAIN_MODULE))
.withFailMessage("Missing classes from main source root")
.allFilesExist(expectedMainFiles),
modules -> assertThat(modules.getModule(TEST_MODULE))
.withFailMessage("Missing classes from test source root")
.allFilesExist(expectedTestFiles)
);
}
}

private static Set<String> getClassesFrom(Path location) throws IOException {
try (var walker = Files.walk(location)) {
return walker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,29 +275,7 @@ private JctCompilerConfigurer<?> initializeConfigurer(
);
}

try {
// Force-enable reflective access. If the user is using a SecurityManager for any reason then
// tough luck. JVM go bang.
// If the module is not open to JCT, then we will get an InaccessibleObjectException that
// we should wrap and rethrow.
constructor.setAccessible(true);

} catch (InaccessibleObjectException ex) {

throw new JctJunitConfigurerException(
"The constructor in " + configurerClass.getSimpleName() + " cannot be called from JCT."
+ "\n"
+ "This is likely because JPMS modules are in use and you have not granted "
+ "permission for JCT to access your classes reflectively."
+ "\n"
+ "To fix this, add the following line into your module-info.java within the "
+ "'module' block:"
+ "\n\n"
+ " opens " + constructor.getDeclaringClass().getPackageName() + " to "
+ getClass().getModule().getName() + ";",
ex
);
}
constructor.setAccessible(true);

try {
return constructor.newInstance();
Expand Down
30 changes: 0 additions & 30 deletions java-compiler-testing/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,34 +150,4 @@
///////////////////////////////////

provides URLStreamHandlerProvider with MemoryFileSystemUrlHandlerProvider;

//////////////////////////////////////////////////////
/// EXPOSURE OF INTERNALS TO THE TESTING NAMESPACE ///
//////////////////////////////////////////////////////

exports io.github.ascopes.jct.compilers.impl to io.github.ascopes.jct.testing;
exports io.github.ascopes.jct.containers.impl to io.github.ascopes.jct.testing;
exports io.github.ascopes.jct.filemanagers.impl to io.github.ascopes.jct.testing;
exports io.github.ascopes.jct.utils to io.github.ascopes.jct.testing;
exports io.github.ascopes.jct.workspaces.impl to io.github.ascopes.jct.testing;

//////////////////////////////////////////////////////////////////////////
/// EXPOSURE OF ALL COMPONENTS TO THE TESTING NAMESPACE FOR REFLECTION ///
//////////////////////////////////////////////////////////////////////////

opens io.github.ascopes.jct.assertions to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.compilers to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.compilers.impl to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.containers to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.containers.impl to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.diagnostics to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.ex to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.filemanagers to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.filemanagers.config to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.filemanagers.impl to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.junit to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.repr to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.utils to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.workspaces to io.github.ascopes.jct.testing;
opens io.github.ascopes.jct.workspaces.impl to io.github.ascopes.jct.testing;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static io.github.ascopes.jct.tests.helpers.Fixtures.someLocation;
import static io.github.ascopes.jct.fixtures.Fixtures.someLocation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -24,8 +24,6 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import io.github.ascopes.jct.assertions.AbstractContainerGroupAssert;
import io.github.ascopes.jct.assertions.LocationAssert;
import io.github.ascopes.jct.containers.ContainerGroup;
import java.util.List;
import java.util.ServiceLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import io.github.ascopes.jct.assertions.AbstractEnumAssert;
import java.util.Arrays;
import java.util.List;
import org.jspecify.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static io.github.ascopes.jct.tests.helpers.Fixtures.someBinaryData;
import static io.github.ascopes.jct.tests.helpers.Fixtures.someCharset;
import static io.github.ascopes.jct.tests.helpers.Fixtures.someJavaFileObject;
import static io.github.ascopes.jct.tests.helpers.Fixtures.somePath;
import static io.github.ascopes.jct.fixtures.Fixtures.someBinaryData;
import static io.github.ascopes.jct.fixtures.Fixtures.someCharset;
import static io.github.ascopes.jct.fixtures.Fixtures.someJavaFileObject;
import static io.github.ascopes.jct.fixtures.Fixtures.somePath;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.when;

import io.github.ascopes.jct.assertions.AbstractJavaFileObjectAssert;
import io.github.ascopes.jct.assertions.JavaFileObjectKindAssert;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static org.mockito.Mockito.mock;

import io.github.ascopes.jct.assertions.ClassLoaderAssert;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import io.github.ascopes.jct.assertions.DiagnosticKindAssert;
import javax.tools.Diagnostic.Kind;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static io.github.ascopes.jct.tests.helpers.Fixtures.someJavaFileObject;
import static io.github.ascopes.jct.fixtures.Fixtures.someJavaFileObject;
import static org.assertj.core.api.Assertions.assertThat;

import io.github.ascopes.jct.assertions.AbstractJavaFileObjectAssert;
import io.github.ascopes.jct.assertions.JavaFileObjectAssert;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import io.github.ascopes.jct.assertions.JavaFileObjectKindAssert;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
import org.assertj.core.api.AbstractStringAssert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.Mockito.mock;

import io.github.ascopes.jct.assertions.DiagnosticKindAssert;
import io.github.ascopes.jct.assertions.JavaFileObjectAssert;
import io.github.ascopes.jct.assertions.JavaFileObjectKindAssert;
import io.github.ascopes.jct.assertions.JctAssertions;
import io.github.ascopes.jct.assertions.JctCompilationAssert;
import io.github.ascopes.jct.assertions.LocationAssert;
import io.github.ascopes.jct.assertions.ModuleContainerGroupAssert;
import io.github.ascopes.jct.assertions.OutputContainerGroupAssert;
import io.github.ascopes.jct.assertions.PackageContainerGroupAssert;
import io.github.ascopes.jct.assertions.PathFileObjectAssert;
import io.github.ascopes.jct.assertions.TraceDiagnosticAssert;
import io.github.ascopes.jct.assertions.TraceDiagnosticListAssert;
import io.github.ascopes.jct.compilers.JctCompilation;
import io.github.ascopes.jct.containers.ModuleContainerGroup;
import io.github.ascopes.jct.containers.OutputContainerGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static io.github.ascopes.jct.tests.helpers.Fixtures.someFlags;
import static io.github.ascopes.jct.tests.helpers.Fixtures.someLocation;
import static io.github.ascopes.jct.tests.helpers.Fixtures.someTraceDiagnostic;
import static io.github.ascopes.jct.fixtures.Fixtures.someFlags;
import static io.github.ascopes.jct.fixtures.Fixtures.someLocation;
import static io.github.ascopes.jct.fixtures.Fixtures.someTraceDiagnostic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -27,10 +27,6 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import io.github.ascopes.jct.assertions.JctCompilationAssert;
import io.github.ascopes.jct.assertions.ModuleContainerGroupAssert;
import io.github.ascopes.jct.assertions.OutputContainerGroupAssert;
import io.github.ascopes.jct.assertions.PackageContainerGroupAssert;
import io.github.ascopes.jct.compilers.JctCompilation;
import io.github.ascopes.jct.containers.ModuleContainerGroup;
import io.github.ascopes.jct.containers.OutputContainerGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static io.github.ascopes.jct.tests.helpers.Fixtures.someBoolean;
import static io.github.ascopes.jct.tests.helpers.Fixtures.someText;
import static io.github.ascopes.jct.fixtures.Fixtures.someBoolean;
import static io.github.ascopes.jct.fixtures.Fixtures.someText;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import io.github.ascopes.jct.assertions.LocationAssert;
import javax.tools.JavaFileManager;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -23,7 +23,6 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import io.github.ascopes.jct.assertions.ModuleContainerGroupAssert;
import io.github.ascopes.jct.containers.ModuleContainerGroup;
import io.github.ascopes.jct.containers.PackageContainerGroup;
import io.github.ascopes.jct.filemanagers.ModuleLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.ascopes.jct.tests.unit.assertions;
package io.github.ascopes.jct.assertions;


import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;

import io.github.ascopes.jct.assertions.OutputContainerGroupAssert;
import io.github.ascopes.jct.containers.OutputContainerGroup;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand Down
Loading
Loading