org.glassfish.scripting.grails.GrailsSniffer Maven / Gradle / Ivy
The newest version!
/*
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2008 Sun Microsystems, Inc. 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.html
* or glassfish/bootstrap/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 glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [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.
*/
package org.glassfish.scripting.grails;
import com.sun.enterprise.module.Module;
import com.sun.enterprise.module.ModuleDefinition;
import com.sun.enterprise.module.ModulesRegistry;
import org.glassfish.api.container.Sniffer;
import org.glassfish.api.deployment.archive.ReadableArchive;
import org.jvnet.hk2.annotations.Inject;
import org.jvnet.hk2.annotations.Scoped;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.component.Habitat;
import org.jvnet.hk2.component.Singleton;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Enumeration;
import java.util.Map;
import java.util.logging.Logger;
/**
* Grails sniffer
*/
@Service(name = "grails")
@Scoped(Singleton.class)
public class GrailsSniffer implements Sniffer {
@Inject
Habitat habitat;
@Inject
ModulesRegistry registry;
private static final String WEB_XML = "WEB-INF/web.xml";
private static final String GRAILS_XML = "WEB-INF/grails.xml";
private static final String GRAILS_APP_DIR="WEB-INF/grails-app";
private static final String GSP_SUFFIX = ".gsp";
private final String[] containers = {"org.glassfish.scripting.grails.GrailsContainer"};
private final String containerName = "grails";
public boolean handles(ReadableArchive archive, ClassLoader classLoader) {
return isGrailsApp(archive);
}
private boolean isGrailsApp(ReadableArchive archive){
try {
if (archive.exists(WEB_XML) && archive.exists(GRAILS_XML) &&
archive.exists(GRAILS_APP_DIR) ) {
return true;
}
Enumeration entries = archive.entries();
while (entries.hasMoreElements()) {
String entryName = entries.nextElement();
if (entryName.endsWith(GSP_SUFFIX)) {
return true;
}
}
return false;
} catch (IOException ioe) {
// ignore
}
return false;
}
public String[] getURLPatterns() {
return null;
}
public Class extends Annotation>[] getAnnotationTypes() {
return new Class[0];
}
public String getModuleType() {
return containerName;
}
/**
* Sets up the container libraries so that any imported bundle from the
* connector jar file will now be known to the module subsystem
*
* This method returns a {@link ModuleDefinition} for the module containing
* the core implementation of the container. That means that this module
* will be locked as long as there is at least one module loaded in the
* associated container.
*
* @param containerHome is where the container implementation resides
* @param logger the logger to use
* @return the module definition of the core container implementation.
* @throws java.io.IOException exception if something goes sour
*/
public Module[] setup(String containerHome, Logger logger) throws IOException {
return null;
}
public void tearDown() {
}
public String[] getContainersNames() {
return containers;
}
public boolean isUserVisible() {
return false;
}
public Map getDeploymentConfigurations(ReadableArchive readableArchive) throws IOException {
return null;
}
@Override
public String[] getIncompatibleSnifferTypes() {
return new String[0];
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy