Skip to content

Commit

Permalink
Cleaned up API to match bld operations and options APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Aug 27, 2024
1 parent 7b6e75d commit f340aed
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Don't forget to include the _Spring Boot Loader_ dependency to your project:

```java
scope(standalone)
.include(dependency("org.springframeworkboot:spring-boot-loader:3.3.2"));
.include(dependency("org.springframeworkboot:spring-boot-loader:3.3.3"));
```

Please check the [BootJarOperation documentation](https://rife2.github.io/bld-spring-boot/rife/bld/extension/BootJarOperation.html#method-summary)
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.downloadLocation=
bld.extension-boot=com.uwyn.rife2:bld-spring-boot:0.9.7
bld.extension-boot=com.uwyn.rife2:bld-spring-boot:0.9.8-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories=
bld.version=2.0.1
158 changes: 125 additions & 33 deletions src/main/java/rife/bld/extension/AbstractBootOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -89,6 +92,17 @@ public T destinationDirectory(String directory) throws IOException {
return destinationDirectory(new File(directory));
}

/**
* Provides the destination directory in which the archive will be created.
*
* @param directory the destination directory
* @return this operation instance
* @throws IOException if an error occurs
*/
public T destinationDirectory(Path directory) throws IOException {
return destinationDirectory(directory.toFile());
}

/**
* Provides the file name that will be used for the archive creation.
*
Expand Down Expand Up @@ -275,9 +289,17 @@ public T infLibs(Collection<File> jars) {
* @return this operation instance
*/
public T infLibs(File... jars) {
infLibs_.addAll(List.of(jars));
//noinspection unchecked
return (T) this;
return infLibs(List.of(jars));
}

/**
* Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public T infLibs(Path... jars) {
return infLibsPaths(List.of(jars));
}

/**
Expand All @@ -287,9 +309,7 @@ public T infLibs(File... jars) {
* @return this operation instance
*/
public T infLibs(String... jars) {
infLibs_.addAll(Arrays.stream(jars).map(File::new).toList());
//noinspection unchecked
return (T) this;
return infLibsStrings(List.of(jars));
}

/**
Expand All @@ -301,6 +321,26 @@ public Collection<File> infLibs() {
return infLibs_;
}

/**
* Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public T infLibsPaths(Collection<Path> jars) {
return infLibs(jars.stream().map(Path::toFile).toList());
}

/**
* Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public T infLibsStrings(Collection<String> jars) {
return infLibs(jars.stream().map(File::new).toList());
}

/**
* Provides the Spring Boot loader launcher fully-qualified class name.
* <p>
Expand Down Expand Up @@ -367,17 +407,8 @@ public T launcherLibs(Collection<File> jars) throws IOException {
* @return this operation instance
* @throws IOException if a JAR could not be found
*/
@SuppressWarnings("UnusedReturnValue")
public T launcherLibs(File... jars) throws IOException {
for (var j : jars) {
if (j.exists()) {
launcherLibs_.add(j);
} else {
throw new IOException("Spring Boot loader launcher library not found: " + j);
}
}
//noinspection unchecked
return (T) this;
return launcherLibs(List.of(jars));
}

/**
Expand All @@ -387,18 +418,41 @@ public T launcherLibs(File... jars) throws IOException {
* @return this operation instance
* @throws IOException if a JAR could not be found
*/
@SuppressWarnings("UnusedReturnValue")
public T launcherLibs(String... jars) throws IOException {
for (var j : jars) {
var p = Path.of(j);
if (Files.exists(p)) {
launcherLibs_.add(p.toFile());
} else {
throw new IOException("Spring Boot loader launcher library not found: " + j);
}
}
//noinspection unchecked
return (T) this;
return launcherLibsStrings(List.of(jars));
}

/**
* Provides the libraries for the Spring Boot loader launcher.
*
* @param jars one or more Java archives
* @return this operation instance
* @throws IOException if a JAR could not be found
*/
public T launcherLibs(Path... jars) throws IOException {
return launcherLibsPaths(List.of(jars));
}

/**
* Provides the libraries for the Spring Boot loader launcher.
*
* @param jars one or more Java archives
* @return this operation instance
* @throws IOException if a JAR could not be found
*/
public T launcherLibsPaths(Collection<Path> jars) throws IOException {
return launcherLibs(jars.stream().map(Path::toFile).toList());
}

/**
* Provides the libraries for the Spring Boot loader launcher.
*
* @param jars one or more Java archives
* @return this operation instance
* @throws IOException if a JAR could not be found
*/
public T launcherLibsStrings(Collection<String> jars) throws IOException {
return launcherLibs(jars.stream().map(File::new).toList());
}

/**
Expand Down Expand Up @@ -463,22 +517,40 @@ public T manifestAttributes(Map<String, String> attributes) {
* @param directories one or more source directories
* @return this operation instance
*/
public T sourceDirectories(File... directories) {
sourceDirectories_.addAll(List.of(directories));
public T sourceDirectories(Collection<File> directories) {
sourceDirectories_.addAll(directories);
//noinspection unchecked
return (T) this;
}

/**
* Provides source directories that will be used for the archive creation.
*
* @param directories one or more source directories
* @return this operation instance
*/
public T sourceDirectories(File... directories) {
return sourceDirectories(List.of(directories));
}

/**
* Provides source directories that will be used for the archive creation.
*
* @param directories one or more source directories
* @return this operation instance
*/
public T sourceDirectories(String... directories) {
sourceDirectories_.addAll(Arrays.stream(directories).map(File::new).toList());
//noinspection unchecked
return (T) this;
return sourceDirectoriesStrings(List.of(directories));
}

/**
* Provides source directories that will be used for the archive creation.
*
* @param directories one or more source directories
* @return this operation instance
*/
public T sourceDirectories(Path... directories) {
return sourceDirectoriesPaths(List.of(directories));
}

/**
Expand All @@ -490,6 +562,26 @@ public Collection<File> sourceDirectories() {
return sourceDirectories_;
}

/**
* Provides source directories that will be used for the archive creation.
*
* @param directories one or more source directories
* @return this operation instance
*/
public T sourceDirectoriesPaths(Collection<Path> directories) {
return sourceDirectories(directories.stream().map(Path::toFile).toList());
}

/**
* Provides source directories that will be used for the archive creation.
*
* @param directories one or more source directories
* @return this operation instance
*/
public T sourceDirectoriesStrings(Collection<String> directories) {
return sourceDirectories(directories.stream().map(File::new).toList());
}

/**
* Verifies that all the elements ({@link #mainClass() mainClass}, {@link #launcherClass() launcherClass} and
* {@link #launcherLibs() launcherLibs}) required to create the archive have been provided, throws an
Expand Down
53 changes: 52 additions & 1 deletion src/main/java/rife/bld/extension/BootWarOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -151,14 +152,64 @@ public BootWarOperation providedLibs(Collection<File> jars) {
return this;
}

/**
* Provides the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public BootWarOperation providedLibs(String... jars) {
return providedLibsStrings(List.of(jars));
}

/**
* Provides the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public BootWarOperation providedLibs(File... jars) {
providedLibs_.addAll(List.of(jars));
return providedLibs(List.of(jars));
}

/**
* Provides the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public BootWarOperation providedLibs(Path... jars) {
return providedLibsPaths(List.of(jars));
}

/**
* Retrieves the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @return the list of Java archive files.
*/
public List<File> providedLibs() {
return providedLibs_;
}

/**
* Provides the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public BootWarOperation providedLibsPaths(Collection<Path> jars) {
providedLibs_.addAll(jars.stream().map(Path::toFile).toList());
return this;
}

/**
* Provides the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @param jars one or more Java archive files
* @return this operation instance
*/
public BootWarOperation providedLibsStrings(Collection<String> jars) {
providedLibs_.addAll(jars.stream().map(File::new).toList());
return this;
}
}
Loading

0 comments on commit f340aed

Please sign in to comment.