Skip to content

Commit af1fa2b

Browse files
reschkeandreeastroe96
authored andcommitted
OAK-11431: Remove usage of Guava Files.createTempDir() (apache#2027)
* OAK-11431: Remove usage of Guava Files.createTempDir() * OAK-11431: Remove usage of Guava Files.createTempDir() - oak-lucene * OAK-11431: Remove usage of Guava Files.createTempDir() - oak-upgrade * OAK-11431: Remove usage of Guava Files.createTempDir() - oak-segment-aws * OAK-11431: Remove usage of Guava Files.createTempDir() - oak-run-commons * OAK-11431: Remove usage of Guava Files.createTempDir() - oak-run
1 parent 6e32d9f commit af1fa2b

File tree

14 files changed

+44
-40
lines changed

14 files changed

+44
-40
lines changed

oak-blob/src/test/java/org/apache/jackrabbit/oak/spi/blob/split/SplitBlobStoreTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,24 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package org.apache.jackrabbit.oak.spi.blob.split;
2120

2221
import java.io.ByteArrayInputStream;
2322
import java.io.File;
2423
import java.io.IOException;
2524
import java.io.InputStream;
25+
import java.nio.file.Files;
2626
import java.util.ArrayList;
2727
import java.util.List;
2828
import java.util.Random;
2929

3030
import org.apache.commons.io.FileUtils;
3131
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
3232
import org.apache.jackrabbit.oak.spi.blob.FileBlobStore;
33-
import org.apache.jackrabbit.oak.spi.blob.split.DefaultSplitBlobStore;
3433
import org.junit.After;
3534
import org.junit.Before;
3635
import org.junit.Test;
3736

38-
import org.apache.jackrabbit.guava.common.io.Files;
39-
4037
import static org.junit.Assert.assertEquals;
4138
import static org.junit.Assert.assertFalse;
4239
import static org.junit.Assert.assertTrue;
@@ -61,7 +58,7 @@ public class SplitBlobStoreTest {
6158

6259
@Before
6360
public void setup() throws IOException {
64-
repository = Files.createTempDir();
61+
repository = Files.createTempDirectory(getClass().getSimpleName() + "-").toFile();
6562
oldBlobStore = new FileBlobStore(repository.getPath() + "/old");
6663
newBlobStore = new FileBlobStore(repository.getPath() + "/new");
6764
splitBlobStore = new DefaultSplitBlobStore(repository.getPath(), oldBlobStore, newBlobStore);

oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/SuggestHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.io.Reader;
24+
import java.nio.file.Files;
2425
import java.util.Collections;
2526
import java.util.List;
2627

2728
import org.apache.jackrabbit.guava.common.io.Closer;
28-
import org.apache.jackrabbit.guava.common.io.Files;
2929
import org.apache.commons.io.FileUtils;
3030
import org.apache.jackrabbit.oak.plugins.index.search.FieldNames;
3131
import org.apache.lucene.analysis.Analyzer;
@@ -67,7 +67,7 @@ public static void updateSuggester(Directory directory, Analyzer analyzer, Index
6767
//create a placeholder non-existing-sub-child which would mark the location when we want to return
6868
//our internal suggestion OakDirectory. After build is done, we'd delete the temp directory
6969
//thereby removing any temp stuff that suggester created in the interim.
70-
tempDir = Files.createTempDir();
70+
tempDir = Files.createTempDirectory(SuggestHelper.class.getSimpleName() + "-").toFile();
7171
File tempSubChild = new File(tempDir, "non-existing-sub-child");
7272

7373
if (reader.getDocCount(FieldNames.SUGGEST) > 0) {

oak-run-commons/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import java.io.FileInputStream;
2424
import java.io.IOException;
2525
import java.io.InputStream;
26+
import java.nio.file.Files;
2627
import java.util.Dictionary;
2728
import java.util.Enumeration;
2829
import java.util.HashMap;
2930
import java.util.Map;
3031
import java.util.Properties;
3132

3233
import org.apache.jackrabbit.guava.common.io.Closer;
33-
import org.apache.jackrabbit.guava.common.io.Files;
3434
import org.apache.commons.io.FileUtils;
3535
import org.apache.commons.io.FilenameUtils;
3636
import org.apache.felix.cm.file.ConfigurationHandler;
@@ -68,7 +68,7 @@ public static BlobStoreFixture create(Options options) throws Exception{
6868
S3DataStore s3ds = new S3DataStore();
6969
Properties props = loadConfig(bsopts.getS3ConfigPath());
7070
s3ds.setProperties(props);
71-
File homeDir = Files.createTempDir();
71+
File homeDir = Files.createTempDirectory(BlobStoreFixtureProvider.class.getSimpleName() + "-").toFile();
7272
closer.register(asCloseable(homeDir));
7373
populate(s3ds, asMap(props), false);
7474
s3ds.init(homeDir.getAbsolutePath());
@@ -78,7 +78,7 @@ public static BlobStoreFixture create(Options options) throws Exception{
7878
String cfgPath = bsopts.getAzureConfigPath();
7979
Properties props = loadConfig(cfgPath);
8080
azureds.setProperties(props);
81-
File homeDir = Files.createTempDir();
81+
File homeDir = Files.createTempDirectory(BlobStoreFixtureProvider.class.getSimpleName() + "-").toFile();
8282
populate(azureds, asMap(props), false);
8383
azureds.init(homeDir.getAbsolutePath());
8484
closer.register(asCloseable(homeDir));

oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static java.util.Optional.empty;
2323
import static java.util.Optional.of;
2424
import static org.apache.jackrabbit.oak.commons.PropertiesUtil.populate;
25-
import static org.apache.jackrabbit.oak.plugins.document.LeaseCheckMode.DISABLED;
2625
import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder.newMongoDocumentNodeStoreBuilder;
2726
import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentNodeStoreBuilder.newRDBDocumentNodeStoreBuilder;
2827
import static org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
@@ -32,6 +31,7 @@
3231
import java.io.FileInputStream;
3332
import java.io.IOException;
3433
import java.io.OutputStream;
34+
import java.nio.file.Files;
3535
import java.util.ArrayList;
3636
import java.util.Dictionary;
3737
import java.util.Enumeration;
@@ -69,7 +69,6 @@
6969
import org.jetbrains.annotations.Nullable;
7070

7171
import org.apache.jackrabbit.guava.common.io.Closer;
72-
import org.apache.jackrabbit.guava.common.io.Files;
7372
import com.mongodb.MongoClientURI;
7473
import com.mongodb.MongoURI;
7574

@@ -298,7 +297,7 @@ public static GarbageCollectableBlobStore bootstrapDataStore(String[] args, Clos
298297
String cfgPath = s3dsConfig.value(options);
299298
Properties props = loadAndTransformProps(cfgPath);
300299
s3ds.setProperties(props);
301-
File homeDir = Files.createTempDir();
300+
File homeDir = Files.createTempDirectory(Utils.class.getSimpleName() + "-").toFile();
302301
closer.register(asCloseable(homeDir));
303302
s3ds.init(homeDir.getAbsolutePath());
304303
delegate = s3ds;
@@ -307,13 +306,13 @@ public static GarbageCollectableBlobStore bootstrapDataStore(String[] args, Clos
307306
String cfgPath = azureBlobDSConfig.value(options);
308307
Properties props = loadAndTransformProps(cfgPath);
309308
azureds.setProperties(props);
310-
File homeDir = Files.createTempDir();
309+
File homeDir = Files.createTempDirectory(Utils.class.getSimpleName() + "-").toFile();
311310
azureds.init(homeDir.getAbsolutePath());
312311
closer.register(asCloseable(homeDir));
313312
delegate = azureds;
314313
} else if (options.has(nods)){
315314
delegate = new DummyDataStore();
316-
File homeDir = Files.createTempDir();
315+
File homeDir = Files.createTempDirectory(Utils.class.getSimpleName() + "-").toFile();
317316
delegate.init(homeDir.getAbsolutePath());
318317
closer.register(asCloseable(homeDir));
319318
}

oak-segment-aws/src/main/java/org/apache/jackrabbit/oak/segment/aws/tool/AwsCompact.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.jackrabbit.oak.segment.aws.tool;
1918

2019
import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;
@@ -26,11 +25,11 @@
2625

2726
import java.io.IOException;
2827
import java.io.PrintStream;
28+
import java.nio.file.Files;
2929
import java.util.Collections;
3030
import java.util.List;
3131

3232
import org.apache.jackrabbit.guava.common.base.Stopwatch;
33-
import org.apache.jackrabbit.guava.common.io.Files;
3433

3534
import org.apache.jackrabbit.oak.segment.SegmentCache;
3635
import org.apache.jackrabbit.oak.segment.aws.tool.AwsToolUtils.SegmentStoreType;
@@ -220,7 +219,8 @@ public int run() throws IOException {
220219
printArchives(System.out, beforeArchives);
221220
System.out.printf(" -> compacting\n");
222221

223-
try (FileStore store = newFileStore(persistence, Files.createTempDir(), strictVersionCheck, segmentCacheSize,
222+
try (FileStore store = newFileStore(persistence,
223+
Files.createTempDirectory(getClass().getSimpleName() + "-").toFile(), strictVersionCheck, segmentCacheSize,
224224
gcLogInterval, compactorType, concurrency)) {
225225
boolean success = false;
226226
switch (gcType) {

oak-segment-aws/src/test/java/org/apache/jackrabbit/oak/segment/aws/fixture/SegmentAwsFixture.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package org.apache.jackrabbit.oak.segment.aws.fixture;
2120

2221
import com.amazonaws.AmazonServiceException;
2322
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
2423
import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded;
2524
import com.amazonaws.services.s3.AmazonS3;
26-
import org.apache.jackrabbit.guava.common.io.Files;
2725
import org.apache.jackrabbit.oak.fixture.NodeStoreFixture;
2826
import org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders;
2927
import org.apache.jackrabbit.oak.segment.aws.AwsContext;
@@ -35,6 +33,7 @@
3533
import org.apache.jackrabbit.oak.spi.state.NodeStore;
3634

3735
import java.io.IOException;
36+
import java.nio.file.Files;
3837
import java.util.HashMap;
3938
import java.util.Map;
4039
import java.util.UUID;
@@ -89,7 +88,7 @@ public NodeStore createNodeStore() {
8988
}
9089

9190
try {
92-
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(Files.createTempDir())
91+
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(Files.createTempDirectory(getClass().getSimpleName() + "-").toFile())
9392
.withCustomPersistence(persistence).build();
9493
NodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
9594
fileStoreMap.put(nodeStore, fileStore);

oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/AzureCheck.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.jackrabbit.oak.segment.azure.tool;
1818

19-
import com.google.common.io.Files;
2019
import com.microsoft.azure.storage.blob.CloudBlobDirectory;
2120
import org.apache.jackrabbit.oak.segment.azure.AzurePersistence;
2221
import org.apache.jackrabbit.oak.segment.azure.AzureStorageCredentialManager;
@@ -29,7 +28,9 @@
2928
import org.apache.jackrabbit.oak.segment.tool.check.CheckHelper;
3029

3130
import java.io.File;
31+
import java.io.IOException;
3232
import java.io.PrintWriter;
33+
import java.nio.file.Files;
3334
import java.text.MessageFormat;
3435
import java.util.Set;
3536
import java.util.concurrent.atomic.AtomicLong;
@@ -388,7 +389,13 @@ public int run() {
388389
persistence = ToolUtils.decorateWithCache(persistence, persistentCachePath, persistentCacheSizeGb);
389390
}
390391

391-
FileStoreBuilder builder = fileStoreBuilder(Files.createTempDir()).withCustomPersistence(persistence);
392+
FileStoreBuilder builder = null;
393+
try {
394+
builder = fileStoreBuilder(Files.createTempDirectory(getClass().getSimpleName() + "-").toFile()).withCustomPersistence(persistence);
395+
} catch (IOException e) {
396+
e.printStackTrace(err);
397+
return 1;
398+
}
392399

393400
if (ioStatistics) {
394401
builder.withIOMonitor(ioMonitor);

oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/tool/AzureCompact.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.jackrabbit.oak.segment.azure.tool;
1918

2019
import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;
@@ -27,7 +26,6 @@
2726
import static org.apache.jackrabbit.oak.segment.azure.tool.ToolUtils.printableStopwatch;
2827

2928
import org.apache.jackrabbit.guava.common.base.Stopwatch;
30-
import org.apache.jackrabbit.guava.common.io.Files;
3129
import com.microsoft.azure.storage.StorageException;
3230
import com.microsoft.azure.storage.blob.BlobListingDetails;
3331
import com.microsoft.azure.storage.blob.CloudBlob;
@@ -53,6 +51,7 @@
5351
import java.io.IOException;
5452
import java.io.PrintStream;
5553
import java.net.URISyntaxException;
54+
import java.nio.file.Files;
5655
import java.util.Collections;
5756
import java.util.EnumSet;
5857
import java.util.List;
@@ -372,7 +371,9 @@ public int run() throws IOException, StorageException, URISyntaxException {
372371
GCGeneration gcGeneration = null;
373372
String root = null;
374373

375-
try (FileStore store = newFileStore(splitPersistence, Files.createTempDir(), strictVersionCheck, segmentCacheSize,
374+
try (FileStore store =newFileStore(splitPersistence,
375+
Files.createTempDirectory(getClass().getSimpleName() + "-").toFile(),
376+
strictVersionCheck, segmentCacheSize,
376377
gcLogInterval, compactorType, concurrency)) {
377378
if (garbageThresholdGb > 0 && garbageThresholdPercentage > 0) {
378379
System.out.printf(" -> minimum garbage threshold set to %d GB or %d%%\n", garbageThresholdGb, garbageThresholdPercentage);

oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/fixture/SegmentAzureFixture.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package org.apache.jackrabbit.oak.segment.azure.fixture;
2120

22-
import org.apache.jackrabbit.guava.common.io.Files;
2321
import com.microsoft.azure.storage.CloudStorageAccount;
2422
import com.microsoft.azure.storage.StorageException;
2523
import com.microsoft.azure.storage.blob.CloudBlobContainer;
@@ -34,6 +32,7 @@
3432

3533
import java.io.IOException;
3634
import java.net.URISyntaxException;
35+
import java.nio.file.Files;
3736
import java.security.InvalidKeyException;
3837
import java.util.HashMap;
3938
import java.util.Map;
@@ -73,7 +72,9 @@ public NodeStore createNodeStore() {
7372
}
7473

7574
try {
76-
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(Files.createTempDir()).withCustomPersistence(persistence).build();
75+
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(
76+
Files.createTempDirectory(getClass().getSimpleName() + "-").toFile()).
77+
withCustomPersistence(persistence).build();
7778
NodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
7879
fileStoreMap.put(nodeStore, fileStore);
7980
containerMap.put(nodeStore, container);

oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/blob/AzureDataStoreFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.File;
2121
import java.io.FileReader;
2222
import java.io.IOException;
23+
import java.nio.file.Files;
2324
import java.util.HashMap;
2425
import java.util.HashSet;
2526
import java.util.Map;
@@ -42,7 +43,6 @@
4243
import org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider;
4344
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
4445
import org.apache.jackrabbit.guava.common.io.Closer;
45-
import org.apache.jackrabbit.guava.common.io.Files;
4646

4747
public class AzureDataStoreFactory implements BlobStoreFactory {
4848

@@ -68,7 +68,7 @@ public AzureDataStoreFactory(String configuration, String directory, boolean ign
6868
// Default directory
6969

7070
this.directory = directory;
71-
this.tempHomeDir = Files.createTempDir();
71+
this.tempHomeDir = Files.createTempDirectory(getClass().getSimpleName() + "-").toFile();
7272
this.ignoreMissingBlobs = ignoreMissingBlobs;
7373
}
7474

0 commit comments

Comments
 (0)