Author: rob.stryker(a)jboss.com
Date: 2012-01-20 06:26:11 -0500 (Fri, 20 Jan 2012)
New Revision: 37999
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/.settings/.api_filters
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/IModulePathFilter.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/ModuleDirectoryScannerPathFilter.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/PublishFilterDirectoryScanner.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2BehaviourDelegate.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2FilterTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishFilterDirectoryScannerTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ResourceModuleResourceUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractBehaviourDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DelegatingServerBehavior.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IJBossBehaviourDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/plugin.xml
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java
Log:
https://issues.jboss.org/browse/JBIDE-10642 - with test cases! :D
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/.settings/.api_filters
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/.settings/.api_filters
(rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/.settings/.api_filters 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="no"?>
+<component id="org.jboss.ide.eclipse.as.core" version="2">
+ <resource
path="jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IJBossBehaviourDelegate.java"
type="org.jboss.ide.eclipse.as.core.server.internal.IJBossBehaviourDelegate">
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument
value="org.jboss.ide.eclipse.as.core.server.internal.IJBossBehaviourDelegate"/>
+ <message_argument value="getPathFilter(IModule[])"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF 2012-01-20
11:15:57 UTC (rev 37998)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF 2012-01-20
11:26:11 UTC (rev 37999)
@@ -33,6 +33,7 @@
org.jboss.ide.eclipse.as.core.extensions.polling,
org.jboss.ide.eclipse.as.core.modules,
org.jboss.ide.eclipse.as.core.publishers,
+ org.jboss.ide.eclipse.as.core.publishers.patterns,
org.jboss.ide.eclipse.as.core.server,
org.jboss.ide.eclipse.as.core.server.bean,
org.jboss.ide.eclipse.as.core.server.internal,
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ResourceModuleResourceUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ResourceModuleResourceUtil.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/ResourceModuleResourceUtil.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -12,21 +12,29 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Properties;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.model.IModuleFile;
import org.eclipse.wst.server.core.model.IModuleFolder;
import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.ModuleDelegate;
import org.eclipse.wst.server.core.util.ModuleFile;
import org.eclipse.wst.server.core.util.ModuleFolder;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
+import
org.jboss.ide.eclipse.as.core.publishers.patterns.ModuleDirectoryScannerPathFilter;
+import org.jboss.ide.eclipse.as.wtp.core.util.ServerModelUtilities;
public class ResourceModuleResourceUtil {
public static IModuleResource createResource(IResource resource) {
@@ -117,5 +125,70 @@
return newResources;
}
-
+ /**
+ * Utility method for just quickly discovering the filtered member list
+ * @since 2.3
+ */
+ public static IModuleResource[] getFilteredMembers(IModule module, String inc, String
exc) throws CoreException {
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, null);
+ ModuleDirectoryScannerPathFilter filter = new
ModuleDirectoryScannerPathFilter(md.members(), inc, exc);
+ return filter.getFilteredMembers();
+ }
+
+ /**
+ * Get a proper includes / excludes filter for this project if it exists
+ * or null
+ * @since 2.3
+ */
+ public static IModulePathFilter findDefaultModuleFilter(IModule module) {
+ if( ServerModelUtilities.isBinaryModule(module) )
+ return null;
+ String[] incExc = getProjectIncludesExcludes(module);
+ if( incExc != null ) {
+ try {
+ ModuleDirectoryScannerPathFilter filter =
+ new ModuleDirectoryScannerPathFilter(getMembers(module),
+ incExc[0], incExc[1]);
+ return filter;
+ } catch( CoreException ce ) {
+ JBossServerCorePlugin.getDefault().getLog().log(ce.getStatus());
+ }
+ }
+ return null;
+ }
+
+ private static IModuleResource[] getMembers(IModule module) throws CoreException {
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, new
NullProgressMonitor());
+ return md == null ? new IModuleResource[0] : md.members();
+ }
+
+
+ /**
+ * @since 2.3
+ */
+ public static final String COMPONENT_INCLUSIONS_PATTERN =
"component.inclusion.patterns"; //$NON-NLS-1$
+ /**
+ * @since 2.3
+ */
+ public static final String COMPONENT_EXCLUSIONS_PATTERN =
"component.exclusion.patterns"; //$NON-NLS-1$
+
+ /**
+ * Does this project have the proper settings that call for
+ * include and exclude patterns in the virtual component metadata?
+ *
+ * Return the includes / excludes pattern if yes.
+ * If no, return null
+ *
+ * @param module
+ * @return
+ */
+ private static String[] getProjectIncludesExcludes(IModule module) {
+ IProject p = module.getProject();
+ IVirtualComponent vc = ComponentCore.createComponent(p);
+ Properties props = vc.getMetaProperties();
+ return new String[]{
+ (String) props.get(COMPONENT_INCLUSIONS_PATTERN),
+ (String) props.get(COMPONENT_EXCLUSIONS_PATTERN)
+ };
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+* Copyright (c) 2011 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -36,9 +36,11 @@
import org.jboss.ide.eclipse.as.core.Messages;
import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.modules.ResourceModuleResourceUtil;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil;
import
org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
@@ -208,7 +210,7 @@
if( !forceZip && !isBinaryObject) {
PublishCopyUtil util = new PublishCopyUtil(callback);
- list.addAll(Arrays.asList(util.initFullPublish(members, getSubMon(monitor, 700))));
+ list.addAll(Arrays.asList(util.initFullPublish(members, getPathFilter(moduleTree),
getSubMon(monitor, 700))));
JSTPublisherXMLToucher.getInstance().touch(deployPath, module, callback);
} else if( isBinaryObject )
list.addAll(Arrays.asList(copyBinaryModule(moduleTree, getSubMon(monitor, 700))));
@@ -232,7 +234,7 @@
try {
ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
IModuleResource[] resources = pm.members();
-
+
IModule[] children = server.getServer().getChildModules(moduleTree, new
NullProgressMonitor());
for( int i = 0; i < children.length; i++ ) {
IPath path = new Path(pm.getPath(children[i]));
@@ -245,7 +247,8 @@
// Make output
temp = File.createTempFile(module.getName(), ".tmp", deployRoot.toFile());
//$NON-NLS-1$
IPath tempFile = new Path(temp.getAbsolutePath());
- IStatus[] e2 =
PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1].getName(), resources,
tempFile);
+ IStatus[] e2 =
PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1].getName(),
+ resources, tempFile, getPathFilter(moduleTree));;
errors.addAll(Arrays.asList(e2));
return temp;
} catch( IOException ioe) {
@@ -254,6 +257,18 @@
}
}
+
+ /**
+ * Some projects may request post-processing filtering on
+ * the servertools list of resources.
+ *
+ * @since 2.3
+ */
+ protected IModulePathFilter getPathFilter(IModule[] moduleTree) {
+ DeployableServerBehavior beh =
ServerConverter.getDeployableServerBehavior(server.getServer());
+ return beh.getPathFilter(moduleTree);
+ }
+
private boolean parentModuleIsForcedZip(IModule[] moduleTree) {
ArrayList<IModule> tmp = new ArrayList<IModule>();
tmp.addAll(Arrays.asList(moduleTree));
@@ -319,7 +334,7 @@
IPublishCopyCallbackHandler handler = null;
if( !forceZip && !isBinaryObject) {
handler = getCallbackHandler(deployPath);
- results = new PublishCopyUtil(handler).publishDelta(delta, getSubMon(monitor, 100));
+ results = new PublishCopyUtil(handler).publishDelta(delta, getPathFilter(moduleTree),
getSubMon(monitor, 100));
} else if( delta.length > 0 ) {
if( isBinaryObject)
results = copyBinaryModule(moduleTree, getSubMon(monitor, 100));
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -35,6 +35,7 @@
import org.eclipse.wst.server.core.util.ProjectModule;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.xpl.ModulePackager;
@@ -44,7 +45,6 @@
import
org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentTypePrefs;
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.core.util.IWTPConstants;
-import org.jboss.ide.eclipse.as.wtp.core.util.ServerModelUtilities;
public class PublishUtil {
public static int countChanges(IModuleResourceDelta[] deltas) {
@@ -314,14 +314,23 @@
return packModuleIntoJar(module.getName(), resources, destination);
}
- public static IStatus[] packModuleIntoJar(String moduleName, IModuleResource[]
resources, IPath destination)throws CoreException {
+ public static IStatus[] packModuleIntoJar(String moduleName, IModuleResource[]
resources, IPath destination) throws CoreException {
+ return packModuleIntoJar(moduleName, resources, destination, null);
+ }
+ /**
+ * @since 2.3
+ */
+ public static IStatus[] packModuleIntoJar(String moduleName, IModuleResource[]
resources,
+ IPath destination, IModulePathFilter filter) throws CoreException {
+
String dest = destination.toOSString();
ModulePackager packager = null;
try {
packager = new ModulePackager(dest, false);
for (int i = 0; i < resources.length; i++) {
- doPackModule(resources[i], packager);
+ if( filter == null || filter.shouldInclude(resources[i]))
+ doPackModule(resources[i], packager, filter);
}
} catch (IOException e) {
IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
IEventCodes.JST_PUB_ASSEMBLE_FAIL,
@@ -345,6 +354,13 @@
/* Add one file or folder to a jar */
public static void doPackModule(IModuleResource resource, ModulePackager packager)
throws CoreException, IOException{
+ doPackModule(resource, packager, null);
+ }
+
+ /**
+ * @since 2.3
+ */
+ public static void doPackModule(IModuleResource resource, ModulePackager packager,
IModulePathFilter filter) throws CoreException, IOException{
if (resource instanceof IModuleFolder) {
IModuleFolder mFolder = (IModuleFolder)resource;
IModuleResource[] resources = mFolder.members();
@@ -352,16 +368,18 @@
packager.writeFolder(resource.getModuleRelativePath().append(resource.getName()).toPortableString());
for (int i = 0; resources!= null && i < resources.length; i++) {
- doPackModule(resources[i], packager);
+ doPackModule(resources[i], packager, filter);
}
} else {
- String destination =
resource.getModuleRelativePath().append(resource.getName()).toPortableString();
- IFile file = (IFile) resource.getAdapter(IFile.class);
- if (file != null)
- packager.write(file, destination);
- else {
- File file2 = (File) resource.getAdapter(File.class);
- packager.write(file2, destination);
+ if( filter == null || filter.shouldInclude(resource)) {
+ String destination =
resource.getModuleRelativePath().append(resource.getName()).toPortableString();
+ IFile file = (IFile) resource.getAdapter(IFile.class);
+ if (file != null)
+ packager.write(file, destination);
+ else {
+ File file2 = (File) resource.getAdapter(File.class);
+ packager.write(file2, destination);
+ }
}
}
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/IModulePathFilter.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/IModulePathFilter.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/IModulePathFilter.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.publishers.patterns;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.server.core.model.IModuleResource;
+
+/**
+ * @since 2.3
+ */
+public interface IModulePathFilter {
+ /**
+ * This method should be used for incremental checks on a
+ * particular resource, such as during incremental publishing
+ * through deltas.
+ *
+ * It *can* be used throughout the entire tree without a substantial
+ * performance hit, however, the suggested API to use for that is
+ * getFilteredResources(IModuleResource[] original)
+ *
+ * @param moduleResource The resource to check
+ * @return
+ */
+ public boolean shouldInclude(IModuleResource moduleResource);
+
+ /**
+ * The easiest way to get a new clean pre-filtered list of members
+ * that actually need to be published
+ *
+ * @return the filtered list of members
+ */
+ public IModuleResource[] getFilteredMembers() throws CoreException;
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/ModuleDirectoryScannerPathFilter.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/ModuleDirectoryScannerPathFilter.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/ModuleDirectoryScannerPathFilter.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.publishers.patterns;
+
+import org.eclipse.wst.server.core.model.IModuleResource;
+
+/**
+ * @since 2.3
+ */
+public class ModuleDirectoryScannerPathFilter implements IModulePathFilter {
+
+ private IModuleResource[] members;
+ private String includes, excludes;
+ private PublishFilterDirectoryScanner scanner;
+ private boolean scanned = false;
+ public ModuleDirectoryScannerPathFilter(IModuleResource[] members,
+ String includes, String excludes) {
+ this.members = members;
+ this.includes = includes;
+ this.excludes = excludes;
+ scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes(includes);
+ scanner.setExcludes(excludes);
+ }
+
+ private void ensureScanned() {
+ // TODO add synchronized
+ if( !scanned ) {
+ scanner.scan();
+ scanned = true;
+ }
+ }
+
+ @Override
+ public boolean shouldInclude(IModuleResource moduleResource) {
+ ensureScanned();
+ return scanner.isRequiredMember(moduleResource);
+ }
+
+ @Override
+ public IModuleResource[] getFilteredMembers() {
+ ensureScanned();
+ return scanner.getCleanedMembers();
+ }
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/PublishFilterDirectoryScanner.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/PublishFilterDirectoryScanner.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/patterns/PublishFilterDirectoryScanner.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,965 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+/*
+ * This file has been CHANGED, MODIFIED, EDITED.
+ * It has been coppied because list(File file) is
+ * a private method and is not able to be overridden.
+ *
+ * For archives, we need to be able to delegate to
+ * the eclipse VFS / resource model.
+ * rob.stryker(a)redhat.com
+ */
+package org.jboss.ide.eclipse.as.core.publishers.patterns;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import org.apache.tools.ant.types.selectors.SelectorUtils;
+import org.apache.tools.ant.util.FileUtils;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleFolder;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.util.ModuleFolder;
+
+/**
+ * Class for scanning a directory for files/directories which match certain
+ * criteria.
+ * <p>
+ * These criteria consist of patterns which have been specified.
+ * With patterns you can include or exclude files based on their filename.
+ * <p>
+ * The idea is simple. A given directory is recursively scanned for all files
+ * and directories. Each file/directory is matched against a set of selectors,
+ * including special support for matching against filenames with include and
+ * and exclude patterns. Only files/directories which match at least one
+ * pattern of the include pattern list , and don't match
+ * any pattern of the exclude pattern list will be placed in the list of
files/directories found.
+ * <p>
+ * When no list of include patterns is supplied, "**" will be used, which
+ * means that everything will be matched. When no list of exclude patterns is
+ * supplied, an empty list is used, such that nothing will be excluded.
+ * <p>
+ * The filename pattern matching is done as follows:
+ * The name to be matched is split up in path segments. A path segment is the
+ * name of a directory or file, which is bounded by
+ * <code>File.separator</code> ('/' under UNIX, '\' under
Windows).
+ * For example, "abc/def/ghi/xyz.java" is split up in the segments
"abc",
+ * "def","ghi" and "xyz.java".
+ * The same is done for the pattern against which should be matched.
+ * <p>
+ * The segments of the name and the pattern are then matched against each
+ * other. When '**' is used for a path segment in the pattern, it matches
+ * zero or more path segments of the name.
+ * <p>
+ * There is a special case regarding the use of <code>File.separator</code>s
+ * at the beginning of the pattern and the string to match:<br>
+ * When a pattern starts with a <code>File.separator</code>, the string
+ * to match must also start with a <code>File.separator</code>.
+ * When a pattern does not start with a <code>File.separator</code>, the
+ * string to match may not start with a <code>File.separator</code>.
+ * When one of these rules is not obeyed, the string will not
+ * match.
+ * <p>
+ * When a name path segment is matched against a pattern path segment, the
+ * following special characters can be used:<br>
+ * '*' matches zero or more characters<br>
+ * '?' matches one character.
+ * <p>
+ * Examples:
+ * <p>
+ * "**\*.class" matches all .class files/dirs in a directory tree.
+ * <p>
+ * "test\a??.java" matches all files/dirs which start with an 'a', then
two
+ * more characters and then ".java", in a directory called test.
+ * <p>
+ * "**" matches everything in a directory tree.
+ * <p>
+ * "**\test\**\XYZ*" matches all files/dirs which start with "XYZ"
and where
+ * there is a parent directory called test (e.g. "abc\test\def\ghi\XYZ123").
+ * <p>
+ * Case sensitivity may be turned off if necessary. By default, it is
+ * turned on.
+ * <p>
+ * Example of usage:
+ * <pre>
+ * String[] includes = {"**\\*.class"};
+ * String[] excludes = {"modules\\*\\**"};
+ * ds.setIncludes(includes);
+ * ds.setExcludes(excludes);
+ * ds.setBasedir(new File("test"));
+ * ds.setCaseSensitive(true);
+ * ds.scan();
+ *
+ * System.out.println("FILES:");
+ * String[] files = ds.getIncludedFiles();
+ * for (int i = 0; i < files.length; i++) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ * This will scan a directory called test for .class files, but excludes all
+ * files in all proper subdirectories of a directory called "modules"
+ * @since 2.3
+ *
+ */
+
+/*
+ * Note: This class ideally should be translated, but since
+ * it was stolen from ant, I'd rather leave it as close to the ant
+ * version as possible.
+ *
+ * Started to diverge quite a bit in preparation for
+ */
+/**
+ * @since 2.3
+ */
+public class PublishFilterDirectoryScanner {
+
+ /** The base directory to be scanned relative to module root. */
+ protected IPath basedir;
+
+ /** The patterns for the files to be included. */
+ protected String[] includes;
+
+ /** The patterns for the files to be excluded. */
+ protected String[] excludes;
+
+ /**
+ * The files which matched at least one include and no excludes
+ * and were selected.
+ */
+ protected Vector<String> filesIncluded;
+
+ /** The files which did not match any includes or selectors. */
+ protected Vector<String> filesNotIncluded;
+
+ /**
+ * The files which matched at least one include and at least
+ * one exclude.
+ */
+ protected Vector<String> filesExcluded;
+
+ /**
+ * The directories which matched at least one include and no excludes
+ * and were selected.
+ */
+ protected Vector<String> dirsIncluded;
+
+ /** The directories which were found and did not match any includes. */
+ protected Vector<String> dirsNotIncluded;
+
+ /** The directories which were found and did not match any includes, but must be
created because files under it are required */
+ protected Vector<String> dirsNotIncludedButRequired;
+
+ /**
+ * The directories which matched at least one include and at least one
+ * exclude.
+ */
+ protected Vector<String> dirsExcluded;
+
+ /** Whether or not everything tested so far has been included. */
+ protected boolean everythingIncluded = true;
+
+ // CheckStyle:VisibilityModifier ON
+
+ /**
+ * List of all scanned directories.
+ *
+ * @since Ant 1.6
+ */
+ private Set<String> scannedDirs = new HashSet<String>();
+
+ /**
+ * Set of all include patterns that are full file names and don't
+ * contain any wildcards.
+ *
+ * <p>If this instance is not case sensitive, the file names get
+ * turned to lower case.</p>
+ *
+ * <p>Gets lazily initialized on the first invocation of
+ * isIncluded or isExcluded and cleared at the end of the scan
+ * method (cleared in clearCaches, actually).</p>
+ *
+ * @since Ant 1.6.3
+ */
+ private Set<String> includeNonPatterns = new HashSet<String>();
+
+ /**
+ * Set of all include patterns that are full file names and don't
+ * contain any wildcards.
+ *
+ * <p>If this instance is not case sensitive, the file names get
+ * turned to lower case.</p>
+ *
+ * <p>Gets lazily initialized on the first invocation of
+ * isIncluded or isExcluded and cleared at the end of the scan
+ * method (cleared in clearCaches, actually).</p>
+ *
+ * @since Ant 1.6.3
+ */
+ private Set<String> excludeNonPatterns = new HashSet<String>();
+
+ /**
+ * Array of all include patterns that contain wildcards.
+ *
+ * <p>Gets lazily initialized on the first invocation of
+ * isIncluded or isExcluded and cleared at the end of the scan
+ * method (cleared in clearCaches, actually).</p>
+ *
+ * @since Ant 1.6.3
+ */
+ private String[] includePatterns;
+
+ /**
+ * Array of all exclude patterns that contain wildcards.
+ *
+ * <p>Gets lazily initialized on the first invocation of
+ * isIncluded or isExcluded and cleared at the end of the scan
+ * method (cleared in clearCaches, actually).</p>
+ *
+ * @since Ant 1.6.3
+ */
+ private String[] excludePatterns;
+
+ /**
+ * Have the non-pattern sets and pattern arrays for in- and
+ * excludes been initialized?
+ *
+ * @since Ant 1.6.3
+ */
+ private boolean areNonPatternSetsReady = false;
+
+ private IModuleResource[] resources;
+
+ /**
+ * Sole constructor.
+ */
+ public PublishFilterDirectoryScanner(IModuleResource[] resources) {
+ this.resources = resources;
+ setBasedir(new Path("/")); //$NON-NLS-1$
+ }
+
+ /* Protected static class delegators to SelectorUtils */
+
+ protected static boolean matchPatternStart(String pattern, String str) {
+ return SelectorUtils.matchPatternStart(pattern, str);
+ }
+
+ protected static boolean matchPatternStart(String pattern, String str,
+ boolean isCaseSensitive) {
+ return SelectorUtils.matchPatternStart(pattern, str, isCaseSensitive);
+ }
+
+ protected static boolean matchPath(String pattern, String str) {
+ return SelectorUtils.matchPath(pattern, str);
+ }
+
+ protected static boolean matchPath(String pattern, String str,
+ boolean isCaseSensitive) {
+ return SelectorUtils.matchPath(pattern, str, isCaseSensitive);
+ }
+
+ public static boolean match(String pattern, String str) {
+ return SelectorUtils.match(pattern, str);
+ }
+
+ protected static boolean match(String pattern, String str,
+ boolean isCaseSensitive) {
+ return SelectorUtils.match(pattern, str, isCaseSensitive);
+ }
+
+ public synchronized void setBasedir(IPath basedir) {
+ this.basedir = basedir;
+ }
+
+ public synchronized IPath getBasedir() {
+ return basedir;
+ }
+ /* end Base dir */
+
+
+ public synchronized void setIncludes(String includes) {
+ boolean nullInc = includes == null || "".equals(includes); //$NON-NLS-1$
+ setIncludes(nullInc ? null : includes.split(",")); //$NON-NLS-1$
+ }
+
+ public synchronized void setIncludes(String[] includes) {
+ if (includes == null) {
+ this.includes = null;
+ } else {
+ this.includes = new String[includes.length];
+ for (int i = 0; i < includes.length; i++) {
+ this.includes[i] = normalizePattern(includes[i]);
+ }
+ }
+ }
+
+ public synchronized void setExcludes(String excludes) {
+ setExcludes(excludes == null ? new String[0] : excludes.split(","));
//$NON-NLS-1$
+ }
+
+ public synchronized void setExcludes(String[] excludes) {
+ if (excludes == null) {
+ this.excludes = null;
+ } else {
+ this.excludes = new String[excludes.length];
+ for (int i = 0; i < excludes.length; i++) {
+ this.excludes[i] = normalizePattern(excludes[i]);
+ }
+ }
+ }
+
+ private static String normalizePattern(String p) {
+ String pattern = p.replace('/', File.separatorChar)
+ .replace('\\', File.separatorChar);
+ if (pattern.endsWith(File.separator)) {
+ pattern += "**";//$NON-NLS-1$
+ }
+ return pattern;
+ }
+
+ public synchronized boolean isEverythingIncluded() {
+ return everythingIncluded;
+ }
+
+
+ protected void scanPrepare() {
+ clearResults();
+ boolean nullIncludes = includes == null;
+ includes = includes == null ? new String[] {"**"} :
includes;//$NON-NLS-1$
+ excludes = excludes == null ? new String[0] : excludes;
+
+ if (basedir == null ) {
+ // if no basedir and no includes, nothing to do:
+ if (nullIncludes) {
+ return;
+ }
+ }
+ if (isIncluded("")) {//$NON-NLS-1$
+ if (!isExcluded("")) {//$NON-NLS-1$
+ dirsIncluded.addElement("");//$NON-NLS-1$
+ } else {
+ dirsExcluded.addElement("");//$NON-NLS-1$
+ }
+ } else {
+ dirsNotIncluded.addElement("");//$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Scan for files which match at least one include pattern and don't match
+ * any exclude patterns. If there are selectors then the files must pass
+ * muster there, as well. Scans under basedir, if set; otherwise the
+ * include patterns without leading wildcards specify the absolute paths of
+ * the files that may be included.
+ *
+ * @exception IllegalStateException if the base directory was set
+ * incorrectly (i.e. if it doesn't exist or isn't a directory).
+ */
+ public void scan() throws IllegalStateException {
+ try {
+ synchronized (this) {
+ scanPrepare();
+ runScan();
+ }
+ } finally {
+ release();
+ }
+ }
+
+ protected void release() {
+ clearCaches();
+ }
+
+ private IModuleFolder findBaseDirResource(IPath path) {
+ IModuleResource root = findResource(null, path);
+ if( root != null && !(root instanceof IModuleFolder))
+ throw new UnsupportedOperationException("Base Directory Cannot Be A
File"); //$NON-NLS-1$
+ return (IModuleFolder)root;
+ }
+
+ private IModuleResource findResource(IModuleFolder parent, IPath path) {
+ return findResource(resources, parent, path);
+ }
+
+ public static IModuleResource findResource(IModuleResource[] allMembers,
+ IModuleFolder parent, IPath path) {
+ if( path == null || path.segmentCount() == 0 )
+ return null;
+
+ IModuleResource[] children = parent == null ? allMembers : parent.members();
+ for( int i = 0; i < children.length; i++ ) {
+ if( children[i].getName().equals(path.segment(0))) {
+ // we found our leaf
+ if( path.segmentCount() == 1 )
+ return children[i];
+ // keep digging
+ if( children[i] instanceof IModuleFolder )
+ return findResource(allMembers, (IModuleFolder)children[i],
path.removeFirstSegments(1));
+ else
+ throw new IllegalStateException("Requested Path Not Found");
//$NON-NLS-1$
+ }
+ }
+ throw new IllegalStateException("Requested Path Not Found");
//$NON-NLS-1$
+ }
+
+ /**
+ * This routine is actually checking all the include patterns in
+ * order to avoid scanning everything under base dir.
+ *
+ * if a pattern says scan it all, though, we scan it all
+ */
+ private void runScan() {
+ Map<String, String> newroots = getNewRoots();
+ if (newroots.containsKey("") && basedir != null)
{//$NON-NLS-1$
+ // we are going to scan everything anyway
+ IModuleFolder root = basedir.segmentCount() == 0 ? null :
findBaseDirResource(basedir);
+ scandirWrap(root, "");//$NON-NLS-1$
+ } else {
+ // only scan directories that can include matched files or
+ // directories
+ Set<String> s = newroots.keySet();
+ Iterator<String> it = s.iterator();
+ String tmp;
+ while (it.hasNext()) {
+ tmp = it.next();
+ handleOneEntry(tmp, newroots.get(tmp));
+ }
+ }
+ }
+
+ protected void handleOneEntry(String includeRoot, String originalPattern) {
+ if (basedir == null && !FileUtils.isAbsolutePath(includeRoot)) {
+ return; // a relative includeroot, with no basedir
+ }
+
+ IModuleResource myfile = findResource(null, new Path(includeRoot));
+ String currentelement = includeRoot;
+
+ if (myfile != null) {
+ if (myfile instanceof IModuleFolder ) {
+ if (isIncluded(currentelement)
+ && currentelement.length() > 0) {
+ accountForIncludedDir(currentelement, (IModuleFolder)myfile);
+ } else {
+ if (currentelement.length() > 0) {
+ if (currentelement.charAt(currentelement
+ .length() - 1)
+ != File.separatorChar) {
+ currentelement =
+ currentelement + File.separatorChar;
+ }
+ }
+ scandirWrap((IModuleFolder)myfile, currentelement);
+ }
+ } else {
+ boolean included = originalPattern.equals(currentelement);
+ if (included) {
+ accountForIncludedFile(currentelement, (IModuleFile)myfile);
+ }
+ }
+ }
+ }
+
+ protected Map<String, String> getNewRoots() {
+ Map<String, String> newroots = new HashMap<String, String>();
+ // put in the newroots map the include patterns without
+ // wildcard tokens
+ for (int i = 0; i < includes.length; i++) {
+ if (FileUtils.isAbsolutePath(includes[i])) {
+ //skip abs. paths not under basedir, if set:
+ if (basedir != null
+ && !SelectorUtils.matchPatternStart(includes[i],
+ basedir.makeAbsolute().toString(), true)) {
+ continue;
+ }
+ } else if (basedir == null) {
+ //skip non-abs. paths if basedir == null:
+ continue;
+ }
+ newroots.put(SelectorUtils.rtrimWildcardTokens(
+ includes[i]), includes[i]);
+ }
+ return newroots;
+ }
+
+ /**
+ * Clear the result caches for a scan.
+ */
+ protected synchronized void clearResults() {
+ filesIncluded = new Vector<String>();
+ filesNotIncluded = new Vector<String>();
+ filesExcluded = new Vector<String>();
+ dirsIncluded = new Vector<String>();
+ dirsNotIncluded = new Vector<String>();
+ dirsNotIncludedButRequired = new Vector<String>();
+ dirsExcluded = new Vector<String>();
+ everythingIncluded = (basedir != null);
+ scannedDirs.clear();
+ }
+
+ protected void scandirWrap(IModuleFolder dir, String vpath) {
+ scandirImpl(dir,vpath);
+ }
+
+ /**
+ * Scan the given directory for files and directories. Found files and
+ * directories are placed in their respective collections, based on the
+ * matching of includes, excludes, and the selectors. When a directory
+ * is found, it is scanned recursively.
+ *
+ * @param dir The IModuleFolder to scan, or null if root
+ * @param vpath The path relative to the base directory (needed to
+ * prevent problems with an absolute path when using
+ * dir). Must not be <code>null</code>.
+ * @param fast Whether or not this call is part of a fast scan.
+ *
+ * @see #filesIncluded
+ * @see #filesNotIncluded
+ * @see #filesExcluded
+ * @see #dirsIncluded
+ * @see #dirsNotIncluded
+ * @see #dirsExcluded
+ * @see #slowScan
+ */
+ protected void scandirImpl(IModuleFolder dir, String vpath) {
+ // avoid double scanning of directories, can only happen in fast mode
+ if (hasBeenScanned(vpath)) {
+ return;
+ }
+
+ IModuleResource[] newfiles = dir == null ? resources : dir.members();
+
+ for (int i = 0; i < newfiles.length; i++) {
+ String name = vpath + newfiles[i].getName();
+ IModuleResource file = newfiles[i];
+ if (file instanceof IModuleFolder ) {
+ if (isIncluded(name)) {
+ accountForIncludedDir(name, (IModuleFolder)file);
+ } else {
+ everythingIncluded = false;
+ dirsNotIncluded.addElement(name);
+ if (couldHoldIncluded(name)) {
+ scandirWrap((IModuleFolder)file, name + File.separator);
+ }
+ }
+ } else if (file instanceof IModuleFile ) {
+ if (isIncluded(name)) {
+ accountForIncludedFile(name, (IModuleFile)file);
+ } else {
+ everythingIncluded = false;
+ filesNotIncluded.addElement(name);
+ }
+ }
+ }
+ }
+
+ protected String getName(File file) {
+ return file.getName();
+ }
+
+ /**
+ * Process included file.
+ * @param name path of the file relative to the directory of the FileSet.
+ * @param file included File.
+ */
+ private void accountForIncludedFile(String name, IModuleFile file) {
+ processIncluded(name, file, filesIncluded, filesExcluded);
+ }
+
+ /**
+ * Process included directory.
+ * @param name path of the directory relative to the directory of
+ * the FileSet.
+ * @param file directory as File.
+ * @param fast whether to perform fast scans.
+ */
+ private void accountForIncludedDir(String name, IModuleFolder file) {
+ processIncluded(name, file, dirsIncluded, dirsExcluded);
+ if (couldHoldIncluded(name) && !contentsExcluded(name)) {
+ scandirWrap(file, name + File.separator);
+ }
+ }
+
+ private void processIncluded(String name, IModuleResource file, Vector<String>
inc, Vector<String> exc) {
+
+ if (inc.contains(name) || exc.contains(name))
+ return;
+
+ boolean included = false;
+ if (isExcluded(name)) {
+ exc.add(name);
+ postExclude(file, name);
+ } else {
+ inc.add(name);
+ // Ensure that all parents which are "notIncluded" are added here
+ IPath p = new Path(name).removeLastSegments(1);
+ while(p.segmentCount() > 0 ) {
+ if( !dirsIncluded.contains(p.toString()) &&
+ !dirsNotIncludedButRequired.contains(p.toString())) {
+ dirsNotIncludedButRequired.add(p.toString());
+ }
+ p = p.removeLastSegments(1);
+ }
+ }
+ everythingIncluded &= included;
+ }
+
+ protected void postInclude(IModuleResource f, String name) {
+ }
+
+ protected void postExclude(IModuleResource f, String name) {
+ // do nothing
+ }
+ /**
+ * Test whether or not a name matches against at least one include
+ * pattern.
+ *
+ * @param name The name to match. Must not be <code>null</code>.
+ * @return <code>true</code> when the name matches against at least one
+ * include pattern, or <code>false</code> otherwise.
+ */
+ protected boolean isIncluded(String name) {
+ ensureNonPatternSetsReady();
+
+ if (includeNonPatterns.contains(name)){
+ return true;
+ }
+ for (int i = 0; i < includePatterns.length; i++) {
+ if (matchPath(includePatterns[i], name, true)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Test whether or not a name matches the start of at least one include
+ * pattern.
+ *
+ * @param name The name to match. Must not be <code>null</code>.
+ * @return <code>true</code> when the name matches against the start of
at
+ * least one include pattern, or <code>false</code> otherwise.
+ */
+ protected boolean couldHoldIncluded(String name) {
+ for (int i = 0; i < includes.length; i++) {
+ if (matchPatternStart(includes[i], name, true)
+ && isMorePowerfulThanExcludes(name, includes[i])
+ && isDeeper(includes[i], name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Verify that a pattern specifies files deeper
+ * than the level of the specified file.
+ * @param pattern the pattern to check.
+ * @param name the name to check.
+ * @return whether the pattern is deeper than the name.
+ * @since Ant 1.6.3
+ */
+ private boolean isDeeper(String pattern, String name) {
+ Vector p = SelectorUtils.tokenizePath(pattern);
+ Vector n = SelectorUtils.tokenizePath(name);
+ return p.contains("**") || p.size() > n.size();//$NON-NLS-1$
+ }
+
+ /**
+ * Find out whether one particular include pattern is more powerful
+ * than all the excludes.
+ * Note: the power comparison is based on the length of the include pattern
+ * and of the exclude patterns without the wildcards.
+ * Ideally the comparison should be done based on the depth
+ * of the match; that is to say how many file separators have been matched
+ * before the first ** or the end of the pattern.
+ *
+ * IMPORTANT : this function should return false "with care".
+ *
+ * @param name the relative path to test.
+ * @param includepattern one include pattern.
+ * @return true if there is no exclude pattern more powerful than this include
pattern.
+ * @since Ant 1.6
+ */
+ private boolean isMorePowerfulThanExcludes(String name, String includepattern) {
+ String soughtexclude = name + File.separator + "**";//$NON-NLS-1$
+ for (int counter = 0; counter < excludes.length; counter++) {
+ if (excludes[counter].equals(soughtexclude)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Test whether all contents of the specified directory must be excluded.
+ * @param name the directory name to check.
+ * @return whether all the specified directory's contents are excluded.
+ */
+ private boolean contentsExcluded(String name) {
+ name = (name.endsWith(File.separator)) ? name : name + File.separator;
+ for (int i = 0; i < excludes.length; i++) {
+ String e = excludes[i];
+ if (e.endsWith("**") &&
SelectorUtils.matchPath(//$NON-NLS-1$
+ e.substring(0, e.length() - 2), name, true)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Test whether or not a name matches against at least one exclude
+ * pattern.
+ *
+ * @param name The name to match. Must not be <code>null</code>.
+ * @return <code>true</code> when the name matches against at least one
+ * exclude pattern, or <code>false</code> otherwise.
+ */
+ protected boolean isExcluded(String name) {
+ ensureNonPatternSetsReady();
+
+ if (excludeNonPatterns.contains(name)){
+ return true;
+ }
+ for (int i = 0; i < excludePatterns.length; i++) {
+ if (matchPath(excludePatterns[i], name, true)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return the names of the files which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ * The names are relative to the base directory.
+ *
+ * @return the names of the files which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ */
+ public synchronized String[] getIncludedFiles() {
+ if (filesIncluded == null) {
+ throw new IllegalStateException("Must call scan()
first");//$NON-NLS-1$
+ }
+ String[] files = new String[filesIncluded.size()];
+ filesIncluded.copyInto(files);
+ Arrays.sort(files);
+ return files;
+ }
+
+ /**
+ * Return the count of included files.
+ * @return <code>int</code>.
+ * @since Ant 1.6.3
+ */
+ public synchronized int getIncludedFilesCount() {
+ if (filesIncluded == null) {
+ throw new IllegalStateException("Must call scan()
first");//$NON-NLS-1$
+ }
+ return filesIncluded.size();
+ }
+
+ /**
+ * Return the names of the directories which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ * The names are relative to the base directory.
+ *
+ * @return the names of the directories which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ */
+ public synchronized String[] getIncludedDirectories() {
+ if (dirsIncluded == null) {
+ throw new IllegalStateException("Must call scan()
first");//$NON-NLS-1$
+ }
+ String[] directories = new String[dirsIncluded.size()];
+ dirsIncluded.copyInto(directories);
+ Arrays.sort(directories);
+ return directories;
+ }
+
+ /**
+ * Return the count of included directories.
+ * @return <code>int</code>.
+ * @since Ant 1.6.3
+ */
+ public synchronized int getIncludedDirsCount() {
+ if (dirsIncluded == null) {
+ throw new IllegalStateException("Must call scan()
first");//$NON-NLS-1$
+ }
+ return dirsIncluded.size();
+ }
+
+ /**
+ * Has the directory with the given path relative to the base
+ * directory already been scanned?
+ *
+ * <p>Registers the given directory as scanned as a side effect.</p>
+ *
+ * @since Ant 1.6
+ */
+ private boolean hasBeenScanned(String vpath) {
+ return !scannedDirs.add(vpath);
+ }
+
+ /**
+ * This method is of interest for testing purposes. The returned
+ * Set is live and should not be modified.
+ * @return the Set of relative directory names that have been scanned.
+ */
+ /* package-private */ Set<String> getScannedDirs() {
+ return scannedDirs;
+ }
+
+ /**
+ * Clear internal caches.
+ *
+ * @since Ant 1.6
+ */
+ private synchronized void clearCaches() {
+ includeNonPatterns.clear();
+ excludeNonPatterns.clear();
+ includePatterns = null;
+ excludePatterns = null;
+ areNonPatternSetsReady = false;
+ }
+
+ /**
+ * Ensure that the in|exclude "patterns"
+ * have been properly divided up.
+ *
+ * @since Ant 1.6.3
+ */
+ private synchronized void ensureNonPatternSetsReady() {
+ if (!areNonPatternSetsReady) {
+ includePatterns = fillNonPatternSet(includeNonPatterns, includes);
+ excludePatterns = fillNonPatternSet(excludeNonPatterns, excludes);
+ areNonPatternSetsReady = true;
+ }
+ }
+
+ /**
+ * Add all patterns that are not real patterns (do not contain
+ * wildcards) to the set and returns the real patterns.
+ *
+ * @param set Set to populate.
+ * @param patterns String[] of patterns.
+ * @since Ant 1.6.3
+ */
+ private String[] fillNonPatternSet(Set<String> set, String[] patterns) {
+ ArrayList<String> al = new ArrayList<String>(patterns.length);
+ for (int i = 0; i < patterns.length; i++) {
+ if (!SelectorUtils.hasWildcards(patterns[i])) {
+ set.add(patterns[i]);
+ } else {
+ al.add(patterns[i]);
+ }
+ }
+ return set.size() == 0 ? patterns
+ : al.toArray(new String[al.size()]);
+ }
+
+ /*
+ * Public accessors
+ */
+ private String getResourcePath(IModuleResource resource) {
+ return
resource.getModuleRelativePath().append(resource.getName()).makeRelative().toString();
+ }
+ public boolean isIncludedFile(IModuleFile resource) {
+ return isIncludedFile(getResourcePath(resource));
+ }
+ public boolean isIncludedDir(IModuleFolder resource) {
+ return isIncludedDir(getResourcePath(resource));
+ }
+ public boolean isNotIncludedButRequiredMember(IModuleResource resource) {
+ return isNotIncludedButRequired(getResourcePath(resource));
+ }
+ public boolean isIncludedMember(IModuleResource resource) {
+ return isIncludedFile(getResourcePath(resource))
+ || isIncludedDir(getResourcePath(resource));
+ }
+ public boolean isRequiredMember(IModuleResource resource) {
+ return isIncludedFile(getResourcePath(resource))
+ || isIncludedDir(getResourcePath(resource))
+ || isNotIncludedButRequired(getResourcePath(resource));
+ }
+ public boolean isIncludedFile(String vpath) {
+ return filesIncluded.contains(vpath);
+ }
+ public boolean isIncludedDir(String vpath) {
+ return dirsIncluded.contains(vpath);
+ }
+ public boolean isNotIncludedButRequired(String vpath) {
+ return dirsNotIncludedButRequired.contains(vpath);
+ }
+ public boolean isIncludedMember(String vpath) {
+ return isIncludedFile(vpath) || isIncludedDir(vpath);
+ }
+ public boolean isRequiredMember(String vpath) {
+ return isIncludedFile(vpath) || isIncludedDir(vpath) ||
isNotIncludedButRequired(vpath);
+ }
+
+ private IModuleResource[] cleaned = null;
+ public IModuleResource[] getCleanedMembers() {
+ if( cleaned == null )
+ cleaned = getCleanedChildren(null);
+ return cleaned;
+ }
+
+ public IModuleResource[] getCleanedChildren(IModuleFolder parent) {
+ IModuleResource[] children = (parent == null ? resources : parent.members());
+ // Depth-first cleaning
+ ArrayList<IModuleResource> cleaned = new ArrayList<IModuleResource>();
+ IModuleResource tmp = null;
+ for( int i = 0; i < children.length; i++ ) {
+ tmp = getCleanedResource(children[i]);
+ if( tmp != null )
+ cleaned.add(tmp);
+ }
+
+ return cleaned.toArray(new IModuleResource[cleaned.size()]);
+ }
+
+ private IModuleResource getCleanedResource(IModuleResource r) {
+ if( r instanceof IModuleFile && isIncludedFile((IModuleFile)r)) {
+ return r; // No need to clone or clean since there are no setters
+ }
+ // IF the folder is included, OR, some file below it is included, this folder must
be created
+ if( r instanceof IModuleFolder && isRequiredMember(r)) {
+ // Cloning folders
+ IModuleFolder o = (IModuleFolder)r;
+ IContainer c = (IContainer)r.getAdapter(IContainer.class);
+ ModuleFolder mf = new ModuleFolder(c, o.getName(), o.getModuleRelativePath());
+ mf.setMembers(getCleanedChildren(o));
+ return mf;
+ }
+ return null;
+ }
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractBehaviourDelegate.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractBehaviourDelegate.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/AbstractBehaviourDelegate.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -14,6 +14,9 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.as.core.modules.ResourceModuleResourceUtil;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
/**
* A complete stub implementation of the interface
@@ -87,10 +90,16 @@
return null;
}
+ /**
+ * @since 2.3
+ */
+ public IModulePathFilter getPathFilter(IModule[] moduleTree) {
+ return
ResourceModuleResourceUtil.findDefaultModuleFilter(moduleTree[moduleTree.length-1]);
+ }
+
@Override
public void dispose() {
// TODO Auto-generated method stub
}
-
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DelegatingServerBehavior.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DelegatingServerBehavior.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DelegatingServerBehavior.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -24,6 +24,7 @@
import org.jboss.ide.eclipse.as.core.publishers.JSTPublisherXMLToucher;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
@@ -67,6 +68,13 @@
return null;
}
+ public IModulePathFilter getPathFilter(IModule[] moduleTree) {
+ if( getDelegate() != null ) {
+ return getDelegate().getPathFilter(moduleTree);
+ }
+ return null;
+ }
+
public void stop(boolean force) {
getDelegate().stop(force);
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -27,6 +27,7 @@
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
@@ -220,4 +221,15 @@
return true;
return false;
}
+
+ /**
+ * Some projects may request post-processing filtering on
+ * the servertools list of resources.
+ *
+ * @since 2.3
+ */
+ public IModulePathFilter getPathFilter(IModule[] moduleTree) {
+ return null;
+ }
+
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IJBossBehaviourDelegate.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IJBossBehaviourDelegate.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/IJBossBehaviourDelegate.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -14,6 +14,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
public interface IJBossBehaviourDelegate {
@@ -39,5 +41,10 @@
public String getDefaultStopArguments() throws CoreException;
+ /**
+ * @since 2.3
+ */
+ public IModulePathFilter getPathFilter(IModule[] moduleTree);
+
public void dispose();
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.xpl;
-import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -33,6 +32,7 @@
import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.publishers.AbstractServerToolsPublisher;
import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
/**
* Utility class with an assortment of useful file methods.
* <p>
@@ -132,8 +132,25 @@
* @param monitor a progress monitor, or <code>null</code> if progress
* reporting and cancellation are not desired
* @return a possibly-empty array of error and warning status
+ * @deprecated
*/
public IStatus[] publishDelta(IModuleResourceDelta[] delta, IProgressMonitor monitor)
throws CoreException {
+ return publishDelta(delta, null, monitor);
+ }
+
+ /**
+ * Handle a delta publish.
+ *
+ * @param delta a module resource delta
+ * @param path the path to publish to
+ * @param monitor a progress monitor, or <code>null</code> if progress
+ * reporting and cancellation are not desired
+ * @return a possibly-empty array of error and warning status
+ * @since 2.3
+ */
+ public IStatus[] publishDelta(IModuleResourceDelta[] delta, IModulePathFilter filter,
+ IProgressMonitor monitor) throws CoreException {
+
if (delta == null)
return EMPTY_STATUS;
@@ -142,13 +159,18 @@
List<IStatus> status = new ArrayList<IStatus>(2);
int size2 = delta.length;
for (int i = 0; i < size2; i++) {
- IStatus[] stat = publishDelta(delta[i], new Path("/"), monitor);
//$NON-NLS-1$
+ IStatus[] stat = publishDelta(delta[i], new Path("/"), filter, monitor);
//$NON-NLS-1$
addArrayToList(status, stat);
}
return status.toArray(new IStatus[status.size()]);
}
+ @Deprecated
+ public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor
monitor) throws CoreException {
+ return publishDelta(delta, path, null, monitor);
+ }
+
/**
* Handle a delta publish.
*
@@ -157,8 +179,10 @@
* @param monitor a progress monitor, or <code>null</code> if progress
* reporting and cancellation are not desired
* @return a possibly-empty array of error and warning status
+ * @since 2.3
*/
- public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor
monitor) throws CoreException {
+ public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path,
+ IModulePathFilter filter, IProgressMonitor monitor) throws CoreException {
List<IStatus> status = new ArrayList<IStatus>(2);
if( monitor.isCanceled())
return canceledStatus();
@@ -172,7 +196,7 @@
IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
handler.deleteResource(path2, monitor);
}
- else {
+ else if( filter == null || filter.shouldInclude(resource)){
IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
handler.makeDirectoryIfRequired(path2.removeLastSegments(1), monitor);
handler.copyFile(file, path2, monitor);
@@ -193,7 +217,7 @@
for (int i = 0; i < size; i++) {
if( monitor.isCanceled())
return canceledStatus();
- IStatus[] stat = publishDelta(childDeltas[i], path, monitor);
+ IStatus[] stat = publishDelta(childDeltas[i], path, filter, monitor);
addArrayToList(status, stat);
}
@@ -212,6 +236,13 @@
/**
+ * @deprecated
+ */
+ public IStatus[] initFullPublish(IModuleResource[] resources, IProgressMonitor monitor)
throws CoreException {
+ return initFullPublish(resources, null, monitor);
+ }
+
+ /**
* Publish the given module resources to the given path.
*
* @param resources an array of module resources
@@ -219,8 +250,9 @@
* @param monitor a progress monitor, or <code>null</code> if progress
* reporting and cancellation are not desired
* @return a possibly-empty array of error and warning status
+ * @since 2.3
*/
- public IStatus[] initFullPublish(IModuleResource[] resources, IProgressMonitor monitor)
throws CoreException {
+ public IStatus[] initFullPublish(IModuleResource[] resources, IModulePathFilter filter,
IProgressMonitor monitor) throws CoreException {
int count = PublishUtil.countMembers(resources);
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask("Publishing " + count + " resources",
//$NON-NLS-1$ //$NON-NLS-2$
@@ -229,12 +261,13 @@
AbstractServerToolsPublisher.getSubMon(monitor, 100));
if( monitor.isCanceled())
return canceledStatus();
- IStatus[] results = publishFull(resources, new Path("/"), monitor);
//$NON-NLS-1$
+ IStatus[] results = publishFull(resources, new Path("/"), filter, monitor);
//$NON-NLS-1$
monitor.done();
return results;
}
- protected IStatus[] publishFull(IModuleResource[] resources, IPath relative,
IProgressMonitor monitor) throws CoreException {
+ protected IStatus[] publishFull(IModuleResource[] resources, IPath relative,
+ IModulePathFilter filter, IProgressMonitor monitor) throws CoreException {
if (resources == null)
return EMPTY_STATUS;
List<IStatus> status = new ArrayList<IStatus>(2);
@@ -242,13 +275,22 @@
for (int i = 0; i < size; i++) {
if( monitor.isCanceled())
return canceledStatus();
- IStatus[] stat = copy(resources[i], relative, monitor);
- addArrayToList(status, stat);
+ if( filter == null || filter.shouldInclude(resources[i])) {
+ IStatus[] stat = copy(resources[i], relative, filter, monitor);
+ addArrayToList(status, stat);
+ }
}
return status.toArray(new IStatus[status.size()]);
}
- private IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor)
throws CoreException {
+
+ @Deprecated
+ protected IStatus[] publishFull(IModuleResource[] resources, IPath relative,
+ IProgressMonitor monitor) throws CoreException {
+ return publishFull(resources, relative, null, monitor);
+ }
+
+ private IStatus[] copy(IModuleResource resource, IPath path, IModulePathFilter filter,
IProgressMonitor monitor) throws CoreException {
String name = resource.getName();
//Trace.trace(Trace.PUBLISHING, "Copying: " + name + " to " +
path.toString());
List<IStatus> status = new ArrayList<IStatus>(2);
@@ -259,18 +301,19 @@
handler.makeDirectoryIfRequired(folder.getModuleRelativePath().append(folder.getName()),
AbstractServerToolsPublisher.getSubMon(monitor, 5));
else {
- IStatus[] stat = publishFull(children, path, monitor);
+ IStatus[] stat = publishFull(children, path, filter, monitor);
addArrayToList(status, stat);
}
} else {
IModuleFile mf = (IModuleFile) resource;
- path = path.append(mf.getModuleRelativePath()).append(name);
- IStatus[] stats = handler.makeDirectoryIfRequired(path.removeLastSegments(1), new
NullProgressMonitor());
- if( stats != null && stats.length > 0 && !stats[0].isOK())
- addArrayToList(status, stats);
-
- addArrayToList(status, handler.copyFile(mf, path,
- AbstractServerToolsPublisher.getSubMon(monitor, 100)));
+ if( filter == null || filter.shouldInclude(resource)) {
+ path = path.append(mf.getModuleRelativePath()).append(name);
+ IStatus[] stats = handler.makeDirectoryIfRequired(path.removeLastSegments(1), new
NullProgressMonitor());
+ if( stats != null && stats.length > 0 && !stats[0].isOK())
+ addArrayToList(status, stats);
+ addArrayToList(status, handler.copyFile(mf, path,
+ AbstractServerToolsPublisher.getSubMon(monitor, 100)));
+ }
}
return status.toArray(new IStatus[status.size()]);
}
Modified: trunk/as/tests/org.jboss.ide.eclipse.as.test/plugin.xml
===================================================================
--- trunk/as/tests/org.jboss.ide.eclipse.as.test/plugin.xml 2012-01-20 11:15:57 UTC (rev
37998)
+++ trunk/as/tests/org.jboss.ide.eclipse.as.test/plugin.xml 2012-01-20 11:26:11 UTC (rev
37999)
@@ -26,6 +26,17 @@
<extension
point="org.jboss.ide.eclipse.as.core.behaviourExtension">
<behaviour
+
behaviourDelegate="org.jboss.ide.eclipse.as.test.publishing.v2.Mock2BehaviourDelegate"
+
launchDelegate="org.jboss.ide.eclipse.as.core.server.internal.launch.LocalJBossStartLaunchDelegate"
+ name="mock2"
+
publishMethod="org.jboss.ide.eclipse.as.test.publishing.v2.MockPublishMethod"
+ serverTypes="%ServerTypesJBoss6OrLower"
+ typeId="mock2">
+ </behaviour>
+ </extension>
+ <extension
+ point="org.jboss.ide.eclipse.as.core.behaviourExtension">
+ <behaviour
behaviourDelegate="org.jboss.ide.eclipse.as.core.server.internal.v7.LocalJBoss7BehaviorDelegate"
launchDelegate="org.jboss.ide.eclipse.as.core.server.internal.v7.LocalJBoss7StartLaunchDelegate"
name="mock"
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -36,8 +36,11 @@
import org.jboss.ide.eclipse.as.test.publishing.v2.JSTDeployBinaryChildModuleTest;
import org.jboss.ide.eclipse.as.test.publishing.v2.JSTDeploymentTester;
import org.jboss.ide.eclipse.as.test.publishing.v2.JSTDeploymentWarUpdateXML;
+import org.jboss.ide.eclipse.as.test.publishing.v2.Mock2FilterTest;
import org.jboss.ide.eclipse.as.test.publishing.v2.MockJSTPublisherTest;
import org.jboss.ide.eclipse.as.test.publishing.v2.MockJSTPublisherTestDynUtil;
+import org.jboss.ide.eclipse.as.test.publishing.v2.PublishFilterDirectoryScannerTest;
+import org.jboss.ide.eclipse.as.test.publishing.v2.PublishingFilterTest;
import
org.jboss.ide.eclipse.as.test.publishing.v2.SingleFileDeployableMockDeploymentTester;
import org.jboss.ide.eclipse.as.test.publishing.v2.SingleFileDeploymentTester;
import org.jboss.ide.eclipse.as.test.server.JBossServerAPITest;
@@ -60,6 +63,8 @@
suite.addTestSuite(ProjectRuntimeTest.class);
suite.addTestSuite(JSTDeploymentWarUpdateXML.class);
suite.addTestSuite(SingleFileDeployableMockDeploymentTester.class);
+
+ // Publishing tests
suite.addTestSuite(MockJSTPublisherTest.class);
suite.addTestSuite(MockJSTPublisherTestDynUtil.class);
suite.addTestSuite(JBIDE1657Test.class);
@@ -71,6 +76,10 @@
suite.addTestSuite(JSTDeployBinaryChildModuleTest.class);
suite.addTestSuite(SingleFileDeploymentTester.class);
suite.addTestSuite(JBossServerAPITest.class);
+ suite.addTestSuite(Mock2FilterTest.class);
+ suite.addTestSuite(PublishFilterDirectoryScannerTest.class);
+ suite.addTestSuite(PublishingFilterTest.class);
+
return suite;
}
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2BehaviourDelegate.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2BehaviourDelegate.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2BehaviourDelegate.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,30 @@
+package org.jboss.ide.eclipse.as.test.publishing.v2;
+
+import org.eclipse.wst.server.core.IModule;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
+import org.jboss.ide.eclipse.as.core.server.internal.LocalJBossBehaviorDelegate;
+
+public class Mock2BehaviourDelegate extends LocalJBossBehaviorDelegate {
+ private IModulePathFilter filter;
+ private boolean useUpstreamBehaviour = false;
+ public void setUseSuperclassBehaviour(boolean val) {
+ useUpstreamBehaviour = val;
+ }
+ public IModulePathFilter getPathFilter(IModule[] moduleTree) {
+ if( useUpstreamBehaviour )
+ return super.getPathFilter(moduleTree);
+ return getFilter();
+ }
+
+ public IModulePathFilter getFilter() {
+ return filter;
+ }
+ public void setFilter(IModulePathFilter filter) {
+ this.filter = filter;
+ }
+
+ public String getBehaviourTypeId() {
+ return "mock2";
+ }
+
+}
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2FilterTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2FilterTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/Mock2FilterTest.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,144 @@
+package org.jboss.ide.eclipse.as.test.publishing.v2;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.internal.ServerPreferences;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
+import org.jboss.ide.eclipse.as.core.server.internal.DelegatingServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.test.util.IOUtil;
+import org.jboss.ide.eclipse.as.test.util.ServerRuntimeUtils;
+
+/**
+ * Tests the concept of a behaviour having a filter...
+ * in this case, customized by the test case.
+ *
+ * @author rob
+ *
+ */
+public class Mock2FilterTest extends AbstractJSTDeploymentTester {
+ public void testNormalLogic() throws CoreException, IOException, Exception {
+ server =
ServerRuntimeUtils.createMockServerWithRuntime(IJBossToolingConstants.SERVER_AS_60,
+ "name1", "default");
+ server = ServerRuntimeUtils.useMock2PublishMethod(server);
+ project = createProject();
+ MockPublishMethod.reset();
+
+ ServerPreferences.getInstance().setAutoPublishing(false);
+ IModule mod = ServerUtil.getModule(project);
+ server = ServerRuntimeUtils.addModule(server, mod);
+
+ DelegatingServerBehavior beh =
(DelegatingServerBehavior)server.loadAdapter(DelegatingServerBehavior.class, null);
+ Mock2BehaviourDelegate del = (Mock2BehaviourDelegate)beh.getDelegate();
+ del.setFilter(getSuffixFilter(null));
+
+ ServerRuntimeUtils.publish(server);
+ assertEquals(2, MockPublishMethod.getChanged().length);
+ MockPublishMethod.reset();
+
+ // Two already in the project
+ // Note: One is application.xml which is touched by our module-restart crap on full
publish
+ ServerRuntimeUtils.publishFull(server);
+ assertEquals(2, MockPublishMethod.getChanged().length);
+ MockPublishMethod.reset();
+
+ IFile textFile = project.getFile(getContentTextFilePath());
+ IOUtil.setContents(textFile, 0);
+ assertEquals(0, MockPublishMethod.getChanged().length);
+ ServerRuntimeUtils.publishFull(server);
+ assertEquals(3, MockPublishMethod.getChanged().length);
+ MockPublishMethod.reset();
+
+ del.setFilter(getSuffixFilter("txt"));
+ ServerRuntimeUtils.publishFull(server);
+ IPath[] changed;
+ changed = MockPublishMethod.getChanged();
+ assertEquals(2, changed.length);
+ MockPublishMethod.reset();
+
+ textFile = project.getFile(new Path(getContentDir()).append("other.txt"));
+ IOUtil.setContents(textFile, 1);
+ assertEquals(0, MockPublishMethod.getChanged().length);
+ del.setFilter(getSuffixFilter(null));
+ ServerRuntimeUtils.publishFull(server);
+ assertEquals(4, MockPublishMethod.getChanged().length);
+ MockPublishMethod.reset();
+
+
+ del.setFilter(getSuffixFilter("txt"));
+ ServerRuntimeUtils.publishFull(server);
+ changed = MockPublishMethod.getChanged();
+ assertEquals(2, changed.length);
+ MockPublishMethod.reset();
+ }
+
+ protected IModulePathFilter getSuffixFilter(String suffix) {
+ return new SuffixFilter(suffix);
+ }
+
+ protected class SuffixFilter implements IModulePathFilter {
+ private String suffix; // filter OUT this suffix
+ public SuffixFilter(String suffix) {
+ this.suffix = suffix;
+ }
+ public boolean shouldInclude(IModuleResource moduleResource) {
+ if( suffix == null )
+ return true;
+ return !moduleResource.getName().endsWith(suffix);
+ }
+ // TODO
+ public IModuleResource[] getFilteredMembers() throws CoreException {
+ return null;
+ }
+ }
+
+ protected void assertRemoved(boolean isAs7, String[] nonAs7, String[] as7) {
+ assertExpectedArtifacts(isAs7, nonAs7, as7, MockPublishMethod.getRemoved());
+ }
+
+ protected void assertChanged(boolean isAs7, String[] nonAs7, String[] as7) {
+ assertExpectedArtifacts(isAs7, nonAs7, as7, MockPublishMethod.getChanged());
+ }
+
+ protected void assertExpectedArtifacts(boolean isAs7, String[] nonAs7, String[] as7,
IPath[] artifacts) {
+ if (isAs7) {
+ assertEquals(as7.length, artifacts.length);
+ } else {
+ assertEquals(nonAs7.length, artifacts.length);
+ }
+
+ if (isAs7) {
+ for (String expectedPath : as7) {
+ if (contains(MockPublishMethod.MOCK_ROOT + "/" + expectedPath, artifacts))
{
+ continue;
+ }
+ fail(expectedPath + " was not among the changed/removed artifacts");
+ }
+ } else {
+ for (String expectedPath : nonAs7) {
+ if (contains(MockPublishMethod.MOCK_ROOT + "/" + expectedPath, artifacts))
{
+ continue;
+ }
+ fail(expectedPath + " was not among the changed/removed artifacts");
+ }
+ }
+ }
+
+ protected boolean contains(String expectedPath, IPath[] paths) {
+ for (IPath path : paths) {
+ if (expectedPath.equals(path.toString())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+}
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishFilterDirectoryScannerTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishFilterDirectoryScannerTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishFilterDirectoryScannerTest.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,220 @@
+package org.jboss.ide.eclipse.as.test.publishing.v2;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.model.IModuleFolder;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.util.ModuleFile;
+import org.eclipse.wst.server.core.util.ModuleFolder;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.PublishFilterDirectoryScanner;
+import org.jboss.ide.eclipse.as.test.publishing.AbstractDeploymentTest;
+
+public class PublishFilterDirectoryScannerTest extends TestCase {
+ private IModuleResource[] members;
+
+ /*
+ logout.html
+ index.html
+ login.html
+ resources/
+ resources/js/
+ resources/js/script.js
+ resources/css/
+ resources/css/two.css
+ resources/css/one.css
+ META-INF/
+ META-INF/MANIFEST.MF
+ META-INF/maven/
+ META-INF/maven/foo.bar/
+ META-INF/maven/foo.bar/webapp/
+ META-INF/maven/foo.bar/webapp/pom.xml
+ META-INF/maven/foo.bar/webapp/pom.properties
+ WEB-INF/
+ WEB-INF/web.xml
+ WEB-INF/classes/
+ WEB-INF/classes/foo/
+ WEB-INF/classes/foo/custom/
+ WEB-INF/classes/foo/custom/some.properties
+ WEB-INF/classes/foo/bar/
+ WEB-INF/classes/foo/bar/Dummy.class
+ WEB-INF/pages/
+ WEB-INF/pages/navbar.html
+ WEB-INF/pages/common.html
+ */
+ protected void setUp() throws Exception {
+ // Dummy file... just need one to make IModuleFile objects...
+ File srcFile =
AbstractDeploymentTest.getFileLocation("projectPieces/EJB3NoDescriptor.jar");
+
+ // Create a fake module tree
+ ArrayList<IModuleResource> resources = new ArrayList<IModuleResource>();
+ // Add some root files
+ resources.add(new ModuleFile(srcFile, "logout.html", new
Path("/")));
+ resources.add(new ModuleFile(srcFile, "login.html", new
Path("/")));
+ resources.add(new ModuleFile(srcFile, "index.html", new
Path("/")));
+
+
+ ModuleFolder resourcesF = new ModuleFolder(null, "resources", new
Path("/"));
+ ModuleFolder resourcesJS = new ModuleFolder(null, "js", new
Path("resources"));
+ ModuleFile jsScript = new ModuleFile(srcFile, "script.js", new
Path("resources/js"));
+ ModuleFolder resourcesCSS = new ModuleFolder(null, "css", new
Path("resources"));
+ ModuleFile onecss = new ModuleFile(srcFile, "one.css", new
Path("resources/css"));
+ ModuleFile twocss = new ModuleFile(srcFile, "two.css", new
Path("resources/css"));
+
+ resourcesCSS.setMembers(new IModuleResource[]{onecss, twocss});
+ resourcesJS.setMembers(new IModuleResource[]{jsScript});
+ resourcesF.setMembers(new IModuleResource[]{resourcesCSS, resourcesJS});
+
+
+ ModuleFolder metainf = new ModuleFolder(null, "META-INF", new
Path("/"));
+ ModuleFile manifest = new ModuleFile(srcFile, "MANIFEST.MF", new
Path("META-INF"));
+ ModuleFolder metainfMaven = new ModuleFolder(null, "maven", new
Path("META-INF"));
+ metainf.setMembers(new IModuleResource[]{manifest, metainfMaven});
+// META-INF/maven/foo.bar/
+// META-INF/maven/foo.bar/webapp/
+// META-INF/maven/foo.bar/webapp/pom.xml
+// META-INF/maven/foo.bar/webapp/pom.properties
+ ModuleFolder fooBar = new ModuleFolder(null, "foo.bar", new
Path("META-INF/maven"));
+ metainfMaven.setMembers(new IModuleResource[]{fooBar});
+ ModuleFolder webapp = new ModuleFolder(null, "webapp", new
Path("META-INF/maven/foo.bar"));
+ fooBar.setMembers(new IModuleResource[]{webapp});
+ ModuleFile pom = new ModuleFile(srcFile, "pom.xml", new
Path("META-INF/maven/foo.bar/webapp"));
+ ModuleFile pomProp = new ModuleFile(srcFile, "pom.properties", new
Path("META-INF/maven/foo.bar/webapp"));
+ webapp.setMembers(new IModuleResource[]{pom, pomProp});
+
+// WEB-INF/
+// WEB-INF/web.xml
+// WEB-INF/classes/
+// WEB-INF/pages/
+ ModuleFolder webinf = new ModuleFolder(null, "WEB-INF", new
Path("/"));
+ ModuleFile webxml = new ModuleFile(srcFile, "web.xml", new
Path("WEB-INF"));
+ ModuleFolder webinfClasses = new ModuleFolder(null, "classes", new
Path("WEB-INF"));
+ ModuleFolder webinfPages = new ModuleFolder(null, "pages", new
Path("WEB-INF"));
+ webinf.setMembers(new IModuleResource[]{webxml, webinfClasses, webinfPages});
+
+// WEB-INF/classes/foo/
+// WEB-INF/classes/foo/custom/
+// WEB-INF/classes/foo/custom/some.properties
+// WEB-INF/classes/foo/bar/
+// WEB-INF/classes/foo/bar/Dummy.class
+ ModuleFolder classesFoo = new ModuleFolder(null, "foo", new
Path("WEB-INF/classes"));
+ webinfClasses.setMembers(new IModuleResource[]{classesFoo});
+
+ ModuleFolder fooCustom = new ModuleFolder(null, "custom", new
Path("WEB-INF/classes/foo"));
+ ModuleFile customProps = new ModuleFile(srcFile, "some.properties", new
Path("WEB-INF/classes/foo/custom"));
+ fooCustom.setMembers(new IModuleResource[]{customProps});
+ ModuleFolder fooBar2 = new ModuleFolder(null, "bar", new
Path("WEB-INF/classes/foo"));
+ classesFoo.setMembers(new IModuleResource[]{fooCustom, fooBar2});
+ ModuleFile dummyClass = new ModuleFile(srcFile, "Dummy.class", new
Path("WEB-INF/classes/foo/bar"));
+ fooBar2.setMembers(new IModuleResource[]{dummyClass});
+
+// WEB-INF/pages/navbar.html
+// WEB-INF/pages/common.html
+ ModuleFile navbar = new ModuleFile(srcFile, "navbar.html", new
Path("WEB-INF/pages"));
+ ModuleFile commonhtml = new ModuleFile(srcFile, "common.html", new
Path("WEB-INF/pages"));
+ webinfPages.setMembers(new IModuleResource[]{navbar, commonhtml});
+
+ resources.add(resourcesF);
+ resources.add(webinf);
+ resources.add(metainf);
+ members = (IModuleResource[]) resources.toArray(new
IModuleResource[resources.size()]);
+ }
+
+ public void testBasicNoFail() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.scan();
+ }
+
+ public void testUtilCount() {
+ assertEquals(27, countAllResources(members));
+ }
+
+ public void testIncludesSpecificFolder() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes(new String[]{"WEB-INF/pages/**"});
+ scanner.setExcludes(new String[]{""});
+ scanner.scan();
+
+ assertTrue(scanner.isRequiredMember("WEB-INF"));
+ assertTrue(scanner.isNotIncludedButRequired("WEB-INF"));
+ assertTrue(scanner.isRequiredMember("WEB-INF/pages"));
+ assertTrue(scanner.isIncludedMember("WEB-INF/pages"));
+ assertTrue(scanner.isIncludedMember("WEB-INF/pages/navbar.html"));
+ assertFalse(scanner.isIncludedFile("resources/css/two.css"));
+ assertFalse(scanner.isRequiredMember("resources"));
+
+ IModuleResource[] cleaned = scanner.getCleanedMembers();
+ assertEquals(27, countAllResources(members));
+ int postTotal = countAllResources(cleaned);
+ assertEquals(4, postTotal);
+ }
+
+ public void testExcludesDeepFolder() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes(new String[]{"**/*"});
+ scanner.setExcludes(new String[]{"WEB-INF/pages/**"});
+ scanner.scan();
+
+ assertTrue(scanner.isRequiredMember("resources"));
+ assertTrue(scanner.isIncludedFile("resources/css/two.css"));
+ assertTrue(scanner.isRequiredMember("WEB-INF"));
+ assertFalse(scanner.isRequiredMember("WEB-INF/pages"));
+ assertFalse(scanner.isIncludedMember("WEB-INF/pages/navbar.html"));
+ assertFalse(scanner.isRequiredMember("WEB-INF/pages/navbar.html"));
+ assertEquals(24, countAllResources(scanner.getCleanedMembers()));
+ }
+
+ public void testExcludesTrailingSlash() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes(new String[]{"**/*"});
+ scanner.setExcludes(new String[]{"WEB-INF/pages"});
+ scanner.scan();
+ assertEquals(27, countAllResources(scanner.getCleanedMembers()));
+ }
+ public void testExcludesTrailingSlash2() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes(new String[]{"**/*"});
+ scanner.setExcludes(new String[]{"WEB-INF/pages/"});
+ scanner.scan();
+ assertEquals(24, countAllResources(scanner.getCleanedMembers()));
+ }
+
+ public void testCommaSeparatedExcludes() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes(new String[]{"**/*"});
+ scanner.setExcludes(new String[]{
"WEB-INF/pages/","WEB-INF/classes/foo/bar/"});
+ scanner.scan();
+ assertEquals(22, countAllResources(scanner.getCleanedMembers()));
+ }
+
+ public void testCommaSeparatedExcludesAutoSplit() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes(new String[]{"**/*"});
+ scanner.setExcludes("WEB-INF/pages/,WEB-INF/classes/foo/bar/");
+ scanner.scan();
+ assertEquals(22, countAllResources(scanner.getCleanedMembers()));
+ }
+ public void testExcludesMorePowerful() {
+ PublishFilterDirectoryScanner scanner = new PublishFilterDirectoryScanner(members);
+ scanner.setIncludes("**/*,WEB-INF/classes/foo/bar/");
+ scanner.setExcludes("WEB-INF/classes/foo/");
+ scanner.scan();
+ assertEquals(22, countAllResources(scanner.getCleanedMembers()));
+ }
+
+ // deep count
+ public static int countAllResources(IModuleResource[] members) {
+ int total = 0;
+ for( int i = 0; i < members.length; i++ ) {
+ total++;
+ if( members[i] instanceof IModuleFolder ) {
+ total += countAllResources(((IModuleFolder)members[i]).members());
+ }
+ }
+ return total;
+ }
+
+}
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/publishing/v2/PublishingFilterTest.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -0,0 +1,141 @@
+package org.jboss.ide.eclipse.as.test.publishing.v2;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.internal.ServerPreferences;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.ModuleDelegate;
+import org.jboss.ide.eclipse.as.core.modules.ResourceModuleResourceUtil;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.IModulePathFilter;
+import org.jboss.ide.eclipse.as.core.publishers.patterns.PublishFilterDirectoryScanner;
+import org.jboss.ide.eclipse.as.core.server.internal.DelegatingServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.test.ASTest;
+import org.jboss.ide.eclipse.as.test.util.IOUtil;
+import org.jboss.ide.eclipse.as.test.util.ServerRuntimeUtils;
+import org.jboss.ide.eclipse.as.test.util.wtp.JavaEEFacetConstants;
+import org.jboss.ide.eclipse.as.test.util.wtp.OperationTestCase;
+import org.jboss.ide.eclipse.as.test.util.wtp.ProjectCreationUtil;
+import org.jboss.ide.eclipse.as.test.util.wtp.ProjectUtility;
+
+/**
+ * Test the integration between components, filters, and servers
+ */
+public class PublishingFilterTest extends TestCase {
+ public void tearDown() throws Exception {
+ ServerRuntimeUtils.deleteAllServers();
+ ServerRuntimeUtils.deleteAllRuntimes();
+ ProjectUtility.deleteAllProjects();
+ ASTest.clearStateLocation();
+ }
+
+ public void testPublishingFilter() throws Exception {
+ publishingFilterTest(createProject("module1"), "**/*",
"**/DONTincludeme.txt", 1);
+ }
+ public void testPublishingFilter2() throws Exception {
+ publishingFilterTest(createProject("module1"), "**/*",
"**/*.txt", 2);
+ }
+ public void testPublishingFilterChange() throws Exception {
+ // Make sure changes to an existing project also work
+ IProject p = createProject("module1");
+ publishingFilterTest(p, "**/*", "**/*.txt", 2);
+ publishingFilterTest(p, "**/*", "**/DON*.txt", 1);
+ }
+
+ private IProject createProject(String name) throws Exception {
+ IDataModel dm = ProjectCreationUtil.getWebDataModel("module1", null, null,
+ "myContent", null, JavaEEFacetConstants.WEB_25, false);
+ OperationTestCase.runAndVerify(dm);
+ IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ IFile f = p.getFile(new Path("myContent/includeme.txt"));
+ IOUtil.setContents(f, "includeMe");
+ IFile f2 = p.getFile(new Path("myContent/DONTincludeme.txt"));
+ IOUtil.setContents(f2, "leave me out");
+ return p;
+ }
+ private void publishingFilterTest(IProject p, String inc, String exc, int difference)
throws Exception {
+ IVirtualComponent vc = ComponentCore.createComponent(p);
+ vc.setMetaProperty("component.inclusion.patterns", inc);
+ vc.setMetaProperty("component.exclusion.patterns", exc);
+
+ IModule module = ServerUtil.getModule(p);
+ IModulePathFilter filter = ResourceModuleResourceUtil.findDefaultModuleFilter(module);
+ assertNotNull(filter);
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, null);
+ IModuleResource[] originalMembers = md.members();
+ IModuleResource[] filteredMembers = filter.getFilteredMembers();
+
+ int oCount = PublishFilterDirectoryScannerTest.countAllResources(originalMembers);
+ int fCount = PublishFilterDirectoryScannerTest.countAllResources(filteredMembers);
+
+ assertEquals(oCount, fCount + difference);
+ }
+
+ public void testServerIntegration() throws CoreException, IOException, Exception {
+ IServer server =
ServerRuntimeUtils.createMockServerWithRuntime(IJBossToolingConstants.SERVER_AS_60,
+ "name1", "default");
+ server = ServerRuntimeUtils.useMock2PublishMethod(server);
+ IProject project = createProject("module1");
+ MockPublishMethod.reset();
+
+ ServerPreferences.getInstance().setAutoPublishing(false);
+ IModule mod = ServerUtil.getModule(project);
+ server = ServerRuntimeUtils.addModule(server, mod);
+ ModuleDelegate md = (ModuleDelegate)mod.loadAdapter(ModuleDelegate.class, null);
+
+ DelegatingServerBehavior beh =
(DelegatingServerBehavior)server.loadAdapter(DelegatingServerBehavior.class, null);
+ Mock2BehaviourDelegate del = (Mock2BehaviourDelegate)beh.getDelegate();
+ del.setUseSuperclassBehaviour(true);
+ IModulePathFilter filter = del.getPathFilter(new IModule[]{mod});
+ IModuleResource[] originalMembers = md.members();
+ IModuleResource[] filteredMembers = filter.getFilteredMembers();
+ int oCount = PublishFilterDirectoryScannerTest.countAllResources(originalMembers);
+ int fCount = PublishFilterDirectoryScannerTest.countAllResources(filteredMembers);
+ assertEquals(oCount, fCount);
+
+ IVirtualComponent vc = ComponentCore.createComponent(mod.getProject());
+
+ vc.setMetaProperty("component.inclusion.patterns", "**/*");
+ vc.setMetaProperty("component.exclusion.patterns", "**/*.txt");
+
+ filter = del.getPathFilter(new IModule[]{mod});
+ originalMembers = md.members();
+ filteredMembers = filter.getFilteredMembers();
+ oCount = PublishFilterDirectoryScannerTest.countAllResources(originalMembers);
+ fCount = PublishFilterDirectoryScannerTest.countAllResources(filteredMembers);
+ assertEquals(oCount, fCount+2);
+
+ vc.setMetaProperty("component.inclusion.patterns", "**/*");
+ vc.setMetaProperty("component.exclusion.patterns", "**/DON*");
+
+ filter = del.getPathFilter(new IModule[]{mod});
+ originalMembers = md.members();
+ filteredMembers = filter.getFilteredMembers();
+ oCount = PublishFilterDirectoryScannerTest.countAllResources(originalMembers);
+ fCount = PublishFilterDirectoryScannerTest.countAllResources(filteredMembers);
+ assertEquals(oCount, fCount+1);
+
+
+ IModuleResource r = PublishFilterDirectoryScanner.findResource(originalMembers, null,
+ new Path("DONTincludeme.txt"));
+ assertNotNull(r);
+ assertFalse(filter.shouldInclude(r));
+ r = PublishFilterDirectoryScanner.findResource(originalMembers, null,
+ new Path("includeme.txt"));
+ assertNotNull(r);
+ assertTrue(filter.shouldInclude(r));
+ }
+}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java 2012-01-20
11:15:57 UTC (rev 37998)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ServerRuntimeUtils.java 2012-01-20
11:26:11 UTC (rev 37999)
@@ -142,7 +142,13 @@
wc.setAttribute(IDeployableServer.SERVER_MODE, "mock");
return wc.save(true, new NullProgressMonitor());
}
-
+
+ public static IServer useMock2PublishMethod(IServer server) throws CoreException {
+ IServerWorkingCopy wc = server.createWorkingCopy();
+ wc.setAttribute(IDeployableServer.SERVER_MODE, "mock2");
+ return wc.save(true, new NullProgressMonitor());
+ }
+
public static IServer createMockDeployOnlyServer(String deployLocation, String
tempDeployLocation) throws CoreException {
return createMockDeployOnlyServer(deployLocation, tempDeployLocation,
"testRuntime", "testServer");
}
@@ -312,11 +318,15 @@
public static IStatus publish(IServer server) throws CoreException {
return publish(IServer.PUBLISH_INCREMENTAL, server);
}
-
+
+ public static IStatus publishFull(IServer server) throws CoreException {
+ return publish(IServer.PUBLISH_FULL, server);
+ }
+
public static IStatus publish(int type, IServer server) throws CoreException {
return server.publish(type, new NullProgressMonitor());
}
-
+
public static IServer setZipped(IServer server, boolean val) {
return ServerRuntimeUtils.setServerAttribute(server,
IDeployableServer.ZIP_DEPLOYMENTS_PREF, val);
}