001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.make;
031:
032: import com.caucho.loader.DynamicClassLoader;
033: import com.caucho.util.Alarm;
034: import com.caucho.util.Log;
035: import com.caucho.vfs.PersistentDependency;
036: import com.caucho.vfs.Dependency;
037:
038: import java.util.ArrayList;
039: import java.util.logging.Logger;
040:
041: /**
042: * Contains a set of dependencies.
043: */
044: public class DependencyList implements PersistentDependency {
045: private ArrayList<PersistentDependency> _dependencyList = new ArrayList<PersistentDependency>();
046:
047: public DependencyList() {
048: }
049:
050: /**
051: * Adds a dependency.
052: */
053: public DependencyList add(PersistentDependency dependency) {
054: if (dependency == this )
055: throw new IllegalArgumentException(
056: "Can't add self as a dependency.");
057:
058: if (!_dependencyList.contains(dependency))
059: _dependencyList.add(dependency);
060:
061: // server/1d0w
062: // XXX: _lastCheckTime = 0;
063:
064: return this ;
065: }
066:
067: /**
068: * Removes a dependency.
069: */
070: public DependencyList remove(PersistentDependency dependency) {
071: if (dependency == this )
072: throw new IllegalArgumentException(
073: "Can't remove self as a dependency.");
074:
075: _dependencyList.remove(dependency);
076:
077: return this ;
078: }
079:
080: /**
081: * Returns true if the underlying dependencies have changed.
082: */
083: public boolean isModified() {
084: for (int i = _dependencyList.size() - 1; i >= 0; i--) {
085: Dependency dependency = _dependencyList.get(i);
086:
087: if (dependency.isModified()) {
088: return true;
089: }
090: }
091:
092: return false;
093: }
094:
095: /**
096: * Logs the reason for modification.
097: */
098: public boolean logModified(Logger log) {
099: for (int i = _dependencyList.size() - 1; i >= 0; i--) {
100: Dependency dependency = _dependencyList.get(i);
101:
102: if (dependency.logModified(log))
103: return true;
104: }
105:
106: return false;
107: }
108:
109: /**
110: * Returns true if the underlying dependencies have changed, forcing a check.
111: */
112: public boolean isModifiedNow() {
113: return isModified();
114: }
115:
116: /**
117: * Returns a string to recreate the dependency.
118: */
119: public String getJavaCreateString() {
120: StringBuilder sb = new StringBuilder();
121:
122: sb.append("new com.caucho.make.DependencyList()");
123:
124: for (int i = 0; i < _dependencyList.size(); i++) {
125: sb.append(".add(");
126: sb.append(_dependencyList.get(i).getJavaCreateString());
127: sb.append(")");
128: }
129:
130: return sb.toString();
131: }
132:
133: public String toString() {
134: return "DependencyList" + _dependencyList;
135: }
136: }
|