本文整理汇总了Java中org.apache.maven.enforcer.rule.api.EnforcerRuleHelper类的典型用法代码示例。如果您正苦于以下问题:Java EnforcerRuleHelper类的具体用法?Java EnforcerRuleHelper怎么用?Java EnforcerRuleHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EnforcerRuleHelper类属于org.apache.maven.enforcer.rule.api包,在下文中一共展示了EnforcerRuleHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFiles
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
private void testFiles(
boolean expected,
int expectedFaultyFilesAmount,
@Nonnull String encoding,
@Nonnull String dir,
@Nonnull String includeRegex,
@Nonnull String excludeRegex
) {
boolean isValid;
CharacterSetEncodingRule rule = new CharacterSetEncodingRule();
rule.setRequireEncoding(encoding);
rule.setDirectory(dir);
rule.setIncludeRegex(includeRegex);
rule.setExcludeRegex(excludeRegex);
try {
EnforcerRuleHelper helper = EnforcerTestUtils.getHelper();
rule.execute(helper);
isValid = true;
} catch (EnforcerRuleException e) {
// e.printStackTrace();
isValid = false;
}
assertTrue(isValid == expected && rule.getFaultyFiles().size() == expectedFaultyFilesAmount);
}
示例2: detectUnmanagedModules
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
private void detectUnmanagedModules(EnforcerRuleHelper helper, MavenProject project) throws ExpressionEvaluationException, EnforcerRuleException {
Log log = helper.getLog();
MavenSession session = RuleHelper.getSession(helper);
List<MavenProject> projects = session.getProjects();
ImmutableListMultimap managedDependencies = RuleHelper.getManagedDependenciesAsMap(project);
for (MavenProject mavenProject : projects) {
if (ruleIsDefinedInProjectOrNotModuleParent(mavenProject, log)) {
continue;
}
String projectIdentifier = RuleHelper.getProjectIdentifier(mavenProject);
if (!managedDependencies.containsKey(projectIdentifier)) {
logHeader(log, "manage all modules");
log.warn("unmanaged project found: " + projectIdentifier);
failureDetected = true;
}
}
if (failureDetected) {
throw new EnforcerRuleException("Failing because of unmanaged projects");
}
}
示例3: checkAgainstParentValue
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
/**
* Checks the value of the project against the one given in the defining ancestor project.
*
* @param project
* @param parent
* @param helper
* @param propValue
* @throws EnforcerRuleException
*/
void checkAgainstParentValue( final MavenProject project, final MavenProject parent, EnforcerRuleHelper helper,
Object propValue ) throws EnforcerRuleException
{
final StringBuilder parentHierarchy = new StringBuilder( "project." );
MavenProject needle = project;
while ( !needle.equals( parent ) )
{
parentHierarchy.append( "parent." );
needle = needle.getParent();
}
final String propertyNameInParent = property.replace( "project.", parentHierarchy.toString() );
Object parentValue = getPropertyValue( helper, propertyNameInParent );
if ( propValue.equals( parentValue ) )
{
final String errorMessage = createResultingErrorMessage( String.format(
"Property '%s' evaluates to '%s'. This does match '%s' from parent %s",
property, propValue, parentValue, parent ) );
throw new EnforcerRuleException( errorMessage );
}
}
示例4: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
Log log = helper.getLog();
List<Pattern> excludedPatterns = new ArrayList<Pattern>(excludes.size());
for (String exclude : excludes) {
excludedPatterns.add(Pattern.compile(exclude));
}
try {
MavenProject project = (MavenProject) helper.evaluate("${project}");
List<Artifact> artifactList = project.getAttachedArtifacts();
for (Artifact artifact : artifactList) {
String artifactFileName = artifact.getFile().getName();
log.debug("evaluating artifact [" + artifactFileName + "]");
for (Pattern pattern : excludedPatterns) {
if (pattern.matcher(artifactFileName).matches()) {
throw new EnforcerRuleException("found banned attached artifact: artifact [" + artifactFileName + "] matched exclude pattern [" + pattern.toString() + "]");
}
}
}
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException("Unable to lookup expression", e);
}
}
示例5: setup
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
@Before
public void setup() throws Exception {
enforcer = new BannedAttachedArtifacts();
helper = mock(EnforcerRuleHelper.class);
when(helper.getLog()).thenReturn(mock(Log.class));
MavenProject project = mock(MavenProject.class);
when(helper.evaluate("${project}")).thenReturn(project);
// add some artifacts
List<Artifact> artifacts = new ArrayList<>();
Artifact zip = mock(Artifact.class);
when(zip.getFile()).thenReturn(Files.createTempFile("banned-artifacts", ".zip").toFile());
artifacts.add(zip);
Artifact foo = mock(Artifact.class);
when(foo.getFile()).thenReturn(Files.createTempFile("good", ".foo").toFile());
artifacts.add(foo);
when(project.getAttachedArtifacts()).thenReturn(artifacts);
}
示例6: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
Log log = helper.getLog();
try {
// get the various expressions out of the helper.
MavenProject project = (MavenProject) helper.evaluate("${project}");
// MavenSession session = (MavenSession) helper.evaluate("${session}");
// String target = (String) helper.evaluate("${project.build.directory}");
// String artifactId = (String) helper.evaluate("${project.artifactId}");
// ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
// RuntimeInfo rti = (RuntimeInfo) helper.getComponent(RuntimeInfo.class);
List compileSourceRoots = project.getCompileSourceRoots();
for (Object compileSourceRoot : compileSourceRoots) {
String path = (String) compileSourceRoot;
applyForJavaSourcesInRoot(path, log);
}
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
}
}
示例7: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
/**
* Main entry point for the enforcer rule.
*
* @param helper
* @throws EnforcerRuleException
*/
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
HashSet<Artifact> artifacts = new HashSet<Artifact>();
ArtifactCollector[] collectors = {
new DependencyTreeCollector(),
new ReactorCollector(),
new BaseArtifactCollector()
};
for (ArtifactCollector collector : collectors ){
try {
artifacts.addAll(collector.with(helper).getArtifacts());
} catch (Throwable e) {
// Expect failures for API incompatabilities
helper.getLog().debug("[victims-enforcer] Artifact Collector failed: " + collector.getClass().getName());
helper.getLog().debug(e.toString());
}
}
execute(setupContext(helper.getLog()), artifacts);
}
示例8: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
Log log = helper.getLog();
try {
MavenProject currentProject = RuleHelper.getSession(helper).getCurrentProject();
checkForSubmoduleDependencyManagement(currentProject, log);
if (failureDetected) {
throw new EnforcerRuleException("Failing because of forbidden dependency management in sub modules");
}
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
}
}
开发者ID:1and1,项目名称:ono-extra-enforcer-rules,代码行数:16,代码来源:ForbidDependencyManagementInSubModulesRule.java
示例9: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
Log log = helper.getLog();
try {
MavenProject project = getProject(helper);
checkPluginManagementDiffs(project, log);
if (failureDetected) {
throw new EnforcerRuleException("Failing because of overridden managed plugins");
}
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
}
}
示例10: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
try {
MavenProject project = RuleHelper.getProject(helper);
if (ruleIsDefinedInProjectOrNotModuleParent(project, helper.getLog())) {
detectUnmanagedModules(helper, project);
}
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
}
}
示例11: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
/**
* Execute the rule.
*
* @param helper the helper
* @throws EnforcerRuleException the enforcer rule exception
*/
public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException
{
final Log log = helper.getLog();
Object propValue = getPropertyValue( helper );
checkPropValueNotBlank( propValue );
final MavenProject project = getMavenProject( helper );
log.debug( getRuleName() + ": checking property '" + property + "' for project " + project );
final MavenProject parent = findDefiningParent( project );
// fail fast if the defining parent could not be found due to a bug in the rule
if ( parent == null )
{
throw new IllegalStateException( "Failed to find parent POM which defines the current rule" );
}
if ( project.equals( parent ) )
{
log.debug( getRuleName() + ": skip for property '" + property + "' as " + project + " defines rule." );
}
else
{
log.debug( "Check configuration defined in " + parent );
if ( regex == null )
{
checkAgainstParentValue( project, parent, helper, propValue );
}
else
{
checkAgainstRegex( propValue );
}
}
}
示例12: getPropertyValue
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
/**
* Extracted for easier testability.
*
* @param helper
* @param propertyName name of the property to extract.
* @return the value of the property.
* @throws EnforcerRuleException
*/
Object getPropertyValue( EnforcerRuleHelper helper, final String propertyName ) throws EnforcerRuleException
{
try
{
return helper.evaluate( "${" + propertyName + "}" );
}
catch ( ExpressionEvaluationException eee )
{
throw new EnforcerRuleException( "Unable to evaluate property: " + propertyName, eee );
}
}
示例13: getMavenProject
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
/**
* Extracted for easier testability.
*
* @param helper
* @return the MavenProject enforcer is running on.
*
* @throws EnforcerRuleException
*/
MavenProject getMavenProject( EnforcerRuleHelper helper ) throws EnforcerRuleException
{
try
{
return ( MavenProject ) helper.evaluate( "${project}" );
}
catch ( ExpressionEvaluationException eee )
{
throw new EnforcerRuleException( "Unable to get project.", eee );
}
}
示例14: execute
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
/**
* Execute the rule.
*
* @param helper the helper
* @throws EnforcerRuleException the enforcer rule exception
*/
public void execute( EnforcerRuleHelper helper )
throws EnforcerRuleException
{
MavenProject mavenProject = getMavenProject( helper );
// Trying to prevent side-effects with unmodifiable sets (already got burned)
final Set<String> requiredRolesSet = Collections.unmodifiableSet( getRolesFromString( requiredRoles ) );
final Set<String> rolesFromProject = Collections.unmodifiableSet(getRolesFromProject( mavenProject ));
checkRequiredRoles( requiredRolesSet, rolesFromProject );
checkValidRoles( requiredRolesSet, rolesFromProject );
}
示例15: initializeArtifactResolver
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; //导入依赖的package包/类
private void initializeArtifactResolver(EnforcerRuleHelper helper) throws EnforcerRuleException {
try {
resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
} catch (ComponentLookupException e) {
throw new EnforcerRuleException("Unable to lookup artifact resolver!", e);
}
}
开发者ID:ImmobilienScout24,项目名称:illegal-transitive-dependency-check,代码行数:8,代码来源:IllegalTransitiveDependencyCheck.java