expanddeploygenerator.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,151 行 · 第 1/2 页

JAVA
1,151
字号
      for (int i = 0; updatedNames != null && i < updatedNames.size(); i++) {	String name = updatedNames.get(i);	getDeployContainer().update(name);      }    } finally {      if (isDeploying) {	_isModified = false;	_isDeploying = false;      }    }  }  /**   * Finds the matching entry.   */  public E generateController(String name)  {    request();    Thread thread = Thread.currentThread();    ClassLoader oldLoader = thread.getContextClassLoader();    try {      thread.setContextClassLoader(getParentClassLoader());	      E controller = createController(name);      if (controller != null) {	controller.setExpandCleanupFileSet(_expandCleanupFileSet);	_controllerNames.add(name); // server/1d19      }            return controller;    } finally {      thread.setContextClassLoader(oldLoader);    }  }  /**   * Returns the digest of the expand and archive directories.   */  private long getDigest()  {    long digest = 0;        long archiveDigest = 0;        Path archiveDirectory = getArchiveDirectory();    if (archiveDirectory != null)      archiveDigest = archiveDirectory.getCrc64();    digest = Crc64.generate(digest, archiveDigest);        long expandDigest = 0;        Path expandDirectory = getExpandDirectory();    if (expandDirectory != null)      expandDigest = expandDirectory.getCrc64();        digest = Crc64.generate(digest, expandDigest);    if (_git != null && _gitPath != null) {      String []tags = _git.listRefs(_gitPath);      for (int i = 0; tags != null && i < tags.length; i++) {	digest = Crc64.generate(digest, tags[i]);      }    }    return digest;  }  public Path getGitRefPath(String name)  {    return _git.getRefPath(_gitPath + "/" + name);  }  public ArrayList<String> getVersionNames(String name)  {    if (! isVersioning())      return null;        TreeSet<String> entryNames;    try {      entryNames = findEntryNames();    } catch (IOException e) {      throw new RuntimeException(e);    }    TreeMap<String,ArrayList<String>> versionMap = buildVersionMap(entryNames);    return versionMap.get(name);  }    /**   * Return the entry names for all deployed objects.   */  private TreeSet<String> findEntryNames()    throws IOException  {    TreeSet<String> entryNames = new TreeSet<String>();    addArchiveEntryNames(entryNames);    addExpandEntryNames(entryNames);    addRepositoryEntryNames(entryNames);    return entryNames;  }    /**   * Return the entry names for all deployed objects.   */  private void addArchiveEntryNames(TreeSet<String> entryNames)    throws IOException  {    Path archiveDirectory = getArchiveDirectory();    if (archiveDirectory == null)      return;    String []entryList = archiveDirectory.list();    // collect all the new entrys    loop:    for (int i = 0; i < entryList.length; i++) {      String archiveName = entryList[i];      Path archivePath = archiveDirectory.lookup(archiveName);      String entryName = null;            if (! archivePath.canRead())        continue;      else	entryName = archiveNameToEntryName(archiveName);      if (entryName != null) {	entryNames.add(entryName);	if (_isVersioning) {	  int p = entryName.lastIndexOf('-');	  if (p >= 0) {	    entryName = entryName.substring(0, p);	    if (! entryNames.contains(entryName))	      entryNames.add(entryName);	  }	}      }    }  }    /**   * Return the entry names for all deployed objects.   */  private void addExpandEntryNames(TreeSet<String> entryNames)    throws IOException  {    Path expandDirectory = getExpandDirectory();    if (expandDirectory == null)      return;        String []entryExpandList = expandDirectory.list();    // collect all the new war expand directories    loop:    for (int i = 0; i < entryExpandList.length; i++) {      String pathName = entryExpandList[i];      /* XXX: this used to be needed to solve issues with NT      if (CauchoSystem.isCaseInsensitive())        pathName = pathName.toLowerCase();      */      Path rootDirectory = expandDirectory.lookup(pathName);            String entryName = pathNameToEntryName(pathName);      if (entryName == null)	continue;      else if (entryName.endsWith(getExtension()))	continue;      if (! isValidDirectory(rootDirectory, pathName))	continue;      if (! entryNames.contains(entryName))	entryNames.add(entryName);      if (_isVersioning) {	int p = entryName.lastIndexOf('-');	if (p >= 0) {	  entryName = entryName.substring(0, p);	  if (! entryNames.contains(entryName))	    entryNames.add(entryName);	}      }    }  }    /**   * Return the entry names for all repository objects.   */  private void addRepositoryEntryNames(TreeSet<String> entryNames)    throws IOException  {    if (_git == null || _gitPath == null)      return;        String []pathList = _git.listRefs(_gitPath);    // collect all the new repository expand directories    for (String pathName : pathList) {      entryNames.add(pathName);    }  }    /**   * Return the entry names for all deployed objects.   */  private TreeMap<String,ArrayList<String>>    buildVersionMap(TreeSet<String> entryNames)  {    TreeMap<String,ArrayList<String>> versionMap;    versionMap = new TreeMap<String,ArrayList<String>>();    for (String name : entryNames) {      String baseName = versionedNameToBaseName(name);      if (_isVersioning && ! baseName.equals(name)) {	ArrayList<String> list = versionMap.get(baseName);	if (list == null)	  list = new ArrayList<String>();	list.add(name);	versionMap.put(baseName, list);      }    }    return versionMap;  }  protected boolean isValidDirectory(Path rootDirectory, String pathName)  {        if (! rootDirectory.isDirectory() || pathName.startsWith(".")) {      return false;    }    if (pathName.equalsIgnoreCase("web-inf")	|| pathName.equalsIgnoreCase("meta-inf"))      return false;    for (int j = 0; j < _requireFiles.size(); j++) {      String file = _requireFiles.get(j);      if (! rootDirectory.lookup(file).canRead())	return false;    }    return true;  }  /**   * Converts the expand-path name to the entry name, returns null if   * the path name is not valid.   */  protected String pathNameToEntryName(String name)  {    if (_expandPrefix == null) {    }    else if (_expandPrefix.equals("")	     && (name.startsWith("_")		 || name.startsWith(".")		 || name.endsWith(".") && CauchoSystem.isWindows()		 || name.equalsIgnoreCase("META-INF")		 || name.equalsIgnoreCase("WEB-INF"))) {      return null;    }    else if (name.startsWith(_expandPrefix)) {      name = name.substring(_expandPrefix.length());    }    else      return null;    if (_expandSuffix == null || "".equals(_expandSuffix)) {    }    else if (name.endsWith(_expandSuffix))      return name.substring(0, name.length() - _expandSuffix.length());    else      return null;    if (_extension != null && name.endsWith(_extension))      return name.substring(0, name.length() - _extension.length());    else      return name;  }  /**   * Converts the archive name to the entry name, returns null if   * the archive name is not valid.   */  protected String entryNameToArchiveName(String entryName)  {    return entryName + getExtension();  }  /**   * Converts the entry name to the archive name, returns null if   * the entry name is not valid.   */  protected String archiveNameToEntryName(String archiveName)  {    if (! archiveName.endsWith(_extension))      return null;    else {      int sublen = archiveName.length() - _extension.length();      return pathNameToEntryName(archiveName.substring(0, sublen));    }  }  /**   * Creates a new entry.   */  abstract protected E createController(String name);  private String nameToEntryName(String name)  {    return archiveNameToEntryName(name + getExtension());  }  private String entryNameToName(String name)  {    String archiveName = entryNameToArchiveName(name);    if (archiveName == null)      return null;    else      return archiveName.substring(0, archiveName.length() - getExtension().length());  }  /**   * returns a version's base name.   */  private String versionedNameToBaseName(String name)  {    int p = name.lastIndexOf('-');    int ch;        if (p > 0 && p + 1 < name.length()	&& '0' <= (ch = name.charAt(p + 1)) && ch <= '9')      return name.substring(0, p);    else      return name;  }  public String[] getNames()  {    String[] names = new String[_controllerNames.size()];    int i = 0;    for (String controllerName : _controllerNames) {      names[i++] = entryNameToName(controllerName);    }    return names;  }  private String getNamesAsString()  {    StringBuilder builder = new StringBuilder();    for (String name : getNames()) {      if (builder.length() > 0)        builder.append(", ");      builder.append(name);    }    builder.insert(0, '[');    builder.append(']');    return builder.toString();  }  /**   * Start the archive.   */  public boolean start(String name)  {    DeployController controller      = getDeployContainer().findController(nameToEntryName(name));    if (controller == null) {      if (log.isLoggable(Level.FINE))        log.log(Level.FINE, L.l("{0} unknown name '{1}' in start", this, name));      if (log.isLoggable(Level.FINER))        log.log(Level.FINER, L.l("{0} known names are {1} in start", this, getNamesAsString()));      return false;    }    controller.start();        return true;  }  /**   * Returns an exception for the named archive or null if there is no exception   */  public Throwable getConfigException(String name)  {    DeployController controller = getDeployContainer().findController(nameToEntryName(name));    if (controller == null) {      if (log.isLoggable(Level.FINE))        log.log(Level.FINE, L.l("unknown name '{0}'", name));      if (log.isLoggable(Level.FINER))        log.log(Level.FINER, L.l("known names are {0}", getNamesAsString()));      return new ConfigException(L.l("unknown name '{0}'", name));    }    return controller.getConfigException();  }  /**   * Stop the archive.   */  public boolean stop(String name)  {    DeployController controller = getDeployContainer().findController(nameToEntryName(name));    if (controller == null) {      if (log.isLoggable(Level.FINE))        log.log(Level.FINE, L.l("unknown name '{0}'", name));      if (log.isLoggable(Level.FINER))        log.log(Level.FINER, L.l("known names are {0}", getNamesAsString()));      return false;    }    controller.stop();    return true;  }  /**   * Undeploy the archive.   */  public boolean undeploy(String name)  {    DeployController controller      = getDeployContainer().findController(nameToEntryName(name));    if (controller == null) {      if (log.isLoggable(Level.FINE))        log.log(Level.FINE, L.l("unknown name '{0}'", name));      if (log.isLoggable(Level.FINER))        log.log(Level.FINER, L.l("known names are {0}", getNamesAsString()));      return false;    }    Path archivePath = getArchivePath(name);    Path expandPath = getExpandPath(name);    controller.stop();    try {      if (log.isLoggable(Level.FINEST))        log.log(Level.FINEST, L.l("deleting {0}", archivePath));      archivePath.removeAll();    }    catch (IOException ex) {      if (log.isLoggable(Level.FINE))        log.log(Level.FINE, ex.toString(), ex);    }    try {      if (expandPath != null) {        if (log.isLoggable(Level.FINEST))          log.log(Level.FINEST, L.l("deleting {0}", expandPath));        expandPath.removeAll();      }    }    catch (IOException ex) {      if (log.isLoggable(Level.FINE))        log.log(Level.FINE, ex.toString(), ex);    }    getDeployContainer().update(nameToEntryName(name));    return true;  }  /**   * Checks for updates.   */  public void handleAlarm(Alarm alarm)  {    if (isDestroyed())      return;        try {      // XXX: tck, but no QA test      // server/10ka      if ("automatic".equals(getRedeployMode()) && isActive())        request();    } catch (Exception e) {      log.log(Level.WARNING, e.toString(), e);    } finally {      _alarm.queue(_cronInterval);    }  }  /**   * Stops the deploy.   */  @Override  protected void stopImpl()  {    _alarm.dequeue();    super.stopImpl();  }  /**   * Tests for equality.   */  public boolean equals(Object o)  {    if (o == null || ! getClass().equals(o.getClass()))      return false;    ExpandDeployGenerator deploy = (ExpandDeployGenerator) o;    Path expandDirectory = getExpandDirectory();    Path deployExpandDirectory = deploy.getExpandDirectory();    if (expandDirectory != deployExpandDirectory &&	(expandDirectory == null ||	 ! expandDirectory.equals(deployExpandDirectory)))      return false;    return true;  }  public String toString()  {    String name = getClass().getName();    int p = name.lastIndexOf('.');    if (p > 0)      name = name.substring(p + 1);        return name + "[" + getExpandDirectory() + "]";  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?