Move the RulesCache to gerrit.rules package

It belongs alongside of the other Prolog support code, not the
ProjectState and ProjectCache.

Add a little bit of documentation to the class.

Change-Id: I3ba50c11641f760441745bc7ea4ac100efb5b2bb
This commit is contained in:
Shawn O. Pearce
2011-06-17 08:53:09 -07:00
parent d87b7d78e1
commit 4da4cbb921
3 changed files with 15 additions and 8 deletions

View File

@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package com.google.gerrit.server.project; package com.google.gerrit.rules;
import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -34,6 +35,13 @@ import java.net.URLClassLoader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* Manages a cache of compiled Prolog rules.
* <p>
* Rules are loaded from the {@code site_path/cache/rules/rules-SHA1.jar}, where
* {@code SHA1} is the SHA1 of the Prolog {@code rules.pl} in a project's
* {@link GitRepositoryManager#REF_CONFIG} branch.
*/
@Singleton @Singleton
public class RulesCache { public class RulesCache {
private static final Logger log = LoggerFactory.getLogger(RulesCache.class); private static final Logger log = LoggerFactory.getLogger(RulesCache.class);
@@ -58,15 +66,12 @@ public class RulesCache {
@Inject @Inject
protected RulesCache (@GerritServerConfig Config config, SitePaths site) { protected RulesCache (@GerritServerConfig Config config, SitePaths site) {
cacheDir = site.resolve(config.getString("cache", null, "directory")); cacheDir = site.resolve(config.getString("cache", null, "directory"));
if (cacheDir != null) { rulesDir = cacheDir != null ? new File(cacheDir, "rules") : null;
rulesDir = new File(cacheDir, "rules");
} else {
rulesDir = null;
}
} }
/** @return URLClassLoader with precompiled rules jar from rules.pl if it exists, /**
* null otherwise * @return ClassLoader with compiled rules jar from rules.pl if it exists;
* null otherwise.
*/ */
public synchronized ClassLoader getClassLoader(ObjectId rulesId) { public synchronized ClassLoader getClassLoader(ObjectId rulesId) {
if (rulesId == null || rulesDir == null) { if (rulesId == null || rulesDir == null) {

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.AccountGroup; import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.reviewdb.Project; import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.rules.PrologEnvironment; import com.google.gerrit.rules.PrologEnvironment;
import com.google.gerrit.rules.RulesCache;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.AllProjectsName; import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.AccountProjectWatch;
import com.google.gerrit.reviewdb.Change; import com.google.gerrit.reviewdb.Change;
import com.google.gerrit.reviewdb.Project; import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.rules.PrologEnvironment; import com.google.gerrit.rules.PrologEnvironment;
import com.google.gerrit.rules.RulesCache;
import com.google.gerrit.server.AccessPath; import com.google.gerrit.server.AccessPath;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.CapabilityControl; import com.google.gerrit.server.account.CapabilityControl;