-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests and DevelocityClient builder
- Loading branch information
1 parent
90c164c
commit f31415a
Showing
17 changed files
with
802 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/dev/erichaag/develocity/api/HttpClientDevelocityClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.erichaag.develocity.api; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
|
||
import static dev.erichaag.develocity.api.AccessKeyProvider.lookupAccessKey; | ||
|
||
public final class HttpClientDevelocityClientBuilder { | ||
|
||
private final URI serverUrl; | ||
private final HttpClient.Builder httpClientBuilder = HttpClient.newBuilder(); | ||
|
||
private boolean useAnonymousAccess = false; | ||
|
||
HttpClientDevelocityClientBuilder(URI serverUrl) { | ||
this.serverUrl = serverUrl; | ||
} | ||
|
||
public HttpClientDevelocityClient build() { | ||
final var accessKey = useAnonymousAccess ? null : lookupAccessKey(serverUrl); | ||
return new HttpClientDevelocityClient(serverUrl, accessKey, httpClientBuilder.build()); | ||
} | ||
|
||
public HttpClientDevelocityClientBuilder withAnonymousAccess() { | ||
this.useAnonymousAccess = true; | ||
return this; | ||
} | ||
|
||
public HttpClientDevelocityClientBuilder followingRedirects() { | ||
this.httpClientBuilder.followRedirects(HttpClient.Redirect.ALWAYS); | ||
return this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/main/java/dev/erichaag/develocity/processing/ProcessListenerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package dev.erichaag.develocity.processing; | ||
|
||
import dev.erichaag.develocity.processing.event.CachedBuildEvent; | ||
import dev.erichaag.develocity.processing.event.DiscoveryFinishedEvent; | ||
import dev.erichaag.develocity.processing.event.DiscoveryStartedEvent; | ||
import dev.erichaag.develocity.processing.event.FetchedBuildEvent; | ||
import dev.erichaag.develocity.processing.event.ProcessingFinishedEvent; | ||
import dev.erichaag.develocity.processing.event.ProcessingStartedEvent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public final class ProcessListenerBuilder { | ||
|
||
private final List<ProcessListener> listeners = new ArrayList<>(); | ||
|
||
ProcessListenerBuilder() { | ||
} | ||
|
||
public ProcessListener build() { | ||
return new ProcessListener() { | ||
|
||
@Override | ||
public void onCachedBuild(CachedBuildEvent event) { | ||
listeners.forEach(it -> it.onCachedBuild(event)); | ||
} | ||
|
||
@Override | ||
public void onFetchedBuild(FetchedBuildEvent event) { | ||
listeners.forEach(it -> it.onFetchedBuild(event)); | ||
} | ||
|
||
@Override | ||
public void onDiscoveryStarted(DiscoveryStartedEvent event) { | ||
listeners.forEach(it -> it.onDiscoveryStarted(event)); | ||
} | ||
|
||
@Override | ||
public void onDiscoveryFinished(DiscoveryFinishedEvent event) { | ||
listeners.forEach(it -> it.onDiscoveryFinished(event)); | ||
} | ||
|
||
@Override | ||
public void onProcessingStarted(ProcessingStartedEvent event) { | ||
listeners.forEach(it -> it.onProcessingStarted(event)); | ||
} | ||
|
||
@Override | ||
public void onProcessingFinished(ProcessingFinishedEvent event) { | ||
listeners.forEach(it -> it.onProcessingFinished(event)); | ||
} | ||
|
||
}; | ||
} | ||
|
||
public ProcessListenerBuilder onCachedBuild(Consumer<CachedBuildEvent> onCachedBuild) { | ||
listeners.add(new ProcessListener() { | ||
@Override | ||
public void onCachedBuild(CachedBuildEvent event) { | ||
onCachedBuild.accept(event); | ||
} | ||
}); | ||
return this; | ||
} | ||
|
||
public ProcessListenerBuilder onFetchedBuild(Consumer<FetchedBuildEvent> onFetchedBuild) { | ||
listeners.add(new ProcessListener() { | ||
@Override | ||
public void onFetchedBuild(FetchedBuildEvent event) { | ||
onFetchedBuild.accept(event); | ||
} | ||
}); | ||
return this; | ||
} | ||
|
||
public ProcessListenerBuilder onDiscoveryStarted(Consumer<DiscoveryStartedEvent> onDiscoveryStarted) { | ||
listeners.add(new ProcessListener() { | ||
@Override | ||
public void onDiscoveryStarted(DiscoveryStartedEvent event) { | ||
onDiscoveryStarted.accept(event); | ||
} | ||
}); | ||
return this; | ||
} | ||
|
||
public ProcessListenerBuilder onDiscoveryFinished(Consumer<DiscoveryFinishedEvent> onDiscoveryFinished) { | ||
listeners.add(new ProcessListener() { | ||
@Override | ||
public void onDiscoveryFinished(DiscoveryFinishedEvent event) { | ||
onDiscoveryFinished.accept(event); | ||
} | ||
}); | ||
return this; | ||
} | ||
|
||
public ProcessListenerBuilder onProcessingStarted(Consumer<ProcessingStartedEvent> onProcessingStarted) { | ||
listeners.add(new ProcessListener() { | ||
@Override | ||
public void onProcessingStarted(ProcessingStartedEvent event) { | ||
onProcessingStarted.accept(event); | ||
} | ||
}); | ||
return this; | ||
} | ||
|
||
public ProcessListenerBuilder onProcessingFinished(Consumer<ProcessingFinishedEvent> onProcessingFinished) { | ||
listeners.add(new ProcessListener() { | ||
@Override | ||
public void onProcessingFinished(ProcessingFinishedEvent event) { | ||
onProcessingFinished.accept(event); | ||
} | ||
}); | ||
return this; | ||
} | ||
|
||
} |
Oops, something went wrong.