From 4739aee7e8e6ee9c66801541921f42f9af93387d Mon Sep 17 00:00:00 2001 From: Colin Decker Date: Tue, 10 Jun 2014 10:21:31 -0400 Subject: Move all classes to com.google.common.jimfs. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=68905401 --- .../google/common/jimfs/TestAttributeProvider.java | 235 +++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java (limited to 'jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java') diff --git a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java new file mode 100644 index 0000000..a912299 --- /dev/null +++ b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java @@ -0,0 +1,235 @@ +/* + * Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.common.jimfs; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +import java.io.IOException; +import java.nio.file.attribute.BasicFileAttributeView; +import java.nio.file.attribute.FileAttributeView; +import java.nio.file.attribute.FileTime; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nullable; + +/** + * @author Colin Decker + */ +public final class TestAttributeProvider extends AttributeProvider { + + private static final ImmutableSet ATTRIBUTES = ImmutableSet.of( + "foo", + "bar", + "baz"); + + @Override + public String name() { + return "test"; + } + + @Override + public ImmutableSet inherits() { + return ImmutableSet.of("basic"); + } + + @Override + public ImmutableSet fixedAttributes() { + return ATTRIBUTES; + } + + @Override + public ImmutableMap defaultValues(Map userDefaults) { + Map result = new HashMap<>(); + + Long bar = 0L; + Integer baz = 1; + if (userDefaults.containsKey("test:bar")) { + bar = checkType("test", "bar", userDefaults.get("test:bar"), Number.class).longValue(); + } + if (userDefaults.containsKey("test:baz")) { + baz = checkType("test", "baz", userDefaults.get("test:baz"), Integer.class); + } + + result.put("test:bar", bar); + result.put("test:baz", baz); + return ImmutableMap.copyOf(result); + } + + @Override + public void set( + File file, String view, String attribute, Object value, boolean create) { + switch (attribute) { + case "bar": + checkNotCreate(view, attribute, create); + file.setAttribute("test", "bar", + checkType(view, attribute, value, Number.class).longValue()); + break; + case "baz": + file.setAttribute("test", "baz", + checkType(view, attribute, value, Integer.class)); + break; + default: + throw unsettable(view, attribute); + } + } + + @Override + public Object get(File file, String attribute) { + if (attribute.equals("foo")) { + return "hello"; + } + return file.getAttribute("test", attribute); + } + + @Override + public Class viewType() { + return TestAttributeView.class; + } + + @Override + public TestAttributeView view( + FileLookup lookup, ImmutableMap inheritedViews) { + return new View(lookup, (BasicFileAttributeView) inheritedViews.get("basic")); + } + + @Override + public Class attributesType() { + return TestAttributes.class; + } + + @Override + public TestAttributes readAttributes(File file) { + return new Attributes(file); + } + + static final class View implements TestAttributeView { + + private final FileLookup lookup; + private final BasicFileAttributeView basicView; + + public View(FileLookup lookup, BasicFileAttributeView basicView) { + this.lookup = checkNotNull(lookup); + this.basicView = checkNotNull(basicView); + } + + @Override + public String name() { + return "test"; + } + + @Override + public Attributes readAttributes() throws IOException { + return new Attributes(lookup.lookup()); + } + + @Override + public void setTimes( + @Nullable FileTime lastModifiedTime, + @Nullable FileTime lastAccessTime, + @Nullable FileTime createTime) throws IOException { + basicView.setTimes(lastModifiedTime, lastAccessTime, createTime); + } + + @Override + public void setBar(long bar) throws IOException { + lookup.lookup().setAttribute("test", "bar", bar); + } + + @Override + public void setBaz(int baz) throws IOException { + lookup.lookup().setAttribute("test", "baz", baz); + } + } + + static final class Attributes implements TestAttributes { + + private final Long bar; + private final Integer baz; + + public Attributes(File file) { + this.bar = (Long) file.getAttribute("test", "bar"); + this.baz = (Integer) file.getAttribute("test", "baz"); + } + + @Override + public String foo() { + return "hello"; + } + + @Override + public long bar() { + return bar; + } + + @Override + public int baz() { + return baz; + } + + // BasicFileAttributes is just implemented here because readAttributes requires a subtype of + // BasicFileAttributes -- methods are not implemented + + @Override + public FileTime lastModifiedTime() { + return null; + } + + @Override + public FileTime lastAccessTime() { + return null; + } + + @Override + public FileTime creationTime() { + return null; + } + + @Override + public boolean isRegularFile() { + return false; + } + + @Override + public boolean isDirectory() { + return false; + } + + @Override + public boolean isSymbolicLink() { + return false; + } + + @Override + public boolean isOther() { + return false; + } + + @Override + public long size() { + return 0; + } + + @Override + public Object fileKey() { + return null; + } + } +} -- cgit v1.2.3 From 213274e39877fb50ef80fa266a15c20a1a83643b Mon Sep 17 00:00:00 2001 From: cgdecker Date: Thu, 28 May 2015 12:34:06 -0700 Subject: Format Jimfs with google-java-format. Made a bunch of manual fixes, but mostly pretty good. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=94692335 --- .../com/google/common/jimfs/TestAttributeProvider.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java') diff --git a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java index a912299..79b92ac 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java +++ b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java @@ -35,10 +35,7 @@ import javax.annotation.Nullable; */ public final class TestAttributeProvider extends AttributeProvider { - private static final ImmutableSet ATTRIBUTES = ImmutableSet.of( - "foo", - "bar", - "baz"); + private static final ImmutableSet ATTRIBUTES = ImmutableSet.of("foo", "bar", "baz"); @Override public String name() { @@ -74,17 +71,15 @@ public final class TestAttributeProvider extends AttributeProvider { } @Override - public void set( - File file, String view, String attribute, Object value, boolean create) { + public void set(File file, String view, String attribute, Object value, boolean create) { switch (attribute) { case "bar": checkNotCreate(view, attribute, create); - file.setAttribute("test", "bar", - checkType(view, attribute, value, Number.class).longValue()); + file.setAttribute( + "test", "bar", checkType(view, attribute, value, Number.class).longValue()); break; case "baz": - file.setAttribute("test", "baz", - checkType(view, attribute, value, Integer.class)); + file.setAttribute("test", "baz", checkType(view, attribute, value, Integer.class)); break; default: throw unsettable(view, attribute); @@ -144,7 +139,8 @@ public final class TestAttributeProvider extends AttributeProvider { public void setTimes( @Nullable FileTime lastModifiedTime, @Nullable FileTime lastAccessTime, - @Nullable FileTime createTime) throws IOException { + @Nullable FileTime createTime) + throws IOException { basicView.setTimes(lastModifiedTime, lastAccessTime, createTime); } -- cgit v1.2.3 From fdc12fe9e0edb4cb952a371df1f43e67d2f8f459 Mon Sep 17 00:00:00 2001 From: cgdecker Date: Wed, 23 Mar 2016 13:54:08 -0700 Subject: A couple attribute-related changes: - Throw UOE instead of IAE when attempting to set an attribute that can't be set at all during file creation. This matches the behavior of the real file system implementations. - Make the owner:owner attribute not settable during file creation, which also matches the actual behavior. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117965277 --- jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java') diff --git a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java index 79b92ac..306f745 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java +++ b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java @@ -82,7 +82,7 @@ public final class TestAttributeProvider extends AttributeProvider { file.setAttribute("test", "baz", checkType(view, attribute, value, Integer.class)); break; default: - throw unsettable(view, attribute); + throw unsettable(view, attribute, create); } } -- cgit v1.2.3 From 64b0b187221a529be531271d9e27627ad1954572 Mon Sep 17 00:00:00 2001 From: kak Date: Thu, 18 Apr 2019 12:00:43 -0700 Subject: Run google-java-format over all of JimFS. RELNOTES=Run google-java-format over all of JimFS. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=244231542 --- .../test/java/com/google/common/jimfs/TestAttributeProvider.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java') diff --git a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java index 306f745..9dbeee9 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java +++ b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java @@ -20,19 +20,15 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; - import java.io.IOException; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileAttributeView; import java.nio.file.attribute.FileTime; import java.util.HashMap; import java.util.Map; - import javax.annotation.Nullable; -/** - * @author Colin Decker - */ +/** @author Colin Decker */ public final class TestAttributeProvider extends AttributeProvider { private static final ImmutableSet ATTRIBUTES = ImmutableSet.of("foo", "bar", "baz"); -- cgit v1.2.3 From a76d68fdcb08c9f5bde0ad2d143d0e8682f807eb Mon Sep 17 00:00:00 2001 From: cpovirk Date: Thu, 3 Oct 2019 12:11:16 -0700 Subject: Mostly migrate off jsr305. - Mostly migrate to Checker Framework declaration annotations. - Migrate @GuardedBy to a custom annotation for now. (We would migrate to Error Prone's, but that's causing me problems as I experiment with JPMS.) Compare to b/69411537 for Guava. I've left @ParametersAreNonnullByDefault in place for now, but we'd need to remove it to fully eliminate the jsr305 dep. RELNOTES=Migrated from jsr305 `@Nullable` to Checker Framework `@NullableDecl`. In addition to the new dependency on the Checker Framework annotations, we keep the dependency on jsr305 for now so that we can keep using `@ParametersAreNonNullByDefault`. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=272713254 --- .../test/java/com/google/common/jimfs/TestAttributeProvider.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java') diff --git a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java index 9dbeee9..4518132 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java +++ b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java @@ -26,7 +26,7 @@ import java.nio.file.attribute.FileAttributeView; import java.nio.file.attribute.FileTime; import java.util.HashMap; import java.util.Map; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** @author Colin Decker */ public final class TestAttributeProvider extends AttributeProvider { @@ -133,9 +133,9 @@ public final class TestAttributeProvider extends AttributeProvider { @Override public void setTimes( - @Nullable FileTime lastModifiedTime, - @Nullable FileTime lastAccessTime, - @Nullable FileTime createTime) + @NullableDecl FileTime lastModifiedTime, + @NullableDecl FileTime lastAccessTime, + @NullableDecl FileTime createTime) throws IOException { basicView.setTimes(lastModifiedTime, lastAccessTime, createTime); } -- cgit v1.2.3