Skip to content

Commit

Permalink
Merge 46c63a0 into 11b90af
Browse files Browse the repository at this point in the history
  • Loading branch information
pith committed Mar 28, 2016
2 parents 11b90af + 46c63a0 commit b22c294
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,10 @@ public Map<String, Plugin> plugins()
{
return this.pluginRegistry.getPluginsByName();
}

@Override
public Set<URL> scannedURLs()
{
return requestHandler.getUrls();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private void initScanner()
printWarnWhenScanningAllClasspath();
ClasspathScannerFactory classpathScannerFactory = new ClasspathScannerFactory(options.get(CLASSPATH_SCAN_MODE));
classpathScanner = classpathScannerFactory.create(classpathStrategy, additionalClasspathScan, packageRoots);
addUrls(classpathScanner.getUrls());
}

private void printWarnWhenScanningAllClasspath()
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/io/nuun/kernel/core/internal/ScanResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.kametic.specifications.Specification;

import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.*;

import static java.util.Collections.*;
Expand All @@ -44,6 +45,7 @@ public class ScanResults
private final Map<String, Collection<String>> propertyFilesByPrefix = new HashMap<String, Collection<String>>();
private final Map<String, Collection<String>> resourcesByRegex = new HashMap<String, Collection<String>>();
private final Collection<String> propertyFiles = new HashSet<String>();
private final Set<URL> urls = new HashSet<URL>();

protected static class Key
{
Expand Down Expand Up @@ -139,6 +141,15 @@ public Collection<String> getPropertyFiles()
return unmodifiableCollection(propertyFiles);
}

public Set<URL> getUrls()
{
return urls;
}

public void addUrls(Set<URL> urls) {
this.urls.addAll(urls);
}

public void addClassesToBind(Collection<Class<?>> classesToBind) {
this.classesToBind.addAll(classesToBind);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
*/
package io.nuun.kernel.core.internal.scanner;

import org.kametic.specifications.Specification;

import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.Collection;
import java.util.Set;

import org.kametic.specifications.Specification;

public interface ClasspathScanner
{
Collection<Class<?>> scanTypes(String typeRegex);
Expand All @@ -41,4 +42,6 @@ public interface ClasspathScanner
Collection<Class<?>> scanSubTypesOf(String typeRegex);

Set<String> scanResources(String pattern);

Set<URL> getUrls();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public ClasspathScannerDisk(ClasspathStrategy classpathStrategy, boolean reachAb

protected void initializeReflections()
{
ConfigurationBuilder configurationBuilder = configurationBuilder().addUrls(findClasspathUrls()).setScanners(getScanners());
ConfigurationBuilder configurationBuilder = configurationBuilder()
.addUrls(findClasspathUrls()).setScanners(getScanners());

reflections = new Reflections(configurationBuilder);
}

Expand Down Expand Up @@ -116,6 +118,11 @@ private Set<URL> findClasspathUrls()
return urls;
}

public Set<URL> getUrls()
{
return Collections.unmodifiableSet(urls);
}

@Override
public Collection<Class<?>> scanTypes(final Specification<Class<?>> specification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
import io.nuun.kernel.api.inmemory.ClasspathAbstractContainer;
import io.nuun.kernel.core.KernelException;
import io.nuun.kernel.core.internal.scanner.disk.ClasspathScannerDisk;

import java.net.MalformedURLException;
import java.util.Iterator;

import org.reflections.Reflections;
import org.reflections.scanners.Scanner;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.vfs.Vfs;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;

/**
* @author epo.jemba{@literal @}kametic.com
*/
public class ClasspathScannerInMemory extends ClasspathScannerDisk
{
private final Classpath classpath;
private final Set<URL> urls = new HashSet<URL>();

public ClasspathScannerInMemory(Classpath classpath, String... packageRoot)
{
Expand Down Expand Up @@ -62,9 +62,16 @@ private void actualInitReflections() {
throw new KernelException("Malformed URL Exception", e);
}
}
urls.addAll(configurationBuilder.getUrls());
reflections = new Reflections(configurationBuilder);
}

@Override
public Set<URL> getUrls()
{
return urls;
}

@Override
protected void initializeReflections() {
// override the Reflections initialization in the super constructor.
Expand Down
17 changes: 11 additions & 6 deletions core/src/test/java/it/ClasspathScanningIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import it.fixture.scan.ClassToScan1;
import it.fixture.scan.ClassToScan2;
import it.fixture.scan.ScanningPlugin;
import org.assertj.core.api.Assertions;
import org.junit.Test;

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

/**
* This class tests the features associated with the scan done by Reflections.
*
Expand All @@ -45,13 +46,17 @@ public void test_class_scan_and_ignored_policy() {
.option(KernelOptions.ROOT_PACKAGES, Lists.newArrayList("it.fixture.scan"))
.addPlugin(ScanningPlugin.class);

Kernel kernel = NuunCore.createKernel(kernelConfig);
Kernel kernel = NuunCore.createKernel(kernelConfig);
assertThat(kernel.scannedURLs()).isNotNull();
assertThat(kernel.scannedURLs()).isEmpty();
kernel.init();

Assertions.assertThat(kernel.plugins()).hasSize(1);
Assertions.assertThat(kernel.plugins().get(ScanningPlugin.NAME)).isInstanceOf(ScanningPlugin.class);
assertThat(kernel.plugins()).hasSize(1);
assertThat(kernel.plugins().get(ScanningPlugin.NAME)).isInstanceOf(ScanningPlugin.class);
ScanningPlugin scanningPlugin = (ScanningPlugin) kernel.plugins().get(ScanningPlugin.NAME);
Assertions.assertThat(scanningPlugin.getScannedClasses()).hasSize(2);
Assertions.assertThat(scanningPlugin.getScannedClasses()).containsOnly(ClassToScan1.class, ClassToScan2.class);
assertThat(scanningPlugin.getScannedClasses()).hasSize(2);
assertThat(scanningPlugin.getScannedClasses()).containsOnly(ClassToScan1.class, ClassToScan2.class);

assertThat(kernel.scannedURLs()).isNotEmpty();
}
}
4 changes: 4 additions & 0 deletions specs/src/main/java/io/nuun/kernel/api/Kernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import io.nuun.kernel.api.di.ObjectGraph;
import io.nuun.kernel.api.di.UnitModule;

import java.net.URL;
import java.util.Map;
import java.util.Set;

/**
* The Kernel is the main component of the I.O.C. technical stack.
Expand Down Expand Up @@ -128,6 +130,8 @@ public interface Kernel
*/
GlobalModule globalModule();

Set<URL> scannedURLs();

/**
* Tell the kernel to start. Then the kernel will create the ObjectGraph of the application. The ObjectGraph will wrap the actual Guice injector.
* <p>
Expand Down

0 comments on commit b22c294

Please sign in to comment.