Skip to content

Commit

Permalink
Provided scope dependencies are now stored in a separate directory an…
Browse files Browse the repository at this point in the history
…d are only added to compile and test classpaths, but are not included for any runtime or distribution contexts.
  • Loading branch information
gbevin committed Jan 7, 2024
1 parent 6ffd626 commit af6525a
Show file tree
Hide file tree
Showing 27 changed files with 467 additions and 192 deletions.
4 changes: 4 additions & 0 deletions .idea/libraries/compile.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/libraries/test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 39 additions & 3 deletions src/main/java/rife/bld/BaseProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ public class BaseProject extends BuildExecutor {
* @since 1.5
*/
protected File libCompileDirectory = null;
/**
* The provided scope lib directory.
*
* @see #libProvidedDirectory()
* @since 1.8
*/
protected File libProvidedDirectory = null;
/**
* The runtime scope lib directory.
*
Expand Down Expand Up @@ -1010,6 +1017,16 @@ public File libCompileDirectory() {
return Objects.requireNonNullElseGet(libCompileDirectory, () -> new File(libDirectory(), "compile"));
}

/**
* Returns the project provided scope lib directory.
* Defaults to {@code "provided"} relative to {@link #libDirectory()}.
*
* @since 1.8
*/
public File libProvidedDirectory() {
return Objects.requireNonNullElseGet(libProvidedDirectory, () -> new File(libDirectory(), "provided"));
}

/**
* Returns the project runtime scope lib directory.
* Defaults to {@code "runtime"} relative to {@link #libDirectory()}.
Expand Down Expand Up @@ -1130,6 +1147,7 @@ public void createProjectStructure() {
libDirectory().mkdirs();
libBldDirectory().mkdirs();
libCompileDirectory().mkdirs();
libProvidedDirectory().mkdirs();
libRuntimeDirectory().mkdirs();
if (libStandaloneDirectory() != null) {
libStandaloneDirectory().mkdirs();
Expand Down Expand Up @@ -1399,6 +1417,24 @@ public List<File> compileClasspathJars() {
// build the compilation classpath
var classpath = new ArrayList<>(jar_files.stream().map(file -> new File(dir_abs, file)).toList());
addLocalDependencies(classpath, Scope.compile);
return classpath;
}

/**
* Returns all the jar files that are in the provided scope classpath.
* <p>
* By default, this collects all the jar files in the {@link #libProvidedDirectory()}
* and adds all the jar files from the provided scope local dependencies.
*
* @since 1.8
*/
public List<File> providedClasspathJars() {
// detect the jar files in the provided lib directory
var dir_abs = libProvidedDirectory().getAbsoluteFile();
var jar_files = FileUtils.getFileList(dir_abs, INCLUDED_JARS, EXCLUDED_JARS);

// build the compilation classpath
var classpath = new ArrayList<>(jar_files.stream().map(file -> new File(dir_abs, file)).toList());
addLocalDependencies(classpath, Scope.provided);
return classpath;
}
Expand Down Expand Up @@ -1491,7 +1527,7 @@ private void addLocalDependencies(List<File> classpath, Scope scope) {
* @since 1.5
*/
public List<String> compileMainClasspath() {
return FileUtils.combineToAbsolutePaths(compileClasspathJars());
return FileUtils.combineToAbsolutePaths(compileClasspathJars(), providedClasspathJars());
}

/**
Expand All @@ -1505,7 +1541,7 @@ public List<String> compileMainClasspath() {
public List<String> compileTestClasspath() {
var paths = new ArrayList<String>();
paths.add(buildMainDirectory().getAbsolutePath());
paths.addAll(FileUtils.combineToAbsolutePaths(compileClasspathJars(), testClasspathJars()));
paths.addAll(FileUtils.combineToAbsolutePaths(compileClasspathJars(), providedClasspathJars(), testClasspathJars()));
return paths;
}

Expand Down Expand Up @@ -1542,7 +1578,7 @@ public List<String> testClasspath() {
paths.add(srcTestResourcesDirectory().getAbsolutePath());
paths.add(buildMainDirectory().getAbsolutePath());
paths.add(buildTestDirectory().getAbsolutePath());
paths.addAll(FileUtils.combineToAbsolutePaths(compileClasspathJars(), runtimeClasspathJars(), standaloneClasspathJars(), testClasspathJars()));
paths.addAll(FileUtils.combineToAbsolutePaths(compileClasspathJars(), providedClasspathJars(), runtimeClasspathJars(), standaloneClasspathJars(), testClasspathJars()));
return paths;
}

Expand Down
19 changes: 17 additions & 2 deletions src/main/java/rife/bld/dependencies/DependencyScopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,23 @@ public DependencySet scope(Scope scope) {
*/
public DependencySet resolveCompileDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
return resolveScopedDependencies(retriever, repositories,
new Scope[]{Scope.provided, Scope.compile},
new Scope[]{Scope.compile},
new Scope[]{Scope.compile},
null);
}

/**
* Returns the transitive set of dependencies that would be used for the provided scope in a project.
*
* @param retriever the retriever to use to get artifacts
* @param repositories the repositories to use for the resolution
* @return the provided scope dependency set
* @since 1.8
*/
public DependencySet resolveProvidedDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
return resolveScopedDependencies(retriever, repositories,
new Scope[]{Scope.provided},
new Scope[]{Scope.compile, Scope.runtime},
null);
}

Expand All @@ -88,7 +103,7 @@ public DependencySet resolveCompileDependencies(ArtifactRetriever retriever, Lis
*/
public DependencySet resolveRuntimeDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
return resolveScopedDependencies(retriever, repositories,
new Scope[]{Scope.provided, Scope.compile, Scope.runtime},
new Scope[]{Scope.compile, Scope.runtime},
new Scope[]{Scope.compile, Scope.runtime},
resolveCompileDependencies(retriever, repositories));
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/rife/bld/operations/DownloadOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
private final List<Repository> repositories_ = new ArrayList<>();
private final DependencyScopes dependencies_ = new DependencyScopes();
private File libCompileDirectory_;
private File libProvidedDirectory_;
private File libRuntimeDirectory_;
private File libStandaloneDirectory_;
private File libTestDirectory_;
Expand All @@ -41,6 +42,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
*/
public void execute() {
executeDownloadCompileDependencies();
executeDownloadProvidedDependencies();
executeDownloadRuntimeDependencies();
executeDownloadStandaloneDependencies();
executeDownloadTestDependencies();
Expand All @@ -58,6 +60,15 @@ protected void executeDownloadCompileDependencies() {
executeDownloadDependencies(libCompileDirectory(), dependencies().resolveCompileDependencies(artifactRetriever(), repositories()));
}

/**
* Part of the {@link #execute} operation, download the {@code provided} scope artifacts.
*
* @since 1.8
*/
protected void executeDownloadProvidedDependencies() {
executeDownloadDependencies(libProvidedDirectory(), dependencies().resolveProvidedDependencies(artifactRetriever(), repositories()));
}

/**
* Part of the {@link #execute} operation, download the {@code runtime} scope artifacts.
*
Expand Down Expand Up @@ -123,6 +134,7 @@ public DownloadOperation fromProject(BaseProject project) {
.repositories(project.repositories())
.dependencies(project.dependencies())
.libCompileDirectory(project.libCompileDirectory())
.libProvidedDirectory(project.libProvidedDirectory())
.libRuntimeDirectory(project.libRuntimeDirectory())
.libStandaloneDirectory(project.libStandaloneDirectory())
.libTestDirectory(project.libTestDirectory())
Expand Down Expand Up @@ -180,6 +192,18 @@ public DownloadOperation libCompileDirectory(File directory) {
return this;
}

/**
* Provides the {@code provided} scope download directory.
*
* @param directory the directory to download the {@code provided} scope artifacts into
* @return this operation instance
* @since 1.8
*/
public DownloadOperation libProvidedDirectory(File directory) {
libProvidedDirectory_ = directory;
return this;
}

/**
* Provides the {@code runtime} scope download directory.
*
Expand Down Expand Up @@ -288,6 +312,16 @@ public File libCompileDirectory() {
return libCompileDirectory_;
}

/**
* Retrieves the {@code provided} scope download directory.
*
* @return the {@code provided} scope download directory
* @since 1.8
*/
public File libProvidedDirectory() {
return libProvidedDirectory_;
}

/**
* Retrieves the {@code runtime} scope download directory.
*
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/rife/bld/operations/PurgeOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
private final List<Repository> repositories_ = new ArrayList<>();
private final DependencyScopes dependencies_ = new DependencyScopes();
private File libCompileDirectory_;
private File libProvidedDirectory_;
private File libRuntimeDirectory_;
private File libStandaloneDirectory_;
private File libTestDirectory_;
Expand All @@ -41,6 +42,7 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
*/
public void execute() {
executePurgeCompileDependencies();
executePurgeProvidedDependencies();
executePurgeRuntimeDependencies();
executePurgeStandaloneDependencies();
executePurgeTestDependencies();
Expand All @@ -58,6 +60,15 @@ protected void executePurgeCompileDependencies() {
executePurgeDependencies(libCompileDirectory(), dependencies().resolveCompileDependencies(artifactRetriever(), repositories()));
}

/**
* Part of the {@link #execute} operation, purge the {@code provided} scope artifacts.
*
* @since 1.8
*/
protected void executePurgeProvidedDependencies() {
executePurgeDependencies(libProvidedDirectory(), dependencies().resolveProvidedDependencies(artifactRetriever(), repositories()));
}

/**
* Part of the {@link #execute} operation, purge the {@code runtime} scope artifacts.
*
Expand Down Expand Up @@ -137,6 +148,7 @@ public PurgeOperation fromProject(BaseProject project) {
.repositories(project.repositories())
.dependencies(project.dependencies())
.libCompileDirectory(project.libCompileDirectory())
.libProvidedDirectory(project.libProvidedDirectory())
.libRuntimeDirectory(project.libRuntimeDirectory())
.libStandaloneDirectory(project.libStandaloneDirectory())
.libTestDirectory(project.libTestDirectory())
Expand Down Expand Up @@ -220,6 +232,18 @@ public PurgeOperation libCompileDirectory(File directory) {
return this;
}

/**
* Provides the {@code provided} scope purge directory.
*
* @param directory the directory to purge the {@code provided} scope artifacts from
* @return this operation instance
* @since 1.8
*/
public PurgeOperation libProvidedDirectory(File directory) {
libProvidedDirectory_ = directory;
return this;
}

/**
* Provides the {@code runtime} scope purge directory.
*
Expand Down Expand Up @@ -302,6 +326,16 @@ public File libCompileDirectory() {
return libCompileDirectory_;
}

/**
* Retrieves the {@code provided} scope purge directory.
*
* @return the {@code provided} scope purge directory
* @since 1.8
*/
public File libProvidedDirectory() {
return libProvidedDirectory_;
}

/**
* Retrieves the {@code runtime} scope purge directory.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/BLD_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.6-SNAPSHOT
1.8.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
<library name="compile">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/compile" />
<root url="file://$PROJECT_DIR$/lib/provided" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/compile" />
<root url="file://$PROJECT_DIR$/lib/provided" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" type="SOURCES" />
<jarDirectory url="file://$PROJECT_DIR$/lib/provided" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/provided" recursive="false" type="SOURCES" />
</library>
</component>
4 changes: 4 additions & 0 deletions src/main/resources/templates/bld/base/idea/libraries/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
<library name="test">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/test" />
<root url="file://$PROJECT_DIR$/lib/provided" />
<root url="file://$PROJECT_DIR$/src/test/resources" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/test" />
<root url="file://$PROJECT_DIR$/lib/provided" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" type="SOURCES" />
<jarDirectory url="file://$PROJECT_DIR$/lib/provided" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/provided" recursive="false" type="SOURCES" />
</library>
</component>
1 change: 1 addition & 0 deletions src/main/resources/templates/bld/base/vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-{{v version/}}.jar",
"lib/compile/*.jar",
"lib/provided/*.jar",
"lib/runtime/*.jar",
"lib/test/*.jar"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
<library name="compile">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/compile" />
<root url="file://$PROJECT_DIR$/lib/provided" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/compile" />
<root url="file://$PROJECT_DIR$/lib/provided" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" type="SOURCES" />
<jarDirectory url="file://$PROJECT_DIR$/lib/provided" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/provided" recursive="false" type="SOURCES" />
</library>
</component>
Loading

0 comments on commit af6525a

Please sign in to comment.