|
Glassfish example source code file (AutoDeployedFilesManager.java)
The Glassfish AutoDeployedFilesManager.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ /* * AutoDeployedFilesManager.java * * Created on September 4, 2003 * */ package org.glassfish.deployment.autodeploy; import com.sun.logging.LogDomains; import java.io.*; import java.net.URI; import java.util.*; import java.util.logging.Logger; import java.util.logging.Level; import org.glassfish.deployment.common.DeploymentUtils; /** * Contains the status of list of files that have been autodeployed. * * @author Mahesh Rangamani */ public class AutoDeployedFilesManager { private static final Logger sLogger=LogDomains.getLogger(DeploymentUtils.class, LogDomains.DPL_LOGGER); static final String STATUS_DIR_NAME = ".autodeploystatus"; /* * Macs use .DS_Store in a folder to track information about * changes to the contents of the folder. If a user uses Finder to move * a previously-autodeployed file to the Trash, the system creates and/or updates .DS_Store. * Clearly we do not want to try deploying that file. */ private static final String DS_STORE = ".DS_Store"; /* * We need to exclude the osgi bundles from being processed by AutoDeployer * and let FileInstall monitor them. */ private static final String OSGI_AUTODEPLOY_DIR ="bundles"; private List<String> FILE_NAMES_TO_IGNORE_FOR_AUTODEPLOY = new ArrayList(); protected String statDir = null; public AutoDeployedFilesManager() { } protected AutoDeployedFilesManager(String s) { statDir = s; FILE_NAMES_TO_IGNORE_FOR_AUTODEPLOY.add(DS_STORE); FILE_NAMES_TO_IGNORE_FOR_AUTODEPLOY.add(OSGI_AUTODEPLOY_DIR); } /** * Create an instance from the persisted file in the specified directory. * @param statusDir Directory in which the status file is to read. */ public static AutoDeployedFilesManager loadStatus(File statusDir) throws Exception { return loadStatus(statusDir.getAbsolutePath()); } public static AutoDeployedFilesManager loadStatus(String autoDeploymentDir) throws Exception { String statusDir = autoDeploymentDir + File.separator + STATUS_DIR_NAME; AutoDeployedFilesManager adfm = new AutoDeployedFilesManager(statusDir); return adfm; } public void writeStatus() throws Exception { // Nothing to do } /** * Update the status of the file as deployed. * */ public void setDeployedFileInfo(File f) throws Exception { try { File statusFile = getStatusFile(f); statusFile.createNewFile(); statusFile.setLastModified(f.lastModified()); } catch (Exception e) { throw e; } } /* * Delete status info for file */ public void deleteDeployedFileInfo(File f) throws Exception { try { File statusFile = getStatusFile(f); statusFile.delete(); } catch (Exception e) { throw e;} } // calculate the status file path. private File getStatusFile(File f) { File outDir = new File(this.statDir); outDir = obtainFileStatusDir(f, outDir, outDir.getParentFile()); return new File(outDir, f.getName()); } static File obtainFileStatusDir(File f, File statDir, File autoDeployDir) { File dir = f.getParentFile(); while (!dir.getAbsolutePath().equals(autoDeployDir.getAbsolutePath())) { statDir = new File(statDir, dir.getName()); dir = dir.getParentFile(); } /* * Do not create all the required directories if the ancestor * autoDeployDir does not already exist. This helps with a race condition * in which a user has stopped the domain (which returns before the * domain has really stopped) and then deleted the domain. In some * cases the delete-domain processing deletes files only for the * autodeployer - still running - to create the autodeploy directory * and all intervening ones again. */ if (autoDeployDir.exists()) { statDir.mkdirs(); } return statDir; } /** * Compare the list of files with the current status info * and determine the files that need to be deployed * */ public File[] getFilesForDeployment(File[] latestFiles) { if (latestFiles == null) return new File[0]; ArrayList<File> arrList = new ArrayList Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish AutoDeployedFilesManager.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.