Skip to content

Commit

Permalink
Improvement to offline operation, now pushed to the actual operations…
Browse files Browse the repository at this point in the history
… instead of the commands
  • Loading branch information
gbevin committed Jul 18, 2024
1 parent d904fd2 commit a02e788
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 33 deletions.
Binary file modified lib/bld/bld-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.downloadLocation=
bld.downloadLocation=file:/Users/gbevin/.m2/repository/com/uwyn/rife2/bld/2.0.0-SNAPSHOT/
bld.extension-antlr=com.uwyn.rife2:bld-antlr4:1.2.8
bld.extension-archive=com.uwyn.rife2:bld-archive:0.4.8
bld.extension-tests=com.uwyn.rife2:bld-tests-badge:1.4.8
Expand Down
23 changes: 4 additions & 19 deletions src/main/java/rife/bld/BaseProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,7 @@ public void compile()
@BuildCommand(value = "dependency-tree", help = DependencyTreeHelp.class)
public void dependencyTree()
throws Exception {
if (isOffline()) {
System.out.println("Offline mode: dependency-tree is disabled");
}
else {
dependencyTreeOperation().executeOnce(() -> dependencyTreeOperation().fromProject(this));
}
dependencyTreeOperation().executeOnce(() -> dependencyTreeOperation().fromProject(this));
}

/**
Expand All @@ -501,12 +496,7 @@ public void dependencyTree()
@BuildCommand(help = DownloadHelp.class)
public void download()
throws Exception {
if (isOffline()) {
System.out.println("Offline mode: download is disabled");
}
else {
downloadOperation().executeOnce(() -> downloadOperation().fromProject(this));
}
downloadOperation().executeOnce(() -> downloadOperation().fromProject(this));
}

/**
Expand All @@ -517,12 +507,7 @@ public void download()
@BuildCommand(help = PurgeHelp.class)
public void purge()
throws Exception {
if (isOffline()) {
System.out.println("Offline mode: purge is disabled");
}
else {
purgeOperation().executeOnce(() -> purgeOperation().fromProject(this));
}
purgeOperation().executeOnce(() -> purgeOperation().fromProject(this));
}

/**
Expand Down Expand Up @@ -1689,7 +1674,7 @@ private void writeHash(File hashFile, String hash) {

@Override
public int execute(String[] arguments) {
if (!isOffline() &&
if (!offline() &&
autoDownloadPurge()) {
performAutoDownloadPurge();
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/rife/bld/BuildExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import rife.bld.operations.HelpOperation;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.ioc.HierarchicalProperties;
import rife.template.Template;
import rife.template.TemplateFactory;
import rife.tools.ExceptionUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;
Expand Down Expand Up @@ -134,7 +131,7 @@ public static HierarchicalProperties setupProperties(File workDirectory) {
* or {@code false} otherwise
* @since 2.0
*/
public boolean isOffline() {
public boolean offline() {
return offline_;
}

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/rife/bld/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,7 @@ public void publish()
jar();
jarSources();
jarJavadoc();
if (isOffline()) {
System.out.println("Offline mode: publish is disabled");
}
else {
publishOperation().executeOnce(() -> publishOperation().fromProject(this));
}
publishOperation().executeOnce(() -> publishOperation().fromProject(this));
}

