Project.java revision 949
761N/A/*
1072N/A * CDDL HEADER START
1072N/A *
1072N/A * The contents of this file are subject to the terms of the
946N/A * Common Development and Distribution License (the "License").
946N/A * You may not use this file except in compliance with the License.
946N/A *
761N/A * See LICENSE.txt included in this distribution for the specific
761N/A * language governing permissions and limitations under the License.
761N/A *
761N/A * When distributing Covered Code, include this CDDL HEADER in each
761N/A * file and include the License file at LICENSE.txt.
1072N/A * If applicable, add the following below this CDDL HEADER, with the
1072N/A * fields enclosed by brackets "[]" replaced with your own identifying
1072N/A * information: Portions Copyright [yyyy] [name of copyright owner]
761N/A *
761N/A * CDDL HEADER END
761N/A */
761N/A
351N/A/*
761N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
761N/A * Use is subject to license terms.
1072N/A */
761N/Apackage org.opensolaris.opengrok.configuration;
761N/A
351N/Aimport java.io.File;
761N/A
761N/A/**
761N/A * Placeholder for the information that builds up a project
761N/A */
761N/Apublic class Project {
1072N/A private String path;
761N/A // this variable is very important, since it's used as the project identifier all over xrefs and webapp
761N/A private String description;
351N/A
761N/A /**
761N/A * Size of tabs in this project. Used for displaying the xrefs correctly in
761N/A * projects with non-standard tab size.
761N/A */
761N/A private int tabSize;
761N/A
761N/A /**
761N/A * Get a textual description of this project
761N/A * @return a textual description of the project
761N/A */
761N/A public String getDescription() {
761N/A return description;
761N/A }
761N/A
761N/A /**
1072N/A * Get the path (relative from source root) where this project is located
1072N/A * @return the relative path
1072N/A */
351N/A public String getPath() {
351N/A return path;
351N/A }
761N/A
351N/A /**
351N/A * Get the project id
351N/A * @return the id of the project
1072N/A */
351N/A public String getId() {
351N/A return path;
351N/A }
351N/A
761N/A /**
761N/A * Get the tab size for this project, if tab size has been set.
351N/A *
351N/A * @return tab size if set, 0 otherwise
351N/A * @see #hasTabSizeSetting()
351N/A */
351N/A public int getTabSize() {
351N/A return tabSize;
351N/A }
351N/A
351N/A /**
351N/A * Set a textual description of this project, prefferably don't use " , " in the name, since it's used as delimiter for more projects
351N/A * @param description a textual description of the project
351N/A */
351N/A public void setDescription(String description) {
351N/A this.description = description;
351N/A }
351N/A
351N/A /**
351N/A * Set the path (relative from source root) this project is located
351N/A * It seems that you should ALWAYS prefix the path with current file.separator , current environment should always have it set up
351N/A * @param path the relative path from source sroot where this project is
1072N/A * located.
351N/A */
351N/A public void setPath(String path) {
351N/A this.path = path;
351N/A }
351N/A
351N/A /**
351N/A * Set tab size for this project. Used for expanding tabs to spaces
351N/A * in xrefs.
351N/A *
351N/A * @param tabSize the size of tabs in this project
351N/A */
351N/A public void setTabSize(int tabSize) {
351N/A this.tabSize = tabSize;
351N/A }
351N/A
351N/A /**
1072N/A * Has this project an explicit tab size setting?
351N/A *
351N/A * @return {@code true} if the tab size has been set for this project, or
351N/A * {@code false} if it hasn't and the default should be used
351N/A */
351N/A public boolean hasTabSizeSetting() {
351N/A return tabSize > 0;
351N/A }
351N/A
351N/A /**
351N/A * Get the project for a specific file
351N/A * @param path the file to lookup (relative from source root)
351N/A * @return the project that this file belongs to (or null if the file
351N/A * doesn't belong to a project)
351N/A */
1072N/A public static Project getProject(String path) {
351N/A Project ret = null;
351N/A String lpath=path;
351N/A if (System.getProperty("file.separator").compareTo("/")!=0) {lpath=path.replace(File.separatorChar, '/');}
351N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
351N/A if (env.hasProjects()) {
351N/A for (Project proj : env.getProjects()) {
351N/A if (lpath.indexOf(proj.getPath()) == 0) {
351N/A ret = proj;
351N/A }
351N/A }
351N/A }
351N/A return ret;
761N/A }
761N/A
351N/A /**
351N/A * Get the project for a specific file
1072N/A * @param file the file to lookup
351N/A * @return the project that this file belongs to (or null if the file
351N/A * doesn't belong to a project)
351N/A */
351N/A public static Project getProject(File file) {
351N/A Project ret = null;
351N/A String root = RuntimeEnvironment.getInstance().getSourceRootFile().getAbsolutePath();
351N/A String me = file.getAbsolutePath();
351N/A if (me.startsWith(root)) {
351N/A ret = getProject(me.substring(root.length()));
351N/A }
351N/A return ret;
351N/A }
351N/A
351N/A /**
351N/A * Returns project object by its description, used in webapp to figure out which project is to be searched
351N/A * @param desc description of the project
351N/A * @return project that fits the description
351N/A */
351N/A public static Project getByDescription(String desc) {
351N/A Project ret = null;
351N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
351N/A if (env.hasProjects()) {
351N/A for (Project proj : env.getProjects()) {
351N/A if (desc.indexOf(proj.getDescription()) == 0) {
351N/A ret = proj;
351N/A }
351N/A }
351N/A }
1072N/A return ret;
351N/A }
351N/A}
351N/A