Skip to content

Commit

Permalink
Renaming of type providers.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Aug 18, 2024
1 parent 002e1ac commit b590494
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.structurizr.component;

import com.structurizr.component.provider.DirectoryTypeProvider;
import com.structurizr.component.provider.JarFileTypeProvider;
import com.structurizr.component.provider.SourceCodeTypeProvider;
import com.structurizr.component.provider.ClassDirectoryTypeProvider;
import com.structurizr.component.provider.ClassJarFileTypeProvider;
import com.structurizr.component.provider.SourceDirectoryTypeProvider;
import com.structurizr.component.provider.TypeProvider;
import com.structurizr.model.Container;

Expand All @@ -15,6 +15,8 @@
*/
public class ComponentFinderBuilder {

private static final String JAR_FILE_EXTENSION = ".jar";

private Container container;
private final List<TypeProvider> typeProviders = new ArrayList<>();
private final List<ComponentFinderStrategy> componentFinderStrategies = new ArrayList<>();
Expand All @@ -25,32 +27,32 @@ public ComponentFinderBuilder forContainer(Container container) {
return this;
}

public ComponentFinderBuilder fromJarFile(String filename) {
return fromJarFile(new File(filename));
}

public ComponentFinderBuilder fromJarFile(File file) {
this.typeProviders.add(new JarFileTypeProvider(file));

return this;
public ComponentFinderBuilder fromClasses(String path) {
return fromClasses(new File(path));
}

public ComponentFinderBuilder fromDirectory(String path) {
return fromDirectory(new File(path));
}
public ComponentFinderBuilder fromClasses(File path) {
if (!path.exists()) {
throw new IllegalArgumentException(path.getAbsolutePath() + " does not exist");
}

public ComponentFinderBuilder fromDirectory(File path) {
this.typeProviders.add(new DirectoryTypeProvider(path));
if (path.isDirectory()) {
this.typeProviders.add(new ClassDirectoryTypeProvider(path));
} else if (path.getName().endsWith(JAR_FILE_EXTENSION)) {
this.typeProviders.add(new ClassJarFileTypeProvider(path));
} else {
throw new IllegalArgumentException("Expected a directory of classes or a .jar file: " + path.getAbsolutePath());
}

return this;
}

public ComponentFinderBuilder fromSourceCode(String path) {
return fromSourceCode(new File(path));
public ComponentFinderBuilder fromSource(String path) {
return fromSource(new File(path));
}

public ComponentFinderBuilder fromSourceCode(File path) {
this.typeProviders.add(new SourceCodeTypeProvider(path));
public ComponentFinderBuilder fromSource(File path) {
this.typeProviders.add(new SourceDirectoryTypeProvider(path));

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
/**
* A type repository that uses Apache Commons BCEL to load Java classes from a local directory.
*/
public final class DirectoryTypeProvider implements TypeProvider {
public final class ClassDirectoryTypeProvider implements TypeProvider {

private static final Log log = LogFactory.getLog(DirectoryTypeProvider.class);
private static final Log log = LogFactory.getLog(ClassDirectoryTypeProvider.class);
private static final String CLASS_FILE_EXTENSION = ".class";

private final File directory;

public DirectoryTypeProvider(File directory) {
public ClassDirectoryTypeProvider(File directory) {
this.directory = directory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
/**
* A type repository that uses Apache Commons BCEL to load Java classes from a local JAR file.
*/
public final class JarFileTypeProvider implements TypeProvider {
public final class ClassJarFileTypeProvider implements TypeProvider {

private static final Log log = LogFactory.getLog(JarFileTypeProvider.class);
private static final Log log = LogFactory.getLog(ClassJarFileTypeProvider.class);
private static final String CLASS_FILE_EXTENSION = ".class";

private final File jarFile;

public JarFileTypeProvider(File file) {
public ClassJarFileTypeProvider(File file) {
this.jarFile = file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
/**
* A type provider that uses JavaParser to read Javadoc comments from source code.
*/
public final class SourceCodeTypeProvider implements TypeProvider {
public final class SourceDirectoryTypeProvider implements TypeProvider {

private static final Log log = LogFactory.getLog(SourceCodeTypeProvider.class);
private static final Log log = LogFactory.getLog(SourceDirectoryTypeProvider.class);
private static final String JAVA_FILE_EXTENSION = ".java";
private static final int DEFAULT_DESCRIPTION_LENGTH = 60;

private final Set<Type> types = new HashSet<>();

public SourceCodeTypeProvider(File path) {
public SourceDirectoryTypeProvider(File path) {
this(path, DEFAULT_DESCRIPTION_LENGTH);
}

public SourceCodeTypeProvider(File path, int maximumDescriptionLength) {
public SourceDirectoryTypeProvider(File path, int maximumDescriptionLength) {
StaticJavaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_21);

parse(path, maximumDescriptionLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static void main(String[] args) {

new ComponentFinderBuilder()
.forContainer(container)
.fromDirectory("structurizr-component/build/classes/java/test")
.fromSourceCode("structurizr-component/src/test/java")
.fromClasses("structurizr-component/build/classes/java/test")
.fromSource("structurizr-component/src/test/java")
.withStrategy(
new ComponentFinderStrategyBuilder()
.matchedBy(new NameSuffixTypeMatcher("Controller", "Web MVC Controller"))
Expand Down

0 comments on commit b590494

Please sign in to comment.