Skip to content

Commit

Permalink
🔀 Merge branch 'release/v82'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombe committed Apr 28, 2020
2 parents faf6624 + 716279c commit 5c5bee9
Show file tree
Hide file tree
Showing 142 changed files with 2,479 additions and 1,623 deletions.
18 changes: 13 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'org.jetbrains.kotlin.plugin.noarg' version '1.3.61'
id 'org.jetbrains.kotlin.jvm' version '1.3.70'
id 'org.jetbrains.kotlin.plugin.noarg' version '1.3.70'
id 'info.solidsoft.pitest' version '1.4.5'
}

group = 'net.pterodactylus'
version = '81'
version = '82'

repositories {
mavenCentral()
Expand All @@ -22,6 +23,12 @@ tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

tasks.withType(KotlinCompile) {
kotlinOptions {
jvmTarget = "1.8"
}
}

configurations {
provided {
dependencies.all { dep ->
Expand All @@ -30,7 +37,7 @@ configurations {
}
compile.extendsFrom provided
}

dependencies {
provided group: 'org.freenetproject', name: 'fred', version: '0.7.5.1475'
provided group: 'org.freenetproject', name: 'freenet-ext', version: '29'
Expand Down Expand Up @@ -69,6 +76,7 @@ task notParallelTest(type: Test) {
useJUnit {
includeCategories 'net.pterodactylus.sone.test.NotParallel'
}
dependsOn parallelTest
}

test {
Expand All @@ -77,7 +85,7 @@ test {
}

task fatJar(type: Jar) {
archiveName = project.name.toLowerCase() + '-jar-with-dependencies.jar'
archiveFileName = project.name.toLowerCase() + '-jar-with-dependencies.jar'
from { (configurations.runtime - configurations.provided).collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes('Plugin-Main-Class': 'net.pterodactylus.sone.main.SonePlugin')
Expand Down
37 changes: 12 additions & 25 deletions src/main/java/net/pterodactylus/sone/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static java.lang.String.format;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static net.pterodactylus.sone.data.AlbumsKt.getAllImages;
import static net.pterodactylus.sone.data.AlbumKt.getAllImages;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -62,6 +62,7 @@
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.data.SoneKt;
import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent;
import net.pterodactylus.sone.data.TemporaryImage;
import net.pterodactylus.sone.database.AlbumBuilder;
Expand Down Expand Up @@ -90,7 +91,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
Expand Down Expand Up @@ -180,24 +180,10 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
private final MetricRegistry metricRegistry;
private final Histogram configurationSaveTimeHistogram;

/**
* Creates a new core.
*
* @param configuration
* The configuration of the core
* @param freenetInterface
* The freenet interface
* @param identityManager
* The identity manager
* @param webOfTrustUpdater
* The WebOfTrust updater
* @param eventBus
* The event bus
* @param database
* The database
*/
private final SoneUriCreator soneUriCreator;

@Inject
public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database, MetricRegistry metricRegistry) {
public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database, MetricRegistry metricRegistry, SoneUriCreator soneUriCreator) {
super("Sone Core");
this.configuration = configuration;
this.freenetInterface = freenetInterface;
Expand All @@ -209,6 +195,7 @@ public Core(Configuration configuration, FreenetInterface freenetInterface, Iden
this.eventBus = eventBus;
this.database = database;
this.metricRegistry = metricRegistry;
this.soneUriCreator = soneUriCreator;
preferences = new Preferences(eventBus);
this.configurationSaveTimeHistogram = metricRegistry.histogram("configuration.save.duration", () -> new Histogram(new ExponentiallyDecayingReservoir(3000, 0)));
}
Expand Down Expand Up @@ -626,7 +613,7 @@ public Sone addLocalSone(OwnIdentity ownIdentity) {
sone.setLatestEdition(fromNullable(tryParse(property)).or(0L));
sone.setClient(new Client("Sone", SonePlugin.getPluginVersion()));
sone.setKnown(true);
SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, metricRegistry, ownIdentity.getId());
SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, metricRegistry, soneUriCreator, ownIdentity.getId());
soneInserter.insertionDelayChanged(new InsertionDelayChangedEvent(preferences.getInsertionDelay()));
eventBus.register(soneInserter);
synchronized (soneInserters) {
Expand Down Expand Up @@ -810,9 +797,9 @@ private List<Object> collectEventsForChangesInSone(Sone oldSone, Sone newSone) {
}
for (PostReply postReply : soneComparison.getNewPostReplies()) {
if (postReply.getSone().equals(newSone)) {
postReply.setKnown(true);
database.setPostReplyKnown(postReply);
} else if (postReply.getTime() < database.getFollowingTime(newSone.getId())) {
postReply.setKnown(true);
database.setPostReplyKnown(postReply);
} else if (!postReply.isKnown()) {
events.add(new NewPostReplyFoundEvent(postReply));
}
Expand Down Expand Up @@ -989,7 +976,7 @@ public void loadSone(Sone sone) {
post.setKnown(true);
}
for (PostReply reply : replies) {
reply.setKnown(true);
database.setPostReplyKnown(reply);
}

logger.info(String.format("Sone loaded successfully: %s", sone));
Expand Down Expand Up @@ -1131,7 +1118,7 @@ public void deleteReply(PostReply reply) {
*/
public void markReplyKnown(PostReply reply) {
boolean previouslyKnown = reply.isKnown();
reply.setKnown(true);
database.setPostReplyKnown(reply);
eventBus.post(new MarkPostReplyKnownEvent(reply));
if (!previouslyKnown) {
touchConfiguration();
Expand Down Expand Up @@ -1405,7 +1392,7 @@ private synchronized void saveSone(Sone sone) {
configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter + "/ID").setValue(null);

/* save albums. first, collect in a flat structure, top-level first. */
List<Album> albums = FluentIterable.from(sone.getRootAlbum().getAlbums()).transformAndConcat(Album.FLATTENER).toList();
List<Album> albums = SoneKt.getAllAlbums(sone);

int albumCounter = 0;
for (Album album : albums) {
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/net/pterodactylus/sone/core/FreenetInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class FreenetInterface {
/** The node to interact with. */
private final Node node;

private final SoneUriCreator soneUriCreator;

/** The high-level client to use for requests. */
private final HighLevelSimpleClient client;
private final RequestClient requestClient = new RequestClientBuilder().realTime().build();
Expand All @@ -104,18 +106,11 @@ public class FreenetInterface {
private final RequestClient imageInserts = new RequestClientBuilder().realTime().build();
private final RequestClient imageLoader = new RequestClientBuilder().realTime().build();

/**
* Creates a new Freenet interface.
*
* @param eventBus
* The event bus
* @param node
* The node to interact with
*/
@Inject
public FreenetInterface(EventBus eventBus, Node node) {
public FreenetInterface(EventBus eventBus, Node node, SoneUriCreator soneUriCreator) {
this.eventBus = eventBus;
this.node = node;
this.soneUriCreator = soneUriCreator;
this.client = node.clientCore.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS, false, true);
}

Expand Down Expand Up @@ -291,9 +286,9 @@ public void unregisterUsk(Sone sone) {
}
try {
logger.log(Level.FINEST, String.format("Unsubscribing from USK for %s…", sone));
node.clientCore.uskManager.unsubscribe(USK.create(sone.getRequestUri()), uskCallback);
node.clientCore.uskManager.unsubscribe(USK.create(soneUriCreator.getRequestUri(sone)), uskCallback);
} catch (MalformedURLException mue1) {
logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", sone.getRequestUri()), mue1);
logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", soneUriCreator.getRequestUri(sone)), mue1);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/pterodactylus/sone/core/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import net.pterodactylus.sone.utils.Option;

import com.google.common.base.Predicate;

/**
* Stores various options that influence Sone’s behaviour.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package net.pterodactylus.sone.core;

import static freenet.support.io.Closer.close;
import static java.lang.String.format;
import static java.lang.System.currentTimeMillis;
import static java.util.concurrent.TimeUnit.DAYS;
Expand Down Expand Up @@ -185,11 +184,8 @@ public Sone fetchSone(Sone sone, FreenetURI soneUri, boolean fetchOnly) {
private Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) {
logger.finest(() -> format("Parsing FetchResult (%d bytes, %s) for %s…", fetchResult.size(), fetchResult.getMimeType(), originalSone));
Bucket soneBucket = fetchResult.asBucket();
InputStream soneInputStream = null;
try {
soneInputStream = soneBucket.getInputStream();
Sone parsedSone = soneParser.parseSone(originalSone,
soneInputStream);
try (InputStream soneInputStream = soneBucket.getInputStream()) {
Sone parsedSone = soneParser.parseSone(originalSone, soneInputStream);
if (parsedSone != null) {
logger.finer(() -> format("Sone %s was successfully parsed.", parsedSone));
parsedSone.setLatestEdition(requestUri.getEdition());
Expand All @@ -198,8 +194,7 @@ private Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI re
} catch (Exception e1) {
logger.log(Level.WARNING, e1, () -> format("Could not parse Sone from %s!", requestUri));
} finally {
close(soneInputStream);
close(soneBucket);
soneBucket.free();
}
return null;
}
Expand Down
Loading

0 comments on commit 5c5bee9

Please sign in to comment.