-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved jandex dependent classes to separate package
- Loading branch information
1 parent
a241a52
commit 1fd9c61
Showing
7 changed files
with
163 additions
and
155 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...g/fuin/utils4j/JandexIndexFileReader.java → ...utils4j/jandex/JandexIndexFileReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g/fuin/utils4j/JandexIndexFileWriter.java → ...utils4j/jandex/JandexIndexFileWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.fuin.utils4j; | ||
package org.fuin.utils4j.jandex; | ||
|
||
import org.jboss.jandex.*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
300 changes: 151 additions & 149 deletions
300
...ava/org/fuin/utils4j/JandexUtilsTest.java → .../fuin/utils4j/jandex/JandexUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,149 +1,151 @@ | ||
/** | ||
* Copyright (C) 2015 Michael Schnell. All rights reserved. | ||
* http://www.fuin.org/ | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package org.fuin.utils4j; | ||
|
||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.Indexer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
/** | ||
* Tests for {@link JandexUtils}. | ||
*/ | ||
// CHECKSTYLE:OFF | ||
public class JandexUtilsTest { | ||
|
||
private static final File TARGET_DIR = new File("target"); | ||
|
||
private static final File CLASSES_DIR = new File(TARGET_DIR, "classes"); | ||
|
||
private static final File TEST_CLASSES_DIR = new File(TARGET_DIR, "test-classes"); | ||
|
||
@Test | ||
public final void testIndexClassFile() { | ||
|
||
// PREPARE | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final File classFile = new File(CLASSES_DIR, JandexUtils.class.getName().replace('.', '/') + ".class"); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
assertThat(JandexUtils.indexClassFile(indexer, knownFiles, classFile)).isTrue(); | ||
assertThat(JandexUtils.indexClassFile(indexer, knownFiles, classFile)).isFalse(); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(knownFiles).contains(classFile); | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexDirSimple() { | ||
|
||
// TEST | ||
final Index index = JandexUtils.indexDir(CLASSES_DIR); | ||
|
||
// VERIFY | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
assertThat(index.getClassByName(DotName.createSimple(Utils4J.class.getName()))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexDir() { | ||
|
||
// PREPARE | ||
final File jandexClassFile = new File(CLASSES_DIR, JandexUtils.class.getName().replace('.', '/') + ".class"); | ||
final File utils4JClassFile = new File(CLASSES_DIR, Utils4J.class.getName().replace('.', '/') + ".class"); | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final File classesDir = new File("target/classes"); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
JandexUtils.indexDir(indexer, knownFiles, classesDir); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(knownFiles).contains(jandexClassFile); | ||
assertThat(knownFiles).contains(utils4JClassFile); | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
assertThat(index.getClassByName(DotName.createSimple(Utils4J.class.getName()))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexJar() { | ||
|
||
// PREPARE | ||
final File jarFile = new File("src/test/resources/ext4logback-0.2.0.jar"); | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
assertThat(JandexUtils.indexJar(indexer, knownFiles, jarFile)).isTrue(); | ||
assertThat(JandexUtils.indexJar(indexer, knownFiles, jarFile)).isFalse(); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(knownFiles).contains(jarFile); | ||
assertThat(index.getClassByName(DotName.createSimple("org.fuin.ext4logback.LogbackStandalone"))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexClasspath() throws IOException { | ||
|
||
// PREPARE | ||
final File jandexClassFile = new File(CLASSES_DIR, JandexUtils.class.getName().replace('.', '/') + ".class") | ||
.getCanonicalFile(); | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
JandexUtils.indexClasspath(indexer, knownFiles); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
assertThat(knownFiles).contains(jandexClassFile); | ||
|
||
} | ||
|
||
@Test | ||
public final void loadClassOK() { | ||
assertThat(JandexUtils.loadClass(DotName.createSimple(Utils4J.class))).isEqualTo(Utils4J.class); | ||
} | ||
|
||
@Test | ||
public final void loadClassFailure() { | ||
assertThatThrownBy(() -> JandexUtils.loadClass(DotName.createSimple("a.b.c.d.DoesNotExist"))) | ||
.isInstanceOf(RuntimeException.class) | ||
.hasMessageContaining("Failed to load class"); | ||
} | ||
|
||
} | ||
// CHECKSTYLE:ON | ||
/** | ||
* Copyright (C) 2015 Michael Schnell. All rights reserved. | ||
* http://www.fuin.org/ | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package org.fuin.utils4j.jandex; | ||
|
||
import org.fuin.utils4j.Utils4J; | ||
import org.fuin.utils4j.jandex.JandexUtils; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Index; | ||
import org.jboss.jandex.Indexer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
/** | ||
* Tests for {@link JandexUtils}. | ||
*/ | ||
// CHECKSTYLE:OFF | ||
public class JandexUtilsTest { | ||
|
||
private static final File TARGET_DIR = new File("target"); | ||
|
||
private static final File CLASSES_DIR = new File(TARGET_DIR, "classes"); | ||
|
||
private static final File TEST_CLASSES_DIR = new File(TARGET_DIR, "test-classes"); | ||
|
||
@Test | ||
public final void testIndexClassFile() { | ||
|
||
// PREPARE | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final File classFile = new File(CLASSES_DIR, JandexUtils.class.getName().replace('.', '/') + ".class"); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
assertThat(JandexUtils.indexClassFile(indexer, knownFiles, classFile)).isTrue(); | ||
assertThat(JandexUtils.indexClassFile(indexer, knownFiles, classFile)).isFalse(); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(knownFiles).contains(classFile); | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexDirSimple() { | ||
|
||
// TEST | ||
final Index index = JandexUtils.indexDir(CLASSES_DIR); | ||
|
||
// VERIFY | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
assertThat(index.getClassByName(DotName.createSimple(Utils4J.class.getName()))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexDir() { | ||
|
||
// PREPARE | ||
final File jandexClassFile = new File(CLASSES_DIR, JandexUtils.class.getName().replace('.', '/') + ".class"); | ||
final File utils4JClassFile = new File(CLASSES_DIR, Utils4J.class.getName().replace('.', '/') + ".class"); | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final File classesDir = new File("target/classes"); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
JandexUtils.indexDir(indexer, knownFiles, classesDir); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(knownFiles).contains(jandexClassFile); | ||
assertThat(knownFiles).contains(utils4JClassFile); | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
assertThat(index.getClassByName(DotName.createSimple(Utils4J.class.getName()))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexJar() { | ||
|
||
// PREPARE | ||
final File jarFile = new File("src/test/resources/ext4logback-0.2.0.jar"); | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
assertThat(JandexUtils.indexJar(indexer, knownFiles, jarFile)).isTrue(); | ||
assertThat(JandexUtils.indexJar(indexer, knownFiles, jarFile)).isFalse(); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(knownFiles).contains(jarFile); | ||
assertThat(index.getClassByName(DotName.createSimple("org.fuin.ext4logback.LogbackStandalone"))).isNotNull(); | ||
|
||
} | ||
|
||
@Test | ||
public final void testIndexClasspath() throws IOException { | ||
|
||
// PREPARE | ||
final File jandexClassFile = new File(CLASSES_DIR, JandexUtils.class.getName().replace('.', '/') + ".class") | ||
.getCanonicalFile(); | ||
final List<File> knownFiles = new ArrayList<File>(); | ||
final Indexer indexer = new Indexer(); | ||
|
||
// TEST | ||
JandexUtils.indexClasspath(indexer, knownFiles); | ||
|
||
// VERIFY | ||
final Index index = indexer.complete(); | ||
assertThat(index.getClassByName(DotName.createSimple(JandexUtils.class.getName()))).isNotNull(); | ||
assertThat(knownFiles).contains(jandexClassFile); | ||
|
||
} | ||
|
||
@Test | ||
public final void loadClassOK() { | ||
assertThat(JandexUtils.loadClass(DotName.createSimple(Utils4J.class))).isEqualTo(Utils4J.class); | ||
} | ||
|
||
@Test | ||
public final void loadClassFailure() { | ||
assertThatThrownBy(() -> JandexUtils.loadClass(DotName.createSimple("a.b.c.d.DoesNotExist"))) | ||
.isInstanceOf(RuntimeException.class) | ||
.hasMessageContaining("Failed to load class"); | ||
} | ||
|
||
} | ||
// CHECKSTYLE:ON |
Binary file not shown.