当前位置: 首页>>代码示例>>Java>>正文


Java EnforcerRuleHelper类代码示例

本文整理汇总了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);
}
 
开发者ID:mikkoi,项目名称:maven-enforcer-char-set-encoding,代码行数:25,代码来源:TestCharacterSetEncodingRule.java

示例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");
    }
}
 
开发者ID:1and1,项目名称:ono-extra-enforcer-rules,代码行数:23,代码来源:ManageAllModulesRule.java

示例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 );
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:30,代码来源:RequirePropertyDiverges.java

示例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);
    }

}
 
开发者ID:elastic,项目名称:attached-artifact-enforcer,代码行数:27,代码来源:BannedAttachedArtifacts.java

示例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);
}
 
开发者ID:elastic,项目名称:attached-artifact-enforcer,代码行数:19,代码来源:BannedAttachedArtifactsTests.java

示例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);
    }
}
 
开发者ID:CloudSlang,项目名称:cloud-slang,代码行数:23,代码来源:SpringCleansingRule.java

示例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);

}
 
开发者ID:victims,项目名称:victims-enforcer-legacy,代码行数:30,代码来源:VictimsRule.java

示例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);
    }
}
 
开发者ID:1and1,项目名称:ono-extra-enforcer-rules,代码行数:16,代码来源:ForbidOverridingManagedPluginsRule.java

示例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);
    }
}
 
开发者ID:1and1,项目名称:ono-extra-enforcer-rules,代码行数:12,代码来源:ManageAllModulesRule.java

示例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 );
        }
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:42,代码来源:RequirePropertyDiverges.java

示例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 );
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:20,代码来源:RequirePropertyDiverges.java

示例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 );
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:20,代码来源:RequirePropertyDiverges.java

示例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 );
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:19,代码来源:AbstractRequireRoles.java

示例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


注:本文中的org.apache.maven.enforcer.rule.api.EnforcerRuleHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。