/**
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/rife/bld/operations/DependencyTreeOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @since 1.5.21
*/
public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOperation> {
private boolean offline_ = false;
private HierarchicalProperties properties_ = null;
private HierarchicalProperties extensionProperties_ = null;
private ArtifactRetriever retriever_ = null;
Expand All @@ -40,6 +41,11 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
* @since 1.5.21
*/
public void execute() {
if (offline_) {
System.out.println("Offline mode: dependency-tree is disabled");
return;
}

var extensions_tree = executeGenerateExtensionsDependencies();
var compile_tree = executeGenerateCompileDependencies();
var provided_tree = executeGenerateProvidedDependencies();
Expand Down Expand Up @@ -157,12 +163,37 @@ public DependencyTreeOperation fromProject(BaseProject project) {
}

// add the repositories and the dependencies from the project
return properties(project.properties())
return offline(project.offline())
.properties(project.properties())
.artifactRetriever(project.artifactRetriever())
.repositories(project.repositories())
.dependencies(project.dependencies());
}

/**
* Indicates whether the operation has to run offline.
*
* @param flag {@code true} if the operation runs offline; or
* {@code false} otherwise
* @return this operation instance
* @since 2.0
*/
public DependencyTreeOperation offline(boolean flag) {
offline_ = flag;
return this;
}

/**
* Returns whether the operation has to run offline.
*
* @return {@code true} if the operation runs offline; or
* {@code false} otherwise
* @since 2.0
*/
public boolean offline() {
return offline_;
}

/**
* Provides repositories to resolve the dependencies against.
*
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/rife/bld/operations/DownloadOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @since 1.5
*/
public class DownloadOperation extends AbstractOperation<DownloadOperation> {
private boolean offline_ = false;
private HierarchicalProperties properties_ = null;
private ArtifactRetriever retriever_ = null;
private final List<Repository> repositories_ = new ArrayList<>();
Expand All @@ -43,6 +44,11 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
* @since 1.5
*/
public void execute() {
if (offline_) {
System.out.println("Offline mode: download is disabled");
return;
}

executeDownloadCompileDependencies();
executeDownloadProvidedDependencies();
executeDownloadRuntimeDependencies();
Expand Down Expand Up @@ -133,7 +139,8 @@ protected void executeDownloadDependencies(File destinationDirectory, Dependency
* @since 1.5
*/
public DownloadOperation fromProject(BaseProject project) {
return properties(project.properties())
return offline(project.offline())
.properties(project.properties())
.artifactRetriever(project.artifactRetriever())
.repositories(project.repositories())
.dependencies(project.dependencies())
Expand All @@ -146,6 +153,30 @@ public DownloadOperation fromProject(BaseProject project) {
.downloadJavadoc(project.downloadJavadoc());
}

/**
* Indicates whether the operation has to run offline.
*
* @param flag {@code true} if the operation runs offline; or
* {@code false} otherwise
* @return this operation instance
* @since 2.0
*/
public DownloadOperation offline(boolean flag) {
offline_ = flag;
return this;
}

/**
* Returns whether the operation has to run offline.
*
* @return {@code true} if the operation runs offline; or
* {@code false} otherwise
* @since 2.0
*/
public boolean offline() {
return offline_;
}

/**
* Provides repositories to resolve the dependencies against.
*
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/rife/bld/operations/PublishOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @since 1.5.7
*/
public class PublishOperation extends AbstractOperation<PublishOperation> {
private boolean offline_ = false;
private HierarchicalProperties properties_ = null;
private ArtifactRetriever retriever_ = null;
private final HttpClient client_ = HttpClient.newHttpClient();
Expand All @@ -56,6 +57,11 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
* @since 1.5.7
*/
public void execute() {
if (offline_) {
System.out.println("Offline mode: publish is disabled");
return;
}

if (repositories().isEmpty()) {
throw new OperationOptionException("ERROR: the publication repositories should be specified");
}
Expand Down Expand Up @@ -506,6 +512,7 @@ public PublishOperation fromProject(BaseProject project) {
.mavenCompilerSource(project.javaRelease())
.mavenCompilerTarget(project.javaRelease());
}
offline(project.offline());
properties(project.properties());
artifactRetriever(project.artifactRetriever());
dependencies().include(project.dependencies());
Expand All @@ -528,6 +535,30 @@ public PublishOperation fromProject(BaseProject project) {
return this;
}

/**
* Indicates whether the operation has to run offline.
*
* @param flag {@code true} if the operation runs offline; or
* {@code false} otherwise
* @return this operation instance
* @since 2.0
*/
public PublishOperation offline(boolean flag) {
offline_ = flag;
return this;
}

/**
* Returns whether the operation has to run offline.
*
* @return {@code true} if the operation runs offline; or
* {@code false} otherwise
* @since 2.0
*/
public boolean offline() {
return offline_;
}

/**
* Provides the moment of publication.
* <p>
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/rife/bld/operations/PurgeOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @since 1.5
*/
public class PurgeOperation extends AbstractOperation<PurgeOperation> {
private boolean offline_ = false;
private HierarchicalProperties properties_ = null;
private ArtifactRetriever retriever_ = null;
private final List<Repository> repositories_ = new ArrayList<>();
Expand All @@ -43,6 +44,11 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
* @since 1.5
*/
public void execute() {
if (offline_) {
System.out.println("Offline mode: purge is disabled");
return;
}

executePurgeCompileDependencies();
executePurgeProvidedDependencies();
executePurgeRuntimeDependencies();
Expand Down Expand Up @@ -147,7 +153,8 @@ private void addTransferLocations(HashSet<String> filenames, Dependency dependen
* @since 1.5
*/
public PurgeOperation fromProject(BaseProject project) {
return properties(project.properties())
return offline(project.offline())
.properties(project.properties())
.artifactRetriever(project.artifactRetriever())
.repositories(project.repositories())
.dependencies(project.dependencies())
Expand All @@ -160,6 +167,30 @@ public PurgeOperation fromProject(BaseProject project) {
.preserveJavadoc(project.downloadJavadoc());
}

/**
* Indicates whether the operation has to run offline.
*
* @param flag {@code true} if the operation runs offline; or
* {@code false} otherwise
* @return this operation instance
* @since 2.0
*/
public PurgeOperation offline(boolean flag) {
offline_ = flag;
return this;
}

/**
* Returns whether the operation has to run offline.
*
* @return {@code true} if the operation runs offline; or
* {@code false} otherwise
* @since 2.0
*/
public boolean offline() {
return offline_;
}

/**
* Indicates whether the sources classifier files should be preserved.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TestDependencyTreeOperation {
@Test
void testInstantiation() {
var operation = new DependencyTreeOperation();
assertFalse(operation.offline());
assertEquals(operation.properties().size(), 0);
assertTrue(operation.dependencies().isEmpty());
assertTrue(operation.repositories().isEmpty());
Expand Down Expand Up @@ -55,7 +56,9 @@ void testPopulation() {
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency2));

var operation3 = new DependencyTreeOperation()
.offline(true)
.repositories(repository1, repository2);
assertTrue(operation3.offline());
assertTrue(operation3.repositories().contains(repository1));
assertTrue(operation3.repositories().contains(repository2));
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/rife/bld/operations/TestDownloadOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TestDownloadOperation {
@Test
void testInstantiation() {
var operation = new DownloadOperation();
assertFalse(operation.offline());
assertTrue(operation.dependencies().isEmpty());
assertTrue(operation.repositories().isEmpty());
assertNull(operation.libCompileDirectory());
Expand Down Expand Up @@ -81,7 +82,9 @@ void testPopulation() {
assertEquals(dir5, operation2.libTestDirectory());

var operation3 = new DownloadOperation()
.offline(true)
.repositories(repository1, repository2);
assertTrue(operation3.offline());
assertTrue(operation3.repositories().contains(repository1));
assertTrue(operation3.repositories().contains(repository2));
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/rife/bld/operations/TestPublishOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public PublishProject(File work, String packageName, String projectName, Version
@Test
void testInstantiation() {
var operation = new PublishOperation();
assertFalse(operation.offline());
assertTrue(operation.repositories().isEmpty());
assertNull(operation.moment());
assertTrue(operation.dependencies().isEmpty());
Expand Down Expand Up @@ -109,10 +110,12 @@ void testPopulation() {
assertTrue(operation2.artifacts().contains(artifact2));

var operation3 = new PublishOperation()
.offline(true)
.repository(repository1)
.repository(repository2)
.moment(moment)
.artifacts(List.of(artifact1, artifact2));
assertTrue(operation3.offline());
operation3.publishProperties().mavenCompilerSource(17).mavenCompilerTarget(19);
assertTrue(operation3.repositories().contains(repository1));
assertTrue(operation3.repositories().contains(repository2));
Expand Down
Loading

0 comments on commit a02e788

Please sign in to comment.