From 09e3ba8880b4e5c2540651a3c6f166602c469ff5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lesot Date: Thu, 19 Mar 2015 22:10:06 +0100 Subject: Make Jack script more robust - Add small support of interruptions, but no synchronization with the compilation server. - Add support of space in command line, but do not support double quote. - Stale lock support. - More robust server by being over-conservative. Change-Id: Ia5fe022e6b820c9c589a1d524278eed0b8009a48 --- .../util/file/CannotSetPermissionException.java | 10 ++-- .../util/file/CannotUnsetPermissionException.java | 70 ++++++++++++++++++++++ .../android/sched/util/file/FileOrDirectory.java | 8 +-- 3 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 sched/src/com/android/sched/util/file/CannotUnsetPermissionException.java (limited to 'sched/src/com/android/sched') diff --git a/sched/src/com/android/sched/util/file/CannotSetPermissionException.java b/sched/src/com/android/sched/util/file/CannotSetPermissionException.java index 59c203b6..273279fd 100644 --- a/sched/src/com/android/sched/util/file/CannotSetPermissionException.java +++ b/sched/src/com/android/sched/util/file/CannotSetPermissionException.java @@ -60,10 +60,10 @@ public class CannotSetPermissionException extends WithLocationException { @Override protected String createMessage(@Nonnull String description) { - return description + " can not be set " + - ((permission == Permission.READ) ? "readable" : - ((permission == Permission.WRITE) ? "writable" : - ((permission == Permission.EXECUTE) ? "executable" : "???"))) + - ((change == ChangePermission.EVERYBODY) ? " for everybody" : ""); + return description + " cannot have its " + + ((permission == Permission.READ) ? "readable " : + ((permission == Permission.WRITE) ? "writable " : + ((permission == Permission.EXECUTE) ? "executable " : "???"))) + "permission set" + + ((change == ChangePermission.EVERYBODY) ? "for everybody" : ""); } } diff --git a/sched/src/com/android/sched/util/file/CannotUnsetPermissionException.java b/sched/src/com/android/sched/util/file/CannotUnsetPermissionException.java new file mode 100644 index 00000000..cb733cc0 --- /dev/null +++ b/sched/src/com/android/sched/util/file/CannotUnsetPermissionException.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * 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.android.sched.util.file; + +import com.android.sched.util.file.FileOrDirectory.ChangePermission; +import com.android.sched.util.file.FileOrDirectory.Permission; +import com.android.sched.util.location.HasLocation; +import com.android.sched.util.location.Location; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** + * Exception when a file or directory can not be cleared of the expected permission. + */ +public class CannotUnsetPermissionException extends WithLocationException { + private static final long serialVersionUID = 1L; + + private final int permission; + @Nonnull + private final ChangePermission change; + + public CannotUnsetPermissionException(@Nonnull Location location, int permission, + @Nonnull ChangePermission change) { + this(location, permission, change, null); + } + + public CannotUnsetPermissionException(@Nonnull Location location, int permission, + @Nonnull ChangePermission change, @CheckForNull Throwable cause) { + super(location, cause); + this.permission = permission; + this.change = change; + } + + public CannotUnsetPermissionException(@Nonnull HasLocation locationProvider, int permission, + @Nonnull ChangePermission change) { + this(locationProvider, permission, change, null); + } + + public CannotUnsetPermissionException(@Nonnull HasLocation locationProvider, int permission, + @Nonnull ChangePermission change, @CheckForNull Throwable cause) { + super(locationProvider, cause); + this.permission = permission; + this.change = change; + } + + @Override + @Nonnull + protected String createMessage(@Nonnull String description) { + return description + " cannot have its " + + ((permission == Permission.READ) ? "readable " : + ((permission == Permission.WRITE) ? "writable " : + ((permission == Permission.EXECUTE) ? "executable " : "???"))) + "permission removed" + + ((change == ChangePermission.EVERYBODY) ? " for everybody" : ""); + } +} diff --git a/sched/src/com/android/sched/util/file/FileOrDirectory.java b/sched/src/com/android/sched/util/file/FileOrDirectory.java index 688e5d22..1065cd01 100644 --- a/sched/src/com/android/sched/util/file/FileOrDirectory.java +++ b/sched/src/com/android/sched/util/file/FileOrDirectory.java @@ -128,7 +128,7 @@ public abstract class FileOrDirectory implements HasLocation { public static void unsetPermissions(@Nonnull File file, @Nonnull Location location, int permissions, @Nonnull FileOrDirectory.ChangePermission change) - throws CannotSetPermissionException { + throws CannotUnsetPermissionException { if (change != ChangePermission.NOCHANGE) { // Set access if ((permissions & Permission.READ) != 0) { @@ -136,7 +136,7 @@ public abstract class FileOrDirectory implements HasLocation { logger.log(Level.FINE, "Clear readable permission to {0} (''{1}'')", new Object[] {location.getDescription(), file.getAbsoluteFile()}); } else { - throw new CannotSetPermissionException(location, Permission.READ, + throw new CannotUnsetPermissionException(location, Permission.READ, change); } } @@ -146,7 +146,7 @@ public abstract class FileOrDirectory implements HasLocation { logger.log(Level.FINE, "Clear writable permission to {0} (''{1}'')", new Object[] {location.getDescription(), file.getAbsoluteFile()}); } else { - throw new CannotSetPermissionException(location, Permission.WRITE, + throw new CannotUnsetPermissionException(location, Permission.WRITE, change); } } @@ -156,7 +156,7 @@ public abstract class FileOrDirectory implements HasLocation { logger.log(Level.FINE, "Clear executable permission to {0} (''{1}'')", new Object[] {location.getDescription(), file.getAbsoluteFile()}); } else { - throw new CannotSetPermissionException(location, Permission.EXECUTE, + throw new CannotUnsetPermissionException(location, Permission.EXECUTE, change); } } -- cgit v1.2.3