
de.smartics.maven.plugin.jboss.modules.descriptor.ModuleMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smartics-jboss-modules-maven-plugin Show documentation
Show all versions of smartics-jboss-modules-maven-plugin Show documentation
Generates an archive of modules based on information in a POM to be copied
to an JBoss 7 installation.
The newest version!
/*
* Copyright 2013-2018 smartics, Kronseder & Reiner GmbH
*
* Licensed 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.
*/
package de.smartics.maven.plugin.jboss.modules.descriptor;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.builder.ToStringBuilder;
import de.smartics.maven.plugin.jboss.modules.util.Arg;
import org.apache.commons.lang.builder.ToStringStyle;
/**
* Descriptor to define the rules for matching modules to be matched to have
* additional information applied.
*/
public final class ModuleMatcher
{
// ********************************* Fields *********************************
// --- constants ------------------------------------------------------------
// --- members --------------------------------------------------------------
/**
* The list of inclusions.
*/
private final List includes;
/**
* The list of exclusions.
*/
private final List excludes;
// ****************************** Initializer *******************************
// ****************************** Constructors ******************************
private ModuleMatcher(final Builder builder)
{
includes = builder.includes;
excludes = builder.excludes;
}
// ****************************** Inner Classes *****************************
/**
* Builds instances of {@link ModuleMatcher}.
*/
public static final class Builder
{
// ******************************** Fields ********************************
// --- constants ----------------------------------------------------------
// --- members ------------------------------------------------------------
/**
* The list of inclusions.
*/
private final List includes = new ArrayList();
/**
* The list of exclusions.
*/
private final List excludes = new ArrayList();
// ***************************** Initializer ******************************
// ***************************** Constructors *****************************
// ***************************** Inner Classes ****************************
// ******************************** Methods *******************************
// --- init ---------------------------------------------------------------
// --- get&set ------------------------------------------------------------
// --- business -----------------------------------------------------------
/**
* Adds an include to the list of includes.
*
* @param include the include to add.
* @throws NullPointerException if {@code include} is null
.
*/
public void addInclude(final ModuleClusion include)
throws NullPointerException
{
includes.add(Arg.checkNotNull("include", include));
}
/**
* Adds an exclude to the list of excludes.
*
* @param exclude the exclude to add.
* @throws NullPointerException if {@code exclude} is null
.
*/
public void addExclude(final ModuleClusion exclude)
throws NullPointerException
{
excludes.add(Arg.checkNotNull("exclude", exclude));
}
/**
* Builds an instance of {@link ModuleMatcher}.
*
* @return the instance.
*/
public ModuleMatcher build()
{
return new ModuleMatcher(this);
}
// --- object basics ------------------------------------------------------
}
// ********************************* Methods ********************************
// --- init -----------------------------------------------------------------
// --- get&set --------------------------------------------------------------
/**
* Returns the list of inclusions.
*
* @return the list of inclusions.
*/
public List getIncludes()
{
return includes;
}
/**
* Returns the list of exclusions.
*
* @return the list of exclusions.
*/
public List getExcludes()
{
return excludes;
}
// --- business -------------------------------------------------------------
/**
* Checks if the matcher matches with the given module name.
*
* @param name the module name to match.
* @return true
on a match, false
otherwise.
*/
public boolean matches(final String name)
{
final boolean included = matches(includes, name, true);
if (included)
{
final boolean excluded = matches(excludes, name, false);
return !excluded;
}
return included;
}
private boolean matches(final List cludes, final String name,
final boolean defaultValue)
{
if (cludes.isEmpty())
{
return defaultValue;
}
for (final ModuleClusion clusion : cludes)
{
if (clusion.match(name))
{
return true;
}
}
return false;
}
// --- object basics --------------------------------------------------------
/**
* {@inheritDoc}
*
* Provides the properties via reflection for displaying debug information.
*
*/
@Override
public String toString()
{
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE, false, null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy