Project.java revision 123
58N/A/*
58N/A * CDDL HEADER START
58N/A *
58N/A * The contents of this file are subject to the terms of the
58N/A * Common Development and Distribution License (the "License").
58N/A * You may not use this file except in compliance with the License.
58N/A *
58N/A * See LICENSE.txt included in this distribution for the specific
58N/A * language governing permissions and limitations under the License.
58N/A *
58N/A * When distributing Covered Code, include this CDDL HEADER in each
58N/A * file and include the License file at LICENSE.txt.
58N/A * If applicable, add the following below this CDDL HEADER, with the
58N/A * fields enclosed by brackets "[]" replaced with your own identifying
58N/A * information: Portions Copyright [yyyy] [name of copyright owner]
58N/A *
58N/A * CDDL HEADER END
58N/A */
58N/A
58N/A/*
58N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
58N/A * Use is subject to license terms.
58N/A */
58N/Apackage org.opensolaris.opengrok.configuration;
58N/A
123N/Aimport java.io.File;
123N/A
58N/A/**
77N/A * Placeholder for the information that builds up a project
77N/A */
58N/Apublic class Project {
58N/A private String path;
58N/A private String description;
58N/A
77N/A /**
77N/A * Get a textual description of this project
77N/A * @return a textual description of the project
77N/A */
58N/A public String getDescription() {
58N/A return description;
58N/A }
58N/A
77N/A /**
77N/A * Get the path (relative from source root) where this project is located
77N/A * @return the relative path
77N/A */
58N/A public String getPath() {
58N/A return path;
58N/A }
58N/A
77N/A /**
77N/A * Set a textual description of this project
77N/A * @param description a textual description of the project
77N/A */
58N/A public void setDescription(String description) {
58N/A this.description = description;
58N/A }
58N/A
77N/A /**
77N/A * Set the path (relative from source root) this project is located
77N/A * @param path the relative path from source sroot where this project is
77N/A * located.
77N/A */
58N/A public void setPath(String path) {
58N/A this.path = path;
58N/A }
58N/A
77N/A /**
77N/A * Creates a new instance of Project
77N/A */
58N/A public Project() {
58N/A }
58N/A
77N/A /**
77N/A * Create a new instance of Project with a given description and path
77N/A * @param description the description of this project
77N/A * @param path the path to where this project is located (relative from source root)
77N/A */
58N/A public Project(String description, String path) {
58N/A this.description = description;
58N/A this.path = path;
58N/A }
123N/A
123N/A /**
123N/A * Get the project for a specific file
123N/A * @param path the file to lookup (relative from source root)
123N/A * @return the project that this file belongs to (or null if the file
123N/A * doesn't belong to a project)
123N/A */
123N/A public static Project getProject(String path) {
123N/A Project ret = null;
123N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
123N/A if (env.hasProjects()) {
123N/A for (Project proj : env.getProjects()) {
123N/A if (path.indexOf(proj.getPath()) == 0) {
123N/A ret = proj;
123N/A }
123N/A }
123N/A }
123N/A return ret;
123N/A }
123N/A
123N/A /**
123N/A * Get the project for a specific file
123N/A * @param file the file to lookup
123N/A * @return the project that this file belongs to (or null if the file
123N/A * doesn't belong to a project)
123N/A */
123N/A public static Project getProject(File file) {
123N/A Project ret = null;
123N/A String root = RuntimeEnvironment.getInstance().getSourceRootFile().getAbsolutePath();
123N/A String me = file.getAbsolutePath();
123N/A if (me.startsWith(root)) {
123N/A ret = getProject(me.substring(root.length()));
123N/A }
123N/A return ret;
123N/A }
58N/A}